From c41d9406509215d31576c4ec1f5aa7193fd9435c Mon Sep 17 00:00:00 2001 From: James Price Date: Mon, 19 Jul 2021 21:32:27 +0000 Subject: [PATCH] Parse num_workgroups builtin and reject it We have chosen not to implement this for origin trial, so just parse it and produce an error in the validator. Bug: tint:752 Change-Id: I40ebf0b4051fb0b8bab9d4c733e555b836320cd4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58780 Auto-Submit: James Price Reviewed-by: Ben Clayton Commit-Queue: James Price Kokoro: Kokoro --- src/ast/builtin.cc | 4 ++++ src/ast/builtin.h | 1 + src/reader/wgsl/parser_impl.cc | 3 +++ src/reader/wgsl/parser_impl_variable_decoration_test.cc | 1 + src/resolver/resolver.cc | 4 ++++ src/writer/spirv/builder.cc | 2 ++ src/writer/spirv/builder_global_variable_test.cc | 2 ++ 7 files changed, 17 insertions(+) diff --git a/src/ast/builtin.cc b/src/ast/builtin.cc index 3e49d14993..e0f8ecc30e 100644 --- a/src/ast/builtin.cc +++ b/src/ast/builtin.cc @@ -59,6 +59,10 @@ std::ostream& operator<<(std::ostream& out, Builtin builtin) { out << "workgroup_id"; break; } + case Builtin::kNumWorkgroups: { + out << "num_workgroups"; + break; + } case Builtin::kSampleIndex: { out << "sample_index"; break; diff --git a/src/ast/builtin.h b/src/ast/builtin.h index e5092c886d..3e03148f2b 100644 --- a/src/ast/builtin.h +++ b/src/ast/builtin.h @@ -32,6 +32,7 @@ enum class Builtin { kLocalInvocationIndex, kGlobalInvocationId, kWorkgroupId, + kNumWorkgroups, kSampleIndex, kSampleMask, diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 7318b37c3a..99e5de9f7d 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -98,6 +98,9 @@ ast::Builtin ident_to_builtin(const std::string& str) { if (str == "workgroup_id") { return ast::Builtin::kWorkgroupId; } + if (str == "num_workgroups") { + return ast::Builtin::kNumWorkgroups; + } if (str == "sample_index") { return ast::Builtin::kSampleIndex; } diff --git a/src/reader/wgsl/parser_impl_variable_decoration_test.cc b/src/reader/wgsl/parser_impl_variable_decoration_test.cc index b3fd05a804..a805f6be22 100644 --- a/src/reader/wgsl/parser_impl_variable_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decoration_test.cc @@ -119,6 +119,7 @@ INSTANTIATE_TEST_SUITE_P( ast::Builtin::kLocalInvocationIndex}, BuiltinData{"global_invocation_id", ast::Builtin::kGlobalInvocationId}, BuiltinData{"workgroup_id", ast::Builtin::kWorkgroupId}, + BuiltinData{"num_workgroups", ast::Builtin::kNumWorkgroups}, BuiltinData{"sample_index", ast::Builtin::kSampleIndex}, BuiltinData{"sample_mask", ast::Builtin::kSampleMask})); diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 492026c312..374f99babb 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -1333,6 +1333,10 @@ bool Resolver::ValidateBuiltinDecoration(const ast::BuiltinDecoration* deco, return false; } break; + case ast::Builtin::kNumWorkgroups: + // TODO(crbug.com/tint/752): Backend support (needs extra work for HLSL). + AddError("num_workgroups builtin is not yet implemented", deco->source()); + return false; default: break; } diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 039269f651..b666345cd5 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -4075,6 +4075,8 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin, return SpvBuiltInPointSize; case ast::Builtin::kWorkgroupId: return SpvBuiltInWorkgroupId; + case ast::Builtin::kNumWorkgroups: + return SpvBuiltInNumWorkgroups; case ast::Builtin::kSampleIndex: push_capability(SpvCapabilitySampleRateShading); return SpvBuiltInSampleId; diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index d7449965a8..d3e111e374 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -329,6 +329,8 @@ INSTANTIATE_TEST_SUITE_P( ast::StorageClass::kInput, SpvBuiltInGlobalInvocationId}, BuiltinData{ast::Builtin::kWorkgroupId, ast::StorageClass::kInput, SpvBuiltInWorkgroupId}, + BuiltinData{ast::Builtin::kNumWorkgroups, ast::StorageClass::kInput, + SpvBuiltInNumWorkgroups}, BuiltinData{ast::Builtin::kSampleIndex, ast::StorageClass::kInput, SpvBuiltInSampleId}, BuiltinData{ast::Builtin::kSampleMask, ast::StorageClass::kInput,