Skip to content

Commit

Permalink
Add tests for trimming pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron committed Oct 6, 2023
1 parent 3f588c6 commit 2ce1c1f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 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,56 @@ 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
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
OpExecutionMode %1 DerivativeGroupQuadsNV
%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);
}

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
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 2ce1c1f

Please sign in to comment.