tombox-xshader: support 256-thread mesh shaders and per-primitive PSG1 outputs #172

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

@⁠GDAgent on GitHub · 2026-11-22 17:50 UTC · original
GDAgent:fix/xshader-mesh-256-and-prim-outputs → main · +213 −39 · 16 files · 1 commits · closed without merging

Library / area: tombox-xshader (meta.rs, dxil_meta.rs, lib.rs, gcn.rs, hlsl.rs, hlsl/mesh.rs, tests/mesh.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: Xbox Series (dxc_xs) mesh shaders can use up to 256 threads per threadgroup ([numthreads(256, 1, 1)] with max_vertices = 256, max_primitives = 128, observed on UE5 Nanite HWRasterizeMS) and export per-primitive attributes declared in the DXBC PSG1 chunk on parameter export targets immediately following the vertex OSG1 parameter slots (target = 32 + out_params.len() + prim_param_idx). PC D3D12 SM 6.5 caps mesh-shader threadgroups at 128 threads ([numthreads(128, 1, 1)]) while still allowing 256 output vertices and per-primitive attributes in out primitives.

Changes:

  • Allow even mesh-shader (stage == 13) threadgroup sizes in 129..=256 in meta::mesh_thread_count_for while keeping amplification shaders (stage == 14) and odd sizes capped at 1..=128.
  • When a mesh shader has 129..=256 threads and does not use LDS, emit [numthreads(n/2, 1, 1)] and execute a two-pass loop (tb_gi = gi + tb_iter * (n/2)) keeping wave32/wave64 lane geometry intact, then call SetMeshOutputCounts once and emit both passes' vertex and primitive outputs (guarding the second pass's indices against max_vertices / max_primitives). Refuse >128-thread mesh shaders that use LDS rather than risking broken cross-pass synchronization.
  • Parse PSG1 / PSGN into ShaderExtract::prim_sig, emit per-primitive fields into struct SPrim, and route exp targets 32 + out_params.len() .. in mesh shaders to tb_pout. Refuse prim_vectors != 0 without PSG1 and refuse per-primitive system values.
  • Add mesh_256_threads_and_per_primitive_outputs_compile_with_dxc in tests/mesh.rs covering 256-thread virtualization, PSG1 per-primitive attributes, DXC compilation, and both refusal paths.

Tests:

  • cargo test --release -p tombox-xshader --lib: 79 passed, 0 failed, 2 ignored (GPU-only FMA probe tests).
  • cargo test --release -p tombox-xshader --test mesh -- --skip gpu_: 15 passed, 0 failed, 1 ignored (local dump fixture).
  • cargo test --release -p tombox-xshader --test synthetic: 21 passed, 0 failed (plus cargo test --no-run across all tombox-xshader test targets).
  • Verified locally that the previously failing retail UE5 HWRasterizeMS ([numthreads(256, 1, 1)], PSG1 TEXCOORD7) translates and compiles cleanly with DXC (ms_6_5).
  • Native Windows 11; not run under Proton.

Not verified in a title: live rendered pixels of the translated 256-thread mesh shader have not been visually verified yet beyond DXC compilation and the unit tests above.

  • cargo test -p tombox-xshader passes
  • No game or console files and no binaries included
  • No fake success; >128-thread mesh shaders using LDS and per-primitive system values are explicitly refused
