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

Change-Id: I2f1785cec1880f728fbbf0c75762bc957e34ca0a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34276
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 16ec1bb626
commit 09b8829d8e
15 changed files with 39 additions and 52 deletions

View File

@@ -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();

View File

@@ -33,9 +33,6 @@ class DepthTextureType : public Castable<DepthTextureType, TextureType> {
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;
};

View File

@@ -54,7 +54,7 @@ TEST_F(DepthTextureTypeTest, Is) {
TEST_F(DepthTextureTypeTest, IsTextureType) {
DepthTextureType d(TextureDimension::kCube);
EXPECT_TRUE(d.IsDepth());
EXPECT_TRUE(d.Is<DepthTextureType>());
EXPECT_FALSE(d.IsSampled());
EXPECT_FALSE(d.IsStorage());
}

View File

@@ -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<DepthTextureType>());
EXPECT_TRUE(ty->IsMultisampled());
EXPECT_FALSE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage());
}
TEST_F(MultisampledTextureTypeTest, Dim) {

View File

@@ -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<DepthTextureType>());
EXPECT_TRUE(ty->IsSampled());
EXPECT_FALSE(ty->IsStorage());
}
TEST_F(SampledTextureTypeTest, Dim) {

View File

@@ -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<DepthTextureType>());
EXPECT_FALSE(ty->IsSampled());
EXPECT_TRUE(ty->IsStorage());
}
TEST_F(StorageTextureTypeTest, Dim) {

View File

@@ -16,7 +16,6 @@
#include <cassert>
#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<const DepthTextureType*>(this);
}
const MultisampledTextureType* TextureType::AsMultisampled() const {
assert(IsMultisampled());
return static_cast<const MultisampledTextureType*>(this);
@@ -94,11 +85,6 @@ const StorageTextureType* TextureType::AsStorage() const {
return static_cast<const StorageTextureType*>(this);
}
DepthTextureType* TextureType::AsDepth() {
assert(IsDepth());
return static_cast<DepthTextureType*>(this);
}
MultisampledTextureType* TextureType::AsMultisampled() {
assert(IsMultisampled());
return static_cast<MultisampledTextureType*>(this);

View File

@@ -63,8 +63,6 @@ class TextureType : public Castable<TextureType, Type> {
/// @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<TextureType, Type> {
/// @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<TextureType, Type> {
/// @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