A method, 
system, and computer-readable storage medium are disclosed for building 
ray tracing data structures for three-dimensional scenes. The methods may include accessing an initial 
data structure representing a coarse hierarchy of a scene geometry, e.g., a 
scene graph, and sorting elements of the initial 
data structure into multiple spatial partitions with respect to one or more splitting planes. The sorting may be dependent on spatial bounding ranges of non-leaf nodes of the initial 
data structure, which may be sorted without visiting the geometric primitives below. Sorting may be performed on pointers to elements of the initial data structure and may comprise a hierarchical 
quicksort. The resulting 
ray tracing data structure may comprise a k-dimensional tree, binary 
space partitioning tree, k-plane tree, bounding interval hierarchy, or fine-grained hierarchical 
bounding volume tree. The methods described herein may accelerate the building of 
ray tracing data structures for use in 
interactive graphics applications.