startup: translate the fetch call of stream vertex shaders from the input layout #1851

Manually merged
github merged 12 commits from gh-pr/1851/head into gh-pr/1851/base 2026-11-26 23:37:41 +00:00
Owner

@⁠NiiRoZz on GitHub · 2026-11-24 19:36 UTC · original
NiiRoZz:startup/stream-input-layout-fetch → main · +681 −38 · 11 files · 12 commits · merged 2026-11-24 20:31 UTC

Change

A slot-86 stream vertex shader can begin with s_swappc_b64 s[4:5], s[4:5], a call into a fetch routine the console driver builds from the stream's input layout. strip_header dropped that call as header bytes, so every fetched input read as zero and the draw had zero area. The translation compiled and the draw was logged as drawn, so nothing reported it.

  • The stand-in reads the INPUT_LAYOUT subobject of the stream and publishes it as req_<key>.ia before .a, adding it to the cache key. It logs one count/format line per stream: x2w-draw stream input layout: N elements (format/slot/offset/class) ….
  • gfx2hlsl.py keeps a call that sits before the prefetch and translates it as vertex-buffer loads (srv buf vb <slot> plus a stride value).
  • Registers come from the 5-byte fetch records at +0x138 of the container header (kind, signature register, mask, first VGPR, count−1). Records are matched to layout elements by semantic, and the record count is checked against +0x1d8.
  • After the call, a register counts as defined only if it is v0, a fetched register, or written before the read in the entry block (up to the first branch or branch target) while exec is unchanged. Any exec write ends that region, whichever instruction makes it; s_wqm exec, exec alone stays a no-op. A read of any other register is refused.
  • Also refused instead of translated: the call without a layout, slot ≥ 8 (the stand-in binds eight vertex-buffer slots), a per-instance element, an unknown format, an unknown append offset, a record reaching past v255, and an unknown header size, record kind or count.

Programs without the call are unaffected. The shared interface touched is the shader request format (req_<key>.ia is new) and pipeline_key, which now takes the layout.

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

Verification

On d1d4c28b (merged with main at b560c3be), WARP 10.0.26100.10068 and an RTX 5090 (driver 32.0.16.2135), Windows build 26300, debug layer off:

ctest --preset release --no-tests=error -R '^(startup_stream_|startup_root_reset_|startup_gfx2hlsl)' -j1: 33/33 passed, no skips.

startup_stream_fetch_{warp,hardware}, on an 8×4 target:

  • exact readback for a start-vertex draw and an indexed base-vertex draw, with the two layout elements in different vertex-buffer slots;
  • swapped registers and a single-slot fetch each fail the exact check.

startup_stream_fetch_translate (translator only, also in the Linux job; python -B tests/startup_stream_fetch_check.py):

  • a text check of the generated loads and manifest entries for both slots;
  • refused: no layout, an unfetched register, a register written only after exec was set to 0, a register written only in code a branch skips, s_wqm_b32 exec_lo, 0 before the write, s_mov_b32 exec_hi, 0, a z-only record with a short count, slot 8, a per-instance element, an unknown format, record kind 7, a record past v255, and a mismatched record count.

Eight mutations of the translator each fail the check: base vertex replaced by start instance, the mask/count check removed, the slot bound loosened, the record-kind check removed, per-instance elements accepted, a masked write counted as a definition, a branch-bypassed write counted as a definition, and an exec write through s_wqm not ending the unconditional region.

Translating 7,457 local shader requests at the base and at this change gives identical results, except one call-starting pipeline (present in three caches), which is now refused when no layout is supplied.

