Skip to content

Commit 999eb5f

Browse files
Allow no derivative layout for SPV_NV_compute_shader_derivatives (KhronosGroup#6678)
While adding glslang support for GL_KHR_compute_shader_derivatives I ran into some compatibility issues with the prior NV version of this extension. The KHR SPIR-V spec differs from the NV version in that is requires one of the DerivativeGroup*KHR modes to be set, while the NV spec says they don't need to be specified: > DerivativeGroup*NV execution mode that was specified for the entry point. If neither derivative group mode was specified, the derivatives return zero. (From https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/NV/SPV_NV_compute_shader_derivatives.asciidoc) The issue raised in KhronosGroup/glslang#4239 shows that there are GLSL shaders using the NV extension that assume that the modes don't have to be set. I modified glslang to allow this behavior for the NV extension in KhronosGroup/glslang#4247, but the generated SPIR-V fails validation. -- For this PR, I've made the execution mode check dependent on the KHR extension. (The execution and capability tokens are aliased between the KHR and NV extensions.) That change caused a unit test regression. AFAICT, that test has never been valid since it uses explicit derivatives in a compute shader without enabling any extensions. I turned that into a test for the KHR extension.
1 parent 6337eb6 commit 999eb5f

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

source/val/validate_derivatives.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ spv_result_t DerivativesPass(ValidationState_t& _, const Instruction* inst) {
9191
models->end() ||
9292
models->find(spv::ExecutionModel::MeshEXT) != models->end() ||
9393
models->find(spv::ExecutionModel::TaskEXT) != models->end()) &&
94+
(state.HasExtension(kSPV_KHR_compute_shader_derivatives)) &&
9495
(!modes ||
9596
(modes->find(spv::ExecutionMode::DerivativeGroupLinearKHR) ==
9697
modes->end() &&

test/val/val_derivatives_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ TEST_F(ValidateDerivatives, OpDPdxWrongExecutionModel) {
163163
TEST_F(ValidateDerivatives, NoExecutionModeGLCompute) {
164164
const std::string spirv = R"(
165165
OpCapability Shader
166+
OpCapability ComputeDerivativeGroupQuadsKHR
167+
OpExtension "SPV_KHR_compute_shader_derivatives"
166168
OpMemoryModel Logical GLSL450
167169
OpEntryPoint GLCompute %main "main"
168170
%void = OpTypeVoid

0 commit comments

Comments
 (0)