tint/transform: Implement CreateASTTypeFor() for pointers
Change-Id: I83b0bb28194be559e6e60caca6f2dc1871e65743 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122340 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
57be2ff2eb
commit
1edc272904
|
@ -173,6 +173,15 @@ ast::Type Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type* ty) {
|
||||||
if (auto* s = ty->As<type::Sampler>()) {
|
if (auto* s = ty->As<type::Sampler>()) {
|
||||||
return ctx.dst->ty.sampler(s->kind());
|
return ctx.dst->ty.sampler(s->kind());
|
||||||
}
|
}
|
||||||
|
if (auto* p = ty->As<type::Pointer>()) {
|
||||||
|
// Note: type::Pointer always has an inferred access, but WGSL only allows an explicit
|
||||||
|
// access in the 'storage' address space.
|
||||||
|
auto address_space = p->AddressSpace();
|
||||||
|
auto access = address_space == builtin::AddressSpace::kStorage
|
||||||
|
? p->Access()
|
||||||
|
: builtin::Access::kUndefined;
|
||||||
|
return ctx.dst->ty.pointer(CreateASTTypeFor(ctx, p->StoreType()), address_space, access);
|
||||||
|
}
|
||||||
TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics())
|
TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics())
|
||||||
<< "Unhandled type: " << ty->TypeInfo().name;
|
<< "Unhandled type: " << ty->TypeInfo().name;
|
||||||
return ast::Type{};
|
return ast::Type{};
|
||||||
|
|
|
@ -127,5 +127,24 @@ TEST_F(CreateASTTypeForTest, Struct) {
|
||||||
ast::CheckIdentifier(ast_type_builder.Symbols(), str, "S");
|
ast::CheckIdentifier(ast_type_builder.Symbols(), str, "S");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CreateASTTypeForTest, PrivatePointer) {
|
||||||
|
auto ptr = create([](ProgramBuilder& b) {
|
||||||
|
return b.create<type::Pointer>(b.create<type::I32>(), builtin::AddressSpace::kPrivate,
|
||||||
|
builtin::Access::kReadWrite);
|
||||||
|
});
|
||||||
|
|
||||||
|
ast::CheckIdentifier(ast_type_builder.Symbols(), ptr, ast::Template("ptr", "private", "i32"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CreateASTTypeForTest, StorageReadWritePointer) {
|
||||||
|
auto ptr = create([](ProgramBuilder& b) {
|
||||||
|
return b.create<type::Pointer>(b.create<type::I32>(), builtin::AddressSpace::kStorage,
|
||||||
|
builtin::Access::kReadWrite);
|
||||||
|
});
|
||||||
|
|
||||||
|
ast::CheckIdentifier(ast_type_builder.Symbols(), ptr,
|
||||||
|
ast::Template("ptr", "storage", "i32", "read_write"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::transform
|
} // namespace tint::transform
|
||||||
|
|
Loading…
Reference in New Issue