Replace TextureType::(Is|As)Sampled with Castable
Change-Id: Id997f118a8ce9f4f7c42bed306368d3f204b6607 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34279 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
1a23756294
commit
b062bbdce8
|
@ -19,6 +19,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/sampled_texture_type.h"
|
||||
#include "src/ast/type/texture_type.h"
|
||||
#include "src/ast/workgroup_decoration.h"
|
||||
|
||||
|
@ -318,7 +319,7 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
|
|||
if ((multisampled &&
|
||||
!unwrapped_type->Is<ast::type::MultisampledTextureType>()) ||
|
||||
(!multisampled &&
|
||||
!unwrapped_type->As<ast::type::TextureType>()->IsSampled())) {
|
||||
!unwrapped_type->Is<ast::type::SampledTextureType>())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -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/sampled_texture_type.h"
|
||||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
|
@ -55,9 +56,9 @@ TEST_F(DepthTextureTypeTest, Is) {
|
|||
|
||||
TEST_F(DepthTextureTypeTest, IsTextureType) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TextureType*ty = &d;
|
||||
TextureType* ty = &d;
|
||||
EXPECT_TRUE(ty->Is<DepthTextureType>());
|
||||
EXPECT_FALSE(ty->IsSampled());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
}
|
||||
|
||||
|
|
|
@ -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/sampled_texture_type.h"
|
||||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
|
@ -60,7 +61,7 @@ TEST_F(MultisampledTextureTypeTest, IsTextureType) {
|
|||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_TRUE(ty->Is<MultisampledTextureType>());
|
||||
EXPECT_FALSE(ty->IsSampled());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,6 @@ SampledTextureType::SampledTextureType(SampledTextureType&&) = default;
|
|||
|
||||
SampledTextureType::~SampledTextureType() = default;
|
||||
|
||||
bool SampledTextureType::IsSampled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string SampledTextureType::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__sampled_texture_" << dim() << type_->type_name();
|
||||
|
|
|
@ -34,9 +34,6 @@ class SampledTextureType : public Castable<SampledTextureType, TextureType> {
|
|||
SampledTextureType(SampledTextureType&&);
|
||||
~SampledTextureType() override;
|
||||
|
||||
/// @returns true if the type is a sampled texture type
|
||||
bool IsSampled() const override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(SampledTextureTypeTest, IsTextureType) {
|
|||
SampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_TRUE(ty->IsSampled());
|
||||
EXPECT_TRUE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,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/sampled_texture_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/u32_type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
|
@ -62,7 +63,7 @@ TEST_F(StorageTextureTypeTest, IsTextureType) {
|
|||
ImageFormat::kRgba32Float);
|
||||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_FALSE(ty->IsSampled());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_TRUE(ty->Is<StorageTextureType>());
|
||||
}
|
||||
|
||||
|
|
|
@ -59,20 +59,6 @@ TextureType::TextureType(TextureType&&) = default;
|
|||
|
||||
TextureType::~TextureType() = default;
|
||||
|
||||
bool TextureType::IsSampled() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const SampledTextureType* TextureType::AsSampled() const {
|
||||
assert(IsSampled());
|
||||
return static_cast<const SampledTextureType*>(this);
|
||||
}
|
||||
|
||||
SampledTextureType* TextureType::AsSampled() {
|
||||
assert(IsSampled());
|
||||
return static_cast<SampledTextureType*>(this);
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
|
|
@ -24,8 +24,6 @@ namespace tint {
|
|||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
class SampledTextureType;
|
||||
|
||||
/// The dimensionality of the texture
|
||||
enum class TextureDimension {
|
||||
/// Invalid texture
|
||||
|
@ -60,15 +58,6 @@ class TextureType : public Castable<TextureType, Type> {
|
|||
/// @returns the texture dimension
|
||||
TextureDimension dim() const { return dim_; }
|
||||
|
||||
/// @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 sampled texture
|
||||
SampledTextureType* AsSampled();
|
||||
|
||||
private:
|
||||
TextureDimension dim_ = TextureDimension::k1d;
|
||||
};
|
||||
|
|
|
@ -386,7 +386,9 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
|
|||
->type()
|
||||
->UnwrapIfNeeded();
|
||||
} else {
|
||||
base_type = texture_type->AsSampled()->type()->UnwrapIfNeeded();
|
||||
base_type = texture_type->As<ast::type::SampledTextureType>()
|
||||
->type()
|
||||
->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
if (base_type->Is<ast::type::ArrayType>()) {
|
||||
|
|
|
@ -80,11 +80,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::F32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k1d);
|
||||
}
|
||||
|
@ -97,11 +95,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::I32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
@ -114,11 +110,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::U32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k3d);
|
||||
}
|
||||
|
@ -172,11 +166,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::F32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k1d);
|
||||
}
|
||||
|
@ -189,11 +181,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::I32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k2d);
|
||||
}
|
||||
|
@ -206,11 +196,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
|
|||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::U32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ast::type::TextureDimension::k3d);
|
||||
}
|
||||
|
|
|
@ -765,11 +765,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) {
|
|||
ASSERT_NE(t.value, nullptr) << p->error();
|
||||
EXPECT_EQ(t.value, type);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::F32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TypeDecl_Texture) {
|
||||
|
@ -786,11 +784,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
|
|||
ASSERT_NE(t.value, nullptr);
|
||||
EXPECT_EQ(t.value, type);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()->IsSampled());
|
||||
ASSERT_TRUE(t->As<ast::type::TextureType>()
|
||||
->AsSampled()
|
||||
->type()
|
||||
->Is<ast::type::F32Type>());
|
||||
ASSERT_TRUE(t->Is<ast::type::SampledTextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::SampledTextureType>()->type()->Is<ast::type::F32Type>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -672,7 +672,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
|
|||
}
|
||||
|
||||
if (!texture->Is<ast::type::StorageTextureType>() &&
|
||||
!(texture->IsSampled() ||
|
||||
!(texture->Is<ast::type::SampledTextureType>() ||
|
||||
texture->Is<ast::type::MultisampledTextureType>())) {
|
||||
set_error(expr->source(), "invalid texture for " + ident->name());
|
||||
return false;
|
||||
|
@ -681,8 +681,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
|
|||
ast::type::Type* type = nullptr;
|
||||
if (texture->Is<ast::type::StorageTextureType>()) {
|
||||
type = texture->As<ast::type::StorageTextureType>()->type();
|
||||
} else if (texture->IsSampled()) {
|
||||
type = texture->AsSampled()->type();
|
||||
} else if (texture->Is<ast::type::SampledTextureType>()) {
|
||||
type = texture->As<ast::type::SampledTextureType>()->type();
|
||||
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
|
||||
type = texture->As<ast::type::MultisampledTextureType>()->type();
|
||||
} else {
|
||||
|
|
|
@ -1900,8 +1900,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
|||
return false;
|
||||
}
|
||||
out_ << ", access::sample";
|
||||
} else if (tex->IsSampled()) {
|
||||
if (!EmitType(tex->AsSampled()->type(), "")) {
|
||||
} else if (tex->Is<ast::type::SampledTextureType>()) {
|
||||
if (!EmitType(tex->As<ast::type::SampledTextureType>()->type(), "")) {
|
||||
return false;
|
||||
}
|
||||
out_ << ", access::sample";
|
||||
|
|
|
@ -2501,7 +2501,7 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
|
|||
if (dim == ast::type::TextureDimension::k1dArray ||
|
||||
dim == ast::type::TextureDimension::k1d) {
|
||||
dim_literal = SpvDim1D;
|
||||
if (texture->IsSampled()) {
|
||||
if (texture->Is<ast::type::SampledTextureType>()) {
|
||||
push_capability(SpvCapabilitySampled1D);
|
||||
} else {
|
||||
assert(texture->Is<ast::type::StorageTextureType>());
|
||||
|
@ -2528,12 +2528,14 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
|
|||
|
||||
uint32_t sampled_literal = 2u;
|
||||
if (texture->Is<ast::type::MultisampledTextureType>() ||
|
||||
texture->IsSampled() || texture->Is<ast::type::DepthTextureType>()) {
|
||||
texture->Is<ast::type::SampledTextureType>() ||
|
||||
texture->Is<ast::type::DepthTextureType>()) {
|
||||
sampled_literal = 1u;
|
||||
}
|
||||
|
||||
if (dim == ast::type::TextureDimension::kCubeArray) {
|
||||
if (texture->IsSampled() || texture->Is<ast::type::DepthTextureType>()) {
|
||||
if (texture->Is<ast::type::SampledTextureType>() ||
|
||||
texture->Is<ast::type::DepthTextureType>()) {
|
||||
push_capability(SpvCapabilitySampledCubeArray);
|
||||
}
|
||||
}
|
||||
|
@ -2542,8 +2544,9 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture,
|
|||
if (texture->Is<ast::type::DepthTextureType>()) {
|
||||
ast::type::F32Type f32;
|
||||
type_id = GenerateTypeIfNeeded(&f32);
|
||||
} else if (texture->IsSampled()) {
|
||||
type_id = GenerateTypeIfNeeded(texture->AsSampled()->type());
|
||||
} else if (texture->Is<ast::type::SampledTextureType>()) {
|
||||
type_id = GenerateTypeIfNeeded(
|
||||
texture->As<ast::type::SampledTextureType>()->type());
|
||||
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
|
||||
type_id = GenerateTypeIfNeeded(
|
||||
texture->As<ast::type::MultisampledTextureType>()->type());
|
||||
|
|
|
@ -472,7 +472,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
out_ << "texture_";
|
||||
if (texture->Is<ast::type::DepthTextureType>()) {
|
||||
out_ << "depth_";
|
||||
} else if (texture->IsSampled()) {
|
||||
} else if (texture->Is<ast::type::SampledTextureType>()) {
|
||||
/* nothing to emit */
|
||||
} else if (texture->Is<ast::type::MultisampledTextureType>()) {
|
||||
out_ << "multisampled_";
|
||||
|
@ -520,8 +520,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (texture->IsSampled()) {
|
||||
auto* sampled = texture->AsSampled();
|
||||
if (texture->Is<ast::type::SampledTextureType>()) {
|
||||
auto* sampled = texture->As<ast::type::SampledTextureType>();
|
||||
|
||||
out_ << "<";
|
||||
if (!EmitType(sampled->type())) {
|
||||
|
|
Loading…
Reference in New Issue