mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2025-01-14 02:10:17 +00:00
Reset the id bound on the module in compact ids (#4744)
If the body of the module does not have any ids change, compact ids will not change the id bound. This can cause problems because the id bound could be much higher than the largest id in that is used. It should be reset any time it is not the larger id used + 1. Fixes #4604
This commit is contained in:
parent
48a36c72e4
commit
0741f42738
@ -86,7 +86,8 @@ Pass::Status CompactIdsPass::Process() {
|
||||
},
|
||||
true);
|
||||
|
||||
if (modified) {
|
||||
if (context()->module()->id_bound() != result_id_mapping.size() + 1) {
|
||||
modified = true;
|
||||
context()->module()->SetIdBound(
|
||||
static_cast<uint32_t>(result_id_mapping.size() + 1));
|
||||
// There are ids in the feature manager that could now be invalid
|
||||
|
@ -310,6 +310,41 @@ OpFunctionEnd
|
||||
EXPECT_THAT(disassembly, ::testing::Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CompactIds, ResetIdBound) {
|
||||
const std::string input(R"(OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %1 "main"
|
||||
OpExecutionMode %1 OriginUpperLeft
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%1 = OpFunction %void None %3
|
||||
%4 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)");
|
||||
|
||||
spvtools::SpirvTools tools(SPV_ENV_UNIVERSAL_1_1);
|
||||
std::unique_ptr<IRContext> context =
|
||||
BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, input,
|
||||
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
||||
ASSERT_NE(context, nullptr);
|
||||
|
||||
CompactIdsPass compact_id_pass;
|
||||
context->module()->SetIdBound(20000);
|
||||
const auto status = compact_id_pass.Run(context.get());
|
||||
EXPECT_EQ(status, Pass::Status::SuccessWithChange);
|
||||
EXPECT_EQ(context->module()->id_bound(), 5);
|
||||
|
||||
// Test output just in case
|
||||
std::vector<uint32_t> binary;
|
||||
context->module()->ToBinary(&binary, false);
|
||||
std::string disassembly;
|
||||
tools.Disassemble(binary, &disassembly,
|
||||
SpirvTools::kDefaultDisassembleOption);
|
||||
|
||||
EXPECT_THAT(disassembly, ::testing::Eq(input));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user