QuadDerivativesKHR

Hello, in Vulkan Spec Document,

A derivative group in a fragment shader is equivalent to the quad scope instance if the
QuadDerivativesKHR execution mode is specified, otherwise it is equivalent to the primitive scope
instance. A derivative group in a mesh, task, or compute shader is equivalent to the quad scope
instance.

-=-=-=-=-=-=-=

But, there is no specification of QuadDerivativesKHR execution mode

And below that, it is written
Derivative operations calculate their results as the difference between the result of P across
invocations in the quad

So, this says derivation is performed on the quad

=-=–=-=-=-=

May I ask

Where QuadDerivativesKHR execution mode is specified?

Copilot says, in fragment shader, quad scope instance is default derivative group in fragment shader. But the statements above (Vulkan Spec Document) say, primtive scope instance is default for fragment shader

Which is correct?

Thank you

Execution modes are specified in the SPIR-V specification - it’s specified by the shader not the API runtime.

Yes, fragment derivatives are always calculated based on quads.

The language here is subtle and is really about defining the size of the “derivative group”, which in turn defines where a shader can safely use derivative operations. The following in the spec defines the rules here - but it’s basically a requirement that shader control flow is uniform across the derivative group, and quad-based execution mode gives a more fine-grained sizing.

1 Like

Hello, Peter
The Spec Document says, if no QuadDerivativesKHR is specified, fragment shader uses primitive scope instance, which made me so confusing, and actually in fragment shader spvasm file, there is no QuadDerivativesKHR keyword inside.

However, it is also written that Derivative operations calculate their results as the difference between the result of P across invocations in the quad

So, I will assume fragment derivatives are simply based on quad, as you said

Thank you for your kindness and see you, Peter