diff --git a/src/dawn/tests/end2end/ShaderTests.cpp b/src/dawn/tests/end2end/ShaderTests.cpp index a4b217e571..f0c12e3bf4 100644 --- a/src/dawn/tests/end2end/ShaderTests.cpp +++ b/src/dawn/tests/end2end/ShaderTests.cpp @@ -1372,6 +1372,57 @@ struct ShaderIO { 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, + @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 { + 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, D3D12Backend(), D3D12Backend({"use_dxc"}), diff --git a/src/tint/transform/renamer.cc b/src/tint/transform/renamer.cc index a467806b65..6f485a4f44 100644 --- a/src/tint/transform/renamer.cc +++ b/src/tint/transform/renamer.cc @@ -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) { if (is_type_short_name(type_name->name)) { preserved_type_names.Add(type_name); diff --git a/src/tint/transform/renamer_test.cc b/src/tint/transform/renamer_test.cc index 152489aa7c..969ce2c4f8 100644 --- a/src/tint/transform/renamer_test.cc +++ b/src/tint/transform/renamer_test.cc @@ -189,6 +189,48 @@ fn tint_symbol() { 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(src); + + EXPECT_EQ(expect, str(got)); + + auto* data = got.data.Get(); + + 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) { auto src = R"( @fragment