GLSL: fix single-valued vector init.

No need for the HLSL-style repeated swizzle; GLSL allows construction
of a vector from a scalar value of the component type.

Bug: tint:1317

Change-Id: Ia0afe3012cbb56716a2d1c5c3849dd662a5ff89c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70342
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White
2021-11-22 16:14:16 +00:00
committed by Tint LUCI CQ
parent 177e7bfa5d
commit 7368e287dc
8 changed files with 34 additions and 93 deletions

View File

@@ -563,12 +563,6 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out,
return EmitZeroValue(out, type);
}
// For single-value vector initializers, swizzle the scalar to the right
// vector dimension using .x
const bool is_single_value_vector_init =
type->is_scalar_vector() && call->Arguments().size() == 1 &&
call->Arguments()[0]->Type()->UnwrapRef()->is_scalar();
auto it = structure_builders_.find(As<sem::Struct>(type));
if (it != structure_builders_.end()) {
out << it->second << "(";
@@ -580,10 +574,6 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out,
out << "(";
}
if (is_single_value_vector_init) {
out << "(";
}
bool first = true;
for (auto* arg : call->Arguments()) {
if (!first) {
@@ -596,10 +586,6 @@ bool GeneratorImpl::EmitTypeConstructor(std::ostream& out,
}
}
if (is_single_value_vector_init) {
out << ")." << std::string(type->As<sem::Vector>()->Width(), 'x');
}
out << ")";
return true;
}

View File

@@ -122,7 +122,7 @@ TEST_F(GlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("vec3((2.0f).xxx)"));
EXPECT_THAT(gen.result(), HasSubstr("vec3(2.0f)"));
}
TEST_F(GlslGeneratorImplTest_Constructor,
@@ -132,7 +132,7 @@ TEST_F(GlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("bvec3((true).xxx)"));
EXPECT_THAT(gen.result(), HasSubstr("bvec3(true)"));
}
TEST_F(GlslGeneratorImplTest_Constructor,
@@ -142,7 +142,7 @@ TEST_F(GlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("ivec3((2).xxx)"));
EXPECT_THAT(gen.result(), HasSubstr("ivec3(2)"));
}
TEST_F(GlslGeneratorImplTest_Constructor,
@@ -152,7 +152,7 @@ TEST_F(GlslGeneratorImplTest_Constructor,
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("uvec3((2u).xxx)"));
EXPECT_THAT(gen.result(), HasSubstr("uvec3(2u)"));
}
TEST_F(GlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {