MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / TEST

Function TEST

test/opt/compact_ids_test.cpp:130–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130TEST(CompactIds, InstructionResultIsUpdated) {
131 // For https://github.com/KhronosGroup/SPIRV-Tools/issues/827
132 // In that bug, the compact Ids pass was directly updating the result Id
133 // word for an OpFunction instruction, but not updating the cached
134 // result_id_ in that Instruction object.
135 //
136 // This test is a bit cheesy. We don't expose internal interfaces enough
137 // to see the inconsistency. So reproduce the original scenario, with
138 // compact ids followed by a pass that trips up on the inconsistency.
139
140 const std::string input(R"(OpCapability Shader
141OpMemoryModel Logical Simple
142OpEntryPoint GLCompute %100 "main"
143%200 = OpTypeVoid
144%300 = OpTypeFunction %200
145%100 = OpFunction %200 None %300
146%400 = OpLabel
147OpReturn
148OpFunctionEnd
149)");
150
151 std::vector<uint32_t> binary;
152 const spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
153 spvtools::SpirvTools tools(env);
154 auto assembled = tools.Assemble(
155 input, &binary, SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
156 EXPECT_TRUE(assembled);
157
158 spvtools::Optimizer optimizer(env);
159 optimizer.RegisterPass(CreateCompactIdsPass());
160 // The exhaustive inliner will use the result_id
161 optimizer.RegisterPass(CreateInlineExhaustivePass());
162
163 // This should not crash!
164 optimizer.Run(binary.data(), binary.size(), &binary);
165
166 std::string disassembly;
167 tools.Disassemble(binary, &disassembly, SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
168
169 const std::string expected(R"(OpCapability Shader
170OpMemoryModel Logical Simple
171OpEntryPoint GLCompute %1 "main"
172%2 = OpTypeVoid
173%3 = OpTypeFunction %2
174%1 = OpFunction %2 None %3
175%4 = OpLabel
176OpReturn
177OpFunctionEnd
178)");
179
180 EXPECT_THAT(disassembly, ::testing::Eq(expected));
181}
182
183TEST(CompactIds, HeaderIsUpdated) {
184 const std::string input(R"(OpCapability Shader

Callers

nothing calls this directly

Calls 15

CreateCompactIdsPassFunction · 0.85
BuildInvalidAnalysesMethod · 0.80
getMethod · 0.80
IsConsistentMethod · 0.80
SetIdBoundMethod · 0.80
id_boundMethod · 0.80
BuildModuleFunction · 0.70
AssembleMethod · 0.45
RunMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected