Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
* Formatting
* Fix invalid fuzzer transforms
  • Loading branch information
alan-baker committed Apr 11, 2024
1 parent 565d2db commit 5be97c9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
5 changes: 5 additions & 0 deletions source/fuzz/transformation_add_no_contraction_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ bool TransformationAddNoContractionDecoration::IsApplicable(
if (!instr) {
return false;
}
// |instr| must not be decorated with NoContraction.
if (ir_context->get_decoration_mgr()->HasDecoration(
message_.result_id(), spv::Decoration::NoContraction)) {
return false;
}
// The instruction must be arithmetic.
return IsArithmetic(instr->opcode());
}
Expand Down
6 changes: 6 additions & 0 deletions source/fuzz/transformation_add_relaxed_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ bool TransformationAddRelaxedDecoration::IsApplicable(
if (!instr) {
return false;
}
// |instr| must not be decorated with RelaxedPrecision.
if (ir_context->get_decoration_mgr()->HasDecoration(
message_.result_id(), spv::Decoration::RelaxedPrecision)) {
return false;
}
opt::BasicBlock* cur_block = ir_context->get_instr_block(instr);
// The instruction must have a block.
if (cur_block == nullptr) {
Expand All @@ -46,6 +51,7 @@ bool TransformationAddRelaxedDecoration::IsApplicable(
cur_block->id()))) {
return false;
}

// The instruction must be numeric.
return IsNumeric(instr->opcode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ TEST(TransformationAddNoContractionDecorationTest, BasicScenarios) {
OpName %8 "x"
OpName %10 "y"
OpName %14 "i"
OpDecorate %32 NoContraction
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
Expand Down Expand Up @@ -110,9 +109,8 @@ TEST(TransformationAddNoContractionDecorationTest, BasicScenarios) {
ASSERT_FALSE(TransformationAddNoContractionDecoration(24).IsApplicable(
context.get(), transformation_context));

// It is valid to add NoContraction to each of these ids (and it's fine to
// have duplicates of the decoration, in the case of 32).
for (uint32_t result_id : {32u, 32u, 27u, 29u, 39u}) {
// It is valid to add NoContraction to each of these ids.
for (uint32_t result_id : {32u, 27u, 29u, 39u}) {
TransformationAddNoContractionDecoration transformation(result_id);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
Expand All @@ -134,8 +132,6 @@ TEST(TransformationAddNoContractionDecorationTest, BasicScenarios) {
OpName %10 "y"
OpName %14 "i"
OpDecorate %32 NoContraction
OpDecorate %32 NoContraction
OpDecorate %32 NoContraction
OpDecorate %27 NoContraction
OpDecorate %29 NoContraction
OpDecorate %39 NoContraction
Expand Down
6 changes: 2 additions & 4 deletions test/fuzz/transformation_add_relaxed_decoration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ TEST(TransformationAddRelaxedDecorationTest, BasicScenarios) {
// Invalid: 28 is in a dead block, but returns bool (not numeric).
ASSERT_FALSE(TransformationAddRelaxedDecoration(28).IsApplicable(
context.get(), transformation_context));
// It is valid to add RelaxedPrecision to 25 (and it's fine to
// have a duplicate).
for (uint32_t result_id : {25u, 25u}) {
// It is valid to add RelaxedPrecision to 25
for (uint32_t result_id : {25u}) {
TransformationAddRelaxedDecoration transformation(result_id);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
Expand All @@ -110,7 +109,6 @@ TEST(TransformationAddRelaxedDecorationTest, BasicScenarios) {
OpName %10 "b"
OpName %14 "c"
OpDecorate %25 RelaxedPrecision
OpDecorate %25 RelaxedPrecision
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeInt 32 1
Expand Down
15 changes: 9 additions & 6 deletions test/val/val_interfaces_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ OpFunctionEnd

CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("decorated with Location multiple times is not allowed"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("decorated with Location multiple times is not allowed"));
}

TEST_F(ValidateInterfacesTest, VulkanLocationsVariableAndMemberAssigned) {
Expand Down Expand Up @@ -506,8 +507,9 @@ OpFunctionEnd

CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("decorated with Location multiple times is not allowed"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("decorated with Location multiple times is not allowed"));
}

TEST_F(ValidateInterfacesTest, VulkanLocationsMissingAssignmentStructMember) {
Expand Down Expand Up @@ -1158,8 +1160,9 @@ OpFunctionEnd

CompileSuccessfully(text, SPV_ENV_VULKAN_1_0);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("decorated with Component multiple times is not allowed"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("decorated with Component multiple times is not allowed"));
}

TEST_F(ValidateInterfacesTest,
Expand Down
18 changes: 12 additions & 6 deletions test/val/val_modes_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,10 @@ OpExtension "SPV_KHR_float_controls"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpExecutionMode %main )" + mode + R"( 16
OpExecutionMode %main )" + mode + R"( 32
OpExecutionMode %main )" + mode +
R"( 16
OpExecutionMode %main )" + mode +
R"( 32
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand All @@ -1069,8 +1071,10 @@ OpExtension "SPV_KHR_float_controls"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpExecutionMode %main )" + mode + R"( 32
OpExecutionMode %main )" + mode + R"( 32
OpExecutionMode %main )" + mode +
R"( 32
OpExecutionMode %main )" + mode +
R"( 32
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down Expand Up @@ -1101,8 +1105,10 @@ OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpExecutionMode %main )" + mode + R"(
OpExecutionMode %main )" + mode + R"(
OpExecutionMode %main )" + mode +
R"(
OpExecutionMode %main )" + mode +
R"(
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
Expand Down

0 comments on commit 5be97c9

Please sign in to comment.