tint/renamer: Preserve diagnostic control names

Add a Dawn E2E test to make sure that diagnostic controls work through
the whole shader compilation flow.

Bug: tint:1809
Fixed: chromium:1410930
Change-Id: Icea31cfadbbc182008a8a07efcddb402954dd1c7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117980
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price 2023-01-28 00:37:42 +00:00 committed by Dawn LUCI CQ
parent 4ec8e5c7f8
commit 7ce72de3a5
3 changed files with 96 additions and 0 deletions

View File

@ -1372,6 +1372,57 @@ struct ShaderIO {
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 102, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 102, 255), renderPass.color, 0, 0);
} }
// Test that the derivative_uniformity diagnostic filter is handled correctly through the full
// shader compilation flow.
TEST_P(ShaderTests, DerivativeUniformityDiagnosticFilter) {
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
struct VertexOut {
@builtin(position) pos : vec4<f32>,
@location(0) value : f32,
}
@vertex
fn main(@builtin(vertex_index) VertexIndex : u32) -> VertexOut {
const pos = array(
vec2( 1.0, -1.0),
vec2(-1.0, -1.0),
vec2( 0.0, 1.0),
);
return VertexOut(vec4(pos[VertexIndex], 0.0, 1.0), 0.5);
})");
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
diagnostic(off, derivative_uniformity);
@fragment
fn main(@location(0) value : f32) -> @location(0) vec4<f32> {
if (value > 0) {
let intensity = 1.0 - dpdx(1.0);
return vec4(intensity, intensity, intensity, 1.0);
}
return vec4(1.0);
})");
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 1, 1);
utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule;
descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList;
descriptor.cTargets[0].format = renderPass.colorFormat;
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline);
pass.Draw(3);
pass.End();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(255, 255, 255, 255), renderPass.color, 0, 0);
}
DAWN_INSTANTIATE_TEST(ShaderTests, DAWN_INSTANTIATE_TEST(ShaderTests,
D3D12Backend(), D3D12Backend(),
D3D12Backend({"use_dxc"}), D3D12Backend({"use_dxc"}),

View File

@ -1313,6 +1313,9 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
}); });
} }
}, },
[&](const ast::DiagnosticControl* diagnostic) {
preserved_identifiers.Add(diagnostic->rule_name);
},
[&](const ast::TypeName* type_name) { [&](const ast::TypeName* type_name) {
if (is_type_short_name(type_name->name)) { if (is_type_short_name(type_name->name)) {
preserved_type_names.Add(type_name); preserved_type_names.Add(type_name);

View File

@ -189,6 +189,48 @@ fn tint_symbol() {
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings)); EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
} }
TEST_F(RenamerTest, PreserveDiagnosticControls) {
auto* src = R"(
diagnostic(off, unreachable_code);
@diagnostic(off, derivative_uniformity)
@fragment
fn entry(@location(0) value : f32) -> @location(0) f32 {
if (value > 0) {
return dpdx(value);
return 0.0;
}
return 1.0;
}
)";
auto* expect = R"(
diagnostic(off, unreachable_code);
@diagnostic(off, derivative_uniformity) @fragment
fn tint_symbol(@location(0) tint_symbol_1 : f32) -> @location(0) f32 {
if ((tint_symbol_1 > 0)) {
return dpdx(tint_symbol_1);
return 0.0;
}
return 1.0;
}
)";
auto got = Run<Renamer>(src);
EXPECT_EQ(expect, str(got));
auto* data = got.data.Get<Renamer::Data>();
ASSERT_NE(data, nullptr);
Renamer::Data::Remappings expected_remappings = {
{"entry", "tint_symbol"},
{"value", "tint_symbol_1"},
};
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
}
TEST_F(RenamerTest, PreserveUnicode) { TEST_F(RenamerTest, PreserveUnicode) {
auto src = R"( auto src = R"(
@fragment @fragment