Evidence and follow-up

  • The fixture is hand-assembled from documented encodings; no archive bytes are used.
  • The record format was checked offline against the input signatures of 628 call-starting vertex programs (1,417 records) in one local shader archive. Only counts are reported here.
  • In a local startup run the new layout line read 3 elements … 6/0/0/0 28/0/12/0 16/0/16/0, and the pipeline translated with a vertex buffer of stride 24. Every first-run screen was pixel-identical to the merge-base build: that pipeline's two textures are unbound there (a separate defect), so covered pixels could not be shown in that run. The fixture is the proof of the fetch.
  • Assumption: missing components read 0, 0, 0, 1, as in the existing vertex-fetch path. Not measured.
  • Not in this change: the pixel stage still pairs attributes by number, not by semantic.
  • The definite-assignment rule is deliberately narrow: with a synthesized layout, 3 of the 628 call-starting programs change from translated to refused because they read a register written only under a changed exec mask. Tracking definitions on every path is left for a follow-up.
  • A pipeline is now translated once per distinct input layout, even when its vertex program has no call.
  • docs/startup-runtime.md has a new section for the request file and the log line.

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 19:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851) `NiiRoZz:startup/stream-input-layout-fetch` → `main` · +681 −38 · 11 files · 12 commits · merged 2026-11-24 20:31 UTC ## Change A slot-86 stream vertex shader can begin with `s_swappc_b64 s[4:5], s[4:5]`, a call into a fetch routine the console driver builds from the stream's input layout. `strip_header` dropped that call as header bytes, so every fetched input read as zero and the draw had zero area. The translation compiled and the draw was logged as drawn, so nothing reported it. - The stand-in reads the `INPUT_LAYOUT` subobject of the stream and publishes it as `req_<key>.ia` before `.a`, adding it to the cache key. It logs one count/format line per stream: `x2w-draw stream input layout: N elements (format/slot/offset/class) …`. - `gfx2hlsl.py` keeps a call that sits before the prefetch and translates it as vertex-buffer loads (`srv buf vb <slot>` plus a stride value). - Registers come from the 5-byte fetch records at +0x138 of the container header (kind, signature register, mask, first VGPR, count−1). Records are matched to layout elements by semantic, and the record count is checked against +0x1d8. - After the call, a register counts as defined only if it is v0, a fetched register, or written before the read in the entry block (up to the first branch or branch target) while exec is unchanged. Any exec write ends that region, whichever instruction makes it; `s_wqm exec, exec` alone stays a no-op. A read of any other register is refused. - Also refused instead of translated: the call without a layout, slot ≥ 8 (the stand-in binds eight vertex-buffer slots), a per-instance element, an unknown format, an unknown append offset, a record reaching past v255, and an unknown header size, record kind or count. Programs without the call are unaffected. The shared interface touched is the shader request format (`req_<key>.ia` is new) and `pipeline_key`, which now takes the layout. Refs #1142. AI-assisted (Claude Code). ## Verification On `d1d4c28b` (merged with `main` at `b560c3be`), WARP 10.0.26100.10068 and an RTX 5090 (driver 32.0.16.2135), Windows build 26300, debug layer off: `ctest --preset release --no-tests=error -R '^(startup_stream_|startup_root_reset_|startup_gfx2hlsl)' -j1`: 33/33 passed, no skips. `startup_stream_fetch_{warp,hardware}`, on an 8×4 target: - exact readback for a start-vertex draw and an indexed base-vertex draw, with the two layout elements in different vertex-buffer slots; - swapped registers and a single-slot fetch each fail the exact check. `startup_stream_fetch_translate` (translator only, also in the Linux job; `python -B tests/startup_stream_fetch_check.py`): - a text check of the generated loads and manifest entries for both slots; - refused: no layout, an unfetched register, a register written only after exec was set to 0, a register written only in code a branch skips, `s_wqm_b32 exec_lo, 0` before the write, `s_mov_b32 exec_hi, 0`, a z-only record with a short count, slot 8, a per-instance element, an unknown format, record kind 7, a record past v255, and a mismatched record count. Eight mutations of the translator each fail the check: base vertex replaced by start instance, the mask/count check removed, the slot bound loosened, the record-kind check removed, per-instance elements accepted, a masked write counted as a definition, a branch-bypassed write counted as a definition, and an exec write through `s_wqm` not ending the unconditional region. Translating 7,457 local shader requests at the base and at this change gives identical results, except one call-starting pipeline (present in three caches), which is now refused when no layout is supplied. ## Evidence and follow-up - The fixture is hand-assembled from documented encodings; no archive bytes are used. - The record format was checked offline against the input signatures of 628 call-starting vertex programs (1,417 records) in one local shader archive. Only counts are reported here. - In a local startup run the new layout line read `3 elements … 6/0/0/0 28/0/12/0 16/0/16/0`, and the pipeline translated with a vertex buffer of stride 24. Every first-run screen was pixel-identical to the merge-base build: that pipeline's two textures are unbound there (a separate defect), so covered pixels could not be shown in that run. The fixture is the proof of the fetch. - Assumption: missing components read 0, 0, 0, 1, as in the existing vertex-fetch path. Not measured. - Not in this change: the pixel stage still pairs attributes by number, not by semantic. - The definite-assignment rule is deliberately narrow: with a synthesized layout, 3 of the 628 call-starting programs change from translated to refused because they read a register written only under a changed exec mask. Tracking definitions on every path is left for a follow-up. - A pipeline is now translated once per distinct input layout, even when its vertex program has no call. - `docs/startup-runtime.md` has a new section for the request file and the log line. ## 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)
A slot-86 vertex shader can start with s_swappc_b64 s[4:5], s[4:5] into a
fetch routine the driver builds from the stream's input layout. strip_header
cut that call off as header, so every fetched input read as zero and the
draw had zero area.

