spirv-opt: Add OpExecutionModeId support (#4719)

Needed for Vulkan1.3 adding LocalSizeId support
This commit is contained in:
sfricke-samsung 2022-02-14 06:33:29 -08:00 committed by GitHub
parent 72e4475b41
commit 471428a04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -189,7 +189,8 @@ bool IrLoader::AddInstruction(const spv_parsed_instruction_t* inst) {
module_->SetMemoryModel(std::move(spv_inst)); module_->SetMemoryModel(std::move(spv_inst));
} else if (opcode == SpvOpEntryPoint) { } else if (opcode == SpvOpEntryPoint) {
module_->AddEntryPoint(std::move(spv_inst)); module_->AddEntryPoint(std::move(spv_inst));
} else if (opcode == SpvOpExecutionMode) { } else if (opcode == SpvOpExecutionMode ||
opcode == SpvOpExecutionModeId) {
module_->AddExecutionMode(std::move(spv_inst)); module_->AddExecutionMode(std::move(spv_inst));
} else if (IsDebug1Inst(opcode)) { } else if (IsDebug1Inst(opcode)) {
module_->AddDebug1Inst(std::move(spv_inst)); module_->AddDebug1Inst(std::move(spv_inst));

View File

@ -128,6 +128,51 @@ TEST_F(FreezeSpecConstantValueRemoveDecorationTest,
/* skip_nop = */ true); /* skip_nop = */ true);
} }
TEST_F(FreezeSpecConstantValueRemoveDecorationTest,
RemoveDecorationForLocalSizeIdWithSpecId) {
std::vector<const char*> text = {
// clang-format off
"OpCapability Shader",
"%1 = OpExtInstImport \"GLSL.std.450\"",
"OpMemoryModel Logical GLSL450",
"OpEntryPoint GLCompute %2 \"main\"",
"OpExecutionModeId %2 LocalSizeId %uint_32 %uint_1 %uint_1_0",
"OpSource GLSL 450",
"OpDecorate %3 SpecId 18",
"OpDecorate %5 SpecId 19",
"%void = OpTypeVoid",
"%9 = OpTypeFunction %void",
"%uint = OpTypeInt 32 0",
"%uint_32 = OpSpecConstant %uint 32",
"%uint_1 = OpConstant %uint 1",
"%uint_1_0 = OpSpecConstant %uint 1",
"%2 = OpFunction %void None %9",
"%11 = OpLabel",
"OpReturn",
"OpFunctionEnd",
// clang-format on
};
std::string expected_disassembly = SelectiveJoin(text, [](const char* line) {
return std::string(line).find("SpecId") != std::string::npos;
});
std::vector<std::pair<const char*, const char*>> replacement_pairs = {
{"%uint_32 = OpSpecConstant %uint 32", "%uint_32 = OpConstant %uint 32"},
{"%uint_1_0 = OpSpecConstant %uint 1", "%uint_1_0 = OpConstant %uint 1"},
};
for (auto& p : replacement_pairs) {
EXPECT_TRUE(FindAndReplace(&expected_disassembly, p.first, p.second))
<< "text:\n"
<< expected_disassembly << "\n"
<< "find_str:\n"
<< p.first << "\n"
<< "replace_str:\n"
<< p.second << "\n";
}
SinglePassRunAndCheck<FreezeSpecConstantValuePass>(JoinAllInsts(text),
expected_disassembly,
/* skip_nop = */ true);
}
} // namespace } // namespace
} // namespace opt } // namespace opt
} // namespace spvtools } // namespace spvtools