This sample demonstrates VK_KHR_compute_shader_derivatives, which enables the use of derivative instructions (like dFdx/dFdy) inside compute shaders. Traditionally, derivatives are only available in fragment shaders, but this extension defines derivative groups in compute and how invocations are paired for derivative computations.
-
SPIR-V: The companion SPIR-V extension allows derivative instructions in the Compute execution model.
-
Vulkan: The device feature is exposed via
VkPhysicalDeviceComputeShaderDerivativesFeaturesKHRwith two booleans:-
computeDerivativeGroupQuads— enables quad-based derivative groups. -
computeDerivativeGroupLinear— enables linearly mapped derivative groups.
-
-
GLSL: Use
#extension GL_KHR_compute_shader_derivatives : enableand a layout qualifier to choose the grouping:-
layout(derivative_group_quadsNV) in; -
layout(derivative_group_linearNV) in;(TheNVsuffix is retained in the GLSL tokens for compatibility.)
-
-
Port algorithms that rely on derivatives (e.g., LOD selection, filtering, gradients) to compute for flexibility or performance.
-
Keep consistent behavior with fragment-stage derivatives by choosing an appropriate grouping mode (quads vs. linear).
-
Requests and requires the feature
computeDerivativeGroupQuads. -
Builds a minimal compute pipeline with a shader that calls
dFdx/dFdyin compute. -
Runs a small per-frame command buffer that dispatches once and then transitions the swapchain image to
PRESENTso presentation is validation-clean. The compute shader has no resource bindings; it exists to demonstrate that derivative instructions are accepted and execute in compute.