- The stand-in reads the INPUT_LAYOUT subobject, publishes it as
  req_<key>.ia before .a, hashes it into the key and logs one line with the
  element count and each element's format, slot, offset and class.
- gfx2hlsl keeps a call before the prefetch, translates the entry call as
  vertex-buffer loads placed by the fetch records in the container header
  (matched to layout elements through the input signature), and refuses a
  call without a layout or a read of a register nothing wrote.
- startup_stream_fetch_{warp,hardware}: exact 8x4 readback, a mutated
  register assignment that fails it, and both refusals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps the shader-4 cache revision with the input-layout key argument, and the
root-reset draw branch next to the vertex-fetch branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- gfx2hlsl refuses a fetched element in vertex-buffer slot 8 or above (the
  stand-in binds eight) and a fetch table whose record count disagrees with
  the header's count at +0x1d8.
- The fixture layout puts TEXCOORD and POSITION in slots 0 and 1, and adds an
  indexed draw with base vertex 5 and a non-zero minimum index, so a fetch
  index without the base-vertex entry value fails the readback. A mutation
  that reads both elements from slot 0 must fail it as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves tools/startup/gfx2hlsl.py: the BUF_FMT_16_16_16_16_FLOAT entry from
#1699 goes into the shared FETCH_FORMATS table that tbuffer loads and the
generated fetch both use; the table equals upstream's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- After a fetch call, a vertex register counts as defined only when it is v0,
  a fetched register, or written in the entry block (the straight-line code up
  to the first branch or branch target) by an instruction that runs with the
  entry exec mask. A read of any other register is refused: a write under a
  changed exec mask or behind a branch no longer counts.
- A fetch record reaching past v255 is refused.
- The translator-only cases run without the consumer, device or compiler
  (startup_stream_fetch_translate, and the Linux job): the generated loads and
  manifest for both slots, and the refusals for no layout, an undefined export,
  a masked-off write, a branch-bypassed write, a short z-only count, slot 8, a
  per-instance element, format 10, record kind 7, a record past v255 and a
  mismatched record count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After a fetch call, s_wqm of exec into itself stays a no-op (it only adds
lanes); every other s_wqm form, a write to exec_hi, and an exec write by an
instruction whose handler does not clear the exec knowledge are refused.
Programs without the call keep their handling. Adds the refused cases
"s_wqm_b32 exec_lo, 0" before the only write of an exported register and
"s_mov_b32 exec_hi, 0", and an accepted s_wqm_b64 exec, exec.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps the shader-5 cache revision from #1854 with the input-layout key argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:37:40 +00:00
github manually merged commit d1d4c28bcd into gh-pr/1851/base 2026-11-26 23:37:41 +00:00
Author
Owner

@⁠NiiRoZz on GitHub · 2026-11-24 20:18 UTC · original

Both reviews are addressed in d1d4c28b (merged with main at b560c3be; the description is updated to match).

Definite assignment (requested change). After the fetch call a register is defined only if it is v0, fetched, or written before the read in the entry block (up to the first branch or branch target) while exec is unchanged. Any exec write ends that region, whichever instruction makes it, including s_wqm; only s_wqm exec, exec stays a no-op, and other s_wqm forms, exec_hi writes and unmodelled exec writes are refused. New source-built refused cases: the only write under a masked-off exec, the only write skipped by an s_branch, s_wqm_b32 exec_lo, 0 before the write, and s_mov_b32 exec_hi, 0. The two-slot draws and the no-layout and unwritten controls are kept. With a synthesized layout, 3 of 628 call-starting programs change from translated to refused; each reads a register written only under a changed exec mask.

