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

Manually merged
github merged 11 commits from gh-pr/1961/head into gh-pr/1961/base 2026-11-26 23:45:44 +00:00
Owner

@⁠NiiRoZz on GitHub · 2026-11-24 22:11 UTC · original
NiiRoZz:startup/ngg-first-slice → main · +704 −0 · 5 files · 11 commits · merged 2026-11-24 22:22 UTC

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

**@⁠NiiRoZz** on GitHub · 2026-11-24 22:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1961) `NiiRoZz:startup/ngg-first-slice` → `main` · +704 −0 · 5 files · 11 commits · merged 2026-11-24 22:22 UTC ## 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)
Five gfx1013 programs (identity triangle, LDS broadcast, reversed primitive,
null primitive, two-wave count broadcast) are encoded, decoded with
disasm_rdna2 and run by a reference model of the NGG protocol and by two
candidate interpretations. Five planted model faults must fail.

Refs #1723

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The interpretations no longer stop at the allocation check, so the two-wave
case shows what each one exports. A changed DS offset must fail the decode
comparison. docs/experiments.md describes the cases and the command.

Refs #1723

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #1723

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every case runs in forward and reverse wave order and must agree, so a model
without s_barrier fails on its own planted fault. Literal anchors (GS_ALLOC_REQ
word, prim export word, wave-id field, expected m0 and primitive words) fail
when encoder and model are changed together. Adds a masked vector-ALU case and
fault, a group-shared interpretation, the 9-bit index plus edge-flag slot
layout, and drops corpus claims from the docstring.

Refs #1723

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #1723

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:45:43 +00:00
github manually merged commit 09b21dfce2 into gh-pr/1961/base 2026-11-26 23:45:44 +00:00
Author
Owner

@⁠NiiRoZz on GitHub · 2026-11-24 22:29 UTC · original

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** on GitHub · 2026-11-24 22:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1961#issuecomment-7146283799) 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.
Author
Owner

@⁠NiiRoZz on GitHub · 2026-11-24 22:54 UTC · original

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.

**@⁠NiiRoZz** on GitHub · 2026-11-24 22:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1961#issuecomment-7146776137) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.