tombox-xshader: keep amplification DispatchMesh Z at 1 (args dword 2 is the payload pointer) #315

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

@⁠enderrr9 on GitHub · 2026-11-23 17:57 UTC · original
enderrr9:xshader-amp-args-pointer → main · +243 −16 · 4 files · 2 commits · closed without merging

Builds on #313. The first commit here is #313's test harness. The new change is the second commit (fbb7dd9).

Bug

The console AS writes its mesh-args entry as {X, 0, payload VA >> 4 high, payload VA >> 4 low} (fixture as3; see the BLOCKERS.md #115 CHECKED line). df91928 (#136) made the translated AS call DispatchMesh(tb_args[0], max(tb_args[1], 1u), max(tb_args[2], 1u), tb_pl), so it reads dword 2 as Z.

In the translator's ring address space the payload VA is 0x20_xxxx_xxxx, so dword 2 is 2. Every amplification group therefore launched each of its mesh groups twice. The pixels don't change, because the duplicate groups draw the same primitives, so no existing test saw it.

Fix

DispatchMesh(tb_args[0], max(tb_args[1], 1u), 1u, tb_pl):

  • X comes from dword 0.
  • Y comes from dword 1, which is 0 in as3, so it stays 1 as before. I kept it so #136's Y path still works if the console ever puts a count there.
  • Z stays 1, because dword 2 is the pointer.

Test

  • render_pair() now also returns an occlusion-query sample count.
  • New: gpu_synthetic_amplification_args_entry_with_the_payload_pointer_launches_each_mesh_group_once. The synthetic AS stores the console-shaped entry with one global_store_dwordx4. Two AS groups launch 1 and 2 mesh groups, each drawing one pixel, so the test expects 3 samples. Before the fix: 6. After: 3.
  • The two existing synthetic GPU tests now also check their sample counts (3 and 4).
  • The pinned HLSL strings in tests/amp.rs / tests/synthetic.rs are updated. The synthetic test is renamed to amplification_dispatch_uses_the_y_group_count_and_not_the_payload_pointer. The BLOCKERS.md #115 line now describes the current behaviour.

cargo test -p tombox-xshader --locked --test amp --test synthetic --test mesh: all pass on WARP. The fixture tests stay ignored here. pr_gate.py: 4 files, 0 problems.

Not covered

How the console compiler encodes Y/Z > 1 in the entry is still unverified, because no console AS seen so far calls a 2D/3D DispatchMesh. If someone has such a fixture, gpu_console_amplification_... could also assert the sample count.

🤖 Generated with Claude Code

**@⁠enderrr9** on GitHub · 2026-11-23 17:57 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/315) `enderrr9:xshader-amp-args-pointer` → `main` · +243 −16 · 4 files · 2 commits · closed without merging **Builds on #313.** The first commit here is #313's test harness. The new change is the second commit (`fbb7dd9`). ## Bug The console AS writes its mesh-args entry as `{X, 0, payload VA >> 4 high, payload VA >> 4 low}` (fixture as3; see the BLOCKERS.md #115 CHECKED line). df91928 (#136) made the translated AS call `DispatchMesh(tb_args[0], max(tb_args[1], 1u), max(tb_args[2], 1u), tb_pl)`, so it reads dword 2 as Z. In the translator's ring address space the payload VA is `0x20_xxxx_xxxx`, so dword 2 is `2`. Every amplification group therefore launched each of its mesh groups twice. The pixels don't change, because the duplicate groups draw the same primitives, so no existing test saw it. ## Fix `DispatchMesh(tb_args[0], max(tb_args[1], 1u), 1u, tb_pl)`: - X comes from dword 0. - Y comes from dword 1, which is 0 in as3, so it stays 1 as before. I kept it so #136's Y path still works if the console ever puts a count there. - Z stays 1, because dword 2 is the pointer. ## Test - `render_pair()` now also returns an occlusion-query sample count. - New: `gpu_synthetic_amplification_args_entry_with_the_payload_pointer_launches_each_mesh_group_once`. The synthetic AS stores the console-shaped entry with one `global_store_dwordx4`. Two AS groups launch 1 and 2 mesh groups, each drawing one pixel, so the test expects 3 samples. **Before the fix: 6. After: 3.** - The two existing synthetic GPU tests now also check their sample counts (3 and 4). - The pinned HLSL strings in `tests/amp.rs` / `tests/synthetic.rs` are updated. The synthetic test is renamed to `amplification_dispatch_uses_the_y_group_count_and_not_the_payload_pointer`. The BLOCKERS.md #115 line now describes the current behaviour. `cargo test -p tombox-xshader --locked --test amp --test synthetic --test mesh`: all pass on WARP. The fixture tests stay ignored here. `pr_gate.py`: 4 files, 0 problems. ## Not covered How the console compiler encodes Y/Z > 1 in the entry is still unverified, because no console AS seen so far calls a 2D/3D DispatchMesh. If someone has such a fixture, `gpu_console_amplification_...` could also assert the sample count. 🤖 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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:18:22 +00:00
github-bot closed this pull request 2026-11-26 06:18:22 +00:00
Author
Owner

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

Applied on main in c1ee4bf (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/315#issuecomment-7164342365) Applied on main in c1ee4bf (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.