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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1874,7 +1874,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
error_ = "Invalid texture dimensions"; error_ = "Invalid texture dimensions";
return false; return false;
} }
if (tex->IsMultisampled()) { if (tex->Is<ast::type::MultisampledTextureType>()) {
out_ << "_ms"; out_ << "_ms";
} }
out_ << "<"; out_ << "<";
@ -1894,8 +1894,9 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
error_ = "Invalid access control for storage texture"; error_ = "Invalid access control for storage texture";
return false; return false;
} }
} else if (tex->IsMultisampled()) { } else if (tex->Is<ast::type::MultisampledTextureType>()) {
if (!EmitType(tex->AsMultisampled()->type(), "")) { if (!EmitType(tex->As<ast::type::MultisampledTextureType>()->type(),
"")) {
return false; return false;
} }
out_ << ", access::sample"; 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 // TODO(dsinclair): Remove the LOD param from textureLoad on storage
// textures when https://github.com/gpuweb/gpuweb/pull/1032 gets merged. // textures when https://github.com/gpuweb/gpuweb/pull/1032 gets merged.
if (pidx.level != kNotUsed) { if (pidx.level != kNotUsed) {
if (texture_type->IsMultisampled()) { if (texture_type->Is<ast::type::MultisampledTextureType>()) {
spirv_operand_mask |= SpvImageOperandsSampleMask; spirv_operand_mask |= SpvImageOperandsSampleMask;
} else { } else {
spirv_operand_mask |= SpvImageOperandsLodMask; spirv_operand_mask |= SpvImageOperandsLodMask;
@ -2516,7 +2516,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
} }
uint32_t ms_literal = 0u; uint32_t ms_literal = 0u;
if (texture->IsMultisampled()) { if (texture->Is<ast::type::MultisampledTextureType>()) {
ms_literal = 1u; ms_literal = 1u;
} }
@ -2526,8 +2526,8 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
} }
uint32_t sampled_literal = 2u; uint32_t sampled_literal = 2u;
if (texture->IsMultisampled() || texture->IsSampled() || if (texture->Is<ast::type::MultisampledTextureType>() ||
texture->Is<ast::type::DepthTextureType>()) { texture->IsSampled() || texture->Is<ast::type::DepthTextureType>()) {
sampled_literal = 1u; sampled_literal = 1u;
} }
@ -2543,8 +2543,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
type_id = GenerateTypeIfNeeded(&f32); type_id = GenerateTypeIfNeeded(&f32);
} else if (texture->IsSampled()) { } else if (texture->IsSampled()) {
type_id = GenerateTypeIfNeeded(texture->AsSampled()->type()); type_id = GenerateTypeIfNeeded(texture->AsSampled()->type());
} else if (texture->IsMultisampled()) { } else if (texture->Is<ast::type::MultisampledTextureType>()) {
type_id = GenerateTypeIfNeeded(texture->AsMultisampled()->type()); type_id = GenerateTypeIfNeeded(
texture->As<ast::type::MultisampledTextureType>()->type());
} else if (texture->IsStorage()) { } else if (texture->IsStorage()) {
if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) { if (texture->AsStorage()->access() == ast::AccessControl::kWriteOnly) {
ast::type::VoidType void_type; ast::type::VoidType void_type;

View File

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