Skip to content

Commit

Permalink
[SPIRV] Stop running ReplaceInvalidOpcPass
Browse files Browse the repository at this point in the history
That pass was intended to remove derivative instructions used in
non-fragment shaders. Now they are available in more places because of
new extensions. In general,
it is better practice to issue an error if they are used in an place
they are not allowed.

Fixes #7086
  • Loading branch information
s-perron committed Feb 11, 2025
1 parent 99726f9 commit 6d18a40
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15218,7 +15218,6 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
optimizer.RegisterPass(
spvtools::CreateAggressiveDCEPass(spirvOptions.preserveInterface));
}
optimizer.RegisterPass(spvtools::CreateReplaceInvalidOpcodePass());
optimizer.RegisterPass(spvtools::CreateCompactIdsPass());
optimizer.RegisterPass(spvtools::CreateSpreadVolatileSemanticsPass());
if (spirvOptions.fixFuncCallArguments) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s --check-prefix=CHECK
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s --check-prefix=CHECK

// CHECK: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -19,4 +20,4 @@ void main(uint3 id : SV_GroupThreadID)
//CHECK-NEXT: [[query1:%[0-9]+]] = OpImageQueryLod %v2float [[si1]] %float_0_5
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query1]] 0
o[0] = t1.CalculateLevelOfDetail(ss, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -19,4 +20,4 @@ void main(uint3 id : SV_GroupThreadID)
//CHECK-NEXT: [[query1:%[0-9]+]] = OpImageQueryLod %v2float [[si1]] %float_0_5
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query1]] 0
o[0] = t1.CalculateLevelOfDetail(ss, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -19,4 +20,4 @@ void main(uint3 id : SV_GroupThreadID)
//CHECK-NEXT: [[query1:%[0-9]+]] = OpImageQueryLod %v2float [[si1]] %float_0_5
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query1]] 1
o[0] = t1.CalculateLevelOfDetailUnclamped(ss, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -19,4 +20,4 @@ void main(uint3 id : SV_GroupThreadID)
//CHECK-NEXT: [[query1:%[0-9]+]] = OpImageQueryLod %v2float [[si1]] %float_0_5
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query1]] 1
o[0] = t1.CalculateLevelOfDetailUnclamped(ss, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -18,4 +19,4 @@ void main(uint3 id : SV_GroupThreadID)
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[ss]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] %float_1 None
o[0] = t1.Sample(ss, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -18,4 +19,4 @@ void main(uint3 id : SV_GroupThreadID)
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[ss]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] %float_1 None
o[0] = t1.Sample(ss, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -13,9 +13,10 @@ Texture1D <float> t1;
[numthreads(8,1,1)]
void main(uint3 id : SV_GroupThreadID)
{
Texture1D<float> local_texture = t1;
// CHECK: [[t1:%[0-9]+]] = OpLoad %type_1d_image %t1
// CHECK-NEXT: [[ss:%[0-9]+]] = OpLoad %type_sampler %ss
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[ss]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] %float_1 Bias %float_0_5
o[0] = t1.SampleBias(ss, 1, 0.5);
}
o[0] = local_texture.SampleBias(ss, 1, 0.5);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -18,4 +19,4 @@ void main(uint3 id : SV_GroupThreadID)
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[ss]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleImplicitLod %v4float [[sampledImg]] %float_1 Bias %float_0_5
o[0] = t1.SampleBias(ss, 1, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -18,4 +19,4 @@ void main(uint3 id : SV_GroupThreadID)
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[scs]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleDrefImplicitLod %float [[sampledImg]] %float_1 %float_0_5
o[0] = t1.SampleCmp(scs, 1, 0.5);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives -fcgl %s -spirv 2>&1 | FileCheck %s
// RUN: %dxc -T cs_6_6 -E main -fspv-extension=SPV_NV_compute_shader_derivatives %s -spirv 2>&1 | FileCheck %s

// CHECK: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
Expand All @@ -18,4 +19,4 @@ void main(uint3 id : SV_GroupThreadID)
// CHECK-NEXT: [[sampledImg:%[0-9]+]] = OpSampledImage %type_sampled_image [[t1]] [[scs]]
// CHECK-NEXT: {{%[0-9]+}} = OpImageSampleDrefImplicitLod %float [[sampledImg]] %float_1 %float_0_5
o[0] = t1.SampleCmp(scs, 1, 0.5);
}
}

0 comments on commit 6d18a40

Please sign in to comment.