Replace TextureType::(Is|As)Storage with Castable

Change-Id: I627304c0b397605f565ae688f2a2b61132c26b9b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34278
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 0441bd1756
commit 1a23756294
14 changed files with 66 additions and 85 deletions

View File

@ -23,6 +23,7 @@
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h" #include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h" #include "src/ast/type/vector_type.h"
@ -54,9 +55,10 @@ TEST_F(DepthTextureTypeTest, Is) {
TEST_F(DepthTextureTypeTest, IsTextureType) { TEST_F(DepthTextureTypeTest, IsTextureType) {
DepthTextureType d(TextureDimension::kCube); DepthTextureType d(TextureDimension::kCube);
EXPECT_TRUE(d.Is<DepthTextureType>()); TextureType*ty = &d;
EXPECT_FALSE(d.IsSampled()); EXPECT_TRUE(ty->Is<DepthTextureType>());
EXPECT_FALSE(d.IsStorage()); EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->Is<StorageTextureType>());
} }
TEST_F(DepthTextureTypeTest, Dim) { TEST_F(DepthTextureTypeTest, Dim) {

View File

@ -23,6 +23,7 @@
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h" #include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h" #include "src/ast/type/vector_type.h"
@ -60,7 +61,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) {
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_TRUE(ty->Is<MultisampledTextureType>()); EXPECT_TRUE(ty->Is<MultisampledTextureType>());
EXPECT_FALSE(ty->IsSampled()); EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage()); EXPECT_FALSE(ty->Is<StorageTextureType>());
} }
TEST_F(MultisampledTextureTypeTest, Dim) { TEST_F(MultisampledTextureTypeTest, Dim) {

View File

@ -23,6 +23,7 @@
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h" #include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h" #include "src/ast/type/vector_type.h"
@ -59,7 +60,7 @@ TEST_F(SampledTextureTypeTest, IsTextureType) {
TextureType* ty = &s; TextureType* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_TRUE(ty->IsSampled()); EXPECT_TRUE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage()); EXPECT_FALSE(ty->Is<StorageTextureType>());
} }
TEST_F(SampledTextureTypeTest, Dim) { TEST_F(SampledTextureTypeTest, Dim) {

View File

@ -169,10 +169,6 @@ StorageTextureType::StorageTextureType(StorageTextureType&&) = default;
StorageTextureType::~StorageTextureType() = default; StorageTextureType::~StorageTextureType() = default;
bool StorageTextureType::IsStorage() const {
return true;
}
std::string StorageTextureType::type_name() const { std::string StorageTextureType::type_name() const {
std::ostringstream out; std::ostringstream out;
out << "__storage_texture_" << access_ << "_" << dim() << "_" out << "__storage_texture_" << access_ << "_" << dim() << "_"

View File

@ -80,9 +80,6 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
StorageTextureType(StorageTextureType&&); StorageTextureType(StorageTextureType&&);
~StorageTextureType() override; ~StorageTextureType() override;
/// @returns true if the type is a storage texture type
bool IsStorage() const override;
/// @param type the subtype of the storage texture /// @param type the subtype of the storage texture
void set_type(Type* const type); void set_type(Type* const type);

View File

@ -63,7 +63,7 @@ TEST_F(StorageTextureTypeTest, IsTextureType) {
TextureType* ty = &s; TextureType* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>()); EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_FALSE(ty->IsSampled()); EXPECT_FALSE(ty->IsSampled());
EXPECT_TRUE(ty->IsStorage()); EXPECT_TRUE(ty->Is<StorageTextureType>());
} }
TEST_F(StorageTextureTypeTest, Dim) { TEST_F(StorageTextureTypeTest, Dim) {
@ -93,44 +93,45 @@ TEST_F(StorageTextureTypeTest, TypeName) {
TEST_F(StorageTextureTypeTest, F32Type) { TEST_F(StorageTextureTypeTest, F32Type) {
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>( Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
TextureDimension::k2dArray, AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRgba32Float); ImageFormat::kRgba32Float);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage()); ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE(s->As<TextureType>()->AsStorage()->type()->Is<F32Type>()); EXPECT_TRUE(
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<F32Type>());
} }
TEST_F(StorageTextureTypeTest, U32Type) { TEST_F(StorageTextureTypeTest, U32Type) {
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>( Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
TextureDimension::k2dArray, AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRg32Uint); ImageFormat::kRg32Uint);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage()); ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE( EXPECT_TRUE(s->As<StorageTextureType>()->type()->Is<U32Type>());
s->As<TextureType>()->AsStorage()->type()->Is<ast::type::U32Type>());
} }
TEST_F(StorageTextureTypeTest, I32Type) { TEST_F(StorageTextureTypeTest, I32Type) {
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>( Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
TextureDimension::k2dArray, AccessControl::kReadOnly, AccessControl::kReadOnly,
ImageFormat::kRgba32Sint); ImageFormat::kRgba32Sint);
TypeDeterminer td(&ctx, &mod); TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>()); ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage()); ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE(s->As<TextureType>()->AsStorage()->type()->Is<I32Type>()); EXPECT_TRUE(
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<I32Type>());
} }
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) { TEST_F(StorageTextureTypeTest, MinBufferBindingSize) {

View File

@ -18,7 +18,6 @@
#include "src/ast/type/multisampled_texture_type.h" #include "src/ast/type/multisampled_texture_type.h"
#include "src/ast/type/sampled_texture_type.h" #include "src/ast/type/sampled_texture_type.h"
#include "src/ast/type/storage_texture_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -60,9 +59,6 @@ TextureType::TextureType(TextureType&&) = default;
TextureType::~TextureType() = default; TextureType::~TextureType() = default;
bool TextureType::IsStorage() const {
return false;
}
bool TextureType::IsSampled() const { bool TextureType::IsSampled() const {
return false; return false;
} }
@ -72,21 +68,11 @@ const SampledTextureType* TextureType::AsSampled() const {
return static_cast<const SampledTextureType*>(this); return static_cast<const SampledTextureType*>(this);
} }
const StorageTextureType* TextureType::AsStorage() const {
assert(IsStorage());
return static_cast<const StorageTextureType*>(this);
}
SampledTextureType* TextureType::AsSampled() { SampledTextureType* TextureType::AsSampled() {
assert(IsSampled()); assert(IsSampled());
return static_cast<SampledTextureType*>(this); return static_cast<SampledTextureType*>(this);
} }
StorageTextureType* TextureType::AsStorage() {
assert(IsStorage());
return static_cast<StorageTextureType*>(this);
}
} // namespace type } // namespace type
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -25,7 +25,6 @@ namespace ast {
namespace type { namespace type {
class SampledTextureType; class SampledTextureType;
class StorageTextureType;
/// The dimensionality of the texture /// The dimensionality of the texture
enum class TextureDimension { enum class TextureDimension {
@ -61,20 +60,14 @@ class TextureType : public Castable<TextureType, Type> {
/// @returns the texture dimension /// @returns the texture dimension
TextureDimension dim() const { return dim_; } TextureDimension dim() const { return dim_; }
/// @returns true if this is a storage texture
virtual bool IsStorage() const;
/// @returns true if this is a sampled texture /// @returns true if this is a sampled texture
virtual bool IsSampled() const; virtual bool IsSampled() const;
/// @returns the texture as a sampled texture /// @returns the texture as a sampled texture
const SampledTextureType* AsSampled() const; const SampledTextureType* AsSampled() const;
/// @returns the texture as a storage texture
const StorageTextureType* AsStorage() const;
/// @returns the texture as a sampled texture /// @returns the texture as a sampled texture
SampledTextureType* AsSampled(); SampledTextureType* AsSampled();
/// @returns the texture as a storage texture
StorageTextureType* AsStorage();
private: private:
TextureDimension dim_ = TextureDimension::k1d; TextureDimension dim_ = TextureDimension::k1d;

View File

@ -320,10 +320,10 @@ TEST_F(ParserImplTest,
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsStorage()); ASSERT_TRUE(t->Is<ast::type::StorageTextureType>());
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->image_format(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->image_format(),
ast::type::ImageFormat::kR8Unorm); ast::type::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->access(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->access(),
ast::AccessControl::kReadOnly); ast::AccessControl::kReadOnly);
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(), EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k1d); ast::type::TextureDimension::k1d);
@ -338,10 +338,10 @@ TEST_F(ParserImplTest,
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsStorage()); ASSERT_TRUE(t->Is<ast::type::StorageTextureType>());
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->image_format(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->image_format(),
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->access(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->access(),
ast::AccessControl::kWriteOnly); ast::AccessControl::kWriteOnly);
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(), EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k2d); ast::type::TextureDimension::k2d);
@ -392,10 +392,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsStorage()); ASSERT_TRUE(t->Is<ast::type::StorageTextureType>());
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->image_format(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->image_format(),
ast::type::ImageFormat::kR8Unorm); ast::type::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->access(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->access(),
ast::AccessControl::kReadOnly); ast::AccessControl::kReadOnly);
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(), EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k1d); ast::type::TextureDimension::k1d);
@ -409,10 +409,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>()); ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsStorage()); ASSERT_TRUE(t->Is<ast::type::StorageTextureType>());
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->image_format(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->image_format(),
ast::type::ImageFormat::kR16Float); ast::type::ImageFormat::kR16Float);
EXPECT_EQ(t->As<ast::type::TextureType>()->AsStorage()->access(), EXPECT_EQ(t->As<ast::type::StorageTextureType>()->access(),
ast::AccessControl::kWriteOnly); ast::AccessControl::kWriteOnly);
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(), EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
ast::type::TextureDimension::k2d); ast::type::TextureDimension::k2d);

