From b6fdcc54df6e012578e69550788e2b4b2b611c32 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 16 Jun 2021 17:42:53 +0000 Subject: [PATCH] transform: remove VarForDynamicIndex transform. Dynamic indexes are limited to references to matrices and arrays https://github.com/gpuweb/gpuweb/pull/1801 Bug: tint:867 Change-Id: I114daa053c8a4ffd23ce784ac4538567a551cc21 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54701 Kokoro: Kokoro Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton Auto-Submit: Sarah Mashayekhi --- src/BUILD.gn | 2 - src/CMakeLists.txt | 3 - src/transform/spirv.cc | 2 - src/transform/var_for_dynamic_index.cc | 80 ------------ src/transform/var_for_dynamic_index.h | 48 ------- src/transform/var_for_dynamic_index_test.cc | 121 ------------------ src/writer/spirv/builder.cc | 11 -- .../spirv/builder_accessor_expression_test.cc | 54 ++++---- test/BUILD.gn | 1 - test/bug/tint/824.wgsl | 6 +- test/bug/tint/824.wgsl.expected.hlsl | 4 +- test/bug/tint/824.wgsl.expected.msl | 4 +- test/bug/tint/824.wgsl.expected.spvasm | 16 +-- test/bug/tint/824.wgsl.expected.wgsl | 4 +- test/bug/tint/825.wgsl | 4 +- test/bug/tint/825.wgsl.expected.hlsl | 2 +- test/bug/tint/825.wgsl.expected.msl | 2 +- test/bug/tint/825.wgsl.expected.spvasm | 8 +- test/bug/tint/825.wgsl.expected.wgsl | 2 +- test/samples/triangle.wgsl | 9 +- test/samples/triangle.wgsl.expected.hlsl | 10 +- test/samples/triangle.wgsl.expected.msl | 8 +- test/samples/triangle.wgsl.expected.spvasm | 53 ++++---- test/samples/triangle.wgsl.expected.wgsl | 3 +- 24 files changed, 92 insertions(+), 365 deletions(-) delete mode 100644 src/transform/var_for_dynamic_index.cc delete mode 100644 src/transform/var_for_dynamic_index.h delete mode 100644 src/transform/var_for_dynamic_index_test.cc diff --git a/src/BUILD.gn b/src/BUILD.gn index 46d577748b..6200be87a6 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -571,8 +571,6 @@ libtint_source_set("libtint_core_all_src") { "transform/single_entry_point.h", "transform/transform.cc", "transform/transform.h", - "transform/var_for_dynamic_index.cc", - "transform/var_for_dynamic_index.h", "transform/vertex_pulling.cc", "transform/vertex_pulling.h", "transform/wrap_arrays_in_structs.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b9dd879f7..bde7627fc3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -296,8 +296,6 @@ set(TINT_LIB_SRCS transform/single_entry_point.h transform/transform.cc transform/transform.h - transform/var_for_dynamic_index.cc - transform/var_for_dynamic_index.h transform/vertex_pulling.cc transform/vertex_pulling.h transform/wrap_arrays_in_structs.cc @@ -859,7 +857,6 @@ if(${TINT_BUILD_TESTS}) transform/simplify_test.cc transform/single_entry_point_test.cc transform/test_helper.h - transform/var_for_dynamic_index_test.cc transform/vertex_pulling_test.cc transform/wrap_arrays_in_structs_test.cc ) diff --git a/src/transform/spirv.cc b/src/transform/spirv.cc index 47ad94fe05..bf261bbb39 100644 --- a/src/transform/spirv.cc +++ b/src/transform/spirv.cc @@ -30,7 +30,6 @@ #include "src/transform/inline_pointer_lets.h" #include "src/transform/manager.h" #include "src/transform/simplify.h" -#include "src/transform/var_for_dynamic_index.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::Spirv::Config); @@ -45,7 +44,6 @@ Output Spirv::Run(const Program* in, const DataMap& data) { manager.Add(); // Required for arrayLength() manager.Add(); // Required for arrayLength() manager.Add(); - manager.Add(); auto transformedInput = manager.Run(in, data); auto* cfg = data.Get(); diff --git a/src/transform/var_for_dynamic_index.cc b/src/transform/var_for_dynamic_index.cc deleted file mode 100644 index ca246458d1..0000000000 --- a/src/transform/var_for_dynamic_index.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/transform/var_for_dynamic_index.h" - -#include - -#include "src/program_builder.h" -#include "src/sem/array.h" -#include "src/sem/block_statement.h" -#include "src/sem/expression.h" -#include "src/sem/statement.h" - -namespace tint { -namespace transform { - -VarForDynamicIndex::VarForDynamicIndex() = default; - -VarForDynamicIndex::~VarForDynamicIndex() = default; - -Output VarForDynamicIndex::Run(const Program* in, const DataMap&) { - ProgramBuilder out; - CloneContext ctx(&out, in); - - for (auto* node : in->ASTNodes().Objects()) { - if (auto* access_expr = node->As()) { - // Found an array accessor expression - auto* index_expr = access_expr->idx_expr(); - auto* indexed_expr = access_expr->array(); - - if (index_expr->Is()) { - // Index expression is a literal value. As this isn't a dynamic index, - // we can ignore this. - continue; - } - - auto* indexed = ctx.src->Sem().Get(indexed_expr); - if (!indexed->Type()->IsAnyOf()) { - // This transform currently only cares about array and matrices. - continue; - } - - auto* stmt = indexed->Stmt(); // Statement that owns the expression - auto* block = stmt->Block(); // Block that owns the statement - - // Construct a `var` declaration to hold the value in memory. - auto* ty = CreateASTTypeFor(&ctx, indexed->Type()); - auto var_name = ctx.dst->Symbols().New("var_for_index"); - auto* var_decl = ctx.dst->Decl(ctx.dst->Var( - var_name, ty, ast::StorageClass::kNone, ctx.Clone(indexed_expr))); - - // Insert the `var` declaration before the statement that performs the - // indexing. Note that for indexing chains, AST node ordering guarantees - // that the inner-most index variable will be placed first in the block. - ctx.InsertBefore(block->Declaration()->statements(), stmt->Declaration(), - var_decl); - - // Replace the original index expression with the new `var`. - ctx.Replace(indexed_expr, ctx.dst->Expr(var_name)); - } - } - - ctx.Clone(); - - return Output(Program(std::move(out))); -} - -} // namespace transform -} // namespace tint diff --git a/src/transform/var_for_dynamic_index.h b/src/transform/var_for_dynamic_index.h deleted file mode 100644 index 86fa30a9bd..0000000000 --- a/src/transform/var_for_dynamic_index.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_ -#define SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_ - -#include -#include - -#include "src/transform/transform.h" - -namespace tint { -namespace transform { - -/// A transform that extracts array and matrix values that are dynamically -/// indexed to a temporary `var` local before performing the index. This -/// transform is used by the SPIR-V writer as there is no SPIR-V instruction -/// that can dynamically index a non-pointer composite. -class VarForDynamicIndex : public Transform { - public: - /// Constructor - VarForDynamicIndex(); - - /// Destructor - ~VarForDynamicIndex() override; - - /// Runs the transform on `program`, returning the transformation result. - /// @param program the source program to transform - /// @param data optional extra transform-specific input data - /// @returns the transformation result - Output Run(const Program* program, const DataMap& data = {}) override; -}; - -} // namespace transform -} // namespace tint - -#endif // SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_ diff --git a/src/transform/var_for_dynamic_index_test.cc b/src/transform/var_for_dynamic_index_test.cc deleted file mode 100644 index 29dd84e610..0000000000 --- a/src/transform/var_for_dynamic_index_test.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/transform/var_for_dynamic_index.h" - -#include "src/transform/test_helper.h" - -namespace tint { -namespace transform { -namespace { - -using VarForDynamicIndexTest = TransformTest; - -TEST_F(VarForDynamicIndexTest, EmptyModule) { - auto* src = ""; - auto* expect = ""; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_F(VarForDynamicIndexTest, ArrayIndexDynamic) { - auto* src = R"( -fn f() { - var i : i32; - let p : array = array(1, 2, 3, 4); - let x : i32 = p[i]; -} -)"; - - auto* expect = R"( -fn f() { - var i : i32; - let p : array = array(1, 2, 3, 4); - var var_for_index : array = p; - let x : i32 = var_for_index[i]; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_F(VarForDynamicIndexTest, ArrayIndexDynamicChain) { - auto* src = R"( -fn f() { - var i : i32; - var j : i32; - let p : array, 2> = array, 2>(array(1, 2), array(3, 4)); - let x : i32 = p[i][j]; -} -)"; - - // TODO(bclayton): Optimize this case: - // This output is not as efficient as it could be. - // We only actually need to hoist the inner-most array to a `var` - // (`var_for_index`), as later indexing operations will be working with - // references, not values. - - auto* expect = R"( -fn f() { - var i : i32; - var j : i32; - let p : array, 2> = array, 2>(array(1, 2), array(3, 4)); - var var_for_index : array, 2> = p; - var var_for_index_1 : array = var_for_index[i]; - let x : i32 = var_for_index_1[j]; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_F(VarForDynamicIndexTest, ArrayIndexLiteral) { - auto* src = R"( -fn f() { - let p : array = array(1, 2, 3, 4); - let x : i32 = p[1]; -} -)"; - - auto* expect = src; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_F(VarForDynamicIndexTest, ArrayIndexLiteralChain) { - auto* src = R"( -fn f() { - let p : array, 2> = array, 2>(array(1, 2), array(3, 4)); - let x : i32 = p[0][1]; -} -)"; - - auto* expect = src; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -} // namespace -} // namespace transform -} // namespace tint diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 0a63efd244..1ed2630c6f 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -1077,17 +1077,6 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) { } info.source_type = TypeOf(source); - if (auto* access = accessors[0]->As()) { - auto* array = TypeOf(access->array())->As(); - bool literal_index = - array && access->idx_expr()->Is(); - if (array && !literal_index) { - TINT_ICE(builder_.Diagnostics()) - << "Dynamic index on array value should have been promoted to " - "storage with the VarForDynamicIndex transform"; - } - } - for (auto* accessor : accessors) { if (auto* array = accessor->As()) { if (!GenerateArrayAccessor(array, &info)) { diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index b77bae2663..266ed49bf1 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -937,12 +937,12 @@ TEST_F(BuilderTest, ArrayAccessor_Array_Literal) { } TEST_F(BuilderTest, ArrayAccessor_Array_Dynamic) { - // let a : array; + // var a : array; // idx : i32 // a[idx] - auto* var = Const("a", ty.array(), - Construct(ty.array(), 0.0f, 0.5f, 1.0f)); + auto* var = Var("a", ty.array(), + Construct(ty.array(), 0.0f, 0.5f, 1.0f)); auto* idx = Var("idx", ty.i32()); auto* expr = IndexAccessor("a", idx); @@ -963,21 +963,21 @@ TEST_F(BuilderTest, ArrayAccessor_Array_Dynamic) { %10 = OpConstant %6 0.5 %11 = OpConstant %6 1 %12 = OpConstantComposite %5 %9 %10 %11 -%15 = OpTypeInt 32 1 -%14 = OpTypePointer Function %15 -%16 = OpConstantNull %15 -%18 = OpTypePointer Function %5 -%19 = OpConstantNull %5 +%14 = OpTypePointer Function %5 +%15 = OpConstantNull %5 +%18 = OpTypeInt 32 1 +%17 = OpTypePointer Function %18 +%19 = OpConstantNull %18 %21 = OpTypePointer Function %6 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), - R"(%13 = OpVariable %14 Function %16 -%17 = OpVariable %18 Function %19 + R"(%13 = OpVariable %14 Function %15 +%16 = OpVariable %17 Function %19 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(OpStore %17 %12 -%20 = OpLoad %15 %13 -%22 = OpAccessChain %21 %17 %20 + R"(OpStore %13 %12 +%20 = OpLoad %18 %16 +%22 = OpAccessChain %21 %13 %20 %23 = OpLoad %6 %22 )"); @@ -985,14 +985,14 @@ TEST_F(BuilderTest, ArrayAccessor_Array_Dynamic) { } TEST_F(BuilderTest, ArrayAccessor_Matrix_Dynamic) { - // let a : mat2x2(vec2(1., 2.), vec2(3., 4.)); + // var a : mat2x2(vec2(1., 2.), vec2(3., 4.)); // idx : i32 // a[idx] auto* var = - Const("a", ty.mat2x2(), - Construct(ty.mat2x2(), Construct(ty.vec2(), 1.f, 2.f), - Construct(ty.vec2(), 3.f, 4.f))); + Var("a", ty.mat2x2(), + Construct(ty.mat2x2(), Construct(ty.vec2(), 1.f, 2.f), + Construct(ty.vec2(), 3.f, 4.f))); auto* idx = Var("idx", ty.i32()); auto* expr = IndexAccessor("a", idx); @@ -1015,21 +1015,21 @@ TEST_F(BuilderTest, ArrayAccessor_Matrix_Dynamic) { %12 = OpConstant %7 4 %13 = OpConstantComposite %6 %11 %12 %14 = OpConstantComposite %5 %10 %13 -%17 = OpTypeInt 32 1 -%16 = OpTypePointer Function %17 -%18 = OpConstantNull %17 -%20 = OpTypePointer Function %5 -%21 = OpConstantNull %5 +%16 = OpTypePointer Function %5 +%17 = OpConstantNull %5 +%20 = OpTypeInt 32 1 +%19 = OpTypePointer Function %20 +%21 = OpConstantNull %20 %23 = OpTypePointer Function %6 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), - R"(%15 = OpVariable %16 Function %18 -%19 = OpVariable %20 Function %21 + R"(%15 = OpVariable %16 Function %17 +%18 = OpVariable %19 Function %21 )"); EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), - R"(OpStore %19 %14 -%22 = OpLoad %17 %15 -%24 = OpAccessChain %23 %19 %22 + R"(OpStore %15 %14 +%22 = OpLoad %20 %18 +%24 = OpAccessChain %23 %15 %22 %25 = OpLoad %6 %24 )"); diff --git a/test/BUILD.gn b/test/BUILD.gn index afbf7aa324..8ec1c358f6 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -286,7 +286,6 @@ tint_unittests_source_set("tint_unittests_core_src") { "../src/transform/single_entry_point_test.cc", "../src/transform/test_helper.h", "../src/transform/transform_test.cc", - "../src/transform/var_for_dynamic_index_test.cc", "../src/transform/vertex_pulling_test.cc", "../src/transform/wrap_arrays_in_structs_test.cc", "../src/utils/enum_set_test.cc", diff --git a/test/bug/tint/824.wgsl b/test/bug/tint/824.wgsl index ed907e3702..302e7bb27a 100644 --- a/test/bug/tint/824.wgsl +++ b/test/bug/tint/824.wgsl @@ -6,7 +6,7 @@ struct Output { [[builtin(vertex_index)]] VertexIndex : u32, [[builtin(instance_index)]] InstanceIndex : u32) -> Output { // TODO: remove workaround for Tint unary array access broke - let zv : array, 4> = array, 4>( + var zv : array, 4> = array, 4>( vec2(0.2, 0.2), vec2(0.3, 0.3), vec2(-0.1, -0.1), @@ -14,7 +14,7 @@ struct Output { let z : f32 = zv[InstanceIndex].x; var output : Output; output.Position = vec4(0.5, 0.5, z, 1.0); - let colors : array, 4> = array, 4>( + var colors : array, 4> = array, 4>( vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), @@ -22,4 +22,4 @@ struct Output { ); output.color = colors[InstanceIndex]; return output; -} +} \ No newline at end of file diff --git a/test/bug/tint/824.wgsl.expected.hlsl b/test/bug/tint/824.wgsl.expected.hlsl index 9351b487b9..5021084b26 100644 --- a/test/bug/tint/824.wgsl.expected.hlsl +++ b/test/bug/tint/824.wgsl.expected.hlsl @@ -20,11 +20,11 @@ struct tint_array_wrapper_1 { tint_symbol_2 main(tint_symbol_1 tint_symbol) { const uint VertexIndex = tint_symbol.VertexIndex; const uint InstanceIndex = tint_symbol.InstanceIndex; - const tint_array_wrapper zv = {{float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}}; + tint_array_wrapper zv = {{float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}}; const float z = zv.arr[InstanceIndex].x; Output output = {float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)}; output.Position = float4(0.5f, 0.5f, z, 1.0f); - const tint_array_wrapper_1 colors = {{float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}}; + tint_array_wrapper_1 colors = {{float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}}; output.color = colors.arr[InstanceIndex]; const tint_symbol_2 tint_symbol_3 = {output.color, output.Position}; return tint_symbol_3; diff --git a/test/bug/tint/824.wgsl.expected.msl b/test/bug/tint/824.wgsl.expected.msl index d0b820ed1e..8094607a65 100644 --- a/test/bug/tint/824.wgsl.expected.msl +++ b/test/bug/tint/824.wgsl.expected.msl @@ -17,11 +17,11 @@ struct tint_array_wrapper_1 { }; vertex tint_symbol_2 tint_symbol(uint VertexIndex [[vertex_id]], uint InstanceIndex [[instance_id]]) { - tint_array_wrapper const zv = {.arr={float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}}; + tint_array_wrapper zv = {.arr={float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}}; float const z = zv.arr[InstanceIndex].x; Output output = {}; output.Position = float4(0.5f, 0.5f, z, 1.0f); - tint_array_wrapper_1 const colors = {.arr={float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}}; + tint_array_wrapper_1 colors = {.arr={float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}}; output.color = colors.arr[InstanceIndex]; tint_symbol_2 const tint_symbol_3 = {.color=output.color, .Position=output.Position}; return tint_symbol_3; diff --git a/test/bug/tint/824.wgsl.expected.spvasm b/test/bug/tint/824.wgsl.expected.spvasm index 394df835b2..feb9f7ceaa 100644 --- a/test/bug/tint/824.wgsl.expected.spvasm +++ b/test/bug/tint/824.wgsl.expected.spvasm @@ -17,9 +17,9 @@ OpName %tint_symbol_5 "tint_symbol_5" OpName %tint_symbol_2 "tint_symbol_2" OpName %main "main" - OpName %var_for_index "var_for_index" + OpName %zv "zv" OpName %output "output" - OpName %var_for_index_1 "var_for_index_1" + OpName %colors "colors" OpDecorate %tint_pointsize BuiltIn PointSize OpDecorate %tint_symbol BuiltIn VertexIndex OpDecorate %tint_symbol_1 BuiltIn InstanceIndex @@ -88,21 +88,21 @@ OpFunctionEnd %main = OpFunction %void None %22 %24 = OpLabel -%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %40 + %zv = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %40 %output = OpVariable %_ptr_Function_Output Function %48 -%var_for_index_1 = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %62 + %colors = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %62 OpStore %tint_pointsize %float_1 - OpStore %var_for_index %37 + OpStore %zv %37 %41 = OpLoad %uint %tint_symbol_1 - %44 = OpAccessChain %_ptr_Function_float %var_for_index %41 %uint_0 + %44 = OpAccessChain %_ptr_Function_float %zv %41 %uint_0 %45 = OpLoad %float %44 %50 = OpAccessChain %_ptr_Function_v4float %output %uint_0 %52 = OpCompositeConstruct %v4float %float_0_5 %float_0_5 %45 %float_1 OpStore %50 %52 - OpStore %var_for_index_1 %59 + OpStore %colors %59 %64 = OpAccessChain %_ptr_Function_v4float %output %uint_1 %65 = OpLoad %uint %tint_symbol_1 - %66 = OpAccessChain %_ptr_Function_v4float %var_for_index_1 %65 + %66 = OpAccessChain %_ptr_Function_v4float %colors %65 %67 = OpLoad %v4float %66 OpStore %64 %67 %69 = OpLoad %Output %output diff --git a/test/bug/tint/824.wgsl.expected.wgsl b/test/bug/tint/824.wgsl.expected.wgsl index 6d051de35a..e6f7ee063d 100644 --- a/test/bug/tint/824.wgsl.expected.wgsl +++ b/test/bug/tint/824.wgsl.expected.wgsl @@ -7,11 +7,11 @@ struct Output { [[stage(vertex)]] fn main([[builtin(vertex_index)]] VertexIndex : u32, [[builtin(instance_index)]] InstanceIndex : u32) -> Output { - let zv : array, 4> = array, 4>(vec2(0.200000003, 0.200000003), vec2(0.300000012, 0.300000012), vec2(-0.100000001, -0.100000001), vec2(1.100000024, 1.100000024)); + var zv : array, 4> = array, 4>(vec2(0.200000003, 0.200000003), vec2(0.300000012, 0.300000012), vec2(-0.100000001, -0.100000001), vec2(1.100000024, 1.100000024)); let z : f32 = zv[InstanceIndex].x; var output : Output; output.Position = vec4(0.5, 0.5, z, 1.0); - let colors : array, 4> = array, 4>(vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0)); + var colors : array, 4> = array, 4>(vec4(1.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0)); output.color = colors[InstanceIndex]; return output; } diff --git a/test/bug/tint/825.wgsl b/test/bug/tint/825.wgsl index 92a0b7e0f5..00ada3b3e1 100644 --- a/test/bug/tint/825.wgsl +++ b/test/bug/tint/825.wgsl @@ -1,6 +1,6 @@ fn f() { var i : i32; var j : i32; - let m : mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + var m : mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); let f : f32 = m[i][j]; -} +} \ No newline at end of file diff --git a/test/bug/tint/825.wgsl.expected.hlsl b/test/bug/tint/825.wgsl.expected.hlsl index 709f782863..1e1f290b43 100644 --- a/test/bug/tint/825.wgsl.expected.hlsl +++ b/test/bug/tint/825.wgsl.expected.hlsl @@ -6,6 +6,6 @@ void unused_entry_point() { void f() { int i = 0; int j = 0; - const float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f)); + float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f)); const float f = m[i][j]; } diff --git a/test/bug/tint/825.wgsl.expected.msl b/test/bug/tint/825.wgsl.expected.msl index 5a8c360d6e..58b800ab3d 100644 --- a/test/bug/tint/825.wgsl.expected.msl +++ b/test/bug/tint/825.wgsl.expected.msl @@ -4,7 +4,7 @@ using namespace metal; void f() { int i = 0; int j = 0; - float2x2 const m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f)); + float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f)); float const f = m[i][j]; } diff --git a/test/bug/tint/825.wgsl.expected.spvasm b/test/bug/tint/825.wgsl.expected.spvasm index d7996bf3b1..0b9dbf672a 100644 --- a/test/bug/tint/825.wgsl.expected.spvasm +++ b/test/bug/tint/825.wgsl.expected.spvasm @@ -11,7 +11,7 @@ OpName %f "f" OpName %i "i" OpName %j "j" - OpName %var_for_index "var_for_index" + OpName %m "m" %void = OpTypeVoid %1 = OpTypeFunction %void %int = OpTypeInt 32 1 @@ -38,11 +38,11 @@ %6 = OpLabel %i = OpVariable %_ptr_Function_int Function %10 %j = OpVariable %_ptr_Function_int Function %10 -%var_for_index = OpVariable %_ptr_Function_mat2v2float Function %24 - OpStore %var_for_index %21 + %m = OpVariable %_ptr_Function_mat2v2float Function %24 + OpStore %m %21 %25 = OpLoad %int %i %26 = OpLoad %int %j - %28 = OpAccessChain %_ptr_Function_float %var_for_index %25 %26 + %28 = OpAccessChain %_ptr_Function_float %m %25 %26 %29 = OpLoad %float %28 OpReturn OpFunctionEnd diff --git a/test/bug/tint/825.wgsl.expected.wgsl b/test/bug/tint/825.wgsl.expected.wgsl index 92a0b7e0f5..a945c40442 100644 --- a/test/bug/tint/825.wgsl.expected.wgsl +++ b/test/bug/tint/825.wgsl.expected.wgsl @@ -1,6 +1,6 @@ fn f() { var i : i32; var j : i32; - let m : mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + var m : mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); let f : f32 = m[i][j]; } diff --git a/test/samples/triangle.wgsl b/test/samples/triangle.wgsl index ba3cb52b52..5bbb43d885 100644 --- a/test/samples/triangle.wgsl +++ b/test/samples/triangle.wgsl @@ -13,14 +13,13 @@ // limitations under the License. // Vertex shader -let pos : array, 3> = array, 3>( - vec2(0.0, 0.5), - vec2(-0.5, -0.5), - vec2(0.5, -0.5)); - [[stage(vertex)]] fn vtx_main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + var pos : array, 3> = array, 3>( + vec2(0.0, 0.5), + vec2(-0.5, -0.5), + vec2(0.5, -0.5)); return vec4(pos[VertexIndex], 0.0, 1.0); } diff --git a/test/samples/triangle.wgsl.expected.hlsl b/test/samples/triangle.wgsl.expected.hlsl index 432135c3b5..29fc958f94 100644 --- a/test/samples/triangle.wgsl.expected.hlsl +++ b/test/samples/triangle.wgsl.expected.hlsl @@ -1,18 +1,16 @@ -struct tint_array_wrapper { - float2 arr[3]; -}; - -static const tint_array_wrapper pos = {{float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}}; - struct tint_symbol_1 { uint VertexIndex : SV_VertexID; }; struct tint_symbol_2 { float4 value : SV_Position; }; +struct tint_array_wrapper { + float2 arr[3]; +}; tint_symbol_2 vtx_main(tint_symbol_1 tint_symbol) { const uint VertexIndex = tint_symbol.VertexIndex; + tint_array_wrapper pos = {{float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}}; const tint_symbol_2 tint_symbol_4 = {float4(pos.arr[VertexIndex], 0.0f, 1.0f)}; return tint_symbol_4; } diff --git a/test/samples/triangle.wgsl.expected.msl b/test/samples/triangle.wgsl.expected.msl index 73b13fdc4d..a0657e47a7 100644 --- a/test/samples/triangle.wgsl.expected.msl +++ b/test/samples/triangle.wgsl.expected.msl @@ -1,18 +1,18 @@ #include using namespace metal; -struct tint_array_wrapper { - float2 arr[3]; -}; struct tint_symbol_1 { float4 value [[position]]; }; +struct tint_array_wrapper { + float2 arr[3]; +}; struct tint_symbol_2 { float4 value [[color(0)]]; }; -constant tint_array_wrapper pos = {.arr={float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}}; vertex tint_symbol_1 vtx_main(uint VertexIndex [[vertex_id]]) { + tint_array_wrapper pos = {.arr={float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}}; tint_symbol_1 const tint_symbol_3 = {.value=float4(pos.arr[VertexIndex], 0.0f, 1.0f)}; return tint_symbol_3; } diff --git a/test/samples/triangle.wgsl.expected.spvasm b/test/samples/triangle.wgsl.expected.spvasm index 6cee9e5199..761865033a 100644 --- a/test/samples/triangle.wgsl.expected.spvasm +++ b/test/samples/triangle.wgsl.expected.spvasm @@ -9,65 +9,64 @@ OpEntryPoint Fragment %frag_main "frag_main" %tint_symbol_5 OpExecutionMode %frag_main OriginUpperLeft OpName %tint_pointsize "tint_pointsize" - OpName %pos "pos" OpName %tint_symbol "tint_symbol" OpName %tint_symbol_2 "tint_symbol_2" OpName %tint_symbol_5 "tint_symbol_5" OpName %tint_symbol_3 "tint_symbol_3" OpName %tint_symbol_1 "tint_symbol_1" OpName %vtx_main "vtx_main" - OpName %var_for_index "var_for_index" + OpName %pos "pos" OpName %tint_symbol_6 "tint_symbol_6" OpName %tint_symbol_4 "tint_symbol_4" OpName %frag_main "frag_main" OpDecorate %tint_pointsize BuiltIn PointSize - OpDecorate %_arr_v2float_uint_3 ArrayStride 8 OpDecorate %tint_symbol BuiltIn VertexIndex OpDecorate %tint_symbol_2 BuiltIn Position OpDecorate %tint_symbol_5 Location 0 + OpDecorate %_arr_v2float_uint_3 ArrayStride 8 %float = OpTypeFloat 32 %_ptr_Output_float = OpTypePointer Output %float %4 = OpConstantNull %float %tint_pointsize = OpVariable %_ptr_Output_float Output %4 - %v2float = OpTypeVector %float 2 %uint = OpTypeInt 32 0 - %uint_3 = OpConstant %uint 3 -%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3 - %float_0 = OpConstant %float 0 - %float_0_5 = OpConstant %float 0.5 - %11 = OpConstantComposite %v2float %float_0 %float_0_5 - %float_n0_5 = OpConstant %float -0.5 - %13 = OpConstantComposite %v2float %float_n0_5 %float_n0_5 - %14 = OpConstantComposite %v2float %float_0_5 %float_n0_5 - %pos = OpConstantComposite %_arr_v2float_uint_3 %11 %13 %14 %_ptr_Input_uint = OpTypePointer Input %uint %tint_symbol = OpVariable %_ptr_Input_uint Input %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float - %21 = OpConstantNull %v4float -%tint_symbol_2 = OpVariable %_ptr_Output_v4float Output %21 -%tint_symbol_5 = OpVariable %_ptr_Output_v4float Output %21 + %11 = OpConstantNull %v4float +%tint_symbol_2 = OpVariable %_ptr_Output_v4float Output %11 +%tint_symbol_5 = OpVariable %_ptr_Output_v4float Output %11 %void = OpTypeVoid - %23 = OpTypeFunction %void %v4float - %28 = OpTypeFunction %void + %13 = OpTypeFunction %void %v4float + %18 = OpTypeFunction %void %float_1 = OpConstant %float 1 + %v2float = OpTypeVector %float 2 + %uint_3 = OpConstant %uint 3 +%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3 + %float_0 = OpConstant %float 0 + %float_0_5 = OpConstant %float 0.5 + %27 = OpConstantComposite %v2float %float_0 %float_0_5 + %float_n0_5 = OpConstant %float -0.5 + %29 = OpConstantComposite %v2float %float_n0_5 %float_n0_5 + %30 = OpConstantComposite %v2float %float_0_5 %float_n0_5 + %31 = OpConstantComposite %_arr_v2float_uint_3 %27 %29 %30 %_ptr_Function__arr_v2float_uint_3 = OpTypePointer Function %_arr_v2float_uint_3 %34 = OpConstantNull %_arr_v2float_uint_3 %_ptr_Function_v2float = OpTypePointer Function %v2float %49 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1 -%tint_symbol_3 = OpFunction %void None %23 +%tint_symbol_3 = OpFunction %void None %13 %tint_symbol_1 = OpFunctionParameter %v4float - %27 = OpLabel + %17 = OpLabel OpStore %tint_symbol_2 %tint_symbol_1 OpReturn OpFunctionEnd - %vtx_main = OpFunction %void None %28 - %30 = OpLabel -%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %34 + %vtx_main = OpFunction %void None %18 + %20 = OpLabel + %pos = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %34 OpStore %tint_pointsize %float_1 - OpStore %var_for_index %pos + OpStore %pos %31 %36 = OpLoad %uint %tint_symbol - %38 = OpAccessChain %_ptr_Function_v2float %var_for_index %36 + %38 = OpAccessChain %_ptr_Function_v2float %pos %36 %39 = OpLoad %v2float %38 %40 = OpCompositeExtract %float %39 0 %41 = OpCompositeExtract %float %39 1 @@ -75,13 +74,13 @@ %35 = OpFunctionCall %void %tint_symbol_3 %42 OpReturn OpFunctionEnd -%tint_symbol_6 = OpFunction %void None %23 +%tint_symbol_6 = OpFunction %void None %13 %tint_symbol_4 = OpFunctionParameter %v4float %45 = OpLabel OpStore %tint_symbol_5 %tint_symbol_4 OpReturn OpFunctionEnd - %frag_main = OpFunction %void None %28 + %frag_main = OpFunction %void None %18 %47 = OpLabel %48 = OpFunctionCall %void %tint_symbol_6 %49 OpReturn diff --git a/test/samples/triangle.wgsl.expected.wgsl b/test/samples/triangle.wgsl.expected.wgsl index bd398e01d7..5e1145b3d6 100644 --- a/test/samples/triangle.wgsl.expected.wgsl +++ b/test/samples/triangle.wgsl.expected.wgsl @@ -1,7 +1,6 @@ -let pos : array, 3> = array, 3>(vec2(0.0, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5)); - [[stage(vertex)]] fn vtx_main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + var pos : array, 3> = array, 3>(vec2(0.0, 0.5), vec2(-0.5, -0.5), vec2(0.5, -0.5)); return vec4(pos[VertexIndex], 0.0, 1.0); }