mirror of
https://gitee.com/openharmony/third_party_spirv-tools
synced 2024-11-27 09:32:08 +00:00
reflect debug (#4662)
The pass to remove the nonsemantic information and instructions is used for drivers or tools that may not support them. Debug information was only partially handle, which is causing a problem. We need to either fully remove debug information or not remove it all. Since I can see it being useful to keep the debug information even when the nonsemantic instructions are removed, I propose we do not remove debug info. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4269
This commit is contained in:
parent
354a46a2a2
commit
b7251d4fb7
@ -76,13 +76,6 @@ Pass::Status StripNonSemanticInfoPass::Process() {
|
||||
}
|
||||
}
|
||||
|
||||
// clear all debug data now if it hasn't been cleared already, to remove any
|
||||
// remaining OpString that may have been referenced by non-semantic extinsts
|
||||
for (auto& dbg : context()->debugs1()) to_remove.push_back(&dbg);
|
||||
for (auto& dbg : context()->debugs2()) to_remove.push_back(&dbg);
|
||||
for (auto& dbg : context()->debugs3()) to_remove.push_back(&dbg);
|
||||
for (auto& dbg : context()->ext_inst_debuginfo()) to_remove.push_back(&dbg);
|
||||
|
||||
// remove any extended inst imports that are non semantic
|
||||
std::unordered_set<uint32_t> non_semantic_sets;
|
||||
for (auto& inst : context()->module()->ext_inst_imports()) {
|
||||
@ -106,19 +99,10 @@ Pass::Status StripNonSemanticInfoPass::Process() {
|
||||
to_remove.push_back(inst);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
// OpName must come first, since they may refer to other debug instructions.
|
||||
// If they are after the instructions that refer to, then they will be killed
|
||||
// when that instruction is killed, which will lead to a double kill.
|
||||
std::sort(to_remove.begin(), to_remove.end(),
|
||||
[](Instruction* lhs, Instruction* rhs) -> bool {
|
||||
if (lhs->opcode() == SpvOpName && rhs->opcode() != SpvOpName)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
for (auto* inst : to_remove) {
|
||||
modified = true;
|
||||
context()->KillInst(inst);
|
||||
|
@ -224,6 +224,73 @@ OpFunctionEnd
|
||||
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
|
||||
}
|
||||
|
||||
// Make sure that strip reflect does not remove the debug info (OpString and
|
||||
// OpLine).
|
||||
TEST_F(StripNonSemanticInfoTest, DontStripDebug) {
|
||||
std::string text = R"(OpCapability Shader
|
||||
OpMemoryModel Logical Simple
|
||||
OpEntryPoint Fragment %1 "main"
|
||||
OpExecutionMode %1 OriginUpperLeft
|
||||
%2 = OpString "file"
|
||||
%void = OpTypeVoid
|
||||
%4 = OpTypeFunction %void
|
||||
%1 = OpFunction %void None %4
|
||||
%5 = OpLabel
|
||||
OpLine %2 1 1
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
SinglePassRunAndCheck<StripNonSemanticInfoPass>(text, text, false);
|
||||
}
|
||||
|
||||
TEST_F(StripNonSemanticInfoTest, RemovedNonSemanticDebugInfo) {
|
||||
const std::string text = R"(
|
||||
;CHECK-NOT: OpExtension "SPV_KHR_non_semantic_info
|
||||
;CHECK-NOT: OpExtInstImport "NonSemantic.Shader.DebugInfo.100
|
||||
;CHECK-NOT: OpExtInst %void {{%\w+}} DebugSource
|
||||
;CHECK-NOT: OpExtInst %void {{%\w+}} DebugLine
|
||||
OpCapability Shader
|
||||
OpExtension "SPV_KHR_non_semantic_info"
|
||||
%1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %PSMain "PSMain" %in_var_COLOR %out_var_SV_TARGET
|
||||
OpExecutionMode %PSMain OriginUpperLeft
|
||||
%5 = OpString "t.hlsl"
|
||||
%6 = OpString "float"
|
||||
%7 = OpString "color"
|
||||
%8 = OpString "PSInput"
|
||||
%9 = OpString "PSMain"
|
||||
%10 = OpString ""
|
||||
%11 = OpString "input"
|
||||
OpName %in_var_COLOR "in.var.COLOR"
|
||||
OpName %out_var_SV_TARGET "out.var.SV_TARGET"
|
||||
OpName %PSMain "PSMain"
|
||||
OpDecorate %in_var_COLOR Location 0
|
||||
OpDecorate %out_var_SV_TARGET Location 0
|
||||
%uint = OpTypeInt 32 0
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%_ptr_Input_v4float = OpTypePointer Input %v4float
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%void = OpTypeVoid
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%uint_9 = OpConstant %uint 9
|
||||
%21 = OpTypeFunction %void
|
||||
%in_var_COLOR = OpVariable %_ptr_Input_v4float Input
|
||||
%out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
|
||||
%13 = OpExtInst %void %1 DebugSource %5
|
||||
%PSMain = OpFunction %void None %21
|
||||
%22 = OpLabel
|
||||
%23 = OpLoad %v4float %in_var_COLOR
|
||||
OpStore %out_var_SV_TARGET %23
|
||||
%24 = OpExtInst %void %1 DebugLine %13 %uint_9 %uint_9 %uint_1 %uint_1
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
SinglePassRunAndMatch<StripNonSemanticInfoPass>(text, true);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user