startup: source-built NGG identity and contrast cases with a reference model #1954

Merged
NiiRoZz merged 11 commits from upstream-pr/1961 into main 2026-11-24 22:22:29 +00:00
NiiRoZz commented 2026-11-24 22:11:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T22:11:09Z.


Change

A first source-built slice for the NGG (primitive shader) vertex programs discussed in #1723: test only, no lowering and no translator change.

tests/startup_ngg_slice_check.py builds six gfx1013 NGG programs from documented encodings: an identity triangle, an LDS broadcast across lanes, a reversed primitive, a null primitive, a two-wave count broadcast and a masked vector ALU case. Each is decoded with the repository's disassembler, run by a multi-wave Python reference model with shared LDS (in forward and reversed wave order, which must agree), and compared on positions, parameters, primitive indices, winding and counts under three candidate interpretations:

  • pass: lane-private LDS, primitive export and counts ignored;
  • lane: lane-private LDS, counts and primitive honoured;
  • shared: group-shared LDS with barriers, counts and primitive honoured.

The check is registered as the CTest startup_ngg_slice, in the Linux Python job and in the pure-Python list in AGENTS.md; docs/experiments.md has a new section.

Refs #1723. AI-assisted (Claude Code).

Verification

At 09b21dfc (merged with main at 82f0db65):

python -B tests/startup_ngg_slice_check.py prints 6 cases decoded, anchored and separated under 3 interpretations; 6 planted model faults detected and exits 0.

python -B tests/rdna2_tools_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py pass.

Not run locally: the CTest registration (no configured build in the worktree used); CI runs it.

Evidence and follow-up

  • The programs are hand-assembled; no archive bytes are used. Field layouts are anchored to literal expected values with their public sources named in the docstring and the docs: LLVM's AMDGPU backend for the opcodes, the prim export target and the GS_ALLOC_REQ message id; Mesa's NGG code for m0 = prim<<12 | vtx, the wave id bits of the merged wave info, the null-primitive flag and the 9-bit index plus edge-flag slot layout.
  • Result: shared matches the reference model on all six cases. lane differs only where LDS carries data between lanes or waves. pass differs on every contrast case except the masked ALU one. On the two-wave case neither lane-private interpretation is right, so the counts have to be group-uniform.
  • Negative controls: a changed DS offset fails the decode check; six planted model faults fail (8-bit index fields, null bit ignored, swapped counts, no wave offset in the thread index, barrier as a no-op, exec ignored on vector ALU); joint encoder-plus-model changes fail against the literal anchors.
  • Limits: three interpretations only; nothing here is a claim about any production lowering or about any title's programs. No llvm-mc reassembly of the encoded words (no binary mode yet). Winding is computed in raw x/y, not in D3D front-face terms.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592423884 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1961). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-24T22:11:09Z. --- ## Change A first source-built slice for the NGG (primitive shader) vertex programs discussed in #1723: test only, no lowering and no translator change. `tests/startup_ngg_slice_check.py` builds six gfx1013 NGG programs from documented encodings: an identity triangle, an LDS broadcast across lanes, a reversed primitive, a null primitive, a two-wave count broadcast and a masked vector ALU case. Each is decoded with the repository's disassembler, run by a multi-wave Python reference model with shared LDS (in forward and reversed wave order, which must agree), and compared on positions, parameters, primitive indices, winding and counts under three candidate interpretations: - `pass`: lane-private LDS, primitive export and counts ignored; - `lane`: lane-private LDS, counts and primitive honoured; - `shared`: group-shared LDS with barriers, counts and primitive honoured. The check is registered as the CTest `startup_ngg_slice`, in the Linux Python job and in the pure-Python list in `AGENTS.md`; `docs/experiments.md` has a new section. Refs #1723. AI-assisted (Claude Code). ## Verification At `09b21dfc` (merged with `main` at `82f0db65`): `python -B tests/startup_ngg_slice_check.py` prints `6 cases decoded, anchored and separated under 3 interpretations; 6 planted model faults detected` and exits 0. `python -B tests/rdna2_tools_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. Not run locally: the CTest registration (no configured build in the worktree used); CI runs it. ## Evidence and follow-up - The programs are hand-assembled; no archive bytes are used. Field layouts are anchored to literal expected values with their public sources named in the docstring and the docs: LLVM's AMDGPU backend for the opcodes, the `prim` export target and the `GS_ALLOC_REQ` message id; Mesa's NGG code for `m0 = prim<<12 | vtx`, the wave id bits of the merged wave info, the null-primitive flag and the 9-bit index plus edge-flag slot layout. - Result: `shared` matches the reference model on all six cases. `lane` differs only where LDS carries data between lanes or waves. `pass` differs on every contrast case except the masked ALU one. On the two-wave case neither lane-private interpretation is right, so the counts have to be group-uniform. - Negative controls: a changed DS offset fails the decode check; six planted model faults fail (8-bit index fields, null bit ignored, swapped counts, no wave offset in the thread index, barrier as a no-op, exec ignored on vector ALU); joint encoder-plus-model changes fail against the literal anchors. - Limits: three interpretations only; nothing here is a claim about any production lowering or about any title's programs. No `llvm-mc` reassembly of the encoded words (no binary mode yet). Winding is computed in raw x/y, not in D3D front-face terms. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 23:03:17 +00:00
NiiRoZz commented 2026-11-24 23:03:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T22:29:01Z.


Added an optional binary <llvm-mc> mode in c6d2b00e: it reassembles all six programs with LLVM 15 llvm-mc (gfx1013, wave64), requires word-for-word identity with the fixture's encoder (342 instructions), and must report a deliberately wrong encoder word. It runs in the Linux LLVM job; the pure-Python mode is unchanged. This closes the "no llvm-mc reassembly" limit in the description.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146283799 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1961#issuecomment-7146283799). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-24T22:29:01Z. --- Added an optional `binary <llvm-mc>` mode in `c6d2b00e`: it reassembles all six programs with LLVM 15 `llvm-mc` (gfx1013, wave64), requires word-for-word identity with the fixture's encoder (342 instructions), and must report a deliberately wrong encoder word. It runs in the Linux LLVM job; the pure-Python mode is unchanged. This closes the "no llvm-mc reassembly" limit in the description.
NiiRoZz commented 2026-11-24 23:03:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T22:54:08Z.


Correction to my note above: this PR merged before that commit was pushed, so the binary mode is not part of what merged here. It is proposed separately in #2000.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146776137 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1961#issuecomment-7146776137). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-24T22:54:08Z. --- Correction to my note above: this PR merged before that commit was pushed, so the `binary` mode is not part of what merged here. It is proposed separately in #2000.
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
R0Y00/Xbox2Windows!1954
No description provided.