tombox-xshader: amplification shaders always use the memory-based root ABI #316

Closed
github-bot wants to merge 3 commits from gh-pr/316/head into gh-pr/316/base
Owner

@⁠enderrr9 on GitHub · 2026-11-23 18:05 UTC · original
enderrr9:xshader-amp-rootmem-rule → main · +271 −20 · 5 files · 3 commits · closed without merging

Builds on #313 and #315. The first two commits are those PRs. The new change is the last commit.

Bug

The console requires FORCE_MEMORY_BASED_ABI for every PSO with an amplification shader (mesh_pso::as_root_rule). An AS gets only COMPUTE_USER_DATA_0..3: s[0:1] is root memory and s2/s3 are the rings (BLOCKERS.md). hlsl/rootmem.rs picked the memory path only when an s_load through s[0:1] came before the first branch.

An AS whose first root load follows a branch took the register path instead:

  • root constant 0 was mapped to s4 by static_sgpr_init;
  • finish_amp then overwrote s4 with gid.x;
  • the s_load from s[0:1] was dropped, so its SGPRs stayed 0.

In the synthetic test, that AS launched no mesh groups and drew nothing, with no refusal.

Fix

detect_rootmem returns true for Stage::Amplification whenever the root signature has parameters. Other compute shaders keep the existing detection. It's a 4-line change in rootmem.rs.

Test

gpu_synthetic_amplification_root_load_after_a_branch_still_uses_s0_s1: the same AS as the root-constant test from #313, with s_cmp_eq_u32 + s_cbranch_scc1 before the s_load_dwordx2. It checks that the HLSL loads s12 from the root constant and doesn't touch s4, then renders on WARP.

  • Before: 0 samples, all pixels at the clear colour.
  • After: pixels 0, 1, 4 and 5 and 4 samples, the same as the straight-line case.

tests/amp.rs, tests/mesh.rs and tests/synthetic.rs pass on WARP. The CI non-exec set (--lib --bins plus every test file except exec) passes too. pr_gate.py: no problems.

BLOCKERS.md

  • The amplification entry still said "not translated ... the translator refuses Stage::Amplification". It now describes the ring model amp.rs already implements.
  • The memory-root line (old "the translator does not model the memory-based root ABI") now says what rootmem.rs covers. It also lists what is still open:
    • descriptor tables in root memory (layout not established);
    • reading the RTS0 flag bit itself;
    • the mesh-shader pointer register.

🤖 Generated with Claude Code

**@⁠enderrr9** on GitHub · 2026-11-23 18:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/316) `enderrr9:xshader-amp-rootmem-rule` → `main` · +271 −20 · 5 files · 3 commits · closed without merging **Builds on #313 and #315.** The first two commits are those PRs. The new change is the last commit. ## Bug The console requires `FORCE_MEMORY_BASED_ABI` for every PSO with an amplification shader (`mesh_pso::as_root_rule`). An AS gets only `COMPUTE_USER_DATA_0..3`: `s[0:1]` is root memory and `s2`/`s3` are the rings (BLOCKERS.md). `hlsl/rootmem.rs` picked the memory path only when an `s_load` through `s[0:1]` came **before the first branch**. An AS whose first root load follows a branch took the register path instead: - root constant 0 was mapped to `s4` by `static_sgpr_init`; - `finish_amp` then overwrote `s4` with `gid.x`; - the `s_load` from `s[0:1]` was dropped, so its SGPRs stayed 0. In the synthetic test, that AS launched **no mesh groups and drew nothing**, with no refusal. ## Fix `detect_rootmem` returns true for `Stage::Amplification` whenever the root signature has parameters. Other compute shaders keep the existing detection. It's a 4-line change in `rootmem.rs`. ## Test `gpu_synthetic_amplification_root_load_after_a_branch_still_uses_s0_s1`: the same AS as the root-constant test from #313, with `s_cmp_eq_u32` + `s_cbranch_scc1` before the `s_load_dwordx2`. It checks that the HLSL loads `s12` from the root constant and doesn't touch `s4`, then renders on WARP. - **Before: 0 samples, all pixels at the clear colour.** - **After: pixels 0, 1, 4 and 5 and 4 samples**, the same as the straight-line case. `tests/amp.rs`, `tests/mesh.rs` and `tests/synthetic.rs` pass on WARP. The CI non-exec set (`--lib --bins` plus every test file except `exec`) passes too. `pr_gate.py`: no problems. ## BLOCKERS.md - The amplification entry still said "not translated ... the translator refuses Stage::Amplification". It now describes the ring model `amp.rs` already implements. - The memory-root line (old "the translator does not model the memory-based root ABI") now says what `rootmem.rs` covers. It also lists what is still open: - descriptor tables in root memory (layout not established); - reading the RTS0 flag bit itself; - the mesh-shader pointer register. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
All four tests in tests/amp.rs need the console_xsc fixtures from local
title dumps. Without them, no amplification shader ever runs on a GPU,
and CI checks the AS path only at the HLSL/DXC level.