Test gaps (second review). Translator-only cases now pin record kind 7, a per-instance element, an unknown format and a record reaching past v255. They and a text check of the generated loads run without the consumer: python -B tests/startup_stream_fetch_check.py, the CTest startup_stream_fetch_translate, and the Linux job. The five mutations from the review, plus three for the cases above, each fail the check.

ctest --preset release --no-tests=error -R '^(startup_stream_|startup_root_reset_|startup_gfx2hlsl)' -j1: 33/33 passed, no skips (WARP and RTX 5090).

AI-assisted (Claude Code).

**@⁠NiiRoZz** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851#issuecomment-7143348492) Both reviews are addressed in `d1d4c28b` (merged with `main` at `b560c3be`; the description is updated to match). **Definite assignment (requested change).** After the fetch call a register is defined only if it is v0, fetched, or written before the read in the entry block (up to the first branch or branch target) while exec is unchanged. Any exec write ends that region, whichever instruction makes it, including `s_wqm`; only `s_wqm exec, exec` stays a no-op, and other `s_wqm` forms, `exec_hi` writes and unmodelled exec writes are refused. New source-built refused cases: the only write under a masked-off exec, the only write skipped by an `s_branch`, `s_wqm_b32 exec_lo, 0` before the write, and `s_mov_b32 exec_hi, 0`. The two-slot draws and the no-layout and unwritten controls are kept. With a synthesized layout, 3 of 628 call-starting programs change from translated to refused; each reads a register written only under a changed exec mask. **Test gaps (second review).** Translator-only cases now pin record kind 7, a per-instance element, an unknown format and a record reaching past v255. They and a text check of the generated loads run without the consumer: `python -B tests/startup_stream_fetch_check.py`, the CTest `startup_stream_fetch_translate`, and the Linux job. The five mutations from the review, plus three for the cases above, each fail the check. `ctest --preset release --no-tests=error -R '^(startup_stream_|startup_root_reset_|startup_gfx2hlsl)' -j1`: 33/33 passed, no skips (WARP and RTX 5090). AI-assisted (Claude Code).
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-24 20:36 UTC · original

Ran the translator controls and broke three parts of the new slice

At the PR head, device-free:

out/pe-env/Scripts/python.exe -B tests/startup_stream_fetch_check.py
translate: s_wqm_b64 exec, exec translates
translate: z-only record with count 3 translates, count 2 refused
translate: slot 8, per-instance, format 10, record kind 7, a record past v255 and a mismatched count refused
exit 0

Three mutations to tools/startup/gfx2hlsl.py, each reverted:

mutation result
FETCH_SLOTS = 8 → 16 (the stand-in binds eight slots) caught
FETCH_COUNT = 0x1d8 → None (the record-count field no longer read) caught
FETCH_CALL = 0xbe842104 → 0xbe842105 (the call is no longer recognised) caught

The third is the important one for this slice: if the call is not recognised, strip_header eats it and every fetched input
reads as zero — the failure mode the description opens with, where "the translation compiled and the draw was logged as
drawn, so nothing reported it". The check notices.

What I did not run

The startup_stream_fetch_<backend> draws (WARP and hardware) need DXC and the consumer executable; I ran only the
_translate controls. So my table says nothing about the GPU path — the PR reports both backends, and I am taking those as
reported rather than verified.

The constants are documented, which matters here

FETCH_RECORDS = 0x138 and FETCH_COUNT = 0x1d8 are container-layout facts, and lines 64–71 say where they came from: "checked
offline against the input signatures of every readable vertex program of one title's shader archive that starts with the
call". That is the right kind of provenance for a magic offset — it names the population that agreed, not just one shader.

One consequence: those offsets are only as general as that archive. If a later program lays out the header differently, the
refusals ("unknown header size, record kind or count") should fire rather than mis-read; the check has cases for exactly
those, which is why I tried the FETCH_COUNT mutation above.

Layout notes

  • CMakeLists.txt registers both shapes: startup_stream_fetch_translate (device-free) and
    startup_stream_fetch_<backend> with SKIP_RETURN_CODE 77. The X2W_FXC env passthrough on the draw test is the same
    pattern the other translate/draw pairs use.
  • AGENTS.md gains the check in the platform-independent list, and .github/workflows/windows.yml gains one line, so it runs
    on both CI paths.

Verdict

Reviewed. The three constants that decide whether the slice works at all are each pinned by a mutation, and the refusal set
around them has cases. No objections; the draw path is the part I have not verified.

