xshader on real NVIDIA hardware: RTX 5090 exec 67 pass / 6 fail -> 76 / 0 (ISA-exact fixes, wave32 lane halves, hardware-checked vectors) #61

Closed
github-bot wants to merge 1 commit from gh-pr/61/head into gh-pr/61/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 22:02 UTC · original
QuentinDanblon:fix/nvidia-hw-conformance → main · +210 −0 · 4 files · 107 commits · closed without merging

Library / area: tombox-xshader: results on real NVIDIA hardware

Exports changed (exports.txt rows): none

Source of the behaviour: RDNA2 ISA (an input NaN is returned quieted, denormals follow MODE, wave32 lanes are 0-31). Each NVIDIA behaviour was isolated with small HLSL probes on an RTX 5090. Test vectors in tests/exec_vop/leonida.rs are re-expressed as facts from Leonida's GPU tests (runtime/test/shaders/*.asm, GPL-3.0, no code copied, credited in comments), with encodings from llvm-mc -mcpu=gfx1013. The observation that some drivers run 64-lane fragment subgroups comes from americas-recomp (observation only).

Rebased on 51f5319. This PR now also carries #62 and #64, which I closed to leave one PR for everything that concerns real hardware. Four commits, one per subject.

Results

cargo test -p tombox-xshader --release --test exec, same machine:

adapter main 51f5319 this branch
WARP 73 pass, 0 fail 76 pass, 0 fail
RTX 5090 (TOMBOX_EXEC_HW=1) 67 pass, 6 fail 76 pass, 0 fail
RTX 5090, TOMBOX_DXC_BRANCH_FREE=0 66 pass, 7 fail 76 pass, 0 fail

The 3 extra tests are the new hardware-vector tests. Your evidence mentions an RTX 5060, so the six failures should show up on your machine too.

--test isa_sweep: 541 of 541 on the RTX 5090, and 530 plus the 11 known WARP deviations on WARP, on both main and this branch. --test opcodes 23, --test synthetic 11, --test mixed_table 3, --test mesh 13, --test centroid 1 pass on both adapters.

1. ISA-exact results on NVIDIA (7d6f37c)

Fails on main with the RTX 5090 Cause Fix
vop::basic::vop1_basic: v_trunc/ceil/floor_f32 of NaN give 0x7fffffff, ISA 0x7fc00000 the driver returns its canonical NaN tb_trunc / tb_ceil / tb_floor: integer NaN test, return input | 0x400000
scalar_mode_effects: s_denorm_mode case gives 0x80000000, expected 0xbf800000 floor / ceil treat denormal inputs as zero despite -denorm preserve denormal ranges handled with one unsigned compare
vector_vop3: v_add_nc_i16 gives 0xffffffff, expected 0xabcdffff the driver miscompiles clamp(x,-32768,32767) & 0xffff (the DXIL is correct) sat_int(): clamp in an offset unsigned range, also used by v_sub / mad_i16, cvt_pk_i16_i32 and MTBUF sint packing
vop::trig_preop_f64: 4 denormal results give 0 the driver folds tb_ldexp64's multiply chain at compile time result built from the table bits, tb_ldexp64 marked precise
exec_mem::ds::ds_lds_atomics_ext: ds_sub_u32 / ds_sub_rtn_u32, CreateComputePipelineState 0x8007000e the driver fails on InterlockedAdd of a negated value, whatever the spelling the compare-exchange loop ds_rsub already uses
vop::vopc::vopc_f16 (only with TOMBOX_DXC_BRANCH_FREE=0): v_cmp(x)_nlg/ngt_f16, pipeline creation 0x8007000e the driver fails on fcmp ule/uge when operand bits are partly known negated compares emitted as nan || <ordered complement>, same results

v_log_f32 also returns powers of two exactly (0.25 was one ulp off on hardware).

2. image_get_lod on hardware (f99b40c)

