writer/hlsl: Zero initialize with (T) 0
For structures and arrays.
This behaves identically to the per-element zero-initialization, but can be significantly less verbose.
Change-Id: I380ef86f16c2b3f37a9de2820e707f368955b761
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56764
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/test/array/assign_to_function_var.wgsl.expected.hlsl b/test/array/assign_to_function_var.wgsl.expected.hlsl
index 04ee28a..a52de60 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 @@
return tint_symbol_6;
}
-static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}};
+static tint_array_wrapper src_private = (tint_array_wrapper)0;
groupshared tint_array_wrapper src_workgroup;
cbuffer cbuffer_src_uniform : register(b0, space0) {
uint4 src_uniform[4];
@@ -35,12 +35,12 @@
RWByteAddressBuffer src_storage : register(u1, space0);
tint_array_wrapper ret_arr() {
- const tint_array_wrapper tint_symbol_7 = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper tint_symbol_7 = {(tint_padded_array_element[4])0};
return tint_symbol_7;
}
S ret_struct_arr() {
- const S tint_symbol_8 = {{{{0}, {0}, {0}, {0}}}};
+ const S tint_symbol_8 = (S)0;
return tint_symbol_8;
}
@@ -55,13 +55,13 @@
};
void foo(tint_array_wrapper src_param) {
- tint_array_wrapper src_function = {{{0}, {0}, {0}, {0}}};
- tint_array_wrapper tint_symbol = {{{0}, {0}, {0}, {0}}};
+ tint_array_wrapper src_function = (tint_array_wrapper)0;
+ tint_array_wrapper tint_symbol = (tint_array_wrapper)0;
const tint_array_wrapper tint_symbol_9 = {{{1}, {2}, {3}, {3}}};
tint_symbol = tint_symbol_9;
tint_symbol = src_param;
tint_symbol = ret_arr();
- const tint_array_wrapper src_let = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper src_let = {(tint_padded_array_element[4])0};
tint_symbol = src_let;
tint_symbol = src_function;
tint_symbol = src_private;
@@ -69,7 +69,7 @@
tint_symbol = ret_struct_arr().arr;
tint_symbol = tint_symbol_2(src_uniform, 0u);
tint_symbol = tint_symbol_4(src_storage, 0u);
- 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_1 src_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_1 dst_nested = (tint_array_wrapper_1)0;
+ tint_array_wrapper_1 src_nested = (tint_array_wrapper_1)0;
dst_nested = src_nested;
}
diff --git a/test/array/assign_to_private_var.wgsl.expected.hlsl b/test/array/assign_to_private_var.wgsl.expected.hlsl
index 7ee5d9d..52cf9b8 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 @@
return tint_symbol_6;
}
-static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}};
+static tint_array_wrapper src_private = (tint_array_wrapper)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 = {{{0}, {0}, {0}, {0}}};
+static tint_array_wrapper tint_symbol = (tint_array_wrapper)0;
struct tint_array_wrapper_3 {
int arr[2];
@@ -45,25 +45,25 @@
tint_array_wrapper_2 arr[4];
};
-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}}}}}};
+static tint_array_wrapper_1 dst_nested = (tint_array_wrapper_1)0;
tint_array_wrapper ret_arr() {
- const tint_array_wrapper tint_symbol_7 = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper tint_symbol_7 = {(tint_padded_array_element[4])0};
return tint_symbol_7;
}
S ret_struct_arr() {
- const S tint_symbol_8 = {{{{0}, {0}, {0}, {0}}}};
+ const S tint_symbol_8 = (S)0;
return tint_symbol_8;
}
void foo(tint_array_wrapper src_param) {
- tint_array_wrapper src_function = {{{0}, {0}, {0}, {0}}};
+ tint_array_wrapper src_function = (tint_array_wrapper)0;
const tint_array_wrapper tint_symbol_9 = {{{1}, {2}, {3}, {3}}};
tint_symbol = tint_symbol_9;
tint_symbol = src_param;
tint_symbol = ret_arr();
- const tint_array_wrapper src_let = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper src_let = {(tint_padded_array_element[4])0};
tint_symbol = src_let;
tint_symbol = src_function;
tint_symbol = src_private;
@@ -71,6 +71,6 @@
tint_symbol = ret_struct_arr().arr;
tint_symbol = tint_symbol_2(src_uniform, 0u);
tint_symbol = tint_symbol_4(src_storage, 0u);
- tint_array_wrapper_1 src_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_1 src_nested = (tint_array_wrapper_1)0;
dst_nested = src_nested;
}
diff --git a/test/array/assign_to_storage_var.wgsl.expected.hlsl b/test/array/assign_to_storage_var.wgsl.expected.hlsl
index fb0d23e..2cf8195 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 @@
tint_symbol_9(buffer, (offset + 72u), value.arr[3u]);
}
-static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}};
+static tint_array_wrapper src_private = (tint_array_wrapper)0;
groupshared tint_array_wrapper src_workgroup;
cbuffer cbuffer_src_uniform : register(b0, space0) {
uint4 src_uniform[4];
@@ -72,22 +72,22 @@
RWByteAddressBuffer dst_nested : register(u3, space0);
tint_array_wrapper ret_arr() {
- const tint_array_wrapper tint_symbol_13 = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper tint_symbol_13 = {(tint_padded_array_element[4])0};
return tint_symbol_13;
}
S ret_struct_arr() {
- const S tint_symbol_14 = {{{{0}, {0}, {0}, {0}}}};
+ const S tint_symbol_14 = (S)0;
return tint_symbol_14;
}
void foo(tint_array_wrapper src_param) {
- tint_array_wrapper src_function = {{{0}, {0}, {0}, {0}}};
+ tint_array_wrapper src_function = (tint_array_wrapper)0;
const tint_array_wrapper tint_symbol_15 = {{{1}, {2}, {3}, {3}}};
tint_symbol_6(tint_symbol, 0u, tint_symbol_15);
tint_symbol_6(tint_symbol, 0u, src_param);
tint_symbol_6(tint_symbol, 0u, ret_arr());
- const tint_array_wrapper src_let = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper src_let = {(tint_padded_array_element[4])0};
tint_symbol_6(tint_symbol, 0u, src_let);
tint_symbol_6(tint_symbol, 0u, src_function);
tint_symbol_6(tint_symbol, 0u, src_private);
@@ -95,6 +95,6 @@
tint_symbol_6(tint_symbol, 0u, ret_struct_arr().arr);
tint_symbol_6(tint_symbol, 0u, tint_symbol_2(src_uniform, 0u));
tint_symbol_6(tint_symbol, 0u, tint_symbol_4(src_storage, 0u));
- tint_array_wrapper_1 src_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_1 src_nested = (tint_array_wrapper_1)0;
tint_symbol_10(dst_nested, 0u, src_nested);
}
diff --git a/test/array/assign_to_subexpr.wgsl.expected.hlsl b/test/array/assign_to_subexpr.wgsl.expected.hlsl
index 1c1d5f5..a4596c3 100644
--- a/test/array/assign_to_subexpr.wgsl.expected.hlsl
+++ b/test/array/assign_to_subexpr.wgsl.expected.hlsl
@@ -14,10 +14,10 @@
};
void foo() {
- const tint_array_wrapper src = {{0, 0, 0, 0}};
- tint_array_wrapper tint_symbol = {{0, 0, 0, 0}};
- S dst_struct = {{{0, 0, 0, 0}}};
- tint_array_wrapper_1 dst_array = {{{{0, 0, 0, 0}}, {{0, 0, 0, 0}}}};
+ const tint_array_wrapper src = {(int[4])0};
+ tint_array_wrapper tint_symbol = (tint_array_wrapper)0;
+ S dst_struct = (S)0;
+ tint_array_wrapper_1 dst_array = (tint_array_wrapper_1)0;
dst_struct.arr = src;
dst_array.arr[1] = src;
tint_symbol = src;
diff --git a/test/array/assign_to_workgroup_var.wgsl.expected.hlsl b/test/array/assign_to_workgroup_var.wgsl.expected.hlsl
index 4a752ef..14443ac 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 @@
return tint_symbol_6;
}
-static tint_array_wrapper src_private = {{{0}, {0}, {0}, {0}}};
+static tint_array_wrapper src_private = (tint_array_wrapper)0;
groupshared tint_array_wrapper src_workgroup;
cbuffer cbuffer_src_uniform : register(b0, space0) {
uint4 src_uniform[4];
@@ -48,22 +48,22 @@
groupshared tint_array_wrapper_1 dst_nested;
tint_array_wrapper ret_arr() {
- const tint_array_wrapper tint_symbol_7 = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper tint_symbol_7 = {(tint_padded_array_element[4])0};
return tint_symbol_7;
}
S ret_struct_arr() {
- const S tint_symbol_8 = {{{{0}, {0}, {0}, {0}}}};
+ const S tint_symbol_8 = (S)0;
return tint_symbol_8;
}
void foo(tint_array_wrapper src_param) {
- tint_array_wrapper src_function = {{{0}, {0}, {0}, {0}}};
+ tint_array_wrapper src_function = (tint_array_wrapper)0;
const tint_array_wrapper tint_symbol_9 = {{{1}, {2}, {3}, {3}}};
tint_symbol = tint_symbol_9;
tint_symbol = src_param;
tint_symbol = ret_arr();
- const tint_array_wrapper src_let = {{{0}, {0}, {0}, {0}}};
+ const tint_array_wrapper src_let = {(tint_padded_array_element[4])0};
tint_symbol = src_let;
tint_symbol = src_function;
tint_symbol = src_private;
@@ -71,6 +71,6 @@
tint_symbol = ret_struct_arr().arr;
tint_symbol = tint_symbol_2(src_uniform, 0u);
tint_symbol = tint_symbol_4(src_storage, 0u);
- tint_array_wrapper_1 src_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_1 src_nested = (tint_array_wrapper_1)0;
dst_nested = src_nested;
}
diff --git a/test/array/function_parameter.wgsl.expected.hlsl b/test/array/function_parameter.wgsl.expected.hlsl
index 7c3bbf9..d7c86d7 100644
--- a/test/array/function_parameter.wgsl.expected.hlsl
+++ b/test/array/function_parameter.wgsl.expected.hlsl
@@ -24,9 +24,9 @@
[numthreads(1, 1, 1)]
void main() {
- const tint_array_wrapper a1 = {{0.0f, 0.0f, 0.0f, 0.0f}};
- const tint_array_wrapper_1 a2 = {{{{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}}};
- const tint_array_wrapper_2 a3 = {{{{{{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}}}, {{{{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}, {{0.0f, 0.0f, 0.0f, 0.0f}}}}}};
+ const tint_array_wrapper a1 = {(float[4])0};
+ const tint_array_wrapper_1 a2 = {(tint_array_wrapper[3])0};
+ const tint_array_wrapper_2 a3 = {(tint_array_wrapper_1[2])0};
const float v1 = f1(a1);
const float v2 = f2(a2);
const float v3 = f3(a3);
diff --git a/test/array/function_return_type.wgsl.expected.hlsl b/test/array/function_return_type.wgsl.expected.hlsl
index 7109b7f..c0b9630 100644
--- a/test/array/function_return_type.wgsl.expected.hlsl
+++ b/test/array/function_return_type.wgsl.expected.hlsl
@@ -3,7 +3,7 @@
};
tint_array_wrapper f1() {
- const tint_array_wrapper tint_symbol = {{0.0f, 0.0f, 0.0f, 0.0f}};
+ const tint_array_wrapper tint_symbol = {(float[4])0};
return tint_symbol;
}
diff --git a/test/array/type_constructor.wgsl.expected.hlsl b/test/array/type_constructor.wgsl.expected.hlsl
index 0c2040a..ddf6220 100644
--- a/test/array/type_constructor.wgsl.expected.hlsl
+++ b/test/array/type_constructor.wgsl.expected.hlsl
@@ -14,10 +14,10 @@
[numthreads(1, 1, 1)]
void main() {
const int x = 42;
- const tint_array_wrapper empty = {{0, 0, 0, 0}};
+ const tint_array_wrapper empty = {(int[4])0};
const tint_array_wrapper nonempty = {{1, 2, 3, 4}};
const tint_array_wrapper nonempty_with_expr = {{1, x, (x + 1), nonempty.arr[3]}};
- const tint_array_wrapper_1 nested_empty = {{{{{{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}}}, {{{{0, 0, 0, 0}}, {{0, 0, 0, 0}}, {{0, 0, 0, 0}}}}}};
+ const tint_array_wrapper_1 nested_empty = {(tint_array_wrapper_2[2])0};
const tint_array_wrapper tint_symbol = {{1, 2, 3, 4}};
const tint_array_wrapper tint_symbol_1 = {{5, 6, 7, 8}};
const tint_array_wrapper tint_symbol_2 = {{9, 10, 11, 12}};
@@ -31,13 +31,13 @@
const tint_array_wrapper tint_symbol_9 = {{5, 6, nonempty.arr[2], (nonempty.arr[3] + 1)}};
const tint_array_wrapper_2 tint_symbol_10 = {{tint_symbol_8, tint_symbol_9, nonempty}};
const tint_array_wrapper_1 nested_nonempty_with_expr = {{tint_symbol_10, nested_nonempty.arr[1]}};
- const tint_array_wrapper tint_symbol_11 = {{0, 0, 0, 0}};
+ const tint_array_wrapper tint_symbol_11 = {(int[4])0};
const int subexpr_empty = tint_symbol_11.arr[1];
const tint_array_wrapper tint_symbol_12 = {{1, 2, 3, 4}};
const int subexpr_nonempty = tint_symbol_12.arr[2];
const tint_array_wrapper tint_symbol_13 = {{1, x, (x + 1), nonempty.arr[3]}};
const int subexpr_nonempty_with_expr = tint_symbol_13.arr[2];
- const tint_array_wrapper_3 tint_symbol_14 = {{{{0, 0, 0, 0}}, {{0, 0, 0, 0}}}};
+ const tint_array_wrapper_3 tint_symbol_14 = {(tint_array_wrapper[2])0};
const tint_array_wrapper subexpr_nested_empty = tint_symbol_14.arr[1];
const tint_array_wrapper tint_symbol_15 = {{1, 2, 3, 4}};
const tint_array_wrapper tint_symbol_16 = {{5, 6, 7, 8}};