Table Of ContentGPU Pro 360
Guide to GPGPU
GPU Pro 360
Guide to GPGPU
Edited by Wolfgang Engel
CRCPress
Taylor&FrancisGroup
6000BrokenSoundParkwayNW,Suite300
BocaRaton,FL33487-2742
(cid:13)c 2019byTaylor&FrancisGroup,LLC
CRCPressisanimprintofTaylor&FrancisGroup,anInformabusiness
NoclaimtooriginalU.S.Governmentworks
Printedonacid-freepaper
InternationalStandardBookNumber-13: 978-1-138-48439-9(Paperback)
InternationalStandardBookNumber-13: 978-1-138-48441-2(Hardback)
Thisbookcontainsinformationobtainedfromauthenticandhighlyregardedsources. Reasonableeffortshave
beenmadetopublishreliabledataandinformation,buttheauthorandpublishercannotassumeresponsibility
forthevalidityofallmaterialsortheconsequencesoftheiruse. Theauthorsandpublishershaveattemptedto
tracethecopyrightholdersofallmaterialreproducedinthispublicationandapologizetocopyrightholdersif
permissiontopublishinthisformhasnotbeenobtained. Ifanycopyrightmaterialhasnotbeenacknowledged
pleasewriteandletusknowsowemayrectifyinanyfuturereprint.
ExceptaspermittedunderU.S.CopyrightLaw,nopartofthisbookmaybereprinted,reproduced,transmitted,
orutilizedinanyformbyanyelectronic,mechanical,orothermeans,nowknownorhereafterinvented,
includingphotocopying,microfilming,andrecording,orinanyinformationstorageorretrievalsystem,without
writtenpermissionfromthepublishers.
Forpermissiontophotocopyorusematerialelectronicallyfromthiswork,pleaseaccesswww.copyright.com
(http://www.copyright.com/)orcontacttheCopyrightClearanceCenter,Inc. (CCC),222RosewoodDrive,
Danvers,MA01923,978-750-8400. CCCisanot-for-profitorganizationthatprovideslicensesandregistration
foravarietyofusers. FororganizationsthathavebeengrantedaphotocopylicensebytheCCC,aseparate
systemofpaymenthasbeenarranged.
Trademark Notice: Productorcorporatenamesmaybetrademarksorregisteredtrademarks,andareused
onlyforidentificationandexplanationwithoutintenttoinfringe.
Library of Congress Cataloging-in-Publication Data
Names: Engel,WolfgangF.,editor.
Title: GPUpro360guidetoGPGPU/[editedby]WolfgangEngel.
Description: Firstedition. |BocaRaton,FL:CRCPress/Taylor&FrancisGroup,2018. |Includes
bibliographicalreferencesandindex.
Identifiers: LCCN2018020469|ISBN9781138484399(pbk. : acid-freepaper)|
ISBN9781138484412(hardback: acid-freepaper)
Subjects: LCSH:Computergraphics. |Graphicsprocessingunits--Programming.
Classification: LCCT385.G688782018|DDC006.6--dc23
LCrecordavailableathttps://lccn.loc.gov/2018020469
Visit the eResources: www.crcpress.com/9781138484399
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Contents
Introduction xi
Web Materials xv
1 2D Distance Field Generation with the GPU 1
Philip Rideout
1.1 Vocabulary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Manhattan Grassfire . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Horizontal-Vertical Erosion . . . . . . . . . . . . . . . . . . . . 6
1.4 Saito-Toriwaki Scanning with OpenCL . . . . . . . . . . . . . 8
1.5 Signed Distance with Two Color Channels . . . . . . . . . . . 16
1.6 Distance Field Applications . . . . . . . . . . . . . . . . . . . 18
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2 Order-Independent Transparency Using Per-Pixel Linked Lists 23
Nicolas Thibieroz
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2 Algorithm Overview. . . . . . . . . . . . . . . . . . . . . . . . 23
2.3 DirectX 11 Features Requisites . . . . . . . . . . . . . . . . . 24
2.4 Head Pointer and Nodes Buffers . . . . . . . . . . . . . . . . . 25
2.5 Per-Pixel Linked List Creation . . . . . . . . . . . . . . . . . . 27
2.6 Per-Pixel Linked Lists Traversal . . . . . . . . . . . . . . . . . 30
2.7 Multisampling Antialiasing Support . . . . . . . . . . . . . . . 35
2.8 Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.9 Tiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.11 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 45
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3 Simple and Fast Fluids 47
Martin Guay, Fabrice Colin, and Richard Egli
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
v
vi Contents
3.2 Fluid Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.3 Solver’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 50
3.4 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.5 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4 A Fast Poisson Solver for OpenCL Using Multigrid Methods 59
Sebastien Noury, Samuel Boivin, and Olivier Le Maˆıtre
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.2 Poisson Equation and Finite Volume Method. . . . . . . . . . 60
4.3 Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.4 Multigrid Methods (MG) . . . . . . . . . . . . . . . . . . . . . 71
4.5 OpenCL Implementation . . . . . . . . . . . . . . . . . . . . . 74
4.6 Benchmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.7 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5 Volumetric Transparency with Per-Pixel Fragment Lists 87
L´aszl´o Sz´ecsi, P´al Barta, and Bal´azs Kov´acs
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2 Light Transport Model . . . . . . . . . . . . . . . . . . . . . . 88
5.3 Ray Decomposition . . . . . . . . . . . . . . . . . . . . . . . . 89
5.4 Finding Intersections with Ray Casting . . . . . . . . . . . . . 91
5.5 Application for Particle System Rendering . . . . . . . . . . . 94
5.6 Finding Intersections with Rasterization . . . . . . . . . . . . 95
5.7 Adding Surface Reflection . . . . . . . . . . . . . . . . . . . . 97
5.8 Shadow Volumes . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6 Practical Binary Surface and Solid Voxelization with Direct3D 11 101
Michael Schwarz
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
6.2 Rasterization-Based Surface Voxelization . . . . . . . . . . . . 102
6.3 Rasterization-Based Solid Voxelization . . . . . . . . . . . . . 106
6.4 Conservative Surface Voxelization with DirectCompute . . . . 108
6.5 Solid Voxelization with DirectCompute . . . . . . . . . . . . . 113
6.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Contents vii
7 Interactive Ray Tracing Using the Compute Shader in DirectX 11 117
Arturo Garc´ıa, Francisco A´vila, Sergio Murgu´ıa, and Leo Reyes
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
7.2 Ray Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
7.3 Our Implementation . . . . . . . . . . . . . . . . . . . . . . . 121
7.4 Primary Rays Stage . . . . . . . . . . . . . . . . . . . . . . . . 125
7.5 Intersection Stage . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.6 Color Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
7.7 Multipass Approach . . . . . . . . . . . . . . . . . . . . . . . . 135
7.8 Results and Discussion . . . . . . . . . . . . . . . . . . . . . . 135
7.9 Optimization. . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
7.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
7.11 Further Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
7.12 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 139
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
8 Bit-Trail Traversal for Stackless LBVH on DirectCompute 141
Sergio Murgu´ıa, Francisco A´vila, Leo Reyes, and Arturo Garc´ıa
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
8.2 Ray Tracing Rendering . . . . . . . . . . . . . . . . . . . . . . 142
8.3 Global Illumination . . . . . . . . . . . . . . . . . . . . . . . . 142
8.4 Stackless LBVH . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.5 The SLBVH in Action . . . . . . . . . . . . . . . . . . . . . . 153
8.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
8.7 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 157
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9 Real-Time JPEG Compression Using DirectCompute 159
Stefan Petersson
9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
9.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
9.5 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 177
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
10 Hair Simulation in TressFX 179
Dongsoo Han
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.2 Simulation Overview . . . . . . . . . . . . . . . . . . . . . . . 180
10.3 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
10.4 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
viii Contents
10.5 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
10.6 Wind and Collision . . . . . . . . . . . . . . . . . . . . . . . . 184
10.7 Authoring Hair Asset . . . . . . . . . . . . . . . . . . . . . . . 185
10.8 GPU Implementation . . . . . . . . . . . . . . . . . . . . . . . 186
10.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11 Object-Order Ray Tracing for Fully Dynamic Scenes 191
Tobias Zirr, Hauke Rehfeld, and Carsten Dachsbacher
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
11.2 Object-Order Ray Tracing Using the Ray Grid . . . . . . . . . 193
11.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
11.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 196
11.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
11.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
12 Quadtrees on the GPU 211
Jonathan Dupuy, Jean-Claude Iehl, and Pierre Poulin
12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
12.2 Linear Quadtrees . . . . . . . . . . . . . . . . . . . . . . . . . 212
12.3 Scalable Grids on the GPU . . . . . . . . . . . . . . . . . . . . 215
12.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
12.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
13 Two-LevelConstraintSolverandPipelinedLocalBatchingforRigid
Body Simulation on GPUs 223
Takahiro Harada
13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
13.2 Rigid Body Simulation . . . . . . . . . . . . . . . . . . . . . . 224
13.3 Two-Level Constraint Solver . . . . . . . . . . . . . . . . . . . 226
13.4 GPU Implementation . . . . . . . . . . . . . . . . . . . . . . . 228
13.5 Comparison of Batching Methods . . . . . . . . . . . . . . . . 231
13.6 Results and Discussion . . . . . . . . . . . . . . . . . . . . . . 233
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
14 Non-separable 2D, 3D, and 4D Filtering with CUDA 241
Anders Eklund and Paul Dufort
14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
14.2 Non-separable Filters . . . . . . . . . . . . . . . . . . . . . . . 243
14.3 Convolution vs. FFT . . . . . . . . . . . . . . . . . . . . . . . 246
14.4 Previous Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Contents ix
14.5 Non-separable 2D Convolution . . . . . . . . . . . . . . . . . . 247
14.6 Non-separable 3D Convolution . . . . . . . . . . . . . . . . . . 252
14.7 Non-separable 4D Convolution . . . . . . . . . . . . . . . . . . 253
14.8 Non-separable 3D Convolution, Revisited . . . . . . . . . . . . 254
14.9 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
14.10 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
15 Compute-Based Tiled Culling 265
Jason Stewart
15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
15.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
15.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 267
15.4 Optimization. . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.5 Unreal Engine 4 Results . . . . . . . . . . . . . . . . . . . . . 282
15.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
15.7 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 288
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
16 Rendering Vector Displacement-Mapped Surfaces in a GPU Ray
Tracer 289
Takahiro Harada
16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
16.2 Displacement Mapping . . . . . . . . . . . . . . . . . . . . . . 289
16.3 Ray Tracing a Scene with Vector Displacement Maps . . . . . 291
16.4 Ray Tracing a Vector Displacement Patch . . . . . . . . . . . 291
16.5 Integration into an OpenCL Ray Tracer . . . . . . . . . . . . 297
16.6 Results and Discussion . . . . . . . . . . . . . . . . . . . . . . 300
16.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
17 Smooth Probabilistic Ambient Occlusion for Volume Rendering 305
Thomas Kroes, Dirk Schut, and Elmar Eisemann
17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
17.2 Smooth Probabilistic Ambient Occlusion . . . . . . . . . . . . 306
17.3 Approximating Ambient Occlusion . . . . . . . . . . . . . . . 311
17.4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
17.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314