Skip to content

Lower OpenCL mix builtin to arithmetic operations - #1655

Merged
rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:main
Sep 25, 2026
Merged

rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:main

Conversation

@rjodinchr

Copy link
Copy Markdown
Collaborator

The OpenCL C specification defines mix(x, y, a) as x + (y - x) * a. Previously, clspv mapped mix directly to the GLSL extended instruction FMix, which evaluates x * (1 - a) + y * a. Due to floating-point rounding differences, this can fail OpenCL CTS accuracy requirements.

Lower mix in ReplaceOpenCLBuiltinPass into explicit FSub, FMul, and FAdd operations conforming to the OpenCL specification formula, unless --use-native-builtins=mix or -native-math is requested. When the first operand is a vector and the third operand is scalar, splat the scalar argument across the vector lanes.

Update existing mix lit tests to use --use-native-builtins=mix to continue validating FMix instruction generation, and add tests covering lowered scalar and vector mix.

The OpenCL C specification defines mix(x, y, a) as x + (y - x) * a.
Previously, clspv mapped mix directly to the GLSL extended instruction
FMix, which evaluates x * (1 - a) + y * a. Due to floating-point rounding
differences, this can fail OpenCL CTS accuracy requirements.

Lower mix in ReplaceOpenCLBuiltinPass into explicit FSub, FMul, and FAdd
operations conforming to the OpenCL specification formula, unless
--use-native-builtins=mix or -native-math is requested. When the first
operand is a vector and the third operand is scalar, splat the scalar
argument across the vector lanes.

Update existing mix lit tests to use --use-native-builtins=mix to
continue validating FMix instruction generation, and add tests covering
lowered scalar and vector mix.
@rjodinchr
rjodinchr enabled auto-merge (squash) September 25, 2026 14:13
@rjodinchr
rjodinchr merged commit 9c6a203 into google:main Sep 25, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants