[ast] Unify the access control types.

This CL merges the StorageAccess enum with the AccessControl enum. The
enum is moved up to src/ast and placed in its own file for clarity.

Change-Id: I95a905a399b5d2e046ea1ea429b35f2064510c2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31242
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-10-29 13:36:32 +00:00 committed by Commit Bot service account
parent 4dd5665502
commit c55fc39acb
20 changed files with 167 additions and 109 deletions

View File

@ -217,6 +217,8 @@ tint_language_header("cldebuginfo100") {
source_set("libtint_core_src") { source_set("libtint_core_src") {
sources = [ sources = [
"src/ast/access_control.cc",
"src/ast/access_control.h",
"src/ast/array_accessor_expression.cc", "src/ast/array_accessor_expression.cc",
"src/ast/array_accessor_expression.h", "src/ast/array_accessor_expression.h",
"src/ast/array_decoration.cc", "src/ast/array_decoration.cc",

View File

@ -38,6 +38,8 @@ endfunction()
set(TINT_LIB_SRCS set(TINT_LIB_SRCS
../include/tint/tint.h ../include/tint/tint.h
ast/access_control.cc
ast/access_control.h
ast/array_accessor_expression.cc ast/array_accessor_expression.cc
ast/array_accessor_expression.h ast/array_accessor_expression.h
ast/array_decoration.cc ast/array_decoration.cc

39
src/ast/access_control.cc Normal file
View File

@ -0,0 +1,39 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/access_control.h"
namespace tint {
namespace ast {
std::ostream& operator<<(std::ostream& out, AccessControl access) {
switch (access) {
case AccessControl::kReadOnly: {
out << "read_only";
break;
}
case AccessControl::kReadWrite: {
out << "read_write";
break;
}
case AccessControl::kWriteOnly: {
out << "write_only";
break;
}
}
return out;
}
} // namespace ast
} // namespace tint

38
src/ast/access_control.h Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_AST_ACCESS_CONTROL_H_
#define SRC_AST_ACCESS_CONTROL_H_
#include <ostream>
namespace tint {
namespace ast {
/// The access control settings
enum class AccessControl {
/// Read only
kReadOnly = 0,
/// Write only
kWriteOnly,
/// Read write
kReadWrite
};
std::ostream& operator<<(std::ostream& out, AccessControl access);
} // namespace ast
} // namespace tint
#endif // SRC_AST_ACCESS_CONTROL_H_

View File

@ -17,20 +17,12 @@
#include "src/ast/type/type.h" #include "src/ast/type/type.h"
#include "src/ast/access_control.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
/// The access control settings
enum class AccessControl {
/// Read only
kReadOnly = 0,
/// Write only
kWriteOnly,
/// Read write
kReadWrite
};
/// An access control type. Holds an access setting and pointer to another type. /// An access control type. Holds an access setting and pointer to another type.
class AccessControlType : public Type { class AccessControlType : public Type {
public: public:

View File

@ -34,18 +34,6 @@ bool IsValidStorageDimension(TextureDimension dim) {
} // namespace } // namespace
std::ostream& operator<<(std::ostream& out, StorageAccess access) {
switch (access) {
case StorageAccess::kRead:
out << "read";
break;
case StorageAccess::kWrite:
out << "write";
break;
}
return out;
}
// Note, these names match the names in the WGSL spec. This behaviour is used // Note, these names match the names in the WGSL spec. This behaviour is used
// in the WGSL writer to emit the texture format names. // in the WGSL writer to emit the texture format names.
std::ostream& operator<<(std::ostream& out, ImageFormat format) { std::ostream& operator<<(std::ostream& out, ImageFormat format) {
@ -163,9 +151,9 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
} }
StorageTextureType::StorageTextureType(TextureDimension dim, StorageTextureType::StorageTextureType(TextureDimension dim,
StorageAccess access, AccessControl access,
ImageFormat format) ImageFormat format)
: TextureType(dim), storage_access_(access), image_format_(format) { : TextureType(dim), access_(access), image_format_(format) {
assert(IsValidStorageDimension(dim)); assert(IsValidStorageDimension(dim));
} }
@ -187,7 +175,7 @@ bool StorageTextureType::IsStorage() const {
std::string StorageTextureType::type_name() const { std::string StorageTextureType::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__storage_texture_" << storage_access_ << "_" << dim() << "_" out << "__storage_texture_" << access_ << "_" << dim() << "_"
<< image_format_; << image_format_;
return out.str(); return out.str();
} }

View File

@ -17,16 +17,13 @@
#include <string> #include <string>
#include "src/ast/access_control.h"
#include "src/ast/type/texture_type.h" #include "src/ast/type/texture_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
/// The access value of the storage texture
enum class StorageAccess { kRead, kWrite };
std::ostream& operator<<(std::ostream& out, StorageAccess dim);
/// The image format in the storage texture /// The image format in the storage texture
enum class ImageFormat { enum class ImageFormat {
kNone = -1, kNone = -1,
@ -76,7 +73,7 @@ class StorageTextureType : public TextureType {
/// @param access the access type for the texture /// @param access the access type for the texture
/// @param format the image format of the texture /// @param format the image format of the texture
StorageTextureType(TextureDimension dim, StorageTextureType(TextureDimension dim,
StorageAccess access, AccessControl access,
ImageFormat format); ImageFormat format);
/// Move constructor /// Move constructor
@ -93,7 +90,7 @@ class StorageTextureType : public TextureType {
Type* type() const; Type* type() const;
/// @returns the storage access /// @returns the storage access
StorageAccess access() const { return storage_access_; } AccessControl access() const { return access_; }
/// @returns the image format /// @returns the image format
ImageFormat image_format() const { return image_format_; } ImageFormat image_format() const { return image_format_; }
@ -103,7 +100,7 @@ class StorageTextureType : public TextureType {
private: private:
Type* type_ = nullptr; Type* type_ = nullptr;
StorageAccess storage_access_ = StorageAccess::kRead; AccessControl access_ = AccessControl::kReadOnly;
ImageFormat image_format_ = ImageFormat::kRgba32Float; ImageFormat image_format_ = ImageFormat::kRgba32Float;
}; };

View File

@ -27,7 +27,7 @@ namespace {
using StorageTextureTypeTest = testing::Test; using StorageTextureTypeTest = testing::Test;
TEST_F(StorageTextureTypeTest, Is) { TEST_F(StorageTextureTypeTest, Is) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_FALSE(s.IsAccessControl()); EXPECT_FALSE(s.IsAccessControl());
EXPECT_FALSE(s.IsAlias()); EXPECT_FALSE(s.IsAlias());
@ -45,7 +45,7 @@ TEST_F(StorageTextureTypeTest, Is) {
} }
TEST_F(StorageTextureTypeTest, IsTextureType) { TEST_F(StorageTextureTypeTest, IsTextureType) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_FALSE(s.IsDepth()); EXPECT_FALSE(s.IsDepth());
EXPECT_FALSE(s.IsSampled()); EXPECT_FALSE(s.IsSampled());
@ -53,33 +53,33 @@ TEST_F(StorageTextureTypeTest, IsTextureType) {
} }
TEST_F(StorageTextureTypeTest, Dim) { TEST_F(StorageTextureTypeTest, Dim) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.dim(), TextureDimension::k2dArray); EXPECT_EQ(s.dim(), TextureDimension::k2dArray);
} }
TEST_F(StorageTextureTypeTest, Access) { TEST_F(StorageTextureTypeTest, Access) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.access(), StorageAccess::kRead); EXPECT_EQ(s.access(), AccessControl::kReadOnly);
} }
TEST_F(StorageTextureTypeTest, Format) { TEST_F(StorageTextureTypeTest, Format) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float); EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float);
} }
TEST_F(StorageTextureTypeTest, TypeName) { TEST_F(StorageTextureTypeTest, TypeName) {
StorageTextureType s(TextureDimension::k2dArray, StorageAccess::kRead, StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
EXPECT_EQ(s.type_name(), "__storage_texture_read_2d_array_rgba32float"); EXPECT_EQ(s.type_name(), "__storage_texture_read_only_2d_array_rgba32float");
} }
TEST_F(StorageTextureTypeTest, F32Type) { TEST_F(StorageTextureTypeTest, F32Type) {
Context ctx; Context ctx;
ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>( ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>(
TextureDimension::k2dArray, StorageAccess::kRead, TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float)); ImageFormat::kRgba32Float));
ast::Module mod; ast::Module mod;
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
@ -93,7 +93,7 @@ TEST_F(StorageTextureTypeTest, F32Type) {
TEST_F(StorageTextureTypeTest, U32Type) { TEST_F(StorageTextureTypeTest, U32Type) {
Context ctx; Context ctx;
ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>( ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>(
TextureDimension::k2dArray, StorageAccess::kRead, TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba8Unorm)); ImageFormat::kRgba8Unorm));
ast::Module mod; ast::Module mod;
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
@ -107,7 +107,7 @@ TEST_F(StorageTextureTypeTest, U32Type) {
TEST_F(StorageTextureTypeTest, I32Type) { TEST_F(StorageTextureTypeTest, I32Type) {
Context ctx; Context ctx;
ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>( ast::type::Type* s = ctx.type_mgr().Get(std::make_unique<StorageTextureType>(
TextureDimension::k2dArray, StorageAccess::kRead, TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Sint)); ImageFormat::kRgba32Sint));
ast::Module mod; ast::Module mod;
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);

View File

@ -653,8 +653,8 @@ ast::type::Type* ParserImpl::texture_sampler_types() {
} }
ast::type::TextureDimension storage_dim; ast::type::TextureDimension storage_dim;
ast::type::StorageAccess storage_access; ast::AccessControl access;
std::tie(storage_dim, storage_access) = storage_texture_type(); std::tie(storage_dim, access) = storage_texture_type();
if (storage_dim != ast::type::TextureDimension::kNone) { if (storage_dim != ast::type::TextureDimension::kNone) {
auto t = next(); auto t = next();
if (!t.IsLessThan()) { if (!t.IsLessThan()) {
@ -677,7 +677,7 @@ ast::type::Type* ParserImpl::texture_sampler_types() {
} }
return ctx_.type_mgr().Get(std::make_unique<ast::type::StorageTextureType>( return ctx_.type_mgr().Get(std::make_unique<ast::type::StorageTextureType>(
storage_dim, storage_access, format)); storage_dim, access, format));
} }
return nullptr; return nullptr;
@ -764,54 +764,54 @@ ast::type::TextureDimension ParserImpl::multisampled_texture_type() {
// | TEXTURE_WO_2D // | TEXTURE_WO_2D
// | TEXTURE_WO_2D_ARRAY // | TEXTURE_WO_2D_ARRAY
// | TEXTURE_WO_3D // | TEXTURE_WO_3D
std::pair<ast::type::TextureDimension, ast::type::StorageAccess> std::pair<ast::type::TextureDimension, ast::AccessControl>
ParserImpl::storage_texture_type() { ParserImpl::storage_texture_type() {
auto t = peek(); auto t = peek();
if (t.IsTextureStorageReadonly1d()) { if (t.IsTextureStorageReadonly1d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k1d, ast::type::StorageAccess::kRead}; return {ast::type::TextureDimension::k1d, ast::AccessControl::kReadOnly};
} }
if (t.IsTextureStorageReadonly1dArray()) { if (t.IsTextureStorageReadonly1dArray()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k1dArray, return {ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kRead}; ast::AccessControl::kReadOnly};
} }
if (t.IsTextureStorageReadonly2d()) { if (t.IsTextureStorageReadonly2d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k2d, ast::type::StorageAccess::kRead}; return {ast::type::TextureDimension::k2d, ast::AccessControl::kReadOnly};
} }
if (t.IsTextureStorageReadonly2dArray()) { if (t.IsTextureStorageReadonly2dArray()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k2dArray, return {ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kRead}; ast::AccessControl::kReadOnly};
} }
if (t.IsTextureStorageReadonly3d()) { if (t.IsTextureStorageReadonly3d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k3d, ast::type::StorageAccess::kRead}; return {ast::type::TextureDimension::k3d, ast::AccessControl::kReadOnly};
} }
if (t.IsTextureStorageWriteonly1d()) { if (t.IsTextureStorageWriteonly1d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k1d, ast::type::StorageAccess::kWrite}; return {ast::type::TextureDimension::k1d, ast::AccessControl::kWriteOnly};
} }
if (t.IsTextureStorageWriteonly1dArray()) { if (t.IsTextureStorageWriteonly1dArray()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k1dArray, return {ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kWrite}; ast::AccessControl::kWriteOnly};
} }
if (t.IsTextureStorageWriteonly2d()) { if (t.IsTextureStorageWriteonly2d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k2d, ast::type::StorageAccess::kWrite}; return {ast::type::TextureDimension::k2d, ast::AccessControl::kWriteOnly};
} }
if (t.IsTextureStorageWriteonly2dArray()) { if (t.IsTextureStorageWriteonly2dArray()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k2dArray, return {ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kWrite}; ast::AccessControl::kWriteOnly};
} }
if (t.IsTextureStorageWriteonly3d()) { if (t.IsTextureStorageWriteonly3d()) {
next(); // Consume the peek next(); // Consume the peek
return {ast::type::TextureDimension::k3d, ast::type::StorageAccess::kWrite}; return {ast::type::TextureDimension::k3d, ast::AccessControl::kWriteOnly};
} }
return {ast::type::TextureDimension::kNone, ast::type::StorageAccess::kRead}; return {ast::type::TextureDimension::kNone, ast::AccessControl::kReadOnly};
} }
// depth_texture_type // depth_texture_type

View File

@ -208,7 +208,7 @@ class ParserImpl {
/// Parses a `storage_texture_type` grammar element /// Parses a `storage_texture_type` grammar element
/// @returns returns the storage texture dimension and the storage access. /// @returns returns the storage texture dimension and the storage access.
/// Returns kNone and kRead if none matched. /// Returns kNone and kRead if none matched.
std::pair<ast::type::TextureDimension, ast::type::StorageAccess> std::pair<ast::type::TextureDimension, ast::AccessControl>
storage_texture_type(); storage_texture_type();
/// Parses a `depth_texture_type` grammar element /// Parses a `depth_texture_type` grammar element
/// @returns the parsed Type or nullptr if none matched. /// @returns the parsed Type or nullptr if none matched.

View File

@ -26,7 +26,7 @@ TEST_F(ParserImplTest, StorageTextureType_Invalid) {
auto* p = parser("abc"); auto* p = parser("abc");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::kNone); EXPECT_EQ(t.first, ast::type::TextureDimension::kNone);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -34,7 +34,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly1d) {
auto* p = parser("texture_ro_1d"); auto* p = parser("texture_ro_1d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); EXPECT_EQ(t.first, ast::type::TextureDimension::k1d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -42,7 +42,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly1dArray) {
auto* p = parser("texture_ro_1d_array"); auto* p = parser("texture_ro_1d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly2d) {
auto* p = parser("texture_ro_2d"); auto* p = parser("texture_ro_2d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); EXPECT_EQ(t.first, ast::type::TextureDimension::k2d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -58,7 +58,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly2dArray) {
auto* p = parser("texture_ro_2d_array"); auto* p = parser("texture_ro_2d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -66,7 +66,7 @@ TEST_F(ParserImplTest, StorageTextureType_Readonly3d) {
auto* p = parser("texture_ro_3d"); auto* p = parser("texture_ro_3d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); EXPECT_EQ(t.first, ast::type::TextureDimension::k3d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kRead); EXPECT_EQ(t.second, ast::AccessControl::kReadOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly1d) {
auto* p = parser("texture_wo_1d"); auto* p = parser("texture_wo_1d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1d); EXPECT_EQ(t.first, ast::type::TextureDimension::k1d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kWrite); EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -82,7 +82,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly1dArray) {
auto* p = parser("texture_wo_1d_array"); auto* p = parser("texture_wo_1d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray); EXPECT_EQ(t.first, ast::type::TextureDimension::k1dArray);
EXPECT_EQ(t.second, ast::type::StorageAccess::kWrite); EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -90,7 +90,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly2d) {
auto* p = parser("texture_wo_2d"); auto* p = parser("texture_wo_2d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2d); EXPECT_EQ(t.first, ast::type::TextureDimension::k2d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kWrite); EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -98,7 +98,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly2dArray) {
auto* p = parser("texture_wo_2d_array"); auto* p = parser("texture_wo_2d_array");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray); EXPECT_EQ(t.first, ast::type::TextureDimension::k2dArray);
EXPECT_EQ(t.second, ast::type::StorageAccess::kWrite); EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }
@ -106,7 +106,7 @@ TEST_F(ParserImplTest, StorageTextureType_Writeonly3d) {
auto* p = parser("texture_wo_3d"); auto* p = parser("texture_wo_3d");
auto t = p->storage_texture_type(); auto t = p->storage_texture_type();
EXPECT_EQ(t.first, ast::type::TextureDimension::k3d); EXPECT_EQ(t.first, ast::type::TextureDimension::k3d);
EXPECT_EQ(t.second, ast::type::StorageAccess::kWrite); EXPECT_EQ(t.second, ast::AccessControl::kWriteOnly);
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
} }

View File

@ -177,7 +177,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(),
ast::type::ImageFormat::kR8Unorm); ast::type::ImageFormat::kR8Unorm);
EXPECT_EQ(t->AsTexture()->AsStorage()->access(), EXPECT_EQ(t->AsTexture()->AsStorage()->access(),
ast::type::StorageAccess::kRead); ast::AccessControl::kReadOnly);
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d);
} }
@ -191,7 +191,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(),
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
EXPECT_EQ(t->AsTexture()->AsStorage()->access(), EXPECT_EQ(t->AsTexture()->AsStorage()->access(),
ast::type::StorageAccess::kWrite); ast::AccessControl::kWriteOnly);
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
} }