The sixth failure, exec_mem::mimg::image_mimg_query, is not a translator error. CalculateLevelOfDetailUnclamped on the RTX 5090 returns multiples of 1/256, the 8 fractional bits D3D12 specifies (D3D12_MIP_LOD_FRACTIONAL_BIT_COUNT), and 4 - 1/256 (0x407fc000) for the exact 4.0 of the last case. WARP keeps float precision. The test tolerance is one LOD step when TOMBOX_EXEC_HW is set, and stays 1e-5 on WARP.

3. Wave32 lanes on a 64-lane host wave (8630ef2, was #62)

Guest lane numbers were used as absolute host lane indices. On a host that runs 64-lane waves, host lanes 32-63 are a second guest wave and would read or write the first one's lanes.

  • guest_lane(L) = (WaveGetLaneIndex() & ~31) | (L & 31) for wave32 guests, used by v_readlane and v_writelane. Wave64 guests are unchanged.
  • STATUS EXECZ / VCCZ use the ballot word of the lane's own half. The DPP row mask index uses (l >> 4) & 1. GDS ds_append / ds_consume count and elect within the lane's half.
  • On hosts with waves of 32 lanes or fewer the half base is 0: one AND / OR more, same results.
  • No adapter here runs 64-lane waves (RTX 5090, Intel UHD 770, WARP), so the 64-wide case itself is not executed. lane_numbering_follows_guest_wave checks the emitted HLSL.

4. Hardware-checked vectors as exec tests (4d2995d, was #64)

  • Bug found: VOP3P v_pk_lshlrev_b16 (0x404) and v_pk_lshrrev_b16 (0x405) had no decoder name, so a shader using them failed to translate. They are named and translated per the ISA: per-half shift by bits [3:0] of S0's selected half, OPSEL / OPSEL_HI as for the f16 packed ops, NEG / NEG_HI / CLAMP refused.
  • New tests/exec_vop/leonida.rs, each case run with constant and runtime inputs: SDWA vectors, pk shifts, v_add_nc_u16 VOP3 keeping the dst high half, v_sin_f16 keeping the high half, v_mul_legacy_f32 0 x inf and 0 x NaN, s_bfm_b64, 64-bit exec-mask half ops, MUBUF raw bounds.
  • One #[ignore]d test (wave_scc_readfirstlane_isa) documents a known limit of the one-lane-per-invocation model: after s_and_saveexec_b64, SCC and v_readfirstlane are per-lane values, not wave values.

Tests

  • Both adapters, all suites: see Results. --lib: 60 pass. --test ps_linkage: 1 pass.

  • Not run against a title.

  • cargo test -p tombox-xshader passes on WARP and on the RTX 5090

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-21 22:02 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/61) `QuentinDanblon:fix/nvidia-hw-conformance` → `main` · +210 −0 · 4 files · 107 commits · closed without merging **Library / area:** tombox-xshader: results on real NVIDIA hardware **Exports changed (exports.txt rows):** none **Source of the behaviour:** RDNA2 ISA (an input NaN is returned quieted, denormals follow MODE, wave32 lanes are 0-31). Each NVIDIA behaviour was isolated with small HLSL probes on an RTX 5090. Test vectors in `tests/exec_vop/leonida.rs` are re-expressed as facts from Leonida's GPU tests (`runtime/test/shaders/*.asm`, GPL-3.0, no code copied, credited in comments), with encodings from llvm-mc `-mcpu=gfx1013`. The observation that some drivers run 64-lane fragment subgroups comes from americas-recomp (observation only). Rebased on `51f5319`. This PR now also carries #62 and #64, which I closed to leave one PR for everything that concerns real hardware. Four commits, one per subject. ### Results `cargo test -p tombox-xshader --release --test exec`, same machine: | adapter | main 51f5319 | this branch | |---|---|---| | WARP | 73 pass, 0 fail | 76 pass, 0 fail | | RTX 5090 (`TOMBOX_EXEC_HW=1`) | 67 pass, **6 fail** | 76 pass, 0 fail | | RTX 5090, `TOMBOX_DXC_BRANCH_FREE=0` | 66 pass, **7 fail** | 76 pass, 0 fail | The 3 extra tests are the new hardware-vector tests. Your evidence mentions an RTX 5060, so the six failures should show up on your machine too. `--test isa_sweep`: 541 of 541 on the RTX 5090, and 530 plus the 11 known WARP deviations on WARP, on both main and this branch. `--test opcodes` 23, `--test synthetic` 11, `--test mixed_table` 3, `--test mesh` 13, `--test centroid` 1 pass on both adapters. ### 1. ISA-exact results on NVIDIA (`7d6f37c`) | Fails on main with the RTX 5090 | Cause | Fix | |---|---|---| | `vop::basic::vop1_basic`: `v_trunc/ceil/floor_f32` of NaN give 0x7fffffff, ISA 0x7fc00000 | the driver returns its canonical NaN | `tb_trunc` / `tb_ceil` / `tb_floor`: integer NaN test, return input \| 0x400000 | | `scalar_mode_effects`: `s_denorm_mode` case gives 0x80000000, expected 0xbf800000 | floor / ceil treat denormal inputs as zero despite `-denorm preserve` | denormal ranges handled with one unsigned compare | | `vector_vop3`: `v_add_nc_i16` gives 0xffffffff, expected 0xabcdffff | the driver miscompiles `clamp(x,-32768,32767) & 0xffff` (the DXIL is correct) | `sat_int()`: clamp in an offset unsigned range, also used by v_sub / mad_i16, cvt_pk_i16_i32 and MTBUF sint packing | | `vop::trig_preop_f64`: 4 denormal results give 0 | the driver folds `tb_ldexp64`'s multiply chain at compile time | result built from the table bits, `tb_ldexp64` marked `precise` | | `exec_mem::ds::ds_lds_atomics_ext`: `ds_sub_u32` / `ds_sub_rtn_u32`, CreateComputePipelineState 0x8007000e | the driver fails on InterlockedAdd of a negated value, whatever the spelling | the compare-exchange loop `ds_rsub` already uses | | `vop::vopc::vopc_f16` (only with `TOMBOX_DXC_BRANCH_FREE=0`): `v_cmp(x)_nlg/ngt_f16`, pipeline creation 0x8007000e | the driver fails on `fcmp ule/uge` when operand bits are partly known | negated compares emitted as `nan \|\| <ordered complement>`, same results | `v_log_f32` also returns powers of two exactly (0.25 was one ulp off on hardware). ### 2. `image_get_lod` on hardware (`f99b40c`) The sixth failure, `exec_mem::mimg::image_mimg_query`, is not a translator error. `CalculateLevelOfDetailUnclamped` on the RTX 5090 returns multiples of 1/256, the 8 fractional bits D3D12 specifies (`D3D12_MIP_LOD_FRACTIONAL_BIT_COUNT`), and 4 - 1/256 (0x407fc000) for the exact 4.0 of the last case. WARP keeps float precision. The test tolerance is one LOD step when `TOMBOX_EXEC_HW` is set, and stays 1e-5 on WARP. ### 3. Wave32 lanes on a 64-lane host wave (`8630ef2`, was #62) Guest lane numbers were used as absolute host lane indices. On a host that runs 64-lane waves, host lanes 32-63 are a second guest wave and would read or write the first one's lanes. - `guest_lane(L)` = `(WaveGetLaneIndex() & ~31) | (L & 31)` for wave32 guests, used by v_readlane and v_writelane. Wave64 guests are unchanged. - STATUS EXECZ / VCCZ use the ballot word of the lane's own half. The DPP row mask index uses `(l >> 4) & 1`. GDS `ds_append` / `ds_consume` count and elect within the lane's half. - On hosts with waves of 32 lanes or fewer the half base is 0: one AND / OR more, same results. - No adapter here runs 64-lane waves (RTX 5090, Intel UHD 770, WARP), so the 64-wide case itself is not executed. `lane_numbering_follows_guest_wave` checks the emitted HLSL. ### 4. Hardware-checked vectors as exec tests (`4d2995d`, was #64) - **Bug found:** VOP3P `v_pk_lshlrev_b16` (0x404) and `v_pk_lshrrev_b16` (0x405) had no decoder name, so a shader using them failed to translate. They are named and translated per the ISA: per-half shift by bits [3:0] of S0's selected half, OPSEL / OPSEL_HI as for the f16 packed ops, NEG / NEG_HI / CLAMP refused. - New `tests/exec_vop/leonida.rs`, each case run with constant and runtime inputs: SDWA vectors, pk shifts, `v_add_nc_u16` VOP3 keeping the dst high half, `v_sin_f16` keeping the high half, `v_mul_legacy_f32` 0 x inf and 0 x NaN, `s_bfm_b64`, 64-bit exec-mask half ops, MUBUF raw bounds. - One `#[ignore]`d test (`wave_scc_readfirstlane_isa`) documents a known limit of the one-lane-per-invocation model: after `s_and_saveexec_b64`, SCC and `v_readfirstlane` are per-lane values, not wave values. ### Tests - Both adapters, all suites: see Results. `--lib`: 60 pass. `--test ps_linkage`: 1 pass. - Not run against a title. - [x] `cargo test -p tombox-xshader` passes on WARP and on the RTX 5090 - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Facts (inputs and hardware results) from Leonida runtime/test/shaders (ps_sdwa, ps_ops4,
ps_legacy_mul, cs_wm_bfm64, cs_wm_half_ops, cs_wm_half_cmp, cs_wm_scc_rfl, cs_bounds),
re-encoded with llvm-mc gfx1013; no Leonida code copied. ps_ops4 exposed missing VOP3P
packed 16-bit shifts (decoded as vop3<0x404/0x405>): added per RDNA2 ISA with OPSEL/OPSEL_HI.
cs_wm_scc_rfl kept as an ignored ISA test: the lane model makes saveexec SCC and
v_readfirstlane per invocation.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:53 +00:00
github-bot closed this pull request 2026-11-26 06:08:53 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 23:09 UTC · original

