[tint][ir][val] Enforce @workgroup_size only valid for compute

Fixes: 374930294
Change-Id: I21138e4f5e439f581a94ba934a3950b2a863d191
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/211816
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/ir/validator.cc b/src/tint/lang/core/ir/validator.cc
index d1bfa1e..9d3ff9d 100644
--- a/src/tint/lang/core/ir/validator.cc
+++ b/src/tint/lang/core/ir/validator.cc
@@ -1781,6 +1781,11 @@
         }
     }
 
+    if (DAWN_UNLIKELY(func->Stage() != Function::PipelineStage::kCompute &&
+                      func->WorkgroupSize().has_value())) {
+        AddError(func) << "workgroup size attribute only valid on compute entry point";
+    }
+
     if (func->Stage() == Function::PipelineStage::kFragment) {
         if (!func->ReturnType()->Is<core::type::Void>()) {
             CheckFunctionReturnAttributes(
diff --git a/src/tint/lang/core/ir/validator_test.cc b/src/tint/lang/core/ir/validator_test.cc
index c92477e..a3352ec 100644
--- a/src/tint/lang/core/ir/validator_test.cc
+++ b/src/tint/lang/core/ir/validator_test.cc
@@ -938,6 +938,28 @@
 )");
 }
 
+TEST_F(IR_ValidatorTest, Function_WorkspaceSizeOnlyOnCompute) {
+    auto* f = FragmentEntryPoint();
+    f->SetWorkgroupSize(0, 0, 0);
+
+    b.Append(f->Block(), [&] { b.Unreachable(); });
+
+    auto res = ir::Validate(mod);
+    ASSERT_NE(res, Success);
+    EXPECT_EQ(res.Failure().reason.Str(),
+              R"(:1:1 error: workgroup size attribute only valid on compute entry point
+%f = @fragment @workgroup_size(0, 0, 0) func():void {
+^^
+
+note: # Disassembly
+%f = @fragment @workgroup_size(0, 0, 0) func():void {
+  $B1: {
+    unreachable
+  }
+}
+)");
+}
+
 TEST_F(IR_ValidatorTest, Function_Vertex_BasicPosition) {
     auto* f = b.Function("my_func", ty.vec4<f32>(), Function::PipelineStage::kVertex);
     f->SetReturnBuiltin(BuiltinValue::kPosition);