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>
This commit is contained in:
Ben Clayton
2021-06-04 20:41:47 +00:00
committed by Tint LUCI CQ
parent b175d91c7e
commit 93e8f527ee
450 changed files with 2651 additions and 2213 deletions

View File

@@ -23,12 +23,9 @@ namespace sem {
StorageTexture::StorageTexture(ast::TextureDimension dim,
ast::ImageFormat format,
ast::AccessControl::Access access_control,
ast::Access access,
sem::Type* subtype)
: Base(dim),
image_format_(format),
access_control_(access_control),
subtype_(subtype) {}
: Base(dim), image_format_(format), access_(access), subtype_(subtype) {}
StorageTexture::StorageTexture(StorageTexture&&) = default;
@@ -37,14 +34,14 @@ StorageTexture::~StorageTexture() = default;
std::string StorageTexture::type_name() const {
std::ostringstream out;
out << "__storage_texture_" << dim() << "_" << image_format_ << "_"
<< access_control_;
<< access_;
return out.str();
}
std::string StorageTexture::FriendlyName(const SymbolTable&) const {
std::ostringstream out;
out << "texture_storage_" << dim() << "<" << image_format_ << ", "
<< access_control_ << ">";
out << "texture_storage_" << dim() << "<" << image_format_ << ", " << access_
<< ">";
return out.str();
}

View File

@@ -17,7 +17,7 @@
#include <string>
#include "src/ast/access_control.h"
#include "src/ast/access.h"
#include "src/ast/storage_texture.h"
#include "src/sem/texture_type.h"
@@ -32,11 +32,11 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
/// Constructor
/// @param dim the dimensionality of the texture
/// @param format the image format of the texture
/// @param access_control the access control type of the texture
/// @param access the access control type of the texture
/// @param subtype the storage subtype. Use SubtypeFor() to calculate this.
StorageTexture(ast::TextureDimension dim,
ast::ImageFormat format,
ast::AccessControl::Access access_control,
ast::Access access,
sem::Type* subtype);
/// Move constructor
@@ -50,7 +50,7 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
ast::ImageFormat image_format() const { return image_format_; }
/// @returns the access control
ast::AccessControl::Access access_control() const { return access_control_; }
ast::Access access() const { return access_; }
/// @returns the name for this type
std::string type_name() const override;
@@ -67,7 +67,7 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
private:
ast::ImageFormat const image_format_;
ast::AccessControl::Access const access_control_;
ast::Access const access_;
Type* const subtype_;
};

View File

@@ -30,7 +30,7 @@ TEST_F(StorageTextureTest, Dim) {
StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Float, Types());
auto* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Float,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
EXPECT_EQ(s->dim(), ast::TextureDimension::k2dArray);
}
@@ -39,7 +39,7 @@ TEST_F(StorageTextureTest, Format) {
StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Float, Types());
auto* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Float,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
EXPECT_EQ(s->image_format(), ast::ImageFormat::kRgba32Float);
}
@@ -48,7 +48,7 @@ TEST_F(StorageTextureTest, TypeName) {
StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Float, Types());
auto* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Float,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
EXPECT_EQ(s->type_name(),
"__storage_texture_2d_array_rgba32float_read_write");
}
@@ -58,7 +58,7 @@ TEST_F(StorageTextureTest, FriendlyName) {
StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Float, Types());
auto* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Float,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
EXPECT_EQ(s->FriendlyName(Symbols()),
"texture_storage_2d_array<rgba32float, read_write>");
}
@@ -68,7 +68,7 @@ TEST_F(StorageTextureTest, F32) {
sem::StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Float, Types());
Type* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Float,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
auto program = Build();
@@ -83,7 +83,7 @@ TEST_F(StorageTextureTest, U32) {
sem::StorageTexture::SubtypeFor(ast::ImageFormat::kRg32Uint, Types());
Type* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRg32Uint,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
auto program = Build();
@@ -98,7 +98,7 @@ TEST_F(StorageTextureTest, I32) {
sem::StorageTexture::SubtypeFor(ast::ImageFormat::kRgba32Sint, Types());
Type* s = create<StorageTexture>(ast::TextureDimension::k2dArray,
ast::ImageFormat::kRgba32Sint,
ast::AccessControl::kReadWrite, subtype);
ast::Access::kReadWrite, subtype);
auto program = Build();

View File

@@ -26,11 +26,11 @@ namespace sem {
Variable::Variable(const ast::Variable* declaration,
const sem::Type* type,
ast::StorageClass storage_class,
ast::AccessControl::Access access_control)
ast::Access access)
: declaration_(declaration),
type_(type),
storage_class_(storage_class),
access_control_(access_control),
access_(access),
is_pipeline_constant_(false) {}
Variable::Variable(const ast::Variable* declaration,
@@ -39,7 +39,7 @@ Variable::Variable(const ast::Variable* declaration,
: declaration_(declaration),
type_(type),
storage_class_(ast::StorageClass::kNone),
access_control_(ast::AccessControl::kReadWrite),
access_(ast::Access::kReadWrite),
is_pipeline_constant_(true),
constant_id_(constant_id) {}

View File

@@ -17,7 +17,7 @@
#include <vector>
#include "src/ast/access_control.h"
#include "src/ast/access.h"
#include "src/ast/storage_class.h"
#include "src/sem/expression.h"
@@ -42,11 +42,11 @@ class Variable : public Castable<Variable, Node> {
/// @param declaration the AST declaration node
/// @param type the variable type
/// @param storage_class the variable storage class
/// @param access_control the variable access control type
/// @param access the variable access control type
Variable(const ast::Variable* declaration,
const sem::Type* type,
ast::StorageClass storage_class,
ast::AccessControl::Access access_control);
ast::Access access);
/// Constructor for overridable pipeline constants
/// @param declaration the AST declaration node
@@ -69,7 +69,7 @@ class Variable : public Castable<Variable, Node> {
ast::StorageClass StorageClass() const { return storage_class_; }
/// @returns the access control for the variable
ast::AccessControl::Access AccessControl() const { return access_control_; }
ast::Access Access() const { return access_; }
/// @returns the expressions that use the variable
const std::vector<const VariableUser*>& Users() const { return users_; }
@@ -87,7 +87,7 @@ class Variable : public Castable<Variable, Node> {
const ast::Variable* const declaration_;
const sem::Type* const type_;
ast::StorageClass const storage_class_;
ast::AccessControl::Access const access_control_;
ast::Access const access_;
std::vector<const VariableUser*> users_;
const bool is_pipeline_constant_;
const uint16_t constant_id_ = 0;