View File

@ -87,11 +87,11 @@ bool TypeDeterminer::Determine() {
for (auto& iter : mod_->types()) { for (auto& iter : mod_->types()) {
auto& type = iter.second; auto& type = iter.second;
if (!type->Is<ast::type::TextureType>() || if (!type->Is<ast::type::TextureType>() ||
!type->As<ast::type::TextureType>()->IsStorage()) { !type->Is<ast::type::StorageTextureType>()) {
continue; continue;
} }
if (!DetermineStorageTextureSubtype( if (!DetermineStorageTextureSubtype(
type->As<ast::type::TextureType>()->AsStorage())) { type->As<ast::type::StorageTextureType>())) {
set_error(Source{}, "unable to determine storage texture subtype for: " + set_error(Source{}, "unable to determine storage texture subtype for: " +
type->type_name()); type->type_name());
return false; return false;
@ -671,7 +671,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
return true; return true;
} }
if (!texture->IsStorage() && if (!texture->Is<ast::type::StorageTextureType>() &&
!(texture->IsSampled() || !(texture->IsSampled() ||
texture->Is<ast::type::MultisampledTextureType>())) { texture->Is<ast::type::MultisampledTextureType>())) {
set_error(expr->source(), "invalid texture for " + ident->name()); set_error(expr->source(), "invalid texture for " + ident->name());
@ -679,8 +679,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
ast::type::Type* type = nullptr; ast::type::Type* type = nullptr;
if (texture->IsStorage()) { if (texture->Is<ast::type::StorageTextureType>()) {
type = texture->AsStorage()->type(); type = texture->As<ast::type::StorageTextureType>()->type();
} else if (texture->IsSampled()) { } else if (texture->IsSampled()) {
type = texture->AsSampled()->type(); type = texture->AsSampled()->type();
} else if (texture->Is<ast::type::MultisampledTextureType>()) { } else if (texture->Is<ast::type::MultisampledTextureType>()) {

View File

@ -47,6 +47,7 @@
#include "src/ast/type/matrix_type.h" #include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/sampler_type.h" #include "src/ast/type/sampler_type.h"
#include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/texture_type.h" #include "src/ast/type/texture_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
@ -2099,7 +2100,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
out << type->As<ast::type::StructType>()->name(); out << type->As<ast::type::StructType>()->name();
} else if (type->Is<ast::type::TextureType>()) { } else if (type->Is<ast::type::TextureType>()) {
auto* tex = type->As<ast::type::TextureType>(); auto* tex = type->As<ast::type::TextureType>();
if (tex->IsStorage()) { if (tex->Is<ast::type::StorageTextureType>()) {
out << "RW"; out << "RW";
} }
out << "Texture"; out << "Texture";

View File

@ -1880,8 +1880,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
out_ << "<"; out_ << "<";
if (tex->Is<ast::type::DepthTextureType>()) { if (tex->Is<ast::type::DepthTextureType>()) {
out_ << "float, access::sample"; out_ << "float, access::sample";
} else if (tex->IsStorage()) { } else if (tex->Is<ast::type::StorageTextureType>()) {
auto* storage = tex->AsStorage(); auto* storage = tex->As<ast::type::StorageTextureType>();
if (!EmitType(storage->type(), "")) { if (!EmitType(storage->type(), "")) {
return false; return false;
} }

View File

@ -718,8 +718,8 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
ops.push_back(Operand::Int(init_id)); ops.push_back(Operand::Int(init_id));
} else if (type->Is<ast::type::TextureType>()) { } else if (type->Is<ast::type::TextureType>()) {
// Decorate storage texture variables with NonRead/Writeable if needed. // Decorate storage texture variables with NonRead/Writeable if needed.
if (type->As<ast::type::TextureType>()->IsStorage()) { if (type->Is<ast::type::StorageTextureType>()) {
switch (type->As<ast::type::TextureType>()->AsStorage()->access()) { switch (type->As<ast::type::StorageTextureType>()->access()) {
case ast::AccessControl::kWriteOnly: case ast::AccessControl::kWriteOnly:
push_annot( push_annot(
spv::Op::OpDecorate, spv::Op::OpDecorate,
@ -1964,8 +1964,9 @@ void Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident,
spirv_operands.reserve(4); // Enough to fit most parameter lists spirv_operands.reserve(4); // Enough to fit most parameter lists
if (ident->intrinsic() == ast::Intrinsic::kTextureLoad) { if (ident->intrinsic() == ast::Intrinsic::kTextureLoad) {
op = texture_type->IsStorage() ? spv::Op::OpImageRead op = texture_type->Is<ast::type::StorageTextureType>()
: spv::Op::OpImageFetch; ? spv::Op::OpImageRead
: spv::Op::OpImageFetch;
spirv_params.emplace_back(gen_param(pidx.texture)); spirv_params.emplace_back(gen_param(pidx.texture));
spirv_params.emplace_back(gen_param(pidx.coords)); spirv_params.emplace_back(gen_param(pidx.coords));
@ -2503,7 +2504,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
if (texture->IsSampled()) { if (texture->IsSampled()) {
push_capability(SpvCapabilitySampled1D); push_capability(SpvCapabilitySampled1D);
} else { } else {
assert(texture->IsStorage()); assert(texture->Is<ast::type::StorageTextureType>());
push_capability(SpvCapabilityImage1D); push_capability(SpvCapabilityImage1D);
} }
} }
@ -2546,12 +2547,14 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
} else if (texture->Is<ast::type::MultisampledTextureType>()) { } else if (texture->Is<ast::type::MultisampledTextureType>()) {
type_id = GenerateTypeIfNeeded( type_id = GenerateTypeIfNeeded(
texture->As<ast::type::MultisampledTextureType>()->type()); texture->As<ast::type::MultisampledTextureType>()->type());
} else if (texture->IsStorage()) { } else if (texture->Is<ast::type::StorageTextureType>()) {
if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) { if (texture->As<ast::type::StorageTextureType>()->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 {
type_id = GenerateTypeIfNeeded(texture->AsStorage()->type()); type_id = GenerateTypeIfNeeded(
texture->As<ast::type::StorageTextureType>()->type());
} }
} }
if (type_id == 0u) { if (type_id == 0u) {
@ -2559,9 +2562,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
} }
uint32_t format_literal = SpvImageFormat_::SpvImageFormatUnknown; uint32_t format_literal = SpvImageFormat_::SpvImageFormatUnknown;
if (texture->IsStorage()) { if (texture->Is<ast::type::StorageTextureType>()) {
format_literal = format_literal = convert_image_format_to_spv(
convert_image_format_to_spv(texture->AsStorage()->image_format()); texture->As<ast::type::StorageTextureType>()->image_format());
} }
push_type(spv::Op::OpTypeImage, push_type(spv::Op::OpTypeImage,

View File

@ -476,10 +476,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
/* nothing to emit */ /* nothing to emit */
} else if (texture->Is<ast::type::MultisampledTextureType>()) { } else if (texture->Is<ast::type::MultisampledTextureType>()) {
out_ << "multisampled_"; out_ << "multisampled_";
} else if (texture->IsStorage()) { } else if (texture->Is<ast::type::StorageTextureType>()) {
out_ << "storage_"; out_ << "storage_";
auto* storage = texture->AsStorage(); auto* storage = texture->As<ast::type::StorageTextureType>();
if (storage->access() == ast::AccessControl::kReadOnly) { if (storage->access() == ast::AccessControl::kReadOnly) {
out_ << "ro_"; out_ << "ro_";
} else if (storage->access() == ast::AccessControl::kWriteOnly) { } else if (storage->access() == ast::AccessControl::kWriteOnly) {
@ -536,8 +536,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
return false; return false;
} }
out_ << ">"; out_ << ">";
} else if (texture->IsStorage()) { } else if (texture->Is<ast::type::StorageTextureType>()) {
auto* storage = texture->AsStorage(); auto* storage = texture->As<ast::type::StorageTextureType>();
out_ << "<"; out_ << "<";
if (!EmitImageFormat(storage->image_format())) { if (!EmitImageFormat(storage->image_format())) {