Skip to content

Latest commit

 

History

History
46 lines (40 loc) · 2.69 KB

File metadata and controls

46 lines (40 loc) · 2.69 KB

VK_KHR_compute_shader_derivatives — Derivatives in compute shaders

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.

What is it?

  • SPIR-V: The companion SPIR-V extension allows derivative instructions in the Compute execution model.

  • Vulkan: The device feature is exposed via VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR with two booleans:

    • computeDerivativeGroupQuads — enables quad-based derivative groups.

    • computeDerivativeGroupLinear — enables linearly mapped derivative groups.

  • GLSL: Use #extension GL_KHR_compute_shader_derivatives : enable and a layout qualifier to choose the grouping:

    • layout(derivative_group_quadsNV) in;

    • layout(derivative_group_linearNV) in; (The NV suffix is retained in the GLSL tokens for compatibility.)

Why/when to use it

  • 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).

What this sample does

  • Requests and requires the feature computeDerivativeGroupQuads.

  • Builds a minimal compute pipeline with a shader that calls dFdx/dFdy in compute.

  • Runs a small per-frame command buffer that dispatches once and then transitions the swapchain image to PRESENT so presentation is validation-clean. The compute shader has no resource bindings; it exists to demonstrate that derivative instructions are accepted and execute in compute.

Required Vulkan extensions and features

  • Instance extension: VK_KHR_get_physical_device_properties2 (for feature chaining).

  • Device extension: VK_KHR_compute_shader_derivatives (required).

  • Device feature: VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR::computeDerivativeGroupQuads = VK_TRUE.