writer/wgsl: Emit access mode on pointer types

Change-Id: If694489a079698df7d767967898d6c5238fe9f54
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59821
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-07-26 22:11:58 +00:00
parent 00320c2580
commit 3d73768aec
5 changed files with 21 additions and 3 deletions

View File

@ -420,6 +420,12 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) {
if (!EmitType(out, ptr->type())) {
return false;
}
if (ptr->access() != ast::Access::kUndefined) {
out << ", ";
if (!EmitAccess(out, ptr->access())) {
return false;
}
}
out << ">";
} else if (auto* atomic = ty->As<ast::Atomic>()) {
out << "atomic<";

View File

@ -125,6 +125,18 @@ TEST_F(WgslGeneratorImplTest, EmitType_Pointer) {
EXPECT_EQ(out.str(), "ptr<workgroup, f32>");
}
TEST_F(WgslGeneratorImplTest, EmitType_PointerAccessMode) {
auto* p =
ty.pointer<f32>(ast::StorageClass::kStorage, ast::Access::kReadWrite);
Alias("make_type_reachable", p);
GeneratorImpl& gen = Build();
std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, p)) << gen.error();
EXPECT_EQ(out.str(), "ptr<storage, f32, read_write>");
}
TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
auto* s = Structure("S", {
Member("a", ty.i32()),

View File

@ -15,7 +15,7 @@ fn main() {
if ((i >= b.count)) {
break;
}
let p : ptr<storage, u32> = &(b.data[i]);
let p : ptr<storage, u32, read_write> = &(b.data[i]);
if (((i % 2u) == 0u)) {
continue;
}

View File

@ -7,6 +7,6 @@ struct S {
[[stage(compute), workgroup_size(1)]]
fn main() {
let p : ptr<storage, i32> = &(buf.a);
let p : ptr<storage, i32, read_write> = &(buf.a);
*(p) = 12;
}

View File

@ -7,6 +7,6 @@ struct S {
[[stage(compute), workgroup_size(1)]]
fn main() {
let p : ptr<storage, i32> = &(v.a);
let p : ptr<storage, i32, read_write> = &(v.a);
let use : i32 = (*(p) + 1);
}