NVIDIA Vulkan Ray Tracing

Mar. 9, 2020

Basics:

There is a detailed article of Nvidia to start learning raytracing. But here are some key points to consider:

  • Enable VK_NV_ray_tracing device extension.
  • Build Bottom Level Acceleration Structure- holding actual scene geometry and vertex data
  • Build Top Level Acceleration Structure- holding instance data and transformation matrix
  • Update a single set of descriptor set containing all necessary information to render a scene. Ex., all the material textures, acceleration structure, output image, vertex and index buffers, uniforms data
  • 3 Shaders: Ray Generation, Miss and Closest Hit
  • Create Shader Binding Table containing shader handles of the 3 shaders mentioned above
Here is my implementation to render a triangle.

Problems encountered:

  • RayTracingPipelineNV creation error.


    A programmer's nightmare: "This was a nullptr" or "Exception thrown: read access violation"
    Yes I've been there too more often than not! This took me quiet some time to understand and resolve.

    You see that for loop; I didn't explicitly assign initial values to every variables in shader stage info struct, so they were garbage. It's like Vulkan's moto: Be Explicit.
    Well this was a minor problem but it took a while to get here. More accurate: Initialize structs with {}.

    VkPipelineShaderStageCreateInfo shaderStages{};

  • Infamous black screen.
    You should know where to look at! I didn't.
    Initially I didn't implement a camera. So, I was putting origin for ray generation in shader vec3(0,0,0). And guess where my traingle was getting rendererd. Origin!

Contact Me