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

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

@⁠QuentinDanblon on GitHub · 2026-11-21 21:54 UTC · original
QuentinDanblon:fix/mesh-s3-wave-info → main · +96 −12 · 2 files · 85 commits · closed without merging

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

**@⁠QuentinDanblon** on GitHub · 2026-11-21 21:54 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/58) `QuentinDanblon:fix/mesh-s3-wave-info` → `main` · +96 −12 · 2 files · 85 commits · closed without merging **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
s3 now carries TGsize[31:28] = ceil(threads/wave), the wave index [27:24] and
the per-wave ES vertex / GS primitive counts [7:0]/[15:8] (RDNA2 ISA 3.12.2,
ES+GS SGPR 3; Mesa ac_nir_lower_intrinsics_to_args.c, ac_nir_lower_ngg.c; LLPC
MeshTaskShader.cpp). GS_ALLOC_REQ decodes M0[9:0] vertices and M0[22:12]
primitives (RDNA2 ISA 12.5.1). v5 semantics unchanged; the two readings
(per-lane vertex id vs Mesa/LLPC fast-launch workgroup index) and the evidence
that settles them are documented in mesh_readfirstlane.

Tests: synthetic mesh programs extract s3[31:28] and s3[15:0] for wave64/wave32
at 128, 96 and 80 threads, and a GS_ALLOC_REQ at the 128/128 limit with bits
outside both fields set; WARP and RTX 5090.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:46 +00:00
github-bot closed this pull request 2026-11-26 06:08:46 +00:00
Author
Owner

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

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.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 23:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/58#issuecomment-7070684630) 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.
Author
Owner

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

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.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/58#issuecomment-7079646664) 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

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