Skip to content

Commit

Permalink
[WGSL] Bitcast needs to concretize abstract floats
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268380
rdar://121527210

Reviewed by Mike Wyrzykowski.

Bitcast doesn't concretize its arguments by default, since there's a special case
for conversions from abstract int to u32, so we need to explicitly concretize
abstract floats.

* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::CONSTANT_FUNCTION):
* Source/WebGPU/WGSL/tests/valid/overload.wgsl:

Canonical link: https://commits.webkit.org/273764@main
  • Loading branch information
tadeuzagallo committed Jan 30, 2024
1 parent b3cdd4e commit 9a42882
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Source/WebGPU/WGSL/ConstantFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,14 @@ CONSTANT_FUNCTION(Bitcast)
return makeUnexpected(makeString("value ", String::number(*abstractInt), " cannot be represented as 'i32'"));
return { convertValue<BitwiseCast>(resultType, *result) };
}

if (auto* abstractFloat = std::get_if<double>(&argument)) {
auto result = convertFloat<float>(*abstractFloat);
if (!result.has_value())
return makeUnexpected(makeString("value ", String::number(*abstractFloat), " cannot be represented as 'f32'"));
return { convertValue<BitwiseCast>(resultType, *result) };
}

return { convertValue<BitwiseCast>(resultType, argument) };
}

Expand Down
2 changes: 2 additions & 0 deletions Source/WebGPU/WGSL/tests/valid/overload.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,8 @@ fn testBitcast()
let f = 0f;
let h = 0h;

{ const x =bitcast<vec2<i32>>(vec2(.659341217228384203)); }

// @const @must_use fn bitcast<T>(e : T) -> T
{ const x: u32 = bitcast<u32>(5u); }
{ const x: i32 = bitcast<i32>(5i); }
Expand Down

0 comments on commit 9a42882

Please sign in to comment.