wgsl: Deprecate [[access]] decorations
Handle access control on var declarations instead of via [[access]]
decorations. This change does the minimal work to migrate the WGSL
parser over to the new syntax. Additional changes will be needed
to correctly generate defaulted access qualifiers, as well as
validating access usage.
The [[access]] decorations are still supported by the WGSL parser,
with new deprecated warnings, but not for aliases. Example:
var x : [[access(x)]] alias_to_struct;
Making this work is far more effort than I want to dedicate to backwards
compatibility, and I do not beleive any real-world usage will be doing
this.
Still TODO:
* Adding access control as the optional, third parameter to ptr<>.
* Calculating default accesses for the various storage types.
* Validating usage of variables against the different accesses.
Bug: tint:846
Change-Id: If8ca82e5d16ec319ecd01f9a2cafffd930963bde
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53088
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index 8bba93a..789bb51 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -17,7 +17,7 @@
#include <algorithm>
#include <limits>
-#include "src/ast/access_control.h"
+#include "src/ast/access.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
@@ -355,25 +355,26 @@
return true;
}
-bool GeneratorImpl::EmitType(const ast::Type* ty) {
- if (auto* ac = ty->As<ast::AccessControl>()) {
- out_ << "[[access(";
- if (ac->IsReadOnly()) {
+bool GeneratorImpl::EmitAccess(const ast::Access access) {
+ switch (access) {
+ case ast::Access::kRead:
out_ << "read";
- } else if (ac->IsWriteOnly()) {
+ return true;
+ case ast::Access::kWrite:
out_ << "write";
- } else if (ac->IsReadWrite()) {
+ return true;
+ case ast::Access::kReadWrite:
out_ << "read_write";
- } else {
- diagnostics_.add_error("invalid access control");
- return false;
- }
- out_ << ")]] ";
- if (!EmitType(ac->type())) {
- return false;
- }
- return true;
- } else if (auto* alias = ty->As<ast::Alias>()) {
+ return true;
+ default:
+ break;
+ }
+ diagnostics_.add_error("unknown access");
+ return false;
+}
+
+bool GeneratorImpl::EmitType(const ast::Type* ty) {
+ if (auto* alias = ty->As<ast::Alias>()) {
out_ << program_->Symbols().NameFor(alias->symbol());
} else if (auto* ary = ty->As<ast::Array>()) {
for (auto* deco : ary->decorations()) {
@@ -477,6 +478,10 @@
if (!EmitImageFormat(storage->image_format())) {
return false;
}
+ out_ << ", ";
+ if (!EmitAccess(storage->access())) {
+ return false;
+ }
out_ << ">";
}
@@ -580,8 +585,16 @@
} else {
out_ << "var";
auto sc = var->declared_storage_class();
- if (sc != ast::StorageClass::kNone) {
- out_ << "<" << sc << ">";
+ auto ac = var->declared_access();
+ if (sc != ast::StorageClass::kNone || ac != ast::Access::kUndefined) {
+ out_ << "<" << sc;
+ if (ac != ast::Access::kUndefined) {
+ out_ << ", ";
+ if (!EmitAccess(ac)) {
+ return false;
+ }
+ }
+ out_ << ">";
}
}