Notes

  • AI-assisted review.
**@⁠ChazY11** on GitHub · 2026-11-24 20:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851#issuecomment-7143805515) ## Ran the translator controls and broke three parts of the new slice At the PR head, device-free: ```powershell out/pe-env/Scripts/python.exe -B tests/startup_stream_fetch_check.py translate: s_wqm_b64 exec, exec translates translate: z-only record with count 3 translates, count 2 refused translate: slot 8, per-instance, format 10, record kind 7, a record past v255 and a mismatched count refused exit 0 ``` Three mutations to `tools/startup/gfx2hlsl.py`, each reverted: | mutation | result | |---|---| | `FETCH_SLOTS = 8` → `16` (the stand-in binds eight slots) | **caught** | | `FETCH_COUNT = 0x1d8` → `None` (the record-count field no longer read) | **caught** | | `FETCH_CALL = 0xbe842104` → `0xbe842105` (the call is no longer recognised) | **caught** | The third is the important one for this slice: if the call is not recognised, `strip_header` eats it and every fetched input reads as zero — the failure mode the description opens with, where "the translation compiled and the draw was logged as drawn, so nothing reported it". The check notices. ## What I did not run The `startup_stream_fetch_<backend>` draws (WARP and hardware) need DXC and the consumer executable; I ran only the `_translate` controls. So my table says nothing about the GPU path — the PR reports both backends, and I am taking those as reported rather than verified. ## The constants are documented, which matters here `FETCH_RECORDS = 0x138` and `FETCH_COUNT = 0x1d8` are container-layout facts, and lines 64–71 say where they came from: "checked offline against the input signatures of every readable vertex program of one title's shader archive that starts with the call". That is the right kind of provenance for a magic offset — it names the population that agreed, not just one shader. One consequence: those offsets are only as general as that archive. If a later program lays out the header differently, the refusals ("unknown header size, record kind or count") should fire rather than mis-read; the check has cases for exactly those, which is why I tried the `FETCH_COUNT` mutation above. ## Layout notes - `CMakeLists.txt` registers both shapes: `startup_stream_fetch_translate` (device-free) and `startup_stream_fetch_<backend>` with `SKIP_RETURN_CODE 77`. The `X2W_FXC` env passthrough on the draw test is the same pattern the other translate/draw pairs use. - `AGENTS.md` gains the check in the platform-independent list, and `.github/workflows/windows.yml` gains one line, so it runs on both CI paths. ## Verdict Reviewed. The three constants that decide whether the slice works at all are each pinned by a mutation, and the refusal set around them has cases. No objections; the draw path is the part I have not verified. ## Notes - AI-assisted review.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:44 UTC · original · reviewed

Review of head ddd6db71d59a98e88c01ce9b23da58e8e684e6ce (three merges of main on top of a8f581c4, f0202ea5 and 15ce041b; base origin/main).

Verdict: no P1. One P2 (test gap, not a correctness defect I could demonstrate), three P3.

What I read The whole diff against origin/main (9 files): stream_input_layout and the cache key in src/startup_stubs/d3d12_draw.inl; strip_header, stream_fetch, parse_input_layout, signature_inputs, op_s_swappc_b64, load_format, the unwritten-register guard in hlsl_vs and the .ia request path in tools/startup/gfx2hlsl.py; container_image in tools/pixel_aot.py; the docs paragraph.

