Have TypesBuilder texture methods return ast types
Bug: tint:724
Change-Id: I31c9632c01971a08185bd95c1a3cc7da759f4002
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51662
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc
index 23d6fac..51f9d41 100644
--- a/src/inspector/inspector_test.cc
+++ b/src/inspector/inspector_test.cc
@@ -572,14 +572,14 @@
/// @param format the image format of the storage texture
/// @param read_only should the access type be read only, otherwise write only
/// @returns the storage texture type, subtype & access control type
- typ::Type MakeStorageTextureTypes(ast::TextureDimension dim,
- ast::ImageFormat format,
- bool read_only) {
+ ast::Type* MakeStorageTextureTypes(ast::TextureDimension dim,
+ ast::ImageFormat format,
+ bool read_only) {
auto ac = read_only ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly;
auto tex = ty.storage_texture(dim, format);
- return {ty.access(ac, tex.ast), tex.sem};
+ return ty.access(ac, tex);
}
/// Adds a storage texture variable to the program
@@ -1688,13 +1688,13 @@
MakeComparisonSamplerReferenceBodyFunction(
"cs_func", "cs_texture", "cs_var", "cs_coords", "cs_depth", ty.f32(), {});
- auto st_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
- ast::ImageFormat::kR32Uint, false);
+ auto* st_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
+ ast::ImageFormat::kR32Uint, false);
AddStorageTexture("st_var", st_type, 4, 0);
MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2<i32>(), {});
- auto rost_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
- ast::ImageFormat::kR32Uint, true);
+ auto* rost_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
+ ast::ImageFormat::kR32Uint, true);
AddStorageTexture("rost_var", rost_type, 4, 1);
MakeStorageTextureBodyFunction("rost_func", "rost_var", ty.vec2<i32>(), {});
@@ -2797,7 +2797,7 @@
ResourceBinding::SampledKind expected_kind;
std::tie(format, expected_format, expected_kind) = format_params;
- auto st_type = MakeStorageTextureTypes(dim, format, read_only);
+ auto* st_type = MakeStorageTextureTypes(dim, format, read_only);
AddStorageTexture("st_var", st_type, 0, 0);
ast::Type* dim_type = nullptr;
diff --git a/src/intrinsic_table_test.cc b/src/intrinsic_table_test.cc
index 4db434d..9cad7dd 100644
--- a/src/intrinsic_table_test.cc
+++ b/src/intrinsic_table_test.cc
@@ -79,7 +79,7 @@
auto* f32 = create<sem::F32>();
auto* i32 = create<sem::I32>();
auto* vec4_f32 = create<sem::Vector>(f32, 4);
- auto tex = ty.sampled_texture(ast::TextureDimension::k1d, f32);
+ auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32);
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@@ -94,7 +94,7 @@
TEST_F(IntrinsicTableTest, MismatchI32) {
auto* f32 = create<sem::F32>();
- auto tex = ty.sampled_texture(ast::TextureDimension::k1d, f32);
+ auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k1d, f32);
auto result =
table->Lookup(*this, IntrinsicType::kTextureLoad, {tex, f32}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
@@ -241,7 +241,7 @@
auto* f32 = create<sem::F32>();
auto* vec2_f32 = create<sem::Vector>(f32, 2);
auto* vec4_f32 = create<sem::Vector>(f32, 4);
- auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32);
+ auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
auto sampler = ty.sampler(ast::SamplerKind::kSampler);
auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, sampler, vec2_f32}, Source{});
@@ -258,7 +258,7 @@
TEST_F(IntrinsicTableTest, MismatchSampler) {
auto* f32 = create<sem::F32>();
auto* vec2_f32 = create<sem::Vector>(f32, 2);
- auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32);
+ auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, f32, vec2_f32}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
@@ -270,7 +270,7 @@
auto* f32 = create<sem::F32>();
auto* vec2_i32 = create<sem::Vector>(i32, 2);
auto* vec4_f32 = create<sem::Vector>(f32, 4);
- auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32);
+ auto* tex = create<sem::SampledTexture>(ast::TextureDimension::k2d, f32);
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, vec2_i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@@ -305,7 +305,7 @@
auto* f32 = create<sem::F32>();
auto* i32 = create<sem::I32>();
auto* vec2_i32 = create<sem::Vector>(i32, 2);
- auto tex = ty.depth_texture(ast::TextureDimension::k2d);
+ auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d);
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, vec2_i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@@ -510,7 +510,7 @@
}
TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) {
- auto tex = ty.depth_texture(ast::TextureDimension::k2d);
+ auto* tex = create<sem::DepthTexture>(ast::TextureDimension::k2d);
auto* bool_ = create<sem::Bool>();
auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions,
{tex, bool_}, Source{});
diff --git a/src/program_builder.h b/src/program_builder.h
index 1ddc135..da8aa40 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -766,8 +766,7 @@
/// @param dims the dimensionality of the texture
/// @returns the depth texture
typ::DepthTexture depth_texture(ast::TextureDimension dims) const {
- return {builder->create<ast::DepthTexture>(dims),
- builder->create<sem::DepthTexture>(dims)};
+ return {builder->create<ast::DepthTexture>(dims)};
}
/// @param source the Source of the node
@@ -775,8 +774,7 @@
/// @returns the depth texture
typ::DepthTexture depth_texture(const Source& source,
ast::TextureDimension dims) const {
- return {builder->create<ast::DepthTexture>(source, dims),
- builder->create<sem::DepthTexture>(dims)};
+ return {builder->create<ast::DepthTexture>(source, dims)};
}
/// @param dims the dimensionality of the texture
@@ -784,10 +782,7 @@
/// @returns the sampled texture
typ::SampledTexture sampled_texture(ast::TextureDimension dims,
typ::Type subtype) const {
- return {subtype.ast ? builder->create<ast::SampledTexture>(dims, subtype)
- : nullptr,
- subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
- : nullptr};
+ return {builder->create<ast::SampledTexture>(dims, subtype)};
}
/// @param source the Source of the node
@@ -797,11 +792,7 @@
typ::SampledTexture sampled_texture(const Source& source,
ast::TextureDimension dims,
typ::Type subtype) const {
- return {subtype.ast
- ? builder->create<ast::SampledTexture>(source, dims, subtype)
- : nullptr,
- subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
- : nullptr};
+ return {builder->create<ast::SampledTexture>(source, dims, subtype)};
}
/// @param dims the dimensionality of the texture
@@ -809,11 +800,7 @@
/// @returns the multisampled texture
typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims,
typ::Type subtype) const {
- return {
- subtype.ast ? builder->create<ast::MultisampledTexture>(dims, subtype)
- : nullptr,
- subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
- : nullptr};
+ return {builder->create<ast::MultisampledTexture>(dims, subtype)};
}
/// @param source the Source of the node
@@ -823,12 +810,7 @@
typ::MultisampledTexture multisampled_texture(const Source& source,
ast::TextureDimension dims,
typ::Type subtype) const {
- return {
- subtype.ast
- ? builder->create<ast::MultisampledTexture>(source, dims, subtype)
- : nullptr,
- subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
- : nullptr};
+ return {builder->create<ast::MultisampledTexture>(source, dims, subtype)};
}
/// @param dims the dimensionality of the texture
@@ -836,12 +818,8 @@
/// @returns the storage texture
typ::StorageTexture storage_texture(ast::TextureDimension dims,
ast::ImageFormat format) const {
- auto* ast_subtype = ast::StorageTexture::SubtypeFor(format, *builder);
- auto* sem_subtype =
- sem::StorageTexture::SubtypeFor(format, builder->Types());
- return {builder->create<ast::StorageTexture>(dims, format, ast_subtype),
- builder->create<sem::StorageTexture>(
- dims, format, ast::AccessControl::kInvalid, sem_subtype)};
+ auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder);
+ return {builder->create<ast::StorageTexture>(dims, format, subtype)};
}
/// @param source the Source of the node
@@ -851,26 +829,20 @@
typ::StorageTexture storage_texture(const Source& source,
ast::TextureDimension dims,
ast::ImageFormat format) const {
- auto* ast_subtype = ast::StorageTexture::SubtypeFor(format, *builder);
- auto* sem_subtype =
- sem::StorageTexture::SubtypeFor(format, builder->Types());
- return {builder->create<ast::StorageTexture>(source, dims, format,
- ast_subtype),
- builder->create<sem::StorageTexture>(
- dims, format, ast::AccessControl::kInvalid, sem_subtype)};
+ auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder);
+ return {
+ builder->create<ast::StorageTexture>(source, dims, format, subtype)};
}
/// @returns the external texture
typ::ExternalTexture external_texture() const {
- return {builder->create<ast::ExternalTexture>(),
- builder->create<sem::ExternalTexture>()};
+ return {builder->create<ast::ExternalTexture>()};
}
/// @param source the Source of the node
/// @returns the external texture
typ::ExternalTexture external_texture(const Source& source) const {
- return {builder->create<ast::ExternalTexture>(source),
- builder->create<sem::ExternalTexture>()};
+ return {builder->create<ast::ExternalTexture>(source)};
}
/// If ty is a ast::Struct or ast::Alias, the returned type is an
diff --git a/src/typepair.h b/src/typepair.h
index 4a6762a..61dfe06 100644
--- a/src/typepair.h
+++ b/src/typepair.h
@@ -237,18 +237,10 @@
using Type = TypePair<ast::Type, sem::Type>;
-using Array = TypePair<ast::Array, sem::Array>;
-using DepthTexture = TypePair<ast::DepthTexture, sem::DepthTexture>;
-using ExternalTexture = TypePair<ast::ExternalTexture, sem::ExternalTexture>;
using Matrix = TypePair<ast::Matrix, sem::Matrix>;
-using MultisampledTexture =
- TypePair<ast::MultisampledTexture, sem::MultisampledTexture>;
using Pointer = TypePair<ast::Pointer, sem::Pointer>;
using Sampler = TypePair<ast::Sampler, sem::Sampler>;
-using SampledTexture = TypePair<ast::SampledTexture, sem::SampledTexture>;
-using StorageTexture = TypePair<ast::StorageTexture, sem::StorageTexture>;
using Struct = TypePair<ast::Struct, sem::Struct>;
-using Texture = TypePair<ast::Texture, sem::Texture>;
using Vector = TypePair<ast::Vector, sem::Vector>;
using Bool = Ptr<ast::Bool>;
@@ -256,6 +248,12 @@
using I32 = Ptr<ast::I32>;
using F32 = Ptr<ast::F32>;
using Void = Ptr<ast::Void>;
+using DepthTexture = Ptr<ast::DepthTexture>;
+using ExternalTexture = Ptr<ast::ExternalTexture>;
+using MultisampledTexture = Ptr<ast::MultisampledTexture>;
+using SampledTexture = Ptr<ast::SampledTexture>;
+using StorageTexture = Ptr<ast::StorageTexture>;
+using Texture = Ptr<ast::Texture>;
// Helpers
diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc
index 51cb38e..255f695 100644
--- a/src/writer/spirv/builder_type_test.cc
+++ b/src/writer/spirv/builder_type_test.cc
@@ -842,7 +842,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R32f
@@ -862,7 +862,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
@@ -882,7 +882,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 2 R32f
@@ -902,7 +902,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 3D 0 0 0 2 R32f
@@ -923,7 +923,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
@@ -944,7 +944,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 2D 0 0 0 2 R32i
@@ -965,7 +965,7 @@
spirv::Builder& b = Build();
- EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
+ EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui