diff --git a/src/ast/type/depth_texture_type.cc b/src/ast/type/depth_texture_type.cc index 79f8e06970..95a954f3c8 100644 --- a/src/ast/type/depth_texture_type.cc +++ b/src/ast/type/depth_texture_type.cc @@ -41,10 +41,6 @@ DepthTextureType::DepthTextureType(DepthTextureType&&) = default; DepthTextureType::~DepthTextureType() = default; -bool DepthTextureType::IsDepth() const { - return true; -} - std::string DepthTextureType::type_name() const { std::ostringstream out; out << "__depth_texture_" << dim(); diff --git a/src/ast/type/depth_texture_type.h b/src/ast/type/depth_texture_type.h index ee05dc3454..4f58fb045c 100644 --- a/src/ast/type/depth_texture_type.h +++ b/src/ast/type/depth_texture_type.h @@ -33,9 +33,6 @@ class DepthTextureType : public Castable { DepthTextureType(DepthTextureType&&); ~DepthTextureType() override; - /// @returns true if the type is a depth texture type - bool IsDepth() const override; - /// @returns the name for this type std::string type_name() const override; }; diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 51c7014f9d..2798b9378f 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -54,7 +54,7 @@ TEST_F(DepthTextureTypeTest, Is) { TEST_F(DepthTextureTypeTest, IsTextureType) { DepthTextureType d(TextureDimension::kCube); - EXPECT_TRUE(d.IsDepth()); + EXPECT_TRUE(d.Is()); EXPECT_FALSE(d.IsSampled()); EXPECT_FALSE(d.IsStorage()); } diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index 32756ced87..108acb2cba 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -18,6 +18,7 @@ #include "src/ast/type/access_control_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/bool_type.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" @@ -55,10 +56,11 @@ TEST_F(MultisampledTextureTypeTest, Is) { TEST_F(MultisampledTextureTypeTest, IsTextureType) { F32Type f32; MultisampledTextureType s(TextureDimension::kCube, &f32); - EXPECT_FALSE(s.IsDepth()); - EXPECT_TRUE(s.IsMultisampled()); - EXPECT_FALSE(s.IsSampled()); - EXPECT_FALSE(s.IsStorage()); + TextureType* ty = &s; + EXPECT_FALSE(ty->Is()); + EXPECT_TRUE(ty->IsMultisampled()); + EXPECT_FALSE(ty->IsSampled()); + EXPECT_FALSE(ty->IsStorage()); } 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 9e68b826f1..a37b8b77b1 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -18,6 +18,7 @@ #include "src/ast/type/access_control_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/bool_type.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" @@ -55,9 +56,10 @@ TEST_F(SampledTextureTypeTest, Is) { TEST_F(SampledTextureTypeTest, IsTextureType) { F32Type f32; SampledTextureType s(TextureDimension::kCube, &f32); - EXPECT_FALSE(s.IsDepth()); - EXPECT_TRUE(s.IsSampled()); - EXPECT_FALSE(s.IsStorage()); + TextureType* ty = &s; + EXPECT_FALSE(ty->Is()); + EXPECT_TRUE(ty->IsSampled()); + EXPECT_FALSE(ty->IsStorage()); } TEST_F(SampledTextureTypeTest, Dim) { diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index 4d71c4190a..cc548c96a2 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -21,6 +21,7 @@ #include "src/ast/type/access_control_type.h" #include "src/ast/type/array_type.h" #include "src/ast/type/bool_type.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" @@ -59,9 +60,10 @@ TEST_F(StorageTextureTypeTest, Is) { TEST_F(StorageTextureTypeTest, IsTextureType) { StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly, ImageFormat::kRgba32Float); - EXPECT_FALSE(s.IsDepth()); - EXPECT_FALSE(s.IsSampled()); - EXPECT_TRUE(s.IsStorage()); + TextureType* ty = &s; + EXPECT_FALSE(ty->Is()); + EXPECT_FALSE(ty->IsSampled()); + EXPECT_TRUE(ty->IsStorage()); } TEST_F(StorageTextureTypeTest, Dim) { diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc index c6ff7f137c..2e986f4432 100644 --- a/src/ast/type/texture_type.cc +++ b/src/ast/type/texture_type.cc @@ -16,7 +16,6 @@ #include -#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/multisampled_texture_type.h" #include "src/ast/type/sampled_texture_type.h" #include "src/ast/type/storage_texture_type.h" @@ -61,9 +60,6 @@ TextureType::TextureType(TextureType&&) = default; TextureType::~TextureType() = default; -bool TextureType::IsDepth() const { - return false; -} bool TextureType::IsMultisampled() const { return false; } @@ -74,11 +70,6 @@ bool TextureType::IsSampled() const { return false; } -const DepthTextureType* TextureType::AsDepth() const { - assert(IsDepth()); - return static_cast(this); -} - const MultisampledTextureType* TextureType::AsMultisampled() const { assert(IsMultisampled()); return static_cast(this); @@ -94,11 +85,6 @@ const StorageTextureType* TextureType::AsStorage() const { return static_cast(this); } -DepthTextureType* TextureType::AsDepth() { - assert(IsDepth()); - return static_cast(this); -} - MultisampledTextureType* TextureType::AsMultisampled() { assert(IsMultisampled()); return static_cast(this); diff --git a/src/ast/type/texture_type.h b/src/ast/type/texture_type.h index 4cb9b239b1..b2eba824a7 100644 --- a/src/ast/type/texture_type.h +++ b/src/ast/type/texture_type.h @@ -63,8 +63,6 @@ class TextureType : public Castable { /// @returns the texture dimension TextureDimension dim() const { return dim_; } - /// @returns true if this is a depth texture - virtual bool IsDepth() const; /// @returns ture if this is a multisampled texture virtual bool IsMultisampled() const; /// @returns true if this is a storage texture @@ -72,8 +70,6 @@ class TextureType : public Castable { /// @returns true if this is a sampled texture virtual bool IsSampled() const; - /// @returns the texture as a depth texture - const DepthTextureType* AsDepth() const; /// @returns the texture as a multisampled texture const MultisampledTextureType* AsMultisampled() const; /// @returns the texture as a sampled texture @@ -81,8 +77,6 @@ class TextureType : public Castable { /// @returns the texture as a storage texture const StorageTextureType* AsStorage() const; - /// @returns the texture as a depth texture - DepthTextureType* AsDepth(); /// @returns the texture as a multisampled texture MultisampledTextureType* AsMultisampled(); /// @returns the texture as a sampled texture diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index ccff3fdee3..bc2d5c7201 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -53,6 +53,7 @@ #include "src/ast/storage_class.h" #include "src/ast/switch_statement.h" #include "src/ast/type/bool_type.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/texture_type.h" @@ -3714,7 +3715,7 @@ bool FunctionEmitter::EmitSampledImageAccess( parser_impl_.GetTypeForHandleVar(*image)) { if (ast::type::TextureType* texture_type = type->type()->As()) { - if (texture_type->IsDepth()) { + if (texture_type->Is()) { // Convert it to an unsigned integer type. lod_operand = ast_module_.create( ast_module_.create(), diff --git a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc index 78783f9c81..fd1d93bdf5 100644 --- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc @@ -37,7 +37,8 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsDepth()); + ASSERT_TRUE( + t->As()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); @@ -50,7 +51,8 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsDepth()); + ASSERT_TRUE( + t->As()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); @@ -63,7 +65,8 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsDepth()); + ASSERT_TRUE( + t->As()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); @@ -76,7 +79,8 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsDepth()); + ASSERT_TRUE( + t->As()->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); 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 d64c5a2e9c..23869a4e4c 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "gtest/gtest.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/multisampled_texture_type.h" @@ -66,7 +67,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->IsDepth()); + ASSERT_TRUE(t->Is()); EXPECT_EQ(t->As()->dim(), ast::type::TextureDimension::k2d); } diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 964a2fbe26..9d75b843b1 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -38,6 +38,7 @@ #include "src/ast/switch_statement.h" #include "src/ast/type/array_type.h" #include "src/ast/type/bool_type.h" +#include "src/ast/type/depth_texture_type.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" @@ -665,7 +666,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, ident->set_intrinsic_signature( std::make_unique(param)); - if (texture->IsDepth()) { + if (texture->Is()) { expr->func()->set_result_type(mod_->create()); return true; } diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 085be0319a..41795e2a68 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1842,7 +1842,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { } else if (type->Is()) { auto* tex = type->As(); - if (tex->IsDepth()) { + if (tex->Is()) { out_ << "depth"; } else { out_ << "texture"; @@ -1878,7 +1878,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { out_ << "_ms"; } out_ << "<"; - if (tex->IsDepth()) { + if (tex->Is()) { out_ << "float, access::sample"; } else if (tex->IsStorage()) { auto* storage = tex->AsStorage(); diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 345de3046e..f7b28a8510 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2521,23 +2521,24 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, } uint32_t depth_literal = 0u; - if (texture->IsDepth()) { + if (texture->Is()) { depth_literal = 1u; } uint32_t sampled_literal = 2u; - if (texture->IsMultisampled() || texture->IsSampled() || texture->IsDepth()) { + if (texture->IsMultisampled() || texture->IsSampled() || + texture->Is()) { sampled_literal = 1u; } if (dim == ast::type::TextureDimension::kCubeArray) { - if (texture->IsSampled() || texture->IsDepth()) { + if (texture->IsSampled() || texture->Is()) { push_capability(SpvCapabilitySampledCubeArray); } } uint32_t type_id = 0u; - if (texture->IsDepth()) { + if (texture->Is()) { ast::type::F32Type f32; type_id = GenerateTypeIfNeeded(&f32); } else if (texture->IsSampled()) { diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 91212c9b15..7e53242caa 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -470,7 +470,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { auto* texture = type->As(); out_ << "texture_"; - if (texture->IsDepth()) { + if (texture->Is()) { out_ << "depth_"; } else if (texture->IsSampled()) { /* nothing to emit */