sysgpu: implement select() intrinsic for HLSL, MSL, and SPIR-V #1436

Open
Crispigt wants to merge 2 commits from Crispigt/sysgpu/hlsl-select into main
Crispigt commented 2025-11-24 10:54:42 +00:00 (Migrated from github.com)
  • By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.

This PR implements the select() intrinsic for HLSL, MSL, and SPIR-V. It also fixes a missing boolean implementation in MSL.

Fixes a panic when compiling shaders using WGSL select().

  • HLSL: Mapped to the ternary operator (cond ? true : false).
  • MSL: Mapped to metal::select(false, true, cond).
    • Fix: Implemented emitBool for MSL (was previously commented out and not implemented), required for select conditions using literals.
  • SPIR-V: Emits OpSelect (OpCode 69).

Left GLSL unimplemented for now as the test suite appears commented out in test.zig, so I figured I wouldn't implement it.

Tested Verified output generation locally for HLSL, MSL, and SPIR-V using a simple test case.
Validated runtime behavior for HLSL and SPIR-V, by rendering a checkered triangle (using select in the fragment shader) on Windows 11 with an AMD Radeon RX 7900 XTX.

- [x] By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right. This PR implements the `select()` intrinsic for HLSL, MSL, and SPIR-V. It also fixes a missing boolean implementation in MSL. Fixes a panic when compiling shaders using WGSL `select()`. * HLSL: Mapped to the ternary operator `(cond ? true : false)`. * MSL: Mapped to `metal::select(false, true, cond)`. * Fix: Implemented `emitBool` for MSL (was previously commented out and not implemented), required for `select` conditions using literals. * SPIR-V: Emits `OpSelect` (OpCode 69). Left GLSL unimplemented for now as the test suite appears commented out in `test.zig`, so I figured I wouldn't implement it. Tested Verified output generation locally for HLSL, MSL, and SPIR-V using a simple test case. Validated runtime behavior for HLSL and SPIR-V, by rendering a checkered triangle (using `select` in the fragment shader) on Windows 11 with an AMD Radeon RX 7900 XTX.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin Crispigt/sysgpu/hlsl-select:Crispigt/sysgpu/hlsl-select
git switch Crispigt/sysgpu/hlsl-select

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff Crispigt/sysgpu/hlsl-select
git switch Crispigt/sysgpu/hlsl-select
git rebase main
git switch main
git merge --ff-only Crispigt/sysgpu/hlsl-select
git switch Crispigt/sysgpu/hlsl-select
git rebase main
git switch main
git merge --no-ff Crispigt/sysgpu/hlsl-select
git switch main
git merge --squash Crispigt/sysgpu/hlsl-select
git switch main
git merge --ff-only Crispigt/sysgpu/hlsl-select
git switch main
git merge Crispigt/sysgpu/hlsl-select
git push origin main
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach!1436
No description provided.