writer/hlsl: Emit zero values for private variables

Also remove the unreachanble constructor logic in EmitHandleVariable.
Variables of the handle storage class cannot have initializers.

Fixed: tint:173
Change-Id: I7c997a8b6a70308ff9b5c42fa1198810ee365bac
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55258
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-06-21 19:37:58 +00:00 committed by Tint LUCI CQ
parent 3b02d54ab0
commit 41f21fe05b
28 changed files with 46 additions and 53 deletions

View File

@ -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 ";

View File

@ -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() {

View File

@ -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,

View File

@ -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];

View File

@ -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}}};

View File

@ -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];

View File

@ -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];

View File

@ -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;

View File

@ -1,4 +1,4 @@
static uint3 arg_1;
static uint3 arg_1 = uint3(0u, 0u, 0u);
void frexp_53d417() {
float3 tint_tmp;

View File

@ -1,4 +1,4 @@
static int3 arg_1;
static int3 arg_1 = int3(0, 0, 0);
void frexp_6efa09() {
float3 tint_tmp;

View File

@ -1,4 +1,4 @@
static int arg_1;
static int arg_1 = 0;
void frexp_a2a617() {
float tint_tmp;

View File

@ -1,4 +1,4 @@
static int4 arg_1;
static int4 arg_1 = int4(0, 0, 0, 0);
void frexp_b45525() {
float4 tint_tmp;

View File

@ -1,4 +1,4 @@
static uint arg_1;
static uint arg_1 = 0u;
void frexp_b7bcbb() {
float tint_tmp;

View File

@ -1,4 +1,4 @@
static int2 arg_1;
static int2 arg_1 = int2(0, 0);
void frexp_c084e3() {
float2 tint_tmp;

View File

@ -1,4 +1,4 @@
static uint4 arg_1;
static uint4 arg_1 = uint4(0u, 0u, 0u, 0u);
void frexp_d14b16() {
float4 tint_tmp;

View File

@ -1,4 +1,4 @@
static uint2 arg_1;
static uint2 arg_1 = uint2(0u, 0u);
void frexp_e06acd() {
float2 tint_tmp;

View File

@ -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);

View File

@ -1,4 +1,4 @@
static float arg_1;
static float arg_1 = 0.0f;
void modf_5e8476() {
float res = modf(1.0f, arg_1);

View File

@ -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);

View File

@ -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);

View File

@ -1,4 +1,4 @@
static int I;
static int I = 0;
[numthreads(1, 1, 1)]
void main() {

View File

@ -2,7 +2,7 @@ struct S {
int i;
};
static S V;
static S V = {0};
void main_1() {
int i = 0;

View File

@ -2,7 +2,7 @@ struct S {
int i;
};
static S V;
static S V = {0};
[numthreads(1, 1, 1)]
void main() {

View File

@ -1,4 +1,4 @@
static int I;
static int I = 0;
[numthreads(1, 1, 1)]
void main() {

View File

@ -2,7 +2,7 @@ struct S {
int i;
};
static S V;
static S V = {0};
void main_1() {
V.i = 5;

View File

@ -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);

View File

@ -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() {

View File

@ -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);