-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ray Tracing Pipeline (NV and KHR extensions) #1350
base: master
Are you sure you want to change the base?
Conversation
3eba233
to
87701eb
Compare
acadd57
to
16a5305
Compare
Refactor write entry point to later support raytracing class of execution models. KhronosGroup/SPIRV-Headers@0350b1d KhronosGroup/SPIRV-Headers@95b48ce
Add shader_device_address Add transform_feedback_buffer Add transform_feedback_counter_buffer Add conditional_rendering Add ray_tracing
Chain `PhysicalDeviceRayTracingPropertiesKHR` and `PhysicalDeviceRayTracingPropertiesNV` in `PhysicalDeviceProperties2KHR` in order to retrieve the same data from two different extensions if they are available. In the case both are unavailable the values are 0. In the case of one or both extensions being supported, grab the maximum, overwriting the 0s in the case of one of both unsupported and reconciling both properties if they are available. One exception is the property `shaderGroupHandleCaptureReplaySize` which is not available in the nvidia ray tracing extension.
Use storage buffer for AABBs. Make procedural geometry using ray marching for a signed distance function.
@bwrsandman Any updates regarding the progress on this feature? It's hard to find volunteers to help with development unfortunately, but the feature would be definitely very beneficial for Vulkano infrastructure. |
I haven't progressed as I require a bit of help / review on the the mentioned points. |
This is something I would like to help with, but I don't have drivers that support these extensions, so I can only write code, I can't do any testing. Since this is such a huge package of changes, I think it may be better to implement it in smaller PRs one at a time. That is, add the smaller pieces first, maybe one PR per extension, even if they are initially useless. Then at the end you implement the main extension that ties it all together. That avoids the current situation where a large amount of work is tied up in a PR without going anywhere. Some of the points you raised have been solved since you started this PR:
|
The KHR extension has wide enough adoption that it's wasteful to support NV, unless you wish to use Vulkano on one specific ancient Nvidia driver. The semantics changed a bit in some key areas, too. |
Good to know. I hope to have some time in the coming weeks to do as you suggested. |
Hello 👋 I'm trying to rewrite the acceleration structure to work with new versions of vulkano. If someone is also doing this, let's discuss |
Hey, I have created a PR with an acceleration structure draft #1736 |
What way should raytracing pipelines be implemented considering the infinite amount of shaders that can be attached? |
I'm planning to rework |
CHANGELOG_VULKANO.md
orCHANGELOG_VK_SYS.md
if knowledge of this change could be valuable to usersI'm proposing these additions to vulkano. I'm setting as draft because I would like some help/feedback. I'm fairly new to Rust and there may be some tricks I don't know about.
There are five main parts to this addition (I also fixed compute shader to swapchain storage image):
Extension
There are two extensions which allow ray tracing:
khr_ray_tracing
andnv_ray_tracing
.The NV extension is likely only available with select NVidia cards. I have a 1070 which supports this on Linux so it is not specifically limited to the RTX line of cards.
The KHR extension is newer and should have wider adoption in the future. As it is now, for NVidia, it requires a beta driver to test. I have not finished implementing this.
The two extensions differ slightly but I wrapped builders to have a unique API. This is done with a
bool
but maybe it could be better with a Generics.Ray Tracing Pipeline
This is different from both Compute and Graphics pipeline.
There can be multiple stages of the Ray Tracing Pipelines of the same type, for example, there can be two miss shaders.
Additionally, there is a concept of shader groups. Ray Generation, Miss and Execution Shaders are alone in their vulkan groups. Actual groups include optional Closest Hit, Any Hit and Intersection Shaders. There can be more than one of these groups.
If a group has an Intersection Shader, the geometry is procedural, otherwise, the geometry should be triangles. This automatically handled in this PR.
This has been challenging to me as I don't know of a way to make variable length generics or to wrap the builder stages in traits. It would be nice to have help here.
In the sample, I create procedural geometry and I would like to add a triangle group but this requires a solution to the variable length of generics.
Note that shaderc links to an old version of glslang which does not support
GL_EXT_ray_tracing
. For this reason, I did not finish implementing the khr side of the implementation.Acceleration Structures
To ray trace, the pipeline must have access to the full scene in the trace command. Vulkan offers acceleration structures (a bounding volume hiearchy of axis-aligned bounding boxes) to quickly traverse the geometry (bounding boxes for procedural geometry or triangles).
For one scene representation, Vulkan offers multiple bottom level acceleration structure for different meshes and only one top level acceleration structure to group them.
A static scene only needs to be built once but a dynamic scene requires a rebuild with the
build_acceleration_structure
command at each change.In this PR,
AccelerationStructureBuilder
automatically creates the top level acceleration structure and all lower level structure created withadd_aabbs
for procedural geometry andadd_triangles
for triangle meshes.The structure requires memory for storage and a scratch buffer for rebuilding.
Adding triangles is not yet implemented.
Shader Binding Tables
The shader binding table is a pointer list the shaders use to call each other.
In this PR, the table has to be built and uploaded in a buffer manually, but it might be possible to do this automatically in the pipeline. Different
trace
calls can use different tables and offsets.nv-ray-tracing example
Help needed
I need some assistance on the following points:
StorageClass
entries require eitherkhr_ray_tracing
ornv_ray_tracing
. As far as I can tell, there is no way to create a requirement which is satisfied by one extension OR another.AcclereationStructureAccess
trait be added?nv_ray_tracing
andkhr_ray_tracing
extensions.VK_KHR_ray_tracing
requires other extenions:VK_EXT_descriptor_indexing
,VK_KHR_buffer_device_address
,VK_KHR_deferred_host_operations
,VK_KHR_pipeline_library
. Should vulkano add those to the list ifDeviceExtensions::khr_ray_tracing
is enabled?khr_ray_tracing
requires enablingvk::PhysicalDeviceRayTracingFeaturesKHR::rayTracing
andvk::PhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress
by passing the structs in apNext
chain in avk::PhysicalDeviceFeatures2
forvk::DeviceCreateInfo.pNext
and forvk::GetPhysicalDeviceFeatures2
. The current set-up does not allow this to be done easily fromcodegen.rs
or the instance builder.features::Features
needs to be expanded to support these other features.NV
andKHR
implementation than myuse_nv_extension bool
check at runtime?vk::MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR
inpNext
when attached to a buffer created withvk::BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_KHR
which is used in thekhr_ray_tracing
implementation for the Acceleration Structures.