Reading, point by point

  • Call and register ABI. strip_header keeps a dword before the prefetch only when it matches the SOP1 s_swappc_b64 pattern; op_s_swappc_b64 then translates it only for a vertex stage, at pc 0 and with exactly s[4:5], s[4:5], and refuses every other form. Before this PR the call was cut off with the header, so the inputs read as 0 (the docs say so). The return address and the routine's other register effects are not modelled; the translation stands for the loads only, which the PR states.
  • Fetch address. a = (vid + ud<basevertex>) * ud<stride of the slot's buffer> + offset is the same shape as the existing idxen path (index plus the base-vertex entry value, times the slot's stride). The runtime biases that entry value by -vertex_first (d3d12_draw.inl ~905-935, 1126), so the indexed and non-indexed draws agree. Loads are ByteAddressBuffer, so an out-of-range read returns 0 and cannot fault.
  • Table. Header size must be 0x2f8; records of 5 bytes from +0x138, kind 6, mask >> last == 1, 1 to 4 components, first VGPR at least 1, at most 16 records, the +0x1d8 count must equal the table, overlapping registers are refused. A truncated image or a run to the end of the image ends in IndexError/ValueError/struct.error, which translate_request now catches and reports as invalid stream shader.
  • Layout. The C++ side bounds NumElements (32), checks readability of the array and of each semantic-name byte (64 max, identifier characters only), builds the text before taking draw_lock, and puts it in the key only when non-empty, so keys of streams without a layout are unchanged. .ia is published before .a. The Python side re-validates the text with a strict regex and the element count. DXGI ids 2, 6, 16, 41, 28, 49, 61, 34, 35 match the formats named. APPEND_ALIGNED is resolved per slot and refused after an unknown or off-dword end.
  • Unwritten registers. After a fetch call, any read of a VGPR that neither the fetch nor earlier program lines wrote is refused (v0 aside). This is a straight-line scan, so it is lenient for branches; it is conservative for the case the PR describes.
  • Clean-room. The wording is title-neutral. The numbers in the docs (628 programs, 1,417 records, 1,983 headers) come from local files I do not have, so I cannot confirm them.

Commands run locally on Linux (g++/Python 3.14; no Windows)

  • The PR's own tests/startup_stream_fetch_check.py and tests/startup_vertex_fetch_formats_check.py need the Windows startup_stream_consumer and a D3D12 adapter (they take it as an argument), so I did not run them. Their translator-only assertions I re-ran in a scratch script outside the repository that builds the same container (vertex()/fetch_container() from the test module) plus a root signature and calls translate_request with X2W_FXC='': fetch translates (ok) with (vid + ud1) * ud3 + 0 for slot 0 and (vid + ud1) * ud4 + 0 for slot 1 on r0/r1; no layout, unwritten v12, z-only count 3/2, slot 8 and a header count of 3 all give the exact messages the test expects.
  • A matrix of 15 cases through the same path: kind 7, unknown register, first VGPR 0, overlapping records, per-instance element, unknown format (10), duplicate semantic, wrong count line, append after a 1-byte element, append after R32G32, offset 4294967294, lower-case semantic: each gives the expected ok or a named refusal. A record at VGPR 255 with three components is accepted and declares v256/v257 (P3 below).
  • All 13 tests/startup_gfx2hlsl_*_check.py, startup_translator_check.py: pass. docs_links_check.py (18 files, 370 links), bidi_controls_check.py (1325 files): pass. git diff --check origin/main...HEAD: clean.

Local mutations of tools/startup/gfx2hlsl.py (each restored with git checkout -- ., tree clean afterwards). "Scratch" is my script above; "repo Linux" is the set of Linux-runnable repo checks named above.

Mutation scratch repo Linux
base-vertex entry value replaced by the start-instance one fails passes
mask >> last != 1 and the count range check removed fails passes
slot bound >= 8 made > 8 fails passes
record-kind check (kind != 6) removed passes passes
per-instance elements accepted passes passes

The first three are covered by the PR's Windows draw and refusal cases (base vertex draw, z-only, slot 8), which I could only reproduce as text. The last two are not covered by the PR's check at all (its refusal list is: no layout, unwritten, z-only, slot 8, header count).

Findings

  1. P2, test gap: nothing pins the record-kind refusal, the per-instance refusal or the unknown-format refusal, all named in the docs under "Refused". The two mutations above survive both my scratch run and the PR's case list. One line each in check() (a record of kind 7; a layout line with class 1 and step 1; format 10) would pin them; they are translator-only, like the existing z-only and slot 8 cases.
  2. P3, nothing runs on Linux: every assertion of the new check sits behind the consumer executable, so the Linux CI jobs never reach the translation text. The refusal cases and a text check of the fetch loads need only gfx2hlsl.py and could run there.
  3. P3, VGPR range: vgpr + count is not bounded by 256 (a record at v255 with three components emits v256 and v257). Harmless (extra locals), but a record that reaches past v255 is not a valid table.
  4. P3, doc: the closing paragraph says the pixel stage reads attribute N from output N without pairing by semantic. That is outside this PR, but it means a correct fetch can still draw wrong parameters.

