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

Change-Id: I9a0e2ba4c6b0950134cef4b291cd1ba5cae1198c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34277
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 09b8829d8e
commit 0441bd1756
12 changed files with 26 additions and 48 deletions

View File

@ -18,6 +18,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/texture_type.h"
#include "src/ast/workgroup_decoration.h"
@ -315,7 +316,7 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
}
if ((multisampled &&
!unwrapped_type->As<ast::type::TextureType>()->IsMultisampled()) ||
!unwrapped_type->Is<ast::type::MultisampledTextureType>()) ||
(!multisampled &&
!unwrapped_type->As<ast::type::TextureType>()->IsSampled())) {
continue;

View File

@ -32,9 +32,6 @@ MultisampledTextureType::MultisampledTextureType(MultisampledTextureType&&) =
MultisampledTextureType::~MultisampledTextureType() = default;
bool MultisampledTextureType::IsMultisampled() const {
return true;
}
std::string MultisampledTextureType::type_name() const {
std::ostringstream out;

View File

@ -35,9 +35,6 @@ class MultisampledTextureType
MultisampledTextureType(MultisampledTextureType&&);
~MultisampledTextureType() override;
/// @returns true if the type is a sampled texture type
bool IsMultisampled() const override;
/// @returns the subtype of the sampled texture
Type* type() const { return type_; }

View File

@ -58,7 +58,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) {
MultisampledTextureType s(TextureDimension::kCube, &f32);
TextureType* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_TRUE(ty->IsMultisampled());
EXPECT_TRUE(ty->Is<MultisampledTextureType>());
EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage());
}

View File

