Recompiler: translate v_cvt_off_f32_i4 #817

Open
github-bot wants to merge 1 commit from github-bot/gh-817 into main AGit
Owner

@⁠mastrr9 on GitHub · 2026-11-24 05:51 UTC · original
mastrr9:feat/recomp-cvt-off-f32-i4 → main · +39 −0 · 2 files · 1 commits · open

Draft pending scripts/smoke.ps1 regression blocks on a retail title (welcome from anyone with a title, or will be added once available).

v_cvt_off_f32_i4 was previously reported unsupported (VALU), preventing shaders that use it from translating.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: translates v_cvt_off_f32_i4 by sign-extending S0[3:0] (ignoring upper bits) and multiplying by 0.0625f (-0.5 .. 0.4375, exact), routed through fres so VOP3 clamp and omod apply.
  • crates/xcl/src/gpu/recomp/tests.rs: HLSL + DXC compile check (v_cvt_off_f32_i4_sign_extends_the_low_nibble) and cross-GPU wave test (gpu_v_cvt_off_f32_i4) checking all 16 signed nibbles with junk upper bits, plain and with VOP3 omod * 2.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command (at head ecb821f3453c921be8030622ed57f298cc957268): cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 706 passed, 0 failed, 41 ignored (0 new warnings).
    • gpu::recomp::tests::v_cvt_off_f32_i4_sign_extends_the_low_nibble — ok
    • gpu::recomp::tests::gpu_v_cvt_off_f32_i4 — ok (executed on RTX 5080, not skipped)
  • SKIPPED (2): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64).

Not tested

  • scripts/smoke.ps1 regression runs on a retail title (hence draft), AMD/wave64 hardware, and release build.

AI use

  • Claude Opus 5.5 (via Claude Duet / Claude Code) wrote the emit.rs translation and initial tests.
  • Antigravity (Gemini 4 Neon & Gemini 4 Hydrogen) audited the RDNA2 ISA semantics, fixed the GPU test to use runner::run_code for wave32 GPUs, verified the full Windows RTX 5080 MSVC + D3D12 debug-layer workspace suite, and drafted this PR description.
