tint: Fix emitting vector constant in HLSL writer
This patch fix the issue that HLSL generator emit wrong constant element index for vectors with all elements being the same, which may cause error when emitting a matrix constant with sub columns having identical elements. Corresponding unit test is implemented. Bug: tint:1588 Change-Id: Ia40b3f1a676d84aadaa5ce900677547fb15abe7f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94041 Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
65d61d76a3
commit
be6fb2a8d2
|
@ -3162,11 +3162,11 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant& constan
|
|||
{
|
||||
ScopedParen sp(out);
|
||||
bool ok = Switch(
|
||||
vec_ty->type(), //
|
||||
[&](const sem::Bool*) { return emit_bool(0); }, //
|
||||
[&](const sem::F32*) { return emit_f32(0); }, //
|
||||
[&](const sem::I32*) { return emit_i32(0); }, //
|
||||
[&](const sem::U32*) { return emit_u32(0); } //
|
||||
vec_ty->type(), //
|
||||
[&](const sem::Bool*) { return emit_bool(start); }, //
|
||||
[&](const sem::F32*) { return emit_f32(start); }, //
|
||||
[&](const sem::I32*) { return emit_i32(start); }, //
|
||||
[&](const sem::U32*) { return emit_u32(start); } //
|
||||
);
|
||||
if (!ok) {
|
||||
return false;
|
||||
|
|
|
@ -186,6 +186,33 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
|
|||
HasSubstr("float2x3(float3(1.0f, 2.0f, 3.0f), float3(3.0f, 4.0f, 5.0f))"));
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat_Complex) {
|
||||
// mat4x4<f32>(
|
||||
// vec4<f32>(2.0f, 3.0f, 4.0f, 8.0f),
|
||||
// vec4<f32>(),
|
||||
// vec4<f32>(7.0f),
|
||||
// vec4<f32>(vec4<f32>(42.0f, 21.0f, 6.0f, -5.0f)),
|
||||
// );
|
||||
auto* vector_literal =
|
||||
vec4<f32>(Expr(f32(2.0)), Expr(f32(3.0)), Expr(f32(4.0)), Expr(f32(8.0)));
|
||||
auto* vector_zero_ctor = vec4<f32>();
|
||||
auto* vector_single_scalar_ctor = vec4<f32>(Expr(f32(7.0)));
|
||||
auto* vector_identical_ctor =
|
||||
vec4<f32>(vec4<f32>(Expr(f32(42.0)), Expr(f32(21.0)), Expr(f32(6.0)), Expr(f32(-5.0))));
|
||||
|
||||
auto* constructor = mat4x4<f32>(vector_literal, vector_zero_ctor, vector_single_scalar_ctor,
|
||||
vector_identical_ctor);
|
||||
|
||||
WrapInFunction(constructor);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
||||
EXPECT_THAT(gen.result(), HasSubstr("float4x4(float4(2.0f, 3.0f, 4.0f, 8.0f), (0.0f).xxxx, "
|
||||
"(7.0f).xxxx, float4(42.0f, 21.0f, 6.0f, -5.0f))"));
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat_Empty) {
|
||||
WrapInFunction(mat2x3<f32>());
|
||||
|
||||
|
|
Loading…
Reference in New Issue