diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 2798b9378f..867c2a1ed8 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_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/u32_type.h" #include "src/ast/type/vector_type.h" @@ -54,9 +55,10 @@ TEST_F(DepthTextureTypeTest, Is) { TEST_F(DepthTextureTypeTest, IsTextureType) { DepthTextureType d(TextureDimension::kCube); - EXPECT_TRUE(d.Is()); - EXPECT_FALSE(d.IsSampled()); - EXPECT_FALSE(d.IsStorage()); + TextureType*ty = &d; + EXPECT_TRUE(ty->Is()); + EXPECT_FALSE(ty->IsSampled()); + EXPECT_FALSE(ty->Is()); } TEST_F(DepthTextureTypeTest, Dim) { diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index 10cf1d2297..1d987e6ac1 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_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/u32_type.h" #include "src/ast/type/vector_type.h" @@ -60,7 +61,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) { EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsSampled()); - EXPECT_FALSE(ty->IsStorage()); + EXPECT_FALSE(ty->Is()); } TEST_F(MultisampledTextureTypeTest, Dim) { diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc index a37b8b77b1..ed6344f101 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_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/u32_type.h" #include "src/ast/type/vector_type.h" @@ -59,7 +60,7 @@ TEST_F(SampledTextureTypeTest, IsTextureType) { TextureType* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsSampled()); - EXPECT_FALSE(ty->IsStorage()); + EXPECT_FALSE(ty->Is()); } TEST_F(SampledTextureTypeTest, Dim) { diff --git a/src/ast/type/storage_texture_type.cc b/src/ast/type/storage_texture_type.cc index d544963d23..963e4911ae 100644 --- a/src/ast/type/storage_texture_type.cc +++ b/src/ast/type/storage_texture_type.cc @@ -169,10 +169,6 @@ StorageTextureType::StorageTextureType(StorageTextureType&&) = default; StorageTextureType::~StorageTextureType() = default; -bool StorageTextureType::IsStorage() const { - return true; -} - std::string StorageTextureType::type_name() const { std::ostringstream out; out << "__storage_texture_" << access_ << "_" << dim() << "_" diff --git a/src/ast/type/storage_texture_type.h b/src/ast/type/storage_texture_type.h index 8157b07bae..84d6e6ec20 100644 --- a/src/ast/type/storage_texture_type.h +++ b/src/ast/type/storage_texture_type.h @@ -80,9 +80,6 @@ class StorageTextureType : public Castable { StorageTextureType(StorageTextureType&&); ~StorageTextureType() override; - /// @returns true if the type is a storage texture type - bool IsStorage() const override; - /// @param type the subtype of the storage texture void set_type(Type* const type); diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index cc548c96a2..9062d7d8e2 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -63,7 +63,7 @@ TEST_F(StorageTextureTypeTest, IsTextureType) { TextureType* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsSampled()); - EXPECT_TRUE(ty->IsStorage()); + EXPECT_TRUE(ty->Is()); } TEST_F(StorageTextureTypeTest, Dim) { @@ -93,44 +93,45 @@ TEST_F(StorageTextureTypeTest, TypeName) { TEST_F(StorageTextureTypeTest, F32Type) { Context ctx; ast::Module mod; - ast::type::Type* s = mod.create( - TextureDimension::k2dArray, AccessControl::kReadOnly, - ImageFormat::kRgba32Float); + Type* s = mod.create(TextureDimension::k2dArray, + AccessControl::kReadOnly, + ImageFormat::kRgba32Float); TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); - ASSERT_TRUE(s->As()->IsStorage()); - EXPECT_TRUE(s->As()->AsStorage()->type()->Is()); + ASSERT_TRUE(s->Is()); + EXPECT_TRUE( + s->As()->As()->type()->Is()); } TEST_F(StorageTextureTypeTest, U32Type) { Context ctx; ast::Module mod; - ast::type::Type* s = mod.create( - TextureDimension::k2dArray, AccessControl::kReadOnly, - ImageFormat::kRg32Uint); + Type* s = mod.create(TextureDimension::k2dArray, + AccessControl::kReadOnly, + ImageFormat::kRg32Uint); TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); - ASSERT_TRUE(s->As()->IsStorage()); - EXPECT_TRUE( - s->As()->AsStorage()->type()->Is()); + ASSERT_TRUE(s->Is()); + EXPECT_TRUE(s->As()->type()->Is()); } TEST_F(StorageTextureTypeTest, I32Type) { Context ctx; ast::Module mod; - ast::type::Type* s = mod.create( - TextureDimension::k2dArray, AccessControl::kReadOnly, - ImageFormat::kRgba32Sint); + Type* s = mod.create(TextureDimension::k2dArray, + AccessControl::kReadOnly, + ImageFormat::kRgba32Sint); TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); - ASSERT_TRUE(s->As()->IsStorage()); - EXPECT_TRUE(s->As()->AsStorage()->type()->Is()); + ASSERT_TRUE(s->Is()); + EXPECT_TRUE( + s->As()->As()->type()->Is()); } TEST_F(StorageTextureTypeTest, MinBufferBindingSize) { diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc index 18ea61a49e..14c698e23f 100644 --- a/src/ast/type/texture_type.cc +++ b/src/ast/type/texture_type.cc @@ -18,7 +18,6 @@ #include "src/ast/type/multisampled_texture_type.h" #include "src/ast/type/sampled_texture_type.h" -#include "src/ast/type/storage_texture_type.h" namespace tint { namespace ast { @@ -60,9 +59,6 @@ TextureType::TextureType(TextureType&&) = default; TextureType::~TextureType() = default; -bool TextureType::IsStorage() const { - return false; -} bool TextureType::IsSampled() const { return false; } @@ -72,21 +68,11 @@ const SampledTextureType* TextureType::AsSampled() const { return static_cast(this); } -const StorageTextureType* TextureType::AsStorage() const { - assert(IsStorage()); - return static_cast(this); -} - SampledTextureType* TextureType::AsSampled() { assert(IsSampled()); return static_cast(this); } -StorageTextureType* TextureType::AsStorage() { - assert(IsStorage()); - return static_cast(this); -} - } // namespace type } // namespace ast } // namespace tint diff --git a/src/ast/type/texture_type.h b/src/ast/type/texture_type.h index a2139b8274..f3047df83e 100644 --- a/src/ast/type/texture_type.h +++ b/src/ast/type/texture_type.h @@ -25,7 +25,6 @@ namespace ast { namespace type { class SampledTextureType; -class StorageTextureType; /// The dimensionality of the texture enum class TextureDimension { @@ -61,20 +60,14 @@ class TextureType : public Castable { /// @returns the texture dimension 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 virtual bool IsSampled() const; /// @returns the texture as a sampled texture const SampledTextureType* AsSampled() const; - /// @returns the texture as a storage texture - const StorageTextureType* AsStorage() const; /// @returns the texture as a sampled texture SampledTextureType* AsSampled(); - /// @returns the texture as a storage texture - StorageTextureType* AsStorage(); private: TextureDimension dim_ = TextureDimension::k1d; diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index 13aab4ff2c..4dcb4227e1 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -320,10 +320,10 @@ TEST_F(ParserImplTest, EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsStorage()); - EXPECT_EQ(t->As()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->AsStorage()->access(), + EXPECT_EQ(t->As()->access(), ast::AccessControl::kReadOnly); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k1d); @@ -338,10 +338,10 @@ TEST_F(ParserImplTest, EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsStorage()); - EXPECT_EQ(t->As()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->AsStorage()->access(), + EXPECT_EQ(t->As()->access(), ast::AccessControl::kWriteOnly); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); @@ -392,10 +392,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsStorage()); - EXPECT_EQ(t->As()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->As()->AsStorage()->access(), + EXPECT_EQ(t->As()->access(), ast::AccessControl::kReadOnly); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k1d); @@ -409,10 +409,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsStorage()); - EXPECT_EQ(t->As()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + EXPECT_EQ(t->As()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->As()->AsStorage()->access(), + EXPECT_EQ(t->As()->access(), ast::AccessControl::kWriteOnly); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 5a423ab389..ffe72d01f4 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -87,11 +87,11 @@ bool TypeDeterminer::Determine() { for (auto& iter : mod_->types()) { auto& type = iter.second; if (!type->Is() || - !type->As()->IsStorage()) { + !type->Is()) { continue; } if (!DetermineStorageTextureSubtype( - type->As()->AsStorage())) { + type->As())) { set_error(Source{}, "unable to determine storage texture subtype for: " + type->type_name()); return false; @@ -671,7 +671,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return true; } - if (!texture->IsStorage() && + if (!texture->Is() && !(texture->IsSampled() || texture->Is())) { set_error(expr->source(), "invalid texture for " + ident->name()); @@ -679,8 +679,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } ast::type::Type* type = nullptr; - if (texture->IsStorage()) { - type = texture->AsStorage()->type(); + if (texture->Is()) { + type = texture->As()->type(); } else if (texture->IsSampled()) { type = texture->AsSampled()->type(); } else if (texture->Is()) { diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 042708f6f2..b9f16d72ce 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -47,6 +47,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_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/texture_type.h" #include "src/ast/type/u32_type.h" @@ -2099,7 +2100,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << type->As()->name(); } else if (type->Is()) { auto* tex = type->As(); - if (tex->IsStorage()) { + if (tex->Is()) { out << "RW"; } out << "Texture"; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 19de1c05af..6205aa8678 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1880,8 +1880,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { out_ << "<"; if (tex->Is()) { out_ << "float, access::sample"; - } else if (tex->IsStorage()) { - auto* storage = tex->AsStorage(); + } else if (tex->Is()) { + auto* storage = tex->As(); if (!EmitType(storage->type(), "")) { return false; } diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 06020069d6..bff08f451c 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -718,8 +718,8 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { ops.push_back(Operand::Int(init_id)); } else if (type->Is()) { // Decorate storage texture variables with NonRead/Writeable if needed. - if (type->As()->IsStorage()) { - switch (type->As()->AsStorage()->access()) { + if (type->Is()) { + switch (type->As()->access()) { case ast::AccessControl::kWriteOnly: push_annot( spv::Op::OpDecorate, @@ -1964,8 +1964,9 @@ void Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, spirv_operands.reserve(4); // Enough to fit most parameter lists if (ident->intrinsic() == ast::Intrinsic::kTextureLoad) { - op = texture_type->IsStorage() ? spv::Op::OpImageRead - : spv::Op::OpImageFetch; + op = texture_type->Is() + ? spv::Op::OpImageRead + : spv::Op::OpImageFetch; spirv_params.emplace_back(gen_param(pidx.texture)); spirv_params.emplace_back(gen_param(pidx.coords)); @@ -2503,7 +2504,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, if (texture->IsSampled()) { push_capability(SpvCapabilitySampled1D); } else { - assert(texture->IsStorage()); + assert(texture->Is()); push_capability(SpvCapabilityImage1D); } } @@ -2546,12 +2547,14 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, } else if (texture->Is()) { type_id = GenerateTypeIfNeeded( texture->As()->type()); - } else if (texture->IsStorage()) { - if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) { + } else if (texture->Is()) { + if (texture->As()->access() == + ast::AccessControl::kWriteOnly) { ast::type::VoidType void_type; type_id = GenerateTypeIfNeeded(&void_type); } else { - type_id = GenerateTypeIfNeeded(texture->AsStorage()->type()); + type_id = GenerateTypeIfNeeded( + texture->As()->type()); } } if (type_id == 0u) { @@ -2559,9 +2562,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, } uint32_t format_literal = SpvImageFormat_::SpvImageFormatUnknown; - if (texture->IsStorage()) { - format_literal = - convert_image_format_to_spv(texture->AsStorage()->image_format()); + if (texture->Is()) { + format_literal = convert_image_format_to_spv( + texture->As()->image_format()); } push_type(spv::Op::OpTypeImage, diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 7f0b7d02ed..f5f6015d95 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -476,10 +476,10 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { /* nothing to emit */ } else if (texture->Is()) { out_ << "multisampled_"; - } else if (texture->IsStorage()) { + } else if (texture->Is()) { out_ << "storage_"; - auto* storage = texture->AsStorage(); + auto* storage = texture->As(); if (storage->access() == ast::AccessControl::kReadOnly) { out_ << "ro_"; } else if (storage->access() == ast::AccessControl::kWriteOnly) { @@ -536,8 +536,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { return false; } out_ << ">"; - } else if (texture->IsStorage()) { - auto* storage = texture->AsStorage(); + } else if (texture->Is()) { + auto* storage = texture->As(); out_ << "<"; if (!EmitImageFormat(storage->image_format())) {