Not run: a Windows build, CTest, the WARP/hardware draws, DXC/FXC on the emitted loads, and the archive census behind the table.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 19:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851#pullrequestreview-6046179491) · **reviewed** Review of head `ddd6db71d59a98e88c01ce9b23da58e8e684e6ce` (three merges of main on top of `a8f581c4`, `f0202ea5` and `15ce041b`; base `origin/main`). **Verdict: no P1. One P2 (test gap, not a correctness defect I could demonstrate), three P3.** **What I read** The whole diff against `origin/main` (9 files): `stream_input_layout` and the cache key in `src/startup_stubs/d3d12_draw.inl`; `strip_header`, `stream_fetch`, `parse_input_layout`, `signature_inputs`, `op_s_swappc_b64`, `load_format`, the unwritten-register guard in `hlsl_vs` and the `.ia` request path in `tools/startup/gfx2hlsl.py`; `container_image` in `tools/pixel_aot.py`; the docs paragraph. **Reading, point by point** - *Call and register ABI.* `strip_header` keeps a dword before the prefetch only when it matches the SOP1 `s_swappc_b64` pattern; `op_s_swappc_b64` then translates it only for a vertex stage, at pc 0 and with exactly `s[4:5], s[4:5]`, and refuses every other form. Before this PR the call was cut off with the header, so the inputs read as 0 (the docs say so). The return address and the routine's other register effects are not modelled; the translation stands for the loads only, which the PR states. - *Fetch address.* `a = (vid + ud<basevertex>) * ud<stride of the slot's buffer> + offset` is the same shape as the existing idxen path (index plus the base-vertex entry value, times the slot's stride). The runtime biases that entry value by `-vertex_first` (`d3d12_draw.inl` ~905-935, 1126), so the indexed and non-indexed draws agree. Loads are `ByteAddressBuffer`, so an out-of-range read returns 0 and cannot fault. - *Table.* Header size must be `0x2f8`; records of 5 bytes from `+0x138`, kind 6, `mask >> last == 1`, 1 to 4 components, first VGPR at least 1, at most 16 records, the +0x1d8 count must equal the table, overlapping registers are refused. A truncated image or a run to the end of the image ends in `IndexError`/`ValueError`/`struct.error`, which `translate_request` now catches and reports as `invalid stream shader`. - *Layout.* The C++ side bounds `NumElements` (32), checks readability of the array and of each semantic-name byte (64 max, identifier characters only), builds the text before taking `draw_lock`, and puts it in the key only when non-empty, so keys of streams without a layout are unchanged. `.ia` is published before `.a`. The Python side re-validates the text with a strict regex and the element count. DXGI ids 2, 6, 16, 41, 28, 49, 61, 34, 35 match the formats named. APPEND_ALIGNED is resolved per slot and refused after an unknown or off-dword end. - *Unwritten registers.* After a fetch call, any read of a VGPR that neither the fetch nor earlier program lines wrote is refused (v0 aside). This is a straight-line scan, so it is lenient for branches; it is conservative for the case the PR describes. - *Clean-room.* The wording is title-neutral. The numbers in the docs (628 programs, 1,417 records, 1,983 headers) come from local files I do not have, so I cannot confirm them. **Commands run locally on Linux** (g++/Python 3.14; no Windows) - The PR's own `tests/startup_stream_fetch_check.py` and `tests/startup_vertex_fetch_formats_check.py` need the Windows `startup_stream_consumer` and a D3D12 adapter (they take it as an argument), so I did not run them. Their translator-only assertions I re-ran in a scratch script outside the repository that builds the same container (`vertex()`/`fetch_container()` from the test module) plus a root signature and calls `translate_request` with `X2W_FXC=''`: fetch translates (`ok`) with `(vid + ud1) * ud3 + 0` for slot 0 and `(vid + ud1) * ud4 + 0` for slot 1 on `r0`/`r1`; no layout, unwritten `v12`, z-only count 3/2, slot 8 and a header count of 3 all give the exact messages the test expects. - A matrix of 15 cases through the same path: kind 7, unknown register, first VGPR 0, overlapping records, per-instance element, unknown format (10), duplicate semantic, wrong count line, append after a 1-byte element, append after R32G32, offset 4294967294, lower-case semantic: each gives the expected `ok` or a named refusal. A record at VGPR 255 with three components is accepted and declares `v256`/`v257` (P3 below). - All 13 `tests/startup_gfx2hlsl_*_check.py`, `startup_translator_check.py`: pass. `docs_links_check.py` (18 files, 370 links), `bidi_controls_check.py` (1325 files): pass. `git diff --check origin/main...HEAD`: clean. **Local mutations of `tools/startup/gfx2hlsl.py`** (each restored with `git checkout -- .`, tree clean afterwards). "Scratch" is my script above; "repo Linux" is the set of Linux-runnable repo checks named above. | Mutation | scratch | repo Linux | |---|---|---| | base-vertex entry value replaced by the start-instance one | fails | passes | | `mask >> last != 1` and the count range check removed | fails | passes | | slot bound `>= 8` made `> 8` | fails | passes | | record-kind check (`kind != 6`) removed | **passes** | passes | | per-instance elements accepted | **passes** | passes | The first three are covered by the PR's Windows draw and refusal cases (base vertex draw, z-only, slot 8), which I could only reproduce as text. The last two are not covered by the PR's check at all (its refusal list is: no layout, unwritten, z-only, slot 8, header count). **Findings** 1. **P2, test gap:** nothing pins the record-kind refusal, the per-instance refusal or the unknown-format refusal, all named in the docs under "Refused". The two mutations above survive both my scratch run and the PR's case list. One line each in `check()` (a record of kind 7; a layout line with class 1 and step 1; format 10) would pin them; they are translator-only, like the existing z-only and slot 8 cases. 2. **P3, nothing runs on Linux:** every assertion of the new check sits behind the consumer executable, so the Linux CI jobs never reach the translation text. The refusal cases and a text check of the fetch loads need only `gfx2hlsl.py` and could run there. 3. **P3, VGPR range:** `vgpr + count` is not bounded by 256 (a record at v255 with three components emits `v256` and `v257`). Harmless (extra locals), but a record that reaches past v255 is not a valid table. 4. **P3, doc:** the closing paragraph says the pixel stage reads attribute N from output N without pairing by semantic. That is outside this PR, but it means a correct fetch can still draw wrong parameters. **Not run:** a Windows build, CTest, the WARP/hardware draws, DXC/FXC on the emitted loads, and the archive census behind the table. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 19:44 UTC · original · requested changes