**@⁠mastrr9** on GitHub · 2026-11-24 05:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/817) `mastrr9:feat/recomp-cvt-off-f32-i4` → `main` · +39 −0 · 2 files · 1 commits · open Draft pending `scripts/smoke.ps1` regression blocks on a retail title (welcome from anyone with a title, or will be added once available). `v_cvt_off_f32_i4` was previously reported unsupported (`VALU`), preventing shaders that use it from translating. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: translates `v_cvt_off_f32_i4` by sign-extending `S0[3:0]` (ignoring upper bits) and multiplying by `0.0625f` (`-0.5` .. `0.4375`, exact), routed through `fres` so VOP3 `clamp` and `omod` apply. - `crates/xcl/src/gpu/recomp/tests.rs`: HLSL + DXC compile check (`v_cvt_off_f32_i4_sign_extends_the_low_nibble`) and cross-GPU wave test (`gpu_v_cvt_off_f32_i4`) checking all 16 signed nibbles with junk upper bits, plain and with VOP3 `omod * 2`. **Tested** - **Environment:** NVIDIA GeForce RTX 5080 (16 GB, wave32, driver `617.42` / `32.0.16.1742`), Windows 11 Pro 25H2 (`26200.9974`), D3D12 debug layer installed (`d3d12SDKLayers.dll`), `rustc 1.100.0 (0ef1bc386 2026-11-09)` MSVC, DXC from Windows SDK `10.0.26100.0`, debug build. - **Command (at head `ecb821f3453c921be8030622ed57f298cc957268`):** `cargo build --workspace && cargo test --workspace -- --test-threads=4` - **Result:** **706 passed, 0 failed, 41 ignored** (0 new warnings). - `gpu::recomp::tests::v_cvt_off_f32_i4_sign_extends_the_low_nibble` — `ok` - `gpu::recomp::tests::gpu_v_cvt_off_f32_i4` — `ok` (executed on RTX 5080, not skipped) - **SKIPPED (2):** `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` (`no wave64`), `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (`no wave64`). **Not tested** - `scripts/smoke.ps1` regression runs on a retail title (hence draft), AMD/wave64 hardware, and release build. **AI use** - Claude Opus 5.5 (via Claude Duet / Claude Code) wrote the `emit.rs` translation and initial tests. - Antigravity (Gemini 4 Neon & Gemini 4 Hydrogen) audited the RDNA2 ISA semantics, fixed the GPU test to use `runner::run_code` for wave32 GPUs, verified the full Windows RTX 5080 MSVC + D3D12 debug-layer workspace suite, and drafted this PR description.
v_cvt_off_f32_i4 was reported unsupported (VALU). It converts the
signed 4-bit value in S0[3:0] to float and divides by 16, giving -0.5
to 0.4375; the bits above the nibble are ignored. Emitted as a sign
extension by shifts and an exact multiply by 0.0625, through fres so
VOP3 clamp and omod apply.

Tests: v_cvt_off_f32_i4_sign_extends_the_low_nibble checks the HLSL
and compiles it with DXC when present; gpu_v_cvt_off_f32_i4 runs all
16 nibbles with junk in the upper bits, plain and with omod *2. Not
built or run on Windows.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:33 +00:00
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 06:41 UTC · original

2|
3|AMD/wave64 + release-build datapoint - the two axes your row lists as not tested.
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross x86_64-pc-windows-gnu, release profile, XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.
6|
7|Merged state: head ecb821f onto main beaa245, clean merge.
8|
9|Full suite, cargo test --workspace --release --no-fail-fast -- --test-threads=4: 705 passed, 10 failed, 41 ignored (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio firing that run (~2/5 rate, PR-independent). Nothing new fails. Your tests pass on RDNA3: gpu_v_cvt_off_f32_i4 ok, v_cvt_off_f32_i4_sign_extends_the_low_nibble ok.
10|
11|Not tested: retail titles (none here), Windows, RDNA4.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-24 06:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7124191800) 2| 3|AMD/wave64 + release-build datapoint - the two axes your row lists as not tested. 4| 5|**Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross `x86_64-pc-windows-gnu`, **release** profile, `XCL_NETWORK=0`, native wave64. Same rig as my Linux rows in #42 / #718. 6| 7|**Merged state:** head `ecb821f` onto main `beaa245`, clean merge. 8| 9|**Full suite, `cargo test --workspace --release --no-fail-fast -- --test-threads=4`:** **705 passed, 10 failed, 41 ignored** (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the #718 flaky trio firing that run (~2/5 rate, PR-independent). Nothing new fails. Your tests pass on RDNA3: `gpu_v_cvt_off_f32_i4` ok, `v_cvt_off_f32_i4_sign_extends_the_low_nibble` ok. 10| 11|**Not tested:** retail titles (none here), Windows, RDNA4. 12|Counts only, no game data. 13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Author
Owner

@⁠4usphs on GitHub · 2026-11-24 09:41 UTC · original

Measured on RDNA2 hardware: v_cvt_off_f32_i4 gives S0[3:0] (signed) / 16 as translated here, and applies omod and clamp. One condition applies to omod; see below.

Method. The Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL 3652.0 (PAL,LC). Each instruction runs as inline RDNA2 assembly in an OpenCL C kernel (the #518 / #772 method), one input per work-item, in wave32 and wave64. The inputs are all 16 nibbles, 4 times each, with junk in bits 4..31 (0xABCDEF7n / 0x1234568n, as in this PR's test).

Result.

  • Plain v_cvt_off_f32_i4: all 64 match (float)(((int)(S0 << 28)) >> 28) * 0.0625f, with values -0.5 … 0.4375, and wave32 = wave64.
  • clamp: all 64 give the clamped value.
  • mul:2 / div:2: all 64 give the modified value when MODE has IEEE = 0 and f32 denormals off (MODE 0x000 or 0x0c0, set with s_setreg_imm32_b32 and read back). With IEEE = 1 or f32 denormals on, which is OpenCL's default 0x3f0, the hardware ignores omod. It gives the unmodified value (mul:4 too). The same happens for v_cvt_f32_i32 and v_cvt_f32_ubyte0, so this is the general RDNA2 omod rule, not something of this instruction. So this PR's omod *2 expectation is right for the mode console shaders normally run in.
MODE f32 denorm IEEE omod applied
0x000, 0x0c0 off 0 yes (64/64)
0x030, 0x0f0 on 0 no
0x200 … 0x3f0 any 1 no

A note outside this PR: out_mods in emit.rs applies omod regardless of the program's float mode. That only matters for a console program that runs with IEEE mode or f32 denormals on and still has omod set. I have not checked whether any does.

For comparison, an RX 9070 XT (gfx1201, RDNA4, OpenCL 3686.0) gives the same conversion and applies omod even in OpenCL's default mode.

Not tested: the console itself (gfx1036 is a desktop RDNA2 APU of the same generation), RDNA1, this PR's D3D12 tests on this GPU, smoke or a title.

AI use: Claude Code (Claude Opus 5.5) wrote the OpenCL probes, ran them on my PC and wrote this comment. I have not reviewed the code.

**@⁠4usphs** on GitHub · 2026-11-24 09:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7127762728) Measured on RDNA2 hardware: `v_cvt_off_f32_i4` gives `S0[3:0]` (signed) / 16 as translated here, and applies omod and clamp. One condition applies to omod; see below. **Method.** The Radeon iGPU of a Ryzen 7 9800X3D (`gfx1036`, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL `3652.0 (PAL,LC)`. Each instruction runs as inline RDNA2 assembly in an OpenCL C kernel (the #518 / #772 method), one input per work-item, in wave32 and wave64. The inputs are all 16 nibbles, 4 times each, with junk in bits 4..31 (`0xABCDEF7n` / `0x1234568n`, as in this PR's test). **Result.** - Plain `v_cvt_off_f32_i4`: all 64 match `(float)(((int)(S0 << 28)) >> 28) * 0.0625f`, with values -0.5 … 0.4375, and wave32 = wave64. - `clamp`: all 64 give the clamped value. - `mul:2` / `div:2`: all 64 give the modified value **when MODE has IEEE = 0 and f32 denormals off** (MODE `0x000` or `0x0c0`, set with `s_setreg_imm32_b32` and read back). With IEEE = 1 or f32 denormals on, which is OpenCL's default `0x3f0`, the hardware ignores omod. It gives the unmodified value (`mul:4` too). The same happens for `v_cvt_f32_i32` and `v_cvt_f32_ubyte0`, so this is the general RDNA2 omod rule, not something of this instruction. So this PR's `omod *2` expectation is right for the mode console shaders normally run in. | MODE | f32 denorm | IEEE | omod applied | |---|---:|---:|---| | `0x000`, `0x0c0` | off | 0 | yes (64/64) | | `0x030`, `0x0f0` | on | 0 | no | | `0x200` … `0x3f0` | any | 1 | no | A note outside this PR: `out_mods` in `emit.rs` applies omod regardless of the program's float mode. That only matters for a console program that runs with IEEE mode or f32 denormals on and still has omod set. I have not checked whether any does. For comparison, an RX 9070 XT (`gfx1201`, RDNA4, OpenCL `3686.0`) gives the same conversion and applies omod even in OpenCL's default mode. **Not tested:** the console itself (`gfx1036` is a desktop RDNA2 APU of the same generation), RDNA1, this PR's D3D12 tests on this GPU, smoke or a title. **AI use:** Claude Code (Claude Opus 5.5) wrote the OpenCL probes, ran them on my PC and wrote this comment. I have not reviewed the code.
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 14:38 UTC · original

@⁠4usphs Thank you for measuring v_cvt_off_f32_i4 directly on RDNA2 (gfx1036) silicon! Really helpful confirmation that the nibble conversion, clamp, and omod behavior match the console's normal float mode.

**@⁠mastrr9** on GitHub · 2026-11-24 14:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7134699339) @⁠4usphs Thank you for measuring `v_cvt_off_f32_i4` directly on RDNA2 (`gfx1036`) silicon! Really helpful confirmation that the nibble conversion, clamp, and `omod` behavior match the console's normal float mode.
Author
Owner

@⁠Toons29 on GitHub · 2026-11-25 03:01 UTC · original

Regression run of 83116a8a on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 83116a8adb31b38885128b1e22d0b97feb53263a
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14868 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

**@⁠Toons29** on GitHub · 2026-11-25 03:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7151522650) Regression run of `83116a8a` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 83116a8adb31b38885128b1e22d0b97feb53263a gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1619 (PresentX 1619) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14868 MB ``` Against the limits in CONTRIBUTING.md: 100 % of `main`'s frames, 100 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:48 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 10:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7160199624) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 03:00 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 03:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7181308860) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/817/head:github-bot/gh-817'
git switch 'github-bot/gh-817'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-817'
git switch 'github-bot/gh-817'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-817'
git switch 'github-bot/gh-817'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-817'
git switch 'main'
git merge --squash 'github-bot/gh-817'
git switch 'main'
git merge --ff-only 'github-bot/gh-817'
git switch 'main'
git merge 'github-bot/gh-817'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.