Skip to content

Commit

Permalink
Add ComputeDerivativeGroup*NV capabilities to trim capabilities pass. (
Browse files Browse the repository at this point in the history
…#5430)

* Add ComputeDerivativeGroup*NV capabilities to trim capabilities pass.

* Add SPV_NV_compute_shader_derivatives to allow lists

No tests needed for this. The code path is well tested. Just adding new
data.
  • Loading branch information
s-perron authored Oct 16, 2023
1 parent 3985f0d commit 5bb5950
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
4 changes: 4 additions & 0 deletions source/opt/aggressive_dead_code_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ Pass::Status AggressiveDCEPass::Process() {

void AggressiveDCEPass::InitExtensions() {
extensions_allowlist_.clear();

// clang-format off
extensions_allowlist_.insert({
"SPV_AMD_shader_explicit_vertex_parameter",
"SPV_AMD_shader_trinary_minmax",
Expand Down Expand Up @@ -1001,7 +1003,9 @@ void AggressiveDCEPass::InitExtensions() {
"SPV_NV_bindless_texture",
"SPV_EXT_shader_atomic_float_add",
"SPV_EXT_fragment_shader_interlock",
"SPV_NV_compute_shader_derivatives"
});
// clang-format on
}

Instruction* AggressiveDCEPass::GetHeaderBranch(BasicBlock* blk) {
Expand Down
3 changes: 2 additions & 1 deletion source/opt/local_access_chain_convert_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ void LocalAccessChainConvertPass::InitExtensions() {
"SPV_KHR_uniform_group_instructions",
"SPV_KHR_fragment_shader_barycentric", "SPV_KHR_vulkan_memory_model",
"SPV_NV_bindless_texture", "SPV_EXT_shader_atomic_float_add",
"SPV_EXT_fragment_shader_interlock"});
"SPV_EXT_fragment_shader_interlock",
"SPV_NV_compute_shader_derivatives"});
}

bool LocalAccessChainConvertPass::AnyIndexIsOutOfBounds(
Expand Down
3 changes: 2 additions & 1 deletion source/opt/local_single_block_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
"SPV_KHR_vulkan_memory_model",
"SPV_NV_bindless_texture",
"SPV_EXT_shader_atomic_float_add",
"SPV_EXT_fragment_shader_interlock"});
"SPV_EXT_fragment_shader_interlock",
"SPV_NV_compute_shader_derivatives"});
}

} // namespace opt
Expand Down
3 changes: 2 additions & 1 deletion source/opt/local_single_store_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void LocalSingleStoreElimPass::InitExtensionAllowList() {
"SPV_KHR_vulkan_memory_model",
"SPV_NV_bindless_texture",
"SPV_EXT_shader_atomic_float_add",
"SPV_EXT_fragment_shader_interlock"});
"SPV_EXT_fragment_shader_interlock",
"SPV_NV_compute_shader_derivatives"});
}
bool LocalSingleStoreElimPass::ProcessVariable(Instruction* var_inst) {
std::vector<Instruction*> users;
Expand Down
4 changes: 3 additions & 1 deletion source/opt/trim_capabilities_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class TrimCapabilitiesPass : public Pass {
spv::Capability::StoragePushConstant16,
spv::Capability::StorageUniform16,
spv::Capability::StorageUniformBufferBlock16,
spv::Capability::ImageMSArray
spv::Capability::ImageMSArray,
spv::Capability::ComputeDerivativeGroupQuadsNV,
spv::Capability::ComputeDerivativeGroupLinearNV
// clang-format on
};

Expand Down
57 changes: 57 additions & 0 deletions test/opt/trim_capabilities_pass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ TEST_F(TrimCapabilitiesPassTest, CheckKnownAliasTransformations) {
OpCapability DotProductInput4x8BitKHR
OpCapability DotProductInput4x8BitPackedKHR
OpCapability DotProductKHR
OpCapability ComputeDerivativeGroupQuadsNV
OpCapability ComputeDerivativeGroupLinearNV
; CHECK: OpCapability Linkage
; CHECK-NOT: OpCapability StorageUniform16
; CHECK-NOT: OpCapability StorageUniformBufferBlock16
Expand All @@ -89,6 +91,8 @@ TEST_F(TrimCapabilitiesPassTest, CheckKnownAliasTransformations) {
; CHECK-NOT: OpCapability DotProductInput4x8BitKHR
; CHECK-NOT: OpCapability DotProductInput4x8BitPackedKHR
; CHECK-NOT: OpCapability DotProductKHR
; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsNV
; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearNV
; CHECK: OpCapability UniformAndStorageBuffer16BitAccess
; CHECK: OpCapability StorageBuffer16BitAccess
; CHECK: OpCapability ShaderViewportIndexLayerEXT
Expand Down Expand Up @@ -2129,6 +2133,59 @@ TEST_F(TrimCapabilitiesPassTest, Float64_RemainsWhenUsed) {
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
}

TEST_F(TrimCapabilitiesPassTest,
ComputeDerivativeGroupQuads_ReamainsWithExecMode) {
const std::string kTest = R"(
OpCapability ComputeDerivativeGroupQuadsNV
OpCapability ComputeDerivativeGroupLinearNV
; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearNV
; CHECK: OpCapability ComputeDerivativeGroupQuadsNV
; CHECK-NOT: OpCapability ComputeDerivativeGroupLinearNV
OpCapability Shader
; CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
OpExtension "SPV_NV_compute_shader_derivatives"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
OpExecutionMode %1 DerivativeGroupQuadsNV
%void = OpTypeVoid
%3 = OpTypeFunction %void
%1 = OpFunction %void None %3
%6 = OpLabel
OpReturn
OpFunctionEnd
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
}

TEST_F(TrimCapabilitiesPassTest,
ComputeDerivativeGroupLinear_ReamainsWithExecMode) {
const std::string kTest = R"(
OpCapability ComputeDerivativeGroupLinearNV
OpCapability ComputeDerivativeGroupQuadsNV
; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsNV
; CHECK: OpCapability ComputeDerivativeGroupLinearNV
; CHECK-NOT: OpCapability ComputeDerivativeGroupQuadsNV
OpCapability Shader
; CHECK: OpExtension "SPV_NV_compute_shader_derivatives"
OpExtension "SPV_NV_compute_shader_derivatives"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
OpExecutionMode %1 DerivativeGroupLinearNV
%void = OpTypeVoid
%float = OpTypeFloat 64
%3 = OpTypeFunction %void
%1 = OpFunction %void None %3
%6 = OpLabel
OpReturn
OpFunctionEnd
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
}

} // namespace
} // namespace opt
} // namespace spvtools

0 comments on commit 5bb5950

Please sign in to comment.