The new fetched-VGPR check in hlsl_vs does not establish definite assignment across control flow. It accepts a line beginning with if (exec & 1), then unconditionally adds that destination to written. A fetched vertex program can write an otherwise unfetched register only under a false EXEC predicate and subsequently export it. This check accepts that path and the generated HLSL uses the initialized zero, even though the PR promises refusal for a never-defined register. A branch path that skips an unguarded assignment has the same problem.

Please add a source-built refused case where the only write is masked off (or bypassed by a branch). Scope the first slice to a path you can prove, or track definitions on every incoming path. Keep the legitimate multiple-buffer draw and the existing no-layout and unwritten controls.

**@⁠R0Y00** on GitHub · 2026-11-24 19:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851#pullrequestreview-6046180153) · **requested changes** The new fetched-VGPR check in hlsl_vs does not establish definite assignment across control flow. It accepts a line beginning with if (exec & 1), then unconditionally adds that destination to written. A fetched vertex program can write an otherwise unfetched register only under a false EXEC predicate and subsequently export it. This check accepts that path and the generated HLSL uses the initialized zero, even though the PR promises refusal for a never-defined register. A branch path that skips an unguarded assignment has the same problem. Please add a source-built refused case where the only write is masked off (or bypassed by a branch). Scope the first slice to a path you can prove, or track definitions on every incoming path. Keep the legitimate multiple-buffer draw and the existing no-layout and unwritten controls.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 20:31 UTC · original · approved these changes

Re-reviewed d1d4c28b. The entry-block rule and the masked/bypassed definition controls address my earlier finding. Both cache-key implementations use revision 5 and include the stream layout when present. Release passed the translator and six WARP/RTX stream fetch, viewport and depth tests, with no skips. The workflow change only adds the device-free stream translator test to the existing Linux job.

**@⁠R0Y00** on GitHub · 2026-11-24 20:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1851#pullrequestreview-6046900225) · **approved these changes** Re-reviewed d1d4c28b. The entry-block rule and the masked/bypassed definition controls address my earlier finding. Both cache-key implementations use revision 5 and include the stream layout when present. Release passed the translator and six WARP/RTX stream fetch, viewport and depth tests, with no skips. The workflow change only adds the device-free stream translator test to the existing Linux job.
This discussion has been locked. Commenting is limited to contributors.
No description provided.