Skip to content

Commit

Permalink
opt: keep all OpSource instructions (#5901)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveUrquhart authored Dec 17, 2024
1 parent a408488 commit 1a84052
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/opt/aggressive_dead_code_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ void AggressiveDCEPass::InitializeModuleScopeLiveInstructions() {
auto op = dbg.GetShader100DebugOpcode();
if (op == NonSemanticShaderDebugInfo100DebugCompilationUnit ||
op == NonSemanticShaderDebugInfo100DebugEntryPoint ||
op == NonSemanticShaderDebugInfo100DebugSource ||
op == NonSemanticShaderDebugInfo100DebugSourceContinued) {
AddToWorklist(&dbg);
}
Expand Down
64 changes: 64 additions & 0 deletions test/opt/aggressive_dead_code_elim_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <vector>

#include "gmock/gmock.h"
#include "test/opt/assembly_builder.h"
#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"
Expand All @@ -26,6 +27,8 @@ namespace {

using AggressiveDCETest = PassTest<::testing::Test>;

using ::testing::HasSubstr;

TEST_F(AggressiveDCETest, EliminateExtendedInst) {
// #version 140
//
Expand Down Expand Up @@ -8233,6 +8236,67 @@ OpFunctionEnd
SinglePassRunAndCheck<AggressiveDCEPass>(spirv, spirv, true, false);
}

TEST_F(AggressiveDCETest, NoEliminateOpSource) {
// Should not eliminate OpSource

const std::string text =
R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %in_var_COLOR %out_var_SV_TARGET
OpExecutionMode %main OriginUpperLeft
%4 = OpString "D:\\directxshadercompiler\\tools\\clang\\test\\CodeGenSPIRV\\spirv.debug.opsource.include.hlsl"
%5 = OpString "D:\\directxshadercompiler\\tools\\clang\\test\\CodeGenSPIRV/spirv.debug.opsource.include-file.hlsli"
OpSource HLSL 600 %4 "// RUN: %dxc -T ps_6_0 -E main -Zi %s -spirv | FileCheck %s
#include \"spirv.debug.opsource.include-file.hlsli\"
struct ColorType
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
float4 main(UBER_TYPE(Color) input) : SV_TARGET
{
return input.color;
}
"
OpSource HLSL 600 %5 "#define UBER_TYPE(x) x ## Type
"
OpName %in_var_COLOR "in.var.COLOR"
OpName %out_var_SV_TARGET "out.var.SV_TARGET"
OpName %main "main"
OpDecorate %in_var_COLOR Location 0
OpDecorate %out_var_SV_TARGET Location 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Input_v4float = OpTypePointer Input %v4float
%_ptr_Output_v4float = OpTypePointer Output %v4float
%void = OpTypeVoid
%11 = OpTypeFunction %void
%in_var_COLOR = OpVariable %_ptr_Input_v4float Input
%out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
OpLine %4 22 1
%main = OpFunction %void None %11
OpNoLine
%12 = OpLabel
OpLine %4 22 1
%13 = OpLoad %v4float %in_var_COLOR
OpStore %out_var_SV_TARGET %13
OpLine %4 25 1
OpReturn
OpFunctionEnd
)";

auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
text, /* skip_nop = */ true, /* skip_validation = */ false);

EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
const std::string& output = std::get<0>(result);
EXPECT_THAT(
output,
HasSubstr("OpSource HLSL 600 %5 \"#define UBER_TYPE(x) x ## Type"));
}

} // namespace
} // namespace opt
} // namespace spvtools

0 comments on commit 1a84052

Please sign in to comment.