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

43
src/ast/access.cc Normal file
View File

@@ -0,0 +1,43 @@
// 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.h"
namespace tint {
namespace ast {
std::ostream& operator<<(std::ostream& out, Access access) {
switch (access) {
case ast::Access::kUndefined: {
out << "undefined";
break;
}
case ast::Access::kRead: {
out << "read";
break;
}
case ast::Access::kReadWrite: {
out << "read_write";
break;
}
case ast::Access::kWrite: {
out << "write";
break;
}
}
return out;
}
} // namespace ast
} // namespace tint

47
src/ast/access.h Normal file
View File

@@ -0,0 +1,47 @@
// 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_H_
#define SRC_AST_ACCESS_H_
#include <ostream>
#include <string>
namespace tint {
namespace ast {
/// The access control settings
enum Access {
/// Not declared in the source
kUndefined,
/// Read only
kRead,
/// Write only
kWrite,
/// Read write
kReadWrite
};
/// @param out the std::ostream to write to
/// @param access the Access
/// @return the std::ostream so calls can be chained
std::ostream& operator<<(std::ostream& out, Access access);
/// [DEPRECATED]: Old name in use by Dawn.
using AccessControl = Access;
} // namespace ast
} // namespace tint
#endif // SRC_AST_ACCESS_H_

View File

@@ -1,97 +0,0 @@
// 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"
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::AccessControl);
namespace tint {
namespace ast {
AccessControl::AccessControl(ProgramID program_id,
const Source& source,
Access access,
const Type* subtype)
: Base(program_id, source), access_(access), subtype_(subtype) {
TINT_ASSERT(subtype_);
TINT_ASSERT(!subtype_->Is<AccessControl>());
}
AccessControl::AccessControl(AccessControl&&) = default;
AccessControl::~AccessControl() = default;
std::string AccessControl::type_name() const {
std::string name = "__access_control_";
switch (access_) {
case ast::AccessControl::kRead:
name += "read_only";
break;
case ast::AccessControl::kWrite:
name += "write_only";
break;
case ast::AccessControl::kReadWrite:
name += "read_write";
break;
}
return name + subtype_->type_name();
}
std::string AccessControl::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "[[access(";
switch (access_) {
case ast::AccessControl::kRead:
out << "read";
break;
case ast::AccessControl::kWrite:
out << "write";
break;
case ast::AccessControl::kReadWrite:
out << "read_write";
break;
}
out << ")]] " << subtype_->FriendlyName(symbols);
return out.str();
}
AccessControl* AccessControl::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
auto* ty = ctx->Clone(type());
return ctx->dst->create<AccessControl>(src, access_, ty);
}
std::ostream& operator<<(std::ostream& out, AccessControl::Access access) {
switch (access) {
case ast::AccessControl::kRead: {
out << "read_only";
break;
}
case ast::AccessControl::kReadWrite: {
out << "read_write";
break;
}
case ast::AccessControl::kWrite: {
out << "write_only";
break;
}
}
return out;
}
} // namespace ast
} // namespace tint

View File

@@ -1,90 +0,0 @@
// 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>
#include <string>
#include "src/ast/type.h"
namespace tint {
namespace ast {
/// An access control type. Holds an access setting and pointer to another type.
class AccessControl : public Castable<AccessControl, Type> {
public:
/// The access control settings
enum Access {
/// Read only
kRead,
/// Write only
kWrite,
/// Read write
kReadWrite
};
/// Constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this node
/// @param access the access control setting
/// @param subtype the access controlled type
AccessControl(ProgramID program_id,
const Source& source,
Access access,
const Type* subtype);
/// Move constructor
AccessControl(AccessControl&&);
~AccessControl() override;
/// @returns true if the access control is read only
bool IsReadOnly() const { return access_ == Access::kRead; }
/// @returns true if the access control is write only
bool IsWriteOnly() const { return access_ == Access::kWrite; }
/// @returns true if the access control is read/write
bool IsReadWrite() const { return access_ == Access::kReadWrite; }
/// @returns the access control value
Access access_control() const { return access_; }
/// @returns the subtype type
Type* type() const { return const_cast<Type*>(subtype_); }
/// @returns the name for this type
std::string type_name() const override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
AccessControl* Clone(CloneContext* ctx) const override;
private:
Access const access_;
const Type* const subtype_;
};
/// @param out the std::ostream to write to
/// @param access the AccessControl
/// @return the std::ostream so calls can be chained
std::ostream& operator<<(std::ostream& out, AccessControl::Access access);
} // namespace ast
} // namespace tint
#endif // SRC_AST_ACCESS_CONTROL_H_