This adds a hand-assembled AS + MS pair and renders it on WARP. The pair
follows the ring ABI the translator decodes: s2/s3 = args/payload ring
>> 8, s4 = group id, and the MS payload window in s[10:11].

- The AS shifts the ring bases left by 8 and offsets them by its group.
  It stores a 16-byte payload with global_store_dwordx4 and the mesh
  group count with global_store_dword. Only dword 0 of the args entry is
  written, so the open Y/Z encoding question in BLOCKERS.md doesn't
  affect the test.
- The MS reads the payload with global_load_dwordx4 through s[10:11]. It
  draws one pixel-wide triangle per mesh group at x = payload[0] + group
  and exports the payload tag, its group index and the AS group.
- Two AS groups launch 1 and 2 mesh groups. They draw pixels 0, 4 and 5
  with no global-memory misses, the same pattern as the as3/ms3 fixture
  test.
- A second case loads the group count and the tag as root constants
  through s[0:1] with s_load_dwordx2. This is the memory-based root ABI
  (rootmem.rs) that amplification shaders must use. It checks that
  pixels 0, 1, 4 and 5 are drawn.

render() is split into render_pair(), which takes translated shaders and
optional root constants. The fixture test still goes through render().
WARP renders take the same lock that tests/mesh.rs uses.

Passes on WARP, and with TOMBOX_EXEC_HW=1 on an RTX 3050 Laptop GPU.
The translator itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console AS writes its mesh-args entry as {X, 0, payload VA >> 4 high,
payload VA >> 4 low} (as3, BLOCKERS.md #115 CHECKED). df91928 started
reading Y and Z from dwords 1 and 2. In the translator's ring address
space the payload VA is 0x20_xxxx_xxxx, so dword 2 is 2, and every
amplification group launched its mesh groups twice (Z = 2). The pixels
don't change, because the duplicates draw the same primitives, so the
extra work was invisible to the existing tests.

DispatchMesh now takes X from dword 0 and Y from dword 1 (0 in as3, so 1),
and keeps Z at 1.

Test: render_pair() now also returns an occlusion-query sample count.
A new synthetic AS stores the console-shaped entry with one
global_store_dwordx4 and must draw exactly 3 samples for 1 + 2 mesh
groups. Before this change it drew 6. The two existing synthetic GPU
tests also check their sample counts (3 and 4). The pinned HLSL strings
in tests/amp.rs and tests/synthetic.rs and the BLOCKERS.md line are
updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console requires FORCE_MEMORY_BASED_ABI for every PSO with an
amplification shader (mesh_pso::as_root_rule), and the AS gets only
COMPUTE_USER_DATA_0..3: s[0:1] = root memory, s2/s3 = rings. rootmem.rs
chose the memory path only when an s_load through s[0:1] came before the
first branch.

An AS whose first root load followed a branch therefore took the
register path, which is wrong in three ways:
- static_sgpr_init put root constant 0 into s4;
- finish_amp then overwrote s4 with the group id;
- the s_load from s[0:1] was dropped, so its SGPRs stayed 0.
In the synthetic test this AS launched no mesh groups and drew nothing,
with no refusal.

detect_rootmem now returns true for Stage::Amplification whenever the
root signature has parameters. Other compute shaders keep the existing
detection.

Test: gpu_synthetic_amplification_root_load_after_a_branch_still_uses_s0_s1
(s_cmp + s_cbranch_scc1 before the s_load_dwordx2). Before the fix it
drew 0 samples. It now draws the same pixels as the straight-line case
(4 samples).

BLOCKERS.md:
- The amplification entry described the stage as "not translated". It
  now describes the translator's ring model, which is already in amp.rs.
- The memory-root line now says what rootmem.rs covers and what is still
  open: root-memory descriptor tables, reading the RTS0 flag, and the
  mesh-shader pointer register.

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

@⁠omonkeyz on GitHub · 2026-11-25 13:49 UTC · original

Applied on main in d19af94 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/316#issuecomment-7164343481) Applied on main in d19af94 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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