From 072f83c68257ec36ef3113b21eb765ce9f519da7 Mon Sep 17 00:00:00 2001 From: James Price Date: Thu, 2 Feb 2023 00:29:27 +0000 Subject: [PATCH] tint/uniformity: filter should not affect result A derivative_uniformity diagnostic filter should not affect the uniformity of the return value of a derivative builtin. Fixed: tint:1815 Change-Id: I58e714978dab747598af5136dc9808a5a658c60e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118001 Commit-Queue: James Price Reviewed-by: David Neto Kokoro: Kokoro --- src/tint/resolver/uniformity.cc | 2 +- src/tint/resolver/uniformity_test.cc | 34 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index ec10d92398..6c4b53a5ee 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -1512,8 +1512,8 @@ class UniformityGraph { sem_.DiagnosticSeverity(call, ast::DiagnosticRule::kDerivativeUniformity); if (severity != ast::DiagnosticSeverity::kOff) { callsite_tag = {CallSiteTag::CallSiteRequiredToBeUniform, severity}; - function_tag = ReturnValueMayBeNonUniform; } + function_tag = ReturnValueMayBeNonUniform; } else if (builtin->IsAtomic()) { callsite_tag = {CallSiteTag::CallSiteNoRestriction}; function_tag = ReturnValueMayBeNonUniform; diff --git a/src/tint/resolver/uniformity_test.cc b/src/tint/resolver/uniformity_test.cc index 59e42df4f1..334352de4f 100644 --- a/src/tint/resolver/uniformity_test.cc +++ b/src/tint/resolver/uniformity_test.cc @@ -8132,6 +8132,40 @@ test:35:7 note: reading from read_write storage buffer 'non_uniform' may result )"); } +TEST_F(UniformityAnalysisDiagnosticFilterTest, BuiltinReturnValueNotAffected) { + // Make sure that a diagnostic filter does not affect the uniformity of the return value of a + // derivative builtin. + std::string src = R"( +fn foo() { + var x: f32; + + @diagnostic(off,derivative_uniformity) { + x = dpdx(1.0); + } + + if (x < 0.5) { + _ = dpdy(1.0); // Should trigger an error + } +} + +)"; + + RunTest(src, false); + EXPECT_EQ(error_, + R"(test:10:9 error: 'dpdy' must only be called from uniform control flow + _ = dpdy(1.0); // Should trigger an error + ^^^^ + +test:9:3 note: control flow depends on possibly non-uniform value + if (x < 0.5) { + ^^ + +test:6:9 note: return value of 'dpdx' may be non-uniform + x = dpdx(1.0); + ^^^^ +)"); +} + TEST_F(UniformityAnalysisDiagnosticFilterTest, BarriersNotAffected) { // Make sure that the diagnostic filter does not affect barriers. std::string src = R"(