diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 23d6fac5b0..51f9d41e69 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -572,14 +572,14 @@ class InspectorHelper : public ProgramBuilder { /// @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 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { 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(), {}); - 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(), {}); @@ -2797,7 +2797,7 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { 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 4db434df17..9cad7dd5dc 100644 --- a/src/intrinsic_table_test.cc +++ b/src/intrinsic_table_test.cc @@ -79,7 +79,7 @@ TEST_F(IntrinsicTableTest, MatchI32) { auto* f32 = create(); auto* i32 = create(); auto* vec4_f32 = create(f32, 4); - auto tex = ty.sampled_texture(ast::TextureDimension::k1d, f32); + auto* tex = create(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, MatchI32) { TEST_F(IntrinsicTableTest, MismatchI32) { auto* f32 = create(); - auto tex = ty.sampled_texture(ast::TextureDimension::k1d, f32); + auto* tex = create(ast::TextureDimension::k1d, f32); auto result = table->Lookup(*this, IntrinsicType::kTextureLoad, {tex, f32}, Source{}); ASSERT_EQ(result.intrinsic, nullptr); @@ -241,7 +241,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) { auto* f32 = create(); auto* vec2_f32 = create(f32, 2); auto* vec4_f32 = create(f32, 4); - auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32); + auto* tex = create(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, MatchSampler) { TEST_F(IntrinsicTableTest, MismatchSampler) { auto* f32 = create(); auto* vec2_f32 = create(f32, 2); - auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32); + auto* tex = create(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 @@ TEST_F(IntrinsicTableTest, MatchSampledTexture) { auto* f32 = create(); auto* vec2_i32 = create(i32, 2); auto* vec4_f32 = create(f32, 4); - auto tex = ty.sampled_texture(ast::TextureDimension::k2d, f32); + auto* tex = create(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 @@ TEST_F(IntrinsicTableTest, MatchDepthTexture) { auto* f32 = create(); auto* i32 = create(); auto* vec2_i32 = create(i32, 2); - auto tex = ty.depth_texture(ast::TextureDimension::k2d); + auto* tex = create(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, OverloadOrderByNumberOfParameters) { } TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) { - auto tex = ty.depth_texture(ast::TextureDimension::k2d); + auto* tex = create(ast::TextureDimension::k2d); auto* bool_ = create(); auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions, {tex, bool_}, Source{}); diff --git a/src/program_builder.h b/src/program_builder.h index 1ddc1355e9..da8aa40505 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -766,8 +766,7 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @returns the depth texture typ::DepthTexture depth_texture(ast::TextureDimension dims) const { - return {builder->create(dims), - builder->create(dims)}; + return {builder->create(dims)}; } /// @param source the Source of the node @@ -775,8 +774,7 @@ class ProgramBuilder { /// @returns the depth texture typ::DepthTexture depth_texture(const Source& source, ast::TextureDimension dims) const { - return {builder->create(source, dims), - builder->create(dims)}; + return {builder->create(source, dims)}; } /// @param dims the dimensionality of the texture @@ -784,10 +782,7 @@ class ProgramBuilder { /// @returns the sampled texture typ::SampledTexture sampled_texture(ast::TextureDimension dims, typ::Type subtype) const { - return {subtype.ast ? builder->create(dims, subtype) - : nullptr, - subtype.sem ? builder->create(dims, subtype) - : nullptr}; + return {builder->create(dims, subtype)}; } /// @param source the Source of the node @@ -797,11 +792,7 @@ class ProgramBuilder { typ::SampledTexture sampled_texture(const Source& source, ast::TextureDimension dims, typ::Type subtype) const { - return {subtype.ast - ? builder->create(source, dims, subtype) - : nullptr, - subtype.sem ? builder->create(dims, subtype) - : nullptr}; + return {builder->create(source, dims, subtype)}; } /// @param dims the dimensionality of the texture @@ -809,11 +800,7 @@ class ProgramBuilder { /// @returns the multisampled texture typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims, typ::Type subtype) const { - return { - subtype.ast ? builder->create(dims, subtype) - : nullptr, - subtype.sem ? builder->create(dims, subtype) - : nullptr}; + return {builder->create(dims, subtype)}; } /// @param source the Source of the node @@ -823,12 +810,7 @@ class ProgramBuilder { typ::MultisampledTexture multisampled_texture(const Source& source, ast::TextureDimension dims, typ::Type subtype) const { - return { - subtype.ast - ? builder->create(source, dims, subtype) - : nullptr, - subtype.sem ? builder->create(dims, subtype) - : nullptr}; + return {builder->create(source, dims, subtype)}; } /// @param dims the dimensionality of the texture @@ -836,12 +818,8 @@ class ProgramBuilder { /// @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(dims, format, ast_subtype), - builder->create( - dims, format, ast::AccessControl::kInvalid, sem_subtype)}; + auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); + return {builder->create(dims, format, subtype)}; } /// @param source the Source of the node @@ -851,26 +829,20 @@ class ProgramBuilder { 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(source, dims, format, - ast_subtype), - builder->create( - dims, format, ast::AccessControl::kInvalid, sem_subtype)}; + auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); + return { + builder->create(source, dims, format, subtype)}; } /// @returns the external texture typ::ExternalTexture external_texture() const { - return {builder->create(), - builder->create()}; + return {builder->create()}; } /// @param source the Source of the node /// @returns the external texture typ::ExternalTexture external_texture(const Source& source) const { - return {builder->create(source), - builder->create()}; + return {builder->create(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 4a6762a585..61dfe0684a 100644 --- a/src/typepair.h +++ b/src/typepair.h @@ -237,18 +237,10 @@ bool operator!=(std::nullptr_t, const TypePair& rhs) { using Type = TypePair; -using Array = TypePair; -using DepthTexture = TypePair; -using ExternalTexture = TypePair; using Matrix = TypePair; -using MultisampledTexture = - TypePair; using Pointer = TypePair; using Sampler = TypePair; -using SampledTexture = TypePair; -using StorageTexture = TypePair; using Struct = TypePair; -using Texture = TypePair; using Vector = TypePair; using Bool = Ptr; @@ -256,6 +248,12 @@ using U32 = Ptr; using I32 = Ptr; using F32 = Ptr; using Void = Ptr; +using DepthTexture = Ptr; +using ExternalTexture = Ptr; +using MultisampledTexture = Ptr; +using SampledTexture = Ptr; +using StorageTexture = Ptr; +using Texture = Ptr; // Helpers diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 51cb38e4ff..255f695dbb 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -842,7 +842,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { 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 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { 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 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { 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 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { 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 @@ TEST_F(BuilderTest_Type, 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 @@ TEST_F(BuilderTest_Type, 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 @@ TEST_F(BuilderTest_Type, 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