1 / 48

Restart Trail for Stackless BVH Traversal

Restart Trail for Stackless BVH Traversal. Samuli Laine NVIDIA Research. Background. Ray casting in usual acceleration hierarchies is tree traversal kd-trees Bounding volume hierarchies Typically, traversal requires a stack Traversal stack is expensive Storage Bandwidth.

saskia
Download Presentation

Restart Trail for Stackless BVH Traversal

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Restart Trail for StacklessBVH Traversal Samuli LaineNVIDIA Research

  2. Background • Ray casting in usual acceleration hierarchies is tree traversal • kd-trees • Bounding volume hierarchies • Typically, traversal requires a stack • Traversal stack is expensive • Storage • Bandwidth

  3. Closer Look at Traversal • Basic non-recursive tree traversal while (not terminated) if (not a leaf node) fetch bounds of children of current node check which children are intersected by the ray if (intersections) sort intersected children according to proximity make closest intersected child the current node push other children into stack else pop stack, terminate if empty end if else process primitives in leaf node pop stack, terminate if empty end if end while

  4. Closer Look at Traversal • Basic non-recursive tree traversal while (not terminated) if (not a leaf node) fetch bounds of children of current node check which children are intersected by the ray if (intersections) sort intersected children according to proximity make closest intersected child the current node push other children into stack else pop stack, terminate if empty end if else process primitives in leaf node pop stack, terminate if empty end if end while

  5. Stackless kd-Tree Traversal • [Foley and Sugerman 2005] while (not terminated) (ray not shrunk to a point) if (not a leaf node) fetch bounds of children of current node check which children are intersected by the ray if (intersections) sort intersected children according to proximity make closest intersected child the current node push other children into stack do nothing else pop stack, terminate if empty shorten ray, restart end if else process primitives in leaf node pop stack, terminate if empty shorten ray, restart end if end while

  6. Why Does this Work? Node Near child Far child Original raybefore restart Intersect! Go here Forget Splitplane

  7. Why Does this Work? Node Near child Far child Shortened ray after restart Intersect!Go here (not intersected) Splitplane

  8. kd-Trees and Other BSP Trees Sorted according to traversal order

  9. kd-Trees and Other BSP Trees Processed nodes Unprocessed nodes Ray part A Ray part B Sorted according to traversal order

  10. Short-Stack kd-tree Traversal • [Horn et al. 2007] • Store only n topmost stack entries • Shorten ray and restart when stack is exhausted • With n=3, only 3% too many nodes processed • Stackless (n=0) roughly doubles the amount of work

  11. What About BVH? • In BVH, nodes may overlap  Unprocessed part of BVH tree does not correspond to a shortened ray  Restarting traversal by shortening the ray is not possible  Stackless and short-stack traversal cannot be used

  12. Example of Impossible Restart B B1 B2 A1 A B A2 A1 B2 A2 B1 A

  13. Example of Impossible Restart B B1 B2 A1 A B A2 A1 B2 A2 B1 A Processed nodes Run out of stack here, need to restart after processing A2

  14. Example of Impossible Restart B B1 B2 A1 A B A2 A1 B2 A2 B1 A Processed nodes Does not work, misses B entirely

  15. Example of Impossible Restart B B1 B2 A1 A B A2 A1 B2 A2 B1 A Processed nodes Does not work, revisits A and A1

  16. Example of Impossible Restart B B1 B2 A1 A B A2 A1 B2 A2 B1 A Processed nodes Problem: Any ray that covers B1 will revisit A and A2

  17. Solution: Restart Trail • If we sort a BVH according to ray traversal order, we can partition it into processed and unprocessed parts • Unlike in kd-trees, these parts do not correspond to ray segments, but there’s no need to worry about that • Therefore, we can cheaply store which part of the hierarchy has been processed • Upon restart, consult the information to steer the traversal to the correct part of the tree

  18. Processed vs Unprocessed Nodes Processed nodes Unprocessed nodes Sorted according to traversal order

  19. Finding the Next Unprocessed Node 0 Restarttrail 1 1 This is the node we need to find Sorted according to traversal order

  20. Restart Trail Encoding, Issues • One bit per level is enough • This leaves many options for the actual encoding • Must remain consistent during traversal • What if only one child node is intersected? • What if the ray is shortened from the end during traversal? • Needs to be updated efficiently • After processing a node, we want to update the trail without remembering anything about our ancestors • Should be transparent during traversal • No splitting into before-restart and after-restart codepaths

  21. Our Encoding Scheme • 0 = Node not visited yet OR node has two children to be traversed, subtree under near child not fully traversed • 1 = Node has one child to be traversed OR node has two children to be traversed, subtree under near child has been fully traversed • One sentinel bit on top of actual trail • Allows easy detection of when to terminate the traversal

  22. Use of Trail During Traversal • If node has two children • 0 = Go to near child • 1 = Go to far child • When initialized to all zeros, does not affect usual traversal order • Always set bit when going through one-child node • Does not affect traversal, but enables efficient updates!

  23. Efficient Updates • Other view of encoding: • 0 = I have a far child that is not processed yet • 1 = otherwise • Trail update must make trail point to next unprocessed node • Find last zero bit, toggle it to one, clear the rest • Sounds suspiciously like binary addition

  24. Traversal Example 0 0 0 0 0 …

  25. Traversal Example 0 0 0 0 0 …

  26. Traversal Example 0 0 0 0 0 …

  27. Traversal Example 0 0 0 1 0 …

  28. Traversal Example 0 0 1 0 0 …

  29. Traversal Example 0 0 1 1 0 …

  30. Traversal Example 0 0 1 1 0 …

  31. Traversal Example 0 1 0 0 0 …

  32. Traversal Example 0 1 1 0 0 …

  33. Traversal Example 0 1 1 0 0 …

  34. Traversal Example 1 0 0 0 0 …

  35. Traversal Example 1 0 0 I’m outtahere 0 0 …

  36. Gotcha: Rays Shortened at the End • During traversal, primitive intersection may shorten the ray at the end • Makes it possible to terminate traversal before ray exits scene • Can change two-child node into one-child node • Node has two children during descent, but only one during restart • If not handled properly, this can cause multiple traversal

  37. Trouble with Shortened Ray … 0 0 …

  38. Trouble with Shortened Ray … 0 0 … This branch gets culled While traversing this subtree

  39. Trouble with Shortened Ray … 0 1 … Trail is updated after this subtree is processed

  40. Trouble with Shortened Ray … 0 1 … Stack is exhausted, and a restart is initiated

  41. Trouble with Shortened Ray … 0 1 … This node does not have a far child anymore, so we cannot go there The same subtree is processed again

  42. Solving the Shortened Ray Problem • Notice which bit was toggled to one when updating trail • When traversing, detect if there is a one-child node on this level • If so, the only explanation is that the far child was culled • Proper action is to update trail and restart again

  43. Practical Implementation • Keep trail and current level bit in registers • Set and query bits trivially using Boolean operations • Trail update • Find last zero above current level, toggle to one, clear the rest TrailReg &= -LevelReg; TrailReg += LevelReg; • Determining level pointer after trail update • Find last one temp = TrailReg >> 1; LevelReg = ((temp – 1) ^ temp) + 1;

  44. Results • Overvisit factor of 2.2–2.4 for stackless traversal • Similar to results of Foley and Sugerman [2005] • Three-entry short stack causes 5–8% overvisit • Compared to 3% reported by Horn et al. [2007] • Possibly because two-child intersections are more frequent in BVHs than kd-trees, yielding more restarts Fairy Forest, 174K tris Conference, 282K tris

  45. Results on Hardware • Restart trails were originally implemented in BVH ray cast kernels • Used to improve performance for a long while, but did not pay off in the most optimized variants • Not tested on Fermi hardware yet • Cache trashing caused by stack traffic could make stackless (or register-only) traversal attractive again

  46. Possible Use Cases • Situations where • Not enough local storage for storing full traversal stack • Not enough memory bandwidth for stack traffic • Custom traversal hardware? • Cleaner memory interface • Read-only memory client • Pays off whenever cost of extra node traversal is less than cost of stack pushes and pops

  47. Extensions, Future Work • Storing two bits per level to avoid doing node intersection tests again • Avoiding intersection tests might not pay off on wide SIMD • Extension to higher branching factors • Could a similar approach be applied in other kinds of traversals? • e.g. closest-point and kNN searches for density estimation

  48. Thank You • Questions

More Related