diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index ebd2ce8d01..97c2f878a2 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1945,7 +1945,8 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( if (format == type::ImageFormat::kNone) { return nullptr; } - auto* subtype = type::StorageTexture::SubtypeFor(format, &builder_); + auto* subtype = + type::StorageTexture::SubtypeFor(format, builder_.Types()); ast_store_type = builder_.create( access, builder_.create(dim, format, subtype)); } diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 63f15c6218..5680c8960f 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -550,7 +550,8 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - auto* subtype = type::StorageTexture::SubtypeFor(format.value, &builder_); + auto* subtype = + type::StorageTexture::SubtypeFor(format.value, builder_.Types()); return builder_.create(storage.value, format.value, subtype); } diff --git a/src/type/storage_texture_type.cc b/src/type/storage_texture_type.cc index 6dd019a6d7..91be1ad780 100644 --- a/src/type/storage_texture_type.cc +++ b/src/type/storage_texture_type.cc @@ -162,7 +162,7 @@ StorageTexture* StorageTexture::Clone(CloneContext* ctx) const { } type::Type* StorageTexture::SubtypeFor(type::ImageFormat format, - ProgramBuilder* builder) { + type::Manager& type_mgr) { switch (format) { case type::ImageFormat::kR8Uint: case type::ImageFormat::kR16Uint: @@ -173,7 +173,7 @@ type::Type* StorageTexture::SubtypeFor(type::ImageFormat format, case type::ImageFormat::kRg32Uint: case type::ImageFormat::kRgba16Uint: case type::ImageFormat::kRgba32Uint: { - return builder->create(); + return type_mgr.Get(); } case type::ImageFormat::kR8Sint: @@ -185,7 +185,7 @@ type::Type* StorageTexture::SubtypeFor(type::ImageFormat format, case type::ImageFormat::kRg32Sint: case type::ImageFormat::kRgba16Sint: case type::ImageFormat::kRgba32Sint: { - return builder->create(); + return type_mgr.Get(); } case type::ImageFormat::kR8Unorm: @@ -205,7 +205,7 @@ type::Type* StorageTexture::SubtypeFor(type::ImageFormat format, case type::ImageFormat::kRg32Float: case type::ImageFormat::kRgba16Float: case type::ImageFormat::kRgba32Float: { - return builder->create(); + return type_mgr.Get(); } case type::ImageFormat::kNone: diff --git a/src/type/storage_texture_type.h b/src/type/storage_texture_type.h index 0c769e6e6c..cff03e26c3 100644 --- a/src/type/storage_texture_type.h +++ b/src/type/storage_texture_type.h @@ -22,6 +22,8 @@ namespace tint { namespace type { +class Manager; + /// The image format in the storage texture enum class ImageFormat { kNone = -1, @@ -91,9 +93,10 @@ class StorageTexture : public Castable { StorageTexture* Clone(CloneContext* ctx) const override; /// @param format the storage texture image format - /// @param builder the ProgramBuilder used to build the returned type + /// @param type_mgr the type::Manager used to build the returned type /// @returns the storage texture subtype for the given ImageFormat - static type::Type* SubtypeFor(ImageFormat format, ProgramBuilder* builder); + static type::Type* SubtypeFor(type::ImageFormat format, + type::Manager& type_mgr); private: ImageFormat const image_format_; diff --git a/src/type/storage_texture_type_test.cc b/src/type/storage_texture_type_test.cc index 3e2dbb08b0..95c498a04d 100644 --- a/src/type/storage_texture_type_test.cc +++ b/src/type/storage_texture_type_test.cc @@ -39,7 +39,8 @@ namespace { using StorageTextureTest = TestHelper; TEST_F(StorageTextureTest, Is) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* subtype = + StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); Type* ty = s; @@ -59,7 +60,8 @@ TEST_F(StorageTextureTest, Is) { } TEST_F(StorageTextureTest, IsTexture) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* subtype = + StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); Texture* ty = s; @@ -69,21 +71,24 @@ TEST_F(StorageTextureTest, IsTexture) { } TEST_F(StorageTextureTest, Dim) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* subtype = + StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); EXPECT_EQ(s->dim(), TextureDimension::k2dArray); } TEST_F(StorageTextureTest, Format) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* subtype = + StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); EXPECT_EQ(s->image_format(), ImageFormat::kRgba32Float); } TEST_F(StorageTextureTest, TypeName) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* subtype = + StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float"); @@ -91,7 +96,7 @@ TEST_F(StorageTextureTest, TypeName) { TEST_F(StorageTextureTest, F32) { auto* subtype = - type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, Types()); Type* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Float, subtype); TypeDeterminer td(this); @@ -104,7 +109,7 @@ TEST_F(StorageTextureTest, F32) { TEST_F(StorageTextureTest, U32) { auto* subtype = - type::StorageTexture::SubtypeFor(ImageFormat::kRg32Uint, this); + type::StorageTexture::SubtypeFor(ImageFormat::kRg32Uint, Types()); Type* s = create(TextureDimension::k2dArray, ImageFormat::kRg32Uint, subtype); TypeDeterminer td(this); @@ -117,7 +122,7 @@ TEST_F(StorageTextureTest, U32) { TEST_F(StorageTextureTest, I32) { auto* subtype = - type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, this); + type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, Types()); Type* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Sint, subtype); TypeDeterminer td(this); @@ -129,7 +134,7 @@ TEST_F(StorageTextureTest, I32) { } TEST_F(StorageTextureTest, MinBufferBindingSize) { - auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, this); + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, Types()); auto* s = create(TextureDimension::k2dArray, ImageFormat::kRgba32Sint, subtype); EXPECT_EQ(0u, s->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 90c93cbcd1..7a89bc6327 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1425,7 +1425,7 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) { auto* coords_type = GetCoordsType(dim, ty.i32()); - auto* subtype = type::StorageTexture::SubtypeFor(format, this); + auto* subtype = type::StorageTexture::SubtypeFor(format, Types()); type::Type* texture_type = create(dim, format, subtype); ast::ExpressionList call_params; diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 6ae94780db..6f29eed5b1 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -407,7 +407,7 @@ using HlslStoragetexturesTest = TestParamHelper; TEST_P(HlslStoragetexturesTest, Emit) { auto params = GetParam(); - auto* subtype = type::StorageTexture::SubtypeFor(params.imgfmt, this); + auto* subtype = type::StorageTexture::SubtypeFor(params.imgfmt, Types()); auto* s = create(params.dim, params.imgfmt, subtype); auto* ac = create(params.ro ? ast::AccessControl::kReadOnly diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index aff333effc..c223f0caa7 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -422,7 +422,7 @@ TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(params.dim, type::ImageFormat::kR16Float, subtype); auto* ac = diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 706799356a..4a9517b0ed 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -543,7 +543,7 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { // var a : [[access(read)]] texture_storage_2d; auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, Types()); auto* type = create( type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); @@ -568,7 +568,7 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : [[access(write)]] texture_storage_2d; auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, Types()); auto* type = create( type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); Global("test_var", ast::StorageClass::kNone, type); @@ -597,7 +597,7 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWithDifferentAccess) { // var b : [[access(write)]] texture_storage_2d; auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, Types()); auto* st = create(type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 33a0bea772..2ffa2175b5 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -875,7 +875,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(type::TextureDimension::k1d, type::ImageFormat::kR16Float, subtype); @@ -897,7 +897,7 @@ OpCapability StorageImageExtendedFormats TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Snorm, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Snorm, Types()); auto* s = create(type::TextureDimension::k1d, type::ImageFormat::kR8Snorm, subtype); @@ -919,7 +919,7 @@ OpCapability StorageImageExtendedFormats TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Unorm, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Unorm, Types()); auto* s = create(type::TextureDimension::k1d, type::ImageFormat::kR8Unorm, subtype); @@ -941,7 +941,7 @@ OpCapability StorageImageExtendedFormats TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Uint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Uint, Types()); auto* s = create(type::TextureDimension::k1d, type::ImageFormat::kR8Uint, subtype); @@ -958,7 +958,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) { TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Sint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Sint, Types()); auto* s = create(type::TextureDimension::k1d, type::ImageFormat::kR8Sint, subtype); @@ -975,7 +975,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) { TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_array) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(type::TextureDimension::k1dArray, type::ImageFormat::kR16Float, subtype); @@ -997,7 +997,7 @@ OpCapability StorageImageExtendedFormats TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(type::TextureDimension::k2d, type::ImageFormat::kR16Float, subtype); @@ -1014,7 +1014,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(type::TextureDimension::k2dArray, type::ImageFormat::kR16Float, subtype); @@ -1031,7 +1031,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()); auto* s = create(type::TextureDimension::k3d, type::ImageFormat::kR16Float, subtype); @@ -1049,7 +1049,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32float) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Float, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Float, Types()); auto* s = create(type::TextureDimension::k2d, type::ImageFormat::kR32Float, subtype); @@ -1067,7 +1067,7 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Sint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Sint, Types()); auto* s = create(type::TextureDimension::k2d, type::ImageFormat::kR32Sint, subtype); @@ -1085,7 +1085,7 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { auto* subtype = - type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, Types()); auto* s = create(type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 4308d7f27c..2c2744f978 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -386,7 +386,7 @@ using WgslGenerator_StorageTextureTest = TestParamHelper; TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); - auto* subtype = type::StorageTexture::SubtypeFor(param.fmt, this); + auto* subtype = type::StorageTexture::SubtypeFor(param.fmt, Types()); auto* t = create(param.dim, param.fmt, subtype); auto* ac = create(param.access, t);