[wgsl-writer] Emit access control type.
This CL updates the WGSL-Writer to emit the access control type. Bug: tint:287 Change-Id: Ifb42a5ab199f18014c33be62960d078e57df8dba Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33360 Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
7214f407dc
commit
ea9c3a604b
|
@ -404,18 +404,17 @@ bool GeneratorImpl::EmitImageFormat(const ast::type::ImageFormat fmt) {
|
|||
bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
||||
if (type->IsAccessControl()) {
|
||||
auto* ac = type->AsAccessControl();
|
||||
// TODO(dsinclair): Access control isn't supported in WGSL yet, so this
|
||||
// is disabled for now.
|
||||
//
|
||||
// out_ << "[[access(";
|
||||
// if (ac->IsReadOnly()) {
|
||||
// out_ << "read";
|
||||
// } else if (ac->IsWriteOnly()) {
|
||||
// out_ << "write";
|
||||
// } else {
|
||||
// out_ << "read_write";
|
||||
// }
|
||||
// out_ << ")]]" << std::endl;
|
||||
|
||||
out_ << "[[access(";
|
||||
if (ac->IsReadOnly()) {
|
||||
out_ << "read";
|
||||
} else if (ac->IsReadWrite()) {
|
||||
out_ << "read_write";
|
||||
} else {
|
||||
error_ = "invalid access control";
|
||||
return false;
|
||||
}
|
||||
out_ << ")]]" << std::endl;
|
||||
if (!EmitType(ac->type())) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -240,7 +240,8 @@ struct Data {
|
|||
d : f32;
|
||||
};
|
||||
|
||||
[[binding(0), set(0)]] var<storage_buffer> data : Data;
|
||||
[[binding(0), set(0)]] var<storage_buffer> data : [[access(read_write)]]
|
||||
Data;
|
||||
|
||||
[[stage(compute)]]
|
||||
fn a() -> void {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/access_control.h"
|
||||
#include "src/ast/stride_decoration.h"
|
||||
#include "src/ast/struct.h"
|
||||
#include "src/ast/struct_block_decoration.h"
|
||||
|
@ -20,6 +21,7 @@
|
|||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/struct_member_decoration.h"
|
||||
#include "src/ast/struct_member_offset_decoration.h"
|
||||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/array_type.h"
|
||||
#include "src/ast/type/bool_type.h"
|
||||
#include "src/ast/type/depth_texture_type.h"
|
||||
|
@ -61,6 +63,46 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) {
|
|||
EXPECT_EQ(gen.result(), "array<bool, 4>");
|
||||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_AccessControl_Read) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::StructMember mem("a", &i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
|
||||
ast::Struct str(decos, members);
|
||||
ast::type::StructType s("S", &str);
|
||||
|
||||
ast::type::AccessControlType a(ast::AccessControl::kReadOnly, &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "[[access(read)]]\nS");
|
||||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_AccessControl_ReadWrite) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::StructMember mem("a", &i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
|
||||
ast::Struct str(decos, members);
|
||||
ast::type::StructType s("S", &str);
|
||||
|
||||
ast::type::AccessControlType a(ast::AccessControl::kReadWrite, &s);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "[[access(read_write)]]\nS");
|
||||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Array_Decoration) {
|
||||
ast::type::BoolType b;
|
||||
ast::ArrayDecorationList decos;
|
||||
|
|
Loading…
Reference in New Issue