-
Notifications
You must be signed in to change notification settings - Fork 757
Add compute shader derivatives sample for Vulkan extension #1421
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
base: main
Are you sure you want to change the base?
Add compute shader derivatives sample for Vulkan extension #1421
Conversation
Introduce a sample demonstrating the `VK_KHR_compute_shader_derivatives` extension. Includes new shader, CMake, and Vulkan application files showcasing the use of derivative instructions in compute shaders with quad-based derivative groups.
| float v = data[idx * 4 + 0]; | ||
| float ddx = data[idx * 4 + 1]; | ||
| float ddy = data[idx * 4 + 2]; | ||
| LOGI("compute-derivatives CPU: tid=({}, {}) v={} ddx={} ddy={}", x, y, v, ddx, ddy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to display them in the app's GUI instead of simply outputting them to the terminal. Depending on how/where you run the sample you don't have direct access to the terminal.
- Store and format compute results for GUI display - Update README with GitHub repository link for sample
|
Again, not sure what I'm supposed to see here, but I'm getting the same weird random frames on the display as I saw with relaxed_extended_instruction and some console output: |
| add_instance_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); | ||
| // Device extension providing the feature | ||
| add_device_extension(VK_KHR_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME); | ||
| // Toolchains may still emit SPV_NV_compute_shader_derivatives; enable NV extension if available to satisfy validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we double-check this? Both Slang and DXC should support khr_compute_shader_derivatives.
It’s probably better not to request the NV extension, since if the shader is using SPV_NV_compute_shader_derivatives that would cause issues if a device supports the KHR extension but not the NV version.
We could add a comment suggesting users update their toolchain if they encounter this problem.
| void ComputeShaderDerivatives::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) | ||
| { | ||
| // Require quads derivative group (the sample shader uses layout(derivative_group_quadsNV/derivative_group_quads_khr)) | ||
| REQUEST_REQUIRED_FEATURE(gpu, VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR, computeDerivativeGroupQuads); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some implementations only support computeDerivativeGroupLinear. As a suggestion, could we add an example using computeDerivativeGroupLinear?
The mapping from a thread to 2D coordinates isn’t immediately obvious when using 1D quads or computeDerivativeGroupLinear, so it would be useful to have an example
https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Derivatives.html
Ideally, this sample could have two shader versions—derivatives_linear.comp and derivatives_quad.comp, both producing identical output with a toggle to alternate between both versions.
Also, as mentioned earlier, I think the sample would be clearer and more useful if we added a SampleGrad to use the derivatives.
Description
Introduce a sample demonstrating the
VK_KHR_compute_shader_derivativesextension. Includes new shader, CMake, and Vulkan application files showcasing the use of derivative instructions in compute shaders with quad-based derivative groups.General Checklist:
Please ensure the following points are checked:
Note: The Samples CI runs a number of checks including:
If this PR contains framework changes:
batchcommand line argument to make sure all samples still work properlySample Checklist
If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist: