xshader mesh: full merged_wave_info in s3, GS_ALLOC_REQ field widths per ISA, v5 readings documented #58

Closed
QuentinDanblon wants to merge 0 commits from upstream-pr/58 into main
QuentinDanblon commented 2026-11-21 21:54:11 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T21:54:11Z.


Library / area: tombox-xshader mesh stage (hlsl/mesh.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: RDNA2 ISA §3.12.2 (GS SGPR 3 layout) and §12.5.1 (GS_ALLOC_REQ M0 fields); Mesa main ef594386 (ac_nir_lower_intrinsics_to_args.c, ac_nir_lower_ngg.c, ac_nir_lower_ngg_mesh.c, MIT); LLPC MeshTaskShader.cpp. Leonida (GPL, used as an observation only) measured that every GTA VI mesh shader reads s3 arithmetically.

Changes

  • s3 = merged_wave_info, all fields. Before, only the wave index [27:24] was set ((gi / w) << 24), so a shader reading waves-per-group [31:28] got 0. Now s3 = ceil(n/w) << 28 | (gi/w) << 24 | min(w, n − wave_base) * 0x101:

    • waves per group = ceil(n/w) in [31:28];
    • the wave's live thread count in both [15:8] (GSPrimCount) and [7:0] (ESVertCount);
    • GSWaveID [23:16] stays 0, because mesh shaders already refuse the GS ring messages.

    The per-wave counts depend on how the driver programs the GE, like v5. They are filled to agree with the existing per-lane v5 reading; under Mesa/LLPC programming they would read 1/1 in wave 0. The code comment says this.

  • GS_ALLOC_REQ decode now uses the ISA widths: vertices m0 & 0x3ff (M0[9:0]), primitives (m0 >> 12) & 0x7ff (M0[22:12]). It used 12-bit fields. Mesa/LLPC describe vertices as 11 bits; bit 10 only matters above 1023 vertices, which no mesh limit allows. The comment records the difference.

  • v5 unchanged, both readings documented. Mesa RADV and LLPC (gfx10.x legacy FAST_LAUNCH) put the flat workgroup index in v5, with citations in the comment. The translator assumes gid.x*threads + tid. That depends on how the console driver programs the GE, which isn't public. The comment says what would settle it: how GTA VI consumes v_readfirstlane_b32 sX, v5 (a shift by log2(threads) vs direct use).

Tests (tests/mesh.rs, synthetic, no fixtures; encodings checked with llvm-mc gfx1013)

  • gpu_mesh_merged_wave_info_fields: extracts s3[31:28] and s3[15:0] and renders them. Expected: wave64×128 → [0x4040, 2], wave32×128 → [0x2020, 4], wave64×96 → [0x2020, 2], wave32×80 → [0x1010, 3].

  • gpu_mesh_alloc_req_counts_at_limit_ignore_bits_outside_fields: counts at the PSO limit, with bit 11 and bits 23-31 set.

  • WARP: --test mesh 15 passed (1 fixture test ignored). RTX 5090 (TOMBOX_EXEC_HW=1): 15 passed, every GPU test rendering on hardware. --lib 17, --test opcodes 22.

  • cargo test -p tombox-xshader --test mesh passes on WARP and hardware

  • No game or console files and no binaries included

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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6534879457 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/58). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T21:54:11Z. --- **Library / area:** tombox-xshader mesh stage (`hlsl/mesh.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** RDNA2 ISA §3.12.2 (GS SGPR 3 layout) and §12.5.1 (GS_ALLOC_REQ M0 fields); Mesa main ef594386 (`ac_nir_lower_intrinsics_to_args.c`, `ac_nir_lower_ngg.c`, `ac_nir_lower_ngg_mesh.c`, MIT); LLPC `MeshTaskShader.cpp`. Leonida (GPL, used as an observation only) measured that every GTA VI mesh shader reads s3 arithmetically. ### Changes - **s3 = merged_wave_info, all fields.** Before, only the wave index [27:24] was set (`(gi / w) << 24`), so a shader reading waves-per-group [31:28] got 0. Now `s3 = ceil(n/w) << 28 | (gi/w) << 24 | min(w, n − wave_base) * 0x101`: - waves per group = ceil(n/w) in [31:28]; - the wave's live thread count in both [15:8] (GSPrimCount) and [7:0] (ESVertCount); - GSWaveID [23:16] stays 0, because mesh shaders already refuse the GS ring messages. The per-wave counts depend on how the driver programs the GE, like v5. They are filled to agree with the existing per-lane v5 reading; under Mesa/LLPC programming they would read 1/1 in wave 0. The code comment says this. - **GS_ALLOC_REQ decode** now uses the ISA widths: vertices `m0 & 0x3ff` (M0[9:0]), primitives `(m0 >> 12) & 0x7ff` (M0[22:12]). It used 12-bit fields. Mesa/LLPC describe vertices as 11 bits; bit 10 only matters above 1023 vertices, which no mesh limit allows. The comment records the difference. - **v5 unchanged, both readings documented.** Mesa RADV and LLPC (gfx10.x legacy FAST_LAUNCH) put the flat workgroup index in v5, with citations in the comment. The translator assumes `gid.x*threads + tid`. That depends on how the console driver programs the GE, which isn't public. The comment says what would settle it: how GTA VI consumes `v_readfirstlane_b32 sX, v5` (a shift by log2(threads) vs direct use). ### Tests (`tests/mesh.rs`, synthetic, no fixtures; encodings checked with llvm-mc gfx1013) - `gpu_mesh_merged_wave_info_fields`: extracts s3[31:28] and s3[15:0] and renders them. Expected: wave64×128 → [0x4040, 2], wave32×128 → [0x2020, 4], wave64×96 → [0x2020, 2], wave32×80 → [0x1010, 3]. - `gpu_mesh_alloc_req_counts_at_limit_ignore_bits_outside_fields`: counts at the PSO limit, with bit 11 and bits 23-31 set. - WARP: `--test mesh` 15 passed (1 fixture test ignored). RTX 5090 (`TOMBOX_EXEC_HW=1`): 15 passed, every GPU test rendering on hardware. `--lib` 17, `--test opcodes` 22. - [x] `cargo test -p tombox-xshader --test mesh` passes on WARP and hardware - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
QuentinDanblon commented 2026-11-21 23:09:35 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T23:09:35Z.


Rebased onto 8491769. --test mesh gives 12 passed, 3 failed on WARP and on the RTX 5090. Main gives 10 passed, 3 failed with the same three tests (mesh_divergent_barrier_with_lds_is_refused, mesh_divergent_barrier_with_memory_store_is_refused, gpu_mesh_divergent_barrier_without_memory_writes), since the new rule that closes the conditional block before an s_barrier. The two tests this PR adds pass. Details on the three are at the end of #70; I left them alone.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7070684630 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/58#issuecomment-7070684630). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T23:09:35Z. --- Rebased onto `8491769`. `--test mesh` gives 12 passed, 3 failed on WARP and on the RTX 5090. Main gives 10 passed, 3 failed with the same three tests (`mesh_divergent_barrier_with_lds_is_refused`, `mesh_divergent_barrier_with_memory_store_is_refused`, `gpu_mesh_divergent_barrier_without_memory_writes`), since the new rule that closes the conditional block before an `s_barrier`. The two tests this PR adds pass. Details on the three are at the end of #70; I left them alone.
omonkeyz commented 2026-11-22 13:12:43 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:43Z.


Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please remove the 45 comment lines, including the game-specific references. Code must not name titles or game corpora. The code change itself looks right. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079646664 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/58#issuecomment-7079646664). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:12:43Z. --- Main's history was rewritten, which auto-closed this PR (sorry for the noise). Please remove the 45 comment lines, including the game-specific references. Code must not name titles or game corpora. The code change itself looks right. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

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
omonkeyz/xbox-emulator!58
No description provided.