View File

@ -1918,7 +1918,7 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) {
ast::type::Type* texture_type = ast::type::Type* texture_type =
ctx()->type_mgr().Get(std::make_unique<ast::type::StorageTextureType>( ctx()->type_mgr().Get(std::make_unique<ast::type::StorageTextureType>(
dim, ast::type::StorageAccess::kRead, format)); dim, ast::AccessControl::kReadOnly, format));
ast::ExpressionList call_params; ast::ExpressionList call_params;

View File

@ -383,7 +383,7 @@ TEST_F(HlslGeneratorImplTest_Function,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadWrite, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -449,7 +449,7 @@ TEST_F(HlslGeneratorImplTest_Function,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadOnly, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -515,7 +515,7 @@ TEST_F(HlslGeneratorImplTest_Function,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadWrite, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
@ -899,7 +899,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::VectorType vec4(&f32, 4); ast::type::VectorType vec4(&f32, 4);
ast::type::AccessControlType ac(ast::type::AccessControl::kReadWrite, &vec4); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &vec4);
auto coord_var = auto coord_var =
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
"coord", ast::StorageClass::kStorageBuffer, &ac)); "coord", ast::StorageClass::kStorageBuffer, &ac));

View File

@ -347,7 +347,7 @@ TEST_F(MslGeneratorImplTest,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadWrite, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
mod.AddConstructedType(&s); mod.AddConstructedType(&s);
@ -426,7 +426,7 @@ TEST_F(MslGeneratorImplTest,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadOnly, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
mod.AddConstructedType(&s); mod.AddConstructedType(&s);
@ -857,7 +857,7 @@ TEST_F(MslGeneratorImplTest,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadWrite, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
mod.AddConstructedType(&s); mod.AddConstructedType(&s);
@ -958,7 +958,7 @@ TEST_F(MslGeneratorImplTest,
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::type::AccessControl::kReadOnly, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadOnly, &s);
mod.AddConstructedType(&s); mod.AddConstructedType(&s);

View File

@ -2362,7 +2362,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
} else if (texture->IsMultisampled()) { } else if (texture->IsMultisampled()) {
type_id = GenerateTypeIfNeeded(texture->AsMultisampled()->type()); type_id = GenerateTypeIfNeeded(texture->AsMultisampled()->type());
} else if (texture->IsStorage()) { } else if (texture->IsStorage()) {
if (texture->AsStorage()->access() == ast::type::StorageAccess::kWrite) { if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
type_id = GenerateTypeIfNeeded(&void_type); type_id = GenerateTypeIfNeeded(&void_type);
} else { } else {

View File

@ -588,7 +588,7 @@ TEST_F(BuilderTest, Call_TextureLoad_Storage_RO_1d) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, ast::type::StorageTextureType s(ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
Context ctx; Context ctx;
@ -640,7 +640,7 @@ TEST_F(BuilderTest, Call_TextureLoad_Storage_RO_2d) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::type::VectorType vec2(&f32, 2); ast::type::VectorType vec2(&f32, 2);
ast::type::StorageTextureType s(ast::type::TextureDimension::k2d, ast::type::StorageTextureType s(ast::type::TextureDimension::k2d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
Context ctx; Context ctx;

View File

@ -952,7 +952,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R16Float) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, ast::type::StorageTextureType s(ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -970,7 +970,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8SNorm) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, ast::type::StorageTextureType s(ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR8Snorm); ast::type::ImageFormat::kR8Snorm);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -988,7 +988,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8UNorm) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, ast::type::StorageTextureType s(ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR8Unorm); ast::type::ImageFormat::kR8Unorm);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1006,7 +1006,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_array) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1dArray, ast::type::StorageTextureType s(ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1024,7 +1024,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_2d) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k2d, ast::type::StorageTextureType s(ast::type::TextureDimension::k2d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1042,7 +1042,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_2dArray) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k2dArray, ast::type::StorageTextureType s(ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1060,7 +1060,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_3d) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k3d, ast::type::StorageTextureType s(ast::type::TextureDimension::k3d,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1078,7 +1078,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_1d) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, ast::type::StorageTextureType s(ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1096,7 +1096,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_1dArray) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k1dArray, ast::type::StorageTextureType s(ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1114,7 +1114,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_2d) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k2d, ast::type::StorageTextureType s(ast::type::TextureDimension::k2d,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1132,7 +1132,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_2dArray) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k2dArray, ast::type::StorageTextureType s(ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
@ -1150,7 +1150,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_3d) {
Builder b(&mod); Builder b(&mod);
ast::type::StorageTextureType s(ast::type::TextureDimension::k3d, ast::type::StorageTextureType s(ast::type::TextureDimension::k3d,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();

View File

@ -465,9 +465,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
} else if (texture->IsStorage()) { } else if (texture->IsStorage()) {
auto* storage = texture->AsStorage(); auto* storage = texture->AsStorage();
if (storage->access() == ast::type::StorageAccess::kRead) { if (storage->access() == ast::AccessControl::kReadOnly) {
out_ << "ro_"; out_ << "ro_";
} else if (storage->access() == ast::type::StorageAccess::kWrite) { } else if (storage->access() == ast::AccessControl::kWriteOnly) {
out_ << "wo_"; out_ << "wo_";
} else { } else {
error_ = "unknown storage texture access"; error_ = "unknown storage texture access";

View File

@ -368,7 +368,7 @@ INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest,
struct StorageTextureData { struct StorageTextureData {
ast::type::ImageFormat fmt; ast::type::ImageFormat fmt;
ast::type::TextureDimension dim; ast::type::TextureDimension dim;
ast::type::StorageAccess access; ast::AccessControl access;
const char* name; const char* name;
}; };
inline std::ostream& operator<<(std::ostream& out, StorageTextureData data) { inline std::ostream& operator<<(std::ostream& out, StorageTextureData data) {
@ -392,38 +392,38 @@ INSTANTIATE_TEST_SUITE_P(
testing::Values( testing::Values(
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kRead, "texture_ro_1d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_ro_1d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k1dArray, ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
"texture_ro_1d_array<r8unorm>"}, "texture_ro_1d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d,
ast::type::StorageAccess::kRead, "texture_ro_2d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_ro_2d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k2dArray, ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kRead, ast::AccessControl::kReadOnly,
"texture_ro_2d_array<r8unorm>"}, "texture_ro_2d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d,
ast::type::StorageAccess::kRead, "texture_ro_3d<r8unorm>"}, ast::AccessControl::kReadOnly, "texture_ro_3d<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k1d,
ast::type::StorageAccess::kWrite, "texture_wo_1d<r8unorm>"}, ast::AccessControl::kWriteOnly, "texture_wo_1d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k1dArray, ast::type::TextureDimension::k1dArray,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
"texture_wo_1d_array<r8unorm>"}, "texture_wo_1d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k2d,
ast::type::StorageAccess::kWrite, "texture_wo_2d<r8unorm>"}, ast::AccessControl::kWriteOnly, "texture_wo_2d<r8unorm>"},
StorageTextureData{ast::type::ImageFormat::kR8Unorm, StorageTextureData{ast::type::ImageFormat::kR8Unorm,
ast::type::TextureDimension::k2dArray, ast::type::TextureDimension::k2dArray,
ast::type::StorageAccess::kWrite, ast::AccessControl::kWriteOnly,
"texture_wo_2d_array<r8unorm>"}, "texture_wo_2d_array<r8unorm>"},
StorageTextureData{ StorageTextureData{
ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d, ast::type::ImageFormat::kR8Unorm, ast::type::TextureDimension::k3d,
ast::type::StorageAccess::kWrite, "texture_wo_3d<r8unorm>"})); ast::AccessControl::kWriteOnly, "texture_wo_3d<r8unorm>"}));
struct ImageFormatData { struct ImageFormatData {
ast::type::ImageFormat fmt; ast::type::ImageFormat fmt;