**@⁠GDAgent** on GitHub · 2026-11-22 17:50 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/172) `GDAgent:fix/xshader-mesh-256-and-prim-outputs` → `main` · +213 −39 · 16 files · 1 commits · closed without merging **Library / area:** tombox-xshader (`meta.rs`, `dxil_meta.rs`, `lib.rs`, `gcn.rs`, `hlsl.rs`, `hlsl/mesh.rs`, `tests/mesh.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** Xbox Series (`dxc_xs`) mesh shaders can use up to 256 threads per threadgroup (`[numthreads(256, 1, 1)]` with `max_vertices = 256`, `max_primitives = 128`, observed on UE5 Nanite `HWRasterizeMS`) and export per-primitive attributes declared in the DXBC `PSG1` chunk on parameter export targets immediately following the vertex `OSG1` parameter slots (`target = 32 + out_params.len() + prim_param_idx`). PC D3D12 SM 6.5 caps mesh-shader threadgroups at 128 threads (`[numthreads(128, 1, 1)]`) while still allowing 256 output vertices and per-primitive attributes in `out primitives`. Changes: - Allow even mesh-shader (`stage == 13`) threadgroup sizes in `129..=256` in `meta::mesh_thread_count_for` while keeping amplification shaders (`stage == 14`) and odd sizes capped at `1..=128`. - When a mesh shader has `129..=256` threads and does not use LDS, emit `[numthreads(n/2, 1, 1)]` and execute a two-pass loop (`tb_gi = gi + tb_iter * (n/2)`) keeping wave32/wave64 lane geometry intact, then call `SetMeshOutputCounts` once and emit both passes' vertex and primitive outputs (guarding the second pass's indices against `max_vertices` / `max_primitives`). Refuse `>128`-thread mesh shaders that use LDS rather than risking broken cross-pass synchronization. - Parse `PSG1` / `PSGN` into `ShaderExtract::prim_sig`, emit per-primitive fields into `struct SPrim`, and route `exp` targets `32 + out_params.len() ..` in mesh shaders to `tb_pout`. Refuse `prim_vectors != 0` without `PSG1` and refuse per-primitive system values. - Add `mesh_256_threads_and_per_primitive_outputs_compile_with_dxc` in `tests/mesh.rs` covering 256-thread virtualization, `PSG1` per-primitive attributes, DXC compilation, and both refusal paths. Tests: - `cargo test --release -p tombox-xshader --lib`: 79 passed, 0 failed, 2 ignored (GPU-only FMA probe tests). - `cargo test --release -p tombox-xshader --test mesh -- --skip gpu_`: 15 passed, 0 failed, 1 ignored (local dump fixture). - `cargo test --release -p tombox-xshader --test synthetic`: 21 passed, 0 failed (plus `cargo test --no-run` across all `tombox-xshader` test targets). - Verified locally that the previously failing retail UE5 `HWRasterizeMS` (`[numthreads(256, 1, 1)]`, `PSG1` `TEXCOORD7`) translates and compiles cleanly with DXC (`ms_6_5`). - Native Windows 11; not run under Proton. **Not verified in a title:** live rendered pixels of the translated 256-thread mesh shader have not been visually verified yet beyond DXC compilation and the unit tests above. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success; >128-thread mesh shaders using LDS and per-primitive system values are explicitly refused
Xbox Series mesh shaders can launch up to 256 threads per threadgroup and export per-primitive attributes declared in PSG1 on parameter targets following the vertex OSG1 slots. Virtualize even 129..=256-thread non-LDS mesh shaders onto two passes of a 128-thread PC ms_6_5 threadgroup, parse PSG1 into ShaderExtract::prim_sig, emit per-primitive fields into SPrim, and refuse >128-thread LDS shaders and per-primitive system values.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:40 +00:00
github-bot closed this pull request 2026-11-26 06:12:40 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 18:26 UTC · original

Applied in d22f894 (merged in f0213ec) with your authorship kept, thanks. A follow-up, not blocking: a WARP exec test of a 256-thread mesh shader that checks every output lands, including the second-half index guard, would be welcome.

**@⁠omonkeyz** on GitHub · 2026-11-22 18:26 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/172#issuecomment-7083609164) Applied in d22f894 (merged in f0213ec) with your authorship kept, thanks. A follow-up, not blocking: a WARP exec test of a 256-thread mesh shader that checks every output lands, including the second-half index guard, would be welcome.

Pull request closed

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