startup: translate the fetch call of stream vertex shaders from the input layout #1844
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1851"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T19:36:10Z.
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_headerdropped 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.INPUT_LAYOUTsubobject of the stream and publishes it asreq_<key>.iabefore.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.pykeeps a call that sits before the prefetch and translates it as vertex-buffer loads (srv buf vb <slot>plus a stride value).s_wqm exec, execalone stays a no-op. A read of any other register is refused.Programs without the call are unaffected. The shared interface touched is the shader request format (
req_<key>.iais new) andpipeline_key, which now takes the layout.Refs #1142. AI-assisted (Claude Code).
Verification
On
d1d4c28b(merged withmainatb560c3be), 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:startup_stream_fetch_translate(translator only, also in the Linux job;python -B tests/startup_stream_fetch_check.py):s_wqm_b32 exec_lo, 0before 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_wqmnot 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
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.docs/startup-runtime.mdhas a new section for the request file and the log line.Checklist
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:44:53Z.
Review: COMMENTED
Review of head
ddd6db71d59a98e88c01ce9b23da58e8e684e6ce(three merges of main on top ofa8f581c4,f0202ea5and15ce041b; baseorigin/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_layoutand the cache key insrc/startup_stubs/d3d12_draw.inl;strip_header,stream_fetch,parse_input_layout,signature_inputs,op_s_swappc_b64,load_format, the unwritten-register guard inhlsl_vsand the.iarequest path intools/startup/gfx2hlsl.py;container_imageintools/pixel_aot.py; the docs paragraph.Reading, point by point
strip_headerkeeps a dword before the prefetch only when it matches the SOP1s_swappc_b64pattern;op_s_swappc_b64then translates it only for a vertex stage, at pc 0 and with exactlys[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.a = (vid + ud<basevertex>) * ud<stride of the slot's buffer> + offsetis 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 areByteAddressBuffer, so an out-of-range read returns 0 and cannot fault.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 inIndexError/ValueError/struct.error, whichtranslate_requestnow catches and reports asinvalid stream shader.NumElements(32), checks readability of the array and of each semantic-name byte (64 max, identifier characters only), builds the text before takingdraw_lock, and puts it in the key only when non-empty, so keys of streams without a layout are unchanged..iais 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.Commands run locally on Linux (g++/Python 3.14; no Windows)
tests/startup_stream_fetch_check.pyandtests/startup_vertex_fetch_formats_check.pyneed the Windowsstartup_stream_consumerand 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 callstranslate_requestwithX2W_FXC='': fetch translates (ok) with(vid + ud1) * ud3 + 0for slot 0 and(vid + ud1) * ud4 + 0for slot 1 onr0/r1; no layout, unwrittenv12, z-only count 3/2, slot 8 and a header count of 3 all give the exact messages the test expects.okor a named refusal. A record at VGPR 255 with three components is accepted and declaresv256/v257(P3 below).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 withgit checkout -- ., tree clean afterwards). "Scratch" is my script above; "repo Linux" is the set of Linux-runnable repo checks named above.mask >> last != 1and the count range check removed>= 8made> 8kind != 6) removedThe 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
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.gfx2hlsl.pyand could run there.vgpr + countis not bounded by 256 (a record at v255 with three components emitsv256andv257). Harmless (extra locals), but a record that reaches past v255 is not a valid table.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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:44:56Z.
Review: CHANGES_REQUESTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T20:31:30Z.
Review: APPROVED
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.Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T20:18:45Z.
Both reviews are addressed in
d1d4c28b(merged withmainatb560c3be; 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; onlys_wqm exec, execstays a no-op, and others_wqmforms,exec_hiwrites and unmodelled exec writes are refused. New source-built refused cases: the only write under a masked-off exec, the only write skipped by ans_branch,s_wqm_b32 exec_lo, 0before the write, ands_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 CTeststartup_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).
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T20:36:24Z.
Ran the translator controls and broke three parts of the new slice
At the PR head, device-free:
Three mutations to
tools/startup/gfx2hlsl.py, each reverted:FETCH_SLOTS = 8→16(the stand-in binds eight slots)FETCH_COUNT = 0x1d8→None(the record-count field no longer read)FETCH_CALL = 0xbe842104→0xbe842105(the call is no longer recognised)The third is the important one for this slice: if the call is not recognised,
strip_headereats it and every fetched inputreads 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_translatecontrols. So my table says nothing about the GPU path — the PR reports both backends, and I am taking those asreported rather than verified.
The constants are documented, which matters here
FETCH_RECORDS = 0x138andFETCH_COUNT = 0x1d8are container-layout facts, and lines 64–71 say where they came from: "checkedoffline 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_COUNTmutation above.Layout notes
CMakeLists.txtregisters both shapes:startup_stream_fetch_translate(device-free) andstartup_stream_fetch_<backend>withSKIP_RETURN_CODE 77. TheX2W_FXCenv passthrough on the draw test is the samepattern the other translate/draw pairs use.
AGENTS.mdgains the check in the platform-independent list, and.github/workflows/windows.ymlgains one line, so it runson 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