View File

@@ -1,94 +0,0 @@
// 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"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {
namespace {
using AstAccessControlTest = TestHelper;
TEST_F(AstAccessControlTest, Create) {
auto* u32 = create<U32>();
auto* a = create<AccessControl>(AccessControl::kReadWrite, u32);
EXPECT_TRUE(a->IsReadWrite());
EXPECT_EQ(a->type(), u32);
}
TEST_F(AstAccessControlTest, AccessRead) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kRead, i32);
EXPECT_TRUE(ac->IsReadOnly());
EXPECT_FALSE(ac->IsWriteOnly());
EXPECT_FALSE(ac->IsReadWrite());
EXPECT_EQ(ac->type_name(), "__access_control_read_only__i32");
}
TEST_F(AstAccessControlTest, AccessWrite) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kWrite, i32);
EXPECT_FALSE(ac->IsReadOnly());
EXPECT_TRUE(ac->IsWriteOnly());
EXPECT_FALSE(ac->IsReadWrite());
EXPECT_EQ(ac->type_name(), "__access_control_write_only__i32");
}
TEST_F(AstAccessControlTest, AccessReadWrite) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kReadWrite, i32);
EXPECT_FALSE(ac->IsReadOnly());
EXPECT_FALSE(ac->IsWriteOnly());
EXPECT_TRUE(ac->IsReadWrite());
EXPECT_EQ(ac->type_name(), "__access_control_read_write__i32");
}
TEST_F(AstAccessControlTest, FriendlyNameReadOnly) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kRead, i32);
EXPECT_EQ(ac->FriendlyName(Symbols()), "[[access(read)]] i32");
}
TEST_F(AstAccessControlTest, FriendlyNameWriteOnly) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kWrite, i32);
EXPECT_EQ(ac->FriendlyName(Symbols()), "[[access(write)]] i32");
}
TEST_F(AstAccessControlTest, FriendlyNameReadWrite) {
auto* i32 = create<I32>();
auto* ac = create<AccessControl>(AccessControl::kReadWrite, i32);
EXPECT_EQ(ac->FriendlyName(Symbols()), "[[access(read_write)]] i32");
}
} // namespace
} // namespace ast
} // namespace tint

View File

@@ -23,7 +23,7 @@ namespace ast {
AccessDecoration::AccessDecoration(ProgramID program_id,
const Source& source,
AccessControl::Access val)
Access val)
: Base(program_id, source), value_(val) {}
AccessDecoration::~AccessDecoration() = default;

View File

