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>
This commit is contained in:
Ben Clayton 2021-05-20 14:42:28 +00:00 committed by Tint LUCI CQ
parent cc98b4f9aa
commit 55ecfc4a24
5 changed files with 42 additions and 72 deletions

View File

@ -572,14 +572,14 @@ class InspectorHelper : public ProgramBuilder {
/// @param format the image format of the storage texture /// @param format the image format of the storage texture
/// @param read_only should the access type be read only, otherwise write only /// @param read_only should the access type be read only, otherwise write only
/// @returns the storage texture type, subtype & access control type /// @returns the storage texture type, subtype & access control type
typ::Type MakeStorageTextureTypes(ast::TextureDimension dim, ast::Type* MakeStorageTextureTypes(ast::TextureDimension dim,
ast::ImageFormat format, ast::ImageFormat format,
bool read_only) { bool read_only) {
auto ac = read_only ? ast::AccessControl::kReadOnly auto ac = read_only ? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly; : ast::AccessControl::kWriteOnly;
auto tex = ty.storage_texture(dim, format); 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 /// Adds a storage texture variable to the program
@ -1688,13 +1688,13 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) {
MakeComparisonSamplerReferenceBodyFunction( MakeComparisonSamplerReferenceBodyFunction(
"cs_func", "cs_texture", "cs_var", "cs_coords", "cs_depth", ty.f32(), {}); "cs_func", "cs_texture", "cs_var", "cs_coords", "cs_depth", ty.f32(), {});
auto st_type = MakeStorageTextureTypes(ast::TextureDimension::k2d, auto* st_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
ast::ImageFormat::kR32Uint, false); ast::ImageFormat::kR32Uint, false);
AddStorageTexture("st_var", st_type, 4, 0); AddStorageTexture("st_var", st_type, 4, 0);
MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2<i32>(), {}); MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2<i32>(), {});
auto rost_type = MakeStorageTextureTypes(ast::TextureDimension::k2d, auto* rost_type = MakeStorageTextureTypes(ast::TextureDimension::k2d,
ast::ImageFormat::kR32Uint, true); ast::ImageFormat::kR32Uint, true);
AddStorageTexture("rost_var", rost_type, 4, 1); AddStorageTexture("rost_var", rost_type, 4, 1);
MakeStorageTextureBodyFunction("rost_func", "rost_var", ty.vec2<i32>(), {}); MakeStorageTextureBodyFunction("rost_func", "rost_var", ty.vec2<i32>(), {});
@ -2797,7 +2797,7 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {
ResourceBinding::SampledKind expected_kind; ResourceBinding::SampledKind expected_kind;
std::tie(format, expected_format, expected_kind) = format_params; 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); AddStorageTexture("st_var", st_type, 0, 0);
ast::Type* dim_type = nullptr; ast::Type* dim_type = nullptr;

View File

@ -79,7 +79,7 @@ TEST_F(IntrinsicTableTest, MatchI32) {
auto* f32 = create<sem::F32>(); auto* f32 = create<sem::F32>();
auto* i32 = create<sem::I32>(); auto* i32 = create<sem::I32>();
auto* vec4_f32 = create<sem::Vector>(f32, 4); 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, auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, i32, i32}, Source{}); {tex, i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr); ASSERT_NE(result.intrinsic, nullptr);
@ -94,7 +94,7 @@ TEST_F(IntrinsicTableTest, MatchI32) {
TEST_F(IntrinsicTableTest, MismatchI32) { TEST_F(IntrinsicTableTest, MismatchI32) {
auto* f32 = create<sem::F32>(); 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 = auto result =
table->Lookup(*this, IntrinsicType::kTextureLoad, {tex, f32}, Source{}); table->Lookup(*this, IntrinsicType::kTextureLoad, {tex, f32}, Source{});
ASSERT_EQ(result.intrinsic, nullptr); ASSERT_EQ(result.intrinsic, nullptr);
@ -241,7 +241,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) {
auto* f32 = create<sem::F32>(); auto* f32 = create<sem::F32>();
auto* vec2_f32 = create<sem::Vector>(f32, 2); auto* vec2_f32 = create<sem::Vector>(f32, 2);
auto* vec4_f32 = create<sem::Vector>(f32, 4); 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 sampler = ty.sampler(ast::SamplerKind::kSampler);
auto result = table->Lookup(*this, IntrinsicType::kTextureSample, auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, sampler, vec2_f32}, Source{}); {tex, sampler, vec2_f32}, Source{});
@ -258,7 +258,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) {
TEST_F(IntrinsicTableTest, MismatchSampler) { TEST_F(IntrinsicTableTest, MismatchSampler) {
auto* f32 = create<sem::F32>(); auto* f32 = create<sem::F32>();
auto* vec2_f32 = create<sem::Vector>(f32, 2); 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, auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, f32, vec2_f32}, Source{}); {tex, f32, vec2_f32}, Source{});
ASSERT_EQ(result.intrinsic, nullptr); ASSERT_EQ(result.intrinsic, nullptr);
@ -270,7 +270,7 @@ TEST_F(IntrinsicTableTest, MatchSampledTexture) {
auto* f32 = create<sem::F32>(); auto* f32 = create<sem::F32>();
auto* vec2_i32 = create<sem::Vector>(i32, 2); auto* vec2_i32 = create<sem::Vector>(i32, 2);
auto* vec4_f32 = create<sem::Vector>(f32, 4); 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, auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, vec2_i32, i32}, Source{}); {tex, vec2_i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr); ASSERT_NE(result.intrinsic, nullptr);
@ -305,7 +305,7 @@ TEST_F(IntrinsicTableTest, MatchDepthTexture) {
auto* f32 = create<sem::F32>(); auto* f32 = create<sem::F32>();
auto* i32 = create<sem::I32>(); auto* i32 = create<sem::I32>();
auto* vec2_i32 = create<sem::Vector>(i32, 2); 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, auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, vec2_i32, i32}, Source{}); {tex, vec2_i32, i32}, Source{});
ASSERT_NE(result.intrinsic, nullptr); ASSERT_NE(result.intrinsic, nullptr);
@ -510,7 +510,7 @@ TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) {
} }
TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) { 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* bool_ = create<sem::Bool>();
auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions, auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions,
{tex, bool_}, Source{}); {tex, bool_}, Source{});

