Skip to content

Commit

Permalink
[WGSL] quantizeToF16 generates invalid code for vectors
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267108
rdar://120500374

Reviewed by Mike Wyrzykowski.

The code generator was always emitting `float(half(x))` for quantizeToF16, but
it should to be `floatN(halfN(x))` if the argument is a vector of size N.

* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::emitQuantizeToF16):

Canonical link: https://commits.webkit.org/272685@main
  • Loading branch information
tadeuzagallo committed Jan 5, 2024
1 parent a059855 commit dd88d93
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,8 +1716,12 @@ static void emitPack4xU8Clamp(FunctionDefinitionWriter* writer, AST::CallExpress

static void emitQuantizeToF16(FunctionDefinitionWriter* writer, AST::CallExpression& call)
{
writer->stringBuilder().append("float(half(");
writer->visit(call.arguments()[0]);
auto& argument = call.arguments()[0];
String suffix = ""_s;
if (auto* vectorType = std::get_if<Types::Vector>(argument.inferredType()))
suffix = String::number(vectorType->size);
writer->stringBuilder().append("float", suffix, "(half", suffix, "(");
writer->visit(argument);
writer->stringBuilder().append("))");
}

Expand Down

0 comments on commit dd88d93

Please sign in to comment.