From 38409c79dc9bc5d1728646bdfea5187ba95c9be4 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 30 Nov 2020 23:30:58 +0000 Subject: [PATCH] Replace Type::(Is|As)Texture with Castable Change-Id: I53bbccc3e1e7b88ad8c201997cf7e2e485ad9c81 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34272 Reviewed-by: dan sinclair --- src/ast/function.cc | 8 +- src/ast/type/access_control_type_test.cc | 3 +- src/ast/type/alias_type_test.cc | 3 +- src/ast/type/array_type_test.cc | 3 +- src/ast/type/bool_type_test.cc | 3 +- src/ast/type/depth_texture_type_test.cc | 2 +- src/ast/type/f32_type_test.cc | 3 +- src/ast/type/i32_type_test.cc | 3 +- src/ast/type/matrix_type_test.cc | 3 +- .../type/multisampled_texture_type_test.cc | 2 +- src/ast/type/pointer_type_test.cc | 3 +- src/ast/type/sampled_texture_type_test.cc | 2 +- src/ast/type/sampler_type_test.cc | 3 +- src/ast/type/storage_texture_type_test.cc | 20 +-- src/ast/type/struct_type_test.cc | 3 +- src/ast/type/texture_type.cc | 4 - src/ast/type/texture_type.h | 3 - src/ast/type/type.cc | 14 -- src/ast/type/type.h | 7 - src/ast/type/u32_type_test.cc | 3 +- src/ast/type/vector_type_test.cc | 3 +- src/inspector/inspector.cc | 3 +- src/reader/spirv/function.cc | 8 +- .../parser_impl_depth_texture_type_test.cc | 28 ++-- .../parser_impl_texture_sampler_types_test.cc | 130 +++++++++++------- src/reader/wgsl/parser_impl_type_decl_test.cc | 18 ++- src/type_determiner.cc | 15 +- src/writer/hlsl/generator_impl.cc | 4 +- src/writer/msl/generator_impl.cc | 6 +- src/writer/spirv/builder.cc | 16 ++- src/writer/wgsl/generator_impl.cc | 4 +- 31 files changed, 181 insertions(+), 149 deletions(-) diff --git a/src/ast/function.cc b/src/ast/function.cc index 2dc9c2160a..09a554f2f8 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -310,12 +310,14 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const { for (auto* var : referenced_module_variables()) { auto* unwrapped_type = var->type()->UnwrapIfNeeded(); - if (!var->IsDecorated() || !unwrapped_type->IsTexture()) { + if (!var->IsDecorated() || !unwrapped_type->Is()) { continue; } - if ((multisampled && !unwrapped_type->AsTexture()->IsMultisampled()) || - (!multisampled && !unwrapped_type->AsTexture()->IsSampled())) { + if ((multisampled && + !unwrapped_type->As()->IsMultisampled()) || + (!multisampled && + !unwrapped_type->As()->IsSampled())) { continue; } diff --git a/src/ast/type/access_control_type_test.cc b/src/ast/type/access_control_type_test.cc index c7ea3a394e..e5fc40a49c 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/ast/type/access_control_type_test.cc @@ -30,6 +30,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" #include "src/ast/type/u32_type.h" namespace tint { @@ -61,7 +62,7 @@ TEST_F(AccessControlTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/alias_type_test.cc b/src/ast/type/alias_type_test.cc index ce2f3c7a71..df38b69b64 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/ast/type/alias_type_test.cc @@ -31,6 +31,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" #include "src/ast/type/u32_type.h" namespace tint { @@ -62,7 +63,7 @@ TEST_F(AliasTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/array_type_test.cc b/src/ast/type/array_type_test.cc index 4cd1567ce2..ba1fdedd1f 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/ast/type/array_type_test.cc @@ -26,6 +26,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" #include "src/ast/type/u32_type.h" namespace tint { @@ -68,7 +69,7 @@ TEST_F(ArrayTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/bool_type_test.cc b/src/ast/type/bool_type_test.cc index dc34ebb07d..e61aa8dc4b 100644 --- a/src/ast/type/bool_type_test.cc +++ b/src/ast/type/bool_type_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(BoolTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/depth_texture_type_test.cc b/src/ast/type/depth_texture_type_test.cc index 7eb088488d..5db5e882d6 100644 --- a/src/ast/type/depth_texture_type_test.cc +++ b/src/ast/type/depth_texture_type_test.cc @@ -45,7 +45,7 @@ TEST_F(DepthTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsTexture()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/f32_type_test.cc b/src/ast/type/f32_type_test.cc index f0138c5c2a..058e2f297e 100644 --- a/src/ast/type/f32_type_test.cc +++ b/src/ast/type/f32_type_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(F32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/i32_type_test.cc b/src/ast/type/i32_type_test.cc index f3b65520c0..ba980b5b35 100644 --- a/src/ast/type/i32_type_test.cc +++ b/src/ast/type/i32_type_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -43,7 +44,7 @@ TEST_F(I32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/matrix_type_test.cc b/src/ast/type/matrix_type_test.cc index 633ec29731..9557e7e8ff 100644 --- a/src/ast/type/matrix_type_test.cc +++ b/src/ast/type/matrix_type_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -52,7 +53,7 @@ TEST_F(MatrixTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/multisampled_texture_type_test.cc b/src/ast/type/multisampled_texture_type_test.cc index d3a410cc33..9db6845d37 100644 --- a/src/ast/type/multisampled_texture_type_test.cc +++ b/src/ast/type/multisampled_texture_type_test.cc @@ -45,7 +45,7 @@ TEST_F(MultisampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsTexture()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/pointer_type_test.cc b/src/ast/type/pointer_type_test.cc index 3ce88367b9..0e440024ee 100644 --- a/src/ast/type/pointer_type_test.cc +++ b/src/ast/type/pointer_type_test.cc @@ -22,6 +22,7 @@ #include "src/ast/type/i32_type.h" #include "src/ast/type/matrix_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -51,7 +52,7 @@ TEST_F(PointerTypeTest, Is) { EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/sampled_texture_type_test.cc b/src/ast/type/sampled_texture_type_test.cc index 162f70100c..525eb990b1 100644 --- a/src/ast/type/sampled_texture_type_test.cc +++ b/src/ast/type/sampled_texture_type_test.cc @@ -45,7 +45,7 @@ TEST_F(SampledTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsTexture()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/sampler_type_test.cc b/src/ast/type/sampler_type_test.cc index 7ab51d97f9..6a4c5f9fc3 100644 --- a/src/ast/type/sampler_type_test.cc +++ b/src/ast/type/sampler_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -55,7 +56,7 @@ TEST_F(SamplerTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index c97c8ca2a2..c87c9ae046 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -49,7 +49,7 @@ TEST_F(StorageTextureTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->IsTexture()); + EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } @@ -95,9 +95,9 @@ TEST_F(StorageTextureTypeTest, F32Type) { TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); - ASSERT_TRUE(s->IsTexture()); - ASSERT_TRUE(s->AsTexture()->IsStorage()); - EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is()); + ASSERT_TRUE(s->Is()); + ASSERT_TRUE(s->As()->IsStorage()); + EXPECT_TRUE(s->As()->AsStorage()->type()->Is()); } TEST_F(StorageTextureTypeTest, U32Type) { @@ -109,9 +109,9 @@ TEST_F(StorageTextureTypeTest, U32Type) { TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); - ASSERT_TRUE(s->IsTexture()); - ASSERT_TRUE(s->AsTexture()->IsStorage()); - EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->IsU32()); + ASSERT_TRUE(s->Is()); + ASSERT_TRUE(s->As()->IsStorage()); + EXPECT_TRUE(s->As()->AsStorage()->type()->IsU32()); } TEST_F(StorageTextureTypeTest, I32Type) { @@ -123,9 +123,9 @@ TEST_F(StorageTextureTypeTest, I32Type) { TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); - ASSERT_TRUE(s->IsTexture()); - ASSERT_TRUE(s->AsTexture()->IsStorage()); - EXPECT_TRUE(s->AsTexture()->AsStorage()->type()->Is()); + ASSERT_TRUE(s->Is()); + ASSERT_TRUE(s->As()->IsStorage()); + EXPECT_TRUE(s->As()->AsStorage()->type()->Is()); } TEST_F(StorageTextureTypeTest, MinBufferBindingSize) { diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index 84e5447740..244bedd90f 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -28,6 +28,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/texture_type.h" #include "src/ast/type/u32_type.h" #include "src/ast/type/vector_type.h" @@ -59,7 +60,7 @@ TEST_F(StructTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/texture_type.cc b/src/ast/type/texture_type.cc index ab4e54f96a..c6ff7f137c 100644 --- a/src/ast/type/texture_type.cc +++ b/src/ast/type/texture_type.cc @@ -61,10 +61,6 @@ TextureType::TextureType(TextureType&&) = default; TextureType::~TextureType() = default; -bool TextureType::IsTexture() const { - return true; -} - bool TextureType::IsDepth() const { return false; } diff --git a/src/ast/type/texture_type.h b/src/ast/type/texture_type.h index 249c85cc6e..4cb9b239b1 100644 --- a/src/ast/type/texture_type.h +++ b/src/ast/type/texture_type.h @@ -60,9 +60,6 @@ class TextureType : public Castable { TextureType(TextureType&&); ~TextureType() override; - /// @returns true if the type is a texture type - bool IsTexture() const override; - /// @returns the texture dimension TextureDimension dim() const { return dim_; } diff --git a/src/ast/type/type.cc b/src/ast/type/type.cc index 0ac063f94f..a2e6267f72 100644 --- a/src/ast/type/type.cc +++ b/src/ast/type/type.cc @@ -66,10 +66,6 @@ Type* Type::UnwrapAll() { return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); } -bool Type::IsTexture() const { - return false; -} - bool Type::IsU32() const { return false; } @@ -134,11 +130,6 @@ bool Type::is_integer_scalar_or_vector() { return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); } -const TextureType* Type::AsTexture() const { - assert(IsTexture()); - return static_cast(this); -} - const U32Type* Type::AsU32() const { assert(IsU32()); return static_cast(this); @@ -154,11 +145,6 @@ const VoidType* Type::AsVoid() const { return static_cast(this); } -TextureType* Type::AsTexture() { - assert(IsTexture()); - return static_cast(this); -} - U32Type* Type::AsU32() { assert(IsU32()); return static_cast(this); diff --git a/src/ast/type/type.h b/src/ast/type/type.h index 7f88819a9b..4061b76ff6 100644 --- a/src/ast/type/type.h +++ b/src/ast/type/type.h @@ -23,7 +23,6 @@ namespace tint { namespace ast { namespace type { -class TextureType; class U32Type; class VectorType; class VoidType; @@ -38,8 +37,6 @@ class Type : public Castable { Type(Type&&); ~Type() override; - /// @returns true if the type is a texture type - virtual bool IsTexture() const; /// @returns true if the type is a u32 type virtual bool IsU32() const; /// @returns true if the type is a vec type @@ -101,8 +98,6 @@ class Type : public Castable { /// @returns true if this type is an integer scalar or vector bool is_integer_scalar_or_vector(); - /// @returns the type as a texture type - const TextureType* AsTexture() const; /// @returns the type as a u32 type const U32Type* AsU32() const; /// @returns the type as a vector type @@ -110,8 +105,6 @@ class Type : public Castable { /// @returns the type as a void type const VoidType* AsVoid() const; - /// @returns the type as a texture type - TextureType* AsTexture(); /// @returns the type as a u32 type U32Type* AsU32(); /// @returns the type as a vector type diff --git a/src/ast/type/u32_type_test.cc b/src/ast/type/u32_type_test.cc index d8e756f4af..dd7096d1bc 100644 --- a/src/ast/type/u32_type_test.cc +++ b/src/ast/type/u32_type_test.cc @@ -24,6 +24,7 @@ #include "src/ast/type/pointer_type.h" #include "src/ast/type/sampler_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -45,7 +46,7 @@ TEST_F(U32TypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->IsU32()); EXPECT_FALSE(ty->IsVector()); } diff --git a/src/ast/type/vector_type_test.cc b/src/ast/type/vector_type_test.cc index 6a67e9ab0b..a6d2d2b9fa 100644 --- a/src/ast/type/vector_type_test.cc +++ b/src/ast/type/vector_type_test.cc @@ -23,6 +23,7 @@ #include "src/ast/type/matrix_type.h" #include "src/ast/type/pointer_type.h" #include "src/ast/type/struct_type.h" +#include "src/ast/type/texture_type.h" namespace tint { namespace ast { @@ -52,7 +53,7 @@ TEST_F(VectorTypeTest, Is) { EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->IsTexture()); + EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->IsU32()); EXPECT_TRUE(ty->IsVector()); } diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index c16c95248b..94ba8bb0b4 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -350,7 +350,8 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( entry.bind_group = binding_info.set->value(); entry.binding = binding_info.binding->value(); - auto* texture_type = var->type()->UnwrapIfNeeded()->AsTexture(); + auto* texture_type = + var->type()->UnwrapIfNeeded()->As(); switch (texture_type->dim()) { case ast::type::TextureDimension::k1d: entry.dim = ResourceBinding::TextureDimension::k1d; diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 5b505314d2..e008eb72ee 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -3711,7 +3711,8 @@ bool FunctionEmitter::EmitSampledImageAccess( // integer. if (ast::type::PointerType* type = parser_impl_.GetTypeForHandleVar(*image)) { - if (ast::type::TextureType* texture_type = type->type()->AsTexture()) { + if (ast::type::TextureType* texture_type = + type->type()->As()) { if (texture_type->IsDepth()) { // Convert it to an unsigned integer type. lod_operand = ast_module_.create( @@ -3782,11 +3783,12 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess( Fail(); return {}; } - if (!type || !type->type()->IsTexture()) { + if (!type || !type->type()->Is()) { Fail() << "invalid texture type for " << image->PrettyPrint(); return {}; } - ast::type::TextureDimension dim = type->type()->AsTexture()->dim(); + ast::type::TextureDimension dim = + type->type()->As()->dim(); // Number of regular coordinates. uint32_t num_axes = 0; bool is_arrayed = false; 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 c7faf990b4..78783f9c81 100644 --- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc @@ -36,9 +36,10 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsDepth()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsDepth()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -48,9 +49,10 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsDepth()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2dArray); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsDepth()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -60,9 +62,10 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsDepth()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::kCube); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsDepth()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -72,9 +75,10 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsDepth()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::kCubeArray); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsDepth()); + 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 463533ddc2..baa7d62301 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -64,9 +64,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsDepth()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsDepth()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { @@ -76,10 +77,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { @@ -89,10 +94,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { @@ -102,10 +111,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsU32()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As()->AsSampled()->type()->IsU32()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid_Old) { @@ -156,10 +166,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { @@ -169,10 +183,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { @@ -182,10 +200,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsU32()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As()->AsSampled()->type()->IsU32()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) { @@ -235,11 +254,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsMultisampled()); - ASSERT_TRUE( - t->AsTexture()->AsMultisampled()->type()->Is()); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsMultisampled()); + ASSERT_TRUE(t->As() + ->AsMultisampled() + ->type() + ->Is()); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) { @@ -290,13 +312,14 @@ TEST_F(ParserImplTest, EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsStorage()); - EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsStorage()); + EXPECT_EQ(t->As()->AsStorage()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->As()->AsStorage()->access(), ast::AccessControl::kReadOnly); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, @@ -307,13 +330,14 @@ TEST_F(ParserImplTest, EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsStorage()); - EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsStorage()); + EXPECT_EQ(t->As()->AsStorage()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->As()->AsStorage()->access(), ast::AccessControl::kWriteOnly); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType_Old) { @@ -360,13 +384,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsStorage()); - EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsStorage()); + EXPECT_EQ(t->As()->AsStorage()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->As()->AsStorage()->access(), ast::AccessControl::kReadOnly); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { @@ -376,13 +401,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsStorage()); - EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsStorage()); + EXPECT_EQ(t->As()->AsStorage()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->As()->AsStorage()->access(), ast::AccessControl::kWriteOnly); - EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim(), + ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 0472dae28b..cb58617e0c 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -764,9 +764,12 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); } TEST_F(ParserImplTest, TypeDecl_Texture) { @@ -782,9 +785,12 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t->IsTexture()); - ASSERT_TRUE(t->AsTexture()->IsSampled()); - ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->Is()); + ASSERT_TRUE(t->Is()); + ASSERT_TRUE(t->As()->IsSampled()); + ASSERT_TRUE(t->As() + ->AsSampled() + ->type() + ->Is()); } } // namespace diff --git a/src/type_determiner.cc b/src/type_determiner.cc index a879a79c78..8f5ab1d873 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -85,10 +85,12 @@ void TypeDeterminer::set_referenced_from_function_if_needed( bool TypeDeterminer::Determine() { for (auto& iter : mod_->types()) { auto& type = iter.second; - if (!type->IsTexture() || !type->AsTexture()->IsStorage()) { + if (!type->Is() || + !type->As()->IsStorage()) { continue; } - if (!DetermineStorageTextureSubtype(type->AsTexture()->AsStorage())) { + if (!DetermineStorageTextureSubtype( + type->As()->AsStorage())) { set_error(Source{}, "unable to determine storage texture subtype for: " + type->type_name()); return false; @@ -550,12 +552,15 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, ast::intrinsic::TextureSignature::Parameters param; auto* texture_param = expr->params()[0]; - if (!texture_param->result_type()->UnwrapPtrIfNeeded()->IsTexture()) { + if (!texture_param->result_type() + ->UnwrapPtrIfNeeded() + ->Is()) { set_error(expr->source(), "invalid first argument for " + ident->name()); return false; } - ast::type::TextureType* texture = - texture_param->result_type()->UnwrapPtrIfNeeded()->AsTexture(); + ast::type::TextureType* texture = texture_param->result_type() + ->UnwrapPtrIfNeeded() + ->As(); bool is_array = false; switch (texture->dim()) { diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 5056a8a811..340af43973 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2089,8 +2089,8 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << "State"; } else if (type->Is()) { out << type->As()->name(); - } else if (type->IsTexture()) { - auto* tex = type->AsTexture(); + } else if (type->Is()) { + auto* tex = type->As(); if (tex->IsStorage()) { out << "RW"; } diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 46b6855e66..a021d79d24 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -712,7 +712,7 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) { auto dim = params[pidx.texture] ->result_type() ->UnwrapPtrIfNeeded() - ->AsTexture() + ->As() ->dim(); switch (dim) { case ast::type::TextureDimension::k2d: @@ -1838,8 +1838,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) { // The struct type emits as just the name. The declaration would be emitted // as part of emitting the constructed types. out_ << type->As()->name(); - } else if (type->IsTexture()) { - auto* tex = type->AsTexture(); + } else if (type->Is()) { + auto* tex = type->As(); if (tex->IsDepth()) { out_ << "depth"; diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 54853a7472..cda2161267 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -716,10 +716,10 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { Operand::Int(ConvertStorageClass(sc))}; if (var->has_constructor()) { ops.push_back(Operand::Int(init_id)); - } else if (type->IsTexture()) { + } else if (type->Is()) { // Decorate storage texture variables with NonRead/Writeable if needed. - if (type->AsTexture()->IsStorage()) { - switch (type->AsTexture()->AsStorage()->access()) { + if (type->As()->IsStorage()) { + switch (type->As()->AsStorage()->access()) { case ast::AccessControl::kWriteOnly: push_annot( spv::Op::OpDecorate, @@ -1917,8 +1917,10 @@ void Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, ast::CallExpression* call, spirv::Operand result_type, spirv::Operand result_id) { - auto* texture_type = - call->params()[0]->result_type()->UnwrapAll()->AsTexture(); + auto* texture_type = call->params()[0] + ->result_type() + ->UnwrapAll() + ->As(); auto* sig = static_cast( ident->intrinsic_signature()); @@ -2453,8 +2455,8 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { } } else if (type->IsVoid()) { push_type(spv::Op::OpTypeVoid, {result}); - } else if (type->IsTexture()) { - if (!GenerateTextureType(type->AsTexture(), result)) { + } else if (type->Is()) { + if (!GenerateTextureType(type->As(), result)) { return 0; } } else if (type->Is()) { diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 402ae87bc6..27d84e7e23 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -464,8 +464,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { // The struct, as a type, is just the name. We should have already emitted // the declaration through a call to |EmitStructType| earlier. out_ << type->As()->name(); - } else if (type->IsTexture()) { - auto* texture = type->AsTexture(); + } else if (type->Is()) { + auto* texture = type->As(); out_ << "texture_"; if (texture->IsDepth()) {