Skip to content

Commit 71eb609

Browse files
authored
Ray tracing siggraph25 (#4)
Moved 18_Ray_tracing.adoc to courses/18_Ray_tracing folder and broke it up into subsections. Did a few minor edits to address flow. The courses folder should make it easier to create courseware content in the future and provide attribution easily via a README file.
1 parent fb2364c commit 71eb609

12 files changed

Lines changed: 976 additions & 1305 deletions

antora/modules/ROOT/nav.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@
5252
* xref:15_GLTF_KTX2_Migration.adoc[Migrating to Modern Asset Formats: glTF and KTX2]
5353
* xref:16_Multiple_Objects.adoc[Rendering Multiple Objects]
5454
* xref:17_Multithreading.adoc[Multithreading]
55+
* xref:courses/18_Ray_tracing/00_Overview.adoc[Ray Tracing]
56+
** xref:courses/18_Ray_tracing/00_Overview.adoc[Overview]
57+
** xref:courses/18_Ray_tracing/01_Dynamic_rendering.adoc[Dynamic rendering]
58+
** xref:courses/18_Ray_tracing/02_Acceleration_structures.adoc[Acceleration structures]
59+
** xref:courses/18_Ray_tracing/03_Ray_query_shadows.adoc[Ray query shadows]
60+
** xref:courses/18_Ray_tracing/04_TLAS_animation.adoc[TLAS animation]
61+
** xref:courses/18_Ray_tracing/05_Bindless_resources.adoc[Bindless resources]
62+
** xref:courses/18_Ray_tracing/06_Shadow_transparency.adoc[Shadow transparency]
63+
** xref:courses/18_Ray_tracing/07_Reflections.adoc[Reflections]
64+
** xref:courses/18_Ray_tracing/08_Conclusion.adoc[Conclusion]
5565
* xref:90_FAQ.adoc[FAQ]

en/18_Ray_tracing.adoc

Lines changed: 0 additions & 1305 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
== SIGGRAPH 2025: Hands-on Vulkan Ray Tracing with Dynamic Rendering
2+
3+
=== Overview
4+
5+
Welcome! In this series, we enhance a Vulkan renderer with ray tracing features to implement real-time pixel-perfect shadows (with and without transparency) and a bonus reflection effect. You will work with provided scaffolded code (based on the Vulkan Tutorial) and fill in key shader functions following step-by-step instructions.
6+
7+
By the end, you'll learn how to:
8+
9+
- Use Vulkan dynamic rendering (no pre-defined render passes) and verify it with RenderDoc.
10+
- Create bottom-level and top-level Acceleration Structures (BLAS and TLAS) for ray tracing.
11+
- Implement ray query based shadow rays (first with all-opaque geometry, then with alpha-test transparency).
12+
- Debug/inspect the acceleration structures in Nsight Graphics.
13+
- (Bonus) Implement ray query based reflections.
14+
15+
Prerequisites:
16+
This series targets intermediate Vulkan programmers. We assume you have completed the basic Vulkan Tutorial (graphics pipeline, descriptor sets, etc.). If not, you can still follow along conceptually. A Windows machine with up-to-date Vulkan SDK (1.4.311), a GPU supporting ray tracing (Vulkan Ray Query), plus RenderDoc and Nsight Graphics is provided.
17+
18+
Mobile Best-Practice Notes:
19+
20+
- We use VK_KHR_dynamic_rendering (core in Vulkan 1.3) instead of traditional render passes. This not only simplifies the API but also, with the VK_KHR_dynamic_rendering_local_read extension, enables tile-local storage reads similar to subpasses, a big deal for mobile tile-based GPUs to save bandwidth.
21+
- We use Ray Queries (from VK_KHR_ray_query) within fragment shaders instead of a separate ray tracing pipeline. On mobile, ray queries are far more widely supported and often (depending on the use case) more efficient than the full ray tracing pipeline. Ray queries integrate nicely into fragment shading, benefiting from on-chip compression and avoiding context switches.
22+
23+
Provided Code:
24+
The provided code is a Vulkan renderer that already implements a basic graphics pipeline with dynamic rendering. It is based on the Vulkan Tutorial and it is self-contained in a single C++ source file and a Slang shader file:
25+
26+
- link:../../../attachments/38_ray_tracing.cpp[38_ray_tracing.cpp]
27+
- link:../../../attachments/38_ray_tracing.slang[38_ray_tracing.slang]
28+
- If you get stuck on shader tasks, you can refer to the provided reference solution: link:../../../attachments/38_ray_tracing_complete.slang[38_ray_tracing_complete.slang]
29+
30+
The source code is structured to guide you through the steps, with hints and boilerplate provided. It also sets up all the required extensions and features, including VK_KHR_acceleration_structure and VK_KHR_ray_query. You will find sections of code marked with // TASKxx which we reference in each chapter.
31+
32+
At the top of the C++ file, note the following variable:
33+
34+
[,c++]
35+
----
36+
#define LAB_TASK_LEVEL 1
37+
----
38+
39+
At certain intervals, you will be instructed to update this variable and re-build to verify the effect of key changes, no need to write new code.
40+
41+
=== Chapters in this series
42+
43+
- link:00_Overview.adoc[Overview]
44+
- link:01_Dynamic_rendering.adoc[Dynamic rendering]
45+
- link:02_Acceleration_structures.adoc[Acceleration structures]
46+
- link:03_Ray_query_shadows.adoc[Ray query shadows]
47+
- link:04_TLAS_animation.adoc[TLAS animation]
48+
- link:05_Bindless_resources.adoc[Bindless resources]
49+
- link:06_Shadow_transparency.adoc[Shadow transparency]
50+
- link:07_Reflections.adoc[Reflections]
51+
- link:08_Conclusion.adoc[Conclusion]
52+
53+
=== Build and Run
54+
55+
You can build and run the provided sample either from Visual Studio (set 38_ray_tracing as the start-up project) or via command line:
56+
57+
[,shell]
58+
----
59+
cmake --build build --target 38_ray_tracing --parallel; start .\build\38_ray_tracing\Debug\38_ray_tracing.exe -wo .\build\38_ray_tracing\
60+
----
61+
62+
Note that the above hasn't changed from the base tutorial, and you may continue to build on other platforms as you have for the rest of the tutorial.
63+
64+
=== Dynamic Rendering
65+
66+
This series uses modern Vulkan dynamic rendering. Please proceed to the dedicated chapter for details, code pointers, and RenderDoc verification.
67+
68+
- Next chapter: link:01_Dynamic_rendering.adoc[Dynamic rendering]
69+
70+
71+
72+
=== Navigation
73+
- Next: link:01_Dynamic_rendering.adoc[Dynamic rendering]
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
== Dynamic Rendering
2+
3+
Objective: Ensure the base project uses dynamic rendering and understand how to verify it using RenderDoc.
4+
5+
In dynamic rendering, we no longer create a VkRenderPass or VkFrameBuffer; instead we begin rendering with vkCmdBeginRenderingKHR, specifying attachments on-the-fly. This makes our code more flexible (no need to predeclare subpasses) and is now the "modern" way to render in Vulkan.
6+
7+
=== Task 1: Check the setup for dynamic rendering
8+
9+
[,c++]
10+
----
11+
/* TASK01: Check the setup for dynamic rendering */
12+
// See pipeline creation: vk::PipelineRenderingCreateInfo with .pNext chain
13+
----
14+
15+
In RenderDoc, verify you see the calls that confirm that dynamic rendering is set up correctly:
16+
17+
. vkCmdBeginRenderingKHR and vkCmdEndRenderingKHR.
18+
. VkRenderingInfoKHR which replaces the fixed framebuffer object.
19+
. Color attachment.
20+
21+
image::../../../images/38_TASK01_renderdoc_events.png[]
22+
image::../../../images/38_TASK01_renderdoc_color.gif[]
23+
24+
NOTE: Dynamic rendering reduces CPU overhead and, with VK_KHR_dynamic_rendering_local_read, lets you do subpass-style tile-local reads without full render passes. This is great for techniques like deferred shading on tilers.
25+
26+
27+
==== Dynamic rendering with RenderDoc
28+
29+
Let’s make sure you can actually see dynamic rendering at work in a capture, and also look at the key places in code.
30+
31+
How to capture with RenderDoc (Windows):
32+
33+
. Set Executable to your built sample, e.g. C:\\Users\\you\\Vulkan-Tutorial\\attachments\\build\\38_ray_tracing\\Debug\\38_ray_tracing.exe
34+
. Set Working Directory to the folder containing the executable, e.g. ...\\attachments\\build\\38_ray_tracing
35+
. Launch and capture a frame.
36+
37+
image::../../../images/38_TASK01_renderdoc_launch.png[]
38+
39+
In the Event Browser and API Inspector you should see:
40+
41+
- vkCmdBeginRenderingKHR / vkCmdEndRenderingKHR
42+
- VkRenderingInfoKHR replacing the old render pass/framebuffer concept
43+
- Color (and depth) attachments set via RenderingAttachmentInfo
44+
45+
The relevant code locations you can skim for orientation:
46+
47+
[,c++]
48+
----
49+
/* TASK01 (excerpt): dynamic rendering is enabled by linking
50+
* vk::PipelineRenderingCreateInfo in the pNext chain when creating the graphics pipeline.
51+
*/
52+
vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{
53+
.colorAttachmentCount = 1,
54+
.pColorAttachmentFormats = &swapChainImageFormat,
55+
.depthAttachmentFormat = depthFormat
56+
};
57+
58+
vk::GraphicsPipelineCreateInfo pipelineInfo{
59+
.pNext = &pipelineRenderingCreateInfo,
60+
// ... standard pipeline state setup omitted for brevity ...
61+
.layout = pipelineLayout,
62+
.renderPass = nullptr
63+
};
64+
----
65+
66+
And when recording the command buffer for a frame:
67+
68+
[,c++]
69+
----
70+
// These attachment infos replace subpass attachments in a legacy render pass
71+
vk::RenderingAttachmentInfo colorAttachmentInfo{
72+
.imageView = swapChainImageViews[imageIndex],
73+
.imageLayout = vk::ImageLayout::eColorAttachmentOptimal,
74+
.loadOp = vk::AttachmentLoadOp::eClear,
75+
.storeOp = vk::AttachmentStoreOp::eStore,
76+
.clearValue = clearColor
77+
};
78+
79+
vk::RenderingAttachmentInfo depthAttachmentInfo{
80+
.imageView = depthImageView,
81+
.imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal,
82+
.loadOp = vk::AttachmentLoadOp::eClear,
83+
.storeOp = vk::AttachmentStoreOp::eDontCare,
84+
.clearValue = clearDepth
85+
};
86+
87+
vk::RenderingInfo renderingInfo{
88+
.renderArea = { .offset = { 0, 0 }, .extent = swapChainExtent },
89+
.layerCount = 1,
90+
.colorAttachmentCount = 1,
91+
.pColorAttachments = &colorAttachmentInfo,
92+
.pDepthAttachment = &depthAttachmentInfo
93+
};
94+
95+
// vkCmdBeginRenderingKHR replaces vkCmdBeginRenderPass
96+
commandBuffer.beginRendering(renderingInfo);
97+
// ... draw calls ...
98+
commandBuffer.endRendering();
99+
----
100+
101+
That’s all there is to it. Dynamic rendering cuts out a lot of boilerplate and is the recommended path in modern Vulkan. It also pairs nicely with ray queries because you keep everything in a single raster pipeline.
102+
103+
104+
=== Navigation
105+
- Previous: link:00_Overview.adoc[Overview]
106+
- Next: link:02_Acceleration_structures.adoc[Acceleration structures]

0 commit comments

Comments
 (0)