[tint] Improve uniformity diagnostics for builtin parameters
When a builtin function's parameter is required to be uniform, make
sure we actually state that in the error message instead of jumping to
the source of non-uniformity.
This only affects workgroupUniformLoad in this patch, but will also
affect the `subgroupShuffle*` builtins in the next patch.
Change-Id: I56199f5e311ae65ae00e5ee838aefc5c84557064
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/214895
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/resolver/uniformity.cc b/src/tint/lang/wgsl/resolver/uniformity.cc
index fd8c243..be0ad09 100644
--- a/src/tint/lang/wgsl/resolver/uniformity.cc
+++ b/src/tint/lang/wgsl/resolver/uniformity.cc
@@ -2011,14 +2011,22 @@
auto& param_info = next_function->parameters[cause->arg_index];
MakeError(*next_function,
is_value ? param_info.value : param_info.ptr_input_contents, severity);
- }
- // Show the place where the non-uniform argument was passed.
- // If this is a builtin, this will be the trigger location for the failure.
- StringStream ss;
- ss << "possibly non-uniform value passed" << (is_value ? "" : " via pointer")
- << " here";
- report(call->args[cause->arg_index]->source, ss.str(), /* note */ user_func != nullptr);
+ // Show the place where the non-uniform argument was passed.
+ // If this is a builtin, this will be the trigger location for the failure.
+ StringStream ss;
+ ss << "possibly non-uniform value passed" << (is_value ? "" : " via pointer")
+ << " here";
+ report(call->args[cause->arg_index]->source, ss.str(), /* note */ true);
+ } else {
+ // The uniformity requirement must come from a builtin function.
+ auto* builtin = target->As<sem::BuiltinFn>();
+ TINT_ASSERT(builtin);
+ StringStream ss;
+ ss << "'" << builtin->Fn() << "' requires argument " << cause->arg_index << " to "
+ << (is_value ? "be uniform" : "have uniform contents");
+ report(call->args[cause->arg_index]->source, ss.str(), /* note */ false);
+ }
// Show the origin of non-uniformity for the value or data that is being passed.
ShowSourceOfNonUniformity(source_node->visited_from);
diff --git a/src/tint/lang/wgsl/resolver/uniformity_test.cc b/src/tint/lang/wgsl/resolver/uniformity_test.cc
index d1c51d7..c77c643 100644
--- a/src/tint/lang/wgsl/resolver/uniformity_test.cc
+++ b/src/tint/lang/wgsl/resolver/uniformity_test.cc
@@ -9044,7 +9044,7 @@
RunTest(src, false);
EXPECT_EQ(error_,
- R"(test:8:28 error: possibly non-uniform value passed here
+ R"(test:8:28 error: 'workgroupUniformLoad' requires argument 0 to be uniform
if (workgroupUniformLoad(&data[idx]) > 0) {
^^^^^^^^^^
@@ -9074,7 +9074,7 @@
RunTest(src, false);
EXPECT_EQ(error_,
- R"(test:6:31 error: possibly non-uniform value passed here
+ R"(test:6:31 error: 'workgroupUniformLoad' requires argument 0 to be uniform
return workgroupUniformLoad(p);
^