From f9b831c39a1f436fe7b5a09a458b6704d2aa69ed Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 29 Aug 2022 21:13:00 +0000 Subject: [PATCH] Convert @binding to an expression This CL updates the binding attribute to store an expression instead of a single value. The parser always produces an IntLiteralExpression at the moment. Bug: tint:1633 Change-Id: I14b2a61b5bcdea66e9e24df7afbb55fb60be785e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100440 Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair Kokoro: Kokoro --- src/tint/ast/binding_attribute.cc | 8 +- src/tint/ast/binding_attribute.h | 9 +- src/tint/ast/binding_attribute_test.cc | 5 +- src/tint/ast/builtin_texture_helper_test.cc | 7 +- src/tint/ast/variable_test.cc | 4 +- src/tint/inspector/test_inspector_builder.cc | 13 +- src/tint/program_builder.h | 24 +- src/tint/reader/spirv/parser_impl.cc | 4 +- src/tint/reader/wgsl/parser_impl.cc | 4 +- .../parser_impl_variable_attribute_test.cc | 12 +- .../resolver/assignment_validation_test.cc | 22 +- src/tint/resolver/atomics_test.cc | 4 +- src/tint/resolver/atomics_validation_test.cc | 14 +- .../resolver/attribute_validation_test.cc | 33 +- src/tint/resolver/builtin_test.cc | 4 +- .../compound_assignment_validation_test.cc | 2 +- .../host_shareable_validation_test.cc | 12 +- .../increment_decrement_validation_test.cc | 2 +- src/tint/resolver/ptr_ref_test.cc | 8 +- src/tint/resolver/ptr_ref_validation_test.cc | 8 +- src/tint/resolver/resolver.cc | 26 +- src/tint/resolver/resolver_test.cc | 42 ++- src/tint/resolver/side_effects_test.cc | 19 +- src/tint/resolver/source_variable_test.cc | 6 +- .../storage_class_layout_validation_test.cc | 32 +- .../resolver/storage_class_validation_test.cc | 74 +++-- .../resolver/struct_storage_class_use_test.cc | 5 +- src/tint/resolver/type_validation_test.cc | 26 +- src/tint/resolver/validation_test.cc | 4 +- src/tint/resolver/variable_test.cc | 16 +- src/tint/resolver/variable_validation_test.cc | 6 +- .../transform/array_length_from_uniform.cc | 7 +- src/tint/transform/binding_remapper.cc | 4 +- src/tint/transform/combine_samplers.cc | 5 +- .../transform/decompose_strided_array_test.cc | 18 +- .../decompose_strided_matrix_test.cc | 16 +- src/tint/transform/first_index_offset.cc | 4 +- .../transform/multiplanar_external_texture.cc | 4 +- .../transform/num_workgroups_from_uniform.cc | 2 +- src/tint/transform/vertex_pulling.cc | 4 +- src/tint/writer/flatten_bindings_test.cc | 36 +- ...generate_external_texture_bindings_test.cc | 22 +- .../glsl/generator_impl_function_test.cc | 19 +- .../generator_impl_member_accessor_test.cc | 2 +- .../glsl/generator_impl_sanitizer_test.cc | 9 +- .../generator_impl_storage_buffer_test.cc | 2 +- .../writer/glsl/generator_impl_type_test.cc | 8 +- .../generator_impl_uniform_buffer_test.cc | 6 +- .../hlsl/generator_impl_function_test.cc | 19 +- .../generator_impl_member_accessor_test.cc | 2 +- .../hlsl/generator_impl_sanitizer_test.cc | 15 +- .../writer/hlsl/generator_impl_type_test.cc | 10 +- .../msl/generator_impl_function_test.cc | 13 +- .../msl/generator_impl_sanitizer_test.cc | 22 +- .../writer/msl/generator_impl_type_test.cc | 20 +- src/tint/writer/spirv/builder.cc | 21 +- src/tint/writer/spirv/builder_assign_test.cc | 16 +- .../spirv/builder_binary_expression_test.cc | 308 +++++++++--------- src/tint/writer/spirv/builder_builtin_test.cc | 28 +- .../writer/spirv/builder_function_test.cc | 2 +- .../spirv/builder_global_variable_test.cc | 22 +- src/tint/writer/spirv/builder_type_test.cc | 18 +- src/tint/writer/wgsl/generator_impl.cc | 6 +- .../wgsl/generator_impl_function_test.cc | 2 +- .../wgsl/generator_impl_global_decl_test.cc | 4 +- .../writer/wgsl/generator_impl_type_test.cc | 2 +- .../wgsl/generator_impl_variable_test.cc | 8 +- 67 files changed, 636 insertions(+), 525 deletions(-) diff --git a/src/tint/ast/binding_attribute.cc b/src/tint/ast/binding_attribute.cc index 8180f99fa1..405fe98658 100644 --- a/src/tint/ast/binding_attribute.cc +++ b/src/tint/ast/binding_attribute.cc @@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingAttribute); namespace tint::ast { -BindingAttribute::BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val) +BindingAttribute::BindingAttribute(ProgramID pid, + NodeID nid, + const Source& src, + const ast::Expression* val) : Base(pid, nid, src), value(val) {} BindingAttribute::~BindingAttribute() = default; @@ -34,7 +37,8 @@ std::string BindingAttribute::Name() const { const BindingAttribute* BindingAttribute::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - return ctx->dst->create(src, value); + auto* value_ = ctx->Clone(value); + return ctx->dst->create(src, value_); } } // namespace tint::ast diff --git a/src/tint/ast/binding_attribute.h b/src/tint/ast/binding_attribute.h index b5379b8bb4..39ca2b67f5 100644 --- a/src/tint/ast/binding_attribute.h +++ b/src/tint/ast/binding_attribute.h @@ -18,6 +18,7 @@ #include #include "src/tint/ast/attribute.h" +#include "src/tint/ast/expression.h" namespace tint::ast { @@ -28,8 +29,8 @@ class BindingAttribute final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param src the source of this node - /// @param value the binding value - BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value); + /// @param value the binding value expression + BindingAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* value); ~BindingAttribute() override; /// @returns the WGSL name for the attribute @@ -41,8 +42,8 @@ class BindingAttribute final : public Castable { /// @return the newly cloned node const BindingAttribute* Clone(CloneContext* ctx) const override; - /// the binding value - const uint32_t value; + /// the binding value expression + const ast::Expression* const value; }; } // namespace tint::ast diff --git a/src/tint/ast/binding_attribute_test.cc b/src/tint/ast/binding_attribute_test.cc index 800093360d..ec8538cdf9 100644 --- a/src/tint/ast/binding_attribute_test.cc +++ b/src/tint/ast/binding_attribute_test.cc @@ -17,11 +17,12 @@ namespace tint::ast { namespace { +using namespace tint::number_suffixes; // NOLINT using BindingAttributeTest = TestHelper; TEST_F(BindingAttributeTest, Creation) { - auto* d = create(2u); - EXPECT_EQ(2u, d->value); + auto* d = Binding(2_a); + EXPECT_TRUE(d->value->Is()); } } // namespace diff --git a/src/tint/ast/builtin_texture_helper_test.cc b/src/tint/ast/builtin_texture_helper_test.cc index 882c0bb0d4..6e34b6d498 100644 --- a/src/tint/ast/builtin_texture_helper_test.cc +++ b/src/tint/ast/builtin_texture_helper_test.cc @@ -143,7 +143,7 @@ const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(ProgramBuil const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const { utils::Vector attrs{ b->create(0u), - b->create(0u), + b->Binding(0_a), }; switch (texture_kind) { case ast::builtin::test::TextureKind::kRegular: @@ -175,10 +175,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b } const ast::Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const { - utils::Vector attrs = { - b->create(0u), - b->create(1u), - }; + utils::Vector attrs = {b->Group(0u), b->Binding(1_a)}; return b->GlobalVar("sampler", b->ty.sampler(sampler_kind), attrs); } diff --git a/src/tint/ast/variable_test.cc b/src/tint/ast/variable_test.cc index 14fb766f46..b0096637ce 100644 --- a/src/tint/ast/variable_test.cc +++ b/src/tint/ast/variable_test.cc @@ -106,7 +106,7 @@ TEST_F(VariableTest, WithAttributes) { } TEST_F(VariableTest, HasBindingPoint_BothProvided) { - auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2), Group(1)); + auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a), Group(1)); EXPECT_TRUE(var->HasBindingPoint()); } @@ -116,7 +116,7 @@ TEST_F(VariableTest, HasBindingPoint_NeitherProvided) { } TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) { - auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2)); + auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a)); EXPECT_FALSE(var->HasBindingPoint()); } diff --git a/src/tint/inspector/test_inspector_builder.cc b/src/tint/inspector/test_inspector_builder.cc index 3d67876f09..e57b85f337 100644 --- a/src/tint/inspector/test_inspector_builder.cc +++ b/src/tint/inspector/test_inspector_builder.cc @@ -126,7 +126,7 @@ void InspectorBuilder::AddUniformBuffer(const std::string& name, const ast::Type* type, uint32_t group, uint32_t binding) { - GlobalVar(name, type, ast::StorageClass::kUniform, Binding(binding), Group(group)); + GlobalVar(name, type, ast::StorageClass::kUniform, Binding(AInt(binding)), Group(group)); } void InspectorBuilder::AddWorkgroupStorage(const std::string& name, const ast::Type* type) { @@ -138,7 +138,8 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name, ast::Access access, uint32_t group, uint32_t binding) { - GlobalVar(name, type, ast::StorageClass::kStorage, access, Binding(binding), Group(group)); + GlobalVar(name, type, ast::StorageClass::kStorage, access, Binding(AInt(binding)), + Group(group)); } void InspectorBuilder::MakeStructVariableReferenceBodyFunction( @@ -170,20 +171,20 @@ void InspectorBuilder::MakeStructVariableReferenceBodyFunction( } void InspectorBuilder::AddSampler(const std::string& name, uint32_t group, uint32_t binding) { - GlobalVar(name, sampler_type(), Binding(binding), Group(group)); + GlobalVar(name, sampler_type(), Binding(AInt(binding)), Group(group)); } void InspectorBuilder::AddComparisonSampler(const std::string& name, uint32_t group, uint32_t binding) { - GlobalVar(name, comparison_sampler_type(), Binding(binding), Group(group)); + GlobalVar(name, comparison_sampler_type(), Binding(AInt(binding)), Group(group)); } void InspectorBuilder::AddResource(const std::string& name, const ast::Type* type, uint32_t group, uint32_t binding) { - GlobalVar(name, type, Binding(binding), Group(group)); + GlobalVar(name, type, Binding(AInt(binding)), Group(group)); } void InspectorBuilder::AddGlobalVariable(const std::string& name, const ast::Type* type) { @@ -285,7 +286,7 @@ void InspectorBuilder::AddStorageTexture(const std::string& name, const ast::Type* type, uint32_t group, uint32_t binding) { - GlobalVar(name, type, Binding(binding), Group(group)); + GlobalVar(name, type, Binding(AInt(binding)), Group(group)); } const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction( diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index c797aaba9e..bf9c9edae3 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -2294,11 +2294,29 @@ class ProgramBuilder { /// @returns the group attribute pointer const ast::GroupAttribute* Group(uint32_t value) { return create(value); } + /// Creates the ast::GroupAttribute + /// @param source the source + /// @param value group attribute index + /// @returns the group attribute pointer + const ast::GroupAttribute* Group(const Source& source, uint32_t value) { + return create(source, value); + } + /// Creates the ast::BindingAttribute - /// @param value the binding index + /// @param value the binding index expression /// @returns the binding deocration pointer - const ast::BindingAttribute* Binding(uint32_t value) { - return create(value); + template + const ast::BindingAttribute* Binding(EXPR&& value) { + return create(Expr(std::forward(value))); + } + + /// Creates the ast::BindingAttribute + /// @param source the source + /// @param value the binding index expression + /// @returns the binding deocration pointer + template + const ast::BindingAttribute* Binding(const Source& source, EXPR&& value) { + return create(source, Expr(std::forward(value))); } /// Creates an ast::Function and registers it with the ast::Module. diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index f9117a5e49..58f59dc0e3 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -1690,13 +1690,13 @@ bool ParserImpl::ConvertDecorationsForVariable(uint32_t id, return Fail() << "malformed DescriptorSet decoration on ID " << id << ": has no operand"; } - decorations->Push(create(Source{}, deco[1])); + decorations->Push(builder_.Group(Source{}, deco[1])); } if (deco[0] == SpvDecorationBinding) { if (deco.size() == 1) { return Fail() << "malformed Binding decoration on ID " << id << ": has no operand"; } - decorations->Push(create(Source{}, deco[1])); + decorations->Push(builder_.Binding(Source{}, AInt(deco[1]))); } } diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index bf95b4e73b..0c20c6dc6b 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -3456,7 +3456,9 @@ Maybe ParserImpl::attribute() { } match(Token::Type::kComma); - return create(t.source(), val.value); + return create( + t.source(), create( + val.value, ast::IntLiteralExpression::Suffix::kNone)); }); } diff --git a/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc b/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc index ef778917d5..d345ac840a 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_attribute_test.cc @@ -364,7 +364,11 @@ TEST_F(ParserImplTest, Attribute_Binding) { ASSERT_TRUE(var_attr->Is()); auto* binding = var_attr->As(); - EXPECT_EQ(binding->value, 4u); + ASSERT_TRUE(binding->value->Is()); + + auto* expr = binding->value->As(); + EXPECT_EQ(expr->value, 4); + EXPECT_EQ(expr->suffix, ast::IntLiteralExpression::Suffix::kNone); } TEST_F(ParserImplTest, Attribute_Binding_TrailingComma) { @@ -379,7 +383,11 @@ TEST_F(ParserImplTest, Attribute_Binding_TrailingComma) { ASSERT_TRUE(var_attr->Is()); auto* binding = var_attr->As(); - EXPECT_EQ(binding->value, 4u); + ASSERT_TRUE(binding->value->Is()); + + auto* expr = binding->value->As(); + EXPECT_EQ(expr->value, 4); + EXPECT_EQ(expr->suffix, ast::IntLiteralExpression::Suffix::kNone); } TEST_F(ParserImplTest, Attribute_Binding_MissingLeftParen) { diff --git a/src/tint/resolver/assignment_validation_test.cc b/src/tint/resolver/assignment_validation_test.cc index 8985e5d8f5..c4f1fe40b2 100644 --- a/src/tint/resolver/assignment_validation_test.cc +++ b/src/tint/resolver/assignment_validation_test.cc @@ -33,7 +33,7 @@ TEST_F(ResolverAssignmentValidationTest, ReadOnlyBuffer) { Member("m", ty.i32()), }); GlobalVar(Source{{12, 34}}, "a", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("a", "m"), 1_i)); @@ -234,8 +234,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Handle) { ast::Access::kWrite); }; - GlobalVar("a", make_type(), Binding(0), Group(0)); - GlobalVar("b", make_type(), Binding(1), Group(0)); + GlobalVar("a", make_type(), Binding(0_a), Group(0)); + GlobalVar("b", make_type(), Binding(1_a), Group(0)); WrapInFunction(Assign(Source{{56, 78}}, "a", "b")); @@ -252,7 +252,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Atomic) { Member("a", ty.atomic(ty.i32())), }); GlobalVar(Source{{12, 34}}, "v", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a"))); @@ -269,7 +269,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_RuntimeArray) { Member("a", ty.array(ty.f32())), }); GlobalVar(Source{{12, 34}}, "v", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); WrapInFunction(Assign(Source{{56, 78}}, MemberAccessor("v", "a"), MemberAccessor("v", "a"))); @@ -288,7 +288,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_NonConstructibleStruct_Fa auto* s = Structure("S", utils::Vector{ Member("arr", ty.array()), }); - GlobalVar("s", ty.Of(s), ast::StorageClass::kStorage, Group(0), Binding(0)); + GlobalVar("s", ty.Of(s), ast::StorageClass::kStorage, Group(0), Binding(0_a)); WrapInFunction(Assign(Phony(), Expr(Source{{12, 34}}, "s"))); @@ -310,7 +310,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_DynamicArray_Fail) { auto* s = Structure("S", utils::Vector{ Member("arr", ty.array()), }); - GlobalVar("s", ty.Of(s), ast::StorageClass::kStorage, Group(0), Binding(0)); + GlobalVar("s", ty.Of(s), ast::StorageClass::kStorage, Group(0), Binding(0_a)); WrapInFunction(Assign(Phony(), MemberAccessor(Source{{12, 34}}, "s", "arr"))); @@ -361,10 +361,10 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_Pass) { Member("i", ty.i32()), }); GlobalVar("tex", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0), - Binding(0)); - GlobalVar("smp", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(1)); - GlobalVar("u", ty.Of(U), ast::StorageClass::kUniform, Group(0), Binding(2)); - GlobalVar("s", ty.Of(S), ast::StorageClass::kStorage, Group(0), Binding(3)); + Binding(0_a)); + GlobalVar("smp", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(1_a)); + GlobalVar("u", ty.Of(U), ast::StorageClass::kUniform, Group(0), Binding(2_a)); + GlobalVar("s", ty.Of(S), ast::StorageClass::kStorage, Group(0), Binding(3_a)); GlobalVar("wg", ty.array(), ast::StorageClass::kWorkgroup); WrapInFunction(Assign(Phony(), 1_i), // diff --git a/src/tint/resolver/atomics_test.cc b/src/tint/resolver/atomics_test.cc index 405bc27ad8..19cc8d538f 100644 --- a/src/tint/resolver/atomics_test.cc +++ b/src/tint/resolver/atomics_test.cc @@ -22,6 +22,8 @@ namespace tint::resolver { namespace { +using namespace tint::number_suffixes; // NOLINT + struct ResolverAtomicTest : public resolver::TestHelper, public testing::Test {}; TEST_F(ResolverAtomicTest, GlobalWorkgroupI32) { @@ -47,7 +49,7 @@ TEST_F(ResolverAtomicTest, GlobalWorkgroupU32) { TEST_F(ResolverAtomicTest, GlobalStorageStruct) { auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))}); auto* g = GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); EXPECT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(TypeOf(g)->Is()); diff --git a/src/tint/resolver/atomics_validation_test.cc b/src/tint/resolver/atomics_validation_test.cc index eb4f43e1a6..b3da7b52e8 100644 --- a/src/tint/resolver/atomics_validation_test.cc +++ b/src/tint/resolver/atomics_validation_test.cc @@ -34,7 +34,7 @@ TEST_F(ResolverAtomicValidationTest, StorageClass_WorkGroup) { TEST_F(ResolverAtomicValidationTest, StorageClass_Storage) { GlobalVar("g", ty.atomic(Source{{12, 34}}, ty.i32()), ast::StorageClass::kStorage, - ast::Access::kReadWrite, Group(0), Binding(0)); + ast::Access::kReadWrite, Group(0), Binding(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); } @@ -42,7 +42,7 @@ TEST_F(ResolverAtomicValidationTest, StorageClass_Storage) { TEST_F(ResolverAtomicValidationTest, StorageClass_Storage_Struct) { auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))}); GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Group(0), - Binding(0)); + Binding(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); } @@ -210,7 +210,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidStorageClass_Complex) { TEST_F(ResolverAtomicValidationTest, Struct_AccessMode_Read) { auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -222,7 +222,7 @@ TEST_F(ResolverAtomicValidationTest, Struct_AccessMode_Read) { TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Struct) { auto* s = Structure("s", utils::Vector{Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -240,7 +240,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_StructOfStruct) { Structure("Inner", utils::Vector{Member("m", ty.atomic(Source{{12, 34}}, ty.i32()))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -258,7 +258,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_StructOfStructOfArray) { Structure("Inner", utils::Vector{Member(Source{{12, 34}}, "m", ty.atomic(ty.i32()))}); auto* Outer = Structure("Outer", utils::Vector{Member("m", ty.Of(Inner))}); GlobalVar(Source{{56, 78}}, "g", ty.Of(Outer), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -300,7 +300,7 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Complex) { auto* s1 = Structure("S1", utils::Vector{Member("x", ty.Of(s2))}); auto* s0 = Structure("S0", utils::Vector{Member("x", ty.Of(s1))}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s0), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), diff --git a/src/tint/resolver/attribute_validation_test.cc b/src/tint/resolver/attribute_validation_test.cc index 70d46123a7..f3c2329aa3 100644 --- a/src/tint/resolver/attribute_validation_test.cc +++ b/src/tint/resolver/attribute_validation_test.cc @@ -91,11 +91,11 @@ static utils::Vector createAttributes(const Source& so case AttributeKind::kAlign: return {builder.MemberAlign(source, 4_u)}; case AttributeKind::kBinding: - return {builder.create(source, 1u)}; + return {builder.Binding(source, 1_a)}; case AttributeKind::kBuiltin: return {builder.Builtin(source, ast::BuiltinValue::kPosition)}; case AttributeKind::kGroup: - return {builder.create(source, 1u)}; + return {builder.Group(source, 1u)}; case AttributeKind::kId: return {builder.create(source, 0u)}; case AttributeKind::kInterpolate: @@ -116,8 +116,7 @@ static utils::Vector createAttributes(const Source& so case AttributeKind::kWorkgroup: return {builder.create(source, builder.Expr(1_i))}; case AttributeKind::kBindingAndGroup: - return {builder.create(source, 1_u), - builder.create(source, 1_u)}; + return {builder.Binding(source, 1_a), builder.Group(source, 1u)}; } return {}; } @@ -509,8 +508,8 @@ TEST_F(EntryPointParameterAttributeTest, DuplicateAttribute) { TEST_F(EntryPointParameterAttributeTest, DuplicateInternalAttribute) { auto* s = Param("s", ty.sampler(ast::SamplerKind::kSampler), utils::Vector{ - create(0u), - create(0u), + Binding(0_a), + Group(0u), Disable(ast::DisabledValidation::kBindingPointCollision), Disable(ast::DisabledValidation::kEntryPointParameter), }); @@ -734,9 +733,8 @@ INSTANTIATE_TEST_SUITE_P(ResolverAttributeValidationTest, TestParams{AttributeKind::kBindingAndGroup, true})); TEST_F(VariableAttributeTest, DuplicateAttribute) { - GlobalVar("a", ty.sampler(ast::SamplerKind::kSampler), - create(Source{{12, 34}}, 2u), create(2u), - create(Source{{56, 78}}, 3u)); + GlobalVar("a", ty.sampler(ast::SamplerKind::kSampler), Binding(Source{{12, 34}}, 2_a), + Group(2u), Binding(Source{{56, 78}}, 3_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -745,10 +743,7 @@ TEST_F(VariableAttributeTest, DuplicateAttribute) { } TEST_F(VariableAttributeTest, LocalVariable) { - auto* v = Var("a", ty.f32(), - utils::Vector{ - create(Source{{12, 34}}, 2u), - }); + auto* v = Var("a", ty.f32(), utils::Vector{Binding(Source{{12, 34}}, 2_a)}); WrapInFunction(v); @@ -1023,7 +1018,7 @@ TEST_F(ResourceAttributeTest, BindingPairMissingBinding) { } TEST_F(ResourceAttributeTest, BindingPairMissingGroup) { - GlobalVar(Source{{12, 34}}, "G", ty.sampler(ast::SamplerKind::kSampler), Binding(1)); + GlobalVar(Source{{12, 34}}, "G", ty.sampler(ast::SamplerKind::kSampler), Binding(1_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -1032,9 +1027,9 @@ TEST_F(ResourceAttributeTest, BindingPairMissingGroup) { TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByEntryPoint) { GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), - Binding(1), Group(2)); + Binding(1_a), Group(2)); GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), - Binding(1), Group(2)); + Binding(1_a), Group(2)); Func("F", utils::Empty, ty.void_(), utils::Vector{ @@ -1054,9 +1049,9 @@ TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByEntryPoint) { TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByDifferentEntryPoints) { GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), - Binding(1), Group(2)); + Binding(1_a), Group(2)); GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), - Binding(1), Group(2)); + Binding(1_a), Group(2)); Func("F_A", utils::Empty, ty.void_(), utils::Vector{ @@ -1077,7 +1072,7 @@ TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByDifferentEntryPoints) { } TEST_F(ResourceAttributeTest, BindingPointOnNonResource) { - GlobalVar(Source{{12, 34}}, "G", ty.f32(), ast::StorageClass::kPrivate, Binding(1), Group(2)); + GlobalVar(Source{{12, 34}}, "G", ty.f32(), ast::StorageClass::kPrivate, Binding(1_a), Group(2)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), diff --git a/src/tint/resolver/builtin_test.cc b/src/tint/resolver/builtin_test.cc index e98d9b5260..f08a875c0b 100644 --- a/src/tint/resolver/builtin_test.cc +++ b/src/tint/resolver/builtin_test.cc @@ -212,7 +212,7 @@ using ResolverBuiltinArrayTest = ResolverTest; TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) { auto* ary = ty.array(); auto* str = Structure("S", utils::Vector{Member("x", ary)}); - GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(0)); auto* call = Call("arrayLength", AddressOf(MemberAccessor("a", "x"))); @@ -2143,7 +2143,7 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParamIsAnyOf()) { - GlobalVar(name, type, Binding(0), Group(0)); + GlobalVar(name, type, Binding(0_a), Group(0)); } else { GlobalVar(name, type, ast::StorageClass::kPrivate); diff --git a/src/tint/resolver/compound_assignment_validation_test.cc b/src/tint/resolver/compound_assignment_validation_test.cc index 9bd5c3a0d3..962bf51e03 100644 --- a/src/tint/resolver/compound_assignment_validation_test.cc +++ b/src/tint/resolver/compound_assignment_validation_test.cc @@ -234,7 +234,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest, ReadOnlyBuffer) { // a += 1i; // } GlobalVar(Source{{12, 34}}, "a", ty.i32(), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); WrapInFunction(CompoundAssign(Source{{56, 78}}, "a", 1_i, ast::BinaryOp::kAdd)); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/resolver/host_shareable_validation_test.cc b/src/tint/resolver/host_shareable_validation_test.cc index b9831cc23b..7893f82a1a 100644 --- a/src/tint/resolver/host_shareable_validation_test.cc +++ b/src/tint/resolver/host_shareable_validation_test.cc @@ -21,13 +21,15 @@ namespace tint::resolver { namespace { +using namespace tint::number_suffixes; // NOLINT + using ResolverHostShareableValidationTest = ResolverTest; TEST_F(ResolverHostShareableValidationTest, BoolMember) { auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.bool_())}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -42,7 +44,7 @@ TEST_F(ResolverHostShareableValidationTest, BoolVectorMember) { auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.vec3())}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -58,7 +60,7 @@ TEST_F(ResolverHostShareableValidationTest, Aliases) { auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.Of(a1))}); auto* a2 = Alias("a2", ty.Of(s)); GlobalVar(Source{{56, 78}}, "g", ty.Of(a2), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -77,7 +79,7 @@ TEST_F(ResolverHostShareableValidationTest, NestedStructures) { auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))}); GlobalVar(Source{{9, 10}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -116,7 +118,7 @@ TEST_F(ResolverHostShareableValidationTest, NoError) { auto* s = Structure("S", utils::Vector{Member(Source{{7, 8}}, "m", ty.Of(i3))}); GlobalVar(Source{{9, 10}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } diff --git a/src/tint/resolver/increment_decrement_validation_test.cc b/src/tint/resolver/increment_decrement_validation_test.cc index 87d7bafbbc..d1afaaf09e 100644 --- a/src/tint/resolver/increment_decrement_validation_test.cc +++ b/src/tint/resolver/increment_decrement_validation_test.cc @@ -194,7 +194,7 @@ TEST_F(ResolverIncrementDecrementValidationTest, ReadOnlyBuffer) { // a++; // } GlobalVar(Source{{12, 34}}, "a", ty.i32(), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); WrapInFunction(Increment(Source{{56, 78}}, "a")); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/resolver/ptr_ref_test.cc b/src/tint/resolver/ptr_ref_test.cc index ba5be6217b..892feb8fc0 100644 --- a/src/tint/resolver/ptr_ref_test.cc +++ b/src/tint/resolver/ptr_ref_test.cc @@ -21,6 +21,8 @@ namespace tint::resolver { namespace { +using namespace tint::number_suffixes; // NOLINT + struct ResolverPtrRefTest : public resolver::TestHelper, public testing::Test {}; TEST_F(ResolverPtrRefTest, AddressOf) { @@ -61,8 +63,10 @@ TEST_F(ResolverPtrRefTest, DefaultPtrStorageClass) { auto* function = Var("f", ty.i32()); auto* private_ = GlobalVar("p", ty.i32(), ast::StorageClass::kPrivate); auto* workgroup = GlobalVar("w", ty.i32(), ast::StorageClass::kWorkgroup); - auto* uniform = GlobalVar("ub", ty.Of(buf), ast::StorageClass::kUniform, Binding(0), Group(0)); - auto* storage = GlobalVar("sb", ty.Of(buf), ast::StorageClass::kStorage, Binding(1), Group(0)); + auto* uniform = + GlobalVar("ub", ty.Of(buf), ast::StorageClass::kUniform, Binding(0_a), Group(0)); + auto* storage = + GlobalVar("sb", ty.Of(buf), ast::StorageClass::kStorage, Binding(1_a), Group(0)); auto* function_ptr = Let("f_ptr", ty.pointer(ty.i32(), ast::StorageClass::kFunction), AddressOf(function)); diff --git a/src/tint/resolver/ptr_ref_validation_test.cc b/src/tint/resolver/ptr_ref_validation_test.cc index 0f6f6e57bd..5b149aad10 100644 --- a/src/tint/resolver/ptr_ref_validation_test.cc +++ b/src/tint/resolver/ptr_ref_validation_test.cc @@ -54,7 +54,8 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfLet) { TEST_F(ResolverPtrRefValidationTest, AddressOfHandle) { // @group(0) @binding(0) var t: texture_3d; // &t - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0), Binding(0)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0), + Binding(0_a)); auto* expr = AddressOf(Expr(Source{{12, 34}}, "t")); WrapInFunction(expr); @@ -93,7 +94,8 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfVectorComponent_IndexAccessor) { TEST_F(ResolverPtrRefValidationTest, IndirectOfAddressOfHandle) { // @group(0) @binding(0) var t: texture_3d; // *&t - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0), Binding(0)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0), + Binding(0_a)); auto* expr = Deref(AddressOf(Expr(Source{{12, 34}}, "t"))); WrapInFunction(expr); @@ -142,7 +144,7 @@ TEST_F(ResolverPtrRefValidationTest, InferredPtrAccessMismatch) { auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array())}); auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))}); auto* storage = GlobalVar("s", ty.Of(buf), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i); auto* ptr = diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 90ec2549da..c469c3c5dd 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -582,8 +582,17 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) { uint32_t binding = 0; { auto* attr = ast::GetAttribute(var->attributes); - // TODO(dsinclair): Materialize when binding attribute is an expression - binding = attr->value; + auto* materialize = Materialize(Expression(attr->value)); + if (!materialize) { + return nullptr; + } + auto* c = materialize->ConstantValue(); + if (!c) { + // TODO(crbug.com/tint/1633): Add error message about invalid materialization + // when binding can be an expression. + return nullptr; + } + binding = c->As(); } uint32_t group = 0; @@ -646,8 +655,17 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index) if (param->HasBindingPoint()) { { auto* attr = ast::GetAttribute(param->attributes); - // TODO(dsinclair): Materialize the binding information - binding_point.binding = attr->value; + auto* materialize = Materialize(Expression(attr->value)); + if (!materialize) { + return nullptr; + } + auto* c = materialize->ConstantValue(); + if (!c) { + // TODO(crbug.com/tint/1633): Add error message about invalid materialization when + // binding can be an expression. + return nullptr; + } + binding_point.binding = c->As(); } { auto* attr = ast::GetAttribute(param->attributes); diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index d4f0ef96cb..80d727ca75 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -777,7 +777,7 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables) { auto* s = Structure("S", utils::Vector{Member("m", ty.u32())}); auto* sb_var = GlobalVar("sb_var", ty.Of(s), ast::StorageClass::kStorage, - ast::Access::kReadWrite, Binding(0), Group(0)); + ast::Access::kReadWrite, Binding(0_a), Group(0)); auto* wg_var = GlobalVar("wg_var", ty.f32(), ast::StorageClass::kWorkgroup); auto* priv_var = GlobalVar("priv_var", ty.f32(), ast::StorageClass::kPrivate); @@ -806,7 +806,7 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) { auto* s = Structure("S", utils::Vector{Member("m", ty.u32())}); auto* sb_var = GlobalVar("sb_var", ty.Of(s), ast::StorageClass::kStorage, - ast::Access::kReadWrite, Binding(0), Group(0)); + ast::Access::kReadWrite, Binding(0_a), Group(0)); auto* wg_var = GlobalVar("wg_var", ty.f32(), ast::StorageClass::kWorkgroup); auto* priv_var = GlobalVar("priv_var", ty.f32(), ast::StorageClass::kPrivate); @@ -1727,7 +1727,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) { TEST_F(ResolverTest, StorageClass_SetForSampler) { auto* t = ty.sampler(ast::SamplerKind::kSampler); - auto* var = GlobalVar("var", t, Binding(0), Group(0)); + auto* var = GlobalVar("var", t, Binding(0_a), Group(0)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1736,7 +1736,7 @@ TEST_F(ResolverTest, StorageClass_SetForSampler) { TEST_F(ResolverTest, StorageClass_SetForTexture) { auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); - auto* var = GlobalVar("var", t, Binding(0), Group(0)); + auto* var = GlobalVar("var", t, Binding(0_a), Group(0)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1757,8 +1757,8 @@ TEST_F(ResolverTest, Access_SetForStorageBuffer) { // struct S { x : i32 }; // var g : S; auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())}); - auto* var = GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, Binding(0), - Group(0)); + auto* var = GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, + Binding(0_a), Group(0)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1768,8 +1768,8 @@ TEST_F(ResolverTest, Access_SetForStorageBuffer) { TEST_F(ResolverTest, BindingPoint_SetForResources) { // @group(1) @binding(2) var s1 : sampler; // @group(3) @binding(4) var s2 : sampler; - auto* s1 = GlobalVar(Sym(), ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2)); - auto* s2 = GlobalVar(Sym(), ty.sampler(ast::SamplerKind::kSampler), Group(3), Binding(4)); + auto* s1 = GlobalVar(Sym(), ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2_a)); + auto* s2 = GlobalVar(Sym(), ty.sampler(ast::SamplerKind::kSampler), Group(3), Binding(4_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1972,8 +1972,9 @@ TEST_F(ResolverTest, UnaryOp_Negation) { } TEST_F(ResolverTest, TextureSampler_TextureSample) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(1)); - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(1_a)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2_a)); auto* call = CallStmt(Call("textureSample", "t", "s", vec2(1_f, 2_f))); const ast::Function* f = Func("test_function", utils::Empty, ty.void_(), utils::Vector{call}, @@ -1989,8 +1990,9 @@ TEST_F(ResolverTest, TextureSampler_TextureSample) { } TEST_F(ResolverTest, TextureSampler_TextureSampleInFunction) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(1)); - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(1_a)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2_a)); auto* inner_call = CallStmt(Call("textureSample", "t", "s", vec2(1_f, 2_f))); const ast::Function* inner_func = @@ -2014,8 +2016,9 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleInFunction) { } TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondSameVariables) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(1)); - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(1_a)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2_a)); auto* inner_call_1 = CallStmt(Call("textureSample", "t", "s", vec2(1_f, 2_f))); const ast::Function* inner_func_1 = @@ -2048,9 +2051,11 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondSameVariables) { } TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondDifferentVariables) { - GlobalVar("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(1)); - GlobalVar("t2", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(2)); - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(3)); + GlobalVar("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(1_a)); + GlobalVar("t2", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(2_a)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(3_a)); auto* inner_call_1 = CallStmt(Call("textureSample", "t1", "s", vec2(1_f, 2_f))); const ast::Function* inner_func_1 = @@ -2085,7 +2090,8 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondDifferentVariabl } TEST_F(ResolverTest, TextureSampler_TextureDimensions) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), Binding(2)); + GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1), + Binding(2_a)); auto* call = Call("textureDimensions", "t"); const ast::Function* f = WrapInFunction(call); diff --git a/src/tint/resolver/side_effects_test.cc b/src/tint/resolver/side_effects_test.cc index 9a7bd9f163..7b720f3204 100644 --- a/src/tint/resolver/side_effects_test.cc +++ b/src/tint/resolver/side_effects_test.cc @@ -175,25 +175,26 @@ TEST_P(SideEffectsBuiltinTest, Test) { GlobalVar("m", ty.mat3x3(), ast::StorageClass::kPrivate); GlobalVar("arr", ty.array(), ast::StorageClass::kPrivate); GlobalVar("storage_arr", ty.array(), ast::StorageClass::kStorage, Group(0), - Binding(next_binding++)); + Binding(AInt(next_binding++))); GlobalVar("a", ty.atomic(ty.i32()), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Group(0), Binding(next_binding++)); + Group(0), Binding(AInt(next_binding++))); if (c.pipeline_stage != ast::PipelineStage::kCompute) { GlobalVar("t2d", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0), - Binding(next_binding++)); + Binding(AInt(next_binding++))); GlobalVar("tdepth2d", ty.depth_texture(ast::TextureDimension::k2d), Group(0), - Binding(next_binding++)); + Binding(AInt(next_binding++))); GlobalVar("t2d_arr", ty.sampled_texture(ast::TextureDimension::k2dArray, ty.f32()), - Group(0), Binding(next_binding++)); + Group(0), Binding(AInt(next_binding++))); GlobalVar("t2d_multi", ty.multisampled_texture(ast::TextureDimension::k2d, ty.f32()), - Group(0), Binding(next_binding++)); + Group(0), Binding(AInt(next_binding++))); GlobalVar("tstorage2d", ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite), - Group(0), Binding(next_binding++)); - GlobalVar("s2d", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(next_binding++)); + Group(0), Binding(AInt(next_binding++))); + GlobalVar("s2d", ty.sampler(ast::SamplerKind::kSampler), Group(0), + Binding(AInt(next_binding++))); GlobalVar("scomp", ty.sampler(ast::SamplerKind::kComparisonSampler), Group(0), - Binding(next_binding++)); + Binding(AInt(next_binding++))); } utils::Vector stmts; diff --git a/src/tint/resolver/source_variable_test.cc b/src/tint/resolver/source_variable_test.cc index ada4fc2b9c..304a554fbf 100644 --- a/src/tint/resolver/source_variable_test.cc +++ b/src/tint/resolver/source_variable_test.cc @@ -48,7 +48,7 @@ TEST_F(ResolverSourceVariableTest, GlobalWorkgroupVar) { } TEST_F(ResolverSourceVariableTest, GlobalStorageVar) { - auto* a = GlobalVar("a", ty.f32(), ast::StorageClass::kStorage, Group(0), Binding(0)); + auto* a = GlobalVar("a", ty.f32(), ast::StorageClass::kStorage, Group(0), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(expr); @@ -59,7 +59,7 @@ TEST_F(ResolverSourceVariableTest, GlobalStorageVar) { } TEST_F(ResolverSourceVariableTest, GlobalUniformVar) { - auto* a = GlobalVar("a", ty.f32(), ast::StorageClass::kUniform, Group(0), Binding(0)); + auto* a = GlobalVar("a", ty.f32(), ast::StorageClass::kUniform, Group(0), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(expr); @@ -71,7 +71,7 @@ TEST_F(ResolverSourceVariableTest, GlobalUniformVar) { TEST_F(ResolverSourceVariableTest, GlobalTextureVar) { auto* a = GlobalVar("a", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), - ast::StorageClass::kNone, Group(0), Binding(0)); + ast::StorageClass::kNone, Group(0), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(Call("textureDimensions", expr)); diff --git a/src/tint/resolver/storage_class_layout_validation_test.cc b/src/tint/resolver/storage_class_layout_validation_test.cc index 51b8eccbc1..c4f73d6b86 100644 --- a/src/tint/resolver/storage_class_layout_validation_test.cc +++ b/src/tint/resolver/storage_class_layout_validation_test.cc @@ -40,7 +40,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, StorageBuffer_UnalignedMember) }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("S"), ast::StorageClass::kStorage, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -70,7 +70,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, StorageBuffer_UnalignedMember_S }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("S"), ast::StorageClass::kStorage, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -101,7 +101,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_UnalignedMember_S }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -146,7 +146,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -171,7 +171,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_UnalignedMember_A }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -205,7 +205,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_UnalignedMember_A }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -237,7 +237,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_MembersOffsetNotM }); GlobalVar(Source{{22, 24}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -289,7 +289,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, }); GlobalVar(Source{{22, 24}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -337,7 +337,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, }); GlobalVar(Source{{22, 34}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -358,7 +358,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_Vec3MemberOffset_ }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("ScalarPackedAtEndOfVec3"), - ast::StorageClass::kUniform, Group(0), Binding(0)); + ast::StorageClass::kUniform, Group(0), Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -384,7 +384,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -418,7 +418,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -461,7 +461,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -479,7 +479,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid // @group(0) @binding(0) // var a : array; GlobalVar(Source{{78, 90}}, "a", ty.array(Source{{34, 56}}, ty.f32(), 4_u), - ast::StorageClass::kUniform, Group(0), Binding(0)); + ast::StorageClass::kUniform, Group(0), Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -501,7 +501,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_FALSE(r()->Resolve()); EXPECT_EQ( @@ -534,7 +534,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_InvalidArrayStrid }); GlobalVar(Source{{78, 90}}, "a", ty.type_name("Outer"), ast::StorageClass::kUniform, Group(0), - Binding(0)); + Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } diff --git a/src/tint/resolver/storage_class_validation_test.cc b/src/tint/resolver/storage_class_validation_test.cc index ab9c0493c7..d93e77d53b 100644 --- a/src/tint/resolver/storage_class_validation_test.cc +++ b/src/tint/resolver/storage_class_validation_test.cc @@ -87,7 +87,8 @@ note: while analysing structure member S.m TEST_F(ResolverStorageClassValidationTest, StorageBufferBool) { // var g : bool; - GlobalVar(Source{{56, 78}}, "g", ty.bool_(), ast::StorageClass::kStorage, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.bool_(), ast::StorageClass::kStorage, Binding(0_a), + Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -101,7 +102,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferBoolAlias) { // type a = bool; // var g : a; auto* a = Alias("a", ty.bool_()); - GlobalVar(Source{{56, 78}}, "g", ty.Of(a), ast::StorageClass::kStorage, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.Of(a), ast::StorageClass::kStorage, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -117,7 +118,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferF16_TemporallyBan) { // var g : f16; Enable(ast::Extension::kF16); - GlobalVar("g", ty.f16(Source{{56, 78}}), ast::StorageClass::kStorage, Binding(0), Group(0)); + GlobalVar("g", ty.f16(Source{{56, 78}}), ast::StorageClass::kStorage, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -132,8 +133,8 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferF16Alias_TemporallyBan) Enable(ast::Extension::kF16); auto* a = Alias("a", ty.f16()); - GlobalVar("g", ty.type_name(Source{{56, 78}}, a->name), ast::StorageClass::kStorage, Binding(0), - Group(0)); + GlobalVar("g", ty.type_name(Source{{56, 78}}, a->name), ast::StorageClass::kStorage, + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -146,7 +147,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferVectorF16_TemporallyBan) // var g : vec4; Enable(ast::Extension::kF16); GlobalVar("g", ty.vec(Source{{56, 78}}, ty.Of(), 4u), ast::StorageClass::kStorage, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -162,7 +163,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferArrayF16_TemporallyBan) auto* s = Structure("S", utils::Vector{Member("a", ty.f16(Source{{56, 78}}))}); auto* a = ty.array(ty.Of(s), 3_u); - GlobalVar("g", a, ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("g", a, ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -176,7 +177,8 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferStructF16_TemporallyBan) Enable(ast::Extension::kF16); auto* s = Structure("S", utils::Vector{Member("x", ty.f16(Source{{12, 34}}))}); - GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -193,7 +195,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferNoErrorStructF16Aliases_ auto* s = Structure("S", utils::Vector{Member("x", ty.f16(Source{{12, 34}}))}); auto* a1 = Alias("a1", ty.Of(s)); auto* a2 = Alias("a2", ty.Of(a1)); - GlobalVar("g", ty.Of(a2), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("g", ty.Of(a2), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -205,7 +207,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferNoErrorStructF16Aliases_ TEST_F(ResolverStorageClassValidationTest, StorageBufferPointer) { // var g : ptr; GlobalVar(Source{{56, 78}}, "g", ty.pointer(ty.f32(), ast::StorageClass::kPrivate), - ast::StorageClass::kStorage, Binding(0), Group(0)); + ast::StorageClass::kStorage, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -217,14 +219,14 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferPointer) { TEST_F(ResolverStorageClassValidationTest, StorageBufferIntScalar) { // var g : i32; - GlobalVar(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kStorage, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kStorage, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } TEST_F(ResolverStorageClassValidationTest, StorageBufferVectorF32) { // var g : vec4; - GlobalVar(Source{{56, 78}}, "g", ty.vec4(), ast::StorageClass::kStorage, Binding(0), + GlobalVar(Source{{56, 78}}, "g", ty.vec4(), ast::StorageClass::kStorage, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -234,8 +236,8 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferArrayF32) { // var g : array; auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); auto* a = ty.array(ty.Of(s), 3_u); - GlobalVar(Source{{56, 78}}, "g", a, ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), - Group(0)); + GlobalVar(Source{{56, 78}}, "g", a, ast::StorageClass::kStorage, ast::Access::kRead, + Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -254,7 +256,7 @@ TEST_F(ResolverStorageClassValidationTest, NotStorage_AccessMode) { TEST_F(ResolverStorageClassValidationTest, Storage_ReadAccessMode) { // @group(0) @binding(0) var a : i32; GlobalVar(Source{{56, 78}}, "a", ty.i32(), ast::StorageClass::kStorage, ast::Access::kRead, - Group(0), Binding(0)); + Group(0), Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -262,7 +264,7 @@ TEST_F(ResolverStorageClassValidationTest, Storage_ReadAccessMode) { TEST_F(ResolverStorageClassValidationTest, Storage_ReadWriteAccessMode) { // @group(0) @binding(0) var a : i32; GlobalVar(Source{{56, 78}}, "a", ty.i32(), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Group(0), Binding(0)); + Group(0), Binding(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -270,7 +272,7 @@ TEST_F(ResolverStorageClassValidationTest, Storage_ReadWriteAccessMode) { TEST_F(ResolverStorageClassValidationTest, Storage_WriteAccessMode) { // @group(0) @binding(0) var a : i32; GlobalVar(Source{{56, 78}}, "a", ty.i32(), ast::StorageClass::kStorage, ast::Access::kWrite, - Group(0), Binding(0)); + Group(0), Binding(0_a)); ASSERT_FALSE(r()->Resolve()); @@ -283,7 +285,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferStructI32) { // var g : S; auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())}); GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()); } @@ -296,7 +298,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferNoErrorStructI32Aliases) auto* a1 = Alias("a1", ty.Of(s)); auto* a2 = Alias("a2", ty.Of(a1)); GlobalVar(Source{{56, 78}}, "g", ty.Of(a2), ast::StorageClass::kStorage, ast::Access::kRead, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()); } @@ -307,7 +309,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBuffer_Struct_Runtime) { auto* s = Structure(Source{{12, 34}}, "S", utils::Vector{Member("m", ty.array())}); - GlobalVar(Source{{56, 78}}, "svar", ty.Of(s), ast::StorageClass::kUniform, Binding(0), + GlobalVar(Source{{56, 78}}, "svar", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -319,7 +321,8 @@ note: while analysing structure member S.m TEST_F(ResolverStorageClassValidationTest, UniformBufferBool) { // var g : bool; - GlobalVar(Source{{56, 78}}, "g", ty.bool_(), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.bool_(), ast::StorageClass::kUniform, Binding(0_a), + Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -333,7 +336,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferBoolAlias) { // type a = bool; // var g : a; auto* a = Alias("a", ty.bool_()); - GlobalVar(Source{{56, 78}}, "g", ty.Of(a), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.Of(a), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -349,7 +352,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferF16_TemporallyBan) { // var g : f16; Enable(ast::Extension::kF16); - GlobalVar("g", ty.f16(Source{{56, 78}}), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar("g", ty.f16(Source{{56, 78}}), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -364,8 +367,8 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferF16Alias_TemporallyBan) Enable(ast::Extension::kF16); auto* a = Alias("a", ty.f16()); - GlobalVar("g", ty.type_name(Source{{56, 78}}, a->name), ast::StorageClass::kUniform, Binding(0), - Group(0)); + GlobalVar("g", ty.type_name(Source{{56, 78}}, a->name), ast::StorageClass::kUniform, + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -378,7 +381,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferVectorF16_TemporallyBan) // var g : vec4; Enable(ast::Extension::kF16); GlobalVar("g", ty.vec(Source{{56, 78}}, ty.Of(), 4u), ast::StorageClass::kUniform, - Binding(0), Group(0)); + Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -396,7 +399,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferArrayF16_TemporallyBan) auto* s = Structure( "S", utils::Vector{Member("a", ty.f16(Source{{56, 78}}), utils::Vector{MemberSize(16)})}); auto* a = ty.array(ty.Of(s), 3_u); - GlobalVar("g", a, ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar("g", a, ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -410,7 +413,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferStructF16_TemporallyBan) Enable(ast::Extension::kF16); auto* s = Structure("S", utils::Vector{Member("x", ty.f16(Source{{12, 34}}))}); - GlobalVar("g", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar("g", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -426,7 +429,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferStructF16Aliases_Tempora auto* s = Structure("S", utils::Vector{Member("x", ty.f16(Source{{12, 34}}))}); auto* a1 = Alias("a1", ty.Of(s)); - GlobalVar("g", ty.Of(a1), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar("g", ty.Of(a1), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -437,7 +440,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferStructF16Aliases_Tempora TEST_F(ResolverStorageClassValidationTest, UniformBufferPointer) { // var g : ptr; GlobalVar(Source{{56, 78}}, "g", ty.pointer(ty.f32(), ast::StorageClass::kPrivate), - ast::StorageClass::kUniform, Binding(0), Group(0)); + ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_FALSE(r()->Resolve()); @@ -449,14 +452,14 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferPointer) { TEST_F(ResolverStorageClassValidationTest, UniformBufferIntScalar) { // var g : i32; - GlobalVar(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } TEST_F(ResolverStorageClassValidationTest, UniformBufferVectorF32) { // var g : vec4; - GlobalVar(Source{{56, 78}}, "g", ty.vec4(), ast::StorageClass::kUniform, Binding(0), + GlobalVar(Source{{56, 78}}, "g", ty.vec4(), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -469,7 +472,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferArrayF32) { // var g : array; auto* s = Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16)})}); auto* a = ty.array(ty.Of(s), 3_u); - GlobalVar(Source{{56, 78}}, "g", a, ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", a, ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -478,7 +481,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferStructI32) { // struct S { x : i32 }; // var g : S; auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())}); - GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } @@ -489,7 +492,8 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferStructI32Aliases) { // var g : a1; auto* s = Structure("S", utils::Vector{Member(Source{{12, 34}}, "x", ty.i32())}); auto* a1 = Alias("a1", ty.Of(s)); - GlobalVar(Source{{56, 78}}, "g", ty.Of(a1), ast::StorageClass::kUniform, Binding(0), Group(0)); + GlobalVar(Source{{56, 78}}, "g", ty.Of(a1), ast::StorageClass::kUniform, Binding(0_a), + Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); } diff --git a/src/tint/resolver/struct_storage_class_use_test.cc b/src/tint/resolver/struct_storage_class_use_test.cc index af7f976a43..69ea590737 100644 --- a/src/tint/resolver/struct_storage_class_use_test.cc +++ b/src/tint/resolver/struct_storage_class_use_test.cc @@ -159,8 +159,9 @@ TEST_F(ResolverStorageClassUseTest, StructReachableViaLocalArray) { TEST_F(ResolverStorageClassUseTest, StructMultipleStorageClassUses) { auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); - GlobalVar("x", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(0)); - GlobalVar("y", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(0)); + GlobalVar("x", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(0)); + GlobalVar("y", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(0)); WrapInFunction(Var("g", ty.Of(s))); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc index 25750029a5..0c76a76cae 100644 --- a/src/tint/resolver/type_validation_test.cc +++ b/src/tint/resolver/type_validation_test.cc @@ -761,7 +761,7 @@ using SampledTextureDimensionTest = ResolverTestWithParam; TEST_P(SampledTextureDimensionTest, All) { auto& params = GetParam(); GlobalVar(Source{{12, 34}}, "a", ty.sampled_texture(params.dim, ty.i32()), Group(0), - Binding(0)); + Binding(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); } @@ -779,7 +779,7 @@ using MultisampledTextureDimensionTest = ResolverTestWithParam; TEST_P(MultisampledTextureDimensionTest, All) { auto& params = GetParam(); GlobalVar("a", ty.multisampled_texture(Source{{12, 34}}, params.dim, ty.i32()), Group(0), - Binding(0)); + Binding(0_a)); if (params.is_valid) { EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -832,7 +832,7 @@ TEST_P(SampledTextureTypeTest, All) { GlobalVar( "a", ty.sampled_texture(Source{{12, 34}}, ast::TextureDimension::k2d, params.type_func(*this)), - Group(0), Binding(0)); + Group(0), Binding(0_a)); if (params.is_valid) { EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -851,7 +851,7 @@ TEST_P(MultisampledTextureTypeTest, All) { GlobalVar("a", ty.multisampled_texture(Source{{12, 34}}, ast::TextureDimension::k2d, params.type_func(*this)), - Group(0), Binding(0)); + Group(0), Binding(0_a)); if (params.is_valid) { EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -890,7 +890,7 @@ TEST_P(StorageTextureDimensionTest, All) { auto* st = ty.storage_texture(Source{{12, 34}}, params.dim, ast::TexelFormat::kR32Uint, ast::Access::kWrite); - GlobalVar("a", st, Group(0), Binding(0)); + GlobalVar("a", st, Group(0), Binding(0_a)); if (params.is_valid) { EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -940,17 +940,17 @@ TEST_P(StorageTextureFormatTest, All) { auto* st_a = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, params.format, ast::Access::kWrite); - GlobalVar("a", st_a, Group(0), Binding(0)); + GlobalVar("a", st_a, Group(0), Binding(0_a)); auto* st_b = ty.storage_texture(ast::TextureDimension::k2d, params.format, ast::Access::kWrite); - GlobalVar("b", st_b, Group(0), Binding(1)); + GlobalVar("b", st_b, Group(0), Binding(1_a)); auto* st_c = ty.storage_texture(ast::TextureDimension::k2dArray, params.format, ast::Access::kWrite); - GlobalVar("c", st_c, Group(0), Binding(2)); + GlobalVar("c", st_c, Group(0), Binding(2_a)); auto* st_d = ty.storage_texture(ast::TextureDimension::k3d, params.format, ast::Access::kWrite); - GlobalVar("d", st_d, Group(0), Binding(3)); + GlobalVar("d", st_d, Group(0), Binding(3_a)); if (params.is_valid) { EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -974,7 +974,7 @@ TEST_F(StorageTextureAccessTest, MissingAccess_Fail) { auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kUndefined); - GlobalVar("a", st, Group(0), Binding(0)); + GlobalVar("a", st, Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: storage texture missing access control"); @@ -987,7 +987,7 @@ TEST_F(StorageTextureAccessTest, RWAccess_Fail) { auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kReadWrite); - GlobalVar("a", st, Group(0), Binding(0)); + GlobalVar("a", st, Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -1001,7 +1001,7 @@ TEST_F(StorageTextureAccessTest, ReadOnlyAccess_Fail) { auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kRead); - GlobalVar("a", st, Group(0), Binding(0)); + GlobalVar("a", st, Group(0), Binding(0_a)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -1015,7 +1015,7 @@ TEST_F(StorageTextureAccessTest, WriteOnlyAccess_Pass) { auto* st = ty.storage_texture(ast::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); - GlobalVar("a", st, Group(0), Binding(0)); + GlobalVar("a", st, Group(0), Binding(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); } diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index cbd05c126a..970e5c9c90 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -329,7 +329,7 @@ TEST_F(ResolverValidationTest, StorageClass_FunctionVariableI32) { TEST_F(ResolverValidationTest, StorageClass_SamplerExplicitStorageClass) { auto* t = ty.sampler(ast::SamplerKind::kSampler); - GlobalVar(Source{{12, 34}}, "var", t, ast::StorageClass::kHandle, Binding(0), Group(0)); + GlobalVar(Source{{12, 34}}, "var", t, ast::StorageClass::kHandle, Binding(0_a), Group(0)); EXPECT_FALSE(r()->Resolve()); @@ -339,7 +339,7 @@ TEST_F(ResolverValidationTest, StorageClass_SamplerExplicitStorageClass) { TEST_F(ResolverValidationTest, StorageClass_TextureExplicitStorageClass) { auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); - GlobalVar(Source{{12, 34}}, "var", t, ast::StorageClass::kHandle, Binding(0), Group(0)); + GlobalVar(Source{{12, 34}}, "var", t, ast::StorageClass::kHandle, Binding(0_a), Group(0)); EXPECT_FALSE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/variable_test.cc b/src/tint/resolver/variable_test.cc index 02c37d5571..4579581267 100644 --- a/src/tint/resolver/variable_test.cc +++ b/src/tint/resolver/variable_test.cc @@ -18,11 +18,11 @@ #include "gmock/gmock.h" -using namespace tint::number_suffixes; // NOLINT - namespace tint::resolver { namespace { +using namespace tint::number_suffixes; // NOLINT + struct ResolverVariableTest : public resolver::TestHelper, public testing::Test {}; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -471,7 +471,7 @@ TEST_F(ResolverVariableTest, LocalLet_InheritsAccessFromOriginatingVariable) { auto* inner = Structure("Inner", utils::Vector{Member("arr", ty.array())}); auto* buf = Structure("S", utils::Vector{Member("inner", ty.Of(inner))}); auto* storage = GlobalVar("s", ty.Of(buf), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4_i); auto* ptr = Let("p", AddressOf(expr)); @@ -1036,10 +1036,12 @@ TEST_F(ResolverVariableTest, GlobalVar_StorageClass) { auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())}); auto* private_ = GlobalVar("p", ty.i32(), ast::StorageClass::kPrivate); auto* workgroup = GlobalVar("w", ty.i32(), ast::StorageClass::kWorkgroup); - auto* uniform = GlobalVar("ub", ty.Of(buf), ast::StorageClass::kUniform, Binding(0), Group(0)); - auto* storage = GlobalVar("sb", ty.Of(buf), ast::StorageClass::kStorage, Binding(1), Group(0)); + auto* uniform = + GlobalVar("ub", ty.Of(buf), ast::StorageClass::kUniform, Binding(0_a), Group(0)); + auto* storage = + GlobalVar("sb", ty.Of(buf), ast::StorageClass::kStorage, Binding(1_a), Group(0)); auto* handle = - GlobalVar("h", ty.depth_texture(ast::TextureDimension::k2d), Binding(2), Group(0)); + GlobalVar("h", ty.depth_texture(ast::TextureDimension::k2d), Binding(2_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -1061,7 +1063,7 @@ TEST_F(ResolverVariableTest, GlobalVar_ExplicitStorageClass) { auto* buf = Structure("S", utils::Vector{Member("m", ty.i32())}); auto* storage = GlobalVar("sb", ty.Of(buf), ast::StorageClass::kStorage, - ast::Access::kReadWrite, Binding(1), Group(0)); + ast::Access::kReadWrite, Binding(1_a), Group(0)); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/variable_validation_test.cc b/src/tint/resolver/variable_validation_test.cc index 0fb50a5d4a..6a61465cc2 100644 --- a/src/tint/resolver/variable_validation_test.cc +++ b/src/tint/resolver/variable_validation_test.cc @@ -124,7 +124,7 @@ TEST_F(ResolverVariableValidationTest, LetTypeNotConstructible) { // @group(0) @binding(0) var t1 : texture_2d; // let t2 : t1; auto* t1 = GlobalVar("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0), - Binding(0)); + Binding(0_a)); auto* t2 = Let(Source{{56, 78}}, "t2", Expr(t1)); WrapInFunction(t2); @@ -294,7 +294,7 @@ TEST_F(ResolverVariableValidationTest, InferredPtrStorageAccessMismatch) { auto* buf = Structure("S", utils::Vector{ Member("inner", ty.Of(inner)), }); - auto* storage = GlobalVar("s", ty.Of(buf), ast::StorageClass::kStorage, Binding(0), Group(0)); + auto* storage = GlobalVar("s", ty.Of(buf), ast::StorageClass::kStorage, Binding(0_a), Group(0)); auto* expr = IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 2_i); auto* ptr = @@ -348,7 +348,7 @@ TEST_F(ResolverVariableValidationTest, NonConstructibleType_InferredType) { // fn foo() { // var v = s; // } - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(0)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(0_a)); auto* v = Var(Source{{12, 34}}, "v", Expr("s")); WrapInFunction(v); diff --git a/src/tint/transform/array_length_from_uniform.cc b/src/tint/transform/array_length_from_uniform.cc index 36ddcdc962..64525a7e03 100644 --- a/src/tint/transform/array_length_from_uniform.cc +++ b/src/tint/transform/array_length_from_uniform.cc @@ -146,9 +146,10 @@ void ArrayLengthFromUniform::Run(CloneContext& ctx, const DataMap& inputs, DataM ctx.dst->ty.array(ctx.dst->ty.vec4(ctx.dst->ty.u32()), u32((max_buffer_size_index / 4) + 1))), }); - buffer_size_ubo = ctx.dst->GlobalVar( - ctx.dst->Sym(), ctx.dst->ty.Of(buffer_size_struct), ast::StorageClass::kUniform, - ctx.dst->Group(cfg->ubo_binding.group), ctx.dst->Binding(cfg->ubo_binding.binding)); + buffer_size_ubo = ctx.dst->GlobalVar(ctx.dst->Sym(), ctx.dst->ty.Of(buffer_size_struct), + ast::StorageClass::kUniform, + ctx.dst->Group(cfg->ubo_binding.group), + ctx.dst->Binding(AInt(cfg->ubo_binding.binding))); } return buffer_size_ubo; }; diff --git a/src/tint/transform/binding_remapper.cc b/src/tint/transform/binding_remapper.cc index eaf9725453..15be81debb 100644 --- a/src/tint/transform/binding_remapper.cc +++ b/src/tint/transform/binding_remapper.cc @@ -106,8 +106,8 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) co auto bp_it = remappings->binding_points.find(from); if (bp_it != remappings->binding_points.end()) { BindingPoint to = bp_it->second; - auto* new_group = ctx.dst->create(to.group); - auto* new_binding = ctx.dst->create(to.binding); + auto* new_group = ctx.dst->Group(to.group); + auto* new_binding = ctx.dst->Binding(AInt(to.binding)); auto* old_group = ast::GetAttribute(var->attributes); auto* old_binding = ast::GetAttribute(var->attributes); diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index 6290b26490..fe66b8ec77 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc @@ -39,6 +39,8 @@ bool IsGlobal(const tint::sem::VariablePair& pair) { namespace tint::transform { +using namespace tint::number_suffixes; // NOLINT + CombineSamplers::BindingInfo::BindingInfo(const BindingMap& map, const sem::BindingPoint& placeholder) : binding_map(map), placeholder_binding_point(placeholder) {} @@ -79,7 +81,8 @@ struct CombineSamplers::State { /// Group 0 and binding 0 are used, with collisions disabled. /// @returns the newly-created attribute list auto Attributes() const { - utils::Vector attributes{ctx.dst->Group(0), ctx.dst->Binding(0)}; + utils::Vector attributes{ctx.dst->Group(0), + ctx.dst->Binding(0_a)}; attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kBindingPointCollision)); return attributes; } diff --git a/src/tint/transform/decompose_strided_array_test.cc b/src/tint/transform/decompose_strided_array_test.cc index 2de42fa3c4..59188a7848 100644 --- a/src/tint/transform/decompose_strided_array_test.cc +++ b/src/tint/transform/decompose_strided_array_test.cc @@ -158,7 +158,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) { // } ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(32))}); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.ty.array(32), b.MemberAccessor("s", "a"))), @@ -206,7 +206,7 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) { // } ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(b.ty.vec4(), 4_u, 16))}); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); b.Func( "f", utils::Empty, b.ty.void_(), utils::Vector{ @@ -252,7 +252,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) { // } ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(32))}); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.ty.array(32), b.MemberAccessor("s", "a"))), @@ -300,7 +300,7 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) { // } ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(4))}); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, b.Group(0), b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.ty.array(4), b.MemberAccessor("s", "a"))), @@ -345,7 +345,7 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageStridedArray) { ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(32))}); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.array(32))), @@ -399,7 +399,7 @@ TEST_F(DecomposeStridedArrayTest, WriteStorageDefaultStridedArray) { ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(4))}); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Assign(b.MemberAccessor("s", "a"), b.Construct(b.ty.array(4))), @@ -451,7 +451,7 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) { ProgramBuilder b; auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.array(32))}); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.AddressOf(b.MemberAccessor("s", "a")))), @@ -512,7 +512,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) { b.Alias("ARR", b.ty.array(32)); auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR"))}); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))), @@ -582,7 +582,7 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) { 4_u, 128)); auto* S = b.Structure("S", utils::Vector{b.Member("a", b.ty.type_name("ARR_B"))}); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.ty.type_name("ARR_B"), b.MemberAccessor("s", "a"))), diff --git a/src/tint/transform/decompose_strided_matrix_test.cc b/src/tint/transform/decompose_strided_matrix_test.cc index a947f6d342..8668ed28b1 100644 --- a/src/tint/transform/decompose_strided_matrix_test.cc +++ b/src/tint/transform/decompose_strided_matrix_test.cc @@ -76,7 +76,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) { b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), }), }); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("x", b.ty.mat2x2(), b.MemberAccessor("s", "m"))), @@ -132,7 +132,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) { b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), }), }); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); b.Func( "f", utils::Empty, b.ty.void_(), utils::Vector{ @@ -185,7 +185,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) { b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute), }), }); - b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); + b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("x", b.ty.mat2x2(), b.MemberAccessor("s", "m"))), @@ -239,7 +239,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) { }), }); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("x", b.ty.mat2x2(), b.MemberAccessor("s", "m"))), @@ -296,7 +296,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) { }), }); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func( "f", utils::Empty, b.ty.void_(), utils::Vector{ @@ -350,7 +350,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) { }), }); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Assign(b.MemberAccessor("s", "m"), @@ -408,7 +408,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) { }), }); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Assign(b.IndexAccessor(b.MemberAccessor("s", "m"), 1_i), b.vec2(1_f, 2_f)), @@ -467,7 +467,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) { }), }); b.GlobalVar("s", b.ty.Of(S), ast::StorageClass::kStorage, ast::Access::kReadWrite, b.Group(0), - b.Binding(0)); + b.Binding(0_a)); b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{ b.Decl(b.Let("a", b.AddressOf(b.MemberAccessor("s", "m")))), diff --git a/src/tint/transform/first_index_offset.cc b/src/tint/transform/first_index_offset.cc index 34b481e3b9..0ba5da6b6c 100644 --- a/src/tint/transform/first_index_offset.cc +++ b/src/tint/transform/first_index_offset.cc @@ -123,8 +123,8 @@ void FirstIndexOffset::Run(CloneContext& ctx, const DataMap& inputs, DataMap& ou Symbol buffer_name = ctx.dst->Sym(); ctx.dst->GlobalVar(buffer_name, ctx.dst->ty.Of(struct_), ast::StorageClass::kUniform, utils::Vector{ - ctx.dst->create(ub_binding), - ctx.dst->create(ub_group), + ctx.dst->Binding(AInt(ub_binding)), + ctx.dst->Group(ub_group), }); // Fix up all references to the builtins with the offsets diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc index 2fb4248549..65f5913346 100644 --- a/src/tint/transform/multiplanar_external_texture.cc +++ b/src/tint/transform/multiplanar_external_texture.cc @@ -131,11 +131,11 @@ struct MultiplanarExternalTexture::State { syms.plane_0 = ctx.Clone(global->symbol); syms.plane_1 = b.Symbols().New("ext_tex_plane_1"); b.GlobalVar(syms.plane_1, b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()), - b.Group(bps.plane_1.group), b.Binding(bps.plane_1.binding)); + b.Group(bps.plane_1.group), b.Binding(AInt(bps.plane_1.binding))); syms.params = b.Symbols().New("ext_tex_params"); b.GlobalVar(syms.params, b.ty.type_name("ExternalTextureParams"), ast::StorageClass::kUniform, b.Group(bps.params.group), - b.Binding(bps.params.binding)); + b.Binding(AInt(bps.params.binding))); // Replace the original texture_external binding with a texture_2d // binding. diff --git a/src/tint/transform/num_workgroups_from_uniform.cc b/src/tint/transform/num_workgroups_from_uniform.cc index 5772424426..62983fddcd 100644 --- a/src/tint/transform/num_workgroups_from_uniform.cc +++ b/src/tint/transform/num_workgroups_from_uniform.cc @@ -150,7 +150,7 @@ void NumWorkgroupsFromUniform::Run(CloneContext& ctx, const DataMap& inputs, Dat num_workgroups_ubo = ctx.dst->GlobalVar( ctx.dst->Sym(), ctx.dst->ty.Of(num_workgroups_struct), ast::StorageClass::kUniform, - ctx.dst->Group(group), ctx.dst->Binding(binding)); + ctx.dst->Group(group), ctx.dst->Binding(AInt(binding))); } return num_workgroups_ubo; }; diff --git a/src/tint/transform/vertex_pulling.cc b/src/tint/transform/vertex_pulling.cc index 346bb1600d..56b6de7236 100644 --- a/src/tint/transform/vertex_pulling.cc +++ b/src/tint/transform/vertex_pulling.cc @@ -260,8 +260,8 @@ struct State { for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { // The decorated variable with struct type ctx.dst->GlobalVar(GetVertexBufferName(i), ctx.dst->ty.Of(struct_type), - ast::StorageClass::kStorage, ast::Access::kRead, ctx.dst->Binding(i), - ctx.dst->Group(cfg.pulling_group)); + ast::StorageClass::kStorage, ast::Access::kRead, + ctx.dst->Binding(AInt(i)), ctx.dst->Group(cfg.pulling_group)); } } diff --git a/src/tint/writer/flatten_bindings_test.cc b/src/tint/writer/flatten_bindings_test.cc index 7137218c08..4cc0c7fca8 100644 --- a/src/tint/writer/flatten_bindings_test.cc +++ b/src/tint/writer/flatten_bindings_test.cc @@ -23,6 +23,8 @@ namespace tint::writer { namespace { +using namespace tint::number_suffixes; // NOLINT + class FlattenBindingsTest : public ::testing::Test {}; TEST_F(FlattenBindingsTest, NoBindings) { @@ -36,9 +38,9 @@ TEST_F(FlattenBindingsTest, NoBindings) { TEST_F(FlattenBindingsTest, AlreadyFlat) { ProgramBuilder b; - b.GlobalVar("a", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); - b.GlobalVar("b", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(1)); - b.GlobalVar("c", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(2)); + b.GlobalVar("a", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); + b.GlobalVar("b", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(1_a)); + b.GlobalVar("c", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(2_a)); Program program(std::move(b)); ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str(); @@ -49,9 +51,9 @@ TEST_F(FlattenBindingsTest, AlreadyFlat) { TEST_F(FlattenBindingsTest, NotFlat_SingleNamespace) { ProgramBuilder b; - b.GlobalVar("a", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); - b.GlobalVar("b", b.ty.i32(), ast::StorageClass::kUniform, b.Group(1), b.Binding(1)); - b.GlobalVar("c", b.ty.i32(), ast::StorageClass::kUniform, b.Group(2), b.Binding(2)); + b.GlobalVar("a", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); + b.GlobalVar("b", b.ty.i32(), ast::StorageClass::kUniform, b.Group(1), b.Binding(1_a)); + b.GlobalVar("c", b.ty.i32(), ast::StorageClass::kUniform, b.Group(2), b.Binding(2_a)); b.WrapInFunction(b.Expr("a"), b.Expr("b"), b.Expr("c")); Program program(std::move(b)); @@ -82,30 +84,30 @@ TEST_F(FlattenBindingsTest, NotFlat_MultipleNamespaces) { ProgramBuilder b; const size_t num_buffers = 3; - b.GlobalVar("buffer1", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0)); - b.GlobalVar("buffer2", b.ty.i32(), ast::StorageClass::kStorage, b.Group(1), b.Binding(1)); + b.GlobalVar("buffer1", b.ty.i32(), ast::StorageClass::kUniform, b.Group(0), b.Binding(0_a)); + b.GlobalVar("buffer2", b.ty.i32(), ast::StorageClass::kStorage, b.Group(1), b.Binding(1_a)); b.GlobalVar("buffer3", b.ty.i32(), ast::StorageClass::kStorage, ast::Access::kRead, b.Group(2), - b.Binding(2)); + b.Binding(2_a)); const size_t num_samplers = 2; - b.GlobalVar("sampler1", b.ty.sampler(ast::SamplerKind::kSampler), b.Group(3), b.Binding(3)); + b.GlobalVar("sampler1", b.ty.sampler(ast::SamplerKind::kSampler), b.Group(3), b.Binding(3_a)); b.GlobalVar("sampler2", b.ty.sampler(ast::SamplerKind::kComparisonSampler), b.Group(4), - b.Binding(4)); + b.Binding(4_a)); const size_t num_textures = 6; b.GlobalVar("texture1", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()), - b.Group(5), b.Binding(5)); + b.Group(5), b.Binding(5_a)); b.GlobalVar("texture2", b.ty.multisampled_texture(ast::TextureDimension::k2d, b.ty.f32()), - b.Group(6), b.Binding(6)); + b.Group(6), b.Binding(6_a)); b.GlobalVar("texture3", b.ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite), - b.Group(7), b.Binding(7)); + b.Group(7), b.Binding(7_a)); b.GlobalVar("texture4", b.ty.depth_texture(ast::TextureDimension::k2d), b.Group(8), - b.Binding(8)); + b.Binding(8_a)); b.GlobalVar("texture5", b.ty.depth_multisampled_texture(ast::TextureDimension::k2d), b.Group(9), - b.Binding(9)); - b.GlobalVar("texture6", b.ty.external_texture(), b.Group(10), b.Binding(10)); + b.Binding(9_a)); + b.GlobalVar("texture6", b.ty.external_texture(), b.Group(10), b.Binding(10_a)); b.WrapInFunction(b.Assign(b.Phony(), "buffer1"), b.Assign(b.Phony(), "buffer2"), b.Assign(b.Phony(), "buffer3"), b.Assign(b.Phony(), "sampler1"), diff --git a/src/tint/writer/generate_external_texture_bindings_test.cc b/src/tint/writer/generate_external_texture_bindings_test.cc index 8c7b8d46b3..faec018321 100644 --- a/src/tint/writer/generate_external_texture_bindings_test.cc +++ b/src/tint/writer/generate_external_texture_bindings_test.cc @@ -21,6 +21,8 @@ namespace tint::writer { namespace { +using namespace tint::number_suffixes; // NOLINT + constexpr auto kUniform = ast::StorageClass::kUniform; class GenerateExternalTextureBindingsTest : public ::testing::Test {}; @@ -36,7 +38,7 @@ TEST_F(GenerateExternalTextureBindingsTest, None) { TEST_F(GenerateExternalTextureBindingsTest, One) { ProgramBuilder b; - b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0)); + b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0_a)); tint::Program program(std::move(b)); ASSERT_TRUE(program.IsValid()); @@ -52,8 +54,8 @@ TEST_F(GenerateExternalTextureBindingsTest, One) { TEST_F(GenerateExternalTextureBindingsTest, Two_SameGroup) { ProgramBuilder b; - b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0)); - b.GlobalVar("v1", b.ty.external_texture(), b.Group(0), b.Binding(1)); + b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0_a)); + b.GlobalVar("v1", b.ty.external_texture(), b.Group(0), b.Binding(1_a)); tint::Program program(std::move(b)); ASSERT_TRUE(program.IsValid()); @@ -75,8 +77,8 @@ TEST_F(GenerateExternalTextureBindingsTest, Two_SameGroup) { TEST_F(GenerateExternalTextureBindingsTest, Two_DifferentGroup) { ProgramBuilder b; - b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0)); - b.GlobalVar("v1", b.ty.external_texture(), b.Group(1), b.Binding(0)); + b.GlobalVar("v0", b.ty.external_texture(), b.Group(0), b.Binding(0_a)); + b.GlobalVar("v1", b.ty.external_texture(), b.Group(1), b.Binding(0_a)); tint::Program program(std::move(b)); ASSERT_TRUE(program.IsValid()); @@ -98,11 +100,11 @@ TEST_F(GenerateExternalTextureBindingsTest, Two_DifferentGroup) { TEST_F(GenerateExternalTextureBindingsTest, Two_WithOtherBindingsInSameGroup) { ProgramBuilder b; - b.GlobalVar("v0", b.ty.i32(), b.Group(0), b.Binding(0), kUniform); - b.GlobalVar("v1", b.ty.external_texture(), b.Group(0), b.Binding(1)); - b.GlobalVar("v2", b.ty.i32(), b.Group(0), b.Binding(2), kUniform); - b.GlobalVar("v3", b.ty.external_texture(), b.Group(0), b.Binding(3)); - b.GlobalVar("v4", b.ty.i32(), b.Group(0), b.Binding(4), kUniform); + b.GlobalVar("v0", b.ty.i32(), b.Group(0), b.Binding(0_a), kUniform); + b.GlobalVar("v1", b.ty.external_texture(), b.Group(0), b.Binding(1_a)); + b.GlobalVar("v2", b.ty.i32(), b.Group(0), b.Binding(2_a), kUniform); + b.GlobalVar("v3", b.ty.external_texture(), b.Group(0), b.Binding(3_a)); + b.GlobalVar("v4", b.ty.i32(), b.Group(0), b.Binding(4_a), kUniform); tint::Program program(std::move(b)); ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str(); diff --git a/src/tint/writer/glsl/generator_impl_function_test.cc b/src/tint/writer/glsl/generator_impl_function_test.cc index 90824baf7a..6b28aec111 100644 --- a/src/tint/writer/glsl/generator_impl_function_test.cc +++ b/src/tint/writer/glsl/generator_impl_function_test.cc @@ -351,7 +351,8 @@ tint_symbol_2 vert_main2() { TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_Uniform) { auto* ubo_ty = Structure("UBO", utils::Vector{Member("coord", ty.vec4())}); - auto* ubo = GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Binding(0), Group(1)); + auto* ubo = + GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Binding(0_a), Group(1)); Func("sub_func", utils::Vector{ @@ -401,7 +402,7 @@ void frag_main() { TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_UniformStruct) { auto* s = Structure("Uniforms", utils::Vector{Member("coord", ty.vec4())}); - GlobalVar("uniforms", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(1)); + GlobalVar("uniforms", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor(MemberAccessor("uniforms", "coord"), "x")); @@ -441,7 +442,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RW_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -488,7 +489,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RO_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -536,7 +537,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_WO_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("frag_main", utils::Empty, ty.void_(), @@ -581,7 +582,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_StorageBuf Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("frag_main", utils::Empty, ty.void_(), @@ -622,7 +623,7 @@ void main() { TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_Uniform) { auto* s = Structure("S", utils::Vector{Member("x", ty.f32())}); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(1)); + GlobalVar("coord", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(1)); Func("sub_func", utils::Vector{Param("param", ty.f32())}, ty.f32(), utils::Vector{ @@ -667,7 +668,7 @@ void frag_main() { TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_StorageBuffer) { auto* s = Structure("S", utils::Vector{Member("x", ty.f32())}); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("sub_func", utils::Vector{Param("param", ty.f32())}, ty.f32(), @@ -893,7 +894,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Multiple_EntryPoint_With_Same_Module auto* s = Structure("Data", utils::Vector{Member("d", ty.f32())}); - GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(0)); { diff --git a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc index 1736ab025a..dd7f0c9e43 100644 --- a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc @@ -92,7 +92,7 @@ class GlslGeneratorImplTest_MemberAccessorBase : public BASE { auto* s = b.Structure("Data", members); b.GlobalVar("data", b.ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - b.Group(1), b.Binding(0)); + b.Group(1), b.Binding(0_a)); } void SetupFunction(utils::VectorRef statements) { diff --git a/src/tint/writer/glsl/generator_impl_sanitizer_test.cc b/src/tint/writer/glsl/generator_impl_sanitizer_test.cc index c801b47868..5592c05088 100644 --- a/src/tint/writer/glsl/generator_impl_sanitizer_test.cc +++ b/src/tint/writer/glsl/generator_impl_sanitizer_test.cc @@ -26,7 +26,8 @@ using GlslSanitizerTest = TestHelper; TEST_F(GlslSanitizerTest, Call_ArrayLength) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -64,7 +65,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) { Member(0, "z", ty.f32()), Member(4, "a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -101,7 +103,8 @@ void main() { TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* p = Let("p", AddressOf("b")); auto* p2 = Let("p2", AddressOf(MemberAccessor(Deref(p), "a"))); diff --git a/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc b/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc index 0264b0249b..b5cc5f2e67 100644 --- a/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc +++ b/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc @@ -37,7 +37,7 @@ void TestAlign(ProgramBuilder* ctx) { ctx->Member("dewey", ctx->ty.f32(), utils::Vector{ctx->MemberAlign(256_u)}), ctx->Member("louie", ctx->ty.f32(), utils::Vector{ctx->MemberAlign(256_u)}), }); - ctx->GlobalVar("nephews", ctx->ty.Of(nephews), ast::StorageClass::kStorage, ctx->Binding(0), + ctx->GlobalVar("nephews", ctx->ty.Of(nephews), ast::StorageClass::kStorage, ctx->Binding(0_a), ctx->Group(0)); } diff --git a/src/tint/writer/glsl/generator_impl_type_test.cc b/src/tint/writer/glsl/generator_impl_type_test.cc index 23da9759e7..ebfc10584e 100644 --- a/src/tint/writer/glsl/generator_impl_type_test.cc +++ b/src/tint/writer/glsl/generator_impl_type_test.cc @@ -312,7 +312,7 @@ TEST_P(GlslDepthTexturesTest, Emit) { auto* t = ty.depth_texture(params.dim); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -340,7 +340,7 @@ using GlslDepthMultisampledTexturesTest = TestHelper; TEST_F(GlslDepthMultisampledTexturesTest, Emit) { auto* t = ty.depth_multisampled_texture(ast::TextureDimension::k2d); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -384,7 +384,7 @@ TEST_P(GlslSampledTexturesTest, Emit) { } auto* t = ty.sampled_texture(params.dim, datatype); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -519,7 +519,7 @@ TEST_P(GlslStorageTexturesTest, Emit) { auto* t = ty.storage_texture(params.dim, params.imgfmt, ast::Access::kWrite); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ diff --git a/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc b/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc index a2e5ee8968..f4ab30133f 100644 --- a/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc +++ b/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc @@ -20,11 +20,13 @@ using ::testing::HasSubstr; namespace tint::writer::glsl { namespace { +using namespace tint::number_suffixes; // NOLINT + using GlslGeneratorImplTest_UniformBuffer = TestHelper; TEST_F(GlslGeneratorImplTest_UniformBuffer, Simple) { auto* simple = Structure("Simple", utils::Vector{Member("member", ty.f32())}); - GlobalVar("simple", ty.Of(simple), ast::StorageClass::kUniform, Group(0), Binding(0)); + GlobalVar("simple", ty.Of(simple), ast::StorageClass::kUniform, Group(0), Binding(0_a)); GeneratorImpl& gen = Build(); @@ -44,7 +46,7 @@ layout(binding = 0) uniform Simple_1 { TEST_F(GlslGeneratorImplTest_UniformBuffer, Simple_Desktop) { auto* simple = Structure("Simple", utils::Vector{Member("member", ty.f32())}); - GlobalVar("simple", ty.Of(simple), ast::StorageClass::kUniform, Group(0), Binding(0)); + GlobalVar("simple", ty.Of(simple), ast::StorageClass::kUniform, Group(0), Binding(0_a)); GeneratorImpl& gen = Build(Version(Version::Standard::kDesktop, 4, 4)); diff --git a/src/tint/writer/hlsl/generator_impl_function_test.cc b/src/tint/writer/hlsl/generator_impl_function_test.cc index 5bff35efd1..48a259aeb3 100644 --- a/src/tint/writer/hlsl/generator_impl_function_test.cc +++ b/src/tint/writer/hlsl/generator_impl_function_test.cc @@ -360,7 +360,8 @@ tint_symbol_1 vert_main2() { TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_Uniform) { auto* ubo_ty = Structure("UBO", utils::Vector{Member("coord", ty.vec4())}); - auto* ubo = GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Binding(0), Group(1)); + auto* ubo = + GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Binding(0_a), Group(1)); Func("sub_func", utils::Vector{ @@ -403,7 +404,7 @@ void frag_main() { TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_UniformStruct) { auto* s = Structure("Uniforms", utils::Vector{Member("coord", ty.vec4())}); - GlobalVar("uniforms", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(1)); + GlobalVar("uniforms", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor(MemberAccessor("uniforms", "coord"), "x")); @@ -436,7 +437,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RW_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -469,7 +470,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RO_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(1)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -502,7 +503,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_WO_Storage Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("frag_main", utils::Empty, ty.void_(), @@ -533,7 +534,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_StorageBuf Member("b", ty.f32()), }); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("frag_main", utils::Empty, ty.void_(), @@ -560,7 +561,7 @@ void frag_main() { TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_Uniform) { auto* s = Structure("S", utils::Vector{Member("x", ty.f32())}); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kUniform, Binding(0), Group(1)); + GlobalVar("coord", ty.Of(s), ast::StorageClass::kUniform, Binding(0_a), Group(1)); Func("sub_func", utils::Vector{ @@ -602,7 +603,7 @@ void frag_main() { TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_StorageBuffer) { auto* s = Structure("S", utils::Vector{Member("x", ty.f32())}); - GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(1)); Func("sub_func", @@ -845,7 +846,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Multiple_EntryPoint_With_Same_Module auto* s = Structure("Data", utils::Vector{Member("d", ty.f32())}); - GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(0)); { diff --git a/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc b/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc index 39dd86cb9a..19aa0d835c 100644 --- a/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc @@ -91,7 +91,7 @@ class HlslGeneratorImplTest_MemberAccessorBase : public BASE { auto* s = b.Structure("Data", members); b.GlobalVar("data", b.ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - b.Group(1), b.Binding(0)); + b.Group(1), b.Binding(0_a)); } void SetupFunction(utils::VectorRef statements) { diff --git a/src/tint/writer/hlsl/generator_impl_sanitizer_test.cc b/src/tint/writer/hlsl/generator_impl_sanitizer_test.cc index 62a236ed3a..c7262ccc6d 100644 --- a/src/tint/writer/hlsl/generator_impl_sanitizer_test.cc +++ b/src/tint/writer/hlsl/generator_impl_sanitizer_test.cc @@ -26,7 +26,8 @@ using HlslSanitizerTest = TestHelper; TEST_F(HlslSanitizerTest, Call_ArrayLength) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -59,7 +60,8 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) { Member(0, "z", ty.f32()), Member(4, "a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -90,7 +92,8 @@ void a_func() { TEST_F(HlslSanitizerTest, Call_ArrayLength_ViaLets) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* p = Let("p", AddressOf("b")); auto* p2 = Let("p2", AddressOf(MemberAccessor(Deref(p), "a"))); @@ -126,8 +129,10 @@ void a_func() { TEST_F(HlslSanitizerTest, Call_ArrayLength_ArrayLengthFromUniform) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); - GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); + GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ diff --git a/src/tint/writer/hlsl/generator_impl_type_test.cc b/src/tint/writer/hlsl/generator_impl_type_test.cc index e89c5008a6..22c26ddf9e 100644 --- a/src/tint/writer/hlsl/generator_impl_type_test.cc +++ b/src/tint/writer/hlsl/generator_impl_type_test.cc @@ -177,7 +177,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl_OmittedIfStorageBuffer) { Member("a", ty.i32()), Member("b", ty.f32()), }); - GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(0)); GeneratorImpl& gen = Build(); @@ -308,7 +308,7 @@ TEST_P(HlslDepthTexturesTest, Emit) { auto* t = ty.depth_texture(params.dim); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -339,7 +339,7 @@ using HlslDepthMultisampledTexturesTest = TestHelper; TEST_F(HlslDepthMultisampledTexturesTest, Emit) { auto* t = ty.depth_multisampled_texture(ast::TextureDimension::k2d); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -383,7 +383,7 @@ TEST_P(HlslSampledTexturesTest, Emit) { } auto* t = ty.sampled_texture(params.dim, datatype); - GlobalVar("tex", t, Binding(1), Group(2)); + GlobalVar("tex", t, Binding(1_a), Group(2)); Func("main", utils::Empty, ty.void_(), utils::Vector{ @@ -522,7 +522,7 @@ TEST_P(HlslStorageTexturesTest, Emit) { GlobalVar("tex", t, utils::Vector{ Group(2), - Binding(1), + Binding(1_a), }); Func("main", utils::Empty, ty.void_(), diff --git a/src/tint/writer/msl/generator_impl_function_test.cc b/src/tint/writer/msl/generator_impl_function_test.cc index 56761a77d2..f5b75c9b3a 100644 --- a/src/tint/writer/msl/generator_impl_function_test.cc +++ b/src/tint/writer/msl/generator_impl_function_test.cc @@ -343,7 +343,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionAttribute_EntryPoint_With_RW_StorageBu }); GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Group(0), - Binding(0)); + Binding(0_a)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -382,7 +382,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionAttribute_EntryPoint_With_RO_StorageBu }); GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Group(0), - Binding(0)); + Binding(0_a)); auto* var = Var("v", ty.f32(), MemberAccessor("coord", "b")); @@ -416,7 +416,8 @@ fragment void frag_main(const device Data* tint_symbol [[buffer(0)]]) { TEST_F(MslGeneratorImplTest, Emit_Attribute_Called_By_EntryPoint_With_Uniform) { auto* ubo_ty = Structure("UBO", utils::Vector{Member("coord", ty.vec4())}); - auto* ubo = GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Group(0), Binding(0)); + auto* ubo = + GlobalVar("ubo", ty.Of(ubo_ty), ast::StorageClass::kUniform, Group(0), Binding(0_a)); Func("sub_func", utils::Vector{ @@ -467,7 +468,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionAttribute_Called_By_EntryPoint_With_RW }); GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Group(0), - Binding(0)); + Binding(0_a)); Func("sub_func", utils::Vector{ @@ -519,7 +520,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionAttribute_Called_By_EntryPoint_With_RO }); GlobalVar("coord", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Group(0), - Binding(0)); + Binding(0_a)); Func("sub_func", utils::Vector{ @@ -657,7 +658,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_Multiple_EntryPoint_With_Same_ModuleV auto* s = Structure("Data", utils::Vector{Member("d", ty.f32())}); GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Group(0), - Binding(0)); + Binding(0_a)); { auto* var = Var("v", ty.f32(), MemberAccessor("data", "d")); diff --git a/src/tint/writer/msl/generator_impl_sanitizer_test.cc b/src/tint/writer/msl/generator_impl_sanitizer_test.cc index 472822bc4a..6b4f927ac4 100644 --- a/src/tint/writer/msl/generator_impl_sanitizer_test.cc +++ b/src/tint/writer/msl/generator_impl_sanitizer_test.cc @@ -22,12 +22,14 @@ namespace tint::writer::msl { namespace { using ::testing::HasSubstr; +using namespace tint::number_suffixes; // NOLINT using MslSanitizerTest = TestHelper; TEST_F(MslSanitizerTest, Call_ArrayLength) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -80,7 +82,8 @@ TEST_F(MslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) { Member(0, "z", ty.f32()), Member(4, "a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -132,7 +135,8 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(30)]]) { TEST_F(MslSanitizerTest, Call_ArrayLength_ViaLets) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* p = Let("p", AddressOf("b")); auto* p2 = Let("p2", AddressOf(MemberAccessor(Deref(p), "a"))); @@ -188,8 +192,10 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(30)]]) { TEST_F(MslSanitizerTest, Call_ArrayLength_ArrayLengthFromUniform) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(0)); - GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2), Group(0)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(0)); + GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2_a), + Group(0)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ @@ -245,8 +251,10 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(29)]]) { TEST_F(MslSanitizerTest, Call_ArrayLength_ArrayLengthFromUniformMissingBinding) { auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array(4))}); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(0)); - GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2), Group(0)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(0)); + GlobalVar("c", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(2_a), + Group(0)); Func("a_func", utils::Empty, ty.void_(), utils::Vector{ diff --git a/src/tint/writer/msl/generator_impl_type_test.cc b/src/tint/writer/msl/generator_impl_type_test.cc index 531a45d72e..6ad7832cd3 100644 --- a/src/tint/writer/msl/generator_impl_type_test.cc +++ b/src/tint/writer/msl/generator_impl_type_test.cc @@ -282,7 +282,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_NonComposites) { Member("z", ty.f32()), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -388,7 +389,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_Structures) { Member("e", ty.f32()), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -478,7 +480,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayDefaultStride) { Member("f", array_z), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -560,7 +563,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayVec3DefaultStride) { Member("c", ty.i32()), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -620,7 +624,8 @@ TEST_F(MslGeneratorImplTest, AttemptTintPadSymbolCollision) { Member("tint_pad_21", ty.f32()), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -677,7 +682,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_WithAttribute) { Member("b", ty.f32()), }); - GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("G", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); GeneratorImpl& gen = Build(); @@ -840,7 +846,7 @@ TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); auto* s = ty.storage_texture(params.dim, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 933b562bc5..55b8bc7dd8 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -762,7 +762,12 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) { return true; } - auto* sem = builder_.Sem().Get(v); + auto* sem = builder_.Sem().Get(v); + if (!sem) { + TINT_ICE(Writer, builder_.Diagnostics()) + << "attempted to generate a global from a non-global variable"; + return false; + } auto* type = sem->Type()->UnwrapRef(); uint32_t init_id = 0; @@ -893,15 +898,17 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) { {Operand(var_id), U32Operand(SpvDecorationInvariant)}); return true; }, - [&](const ast::BindingAttribute* binding) { + [&](const ast::BindingAttribute*) { + auto bp = sem->BindingPoint(); push_annot(spv::Op::OpDecorate, {Operand(var_id), U32Operand(SpvDecorationBinding), - Operand(binding->value)}); + Operand(bp.binding)}); return true; }, - [&](const ast::GroupAttribute* group) { - push_annot(spv::Op::OpDecorate, - {Operand(var_id), U32Operand(SpvDecorationDescriptorSet), - Operand(group->value)}); + [&](const ast::GroupAttribute*) { + auto bp = sem->BindingPoint(); + push_annot( + spv::Op::OpDecorate, + {Operand(var_id), U32Operand(SpvDecorationDescriptorSet), Operand(bp.group)}); return true; }, [&](const ast::IdAttribute*) { diff --git a/src/tint/writer/spirv/builder_assign_test.cc b/src/tint/writer/spirv/builder_assign_test.cc index be30dc76c3..963e680db3 100644 --- a/src/tint/writer/spirv/builder_assign_test.cc +++ b/src/tint/writer/spirv/builder_assign_test.cc @@ -186,7 +186,7 @@ TEST_F(BuilderTest, Assign_StructMember) { spirv::Builder& b = Build(); b.push_function(Function{}); - EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); + EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error(); @@ -195,16 +195,16 @@ TEST_F(BuilderTest, Assign_StructMember) { EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32 %3 = OpTypeStruct %4 %4 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%5 = OpTypeInt 32 0 -%6 = OpConstant %5 1 -%7 = OpTypePointer Function %4 -%9 = OpConstant %4 4 +%5 = OpConstantNull %3 +%6 = OpTypeInt 32 0 +%7 = OpConstant %6 1 +%8 = OpTypePointer Function %4 +%10 = OpConstant %4 4 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%8 = OpAccessChain %7 %1 %6 -OpStore %8 %9 + R"(%9 = OpAccessChain %8 %1 %7 +OpStore %9 %10 )"); } diff --git a/src/tint/writer/spirv/builder_binary_expression_test.cc b/src/tint/writer/spirv/builder_binary_expression_test.cc index 922473eb43..9c4ba0817c 100644 --- a/src/tint/writer/spirv/builder_binary_expression_test.cc +++ b/src/tint/writer/spirv/builder_binary_expression_test.cc @@ -703,7 +703,6 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector_F16) { TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F32) { auto* var = Var("mat", ty.mat3x3()); - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), Expr(1_f)); WrapInFunction(var, expr); @@ -711,120 +710,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F32) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); - - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), - R"(%5 = OpTypeFloat 32 -%4 = OpTypeVector %5 3 -%3 = OpTypeMatrix %4 3 -%2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%7 = OpConstant %5 1 -)"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%8 = OpMatrixTimesScalar %3 %6 %7 -)"); -} - -TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F16) { - Enable(ast::Extension::kF16); - - auto* var = Var("mat", ty.mat3x3()); - - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), Expr(1_h)); - - WrapInFunction(var, expr); - - spirv::Builder& b = Build(); - - b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); - - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), - R"(%5 = OpTypeFloat 16 -%4 = OpTypeVector %5 3 -%3 = OpTypeMatrix %4 3 -%2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%7 = OpConstant %5 0x1p+0 -)"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%8 = OpMatrixTimesScalar %3 %6 %7 -)"); -} - -TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F32) { - auto* var = Var("mat", ty.mat3x3()); - - auto* expr = create(ast::BinaryOp::kMultiply, Expr(1_f), Expr("mat")); - - WrapInFunction(var, expr); - - spirv::Builder& b = Build(); - - b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); - - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), - R"(%5 = OpTypeFloat 32 -%4 = OpTypeVector %5 3 -%3 = OpTypeMatrix %4 3 -%2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%6 = OpConstant %5 1 -)"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%7 = OpLoad %3 %1 -%8 = OpMatrixTimesScalar %3 %7 %6 -)"); -} - -TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F16) { - Enable(ast::Extension::kF16); - - auto* var = Var("mat", ty.mat3x3()); - - auto* expr = create(ast::BinaryOp::kMultiply, Expr(1_h), Expr("mat")); - - WrapInFunction(var, expr); - - spirv::Builder& b = Build(); - - b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); - - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), - R"(%5 = OpTypeFloat 16 -%4 = OpTypeVector %5 3 -%3 = OpTypeMatrix %4 3 -%2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%6 = OpConstant %5 0x1p+0 -)"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%7 = OpLoad %3 %1 -%8 = OpMatrixTimesScalar %3 %7 %6 -)"); -} - -TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F32) { - auto* var = Var("mat", ty.mat3x3()); - auto* rhs = vec3(1_f, 1_f, 1_f); - - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), rhs); - - WrapInFunction(var, expr); - - spirv::Builder& b = Build(); - - b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), @@ -832,13 +718,122 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F32) { %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%7 = OpConstant %5 1 -%8 = OpConstantComposite %4 %7 %7 %7 +%6 = OpConstantNull %3 +%8 = OpConstant %5 1 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%9 = OpMatrixTimesVector %4 %6 %8 + R"(%7 = OpLoad %3 %1 +%9 = OpMatrixTimesScalar %3 %7 %8 +)"); +} + +TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F16) { + Enable(ast::Extension::kF16); + + auto* var = Var("mat", ty.mat3x3()); + auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), Expr(1_h)); + + WrapInFunction(var, expr); + + spirv::Builder& b = Build(); + + b.push_function(Function{}); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); + + EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), + R"(%5 = OpTypeFloat 16 +%4 = OpTypeVector %5 3 +%3 = OpTypeMatrix %4 3 +%2 = OpTypePointer Function %3 +%6 = OpConstantNull %3 +%8 = OpConstant %5 0x1p+0 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%7 = OpLoad %3 %1 +%9 = OpMatrixTimesScalar %3 %7 %8 +)"); +} + +TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F32) { + auto* var = Var("mat", ty.mat3x3()); + auto* expr = create(ast::BinaryOp::kMultiply, Expr(1_f), Expr("mat")); + + WrapInFunction(var, expr); + + spirv::Builder& b = Build(); + + b.push_function(Function{}); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); + + EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), + R"(%5 = OpTypeFloat 32 +%4 = OpTypeVector %5 3 +%3 = OpTypeMatrix %4 3 +%2 = OpTypePointer Function %3 +%6 = OpConstantNull %3 +%7 = OpConstant %5 1 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%8 = OpLoad %3 %1 +%9 = OpMatrixTimesScalar %3 %8 %7 +)"); +} + +TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F16) { + Enable(ast::Extension::kF16); + + auto* var = Var("mat", ty.mat3x3()); + auto* expr = create(ast::BinaryOp::kMultiply, Expr(1_h), Expr("mat")); + + WrapInFunction(var, expr); + + spirv::Builder& b = Build(); + + b.push_function(Function{}); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); + + EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), + R"(%5 = OpTypeFloat 16 +%4 = OpTypeVector %5 3 +%3 = OpTypeMatrix %4 3 +%2 = OpTypePointer Function %3 +%6 = OpConstantNull %3 +%7 = OpConstant %5 0x1p+0 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%8 = OpLoad %3 %1 +%9 = OpMatrixTimesScalar %3 %8 %7 +)"); +} + +TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F32) { + auto* var = Var("mat", ty.mat3x3()); + auto* rhs = vec3(1_f, 1_f, 1_f); + auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), rhs); + + WrapInFunction(var, expr); + + spirv::Builder& b = Build(); + + b.push_function(Function{}); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); + + EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), + R"(%5 = OpTypeFloat 32 +%4 = OpTypeVector %5 3 +%3 = OpTypeMatrix %4 3 +%2 = OpTypePointer Function %3 +%6 = OpConstantNull %3 +%8 = OpConstant %5 1 +%9 = OpConstantComposite %4 %8 %8 %8 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%7 = OpLoad %3 %1 +%10 = OpMatrixTimesVector %4 %7 %9 )"); } @@ -847,7 +842,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F16) { auto* var = Var("mat", ty.mat3x3()); auto* rhs = vec3(1_h, 1_h, 1_h); - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), rhs); WrapInFunction(var, expr); @@ -855,28 +849,27 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F16) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); - EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 16 %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%7 = OpConstant %5 0x1p+0 -%8 = OpConstantComposite %4 %7 %7 %7 +%6 = OpConstantNull %3 +%8 = OpConstant %5 0x1p+0 +%9 = OpConstantComposite %4 %8 %8 %8 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%9 = OpMatrixTimesVector %4 %6 %8 + R"(%7 = OpLoad %3 %1 +%10 = OpMatrixTimesVector %4 %7 %9 )"); } TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F32) { auto* var = Var("mat", ty.mat3x3()); auto* lhs = vec3(1_f, 1_f, 1_f); - auto* expr = create(ast::BinaryOp::kMultiply, lhs, Expr("mat")); WrapInFunction(var, expr); @@ -884,21 +877,21 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F32) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); - EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32 %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%6 = OpConstant %5 1 -%7 = OpConstantComposite %4 %6 %6 %6 +%6 = OpConstantNull %3 +%7 = OpConstant %5 1 +%8 = OpConstantComposite %4 %7 %7 %7 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%8 = OpLoad %3 %1 -%9 = OpVectorTimesMatrix %4 %7 %8 + R"(%9 = OpLoad %3 %1 +%10 = OpVectorTimesMatrix %4 %8 %9 )"); } @@ -915,27 +908,26 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F16) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); - EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); + EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 16 %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function -%6 = OpConstant %5 0x1p+0 -%7 = OpConstantComposite %4 %6 %6 %6 +%6 = OpConstantNull %3 +%7 = OpConstant %5 0x1p+0 +%8 = OpConstantComposite %4 %7 %7 %7 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%8 = OpLoad %3 %1 -%9 = OpVectorTimesMatrix %4 %7 %8 + R"(%9 = OpLoad %3 %1 +%10 = OpVectorTimesMatrix %4 %8 %9 )"); } TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F32) { auto* var = Var("mat", ty.mat3x3()); - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), Expr("mat")); WrapInFunction(var, expr); @@ -943,20 +935,20 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F32) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); + EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32 %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function +%6 = OpConstantNull %3 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%7 = OpLoad %3 %1 -%8 = OpMatrixTimesMatrix %3 %6 %7 + R"(%7 = OpLoad %3 %1 +%8 = OpLoad %3 %1 +%9 = OpMatrixTimesMatrix %3 %7 %8 )"); } @@ -964,7 +956,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F16) { Enable(ast::Extension::kF16); auto* var = Var("mat", ty.mat3x3()); - auto* expr = create(ast::BinaryOp::kMultiply, Expr("mat"), Expr("mat")); WrapInFunction(var, expr); @@ -972,28 +963,26 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F16) { spirv::Builder& b = Build(); b.push_function(Function{}); - ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); + ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error(); - EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error(); + EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 16 %4 = OpTypeVector %5 3 %3 = OpTypeMatrix %4 3 %2 = OpTypePointer Function %3 -%1 = OpVariable %2 Function +%6 = OpConstantNull %3 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(%6 = OpLoad %3 %1 -%7 = OpLoad %3 %1 -%8 = OpMatrixTimesMatrix %3 %6 %7 + R"(%7 = OpLoad %3 %1 +%8 = OpLoad %3 %1 +%9 = OpMatrixTimesMatrix %3 %7 %8 )"); } TEST_F(BuilderTest, Binary_LogicalAnd) { auto* lhs = create(ast::BinaryOp::kEqual, Expr(1_i), Expr(2_i)); - auto* rhs = create(ast::BinaryOp::kEqual, Expr(3_i), Expr(4_i)); - auto* expr = create(ast::BinaryOp::kLogicalAnd, lhs, rhs); WrapInFunction(expr); @@ -1028,7 +1017,6 @@ OpBranch %7 TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) { auto* a_var = GlobalVar("a", ty.bool_(), ast::StorageClass::kPrivate, Expr(true)); auto* b_var = GlobalVar("b", ty.bool_(), ast::StorageClass::kPrivate, Expr(false)); - auto* expr = create(ast::BinaryOp::kLogicalAnd, Expr("a"), Expr("b")); WrapInFunction(expr); diff --git a/src/tint/writer/spirv/builder_builtin_test.cc b/src/tint/writer/spirv/builder_builtin_test.cc index f4b6096a69..5dc2401adc 100644 --- a/src/tint/writer/spirv/builder_builtin_test.cc +++ b/src/tint/writer/spirv/builder_builtin_test.cc @@ -43,8 +43,8 @@ TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) { auto* s = ty.sampler(ast::SamplerKind::kComparisonSampler); auto* t = ty.depth_texture(ast::TextureDimension::k2d); - auto* tex = GlobalVar("texture", t, Binding(0), Group(0)); - auto* sampler = GlobalVar("sampler", s, Binding(1), Group(0)); + auto* tex = GlobalVar("texture", t, Binding(0_a), Group(0)); + auto* sampler = GlobalVar("sampler", s, Binding(1_a), Group(0)); auto* expr1 = Call("textureSampleCompare", "texture", "sampler", vec2(1_f, 2_f), 2_f); auto* expr2 = Call("textureSampleCompare", "texture", "sampler", vec2(1_f, 2_f), 2_f); @@ -277,7 +277,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength) { auto* s = Structure("my_struct", utils::Vector{ Member("a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* expr = Call("arrayLength", AddressOf(MemberAccessor("b", "a"))); Func("a_func", utils::Empty, ty.void_(), @@ -320,7 +321,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_OtherMembersInStruct) { Member("z", ty.f32()), Member(4, "a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* expr = Call("arrayLength", AddressOf(MemberAccessor("b", "a"))); Func("a_func", utils::Empty, ty.void_(), @@ -362,7 +364,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets) { auto* s = Structure("my_struct", utils::Vector{ Member("a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* p = Let("p", AddressOf("b")); auto* p2 = Let("p2", AddressOf(MemberAccessor(Deref(p), "a"))); @@ -420,7 +423,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets_WithPtrNoise) { auto* s = Structure("my_struct", utils::Vector{ Member("a", ty.array(4)), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1), Group(2)); + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(1_a), + Group(2)); auto* p = Let("p", AddressOf(Deref(AddressOf("b")))); auto* p2 = Let("p2", AddressOf(Deref(p))); @@ -3219,7 +3223,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) { Member("u", ty.atomic()), Member("i", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), @@ -3282,7 +3286,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicStore) { Member("u", ty.atomic()), Member("i", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), @@ -3353,7 +3357,7 @@ TEST_P(Builtin_Builder_AtomicRMW_i32, Test) { auto* s = Structure("S", utils::Vector{ Member("v", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), @@ -3425,7 +3429,7 @@ TEST_P(Builtin_Builder_AtomicRMW_u32, Test) { auto* s = Structure("S", utils::Vector{ Member("v", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), @@ -3499,7 +3503,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicExchange) { Member("u", ty.atomic()), Member("i", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), @@ -3574,7 +3578,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) { Member("u", ty.atomic()), Member("i", ty.atomic()), }); - GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1), + GlobalVar("b", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(1_a), Group(2)); Func("a_func", utils::Empty, ty.void_(), diff --git a/src/tint/writer/spirv/builder_function_test.cc b/src/tint/writer/spirv/builder_function_test.cc index d1c0e9f76f..8a0bebfaa4 100644 --- a/src/tint/writer/spirv/builder_function_test.cc +++ b/src/tint/writer/spirv/builder_function_test.cc @@ -198,7 +198,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { auto* s = Structure("Data", utils::Vector{Member("d", ty.f32())}); - GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(0)); { diff --git a/src/tint/writer/spirv/builder_global_variable_test.cc b/src/tint/writer/spirv/builder_global_variable_test.cc index bfecdf14da..996f0b779b 100644 --- a/src/tint/writer/spirv/builder_global_variable_test.cc +++ b/src/tint/writer/spirv/builder_global_variable_test.cc @@ -233,7 +233,7 @@ TEST_F(BuilderTest, GlobalConst_Nested_Vec_Constructor) { } TEST_F(BuilderTest, GlobalVar_WithBindingAndGroup) { - auto* v = GlobalVar("var", ty.sampler(ast::SamplerKind::kSampler), Binding(2), Group(3)); + auto* v = GlobalVar("var", ty.sampler(ast::SamplerKind::kSampler), Binding(2_a), Group(3)); spirv::Builder& b = Build(); @@ -447,7 +447,8 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) { Member("b", ty.i32()), }); - GlobalVar("b", ty.Of(A), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("b", ty.Of(A), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); spirv::Builder& b = SanitizeAndBuild(); @@ -484,7 +485,8 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) { auto* A = Structure("A", utils::Vector{Member("a", ty.i32())}); auto* B = Alias("B", ty.Of(A)); - GlobalVar("b", ty.Of(B), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("b", ty.Of(B), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); spirv::Builder& b = SanitizeAndBuild(); @@ -519,7 +521,8 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) { auto* A = Structure("A", utils::Vector{Member("a", ty.i32())}); auto* B = Alias("B", ty.Of(A)); - GlobalVar("b", ty.Of(B), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), Group(0)); + GlobalVar("b", ty.Of(B), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), + Group(0)); spirv::Builder& b = SanitizeAndBuild(); @@ -553,9 +556,10 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) { // var c : A auto* A = Structure("A", utils::Vector{Member("a", ty.i32())}); - GlobalVar("b", ty.Of(A), ast::StorageClass::kStorage, ast::Access::kRead, Group(0), Binding(0)); + GlobalVar("b", ty.Of(A), ast::StorageClass::kStorage, ast::Access::kRead, Group(0), + Binding(0_a)); GlobalVar("c", ty.Of(A), ast::StorageClass::kStorage, ast::Access::kReadWrite, Group(1), - Binding(0)); + Binding(0_a)); spirv::Builder& b = SanitizeAndBuild(); @@ -592,7 +596,7 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { auto* type = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); - auto* var_a = GlobalVar("a", type, Binding(0), Group(0)); + auto* var_a = GlobalVar("a", type, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -619,11 +623,11 @@ TEST_F(BuilderTest, DISABLED_GlobalVar_TextureStorageWithDifferentAccess) { auto* type_a = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kReadWrite); - auto* var_a = GlobalVar("a", type_a, Binding(0), Group(0)); + auto* var_a = GlobalVar("a", type_a, Binding(0_a), Group(0)); auto* type_b = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); - auto* var_b = GlobalVar("b", type_b, Binding(1), Group(0)); + auto* var_b = GlobalVar("b", type_b, Binding(1_a), Group(0)); spirv::Builder& b = Build(); diff --git a/src/tint/writer/spirv/builder_type_test.cc b/src/tint/writer/spirv/builder_type_test.cc index 3b8e0b170d..51a9cd5a3a 100644 --- a/src/tint/writer/spirv/builder_type_test.cc +++ b/src/tint/writer/spirv/builder_type_test.cc @@ -28,7 +28,7 @@ using BuilderTest_Type = TestHelper; TEST_F(BuilderTest_Type, GenerateRuntimeArray) { auto* ary = ty.array(ty.i32()); auto* str = Structure("S", utils::Vector{Member("x", ary)}); - GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -45,7 +45,7 @@ TEST_F(BuilderTest_Type, GenerateRuntimeArray) { TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) { auto* ary = ty.array(ty.i32()); auto* str = Structure("S", utils::Vector{Member("x", ary)}); - GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), + GlobalVar("a", ty.Of(str), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -836,7 +836,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { auto* s = ty.storage_texture(ast::TextureDimension::k1d, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -851,7 +851,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -866,7 +866,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { auto* s = ty.storage_texture(ast::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -881,7 +881,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { auto* s = ty.storage_texture(ast::TextureDimension::k3d, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -896,7 +896,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32floa auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -911,7 +911,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Sint, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); @@ -926,7 +926,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); - GlobalVar("test_var", s, Binding(0), Group(0)); + GlobalVar("test_var", s, Binding(0_a), Group(0)); spirv::Builder& b = Build(); diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 9f9c4c6809..7b619cd7b8 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -740,7 +740,11 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out, return true; }, [&](const ast::BindingAttribute* binding) { - out << "binding(" << binding->value << ")"; + out << "binding("; + if (!EmitExpression(out, binding->value)) { + return false; + } + out << ")"; return true; }, [&](const ast::GroupAttribute* group) { diff --git a/src/tint/writer/wgsl/generator_impl_function_test.cc b/src/tint/writer/wgsl/generator_impl_function_test.cc index 09e1e8b369..dc189721ad 100644 --- a/src/tint/writer/wgsl/generator_impl_function_test.cc +++ b/src/tint/writer/wgsl/generator_impl_function_test.cc @@ -179,7 +179,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_Multiple_EntryPoint_With_Same_Module Member("d", ty.f32()), }); - GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0), + GlobalVar("data", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, Binding(0_a), Group(0)); { diff --git a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc index fc424f6051..6c87cab7e9 100644 --- a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc @@ -105,7 +105,7 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) { } TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { - GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(0)); + GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0), Binding(0_a)); GeneratorImpl& gen = Build(); @@ -117,7 +117,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) { auto* st = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); - GlobalVar("t", st, Group(0), Binding(0)); + GlobalVar("t", st, Group(0), Binding(0_a)); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/wgsl/generator_impl_type_test.cc b/src/tint/writer/wgsl/generator_impl_type_test.cc index cdba585176..66538e941a 100644 --- a/src/tint/writer/wgsl/generator_impl_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_type_test.cc @@ -462,7 +462,7 @@ TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); auto* t = ty.storage_texture(param.dim, param.fmt, param.access); - GlobalVar("g", t, Binding(1), Group(2)); + GlobalVar("g", t, Binding(1_a), Group(2)); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/wgsl/generator_impl_variable_test.cc b/src/tint/writer/wgsl/generator_impl_variable_test.cc index 521d3b6034..66b2644037 100644 --- a/src/tint/writer/wgsl/generator_impl_variable_test.cc +++ b/src/tint/writer/wgsl/generator_impl_variable_test.cc @@ -43,8 +43,8 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) { TEST_F(WgslGeneratorImplTest, EmitVariable_Access_Read) { auto* s = Structure("S", utils::Vector{Member("a", ty.i32())}); - auto* v = GlobalVar("a", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, Binding(0), - Group(0)); + auto* v = GlobalVar("a", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kRead, + Binding(0_a), Group(0)); GeneratorImpl& gen = Build(); @@ -56,7 +56,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_Read) { TEST_F(WgslGeneratorImplTest, EmitVariable_Access_ReadWrite) { auto* s = Structure("S", utils::Vector{Member("a", ty.i32())}); auto* v = GlobalVar("a", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite, - Binding(0), Group(0)); + Binding(0_a), Group(0)); GeneratorImpl& gen = Build(); @@ -66,7 +66,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Access_ReadWrite) { } TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) { - auto* v = GlobalVar("a", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2)); + auto* v = GlobalVar("a", ty.sampler(ast::SamplerKind::kSampler), Group(1), Binding(2_a)); GeneratorImpl& gen = Build();