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

Change-Id: I627304c0b397605f565ae688f2a2b61132c26b9b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34278
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 0441bd1756
commit 1a23756294
14 changed files with 66 additions and 85 deletions

View File

@@ -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/storage_texture_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
@@ -54,9 +55,10 @@ TEST_F(DepthTextureTypeTest, Is) {
TEST_F(DepthTextureTypeTest, IsTextureType) {
DepthTextureType d(TextureDimension::kCube);
EXPECT_TRUE(d.Is<DepthTextureType>());
EXPECT_FALSE(d.IsSampled());
EXPECT_FALSE(d.IsStorage());
TextureType*ty = &d;
EXPECT_TRUE(ty->Is<DepthTextureType>());
EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->Is<StorageTextureType>());
}
TEST_F(DepthTextureTypeTest, Dim) {

View File

@@ -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/storage_texture_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
@@ -60,7 +61,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) {
EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_TRUE(ty->Is<MultisampledTextureType>());
EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage());
EXPECT_FALSE(ty->Is<StorageTextureType>());
}
TEST_F(MultisampledTextureTypeTest, Dim) {

View File

@@ -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/storage_texture_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
@@ -59,7 +60,7 @@ TEST_F(SampledTextureTypeTest, IsTextureType) {
TextureType* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_TRUE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage());
EXPECT_FALSE(ty->Is<StorageTextureType>());
}
TEST_F(SampledTextureTypeTest, Dim) {

View File

@@ -169,10 +169,6 @@ StorageTextureType::StorageTextureType(StorageTextureType&&) = default;
StorageTextureType::~StorageTextureType() = default;
bool StorageTextureType::IsStorage() const {
return true;
}
std::string StorageTextureType::type_name() const {
std::ostringstream out;
out << "__storage_texture_" << access_ << "_" << dim() << "_"

View File

@@ -80,9 +80,6 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
StorageTextureType(StorageTextureType&&);
~StorageTextureType() override;
/// @returns true if the type is a storage texture type
bool IsStorage() const override;
/// @param type the subtype of the storage texture
void set_type(Type* const type);

View File

@@ -63,7 +63,7 @@ TEST_F(StorageTextureTypeTest, IsTextureType) {
TextureType* ty = &s;
EXPECT_FALSE(ty->Is<DepthTextureType>());
EXPECT_FALSE(ty->IsSampled());
EXPECT_TRUE(ty->IsStorage());
EXPECT_TRUE(ty->Is<StorageTextureType>());
}
TEST_F(StorageTextureTypeTest, Dim) {
@@ -93,44 +93,45 @@ TEST_F(StorageTextureTypeTest, TypeName) {
TEST_F(StorageTextureTypeTest, F32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float);
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly,
ImageFormat::kRgba32Float);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage());
EXPECT_TRUE(s->As<TextureType>()->AsStorage()->type()->Is<F32Type>());
ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE(
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<F32Type>());
}
TEST_F(StorageTextureTypeTest, U32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRg32Uint);
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly,
ImageFormat::kRg32Uint);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage());
EXPECT_TRUE(
s->As<TextureType>()->AsStorage()->type()->Is<ast::type::U32Type>());
ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE(s->As<StorageTextureType>()->type()->Is<U32Type>());
}
TEST_F(StorageTextureTypeTest, I32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Sint);
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
AccessControl::kReadOnly,
ImageFormat::kRgba32Sint);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(s->Is<TextureType>());
ASSERT_TRUE(s->As<TextureType>()->IsStorage());
EXPECT_TRUE(s->As<TextureType>()->AsStorage()->type()->Is<I32Type>());
ASSERT_TRUE(s->Is<StorageTextureType>());
EXPECT_TRUE(
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<I32Type>());
}
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) {

View File

@@ -18,7 +18,6 @@
#include "src/ast/type/multisampled_texture_type.h"
#include "src/ast/type/sampled_texture_type.h"
#include "src/ast/type/storage_texture_type.h"
namespace tint {
namespace ast {
@@ -60,9 +59,6 @@ TextureType::TextureType(TextureType&&) = default;
TextureType::~TextureType() = default;
bool TextureType::IsStorage() const {
return false;
}
bool TextureType::IsSampled() const {
return false;
}
@@ -72,21 +68,11 @@ const SampledTextureType* TextureType::AsSampled() const {
return static_cast<const SampledTextureType*>(this);
}
const StorageTextureType* TextureType::AsStorage() const {
assert(IsStorage());
return static_cast<const StorageTextureType*>(this);
}
SampledTextureType* TextureType::AsSampled() {
assert(IsSampled());
return static_cast<SampledTextureType*>(this);
}
StorageTextureType* TextureType::AsStorage() {
assert(IsStorage());
return static_cast<StorageTextureType*>(this);
}
} // namespace type
} // namespace ast
} // namespace tint

View File

@@ -25,7 +25,6 @@ namespace ast {
namespace type {
class SampledTextureType;
class StorageTextureType;
/// The dimensionality of the texture
enum class TextureDimension {
@@ -61,20 +60,14 @@ class TextureType : public Castable<TextureType, Type> {
/// @returns the texture dimension
TextureDimension dim() const { return dim_; }
/// @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 sampled texture
const SampledTextureType* AsSampled() const;
/// @returns the texture as a storage texture
const StorageTextureType* AsStorage() const;
/// @returns the texture as a sampled texture
SampledTextureType* AsSampled();
/// @returns the texture as a storage texture
StorageTextureType* AsStorage();
private:
TextureDimension dim_ = TextureDimension::k1d;