GPU Ray-Traced Collision Detection Fine Pipeline Reorganization
Total Page:16
File Type:pdf, Size:1020Kb
GPU Ray-traced Collision Detection Fine Pipeline Reorganization Franc¸ois Lehericey, Valerie´ Gouranton and Bruno Arnaldi INSA de Rennes, IRISA, Inria, Campus de Beaulieu, 35042 Rennes cedex, France Keywords: Collision Detection, Narrow-phase, GPU Computing. Abstract: Ray-tracing algorithms can be used to render a virtual scene and to detect collisions between objects. Numer- ous ray-tracing algorithms have been proposed which use data structures optimized for specific cases (rigid objects, deformable objects, etc.). Some solutions try to optimize performance by combining several algo- rithms to use the most efficient algorithm for each ray. This paper presents a ray-traced collision detection pipeline that improves the performance on a graphicd processing unit (GPU) when several ray-tracing algo- rithms are used. When combining several ray-tracing algorithms on a GPU, a well-known drawback is thread divergence among work-groups that can cause loss of performance by causing idle threads. In this paper we avoid branch divergence by dividing the ray tracing into three steps with append buffers in between. We also show that prediction can be used to avoid unnecessary synchronizations between the CPU and GPU. Applied to a narrow-phase collision detection algorithm, results show an improvement of performance up to 2.7 times. 1 INTRODUCTION In the literature four categories of narrow-phase algorithms are studied, including image-based algo- Collision detection (CD) is an important task in vir- rithms that uses rendering techniques to detect colli- tual reality (VR). From a set of objects, we need to sions. As GPUs are designed especially for render- know those which collide. Nowadays collision is one ing, image-based methods are well suited for GPGPU of the main bottlenecks in VR applications due to the implementations. In particular ray-tracing algorithms complexity of environments we want to simulate and can be used and several ones can be combined the real-time constraint required by VR. We need to to improve performance (Lehericey et al., 2013a). simulate large environments that can count millions When implementing several ray-tracing algorithms of objects. And we want to include complex objects on GPUs, high branch divergence in the execution that can be deformable, undergo topology changes or can lead to underuse of the GPU and reduced perfor- be fluids. mance. To handle such a work load, collision is generally Main Contributions: we present a new pipeline or- divided into two phases: broad-phase and narrow- ganization of the narrow-phase for ray-traced colli- phase. The broad-phase takes the whole set of objects sion detection. The goal of our pipeline is to minimize from the environment and provides a set of pairs of thread divergence on GPUs to improve performance. objects that might collide. The narrow-phase takes Our pipeline is designed to be able to integrate sev- these pairs and outputs the ones that actually col- eral ray-tracing algorithms without causing overhead. lide. This paper focuses on the narrow-phase which We then present a prediction method to avoid CPU- is nowadays the most time-consuming phase. GPU synchronization between steps of the pipeline to Recent approaches use GPGPU (general-purpose further improve performance. computing on graphics processing units) to take ad- This paper is arranged as follows. The follow- vantage of the high computational power of recent ing section provides a reviex of the relevant literature. GPUs. Parallel implementation of the broad-phase Section 3 presents our ray-traced collision pipeline. sweep and prune algorithm on GPUs improve per- Section 4 shows how prediction can be used to avoid formance by orders of magnitude (Liu et al., 2010). unnecessary synchronization between the CPU and The narrow-phase can also be implemented on a GPU GPU. Implementation and results are discussed in (Pabst et al., 2010). Section 5. Section 6 concludes this paper. Lehericey F., Gouranton V. and Arnaldi B.. 317 GPU Ray-traced Collision Detection - Fine Pipeline Reorganization. DOI: 10.5220/0005299603170324 In Proceedings of the 10th International Conference on Computer Graphics Theory and Applications (GRAPP-2015), pages 317-324 ISBN: 978-989-758-087-1 Copyright c 2015 SCITEPRESS (Science and Technology Publications, Lda.) GRAPP2015-InternationalConferenceonComputerGraphicsTheoryandApplications 2 RELATED WORK gorithm is a fast ray-tracing algorithm that exploits spatial and temporal coherency by updating the previ- This section focuses on the literature on CD which is ous time-step. These algorithms can be used on GPUs most pertinent to our work, in particular image-based for improved performance. algorithms for the narrow-phase. For an exhaustive overview on CD, readers should refer to surveys such 2.2 GPU Computing as (Teschner et al., 2005; Kockara et al., 2007). Several methods consider the GPU as a streaming 2.1 Image-based Collision Detection processor. As GPUs are massively parallel proces- sors, computations should be arranged to be made parallel (Nickolls and Dally, 2010). Image-based algorithms use rendering techniques to When code runs on a GPU, the same function detect collisions. These methods are often adapted for (called kernel) is called by multiple threads (called GPUs, which are processors designed for rendering. work-item) on different data. Work-items do not run Image-based methods can be used to perform colli- independently but in a group (called work-group); in sion detection on rigid and deformable bodies. These a work-group, work-items run in a single instruction, techniques usually do not require any pre-processing multiple data way. On a conditional branch, if the steps which makes them suitable for dynamically de- work-items diverge among a work-group, each branch forming objects. Image-based algorithms can either runs serially. This phenomena is called thread diver- use rasterization or ray-tracing techniques. gence and reduces performance (Zhang et al., 2010). Rasterization can be used to compute a layered One case of thread divergence is having a sparse depth image (LDI) which can be post-processed to input, in which case some work-items have nothing to detect collisions (Allard et al., 2010). The CInDeR do and are idle in a work-group while the other work- algorithm (Knott, 2003) uses rasterization to implic- items finish. Collision-streams (Tang et al., 2011) itly cast rays from the edges of an object and counts use stream compaction to avoid kernel execution on how many object faces the ray passes through. If the sparse inputs. Collision detection is divided into sev- result is odd then there is collision; otherwise there is eral steps and streaming compaction is used between no collision. (Heidelberger et al., 2003; Heidelberger steps to ensure dense input for each kernel. et al., 2004) take three-dimensional closed objects and output the intersection volume without the needs of 2.3 Synthesis any data structures making it suitable for deformable objects. The main drawback of these techniques is the Ray-traced collision detection can be used on GPUs discretization of the space through rendering that in- to achieve high performance on complex scenes. In duces approximations and may lead to the omission a simple scenario only one ray-tracing algorithm can of small objects. be used to resolve collisions. But in complex scenes Ray-tracing algorithms can be used to overcome with objects of different nature we can employ sev- these approximations. (Wang et al., 2012) show that eral ray-tracing algorithms to optimize each nature of ray tracing can be used to compute a LDI with a object. With rigid objects we can use algorithms with higher resolution around small objects by increasing complex data structures. With deformable objects we the density or rays locally to increase the precision. need data structures that can be updated at each time- (Hermann et al., 2008) detect collisions by casting step. In the case of topology changes we need to re- rays from each vertex of the objects. Rays are cast construct the ray-tracing data structures occasionally. in the inward direction; the ones that hit another ob- Iterative ray-tracing can be used to accelerate all of ject before leaving the source object detect a collision. these algorithms. Before casting a ray, the ones that are outside the in- In complex scenes where all these properties tersection of the bonding volumes are dropped since are represented, combining several ray-tracing algo- they cannot collide. rithms improves performance. In such situations, the Based on Hermann et al.’s algorithm, (Lehericey need of a narrow-phase that can easily manage di- et al., 2013a; Lehericey et al., 2013b) introduced verse ray-tracing algorithms without losing perfor- an iterative ray-traced collision detection algorithm mance emerges. (IRTCD). This method combines two different ray- tracing algorithms; a full and an iterative algorithm that are respectively used for high and small displace- ments between objects. The full algorithm can be any existing ray-tracing algorithm. The iterative al- 318 GPURay-tracedCollisionDetection-FinePipelineReorganization 3 RAY-TRACED CD PIPELINE quentially. Second, in a context where we can safely cull some vertices to reduce the amount of compu- To perform our ray-traced CD method there are sev- tation, this naive implementation will initiate work- eral ray-tracing algorithms available in the literature. items that finish immediately. These work-items will We selected three algorithms. We qualify the two first then be idle while the other work-items of the work- ones as ‘full’ ray-tracing algorithms; these algorithms group finish. can be used at any time. The third algorithm, called This section presents our pipeline distribution of iterative, requires specific conditions. tasks to improve the performance of ray-traced col- The first full algorithm is a stackless bounding lision detection on GPUs. Subsection 3.1 gives an volume hierarchy (BVH) traversal.