diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 2d164f0129..d472bd5e01 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2119,13 +2119,6 @@ bool GeneratorImpl::EmitHandleVariable(std::ostream& out, auto* decl = var->Declaration(); auto* unwrapped_type = var->Type()->UnwrapRef(); - std::ostringstream constructor_out; - if (auto* constructor = decl->constructor()) { - if (!EmitExpression(out, constructor_out, constructor)) { - return false; - } - } - auto name = builder_.Symbols().NameFor(decl->symbol()); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { @@ -2151,10 +2144,6 @@ bool GeneratorImpl::EmitHandleVariable(std::ostream& out, << bp.group->value() << ")"; } - if (constructor_out.str().length()) { - out << " = " << constructor_out.str(); - } - out << ";" << std::endl; return true; } @@ -2170,6 +2159,10 @@ bool GeneratorImpl::EmitPrivateVariable(std::ostream& out, if (!EmitExpression(out, constructor_out, constructor)) { return false; } + } else { + if (!EmitZeroValue(constructor_out, var->Type()->UnwrapRef())) { + return false; + } } out << "static "; diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index 69f8142d7e..203551d451 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -136,7 +136,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) { float mem; }; -static Data str; +static Data str = {0.0f}; [numthreads(1, 1, 1)] void test_function() { diff --git a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc index a1345bd8cb..2ce7469e1a 100644 --- a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc @@ -75,7 +75,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) { gen.increment_indent(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_THAT(result(), HasSubstr(" static float a;\n")); + EXPECT_THAT(result(), HasSubstr(" static float a = 0.0f;\n")); } TEST_F(HlslGeneratorImplTest_VariableDecl, diff --git a/test/array/assign_to_function_var.wgsl.expected.hlsl b/test/array/assign_to_function_var.wgsl.expected.hlsl index 133a58e567..04ee28a91c 100644 --- a/test/array/assign_to_function_var.wgsl.expected.hlsl +++ b/test/array/assign_to_function_var.wgsl.expected.hlsl @@ -27,7 +27,7 @@ tint_array_wrapper tint_symbol_4(RWByteAddressBuffer buffer, uint offset) { return tint_symbol_6; } -static tint_array_wrapper src_private; +static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}}; groupshared tint_array_wrapper src_workgroup; cbuffer cbuffer_src_uniform : register(b0, space0) { uint4 src_uniform[4]; diff --git a/test/array/assign_to_private_var.wgsl.expected.hlsl b/test/array/assign_to_private_var.wgsl.expected.hlsl index 101ba44a21..7ee5d9d46b 100644 --- a/test/array/assign_to_private_var.wgsl.expected.hlsl +++ b/test/array/assign_to_private_var.wgsl.expected.hlsl @@ -27,13 +27,13 @@ tint_array_wrapper tint_symbol_4(RWByteAddressBuffer buffer, uint offset) { return tint_symbol_6; } -static tint_array_wrapper src_private; +static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}}; groupshared tint_array_wrapper src_workgroup; cbuffer cbuffer_src_uniform : register(b0, space0) { uint4 src_uniform[4]; }; RWByteAddressBuffer src_storage : register(u1, space0); -static tint_array_wrapper tint_symbol; +static tint_array_wrapper tint_symbol = {{{0}, {0}, {0}, {0}}}; struct tint_array_wrapper_3 { int arr[2]; @@ -45,7 +45,7 @@ struct tint_array_wrapper_1 { tint_array_wrapper_2 arr[4]; }; -static tint_array_wrapper_1 dst_nested; +static tint_array_wrapper_1 dst_nested = {{{{{{0, 0}}, {{0, 0}}, {{0, 0}}}}, {{{{0, 0}}, {{0, 0}}, {{0, 0}}}}, {{{{0, 0}}, {{0, 0}}, {{0, 0}}}}, {{{{0, 0}}, {{0, 0}}, {{0, 0}}}}}}; tint_array_wrapper ret_arr() { const tint_array_wrapper tint_symbol_7 = {{{0}, {0}, {0}, {0}}}; diff --git a/test/array/assign_to_storage_var.wgsl.expected.hlsl b/test/array/assign_to_storage_var.wgsl.expected.hlsl index ba72892c87..fb0d23ee76 100644 --- a/test/array/assign_to_storage_var.wgsl.expected.hlsl +++ b/test/array/assign_to_storage_var.wgsl.expected.hlsl @@ -62,7 +62,7 @@ void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, tint_array_wrapper_ tint_symbol_9(buffer, (offset + 72u), value.arr[3u]); } -static tint_array_wrapper src_private; +static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}}; groupshared tint_array_wrapper src_workgroup; cbuffer cbuffer_src_uniform : register(b0, space0) { uint4 src_uniform[4]; diff --git a/test/array/assign_to_workgroup_var.wgsl.expected.hlsl b/test/array/assign_to_workgroup_var.wgsl.expected.hlsl index 49062f7e12..4a752ef8bd 100644 --- a/test/array/assign_to_workgroup_var.wgsl.expected.hlsl +++ b/test/array/assign_to_workgroup_var.wgsl.expected.hlsl @@ -27,7 +27,7 @@ tint_array_wrapper tint_symbol_4(RWByteAddressBuffer buffer, uint offset) { return tint_symbol_6; } -static tint_array_wrapper src_private; +static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}}; groupshared tint_array_wrapper src_workgroup; cbuffer cbuffer_src_uniform : register(b0, space0) { uint4 src_uniform[4]; diff --git a/test/bug/tint/749.spvasm.expected.hlsl b/test/bug/tint/749.spvasm.expected.hlsl index 8d3b29803e..f7e876162e 100644 --- a/test/bug/tint/749.spvasm.expected.hlsl +++ b/test/bug/tint/749.spvasm.expected.hlsl @@ -5,12 +5,12 @@ struct QuicksortObject { tint_array_wrapper numbers; }; -static QuicksortObject obj; -static float4 gl_FragCoord; +static QuicksortObject obj = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}}; +static float4 gl_FragCoord = float4(0.0f, 0.0f, 0.0f, 0.0f); cbuffer cbuffer_x_188 : register(b0, space0) { uint4 x_188[1]; }; -static float4 x_GLF_color; +static float4 x_GLF_color = float4(0.0f, 0.0f, 0.0f, 0.0f); void swap_i1_i1_(inout int i, inout int j) { int temp = 0; diff --git a/test/intrinsics/gen/frexp/53d417.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/53d417.wgsl.expected.hlsl index 5d6b79b4e7..d9d77ebf3d 100644 --- a/test/intrinsics/gen/frexp/53d417.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/53d417.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static uint3 arg_1; +static uint3 arg_1 = uint3(0u, 0u, 0u); void frexp_53d417() { float3 tint_tmp; diff --git a/test/intrinsics/gen/frexp/6efa09.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/6efa09.wgsl.expected.hlsl index c800107ab3..81162a176d 100644 --- a/test/intrinsics/gen/frexp/6efa09.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/6efa09.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int3 arg_1; +static int3 arg_1 = int3(0, 0, 0); void frexp_6efa09() { float3 tint_tmp; diff --git a/test/intrinsics/gen/frexp/a2a617.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/a2a617.wgsl.expected.hlsl index c91adac43f..d6c787d96b 100644 --- a/test/intrinsics/gen/frexp/a2a617.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/a2a617.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int arg_1; +static int arg_1 = 0; void frexp_a2a617() { float tint_tmp; diff --git a/test/intrinsics/gen/frexp/b45525.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/b45525.wgsl.expected.hlsl index 3ab6fd4ea7..e0b30abb60 100644 --- a/test/intrinsics/gen/frexp/b45525.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/b45525.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int4 arg_1; +static int4 arg_1 = int4(0, 0, 0, 0); void frexp_b45525() { float4 tint_tmp; diff --git a/test/intrinsics/gen/frexp/b7bcbb.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/b7bcbb.wgsl.expected.hlsl index bf2c7d3dc9..f817d13121 100644 --- a/test/intrinsics/gen/frexp/b7bcbb.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/b7bcbb.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static uint arg_1; +static uint arg_1 = 0u; void frexp_b7bcbb() { float tint_tmp; diff --git a/test/intrinsics/gen/frexp/c084e3.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/c084e3.wgsl.expected.hlsl index 34d18ecbb7..803ea55b7c 100644 --- a/test/intrinsics/gen/frexp/c084e3.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/c084e3.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int2 arg_1; +static int2 arg_1 = int2(0, 0); void frexp_c084e3() { float2 tint_tmp; diff --git a/test/intrinsics/gen/frexp/d14b16.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/d14b16.wgsl.expected.hlsl index a041a77501..354933f224 100644 --- a/test/intrinsics/gen/frexp/d14b16.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/d14b16.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static uint4 arg_1; +static uint4 arg_1 = uint4(0u, 0u, 0u, 0u); void frexp_d14b16() { float4 tint_tmp; diff --git a/test/intrinsics/gen/frexp/e06acd.wgsl.expected.hlsl b/test/intrinsics/gen/frexp/e06acd.wgsl.expected.hlsl index aa0ab83883..34631276a2 100644 --- a/test/intrinsics/gen/frexp/e06acd.wgsl.expected.hlsl +++ b/test/intrinsics/gen/frexp/e06acd.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static uint2 arg_1; +static uint2 arg_1 = uint2(0u, 0u); void frexp_e06acd() { float2 tint_tmp; diff --git a/test/intrinsics/gen/modf/3d00e2.wgsl.expected.hlsl b/test/intrinsics/gen/modf/3d00e2.wgsl.expected.hlsl index 3a5c5bd586..202046108a 100644 --- a/test/intrinsics/gen/modf/3d00e2.wgsl.expected.hlsl +++ b/test/intrinsics/gen/modf/3d00e2.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static float4 arg_1; +static float4 arg_1 = float4(0.0f, 0.0f, 0.0f, 0.0f); void modf_3d00e2() { float4 res = modf(float4(0.0f, 0.0f, 0.0f, 0.0f), arg_1); diff --git a/test/intrinsics/gen/modf/5e8476.wgsl.expected.hlsl b/test/intrinsics/gen/modf/5e8476.wgsl.expected.hlsl index a49ae64ed5..8fabfe20df 100644 --- a/test/intrinsics/gen/modf/5e8476.wgsl.expected.hlsl +++ b/test/intrinsics/gen/modf/5e8476.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static float arg_1; +static float arg_1 = 0.0f; void modf_5e8476() { float res = modf(1.0f, arg_1); diff --git a/test/intrinsics/gen/modf/9c6a91.wgsl.expected.hlsl b/test/intrinsics/gen/modf/9c6a91.wgsl.expected.hlsl index ba4ea6c930..26b8eaf60e 100644 --- a/test/intrinsics/gen/modf/9c6a91.wgsl.expected.hlsl +++ b/test/intrinsics/gen/modf/9c6a91.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static float2 arg_1; +static float2 arg_1 = float2(0.0f, 0.0f); void modf_9c6a91() { float2 res = modf(float2(0.0f, 0.0f), arg_1); diff --git a/test/intrinsics/gen/modf/9cecfc.wgsl.expected.hlsl b/test/intrinsics/gen/modf/9cecfc.wgsl.expected.hlsl index 80d1eda1d8..72befc31e2 100644 --- a/test/intrinsics/gen/modf/9cecfc.wgsl.expected.hlsl +++ b/test/intrinsics/gen/modf/9cecfc.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static float3 arg_1; +static float3 arg_1 = float3(0.0f, 0.0f, 0.0f); void modf_9cecfc() { float3 res = modf(float3(0.0f, 0.0f, 0.0f), arg_1); diff --git a/test/ptr_ref/load/global/i32.wgsl.expected.hlsl b/test/ptr_ref/load/global/i32.wgsl.expected.hlsl index 8d7fb51271..85b02045e7 100644 --- a/test/ptr_ref/load/global/i32.wgsl.expected.hlsl +++ b/test/ptr_ref/load/global/i32.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int I; +static int I = 0; [numthreads(1, 1, 1)] void main() { diff --git a/test/ptr_ref/load/global/struct_field.spvasm.expected.hlsl b/test/ptr_ref/load/global/struct_field.spvasm.expected.hlsl index 038d7fcc20..50c26c88db 100644 --- a/test/ptr_ref/load/global/struct_field.spvasm.expected.hlsl +++ b/test/ptr_ref/load/global/struct_field.spvasm.expected.hlsl @@ -2,7 +2,7 @@ struct S { int i; }; -static S V; +static S V = {0}; void main_1() { int i = 0; diff --git a/test/ptr_ref/load/global/struct_field.wgsl.expected.hlsl b/test/ptr_ref/load/global/struct_field.wgsl.expected.hlsl index ec19102c14..f5c5e90033 100644 --- a/test/ptr_ref/load/global/struct_field.wgsl.expected.hlsl +++ b/test/ptr_ref/load/global/struct_field.wgsl.expected.hlsl @@ -2,7 +2,7 @@ struct S { int i; }; -static S V; +static S V = {0}; [numthreads(1, 1, 1)] void main() { diff --git a/test/ptr_ref/store/global/i32.wgsl.expected.hlsl b/test/ptr_ref/store/global/i32.wgsl.expected.hlsl index 8546bd5a32..cb1bb3dbd8 100644 --- a/test/ptr_ref/store/global/i32.wgsl.expected.hlsl +++ b/test/ptr_ref/store/global/i32.wgsl.expected.hlsl @@ -1,4 +1,4 @@ -static int I; +static int I = 0; [numthreads(1, 1, 1)] void main() { diff --git a/test/ptr_ref/store/global/struct_field.spvasm.expected.hlsl b/test/ptr_ref/store/global/struct_field.spvasm.expected.hlsl index 0ce7881bd0..8a3e891313 100644 --- a/test/ptr_ref/store/global/struct_field.spvasm.expected.hlsl +++ b/test/ptr_ref/store/global/struct_field.spvasm.expected.hlsl @@ -2,7 +2,7 @@ struct S { int i; }; -static S V; +static S V = {0}; void main_1() { V.i = 5; diff --git a/test/samples/simple_vertex.spvasm.expected.hlsl b/test/samples/simple_vertex.spvasm.expected.hlsl index 7469b78949..05826f0dd1 100644 --- a/test/samples/simple_vertex.spvasm.expected.hlsl +++ b/test/samples/simple_vertex.spvasm.expected.hlsl @@ -1,4 +1,4 @@ -static float4 gl_Position; +static float4 gl_Position = float4(0.0f, 0.0f, 0.0f, 0.0f); void main_1() { gl_Position = float4(0.0f, 0.0f, 0.0f, 0.0f); diff --git a/test/types/module_scope_var.wgsl.expected.hlsl b/test/types/module_scope_var.wgsl.expected.hlsl index d5ffa61a55..176ade448a 100644 --- a/test/types/module_scope_var.wgsl.expected.hlsl +++ b/test/types/module_scope_var.wgsl.expected.hlsl @@ -1,21 +1,21 @@ struct S { }; -static bool bool_var; -static int i32_var; -static uint u32_var; -static float f32_var; -static int2 v2i32_var; -static uint3 v3u32_var; -static float4 v4f32_var; -static float2x3 m2x3_var; +static bool bool_var = false; +static int i32_var = 0; +static uint u32_var = 0u; +static float f32_var = 0.0f; +static int2 v2i32_var = int2(0, 0); +static uint3 v3u32_var = uint3(0u, 0u, 0u); +static float4 v4f32_var = float4(0.0f, 0.0f, 0.0f, 0.0f); +static float2x3 m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); struct tint_array_wrapper { float arr[4]; }; -static tint_array_wrapper arr_var; -static S struct_var; +static tint_array_wrapper arr_var = {{0.0f, 0.0f, 0.0f, 0.0f}}; +static S struct_var = {}; [numthreads(1, 1, 1)] void main() { diff --git a/test/var/private.wgsl.expected.hlsl b/test/var/private.wgsl.expected.hlsl index 8f150066ab..606819feaa 100644 --- a/test/var/private.wgsl.expected.hlsl +++ b/test/var/private.wgsl.expected.hlsl @@ -1,6 +1,6 @@ -static int a; -static int b; -static int c; +static int a = 0; +static int b = 0; +static int c = 0; void uses_a() { a = (a + 1);