xshader: keep VCC when a paired-wave64 v_cmpx narrows EXEC #380

Merged
NathansDomainSolutions merged 1 commit from upstream-pr/380 into main 2026-11-28 09:22:22 +00:00
NathansDomainSolutions commented 2026-11-28 07:55:24 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-11-28T07:55:24Z.


On RDNA2, v_cmpx_* writes EXEC only. GFX10 dropped the VCC/SDST write that GCN's CMPX had. The decoder still gives every VOPC instruction an implicit VccLo destination (runtime/dxbc/src/rdna2/operands.rs). The ordinary emitter handles this correctly (vector_wide.rs writes ExecLo for v_cmpx), but the two-lanes-per-thread translation (paired_wave64.rs) also counted VCC as written and rebuilt it:

vcc_lo = WaveActiveBallot(tbm_vcc_lo[0]).x & tbx_exec_lo[0]; vcc_hi = ...

Here tbx_exec_lo is EXEC before the compare. Every lane another mask had already turned off lost its VCC bit. So a program that sets VCC under a wider EXEC, narrows EXEC (with s_and_saveexec, then v_cmpx), restores EXEC and reads VCC sees zeros there. This translation is what 32-lane hosts (NVIDIA, Intel) run for 64-lane console programs.

Change

For v_cmpx_*, the paired translation now treats EXEC as the only mask written, as the ordinary one does. The per-lane VCC shadows and the two ballots that rebuilt VCC are no longer emitted.

Checks

RTX 4070 (10de:2786), driver 620.73.04, GE-Proton11-14, on cba382c.

  • New case cmpx_vcc (and cmpx_vcc_half) in tools/check_paired_wave64.py. It sets VCC, narrows EXEC with s_and_saveexec, narrows it again with v_cmpx, restores EXEC, then runs v_cndmask/s_bcnt1 on VCC. The reference model already treats CMPX as EXEC-only.
    • main: FAIL: 2 of 51 programs, WRONG cmpx_vcc: wave 2 lane 0 s20 got 3 wanted 8 and WRONG cmpx_vcc_half: wave 4 lane 0 s20 got 0 wanted 13.
    • This branch: PASS: 51 programs, 3342336 words.
  • tools/check_translator_gpu.py (all checks): 59 of 59 passed.
  • tuxbox.py verify --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute: 28 of 28 passed.
  • tuxbox.py check --no-gpu: all passed.
  • host_profiles.txt was re-blessed. The rows that changed are paired (two-lanes) and wave32-host translations of programs containing a v_cmpx. Every one of them does, because the check's prologue starts each program with one. The only differences are the removed VCC shadows and ballots.

Effect on recorded requests. Over the 394 _w32 requests ProjectScarlett 1.0.2.1 made on this card in a live run, 342 translations change and 52 are identical. Their HLSL total goes from 167.3 MB to 163.9 MB, which is two fewer wave ballots per v_cmpx. I didn't work out which of the 342 actually read VCC after the narrowed region, so the visible effect in the game is unmeasured.

Missing: an AMD run. 64-lane AMD hosts don't take this path unless forced with TUXBOX_HOST_PROFILE, so the result shouldn't depend on the vendor, but CONTRIBUTING asks for both.

AI-assisted: found and written with Claude Code (Claude Opus 5.5). I reviewed the change and ran the checks above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5538089244 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/380). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-11-28T07:55:24Z. --- On RDNA2, `v_cmpx_*` writes **EXEC only**. GFX10 dropped the VCC/SDST write that GCN's CMPX had. The decoder still gives every VOPC instruction an implicit `VccLo` destination (`runtime/dxbc/src/rdna2/operands.rs`). The ordinary emitter handles this correctly (`vector_wide.rs` writes `ExecLo` for `v_cmpx`), but the two-lanes-per-thread translation (`paired_wave64.rs`) also counted VCC as written and rebuilt it: ```hlsl vcc_lo = WaveActiveBallot(tbm_vcc_lo[0]).x & tbx_exec_lo[0]; vcc_hi = ... ``` Here `tbx_exec_lo` is EXEC before the compare. Every lane another mask had already turned off lost its VCC bit. So a program that sets VCC under a wider EXEC, narrows EXEC (with `s_and_saveexec`, then `v_cmpx`), restores EXEC and reads VCC sees zeros there. This translation is what 32-lane hosts (NVIDIA, Intel) run for 64-lane console programs. ## Change For `v_cmpx_*`, the paired translation now treats EXEC as the only mask written, as the ordinary one does. The per-lane VCC shadows and the two ballots that rebuilt VCC are no longer emitted. ## Checks RTX 4070 (`10de:2786`), driver 620.73.04, GE-Proton11-14, on `cba382c`. - **New case** `cmpx_vcc` (and `cmpx_vcc_half`) in `tools/check_paired_wave64.py`. It sets VCC, narrows EXEC with `s_and_saveexec`, narrows it again with `v_cmpx`, restores EXEC, then runs `v_cndmask`/`s_bcnt1` on VCC. The reference model already treats CMPX as EXEC-only. - `main`: `FAIL: 2 of 51 programs`, `WRONG cmpx_vcc: wave 2 lane 0 s20 got 3 wanted 8` and `WRONG cmpx_vcc_half: wave 4 lane 0 s20 got 0 wanted 13`. - This branch: `PASS: 51 programs, 3342336 words`. - `tools/check_translator_gpu.py` (all checks): 59 of 59 passed. - `tuxbox.py verify --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-bindless-compute`: 28 of 28 passed. - `tuxbox.py check --no-gpu`: all passed. - `host_profiles.txt` was re-blessed. The rows that changed are paired (`two-lanes`) and `wave32-host` translations of programs containing a `v_cmpx`. Every one of them does, because the check's prologue starts each program with one. The only differences are the removed VCC shadows and ballots. **Effect on recorded requests.** Over the 394 `_w32` requests ProjectScarlett 1.0.2.1 made on this card in a live run, 342 translations change and 52 are identical. Their HLSL total goes from 167.3 MB to 163.9 MB, which is two fewer wave ballots per `v_cmpx`. I didn't work out which of the 342 actually read VCC after the narrowed region, so the visible effect in the game is unmeasured. **Missing:** an AMD run. 64-lane AMD hosts don't take this path unless forced with `TUXBOX_HOST_PROFILE`, so the result shouldn't depend on the vendor, but CONTRIBUTING asks for both. AI-assisted: found and written with Claude Code (Claude Opus 5.5). I reviewed the change and ran the checks above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!380
No description provided.