@ -60,9 +60,6 @@ TextureType::TextureType(TextureType&&) = default;
TextureType::~TextureType() = default;
bool TextureType::IsMultisampled() const {
return false;
}
bool TextureType::IsStorage() const {
return false;
}
@ -70,11 +67,6 @@ bool TextureType::IsSampled() const {
return false;
}
const MultisampledTextureType* TextureType::AsMultisampled() const {
assert(IsMultisampled());
return static_cast<const MultisampledTextureType*>(this);
}
const SampledTextureType* TextureType::AsSampled() const {
assert(IsSampled());
return static_cast<const SampledTextureType*>(this);
@ -85,11 +77,6 @@ const StorageTextureType* TextureType::AsStorage() const {
return static_cast<const StorageTextureType*>(this);
}
MultisampledTextureType* TextureType::AsMultisampled() {
assert(IsMultisampled());
return static_cast<MultisampledTextureType*>(this);
}
SampledTextureType* TextureType::AsSampled() {
assert(IsSampled());
return static_cast<SampledTextureType*>(this);

View File

@ -24,8 +24,6 @@ namespace tint {
namespace ast {
namespace type {
class DepthTextureType;
class MultisampledTextureType;
class SampledTextureType;
class StorageTextureType;
@ -63,22 +61,16 @@ class TextureType : public Castable<TextureType, Type> {
/// @returns the texture dimension
TextureDimension dim() const { return dim_; }
/// @returns ture if this is a multisampled texture
virtual bool IsMultisampled() const;
/// @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 multisampled texture
const MultisampledTextureType* AsMultisampled() 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 multisampled texture
MultisampledTextureType* AsMultisampled();
/// @returns the texture as a sampled texture
SampledTextureType* AsSampled();
/// @returns the texture as a storage texture

View File

@ -382,7 +382,9 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
ast::type::Type* base_type = nullptr;
if (multisampled_only) {
base_type = texture_type->AsMultisampled()->type()->UnwrapIfNeeded();
base_type = texture_type->As<ast::type::MultisampledTextureType>()
->type()
->UnwrapIfNeeded();
} else {
base_type = texture_type->AsSampled()->type()->UnwrapIfNeeded();
}

View File

@ -263,9 +263,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::type::TextureType>());
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsMultisampled());
ASSERT_TRUE(t->As<ast::type::TextureType>()
->AsMultisampled()
ASSERT_TRUE(t->Is<ast::type::MultisampledTextureType>());
ASSERT_TRUE(t->As<ast::type::MultisampledTextureType>()
->type()
->Is<ast::type::I32Type>());
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),

View File

@ -672,7 +672,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
}
if (!texture->IsStorage() &&
!(texture->IsSampled() || texture->IsMultisampled())) {
!(texture->IsSampled() ||
texture->Is<ast::type::MultisampledTextureType>())) {
set_error(expr->source(), "invalid texture for " + ident->name());
return false;
}
@ -682,8 +683,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
type = texture->AsStorage()->type();
} else if (texture->IsSampled()) {
type = texture->AsSampled()->type();
} else if (texture->IsMultisampled()) {
type = texture->AsMultisampled()->type();
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
type = texture->As<ast::type::MultisampledTextureType>()->type();
} else {
set_error(expr->source(), "unknown texture type for texture sampling");
return false;

View File

@ -1874,7 +1874,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
error_ = "Invalid texture dimensions";
return false;
}
if (tex->IsMultisampled()) {
if (tex->Is<ast::type::MultisampledTextureType>()) {
out_ << "_ms";
}
out_ << "<";
@ -1894,8 +1894,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
error_ = "Invalid access control for storage texture";
return false;
}
} else if (tex->IsMultisampled()) {
if (!EmitType(tex->AsMultisampled()->type(), "")) {
} else if (tex->Is<ast::type::MultisampledTextureType>()) {
if (!EmitType(tex->As<ast::type::MultisampledTextureType>()->type(),
"")) {
return false;
}
out_ << ", access::sample";

View File

@ -1972,7 +1972,7 @@ void Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident,
// TODO(dsinclair): Remove the LOD param from textureLoad on storage
// textures when https://github.com/gpuweb/gpuweb/pull/1032 gets merged.
if (pidx.level != kNotUsed) {
if (texture_type->IsMultisampled()) {
if (texture_type->Is<ast::type::MultisampledTextureType>()) {
spirv_operand_mask |= SpvImageOperandsSampleMask;
} else {
spirv_operand_mask |= SpvImageOperandsLodMask;
@ -2516,7 +2516,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
}
uint32_t ms_literal = 0u;
if (texture->IsMultisampled()) {
if (texture->Is<ast::type::MultisampledTextureType>()) {
ms_literal = 1u;
}
@ -2526,8 +2526,8 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
}
uint32_t sampled_literal = 2u;
if (texture->IsMultisampled() || texture->IsSampled() ||
texture->Is<ast::type::DepthTextureType>()) {
if (texture->Is<ast::type::MultisampledTextureType>() ||
texture->IsSampled() || texture->Is<ast::type::DepthTextureType>()) {
sampled_literal = 1u;
}
@ -2543,8 +2543,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
type_id = GenerateTypeIfNeeded(&f32);
} else if (texture->IsSampled()) {
type_id = GenerateTypeIfNeeded(texture->AsSampled()->type());
} else if (texture->IsMultisampled()) {
type_id = GenerateTypeIfNeeded(texture->AsMultisampled()->type());
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
type_id = GenerateTypeIfNeeded(
texture->As<ast::type::MultisampledTextureType>()->type());
} else if (texture->IsStorage()) {
if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) {
ast::type::VoidType void_type;

View File

@ -474,7 +474,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
out_ << "depth_";
} else if (texture->IsSampled()) {
/* nothing to emit */
} else if (texture->IsMultisampled()) {
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
out_ << "multisampled_";
} else if (texture->IsStorage()) {
out_ << "storage_";
@ -528,8 +528,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
return false;
}
out_ << ">";
} else if (texture->IsMultisampled()) {
auto* sampled = texture->AsMultisampled();
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
auto* sampled = texture->As<ast::type::MultisampledTextureType>();
out_ << "<";
if (!EmitType(sampled->type())) {