linker: merge debug annotations from category c)

Fixes: https://github.com/KhronosGroup/SPIRV-Tools/issues/1218
This commit is contained in:
Pierre Moreau 2018-02-14 19:12:05 +01:00 committed by David Neto
parent bdd6617faa
commit 9394272c98
3 changed files with 30 additions and 3 deletions

View File

@ -447,6 +447,24 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
linked_module->AddDebug2Inst(
std::unique_ptr<Instruction>(inst.Clone(linked_context)));
for (const auto& module : input_modules)
for (const auto& inst : module->debugs3())
linked_module->AddDebug3Inst(
std::unique_ptr<Instruction>(inst.Clone(linked_context)));
// If the generated module uses SPIR-V 1.1 or higher, add an
// OpModuleProcessed instruction about the linking step.
if (linked_module->version() >= 0x10100) {
const std::string processed_string("Linked by SPIR-V Tools Linker");
const size_t words_nb =
processed_string.size() / 4u + (processed_string.size() % 4u != 0u);
std::vector<uint32_t> processed_words(words_nb, 0u);
std::memcpy(processed_words.data(), processed_string.data(), words_nb * 4u);
linked_module->AddDebug3Inst(std::unique_ptr<Instruction>(
new Instruction(linked_context, SpvOpModuleProcessed, 0u, 0u,
{{SPV_OPERAND_TYPE_LITERAL_STRING, processed_words}})));
}
for (const auto& module : input_modules)
for (const auto& inst : module->annotations())
linked_module->AddAnnotationInst(

View File

@ -40,7 +40,9 @@ OpDecorate %1 LinkageAttributes "foo" Export
EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
<< GetErrorMessage();
const std::string expected_res = R"(%1 = OpTypeFloat 32
const std::string expected_res =
R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
%1 = OpTypeFloat 32
%2 = OpVariable %1 Input
%3 = OpConstant %1 42
%4 = OpVariable %1 Uniform %3
@ -64,7 +66,9 @@ OpDecorate %1 LinkageAttributes "foo" Export
EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body}, &linked_binary))
<< GetErrorMessage();
const std::string expected_res = R"(%1 = OpTypeFloat 32
const std::string expected_res =
R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
%1 = OpTypeFloat 32
%2 = OpVariable %1 Uniform
)";
std::string res_body;
@ -89,6 +93,7 @@ OpDecorate %1 LinkageAttributes "foo" Export
<< GetErrorMessage();
const std::string expected_res = R"(OpCapability Linkage
OpModuleProcessed "Linked by SPIR-V Tools Linker"
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform
@ -267,6 +272,7 @@ OpFunctionEnd
<< GetErrorMessage();
const std::string expected_res = R"(OpCapability Kernel
OpModuleProcessed "Linked by SPIR-V Tools Linker"
OpDecorate %1 FuncParamAttr Sext
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
@ -310,7 +316,9 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, AssembleAndLink({body1, body2}, &linked_binary))
<< GetErrorMessage();
const std::string expected_res = R"(%1 = OpTypeVoid
const std::string expected_res =
R"(OpModuleProcessed "Linked by SPIR-V Tools Linker"
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpTypeFloat 32
%4 = OpVariable %3 Uniform

View File

@ -44,6 +44,7 @@ OpDecorate %1 LinkageAttributes "bar" Export
AssembleAndLink({body1, body2}, &linked_binary, linker_options));
const std::string expected_res = R"(OpCapability Linkage
OpModuleProcessed "Linked by SPIR-V Tools Linker"
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform