mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 22:44:04 +00:00
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:
committed by
Tint LUCI CQ
parent
3b02d54ab0
commit
41f21fe05b
@@ -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 ";
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user