From 1c75921db9c0095d7ab96c686f51efa2951b2f4f Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Sun, 15 May 2022 13:53:21 +0000 Subject: [PATCH] tint: fix translation of DP4a on HLSL This patch adds a workaround on a DXC error in the translation of DP4a functions that the third parameter "acc" of both dot4add_i8packed() and dot4add_u8packed() can only be a variable, or a compile error will be generated. Bug: tint:1497 Test: tint_unittests Change-Id: I263d27fb18bd354e0c9110f60cbc98860cf7afe5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90027 Reviewed-by: Ben Clayton Commit-Queue: Jiawei Shao Kokoro: Kokoro --- src/tint/writer/hlsl/generator_impl.cc | 4 +++- src/tint/writer/hlsl/generator_impl_builtin_test.cc | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index fb4efb6c31..b7020f6945 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -2045,9 +2045,11 @@ bool GeneratorImpl::EmitDP4aCall(std::ostream& out, std::string functionName; switch (builtin->Type()) { case sem::BuiltinType::kDot4I8Packed: + line(b) << "int accumulator = 0;"; functionName = "dot4add_i8packed"; break; case sem::BuiltinType::kDot4U8Packed: + line(b) << "uint accumulator = 0u;"; functionName = "dot4add_u8packed"; break; default: @@ -2056,7 +2058,7 @@ bool GeneratorImpl::EmitDP4aCall(std::ostream& out, return false; } line(b) << "return " << functionName << "(" << params[0] << ", " << params[1] - << ", 0);"; + << ", accumulator);"; return true; }); diff --git a/src/tint/writer/hlsl/generator_impl_builtin_test.cc b/src/tint/writer/hlsl/generator_impl_builtin_test.cc index 64ef7404f5..6c573ffb15 100644 --- a/src/tint/writer/hlsl/generator_impl_builtin_test.cc +++ b/src/tint/writer/hlsl/generator_impl_builtin_test.cc @@ -741,7 +741,8 @@ TEST_F(HlslGeneratorImplTest_Builtin, Dot4I8Packed) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(int tint_dot4I8Packed(uint param_0, uint param_1) { - return dot4add_i8packed(param_0, param_1, 0); + int accumulator = 0; + return dot4add_i8packed(param_0, param_1, accumulator); } [numthreads(1, 1, 1)] @@ -769,7 +770,8 @@ TEST_F(HlslGeneratorImplTest_Builtin, Dot4U8Packed) { ASSERT_TRUE(gen.Generate()) << gen.error(); EXPECT_EQ(gen.result(), R"(uint tint_dot4U8Packed(uint param_0, uint param_1) { - return dot4add_u8packed(param_0, param_1, 0); + uint accumulator = 0u; + return dot4add_u8packed(param_0, param_1, accumulator); } [numthreads(1, 1, 1)]