tint/uniformity: Violations are now errors

Switch the default severity for all uniformity violations to errors.

We now have an opt-out mechanism for deriviative operations (via
diagnostic filters), and a `workgroupUniformLoad()` builtin for
compute shaders.

Bug: tint:1809
Change-Id: I666c706d6195ca0d24ead14c4709e7f646bfcc64
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117741
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-01-25 01:24:46 +00:00
parent f38ee3e073
commit bb0229002d
6 changed files with 182 additions and 185 deletions

View File

@ -64,8 +64,7 @@ TEST_F(ParserTest, AllowNonUniformDerivatives_False) {
options.allow_non_uniform_derivatives = false;
auto program = Parse(spv, options);
auto errs = diag::Formatter().format(program.Diagnostics());
// TODO(jrprice): This will become EXPECT_FALSE.
EXPECT_TRUE(program.IsValid()) << errs;
EXPECT_FALSE(program.IsValid()) << errs;
EXPECT_THAT(errs, ::testing::HasSubstr("'dpdx' must only be called from uniform control flow"));
}

View File

@ -146,9 +146,7 @@ bool Resolver::Resolve() {
// Run the uniformity analysis, which requires a complete semantic module.
if (!enabled_extensions_.Contains(ast::Extension::kChromiumDisableUniformityAnalysis)) {
if (!AnalyzeUniformity(builder_, dependencies_)) {
if (kUniformityFailuresAsError) {
return false;
}
return false;
}
}
}

View File

@ -26,7 +26,7 @@ class ProgramBuilder;
namespace tint::resolver {
/// If true, uniformity analysis failures will be treated as an error, else as a warning.
constexpr bool kUniformityFailuresAsError = false;
constexpr bool kUniformityFailuresAsError = true;
/// Analyze the uniformity of a program.
/// @param builder the program to analyze

File diff suppressed because it is too large Load Diff

View File

@ -169,7 +169,7 @@ Validator::Validator(
valid_type_storage_layouts_(valid_type_storage_layouts) {
// Set default severities for filterable diagnostic rules.
diagnostic_filters_.Set(ast::DiagnosticRule::kDerivativeUniformity,
ast::DiagnosticSeverity::kWarning);
ast::DiagnosticSeverity::kError);
diagnostic_filters_.Set(ast::DiagnosticRule::kChromiumUnreachableCode,
ast::DiagnosticSeverity::kWarning);
}

View File

@ -542,10 +542,10 @@ fn foo_discard(@location(0) in : f32, @location(1) coord : vec2<f32>) {
@fragment
fn foo_no_discard(@location(0) in : f32, @location(1) coord : vec2<f32>) {
let ret = bar_no_discard(in, coord);
if (in == 0.0) {
return;
}
let ret = bar_no_discard(in, coord);
v2 = ret;
}
)";
@ -591,10 +591,10 @@ fn foo_discard(@location(0) in : f32, @location(1) coord : vec2<f32>) {
@fragment
fn foo_no_discard(@location(0) in : f32, @location(1) coord : vec2<f32>) {
let ret = bar_no_discard(in, coord);
if ((in == 0.0)) {
return;
}
let ret = bar_no_discard(in, coord);
v2 = ret;
}
)";
@ -992,8 +992,9 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
}
var result = 0;
for (var i = 0; i < 10; i = atomicAdd(&a, 1)) {
result += i32(textureSample(t, s, coord).x);
result += i;
}
result += i32(textureSample(t, s, coord).x);
return result;
}
)";
@ -1020,7 +1021,7 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
break;
}
{
result += i32(textureSample(t, s, coord).x);
result += i;
}
continuing {
@ -1032,6 +1033,7 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
}
}
}
result += i32(textureSample(t, s, coord).x);
if (tint_discarded) {
discard;
}
@ -1060,8 +1062,9 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
var result = 0;
if (!atomicCompareExchangeWeak(&a, i32(in), 42).exchanged) {
let xchg = atomicCompareExchangeWeak(&a, i32(in), 42);
result = i32(textureSample(t, s, coord).x) * xchg.old_value;
result = xchg.old_value;
}
result += i32(textureSample(t, s, coord).x);
return result;
}
)";
@ -1100,8 +1103,9 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
tint_symbol_3.exchanged = tint_symbol_4.exchanged;
}
let xchg = tint_symbol_3;
result = (i32(textureSample(t, s, coord).x) * xchg.old_value);
result = xchg.old_value;
}
result += i32(textureSample(t, s, coord).x);
if (tint_discarded) {
discard;
}