Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: add PhysicalStorageBufferAddresses to trim #5476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions source/opt/trim_capabilities_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ class TrimCapabilitiesPass : public Pass {
// contains unsupported instruction, the pass could yield bad results.
static constexpr std::array kSupportedCapabilities{
// clang-format off
spv::Capability::ComputeDerivativeGroupLinearNV,
spv::Capability::ComputeDerivativeGroupQuadsNV,
spv::Capability::Float64,
spv::Capability::FragmentShaderPixelInterlockEXT,
spv::Capability::FragmentShaderSampleInterlockEXT,
spv::Capability::FragmentShaderShadingRateInterlockEXT,
spv::Capability::Groups,
spv::Capability::ImageMSArray,
spv::Capability::Int64,
spv::Capability::Linkage,
spv::Capability::MinLod,
spv::Capability::PhysicalStorageBufferAddresses,
spv::Capability::RayQueryKHR,
spv::Capability::RayTracingKHR,
spv::Capability::RayTraversalPrimitiveCullingKHR,
Expand All @@ -91,10 +95,7 @@ class TrimCapabilitiesPass : public Pass {
spv::Capability::StorageInputOutput16,
spv::Capability::StoragePushConstant16,
spv::Capability::StorageUniform16,
spv::Capability::StorageUniformBufferBlock16,
spv::Capability::ImageMSArray,
spv::Capability::ComputeDerivativeGroupQuadsNV,
spv::Capability::ComputeDerivativeGroupLinearNV
spv::Capability::StorageUniformBufferBlock16
// clang-format on
};

Expand Down
120 changes: 120 additions & 0 deletions test/opt/trim_capabilities_pass_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,126 @@ TEST_F(TrimCapabilitiesPassTest,
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
}

TEST_F(TrimCapabilitiesPassTest, PhysicalStorageBuffer_RemovedWhenUnused) {
const std::string kTest = R"(
OpCapability PhysicalStorageBufferAddresses
; CHECK-NOT: OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
%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,
PhysicalStorageBuffer_RemainsWithOpTypeForwardPointer) {
const std::string kTest = R"(
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 2 4
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
OpTypeForwardPointer %ptr PhysicalStorageBuffer
%ptr = OpTypePointer PhysicalStorageBuffer %struct
%3 = OpTypeFunction %void
%main = 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::SuccessWithoutChange);
}

TEST_F(TrimCapabilitiesPassTest,
PhysicalStorageBuffer_RemainsWithPhysicalStorageBufferStorage) {
const std::string kTest = R"(
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 2 4
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%ptr = OpTypePointer PhysicalStorageBuffer %struct
%3 = OpTypeFunction %void
%main = 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::SuccessWithoutChange);
}

TEST_F(TrimCapabilitiesPassTest,
PhysicalStorageBuffer_RemainsWithRestrictDecoration) {
const std::string kTest = R"(
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 2 4
OpDecorate %var RestrictPointer
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%ptr = OpTypePointer Function %struct
%3 = OpTypeFunction %void
%main = OpFunction %void None %3
%6 = OpLabel
%var = OpVariable %ptr Function
OpReturn
OpFunctionEnd;
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
}

TEST_F(TrimCapabilitiesPassTest,
PhysicalStorageBuffer_RemainsWithAliasedDecoration) {
const std::string kTest = R"(
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 2 4
OpDecorate %var AliasedPointer
%void = OpTypeVoid
%int = OpTypeInt 32 0
%struct = OpTypeStruct %int
%ptr = OpTypePointer Function %struct
%3 = OpTypeFunction %void
%main = OpFunction %void None %3
%6 = OpLabel
%var = OpVariable %ptr Function
OpReturn
OpFunctionEnd;
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
}

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