View File

@ -766,8 +766,7 @@ class ProgramBuilder {
/// @param dims the dimensionality of the texture /// @param dims the dimensionality of the texture
/// @returns the depth texture /// @returns the depth texture
typ::DepthTexture depth_texture(ast::TextureDimension dims) const { typ::DepthTexture depth_texture(ast::TextureDimension dims) const {
return {builder->create<ast::DepthTexture>(dims), return {builder->create<ast::DepthTexture>(dims)};
builder->create<sem::DepthTexture>(dims)};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -775,8 +774,7 @@ class ProgramBuilder {
/// @returns the depth texture /// @returns the depth texture
typ::DepthTexture depth_texture(const Source& source, typ::DepthTexture depth_texture(const Source& source,
ast::TextureDimension dims) const { ast::TextureDimension dims) const {
return {builder->create<ast::DepthTexture>(source, dims), return {builder->create<ast::DepthTexture>(source, dims)};
builder->create<sem::DepthTexture>(dims)};
} }
/// @param dims the dimensionality of the texture /// @param dims the dimensionality of the texture
@ -784,10 +782,7 @@ class ProgramBuilder {
/// @returns the sampled texture /// @returns the sampled texture
typ::SampledTexture sampled_texture(ast::TextureDimension dims, typ::SampledTexture sampled_texture(ast::TextureDimension dims,
typ::Type subtype) const { typ::Type subtype) const {
return {subtype.ast ? builder->create<ast::SampledTexture>(dims, subtype) return {builder->create<ast::SampledTexture>(dims, subtype)};
: nullptr,
subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
: nullptr};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -797,11 +792,7 @@ class ProgramBuilder {
typ::SampledTexture sampled_texture(const Source& source, typ::SampledTexture sampled_texture(const Source& source,
ast::TextureDimension dims, ast::TextureDimension dims,
typ::Type subtype) const { typ::Type subtype) const {
return {subtype.ast return {builder->create<ast::SampledTexture>(source, dims, subtype)};
? builder->create<ast::SampledTexture>(source, dims, subtype)
: nullptr,
subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
: nullptr};
} }
/// @param dims the dimensionality of the texture /// @param dims the dimensionality of the texture
@ -809,11 +800,7 @@ class ProgramBuilder {
/// @returns the multisampled texture /// @returns the multisampled texture
typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims, typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims,
typ::Type subtype) const { typ::Type subtype) const {
return { return {builder->create<ast::MultisampledTexture>(dims, subtype)};
subtype.ast ? builder->create<ast::MultisampledTexture>(dims, subtype)
: nullptr,
subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
: nullptr};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -823,12 +810,7 @@ class ProgramBuilder {
typ::MultisampledTexture multisampled_texture(const Source& source, typ::MultisampledTexture multisampled_texture(const Source& source,
ast::TextureDimension dims, ast::TextureDimension dims,
typ::Type subtype) const { typ::Type subtype) const {
return { return {builder->create<ast::MultisampledTexture>(source, dims, subtype)};
subtype.ast
? builder->create<ast::MultisampledTexture>(source, dims, subtype)
: nullptr,
subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
: nullptr};
} }
/// @param dims the dimensionality of the texture /// @param dims the dimensionality of the texture
@ -836,12 +818,8 @@ class ProgramBuilder {
/// @returns the storage texture /// @returns the storage texture
typ::StorageTexture storage_texture(ast::TextureDimension dims, typ::StorageTexture storage_texture(ast::TextureDimension dims,
ast::ImageFormat format) const { ast::ImageFormat format) const {
auto* ast_subtype = ast::StorageTexture::SubtypeFor(format, *builder); auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder);
auto* sem_subtype = return {builder->create<ast::StorageTexture>(dims, format, 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)};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -851,26 +829,20 @@ class ProgramBuilder {
typ::StorageTexture storage_texture(const Source& source, typ::StorageTexture storage_texture(const Source& source,
ast::TextureDimension dims, ast::TextureDimension dims,
ast::ImageFormat format) const { ast::ImageFormat format) const {
auto* ast_subtype = ast::StorageTexture::SubtypeFor(format, *builder); auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder);
auto* sem_subtype = return {
sem::StorageTexture::SubtypeFor(format, builder->Types()); builder->create<ast::StorageTexture>(source, dims, format, subtype)};
return {builder->create<ast::StorageTexture>(source, dims, format,
ast_subtype),
builder->create<sem::StorageTexture>(
dims, format, ast::AccessControl::kInvalid, sem_subtype)};
} }
/// @returns the external texture /// @returns the external texture
typ::ExternalTexture external_texture() const { typ::ExternalTexture external_texture() const {
return {builder->create<ast::ExternalTexture>(), return {builder->create<ast::ExternalTexture>()};
builder->create<sem::ExternalTexture>()};
} }
/// @param source the Source of the node /// @param source the Source of the node
/// @returns the external texture /// @returns the external texture
typ::ExternalTexture external_texture(const Source& source) const { typ::ExternalTexture external_texture(const Source& source) const {
return {builder->create<ast::ExternalTexture>(source), return {builder->create<ast::ExternalTexture>(source)};
builder->create<sem::ExternalTexture>()};
} }
/// If ty is a ast::Struct or ast::Alias, the returned type is an /// If ty is a ast::Struct or ast::Alias, the returned type is an

View File

@ -237,18 +237,10 @@ bool operator!=(std::nullptr_t, const TypePair<AST, SEM>& rhs) {
using Type = TypePair<ast::Type, sem::Type>; 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 Matrix = TypePair<ast::Matrix, sem::Matrix>;
using MultisampledTexture =
TypePair<ast::MultisampledTexture, sem::MultisampledTexture>;
using Pointer = TypePair<ast::Pointer, sem::Pointer>; using Pointer = TypePair<ast::Pointer, sem::Pointer>;
using Sampler = TypePair<ast::Sampler, sem::Sampler>; 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 Struct = TypePair<ast::Struct, sem::Struct>;
using Texture = TypePair<ast::Texture, sem::Texture>;
using Vector = TypePair<ast::Vector, sem::Vector>; using Vector = TypePair<ast::Vector, sem::Vector>;
using Bool = Ptr<ast::Bool>; using Bool = Ptr<ast::Bool>;
@ -256,6 +248,12 @@ using U32 = Ptr<ast::U32>;
using I32 = Ptr<ast::I32>; using I32 = Ptr<ast::I32>;
using F32 = Ptr<ast::F32>; using F32 = Ptr<ast::F32>;
using Void = Ptr<ast::Void>; 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 // Helpers

View File

@ -842,7 +842,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) {
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R32f %1 = OpTypeImage %2 1D 0 0 0 2 R32f
@ -862,7 +862,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f %1 = OpTypeImage %2 2D 0 0 0 2 R32f
@ -882,7 +882,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 2 R32f %1 = OpTypeImage %2 2D 0 1 0 2 R32f
@ -902,7 +902,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 3D 0 0 0 2 R32f %1 = OpTypeImage %2 3D 0 0 0 2 R32f
@ -923,7 +923,7 @@ TEST_F(BuilderTest_Type,
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f %1 = OpTypeImage %2 2D 0 0 0 2 R32f
@ -944,7 +944,7 @@ TEST_F(BuilderTest_Type,
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 2D 0 0 0 2 R32i %1 = OpTypeImage %2 2D 0 0 0 2 R32i
@ -965,7 +965,7 @@ TEST_F(BuilderTest_Type,
spirv::Builder& b = Build(); 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(); ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui %1 = OpTypeImage %2 2D 0 0 0 2 R32ui