@@ -15,26 +15,25 @@
#ifndef SRC_AST_ACCESS_DECORATION_H_
#define SRC_AST_ACCESS_DECORATION_H_
#include "src/ast/access_control.h"
#include "src/ast/access.h"
#include "src/ast/decoration.h"
namespace tint {
namespace ast {
/// An access decoration
/// [DEPRECATED]: TODO(crbug.com/tint/846): Remove this class
class AccessDecoration : public Castable<AccessDecoration, Decoration> {
public:
/// constructor
/// @param program_id the identifier of the program that owns this node
/// @param source the source of this decoration
/// @param value the access value
AccessDecoration(ProgramID program_id,
const Source& source,
AccessControl::Access value);
AccessDecoration(ProgramID program_id, const Source& source, Access value);
~AccessDecoration() override;
/// @returns the access control value
AccessControl::Access value() const { return value_; }
Access value() const { return value_; }
/// Outputs the decoration to the given stream
/// @param sem the semantic info for the program
@@ -51,7 +50,7 @@ class AccessDecoration : public Castable<AccessDecoration, Decoration> {
AccessDecoration* Clone(CloneContext* ctx) const override;
private:
AccessControl::Access const value_;
Access const value_;
};
} // namespace ast

View File

@@ -23,13 +23,13 @@ namespace {
using AccessDecorationTest = TestHelper;
TEST_F(AccessDecorationTest, Creation) {
auto* d = create<AccessDecoration>(ast::AccessControl::kWrite);
EXPECT_EQ(ast::AccessControl::kWrite, d->value());
auto* d = create<AccessDecoration>(ast::Access::kWrite);
EXPECT_EQ(ast::Access::kWrite, d->value());
}
TEST_F(AccessDecorationTest, ToStr) {
auto* d = create<AccessDecoration>(ast::AccessControl::kRead);
EXPECT_EQ(str(d), R"(AccessDecoration{read_only}
auto* d = create<AccessDecoration>(ast::Access::kRead);
EXPECT_EQ(str(d), R"(AccessDecoration{read}
)");
}

View File

@@ -13,7 +13,7 @@
// limitations under the License.
#include "src/ast/alias.h"
#include "src/ast/access_control.h"
#include "src/ast/access.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
@@ -76,23 +76,6 @@ TEST_F(AstAliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
EXPECT_EQ(aapaa->UnwrapAll(), u32);
}
TEST_F(AstAliasTest, UnwrapAll_AccessControlPointer) {
auto* u32 = create<U32>();
auto* a = create<AccessControl>(AccessControl::kRead, u32);
auto* pa = create<Pointer>(a, StorageClass::kUniform);
EXPECT_EQ(pa->type(), a);
EXPECT_EQ(pa->UnwrapAll(), u32);
}
TEST_F(AstAliasTest, UnwrapAll_PointerAccessControl) {
auto* u32 = create<U32>();
auto* p = create<Pointer>(u32, StorageClass::kUniform);
auto* a = create<AccessControl>(AccessControl::kRead, p);
EXPECT_EQ(a->type(), p);
EXPECT_EQ(a->UnwrapAll(), u32);
}
} // namespace
} // namespace ast
} // namespace tint

View File

@@ -13,19 +13,8 @@
// limitations under the License.
#include "src/ast/array.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -14,7 +14,6 @@
#include "src/ast/type.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
@@ -43,8 +42,6 @@ Type* Type::UnwrapAll() {
while (true) {
if (auto* alias = type->As<Alias>()) {
type = alias->type();
} else if (auto* access = type->As<AccessControl>()) {
type = access->type();
} else if (auto* ptr = type->As<Pointer>()) {
type = ptr->type();
} else {

View File

@@ -13,19 +13,8 @@
// limitations under the License.
#include "src/ast/bool.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -13,22 +13,8 @@
// limitations under the License.
#include "src/ast/depth_texture.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampled_texture.h"
#include "src/ast/sampler.h"
#include "src/ast/storage_texture.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -14,22 +14,7 @@
#include "src/ast/external_texture.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/depth_texture.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/storage_texture.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -13,19 +13,8 @@
// limitations under the License.
#include "src/ast/f32.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -189,6 +189,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
VariableConst{
var
none
undefined
__i32
}
)

View File

@@ -14,19 +14,7 @@
#include "src/ast/i32.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -62,7 +62,7 @@ TextureOverloadCase::TextureOverloadCase(
TextureOverloadCase::TextureOverloadCase(
ValidTextureOverload o,
const char* d,
AccessControl::Access access,
Access acc,
ast::ImageFormat i,
ast::TextureDimension dims,
TextureDataType datatype,
@@ -71,7 +71,7 @@ TextureOverloadCase::TextureOverloadCase(
: overload(o),
description(d),
texture_kind(TextureKind::kStorage),
access_control(access),
access(acc),
image_format(i),
texture_dimension(dims),
texture_data_type(datatype),
@@ -124,7 +124,7 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) {
out << "<unused>";
}
out << "\n";
out << "access_control: " << data.access_control << "\n";
out << "access: " << data.access << "\n";
out << "image_format: " << data.image_format << "\n";
out << "texture_dimension: " << data.texture_dimension << "\n";
out << "texture_data_type: " << data.texture_data_type << "\n";
@@ -157,23 +157,22 @@ ast::Variable* TextureOverloadCase::buildTextureVariable(
return b->Global("texture",
b->ty.sampled_texture(texture_dimension,
buildResultVectorComponentType(b)),
ast::StorageClass::kNone, nullptr, decos);
decos);
case ast::intrinsic::test::TextureKind::kDepth:
return b->Global("texture", b->ty.depth_texture(texture_dimension),
ast::StorageClass::kNone, nullptr, decos);
decos);
case ast::intrinsic::test::TextureKind::kMultisampled:
return b->Global(
"texture",
b->ty.multisampled_texture(texture_dimension,
buildResultVectorComponentType(b)),
ast::StorageClass::kNone, nullptr, decos);
decos);
case ast::intrinsic::test::TextureKind::kStorage: {
auto* st = b->ty.storage_texture(texture_dimension, image_format);
auto* ac = b->ty.access(access_control, st);
return b->Global("texture", ac, ast::StorageClass::kNone, nullptr, decos);
auto* st = b->ty.storage_texture(texture_dimension, image_format, access);
return b->Global("texture", st, decos);
}
}
@@ -187,8 +186,7 @@ ast::Variable* TextureOverloadCase::buildSamplerVariable(
b->create<ast::GroupDecoration>(0),
b->create<ast::BindingDecoration>(1),
};
return b->Global("sampler", b->ty.sampler(sampler_kind),
ast::StorageClass::kNone, nullptr, decos);
return b->Global("sampler", b->ty.sampler(sampler_kind), decos);
}
std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
@@ -405,7 +403,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
{
ValidTextureOverload::kDimensionsStorageRO1d,
"textureDimensions(t : texture_storage_1d<rgba32float>) -> i32",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k1d,
TextureDataType::kF32,
@@ -416,7 +414,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageRO2d,
"textureDimensions(t : texture_storage_2d<rgba32float>) -> "
"vec2<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -427,7 +425,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageRO2dArray,
"textureDimensions(t : texture_storage_2d_array<rgba32float>) -> "
"vec2<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2dArray,
TextureDataType::kF32,
@@ -438,7 +436,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageRO3d,
"textureDimensions(t : texture_storage_3d<rgba32float>) -> "
"vec3<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k3d,
TextureDataType::kF32,
@@ -448,7 +446,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
{
ValidTextureOverload::kDimensionsStorageWO1d,
"textureDimensions(t : texture_storage_1d<rgba32float>) -> i32",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k1d,
TextureDataType::kF32,
@@ -459,7 +457,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageWO2d,
"textureDimensions(t : texture_storage_2d<rgba32float>) -> "
"vec2<i32>",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -470,7 +468,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageWO2dArray,
"textureDimensions(t : texture_storage_2d_array<rgba32float>) -> "
"vec2<i32>",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2dArray,
TextureDataType::kF32,
@@ -481,7 +479,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kDimensionsStorageWO3d,
"textureDimensions(t : texture_storage_3d<rgba32float>) -> "
"vec3<i32>",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k3d,
TextureDataType::kF32,
@@ -531,7 +529,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
{
ValidTextureOverload::kNumLayersStorageWO2dArray,
"textureNumLayers(t : texture_storage_2d_array<rgba32float>) -> i32",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2dArray,
TextureDataType::kF32,
@@ -1887,7 +1885,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO1dRgba32float,
"textureLoad(t : texture_storage_1d<rgba32float>,\n"
" coords : i32) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k1d,
TextureDataType::kF32,
@@ -1901,7 +1899,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba8unorm,
"textureLoad(t : texture_storage_2d<rgba8unorm>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba8Unorm,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -1915,7 +1913,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba8snorm,
"textureLoad(t : texture_storage_2d<rgba8snorm>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba8Snorm,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -1929,7 +1927,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba8uint,
"textureLoad(t : texture_storage_2d<rgba8uint>,\n"
" coords : vec2<i32>) -> vec4<u32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba8Uint,
ast::TextureDimension::k2d,
TextureDataType::kU32,
@@ -1943,7 +1941,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba8sint,
"textureLoad(t : texture_storage_2d<rgba8sint>,\n"
" coords : vec2<i32>) -> vec4<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba8Sint,
ast::TextureDimension::k2d,
TextureDataType::kI32,
@@ -1957,7 +1955,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba16uint,
"textureLoad(t : texture_storage_2d<rgba16uint>,\n"
" coords : vec2<i32>) -> vec4<u32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba16Uint,
ast::TextureDimension::k2d,
TextureDataType::kU32,
@@ -1971,7 +1969,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba16sint,
"textureLoad(t : texture_storage_2d<rgba16sint>,\n"
" coords : vec2<i32>) -> vec4<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba16Sint,
ast::TextureDimension::k2d,
TextureDataType::kI32,
@@ -1985,7 +1983,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba16float,
"textureLoad(t : texture_storage_2d<rgba16float>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba16Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -1999,7 +1997,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dR32uint,
"textureLoad(t : texture_storage_2d<r32uint>,\n"
" coords : vec2<i32>) -> vec4<u32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kR32Uint,
ast::TextureDimension::k2d,
TextureDataType::kU32,
@@ -2013,7 +2011,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dR32sint,
"textureLoad(t : texture_storage_2d<r32sint>,\n"
" coords : vec2<i32>) -> vec4<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kR32Sint,
ast::TextureDimension::k2d,
TextureDataType::kI32,
@@ -2027,7 +2025,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dR32float,
"textureLoad(t : texture_storage_2d<r32float>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kR32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -2041,7 +2039,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRg32uint,
"textureLoad(t : texture_storage_2d<rg32uint>,\n"
" coords : vec2<i32>) -> vec4<u32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRg32Uint,
ast::TextureDimension::k2d,
TextureDataType::kU32,
@@ -2055,7 +2053,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRg32sint,
"textureLoad(t : texture_storage_2d<rg32sint>,\n"
" coords : vec2<i32>) -> vec4<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRg32Sint,
ast::TextureDimension::k2d,
TextureDataType::kI32,
@@ -2069,7 +2067,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRg32float,
"textureLoad(t : texture_storage_2d<rg32float>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRg32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -2083,7 +2081,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba32uint,
"textureLoad(t : texture_storage_2d<rgba32uint>,\n"
" coords : vec2<i32>) -> vec4<u32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Uint,
ast::TextureDimension::k2d,
TextureDataType::kU32,
@@ -2097,7 +2095,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba32sint,
"textureLoad(t : texture_storage_2d<rgba32sint>,\n"
" coords : vec2<i32>) -> vec4<i32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Sint,
ast::TextureDimension::k2d,
TextureDataType::kI32,
@@ -2111,7 +2109,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO2dRgba32float,
"textureLoad(t : texture_storage_2d<rgba32float>,\n"
" coords : vec2<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -2127,7 +2125,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
"texture_storage_2d_array<rgba32float>,\n"
" coords : vec2<i32>,\n"
" array_index : i32) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2dArray,
TextureDataType::kF32,
@@ -2142,7 +2140,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
ValidTextureOverload::kLoadStorageRO3dRgba32float,
"textureLoad(t : texture_storage_3d<rgba32float>,\n"
" coords : vec3<i32>) -> vec4<f32>",
ast::AccessControl::kRead,
ast::Access::kRead,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k3d,
TextureDataType::kF32,
@@ -2157,7 +2155,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
"textureStore(t : texture_storage_1d<rgba32float>,\n"
" coords : i32,\n"
" value : vec4<T>)",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k1d,
TextureDataType::kF32,
@@ -2173,7 +2171,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
"textureStore(t : texture_storage_2d<rgba32float>,\n"
" coords : vec2<i32>,\n"
" value : vec4<T>)",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2d,
TextureDataType::kF32,
@@ -2190,7 +2188,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
" coords : vec2<i32>,\n"
" array_index : i32,\n"
" value : vec4<T>)",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k2dArray,
TextureDataType::kF32,
@@ -2207,7 +2205,7 @@ std::vector<TextureOverloadCase> TextureOverloadCase::ValidCases() {
"textureStore(t : texture_storage_3d<rgba32float>,\n"
" coords : vec3<i32>,\n"
" value : vec4<T>)",
ast::AccessControl::kWrite,
ast::Access::kWrite,
ast::ImageFormat::kRgba32Float,
ast::TextureDimension::k3d,
TextureDataType::kF32,

View File

@@ -17,7 +17,7 @@
#include <vector>
#include "src/ast/access_control.h"
#include "src/ast/access.h"
#include "src/program_builder.h"
#include "src/sem/storage_texture_type.h"
@@ -192,7 +192,7 @@ struct TextureOverloadCase {
/// Constructor for textureLoad() with storage textures
TextureOverloadCase(ValidTextureOverload,
const char*,
AccessControl::Access,
Access,
ast::ImageFormat,
ast::TextureDimension,
TextureDataType,
@@ -230,7 +230,7 @@ struct TextureOverloadCase {
ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler;
/// The access control for the storage texture
/// Used only when texture_kind is kStorage
AccessControl::Access const access_control = AccessControl::kReadWrite;
Access const access = Access::kReadWrite;
/// The image format for the storage texture
/// Used only when texture_kind is kStorage
ast::ImageFormat const image_format = ast::ImageFormat::kNone;

View File

@@ -13,7 +13,7 @@
// limitations under the License.
#include "src/ast/matrix.h"
#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"

View File

@@ -42,15 +42,15 @@ type t1 = array<vec4<f32>>;
var<private> g0 : u32 = 20u;
var<private> g1 : f32 = 123.0;
[[group(0), binding(0)]] var g2 : texture_2d<f32>;
[[group(1), binding(0)]] var g3 : [[access(read)]] texture_storage_2d<r32uint>;
[[group(2), binding(0)]] var g4 : [[access(write)]] texture_storage_2d<rg32float>;
[[group(3), binding(0)]] var g5 : [[access(read)]] texture_storage_2d<r32uint>;
[[group(4), binding(0)]] var g6 : [[access(write)]] texture_storage_2d<rg32float>;
[[group(1), binding(0)]] var g3 : texture_storage_2d<r32uint, read>;
[[group(2), binding(0)]] var g4 : texture_storage_2d<rg32float, write>;
[[group(3), binding(0)]] var g5 : texture_storage_2d<r32uint, read>;
[[group(4), binding(0)]] var g6 : texture_storage_2d<rg32float, write>;
var<private> g7 : vec3<f32>;
[[group(0), binding(1)]] var<storage> g8 : [[access(write)]] S;
[[group(1), binding(1)]] var<storage> g9 : [[access(read)]] S;
[[group(2), binding(1)]] var<storage> g10 : [[access(read_write)]] S;
[[group(0), binding(1)]] var<storage, write> g8 : S;
[[group(1), binding(1)]] var<storage, read> g9 : S;
[[group(2), binding(1)]] var<storage, read_write> g10 : S;
fn f0(p0 : bool) -> f32 {
if (p0) {

View File

@@ -14,7 +14,7 @@
#include "src/ast/multisampled_texture.h"
#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"

View File

@@ -13,19 +13,9 @@
// limitations under the License.
#include "src/ast/pointer.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -14,22 +14,8 @@
#include "src/ast/sampled_texture.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/depth_texture.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/storage_texture.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -13,19 +13,8 @@
// limitations under the License.
#include "src/ast/sampler.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -144,8 +144,12 @@ StorageTexture::StorageTexture(ProgramID program_id,
const Source& source,
TextureDimension dim,
ImageFormat format,
Type* subtype)
: Base(program_id, source, dim), image_format_(format), subtype_(subtype) {}
Type* subtype,
Access access)
: Base(program_id, source, dim),
image_format_(format),
subtype_(subtype),
access_(access) {}
StorageTexture::StorageTexture(StorageTexture&&) = default;
@@ -153,13 +157,15 @@ StorageTexture::~StorageTexture() = default;
std::string StorageTexture::type_name() const {
std::ostringstream out;
out << "__storage_texture_" << dim() << "_" << image_format_;
out << "__storage_texture_" << dim() << "_" << image_format_ << "_"
<< access_;
return out.str();
}
std::string StorageTexture::FriendlyName(const SymbolTable&) const {
std::ostringstream out;
out << "texture_storage_" << dim() << "<" << image_format_ << ">";
out << "texture_storage_" << dim() << "<" << image_format_ << ", " << access_
<< ">";
return out.str();
}
@@ -167,7 +173,8 @@ StorageTexture* StorageTexture::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
auto* ty = ctx->Clone(type());
return ctx->dst->create<StorageTexture>(src, dim(), image_format_, ty);
return ctx->dst->create<StorageTexture>(src, dim(), image_format(), ty,
access());
}
Type* StorageTexture::SubtypeFor(ImageFormat format, ProgramBuilder& builder) {

View File

@@ -17,6 +17,7 @@
#include <string>
#include "src/ast/access.h"
#include "src/ast/texture.h"
namespace tint {
@@ -78,21 +79,33 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
/// @param dim the dimensionality of the texture
/// @param format the image format of the texture
/// @param subtype the storage subtype. Use SubtypeFor() to calculate this.
/// @param access_control the access control for the texture.
StorageTexture(ProgramID program_id,
const Source& source,
TextureDimension dim,
ImageFormat format,
Type* subtype);
Type* subtype,
Access access_control);
/// Move constructor
StorageTexture(StorageTexture&&);
~StorageTexture() override;
/// @returns the image format
ImageFormat image_format() const { return image_format_; }
/// @returns the storage subtype
Type* type() const { return subtype_; }
/// @returns the image format
ImageFormat image_format() const { return image_format_; }
/// @returns the access control
Access access() const { return access_; }
/// @returns true if the access control is read only
bool is_read_only() const { return access_ == Access::kRead; }
/// @returns true if the access control is write only
bool is_write_only() const { return access_ == Access::kWrite; }
/// @returns true if the access control is read/write
bool is_read_write() const { return access_ == Access::kReadWrite; }
/// @returns the name for this type
std::string type_name() const override;
@@ -115,6 +128,7 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
private:
ImageFormat const image_format_;
Type* const subtype_;
Access const access_;
};
} // namespace ast

View File

@@ -13,22 +13,8 @@
// limitations under the License.
#include "src/ast/storage_texture.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/depth_texture.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampled_texture.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {
@@ -38,8 +24,9 @@ using AstStorageTextureTest = TestHelper;
TEST_F(AstStorageTextureTest, IsTexture) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
Texture* ty = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
Texture* ty =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<SampledTexture>());
EXPECT_TRUE(ty->Is<StorageTexture>());
@@ -47,37 +34,42 @@ TEST_F(AstStorageTextureTest, IsTexture) {
TEST_F(AstStorageTextureTest, Dim) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
auto* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
auto* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
EXPECT_EQ(s->dim(), TextureDimension::k2dArray);
}
TEST_F(AstStorageTextureTest, Format) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
auto* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
auto* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
EXPECT_EQ(s->image_format(), ImageFormat::kRgba32Float);
}
TEST_F(AstStorageTextureTest, TypeName) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
auto* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float");
auto* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float_read");
}
TEST_F(AstStorageTextureTest, FriendlyName) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
auto* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
auto* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
EXPECT_EQ(s->FriendlyName(Symbols()),
"texture_storage_2d_array<rgba32float>");
"texture_storage_2d_array<rgba32float, read>");
}
TEST_F(AstStorageTextureTest, F32) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, *this);
Type* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype);
Type* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Float, subtype, Access::kRead);
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
@@ -86,8 +78,9 @@ TEST_F(AstStorageTextureTest, F32) {
TEST_F(AstStorageTextureTest, U32) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRg32Uint, *this);
Type* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRg32Uint, subtype);
Type* s =
create<StorageTexture>(TextureDimension::k2dArray, ImageFormat::kRg32Uint,
subtype, Access::kRead);
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
@@ -96,8 +89,9 @@ TEST_F(AstStorageTextureTest, U32) {
TEST_F(AstStorageTextureTest, I32) {
auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, *this);
Type* s = create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Sint, subtype);
Type* s =
create<StorageTexture>(TextureDimension::k2dArray,
ImageFormat::kRgba32Sint, subtype, Access::kRead);
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());