Rebased onto 8491769 and re-run on both backends.

--test exec passed failed
main, RTX 5090 61 9
this branch, RTX 5090 67 3
main and this branch, WARP 68 2

The 3 left on hardware are image_mimg_query (LOD precision, as before) plus scalar_sop2 and vop::basic::salu_basic. Those two also fail on main on WARP since 8491769: the s_bfe test oracles were not updated with the translator. #70 fixes them, which would put this branch back at 69 / 1 on the 5090.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 23:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/61#issuecomment-7070684162) Rebased onto `8491769` and re-run on both backends. | `--test exec` | passed | failed | |---|---|---| | main, RTX 5090 | 61 | 9 | | this branch, RTX 5090 | 67 | 3 | | main and this branch, WARP | 68 | 2 | The 3 left on hardware are `image_mimg_query` (LOD precision, as before) plus `scalar_sop2` and `vop::basic::salu_basic`. Those two also fail on main on WARP since `8491769`: the `s_bfe` test oracles were not updated with the translator. #70 fixes them, which would put this branch back at 69 / 1 on the 5090.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR. It is applied in 4f89f4e, 93861d6, b445a1f and 6afb54f (merged in 81a1252) with your authorship kept, thanks! The added comment lines were stripped on the applied copy (the project keeps code free of comment lines).

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/61#issuecomment-7079639744) Main's history was rewritten, which auto-closed this PR. It is applied in 4f89f4e, 93861d6, b445a1f and 6afb54f (merged in 81a1252) with your authorship kept, thanks! The added comment lines were stripped on the applied copy (the project keeps code free of comment lines).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.