diff --git a/src/ast/function.cc b/src/ast/function.cc index 08a286955f..0d20fc1497 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -19,6 +19,7 @@ #include "src/ast/decorated_variable.h" #include "src/ast/stage_decoration.h" #include "src/ast/type/multisampled_texture_type.h" +#include "src/ast/type/sampled_texture_type.h" #include "src/ast/type/texture_type.h" #include "src/ast/workgroup_decoration.h" @@ -318,7 +319,7 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const { if ((multisampled && !unwrapped_type->Is()) || (!multisampled && - !unwrapped_type->As()->IsSampled())) { + !unwrapped_type->Is())) { continue; } diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 867c2a1ed8..4b39585455 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/sampled_texture_type.h" #include "src/ast/type/storage_texture_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/u32_type.h" @@ -55,9 +56,9 @@ TEST_F(DepthTextureTypeTest, Is) { TEST_F(DepthTextureTypeTest, IsTextureType) { DepthTextureType d(TextureDimension::kCube); - TextureType*ty = &d; + TextureType* ty = &d; EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsSampled()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); } diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index 1d987e6ac1..8b1aa211ec 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/sampled_texture_type.h" #include "src/ast/type/storage_texture_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/u32_type.h" @@ -60,7 +61,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) { TextureType* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsSampled()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); } diff --git a/src/ast/type/sampled_texture_type.cc b/src/ast/type/sampled_texture_type.cc index 78576b738d..dc03bebce8 100644 --- a/src/ast/type/sampled_texture_type.cc +++ b/src/ast/type/sampled_texture_type.cc @@ -30,10 +30,6 @@ SampledTextureType::SampledTextureType(SampledTextureType&&) = default; SampledTextureType::~SampledTextureType() = default; -bool SampledTextureType::IsSampled() const { - return true; -} - std::string SampledTextureType::type_name() const { std::ostringstream out; out << "__sampled_texture_" << dim() << type_->type_name(); diff --git a/src/ast/type/sampled_texture_type.h b/src/ast/type/sampled_texture_type.h index 3b1fb3fb8e..a270a95272 100644 --- a/src/ast/type/sampled_texture_type.h +++ b/src/ast/type/sampled_texture_type.h @@ -34,9 +34,6 @@ class SampledTextureType : public Castable { SampledTextureType(SampledTextureType&&); ~SampledTextureType() override; - /// @returns true if the type is a sampled texture type - bool IsSampled() const override; - /// @returns the subtype of the sampled texture Type* type() const { return type_; } diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc index ed6344f101..f0049a4909 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -59,7 +59,7 @@ TEST_F(SampledTextureTypeTest, IsTextureType) { SampledTextureType s(TextureDimension::kCube, &f32); TextureType* ty = &s; EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsSampled()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); } diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index 9062d7d8e2..0f290999cf 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -26,6 +26,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/sampled_texture_type.h" #include "src/ast/type/struct_type.h" #include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" @@ -62,7 +63,7 @@ TEST_F(StorageTextureTypeTest, IsTextureType) { ImageFormat::kRgba32Float); TextureType* ty = &s; EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsSampled()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); } diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc index 14c698e23f..453dcd092c 100644 --- a/src/ast/type/texture_type.cc +++ b/src/ast/type/texture_type.cc @@ -59,20 +59,6 @@ TextureType::TextureType(TextureType&&) = default; TextureType::~TextureType() = default; -bool TextureType::IsSampled() const { - return false; -} - -const SampledTextureType* TextureType::AsSampled() const { - assert(IsSampled()); - return static_cast(this); -} - -SampledTextureType* TextureType::AsSampled() { - assert(IsSampled()); - 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 f3047df83e..aa8db9fccc 100644 --- a/src/ast/type/texture_type.h +++ b/src/ast/type/texture_type.h @@ -24,8 +24,6 @@ namespace tint { namespace ast { namespace type { -class SampledTextureType; - /// The dimensionality of the texture enum class TextureDimension { /// Invalid texture @@ -60,15 +58,6 @@ class TextureType : public Castable { /// @returns the texture dimension TextureDimension dim() const { return dim_; } - /// @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 sampled texture - SampledTextureType* AsSampled(); - private: TextureDimension dim_ = TextureDimension::k1d; }; diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index 5cacc0fa86..7a62f3fc11 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -386,7 +386,9 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( ->type() ->UnwrapIfNeeded(); } else { - base_type = texture_type->AsSampled()->type()->UnwrapIfNeeded(); + base_type = texture_type->As() + ->type() + ->UnwrapIfNeeded(); } if (base_type->Is()) { 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 4dcb4227e1..182776682a 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -80,11 +80,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k1d); } @@ -97,11 +95,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); } @@ -114,11 +110,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k3d); } @@ -172,11 +166,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k1d); } @@ -189,11 +181,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); } @@ -206,11 +196,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k3d); } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 24ac3cdcf0..29c509c818 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -765,11 +765,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) { ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); } TEST_F(ParserImplTest, TypeDecl_Texture) { @@ -786,11 +784,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { ASSERT_NE(t.value, nullptr); EXPECT_EQ(t.value, type); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsSampled()); - ASSERT_TRUE(t->As() - ->AsSampled() - ->type() - ->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE( + t->As()->type()->Is()); } } // namespace diff --git a/src/type_determiner.cc b/src/type_determiner.cc index ffe72d01f4..40f55a748f 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -672,7 +672,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } if (!texture->Is() && - !(texture->IsSampled() || + !(texture->Is() || texture->Is())) { set_error(expr->source(), "invalid texture for " + ident->name()); return false; @@ -681,8 +681,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, ast::type::Type* type = nullptr; if (texture->Is()) { type = texture->As()->type(); - } else if (texture->IsSampled()) { - type = texture->AsSampled()->type(); + } else if (texture->Is()) { + type = texture->As()->type(); } else if (texture->Is()) { type = texture->As()->type(); } else { diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 6205aa8678..0bd9116956 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1900,8 +1900,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { return false; } out_ << ", access::sample"; - } else if (tex->IsSampled()) { - if (!EmitType(tex->AsSampled()->type(), "")) { + } else if (tex->Is()) { + if (!EmitType(tex->As()->type(), "")) { return false; } out_ << ", access::sample"; diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index bff08f451c..8a56827cd2 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2501,7 +2501,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, if (dim == ast::type::TextureDimension::k1dArray || dim == ast::type::TextureDimension::k1d) { dim_literal = SpvDim1D; - if (texture->IsSampled()) { + if (texture->Is()) { push_capability(SpvCapabilitySampled1D); } else { assert(texture->Is()); @@ -2528,12 +2528,14 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, uint32_t sampled_literal = 2u; if (texture->Is() || - texture->IsSampled() || texture->Is()) { + texture->Is() || + texture->Is()) { sampled_literal = 1u; } if (dim == ast::type::TextureDimension::kCubeArray) { - if (texture->IsSampled() || texture->Is()) { + if (texture->Is() || + texture->Is()) { push_capability(SpvCapabilitySampledCubeArray); } } @@ -2542,8 +2544,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, if (texture->Is()) { ast::type::F32Type f32; type_id = GenerateTypeIfNeeded(&f32); - } else if (texture->IsSampled()) { - type_id = GenerateTypeIfNeeded(texture->AsSampled()->type()); + } else if (texture->Is()) { + type_id = GenerateTypeIfNeeded( + texture->As()->type()); } else if (texture->Is()) { type_id = GenerateTypeIfNeeded( texture->As()->type()); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index f5f6015d95..2428187784 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -472,7 +472,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { out_ << "texture_"; if (texture->Is()) { out_ << "depth_"; - } else if (texture->IsSampled()) { + } else if (texture->Is()) { /* nothing to emit */ } else if (texture->Is()) { out_ << "multisampled_"; @@ -520,8 +520,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { return false; } - if (texture->IsSampled()) { - auto* sampled = texture->AsSampled(); + if (texture->Is()) { + auto* sampled = texture->As(); out_ << "<"; if (!EmitType(sampled->type())) {