View File

@@ -14,19 +14,7 @@
#include "src/ast/u32.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/vector.h"
namespace tint {
namespace ast {

View File

@@ -27,6 +27,7 @@ Variable::Variable(ProgramID program_id,
const Source& source,
const Symbol& sym,
StorageClass declared_storage_class,
Access declared_access,
const ast::Type* type,
bool is_const,
Expression* constructor,
@@ -37,7 +38,8 @@ Variable::Variable(ProgramID program_id,
is_const_(is_const),
constructor_(constructor),
decorations_(std::move(decorations)),
declared_storage_class_(declared_storage_class) {
declared_storage_class_(declared_storage_class),
declared_access_(declared_access) {
TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id);
@@ -66,8 +68,9 @@ Variable* Variable::Clone(CloneContext* ctx) const {
auto* ty = ctx->Clone(type());
auto* ctor = ctx->Clone(constructor());
auto decos = ctx->Clone(decorations());
return ctx->dst->create<Variable>(src, sym, declared_storage_class(), ty,
is_const_, ctor, decos);
return ctx->dst->create<Variable>(src, sym, declared_storage_class(),
declared_access(), ty, is_const_, ctor,
decos);
}
void Variable::info_to_str(const sem::Info& sem,
@@ -80,6 +83,8 @@ void Variable::info_to_str(const sem::Info& sem,
out << (var_sem ? var_sem->StorageClass() : declared_storage_class())
<< std::endl;
make_indent(out, indent);
out << declared_access_ << std::endl;
make_indent(out, indent);
out << type_->type_name() << std::endl;
}

View File

@@ -18,6 +18,7 @@
#include <utility>
#include <vector>
#include "src/ast/access.h"
#include "src/ast/decoration.h"
#include "src/ast/expression.h"
#include "src/ast/storage_class.h"
@@ -103,6 +104,7 @@ class Variable : public Castable<Variable, Node> {
/// @param source the variable source
/// @param sym the variable symbol
/// @param declared_storage_class the declared storage class
/// @param declared_access the declared access control
/// @param type the declared variable type
/// @param is_const true if the variable is const
/// @param constructor the constructor expression
@@ -111,6 +113,7 @@ class Variable : public Castable<Variable, Node> {
const Source& source,
const Symbol& sym,
StorageClass declared_storage_class,
Access declared_access,
const ast::Type* type,
bool is_const,
Expression* constructor,
@@ -130,6 +133,10 @@ class Variable : public Castable<Variable, Node> {
StorageClass declared_storage_class() const {
return declared_storage_class_;
}
/// @returns the declared access control
Access declared_access() const { return declared_access_; }
/// @returns the constructor expression or nullptr if none set
Expression* constructor() const { return constructor_; }
/// @returns true if the variable has an constructor
@@ -184,6 +191,7 @@ class Variable : public Castable<Variable, Node> {
Expression* const constructor_;
DecorationList const decorations_;
StorageClass const declared_storage_class_;
Access const declared_access_;
};
/// A list of variables

View File

@@ -76,6 +76,7 @@ TEST_F(VariableDeclStatementTest, ToStr) {
Variable{
a
none
undefined
__f32
}
}

View File

@@ -92,10 +92,12 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
}
TEST_F(VariableTest, to_str) {
auto* v = Var("my_var", ty.f32(), StorageClass::kFunction);
auto* v =
Var("my_var", ty.f32(), StorageClass::kFunction, ast::Access::kReadWrite);
EXPECT_EQ(str(v), R"(Variable{
my_var
function
read_write
__f32
}
)");
@@ -161,7 +163,8 @@ TEST_F(VariableTest, BindingPointMissingBindingDecoration) {
}
TEST_F(VariableTest, Decorated_to_str) {
auto* var = Var("my_var", ty.f32(), StorageClass::kFunction, Expr("expr"),
auto* var = Var("my_var", ty.f32(), StorageClass::kFunction,
ast::Access::kRead, Expr("expr"),
DecorationList{
create<BindingDecoration>(2),
create<GroupDecoration>(1),
@@ -174,6 +177,7 @@ TEST_F(VariableTest, Decorated_to_str) {
}
my_var
function
read
__f32
{
Identifier[not set]{expr}

View File

@@ -13,19 +13,9 @@
// limitations under the License.
#include "src/ast/vector.h"
#include "src/ast/access_control.h"
#include "src/ast/alias.h"
#include "src/ast/array.h"
#include "src/ast/bool.h"
#include "src/ast/f32.h"
#include "src/ast/i32.h"
#include "src/ast/matrix.h"
#include "src/ast/pointer.h"
#include "src/ast/sampler.h"
#include "src/ast/struct.h"
#include "src/ast/test_helper.h"
#include "src/ast/texture.h"
#include "src/ast/u32.h"
namespace tint {
namespace ast {