Move TextureDimension to type/

This cl pulls TextureDimension out of ast/texture and into
type/texture_dimension removing a type dependency on ast.

Change-Id: Icf06ec32ee9051286f169ae9538c48416f513039
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117603
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2023-01-21 19:16:15 +00:00
committed by Dawn LUCI CQ
parent d54dabeab5
commit 3cbf3fc4c5
100 changed files with 1134 additions and 1009 deletions

View File

@@ -16,10 +16,10 @@
#include <string>
#include "src/tint/ast/variable.h"
#include "src/tint/debug.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/manager.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::Array);

View File

@@ -15,6 +15,7 @@
#include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/program_builder.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::DepthMultisampledTexture);
@@ -22,13 +23,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::DepthMultisampledTexture);
namespace tint::type {
namespace {
bool IsValidDepthDimension(ast::TextureDimension dim) {
return dim == ast::TextureDimension::k2d;
bool IsValidDepthDimension(TextureDimension dim) {
return dim == TextureDimension::k2d;
}
} // namespace
DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim)
DepthMultisampledTexture::DepthMultisampledTexture(TextureDimension dim)
: Base(utils::Hash(TypeInfo::Of<DepthMultisampledTexture>().full_hashcode, dim), dim) {
TINT_ASSERT(Type, IsValidDepthDimension(dim));
}

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/type/texture.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
@@ -26,7 +27,7 @@ class DepthMultisampledTexture final : public Castable<DepthMultisampledTexture,
public:
/// Constructor
/// @param dim the dimensionality of the texture
explicit DepthMultisampledTexture(ast::TextureDimension dim);
explicit DepthMultisampledTexture(TextureDimension dim);
/// Destructor
~DepthMultisampledTexture() override;

View File

@@ -18,6 +18,7 @@
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
@@ -25,22 +26,22 @@ namespace {
using DepthMultisampledTextureTest = TestHelper;
TEST_F(DepthMultisampledTextureTest, Creation) {
auto* a = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthMultisampledTexture>(TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(TextureDimension::k2d);
EXPECT_EQ(a, b);
}
TEST_F(DepthMultisampledTextureTest, Hash) {
auto* a = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthMultisampledTexture>(TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(TextureDimension::k2d);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(DepthMultisampledTextureTest, Equals) {
auto* a = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthMultisampledTexture>(TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(TextureDimension::k2d);
EXPECT_TRUE(a->Equals(*a));
EXPECT_TRUE(a->Equals(*b));
@@ -48,23 +49,23 @@ TEST_F(DepthMultisampledTextureTest, Equals) {
}
TEST_F(DepthMultisampledTextureTest, Dim) {
DepthMultisampledTexture d(ast::TextureDimension::k2d);
EXPECT_EQ(d.dim(), ast::TextureDimension::k2d);
DepthMultisampledTexture d(TextureDimension::k2d);
EXPECT_EQ(d.dim(), TextureDimension::k2d);
}
TEST_F(DepthMultisampledTextureTest, FriendlyName) {
DepthMultisampledTexture d(ast::TextureDimension::k2d);
DepthMultisampledTexture d(TextureDimension::k2d);
EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_multisampled_2d");
}
TEST_F(DepthMultisampledTextureTest, Clone) {
auto* a = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthMultisampledTexture>(TextureDimension::k2d);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* dt = a->Clone(ctx);
EXPECT_EQ(dt->dim(), ast::TextureDimension::k2d);
EXPECT_EQ(dt->dim(), TextureDimension::k2d);
}
} // namespace

View File

@@ -15,6 +15,7 @@
#include "src/tint/type/depth_texture.h"
#include "src/tint/program_builder.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::DepthTexture);
@@ -22,14 +23,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::DepthTexture);
namespace tint::type {
namespace {
bool IsValidDepthDimension(ast::TextureDimension dim) {
return dim == ast::TextureDimension::k2d || dim == ast::TextureDimension::k2dArray ||
dim == ast::TextureDimension::kCube || dim == ast::TextureDimension::kCubeArray;
bool IsValidDepthDimension(TextureDimension dim) {
return dim == TextureDimension::k2d || dim == TextureDimension::k2dArray ||
dim == TextureDimension::kCube || dim == TextureDimension::kCubeArray;
}
} // namespace
DepthTexture::DepthTexture(ast::TextureDimension dim)
DepthTexture::DepthTexture(TextureDimension dim)
: Base(utils::Hash(TypeInfo::Of<DepthTexture>().full_hashcode, dim), dim) {
TINT_ASSERT(Type, IsValidDepthDimension(dim));
}

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/type/texture.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
@@ -26,7 +27,7 @@ class DepthTexture final : public Castable<DepthTexture, Texture> {
public:
/// Constructor
/// @param dim the dimensionality of the texture
explicit DepthTexture(ast::TextureDimension dim);
explicit DepthTexture(TextureDimension dim);
/// Destructor
~DepthTexture() override;

View File

@@ -18,6 +18,7 @@
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
@@ -25,25 +26,25 @@ namespace {
using DepthTextureTest = TestHelper;
TEST_F(DepthTextureTest, Creation) {
auto* a = create<DepthTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthTexture>(ast::TextureDimension::k2d);
auto* c = create<DepthTexture>(ast::TextureDimension::k2dArray);
auto* a = create<DepthTexture>(TextureDimension::k2d);
auto* b = create<DepthTexture>(TextureDimension::k2d);
auto* c = create<DepthTexture>(TextureDimension::k2dArray);
EXPECT_EQ(a, b);
EXPECT_NE(a, c);
}
TEST_F(DepthTextureTest, Hash) {
auto* a = create<DepthTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthTexture>(TextureDimension::k2d);
auto* b = create<DepthTexture>(TextureDimension::k2d);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(DepthTextureTest, Equals) {
auto* a = create<DepthTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthTexture>(ast::TextureDimension::k2d);
auto* c = create<DepthTexture>(ast::TextureDimension::k2dArray);
auto* a = create<DepthTexture>(TextureDimension::k2d);
auto* b = create<DepthTexture>(TextureDimension::k2d);
auto* c = create<DepthTexture>(TextureDimension::k2dArray);
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -51,7 +52,7 @@ TEST_F(DepthTextureTest, Equals) {
}
TEST_F(DepthTextureTest, IsTexture) {
DepthTexture d(ast::TextureDimension::kCube);
DepthTexture d(TextureDimension::kCube);
Texture* ty = &d;
EXPECT_TRUE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<ExternalTexture>());
@@ -60,23 +61,23 @@ TEST_F(DepthTextureTest, IsTexture) {
}
TEST_F(DepthTextureTest, Dim) {
DepthTexture d(ast::TextureDimension::kCube);
EXPECT_EQ(d.dim(), ast::TextureDimension::kCube);
DepthTexture d(TextureDimension::kCube);
EXPECT_EQ(d.dim(), TextureDimension::kCube);
}
TEST_F(DepthTextureTest, FriendlyName) {
DepthTexture d(ast::TextureDimension::kCube);
DepthTexture d(TextureDimension::kCube);
EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_cube");
}
TEST_F(DepthTextureTest, Clone) {
auto* a = create<DepthTexture>(ast::TextureDimension::k2d);
auto* a = create<DepthTexture>(TextureDimension::k2d);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* dt = a->Clone(ctx);
EXPECT_EQ(dt->dim(), ast::TextureDimension::k2d);
EXPECT_EQ(dt->dim(), TextureDimension::k2d);
}
} // namespace

View File

@@ -15,6 +15,7 @@
#include "src/tint/type/external_texture.h"
#include "src/tint/program_builder.h"
#include "src/tint/type/texture_dimension.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::ExternalTexture);
@@ -22,7 +23,7 @@ namespace tint::type {
ExternalTexture::ExternalTexture()
: Base(static_cast<size_t>(TypeInfo::Of<ExternalTexture>().full_hashcode),
ast::TextureDimension::k2d) {}
TextureDimension::k2d) {}
ExternalTexture::~ExternalTexture() = default;

View File

@@ -19,6 +19,7 @@
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
@@ -58,7 +59,7 @@ TEST_F(ExternalTextureTest, IsTexture) {
TEST_F(ExternalTextureTest, Dim) {
F32 f32;
ExternalTexture s;
EXPECT_EQ(s.dim(), ast::TextureDimension::k2d);
EXPECT_EQ(s.dim(), TextureDimension::k2d);
}
TEST_F(ExternalTextureTest, FriendlyName) {

View File

@@ -15,13 +15,14 @@
#include "src/tint/type/multisampled_texture.h"
#include "src/tint/program_builder.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::MultisampledTexture);
namespace tint::type {
MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, const Type* type)
MultisampledTexture::MultisampledTexture(TextureDimension dim, const Type* type)
: Base(utils::Hash(TypeInfo::Of<MultisampledTexture>().full_hashcode, dim, type), dim),
type_(type) {
TINT_ASSERT(Type, type_);

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/type/texture.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
@@ -27,7 +28,7 @@ class MultisampledTexture final : public Castable<MultisampledTexture, Texture>
/// Constructor
/// @param dim the dimensionality of the texture
/// @param type the data type of the multisampled texture
MultisampledTexture(ast::TextureDimension dim, const Type* type);
MultisampledTexture(TextureDimension dim, const Type* type);
/// Destructor
~MultisampledTexture() override;

View File

@@ -19,6 +19,7 @@
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
@@ -26,26 +27,26 @@ namespace {
using MultisampledTextureTest = TestHelper;
TEST_F(MultisampledTextureTest, Creation) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<I32>());
auto* a = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
auto* c = create<MultisampledTexture>(TextureDimension::k3d, create<F32>());
auto* d = create<MultisampledTexture>(TextureDimension::k2d, create<I32>());
EXPECT_EQ(a, b);
EXPECT_NE(a, c);
EXPECT_NE(a, d);
}
TEST_F(MultisampledTextureTest, Hash) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* a = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(MultisampledTextureTest, Equals) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* c = create<MultisampledTexture>(ast::TextureDimension::k3d, create<F32>());
auto* d = create<MultisampledTexture>(ast::TextureDimension::k2d, create<I32>());
auto* a = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
auto* c = create<MultisampledTexture>(TextureDimension::k3d, create<F32>());
auto* d = create<MultisampledTexture>(TextureDimension::k2d, create<I32>());
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
EXPECT_FALSE(a->Equals(*d));
@@ -54,7 +55,7 @@ TEST_F(MultisampledTextureTest, Equals) {
TEST_F(MultisampledTextureTest, IsTexture) {
F32 f32;
MultisampledTexture s(ast::TextureDimension::kCube, &f32);
MultisampledTexture s(TextureDimension::kCube, &f32);
Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<ExternalTexture>());
@@ -65,30 +66,30 @@ TEST_F(MultisampledTextureTest, IsTexture) {
TEST_F(MultisampledTextureTest, Dim) {
F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), ast::TextureDimension::k3d);
MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), TextureDimension::k3d);
}
TEST_F(MultisampledTextureTest, Type) {
F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32);
}
TEST_F(MultisampledTextureTest, FriendlyName) {
F32 f32;
MultisampledTexture s(ast::TextureDimension::k3d, &f32);
MultisampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_multisampled_3d<f32>");
}
TEST_F(MultisampledTextureTest, Clone) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* a = create<MultisampledTexture>(TextureDimension::k2d, create<F32>());
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* mt = a->Clone(ctx);
EXPECT_EQ(mt->dim(), ast::TextureDimension::k2d);
EXPECT_EQ(mt->dim(), TextureDimension::k2d);
EXPECT_TRUE(mt->type()->Is<F32>());
}

View File

@@ -15,13 +15,14 @@
#include "src/tint/type/sampled_texture.h"
#include "src/tint/program_builder.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/utils/hash.h"
TINT_INSTANTIATE_TYPEINFO(tint::type::SampledTexture);
namespace tint::type {
SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type)
SampledTexture::SampledTexture(TextureDimension dim, const Type* type)
: Base(utils::Hash(TypeInfo::Of<SampledTexture>().full_hashcode, dim, type), dim), type_(type) {
TINT_ASSERT(Type, type_);
}

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/type/texture.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
@@ -27,7 +28,7 @@ class SampledTexture final : public Castable<SampledTexture, Texture> {
/// Constructor
/// @param dim the dimensionality of the texture
/// @param type the data type of the sampled texture
SampledTexture(ast::TextureDimension dim, const Type* type);
SampledTexture(TextureDimension dim, const Type* type);
/// Destructor
~SampledTexture() override;

View File

@@ -18,6 +18,7 @@
#include "src/tint/type/external_texture.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
@@ -25,13 +26,13 @@ namespace {
using SampledTextureTest = TestHelper;
TEST_F(SampledTextureTest, Creation) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<I32>());
auto* a = create<SampledTexture>(TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(TextureDimension::kCube, create<F32>());
auto* c = create<SampledTexture>(TextureDimension::k2d, create<F32>());
auto* d = create<SampledTexture>(TextureDimension::kCube, create<I32>());
EXPECT_TRUE(a->type()->Is<F32>());
EXPECT_EQ(a->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(a->dim(), TextureDimension::kCube);
EXPECT_EQ(a, b);
EXPECT_NE(a, c);
@@ -39,17 +40,17 @@ TEST_F(SampledTextureTest, Creation) {
}
TEST_F(SampledTextureTest, Hash) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* a = create<SampledTexture>(TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(TextureDimension::kCube, create<F32>());
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(SampledTextureTest, Equals) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* c = create<SampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* d = create<SampledTexture>(ast::TextureDimension::kCube, create<I32>());
auto* a = create<SampledTexture>(TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(TextureDimension::kCube, create<F32>());
auto* c = create<SampledTexture>(TextureDimension::k2d, create<F32>());
auto* d = create<SampledTexture>(TextureDimension::kCube, create<I32>());
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -59,7 +60,7 @@ TEST_F(SampledTextureTest, Equals) {
TEST_F(SampledTextureTest, IsTexture) {
F32 f32;
SampledTexture s(ast::TextureDimension::kCube, &f32);
SampledTexture s(TextureDimension::kCube, &f32);
Texture* ty = &s;
EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_FALSE(ty->Is<ExternalTexture>());
@@ -69,30 +70,30 @@ TEST_F(SampledTextureTest, IsTexture) {
TEST_F(SampledTextureTest, Dim) {
F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), ast::TextureDimension::k3d);
SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.dim(), TextureDimension::k3d);
}
TEST_F(SampledTextureTest, Type) {
F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.type(), &f32);
}
TEST_F(SampledTextureTest, FriendlyName) {
F32 f32;
SampledTexture s(ast::TextureDimension::k3d, &f32);
SampledTexture s(TextureDimension::k3d, &f32);
EXPECT_EQ(s.FriendlyName(Symbols()), "texture_3d<f32>");
}
TEST_F(SampledTextureTest, Clone) {
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* a = create<SampledTexture>(TextureDimension::kCube, create<F32>());
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* mt = a->Clone(ctx);
EXPECT_EQ(mt->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(mt->dim(), TextureDimension::kCube);
EXPECT_TRUE(mt->type()->Is<F32>());
}

View File

@@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::StorageTexture);
namespace tint::type {
StorageTexture::StorageTexture(ast::TextureDimension dim,
StorageTexture::StorageTexture(TextureDimension dim,
ast::TexelFormat format,
ast::Access access,
Type* subtype)

View File

@@ -20,6 +20,7 @@
#include "src/tint/ast/access.h"
#include "src/tint/ast/storage_texture.h"
#include "src/tint/type/texture.h"
#include "src/tint/type/texture_dimension.h"
// Forward declarations
namespace tint::type {
@@ -36,7 +37,7 @@ class StorageTexture final : public Castable<StorageTexture, Texture> {
/// @param format the texel format of the texture
/// @param access the access control type of the texture
/// @param subtype the storage subtype. Use SubtypeFor() to calculate this.
StorageTexture(ast::TextureDimension dim,
StorageTexture(TextureDimension dim,
ast::TexelFormat format,
ast::Access access,
Type* subtype);

View File

@@ -18,31 +18,30 @@
#include "src/tint/type/external_texture.h"
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/test_helper.h"
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
namespace {
struct StorageTextureTest : public TestHelper {
StorageTexture* Create(ast::TextureDimension dims, ast::TexelFormat fmt, ast::Access access) {
StorageTexture* Create(TextureDimension dims, ast::TexelFormat fmt, ast::Access access) {
auto* subtype = StorageTexture::SubtypeFor(fmt, Types());
return create<StorageTexture>(dims, fmt, access, subtype);
}
};
TEST_F(StorageTextureTest, Creation) {
auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* a =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* b =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* c =
Create(ast::TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* d =
Create(ast::TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite);
auto* e =
Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead);
Create(TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* d = Create(TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite);
auto* e = Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead);
EXPECT_TRUE(a->type()->Is<F32>());
EXPECT_EQ(a->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(a->dim(), TextureDimension::kCube);
EXPECT_EQ(a, b);
EXPECT_NE(a, c);
@@ -51,25 +50,23 @@ TEST_F(StorageTextureTest, Creation) {
}
TEST_F(StorageTextureTest, Hash) {
auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* a =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* b =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
EXPECT_EQ(a->unique_hash, b->unique_hash);
}
TEST_F(StorageTextureTest, Equals) {
auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* a =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* b =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* c =
Create(ast::TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* d =
Create(ast::TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite);
auto* e =
Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead);
Create(TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto* d = Create(TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite);
auto* e = Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead);
EXPECT_TRUE(a->Equals(*b));
EXPECT_FALSE(a->Equals(*c));
@@ -79,26 +76,26 @@ TEST_F(StorageTextureTest, Equals) {
}
TEST_F(StorageTextureTest, Dim) {
auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
EXPECT_EQ(s->dim(), ast::TextureDimension::k2dArray);
auto* s =
Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
EXPECT_EQ(s->dim(), TextureDimension::k2dArray);
}
TEST_F(StorageTextureTest, Format) {
auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* s =
Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
EXPECT_EQ(s->texel_format(), ast::TexelFormat::kRgba32Float);
}
TEST_F(StorageTextureTest, FriendlyName) {
auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* s =
Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
EXPECT_EQ(s->FriendlyName(Symbols()), "texture_storage_2d_array<rgba32float, read_write>");
}
TEST_F(StorageTextureTest, F32) {
Type* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
Type* s =
Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
auto program = Build();
@@ -110,7 +107,7 @@ TEST_F(StorageTextureTest, F32) {
TEST_F(StorageTextureTest, U32) {
auto* subtype = StorageTexture::SubtypeFor(ast::TexelFormat::kRg32Uint, Types());
Type* s = create<StorageTexture>(ast::TextureDimension::k2dArray, ast::TexelFormat::kRg32Uint,
Type* s = create<StorageTexture>(TextureDimension::k2dArray, ast::TexelFormat::kRg32Uint,
ast::Access::kReadWrite, subtype);
auto program = Build();
@@ -123,7 +120,7 @@ TEST_F(StorageTextureTest, U32) {
TEST_F(StorageTextureTest, I32) {
auto* subtype = StorageTexture::SubtypeFor(ast::TexelFormat::kRgba32Sint, Types());
Type* s = create<StorageTexture>(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Sint,
Type* s = create<StorageTexture>(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Sint,
ast::Access::kReadWrite, subtype);
auto program = Build();
@@ -135,14 +132,14 @@ TEST_F(StorageTextureTest, I32) {
}
TEST_F(StorageTextureTest, Clone) {
auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float,
ast::Access::kReadWrite);
auto* a =
Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite);
type::Manager mgr;
type::CloneContext ctx{{nullptr}, {nullptr, &mgr}};
auto* mt = a->Clone(ctx);
EXPECT_EQ(mt->dim(), ast::TextureDimension::kCube);
EXPECT_EQ(mt->dim(), TextureDimension::kCube);
EXPECT_EQ(mt->texel_format(), ast::TexelFormat::kRgba32Float);
EXPECT_TRUE(mt->type()->Is<F32>());
}

View File

@@ -18,7 +18,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Texture);
namespace tint::type {
Texture::Texture(size_t hash, ast::TextureDimension dim) : Base(hash, type::Flags{}), dim_(dim) {}
Texture::Texture(size_t hash, TextureDimension dim) : Base(hash, type::Flags{}), dim_(dim) {}
Texture::~Texture() = default;

View File

@@ -16,6 +16,7 @@
#define SRC_TINT_TYPE_TEXTURE_H_
#include "src/tint/ast/texture.h"
#include "src/tint/type/texture_dimension.h"
#include "src/tint/type/type.h"
namespace tint::type {
@@ -26,15 +27,15 @@ class Texture : public Castable<Texture, Type> {
/// Constructor
/// @param hash the unique hash of the node
/// @param dim the dimensionality of the texture
Texture(size_t hash, ast::TextureDimension dim);
Texture(size_t hash, TextureDimension dim);
/// Destructor
~Texture() override;
/// @returns the texture dimension
ast::TextureDimension dim() const { return dim_; }
TextureDimension dim() const { return dim_; }
private:
ast::TextureDimension const dim_;
TextureDimension const dim_;
};
} // namespace tint::type

View File

@@ -0,0 +1,46 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/type/texture_dimension.h"
namespace tint::type {
std::ostream& operator<<(std::ostream& out, type::TextureDimension dim) {
switch (dim) {
case type::TextureDimension::kNone:
out << "None";
break;
case type::TextureDimension::k1d:
out << "1d";
break;
case type::TextureDimension::k2d:
out << "2d";
break;
case type::TextureDimension::k2dArray:
out << "2d_array";
break;
case type::TextureDimension::k3d:
out << "3d";
break;
case type::TextureDimension::kCube:
out << "cube";
break;
case type::TextureDimension::kCubeArray:
out << "cube_array";
break;
}
return out;
}
} // namespace tint::type

View File

@@ -0,0 +1,47 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_TYPE_TEXTURE_DIMENSION_H_
#define SRC_TINT_TYPE_TEXTURE_DIMENSION_H_
#include <ostream>
namespace tint::type {
/// The dimensionality of the texture
enum class TextureDimension {
/// Invalid texture
kNone = -1,
/// 1 dimensional texture
k1d,
/// 2 dimensional texture
k2d,
/// 2 dimensional array texture
k2dArray,
/// 3 dimensional texture
k3d,
/// cube texture
kCube,
/// cube array texture
kCubeArray,
};
/// @param out the std::ostream to write to
/// @param dim the type::TextureDimension
/// @return the std::ostream so calls can be chained
std::ostream& operator<<(std::ostream& out, type::TextureDimension dim);
} // namespace tint::type
#endif // SRC_TINT_TYPE_TEXTURE_DIMENSION_H_

View File

@@ -20,7 +20,7 @@
namespace tint::type {
namespace {
using TextureTypeDimTest = TestParamHelper<ast::TextureDimension>;
using TextureTypeDimTest = TestParamHelper<TextureDimension>;
TEST_P(TextureTypeDimTest, DimMustMatch) {
// Check that the dim() query returns the right dimensionality.
@@ -33,12 +33,12 @@ TEST_P(TextureTypeDimTest, DimMustMatch) {
INSTANTIATE_TEST_SUITE_P(Dimensions,
TextureTypeDimTest,
::testing::Values(ast::TextureDimension::k1d,
ast::TextureDimension::k2d,
ast::TextureDimension::k2dArray,
ast::TextureDimension::k3d,
ast::TextureDimension::kCube,
ast::TextureDimension::kCubeArray));
::testing::Values(TextureDimension::k1d,
TextureDimension::k2d,
TextureDimension::k2dArray,
TextureDimension::k3d,
TextureDimension::kCube,
TextureDimension::kCubeArray));
} // namespace
} // namespace tint::type