Recompiler: translate v_cvt_off_f32_i4 #811

Closed
mastrr9 wants to merge 1 commit from upstream-pr/817 into main
mastrr9 commented 2026-11-24 05:51:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T05:51:00Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5466883807 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817). Originally posted by [mastrr9](https://github.com/mastrr9) on 2026-11-24T05:51:00Z. --- 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.
SlopTart commented 2026-11-24 07:06:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T06:41:26Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7124191800 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/817#issuecomment-7124191800). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-24T06:41:26Z. --- 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.
4usphs commented 2026-11-24 10:04:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by 4usphs on 2026-11-24T09:41:48Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7127762728 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/817#issuecomment-7127762728). Originally posted by [4usphs](https://github.com/4usphs) on 2026-11-24T09:41:48Z. --- 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.
mastrr9 commented 2026-11-24 15:05:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T14:38:11Z.


@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.

<!-- greyfinch-sync:ivall/xcl:comment:7134699339 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/817#issuecomment-7134699339). Originally posted by [mastrr9](https://github.com/mastrr9) on 2026-11-24T14:38:11Z. --- @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.
Toons29 commented 2026-11-25 03:05:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:01:59Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7151522650 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7151522650). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:01:59Z. --- 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.
DavidM1911 commented 2026-11-25 11:09:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:48:29Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7160199624 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7160199624). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T10:48:29Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
DavidM1911 commented 2026-11-26 03:06:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:00:17Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7181308860 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7181308860). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T03:00:17Z. --- 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
github-actions[bot] commented 2026-11-30 08:41:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:41:39Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273226042 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7273226042). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:41:39Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:11:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:11:40Z.


Triage (#1607) – head 2c02b88

Main already translates v_cvt_off_f32_i4. Commit d7df3f9 (#2241) emits (float)((int)({a} << 28) >> 28) * 0.0625f in recomp/emit.rs, the same lowering as here, and also lowers it in the direct-DXIL path (dxil/lower_valu.rs). Its test checks values read from RDNA2 hardware.
Recommendation: close (superseded by main commit d7df3f9 / #2241).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7300475728 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7300475728). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:11:40Z. --- **Triage (#1607)** – head 2c02b88 Main already translates `v_cvt_off_f32_i4`. Commit d7df3f9 (#2241) emits `(float)((int)({a} << 28) >> 28) * 0.0625f` in recomp/emit.rs, the same lowering as here, and also lowers it in the direct-DXIL path (dxil/lower_valu.rs). Its test checks values read from RDNA2 hardware. Recommendation: close (superseded by main commit d7df3f9 / #2241). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:39:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:39:39Z.


Closing as superseded: this change is already on main (d7df3f9). main emit.rs translates v_cvt_off_f32_i4 as sign-extended nibble * 0.0625 and has hardware-value tests; PR is the same expression

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311461861 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/817#issuecomment-7311461861). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:39:39Z. --- Closing as superseded: this change is already on `main` (d7df3f9). main emit.rs translates v_cvt_off_f32_i4 as sign-extended nibble * 0.0625 and has hardware-value tests; PR is the same expression Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
xcl-dev/xcl!811
No description provided.