![Page 2: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/2.jpg)
2
OVERVIEW
Ray tracing vs. rasterization
How did we get here?
Real-time ray tracing applications
Exposing RTX through Vulkan
![Page 3: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/3.jpg)
3
Ray Tracing vs. Rasterization
▪ Rasterization: evaluate one triangle at
a time
o Store and accumulate some of the
output data, but discard most of it
▪ Computationally cheap, but “local”
▪ Amenable to hardware implementation
![Page 4: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/4.jpg)
4
Ray Tracing vs. Rasterization
▪ Ray tracing: sampling the entire scene
one ray at a time
o Entire scene is evaluated
o Can visit same primitive many times
▪ Extremely flexible
▪ Can be computationally intensive
![Page 5: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/5.jpg)
5
RAY TRACING AT NVIDIA
Real-time graphics: rasterization is king
GPUs evolve to enable powerful rasterization-based algorithms
2007: CUDA brings general purpose computing to GPUs
Ray tracing research focused on acceleration via GPGPU
Decade+ of R&D
![Page 6: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/6.jpg)
6
OPTIX: A GENERAL PURPOSE RAY TRACING ENGINE
Parker et al, OptiX: A General Purpose Ray Tracing Engine, SIGGRAPH 2010
![Page 7: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/7.jpg)
7
NVIDIA RTX
OptiXfor CUDA
Raytracing Extensionsfor Vulkan
DirectX Raytracingfor Microsoft DX12
Applications
NVIDIA® RTX™ Technology
NVIDIA GPU
NVIDIA DesignWorks NVIDIA GameWorks
![Page 8: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/8.jpg)
8
TURING: HARDWARE ACCELERATED RAY
TRACING
![Page 9: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/9.jpg)
9
Physically correct shadows
Sharp and Contact Hardening
Ray Traced Shadows
![Page 10: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/10.jpg)
10
RTAO
SSAOImproved ambient occlusion detail with
fewer artifacts
Ray Traced Ambient Occlusion
![Page 11: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/11.jpg)
11
Physically-correct reflections on arbitrary
surfaces
Ray Traced Reflections
![Page 12: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/12.jpg)
12
Physically-correct light transport in a
complex game
Full Real-Time Path Tracing
![Page 13: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/13.jpg)
13
Ray Tracing: Not Just Graphics
▪ Physics, particle simulations
▪ Audio path tracing / simulation
▪ AI visibility queries
![Page 14: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/14.jpg)
14
EXPOSING RTX THROUGH VULKAN
VK_NV_raytracing
![Page 15: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/15.jpg)
15
API design principles
▪ Proven ray tracing API concepts
▪ Hardware-agnostic
▪ Good fit with Vulkan API
▪ Implementable on compute
functionality
![Page 16: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/16.jpg)
16
GRAPHICS PIPELINES
Ray
Generation
Traversal &
IntersectionShadingScheduling Scheduling
Vertex
Shading
Fragment
ShadingROP
Draw
CallRasterizationScheduling
Rasterization
Ray Tracing
![Page 17: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/17.jpg)
17
BUILDING THE PIPELINE
Acceleration Structure
Abstraction for scene geometry, enables efficient scene traversal
Ray tracing shader domains
Handle ray generation and termination, intersections, material shading
Shader binding table
Links shaders and resources to be used during traversal
Ray tracing Pipeline object
Ray tracing building blocks
![Page 18: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/18.jpg)
18
Acceleration Structure Concepts
▪ Ray tracing: testing one ray against all scene primitives
▪ Acceleration structures required for efficient operation
![Page 19: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/19.jpg)
19
Acceleration Structure Concepts
▪ Dual-level acceleration structure
▪ Opaque (implementation-defined)
data structures
▪ Efficient build and update
Top Level Acceleration Structure (AS)
Transform
and shading
information
Bottom
Level AS
Bottom
Level AS
Transform
and shading
information
Transform
and shading
information
![Page 20: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/20.jpg)
20
Bottom Level AS
Building Acceleration Structures
Vertex & Index Buffers
Build/Update
Bottom Level ASVertex & Index
BuffersBuild/Update
Bottom Level ASVertex & Index
BuffersBuild/Update
![Page 21: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/21.jpg)
21
Bottom Level AS
Building Acceleration Structures
Xform / Shading
Top Level ASBottom Level AS Xform / Shading Build/Update
Bottom Level AS Xform / Shading
![Page 22: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/22.jpg)
22
Creating Acceleration Structures
▪ New object type VkAccelerationStructureNV
▪ New descriptor type for binding AS to shaders
struct VkAccelerationStructureInfoNV {VkStructureType sType;void *pNext;// top-level or bottom-levelVkAccelerationStructureTypeNV type;VkAccelerationStructureCreateFlagsNV flags;uint32_t instanceCount;uint32_t geometryCount;const VkGeometryNV* pGeometries;
};
vkCreateAccelerationStructureNV(VkDevice device,constVkAccelerationStructureCreateInfoNV *info,const VkAllocationCallbacks *pAllocator,VkAccelerationStructureNV *pAccelerationStruct
);
![Page 23: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/23.jpg)
23
Acceleration Structure Memory Management
▪ Backing store for AS is managed by application
▪ Memory requirements will vary
vkGetAccelerationStructureMemoryRequirementsNV(VkDevice device,const
VkAccelerationStructureMemoryRequirementsInfoNV*pInfo,VkMemoryReqiurements2 *pMemoryRequirements
);
vkBindAccelerationStructureMemoryNV(…);
![Page 24: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/24.jpg)
24
Acceleration Structure Build/Update
▪ Single command to build or update an AS
▪ AS updates have restrictions for efficiency
vkCmdBuildAccelerationStructureNV(VkCommandBuffer cmdBuf,const VKAccelerationStructutreInfoNV*,VkBuffer instanceData,VkDeviceSize instanceOffset,VkBool32 update,VkAccelerationStructureNV dst,VkAccelerationStructureNV src,VkBuffer scratch,VkDeviceSize scratchOffset
);
![Page 25: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/25.jpg)
25
Acceleration StructureCopy
▪ Acceleration structures can be copied, optionally
compacting during the copy
vkCmdCopyAccelerationStructure(VkCommandBuffer cmdBuf,VkAccelerationStructure dst,VkAccelerationStructure src,VkCopyAccelerationStructureModeNV mode
);
![Page 26: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/26.jpg)
26
Ray tracing shader domains
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Intersection
Any Hit
yesno
Ray Generation
IntersectionAny-Hit
IntersectionAny-Hit
Closest-Hit
![Page 27: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/27.jpg)
27
Inter-shader communication▪ Ray payload
o Application-defined structure to pass
data between hit stages and shader
stage that spawned a ray
o Used to return final intersection
information to ray generation shader
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Intersection
Any Hit
yesno
Ray Generation:Allocate and fill initial payload
Any-hit: read/update payload
Closest Hit:read/update
Payload
![Page 28: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/28.jpg)
28
Inter-shader communication▪ Ray Attributes
o Application-defined structure to pass
intersection information from
intersection shader to hit shaders
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Intersection
Any Hit
yesnoIntersection: write attributes
Any Hit: read attributes
Intersection: write attributesClosest Hit: read attributes
![Page 29: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/29.jpg)
29
Ray Generation Shaders
▪ Starting point for all ray tracing work
▪ Simple grid of threads launched from
host
▪ Traces rays, writes final output
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Intersection
Any Hit
yesno
![Page 30: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/30.jpg)
30
Intersection Shaders
▪ Compute ray intersections with app-
defined primitives
▪ Ray-triangle intersections built-in
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Any Hit
yesno
Intersection
![Page 31: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/31.jpg)
31
Any-hit shader
▪ Invoked after an intersection is found
▪ Multiple intersections invoked in
arbitrary order
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss Closest Hit
Intersection
yesno
Any Hit
![Page 32: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/32.jpg)
32
Closest-hit shader
▪ Invoked on the closest intersection of
the ray
▪ Can read attributes and trace rays to
modify the payload
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Miss
Intersection
Any Hit
yesno
Closest Hit
![Page 33: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/33.jpg)
33
Miss shader
▪ Invoked if no hit is found and
accepted
▪ Can trace rays and modify ray payload
Ray Generation
traceNV()
Acceleration
Structure
Traversal
Hit?
Closest Hit
Intersection
Any Hit
yesno
Miss
![Page 34: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/34.jpg)
34
Inter-shader Interface Mapping to GLSL
▪ Ray payload and intersection attributes: new
block decorations
▪ traceNV() builtin may be called with different
payload structures in a single shader
rayPayloadNV { … }intersectionAttributesNV { … }
layout (location= 1)rayPayloadNV firstInterface {…}
layout (location= 2)rayPayloadNV secondInterface {…}
traceNV(…, 1) // firstInterfacetraceNV(…, 2) // secondInterface
![Page 35: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/35.jpg)
35
GLSL Extensions▪ Built-in variable decorations:
o ID/index information
o ray parameters, hit parameters
o instance transforms
▪ New functions:
o traceNV() traces a ray into the scene
o reportIntersectionNV() outputs intersection
information
o ignoreIntersectionNV() rejects an intersection
o terminateRayNV() terminates the current ray
traceNV(accelerationStructure topLevel,uint rayFlags,uint cullMask,uint sbtRecordOffset,uint sbtRecordStride,uint missIndex,vec3 origin,float tmin,vec3 direction,float tmax,int payload
);
reportIntersectionNV(float hit,uint hitKind
);
ignoreIntersectionNV();
terminateRayNV();
![Page 36: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/36.jpg)
36
Shader Binding Table
▪ A given ray query into the scene can hit any object
o … with different kinds of material shaders
o … requiring different kinds of resources (e.g., textures)
o … and different parameters (e.g., transparency value)
o … per object instance!
![Page 37: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/37.jpg)
37
Shader Binding Table
▪ Array of opaque shader handles + application storage inside VkBuffer
▪ Indexing used to determine shaders / data used
▪ App-defined stride for SBT records to accommodate different resource sets
![Page 38: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/38.jpg)
38
Shader Binding Table
......
RT Pipeline with RayGeneration
ShaderBindingTable Buffer
Acceleration Structures
Shader Reference
Custom Data & Indices
Descriptor Sets
Shader Reference
Custom Data & Indices
Traversal yields
instanceOffset
Descriptor Sets
Textures etc.
RT Pipeline with ClosestHit
Shader
traces rays
Shader reacts on
hit (can trace)
![Page 39: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/39.jpg)
39
Shader Binding Table and vkCmdTraceRays
......
RT Pipeline with RayGeneration
ShaderBindingTable Buffer
Acceleration Structures
vkCmdTraceRaysNV(VkCommandBuffer, VkBuffer shaderBindingTable, raygenIndex, …)
Shader Reference
Custom Data & Indices
DescriptorSets
Shader Reference
Custom Data & Indices
3: Traversal yields
instanceOffset
DescriptorSets
Textures etc.
RT Pipeline with ClosestHit
1: API invokes RayGeneration Shader
2: Shader
traces rays
4: Shader reacts
on hit (can trace)
![Page 40: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/40.jpg)
40
Ray Tracing Pipeline Creation
▪ Ray tracing pipeline contains all shaders used
together
▪ Can have multiple shaders of the same stage
struct VkRaytracingPipelineCreateInfoNV {VkStructureType sType;void *pNext;
VkPipelineCreateFlags flags;uint32_t stageCount;constVkPipelineShaderStageCreateInfo *stages;uint32_t groupCount;constVkRayTracingShaderGroupCreateInfoNV*pGroups;
uint32_t maxRecursionDepth;VkPipelineLayout layout;VkPipeline basePipelineHandle;int32_t basePipelineIndex;
};
vkCreateRaytracingPipelinesNV(…);
![Page 41: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/41.jpg)
41
Ray Tracing Shader Handles
▪ Exposes opaque shader handles to be used inside
Shader Binding Table
vkGetRaytracingShaderGroupHandlesNV(VkDevice device,VkPipeline pipeline,uint32_t firstGroup,uint32_t groupCount,size_t dataSize,void *pData
);
![Page 42: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/42.jpg)
42
vkCmdTraceRaysNV
▪ Entry point to invoke ray tracing work
▪ Uses existing vkCmdBindPipeline and
vkCmdBindDescriptorSets with new bind point
vkCmdTraceRaysNV(VkCommandBuffer cmdBuf,VkBuffer raygenSBT,VkDeviceSize raygenSBTOffset,VkBuffer missSBT,VkDeviceSize missSBTOffset,VkDeviceSize missSBTStride,VkBuffer hitSBT,VkDeviceSize hitSBTOffset,VkDeviceSize hitSBTStride,VkBuffer callableSBT,VkDeviceSize callableSBTOffset,VkDeviceSize callableSBTStride,uint32_t width,uint32_t height,uint32_t depth
);
![Page 43: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/43.jpg)
43
Example Ray Generation Shader// Binding for the acceleration structurelayout(set = 0, binding = 0) accelerationStructureNV scene;layout(set = 1, binding = 0) image2D framebufferImage;
layout(set = 2, binding = 0, std140) uniform traceParameters {uint sbtMiss;uint sbtOffset;uint sbtStride;vec3 origin;vec3 dir;
}
layout(location = 1) rayPayloadNV primaryPayload {vec4 color;
}
void main() {primaryPayload.color = vec4(0.0, 0.0, 0.0, 0.0);
traceNV(scene, 0, 0, sbtMiss, sbtOffset, sbtStride, traceParameters.origin,0.0, computeDir(gl_GlobalInvocationIDNV.xy, traceParameters.dir),1.e9, 1);
imageStore(framebufferImage, gl_GlobalInvocationIDNV.xy, primaryPayload.color);}
![Page 44: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/44.jpg)
44
Example Closest Hit Shader
// Closest hit shader
//
// Closest hit shaders only have one payload -
// for the incoming ray
rayPayloadInNV primaryPayload {
vec4 color;
}
layout(set = 3, binding = 0) sampler3D solidMaterialSampler;
void main() {
vec3 pos = gl_WorldRayOriginNV + gl_hitTNV * gl_WorldRayDirectionNV;
primaryPayload.color = texture(
solidMaterialSampler, pos);
}
![Page 45: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/45.jpg)
45
Iterative Loop Path Tracing in Ray Generation Shader
vec3 color = 0.0f;Float sample_pdf = 1.0f;vec3 path_throughput = 1.0f;
// GBufferEntry contains all necessary info to reconstruct the hit and local brdfGBufferEntry gbuffer_entry = imageLoad(gbuffer, gl_GlobalInvocationID.xy);
Ray ray = reconstruct_ray( gbuffer_entry, pixel ); // reconstruct the first ray
for (uint32 bounce = 0; bounce < max_bounces; ++bounce) {// unpack the brdfBrdf brdf = get_brdf( gbuffer_entry );
// accumulate emission of the local surfacecolor += path_throughput * local_emission( gbuffer_entry, brdf, sample_pdf );
// perform next-event estimation (casts one or more shadow rays, getting visibility as a return value)color += path_throughput * next_event_estimation( gbuffer_entry, brdf, sample_pdf );
// sample the brdfvec3 sample_throughput;
ray = sample_brdf( gbuffer_entry, brdf, sample_throughput, sample_pdf );
// perform Russian-Roulette to terminate pathif (random() >= max(sample_throughput))
break;
// accumulate the path throughputpath_throughput *= sample_throughput / max(sample_throughput);
// trace a ray and get a brdf as a return valuegbuffer_entry = trace(…, ray.origin, ray.direction, …);
}
![Page 46: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/46.jpg)
46
HLSL Support
Mainline DXC now has initial support for compiling DXR shaders into SPIR-V!
▪ NVIDIA working with Google on enhancing Spiregg to support ray tracing shaders
▪ Support for RT shader stages and built-ins available in mainline today
▪ SBT not yet exposed, but coming soon
![Page 47: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/47.jpg)
47
HLSL Support
▪ Resource binding model is different between DXR and Vulkan
o DXR: SBT contains local root signature, used by the bytecode compiler to map
resources
o Vulkan: SBT is just memory, used by the shader directly
• Intent is for app to use EXT_descriptor_indexing to make resources available, then store
indices in the SBT record
• EXT_device_buffer_address allows buffer pointers in SBT
▪ Design work underway to expose SBT with source-level compatibility for DXR
shaders
![Page 48: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/48.jpg)
48
Check out Quake 2 RTX at our booth!
![Page 49: RTX ON VULKAN - developer.download.nvidia.com · 3 Ray Tracing vs. Rasterization Rasterization: evaluate one triangle at a time o Store and accumulate some of the output data, but](https://reader030.vdocument.in/reader030/viewer/2022040700/5d4fbdc588c993110c8b7a7b/html5/thumbnails/49.jpg)
49
Conclusion
▪ RTX is available in Vulkan!
▪ NVIDIA fully committed to working with Khronos on
multi-vendor standardization
https://www.khronos.org/registry/vulkan/specs/1.1-
extensions/html/
https://developer.nvidia.com/rtx/raytracing/vkray
https://devblogs.nvidia.com/rtx-best-practices (soon!)