diff --git a/src/ast/intrinsic_texture_helper_test.cc b/src/ast/intrinsic_texture_helper_test.cc index 2170ea43b6..27214ed675 100644 --- a/src/ast/intrinsic_texture_helper_test.cc +++ b/src/ast/intrinsic_texture_helper_test.cc @@ -177,9 +177,8 @@ ast::Variable* TextureOverloadCase::buildTextureVariable( nullptr, decos); case ast::intrinsic::test::TextureKind::kStorage: { - auto* st = - b->create(texture_dimension, image_format); - st->set_type(datatype); + auto* st = b->create(texture_dimension, + image_format, datatype); auto* ac = b->create(access_control, st); return b->Global("texture", ast::StorageClass::kUniformConstant, ac, diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 8676836e12..8a14e8e971 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1894,8 +1894,9 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( if (format == type::ImageFormat::kNone) { return nullptr; } + auto* subtype = type::StorageTexture::SubtypeFor(format, &builder_); ast_store_type = builder_.create( - access, builder_.create(dim, format)); + access, builder_.create(dim, format, subtype)); } } else { Fail() << "unsupported: UniformConstant variable is not a recognized " diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 669f054287..07fb14508e 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -543,7 +543,9 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - return builder_.create(storage.value, format.value); + auto* subtype = type::StorageTexture::SubtypeFor(format.value, &builder_); + return builder_.create(storage.value, format.value, + subtype); } return Failure::kNoMatch; diff --git a/src/type/storage_texture_type.cc b/src/type/storage_texture_type.cc index bdd76105fb..6dd019a6d7 100644 --- a/src/type/storage_texture_type.cc +++ b/src/type/storage_texture_type.cc @@ -141,16 +141,10 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) { return out; } -StorageTexture::StorageTexture(TextureDimension dim, ImageFormat format) - : Base(dim), image_format_(format) {} - -void StorageTexture::set_type(Type* const type) { - type_ = type; -} - -Type* StorageTexture::type() const { - return type_; -} +StorageTexture::StorageTexture(TextureDimension dim, + ImageFormat format, + type::Type* subtype) + : Base(dim), image_format_(format), subtype_(subtype) {} StorageTexture::StorageTexture(StorageTexture&&) = default; @@ -163,7 +157,62 @@ std::string StorageTexture::type_name() const { } StorageTexture* StorageTexture::Clone(CloneContext* ctx) const { - return ctx->dst->create(dim(), image_format_); + return ctx->dst->create(dim(), image_format_, + ctx->Clone(subtype_)); +} + +type::Type* StorageTexture::SubtypeFor(type::ImageFormat format, + ProgramBuilder* builder) { + switch (format) { + case type::ImageFormat::kR8Uint: + case type::ImageFormat::kR16Uint: + case type::ImageFormat::kRg8Uint: + case type::ImageFormat::kR32Uint: + case type::ImageFormat::kRg16Uint: + case type::ImageFormat::kRgba8Uint: + case type::ImageFormat::kRg32Uint: + case type::ImageFormat::kRgba16Uint: + case type::ImageFormat::kRgba32Uint: { + return builder->create(); + } + + case type::ImageFormat::kR8Sint: + case type::ImageFormat::kR16Sint: + case type::ImageFormat::kRg8Sint: + case type::ImageFormat::kR32Sint: + case type::ImageFormat::kRg16Sint: + case type::ImageFormat::kRgba8Sint: + case type::ImageFormat::kRg32Sint: + case type::ImageFormat::kRgba16Sint: + case type::ImageFormat::kRgba32Sint: { + return builder->create(); + } + + case type::ImageFormat::kR8Unorm: + case type::ImageFormat::kRg8Unorm: + case type::ImageFormat::kRgba8Unorm: + case type::ImageFormat::kRgba8UnormSrgb: + case type::ImageFormat::kBgra8Unorm: + case type::ImageFormat::kBgra8UnormSrgb: + case type::ImageFormat::kRgb10A2Unorm: + case type::ImageFormat::kR8Snorm: + case type::ImageFormat::kRg8Snorm: + case type::ImageFormat::kRgba8Snorm: + case type::ImageFormat::kR16Float: + case type::ImageFormat::kR32Float: + case type::ImageFormat::kRg16Float: + case type::ImageFormat::kRg11B10Float: + case type::ImageFormat::kRg32Float: + case type::ImageFormat::kRgba16Float: + case type::ImageFormat::kRgba32Float: { + return builder->create(); + } + + case type::ImageFormat::kNone: + break; + } + + return nullptr; } } // namespace type diff --git a/src/type/storage_texture_type.h b/src/type/storage_texture_type.h index 51b147e276..0c769e6e6c 100644 --- a/src/type/storage_texture_type.h +++ b/src/type/storage_texture_type.h @@ -69,17 +69,15 @@ class StorageTexture : public Castable { /// Constructor /// @param dim the dimensionality of the texture /// @param format the image format of the texture - StorageTexture(TextureDimension dim, ImageFormat format); + /// @param subtype the storage subtype. Use SubtypeFor() to calculate this. + StorageTexture(TextureDimension dim, ImageFormat format, type::Type* subtype); /// Move constructor StorageTexture(StorageTexture&&); ~StorageTexture() override; - /// @param type the subtype of the storage texture - void set_type(Type* const type); - - /// @returns the subtype of the storage texture set with set_type - Type* type() const; + /// @returns the storage subtype + Type* type() const { return subtype_; } /// @returns the image format ImageFormat image_format() const { return image_format_; } @@ -92,10 +90,14 @@ class StorageTexture : public Castable { /// @return the newly cloned type StorageTexture* Clone(CloneContext* ctx) const override; + /// @param format the storage texture image format + /// @param builder the ProgramBuilder used to build the returned type + /// @returns the storage texture subtype for the given ImageFormat + static type::Type* SubtypeFor(ImageFormat format, ProgramBuilder* builder); + private: ImageFormat const image_format_; - - Type* type_ = nullptr; // Semantic info + Type* const subtype_; }; } // namespace type diff --git a/src/type/storage_texture_type_test.cc b/src/type/storage_texture_type_test.cc index a6829ed299..3e2dbb08b0 100644 --- a/src/type/storage_texture_type_test.cc +++ b/src/type/storage_texture_type_test.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Tint Authors. +// Copyright 2020 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. @@ -39,8 +39,10 @@ namespace { using StorageTextureTest = TestHelper; TEST_F(StorageTextureTest, Is) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Float); - Type* ty = &s; + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Float, subtype); + Type* ty = s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -57,31 +59,41 @@ TEST_F(StorageTextureTest, Is) { } TEST_F(StorageTextureTest, IsTexture) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Float); - Texture* ty = &s; + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Float, subtype); + Texture* ty = s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); } TEST_F(StorageTextureTest, Dim) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Float); - EXPECT_EQ(s.dim(), TextureDimension::k2dArray); + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Float, subtype); + EXPECT_EQ(s->dim(), TextureDimension::k2dArray); } TEST_F(StorageTextureTest, Format) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Float); - EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float); + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Float, subtype); + EXPECT_EQ(s->image_format(), ImageFormat::kRgba32Float); } TEST_F(StorageTextureTest, TypeName) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Float); - EXPECT_EQ(s.type_name(), "__storage_texture_2d_array_rgba32float"); + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Float, subtype); + EXPECT_EQ(s->type_name(), "__storage_texture_2d_array_rgba32float"); } TEST_F(StorageTextureTest, F32) { + auto* subtype = + type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Float, this); Type* s = create(TextureDimension::k2dArray, - ImageFormat::kRgba32Float); + ImageFormat::kRgba32Float, subtype); TypeDeterminer td(this); ASSERT_TRUE(td.Determine()) << td.error(); @@ -91,8 +103,10 @@ TEST_F(StorageTextureTest, F32) { } TEST_F(StorageTextureTest, U32) { + auto* subtype = + type::StorageTexture::SubtypeFor(ImageFormat::kRg32Uint, this); Type* s = create(TextureDimension::k2dArray, - ImageFormat::kRg32Uint); + ImageFormat::kRg32Uint, subtype); TypeDeterminer td(this); ASSERT_TRUE(td.Determine()) << td.error(); @@ -102,8 +116,10 @@ TEST_F(StorageTextureTest, U32) { } TEST_F(StorageTextureTest, I32) { + auto* subtype = + type::StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, this); Type* s = create(TextureDimension::k2dArray, - ImageFormat::kRgba32Sint); + ImageFormat::kRgba32Sint, subtype); TypeDeterminer td(this); ASSERT_TRUE(td.Determine()) << td.error(); @@ -113,8 +129,10 @@ TEST_F(StorageTextureTest, I32) { } TEST_F(StorageTextureTest, MinBufferBindingSize) { - StorageTexture s(TextureDimension::k2dArray, ImageFormat::kRgba32Sint); - EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); + auto* subtype = StorageTexture::SubtypeFor(ImageFormat::kRgba32Sint, this); + auto* s = create(TextureDimension::k2dArray, + ImageFormat::kRgba32Sint, subtype); + EXPECT_EQ(0u, s->MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } } // namespace diff --git a/src/type_determiner.cc b/src/type_determiner.cc index e75bdc8f49..09cc6a6f06 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -116,23 +116,6 @@ bool TypeDeterminer::Determine() { } bool TypeDeterminer::DetermineInternal() { - std::vector storage_textures; - - for (auto& it : builder_->Types().types()) { - if (auto* storage = - it.second->UnwrapIfNeeded()->As()) { - storage_textures.emplace_back(storage); - } - } - - for (auto* storage : storage_textures) { - if (!DetermineStorageTextureSubtype(storage)) { - set_error(Source{}, "unable to determine storage texture subtype for: " + - storage->type_name()); - return false; - } - } - for (auto* var : builder_->AST().GlobalVariables()) { variable_stack_.set_global(var->symbol(), CreateVariableInfo(var)); @@ -1166,66 +1149,6 @@ TypeDeterminer::VariableInfo* TypeDeterminer::CreateVariableInfo( return info; } -bool TypeDeterminer::DetermineStorageTextureSubtype(type::StorageTexture* tex) { - if (tex->type() != nullptr) { - return true; - } - - switch (tex->image_format()) { - case type::ImageFormat::kR8Uint: - case type::ImageFormat::kR16Uint: - case type::ImageFormat::kRg8Uint: - case type::ImageFormat::kR32Uint: - case type::ImageFormat::kRg16Uint: - case type::ImageFormat::kRgba8Uint: - case type::ImageFormat::kRg32Uint: - case type::ImageFormat::kRgba16Uint: - case type::ImageFormat::kRgba32Uint: { - tex->set_type(builder_->create()); - return true; - } - - case type::ImageFormat::kR8Sint: - case type::ImageFormat::kR16Sint: - case type::ImageFormat::kRg8Sint: - case type::ImageFormat::kR32Sint: - case type::ImageFormat::kRg16Sint: - case type::ImageFormat::kRgba8Sint: - case type::ImageFormat::kRg32Sint: - case type::ImageFormat::kRgba16Sint: - case type::ImageFormat::kRgba32Sint: { - tex->set_type(builder_->create()); - return true; - } - - case type::ImageFormat::kR8Unorm: - case type::ImageFormat::kRg8Unorm: - case type::ImageFormat::kRgba8Unorm: - case type::ImageFormat::kRgba8UnormSrgb: - case type::ImageFormat::kBgra8Unorm: - case type::ImageFormat::kBgra8UnormSrgb: - case type::ImageFormat::kRgb10A2Unorm: - case type::ImageFormat::kR8Snorm: - case type::ImageFormat::kRg8Snorm: - case type::ImageFormat::kRgba8Snorm: - case type::ImageFormat::kR16Float: - case type::ImageFormat::kR32Float: - case type::ImageFormat::kRg16Float: - case type::ImageFormat::kRg11B10Float: - case type::ImageFormat::kRg32Float: - case type::ImageFormat::kRgba16Float: - case type::ImageFormat::kRgba32Float: { - tex->set_type(builder_->create()); - return true; - } - - case type::ImageFormat::kNone: - break; - } - - return false; -} - void TypeDeterminer::SetType(ast::Expression* expr, type::Type* type) const { return builder_->Sem().Add(expr, builder_->create(type)); diff --git a/src/type_determiner.h b/src/type_determiner.h index 1402dda36a..8fdf969e21 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -148,10 +148,6 @@ class TypeDeterminer { /// @param stmt the statement to check /// @returns false on error bool DetermineVariableStorageClass(ast::Statement* stmt); - /// Determines the result type based off a storage texture format - /// @param tex the storage texture - /// @returns false on error - bool DetermineStorageTextureSubtype(type::StorageTexture* tex); /// Creates the nodes and adds them to the semantic::Info mappings of the /// ProgramBuilder. diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 96def378b2..4878e01739 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1323,7 +1323,8 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) { auto* coords_type = get_coords_type(dim, ty.i32()); - type::Type* texture_type = create(dim, format); + auto* subtype = type::StorageTexture::SubtypeFor(format, this); + 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 59a2d75dec..6ae94780db 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -407,7 +407,8 @@ using HlslStoragetexturesTest = TestParamHelper; TEST_P(HlslStoragetexturesTest, Emit) { auto params = GetParam(); - auto* s = create(params.dim, params.imgfmt); + auto* subtype = type::StorageTexture::SubtypeFor(params.imgfmt, this); + auto* s = create(params.dim, params.imgfmt, subtype); auto* ac = create(params.ro ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly, diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index a4b9f7eb23..aff333effc 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -421,8 +421,10 @@ using MslStorageTexturesTest = TestParamHelper; TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); - auto* s = - create(params.dim, type::ImageFormat::kR16Float); + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); + auto* s = create(params.dim, + type::ImageFormat::kR16Float, subtype); auto* ac = create(params.ro ? ast::AccessControl::kReadOnly : ast::AccessControl::kWriteOnly, diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 51c19fbfb6..706799356a 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -542,8 +542,10 @@ OpName %5 "c" TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { // var a : [[access(read)]] texture_storage_2d; - auto* type = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Uint); + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + auto* type = create( + type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); auto* ac = create(ast::AccessControl::kReadOnly, type); @@ -565,8 +567,10 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageReadOnly) { TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : [[access(write)]] texture_storage_2d; - auto* type = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Uint); + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); + auto* type = create( + type::TextureDimension::k2d, type::ImageFormat::kR32Uint, subtype); Global("test_var", ast::StorageClass::kNone, type); auto* ac = create(ast::AccessControl::kWriteOnly, type); @@ -592,8 +596,10 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWithDifferentAccess) { // var a : [[access(read)]] texture_storage_2d; // var b : [[access(write)]] texture_storage_2d; + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); auto* st = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Uint); + type::ImageFormat::kR32Uint, subtype); Global("test_var", ast::StorageClass::kNone, st); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 87da972259..33a0bea772 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -874,8 +874,10 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); auto* s = create(type::TextureDimension::k1d, - type::ImageFormat::kR16Float); + type::ImageFormat::kR16Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -894,8 +896,10 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Snorm, this); auto* s = create(type::TextureDimension::k1d, - type::ImageFormat::kR8Snorm); + type::ImageFormat::kR8Snorm, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -914,8 +918,10 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Unorm, this); auto* s = create(type::TextureDimension::k1d, - type::ImageFormat::kR8Unorm); + type::ImageFormat::kR8Unorm, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -934,8 +940,10 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR8Uint, this); auto* s = create(type::TextureDimension::k1d, - type::ImageFormat::kR8Uint); + type::ImageFormat::kR8Uint, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -949,8 +957,10 @@ 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); auto* s = create(type::TextureDimension::k1d, - type::ImageFormat::kR8Sint); + type::ImageFormat::kR8Sint, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -964,8 +974,10 @@ 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); auto* s = create(type::TextureDimension::k1dArray, - type::ImageFormat::kR16Float); + type::ImageFormat::kR16Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -984,8 +996,10 @@ OpCapability StorageImageExtendedFormats } TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); auto* s = create(type::TextureDimension::k2d, - type::ImageFormat::kR16Float); + type::ImageFormat::kR16Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -999,8 +1013,10 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); auto* s = create(type::TextureDimension::k2dArray, - type::ImageFormat::kR16Float); + type::ImageFormat::kR16Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -1014,8 +1030,10 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, this); auto* s = create(type::TextureDimension::k3d, - type::ImageFormat::kR16Float); + type::ImageFormat::kR16Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -1030,8 +1048,10 @@ 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); auto* s = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Float); + type::ImageFormat::kR32Float, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -1046,8 +1066,10 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Sint, this); auto* s = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Sint); + type::ImageFormat::kR32Sint, subtype); Global("test_var", ast::StorageClass::kNone, s); @@ -1062,8 +1084,10 @@ TEST_F(BuilderTest_Type, TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { + auto* subtype = + type::StorageTexture::SubtypeFor(type::ImageFormat::kR32Uint, this); auto* s = create(type::TextureDimension::k2d, - type::ImageFormat::kR32Uint); + type::ImageFormat::kR32Uint, subtype); Global("test_var", ast::StorageClass::kNone, s); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 4751a8e729..4308d7f27c 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -386,7 +386,8 @@ using WgslGenerator_StorageTextureTest = TestParamHelper; TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); - auto* t = create(param.dim, param.fmt); + auto* subtype = type::StorageTexture::SubtypeFor(param.fmt, this); + auto* t = create(param.dim, param.fmt, subtype); auto* ac = create(param.access, t); GeneratorImpl& gen = Build();