startup: convert GPU-written rectangle-list indirect Draw arguments (Part of #1999) #2165
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2173"
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 tedin7 on 2026-11-25T02:50:59Z.
Part of #1999
What this unblocks: GPU-written indirect
Drawrecords recorded under the console-only rectangle-list topology (0x11) now reach the desktop as a triangle-list draw (item E, non-indexed).Changes:
ExecuteIndirectwith topology 0x11 runs a one-thread compute pass that writescount / 3 * 6(other words unchanged) into a scratch record; the desktop draw reads that record. The title's argument buffer is not modified. A count that would overflow 32 bits draws nothing.docs/experiments.md.convert_indirect_draw_argumentswith controls intests/rectlist_topology_check.py.rectmode instartup_indirect_draw_indexed(cteststartup_indirect_rectlist_{warp,hardware}): compute-written 1 and 2 rectangles, D3D12 pixel readback against the expected halves, argument words checked unchanged, plus omitted-producer, short-argument, missing-viewport and overflowing-count cases.Verification:
python3 -B tests/rectlist_topology_check.py(18 tests OK),python3 -B tests/docs_links_check.py(OK).4c70d27e, viapython3 x2w_pipe.py win2025 2173 --force:cmake --build --preset dev --target <25 targets> -- -j 3OK (compilation failures 0);ctest --preset dev -R '^(cpu_native_shim_startup|cpu_shim_*_warp|d3d12x_*_warp|rectlist_draw_warp|rectlist_topology|startup_indirect_{counts_control,draw,draw_indexed,mesh,rectlist}_warp|startup_sampler_heap_wrapped_warp|startup_stubs|xgameruntime_preflight_stub_refused)$' --parallel 2 --no-tests=error --output-on-failure: 28/28 passed, 0 skipped.cmake --build --preset release --target <same 25 targets> -- -j 3OK; samectest --preset release -R ...: 28/28 passed, 0 skipped.*_hardware) not run: the Windows node only has WARP.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T04:19:17Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
4c70d27ed8ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:40:03Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:40:05Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T04:13:09Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
4c70d27ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T04:19:17Z.
Code review location:
src/startup_stubs/rect_indirect_args.h; line 34For a rectangle-list record with a nonzero start, such as
(3, 1, 3, 0)selecting the second three-vertex rectangle, this expands the count but leavesStartVertexLocationin the original vertex domain. The newvertex_rectfixture shader computes the rectangle asSV_VertexID / 6, so the resulting desktop vertices 3 through 8 produce one triangle from each of two rectangles instead of both triangles of the second rectangle. Translate the start consistently with the expansion, including overflow handling, or reject unsupported nonzero starts.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T04:19:17Z.
Code review location:
src/startup_stubs/rect_indirect_args.h; line 86When two direct queues on the same device execute rectangle-list draws concurrently, this cache gives both recordings the same scratch buffer.
queue_executesubmits asynchronously, and neither its submission bookkeeping nor the transitions inconvertandfinishestablish a cross-queue dependency. One queue can therefore overwrite the converted argument words while the other queue is consuming them, causing incorrect draw counts or resource-state hazards even when the application's original buffers are independent. Allocate scratch storage per in-flight use or synchronize its reuse across queues.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:40:03Z.
Code review location:
src/startup_stubs/rect_indirect_args.h; line 34Fixed in
d1837dde. A desktop draw's StartVertexLocation never reaches SV_VertexID (the fixture on WARP showed the record(3, 1, 3, 0)still drew the first rectangle), and an indirect draw has no root constant to pass the start to the shader as the direct draw does. A nonzero start vertex cannot be honoured, so the conversion pass now writes 0 vertices for it (nothing is drawn) instead of forwarding a start that names the wrong rectangle. Model, header comment and docs updated.Regression:
tests/rectlist_topology_check.py(test_nonzero_start_vertex_draws_nothing) and thestartup_indirect_rectlistfixture case "nonzero start vertex" (record(3, 1, 3, 0), target stays clear, argument words intact). Executed locally:python3 -B tests/rectlist_topology_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py,tests/run_checks_parallel_check.pyall OK. Win2025 3-slotx2w_pipe.py win2025 2173 --force: dev 28/28 and release 28/28 passed, 0 skips.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:40:05Z.
Code review location:
src/startup_stubs/rect_indirect_args.h; line 86Fixed in
14a50ec4(kept ind1837dde). The conversion no longer uses one scratch buffer per device. Each recorded conversion now takes its own scratch buffer from the allocator that holds the recording; buffers are reused only when that allocator is Reset, which already requires it to be idle. Lists running on different queues therefore never share scratch words or its resource state.Regression: the
startup_indirect_rectlistfixture now asserts that every recording holds exactly one scratch buffer on its own allocator (0 for refused draws) through a new fixture export. Executed locally: same Linux checks as above, and Win2025 3-slotx2w_pipe.py win2025 2173 --force: dev 28/28 and release 28/28 passed, 0 skips.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T05:28:28Z.
Review: CHANGES_REQUESTED
This still needs the #2181 merge resolution, retaining the rooted Dispatch restrictions. The rectangle conversion also uses one scratch buffer per device. Two direct queues can execute their conversion passes concurrently, between another queue's conversion and ExecuteIndirect. One queue can then draw using the other queue's argument count. Please allocate scratch per recorded operation, retain it through the recording and every consuming queue fence, or refuse an unproved overlap. A two-queue fence-controlled case with different argument counts should match both expected targets, with shared scratch as the negative. The converter should also refuse before it mutates a live compute root with arguments unless it can restore those arguments.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:53:47Z.
Pushed
6430ac24(merged current main on top; the code change is in7ac8d821).startup_indirect_rectlist_*now also runs two recordings with different counts (one and two rectangles) on two queues, 24 rounds each, with both submits released together. Each target must match its own count. I did not add a shared-scratch negative: that would need test-only production code, and the interleaving between the conversion and the draw sits inside one runtime call, so I cannot hold it open from the fixture. Tell me if you want a different shape.tests/docs_links_check.pyandtests/rectlist_topology_check.pypass.x2w_pipe.py win2025 2173 --force: dev and release both 100% passed, 28 of 28, zero skips.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T06:02:39Z.
Ran head
6430ac24(build targetstartup_indirect_draw_indexed). WARP passes; the hardware run fails on an Intel HD Graphics 530. Windows 11 build 26100, debug layer unavailable.startup_indirect_rectlist_warpstartup_indirect_rectlist_hardwareone rectangle: 0/8 non-clear pixels, argument guards intact, withpixel (0,0): got 0xff000000, expected 0xff0000ffand the same for (1,0), (0,1), (1,1)The draw writes nothing on Gen9. The argument guards stay intact, so the indirect arguments are not corrupted; the rectangle simply produces no pixels. The existing
startup_indirect_draw_hardware,startup_indirect_draw_indexed_hardwareandstartup_indirect_dispatch_hardwarefrom the same build pass on the same adapter. This looks specific to the rectangle-list path on that driver, but I have not pinned the cause.A second point: this executable ignores
XBOX2WINDOWS_ADAPTER. WithXBOX2WINDOWS_ADAPTER=Quadroit still printedadapter: Intel(R) HD Graphics 530(the first hardware adapter on this laptop), so I have no NVIDIA Quadro M1000M result for this test. Logs are available if useful.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T06:12:48Z.
Thank you @legacy-code-archaeologist, this was a real find.
Root cause: the one-thread conversion pass read the four draw words with a single 16-byte
Load4from a root SRV address. The title's draw record can sit at any 4-byte offset (the fixture places it at byte 4), and that unaligned vector load is not valid on every GPU. WARP accepts it. On Gen9 the converted count was wrong, so nothing was drawn, while the guard words stayed intact, as you saw.Fix in
ae093613: the four words are now read and written as scalar 4-byte accesses. The existingstartup_indirect_rectlist_*cases already use the 4-byte offset, so they cover this exact layout.Verification:
python3 tests/docs_links_check.pyandpython3 tests/rectlist_topology_check.py: pass.x2w_pipe.py win2025 2173 --force: dev and release both 100% passed, 28 of 28, zero skips.Could you re-run
startup_indirect_rectlist_hardwareon the HD 530 with the new head? I have no Gen9 hardware here, so the hardware result is yours to confirm. Also noted: the executable ignoringXBOX2WINDOWS_ADAPTER. I'll look at that separately.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T06:23:25Z.
@tedin7 I re-ran head
ae093613(worktree,startup_indirect_draw_indexedrebuilt). It still fails on the HD 530, identically to before:startup_indirect_rectlist_warpstartup_indirect_rectlist_hardwareone rectangle: 0/8 non-clear pixels, argument guards intact, andpixel (0,0)…(1,1): got 0xff000000, expected 0xff0000ffSo the scalar loads do not change the outcome on Gen9; the unaligned
Load4was not the cause there, or not the only one. Things I checked without finding anything:convert()has the COMMON → UNORDERED_ACCESS → INDIRECT_ARGUMENT transitions around the dispatch, so a missing state transition on the scratch buffer is not it.startup_indirect_draw_hardware,_draw_indexed_hardwareand_dispatch_hardwarepass on this adapter, so plainExecuteIndirectworks here.I have not narrowed it further. What would separate the remaining possibilities on Gen9 is a readback of the scratch buffer after the conversion. It would show whether the converted count is wrong (the conversion, or how the source root SRV reads at byte offset 4) or the four words are right and the draw itself produces nothing. If you add a debug readback or a fixture case that dumps those words, I can run it here.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T06:32:07Z.
Thank you @legacy-code-archaeologist, and sorry the scalar-load change did not help. Your point that the draw record and guards were intact, and that the plain indirect draw tests pass on the same adapter, narrowed this to what is special about the conversion pass.
I have not isolated the exact Gen9 cause, so this is a change that removes the suspect, not a confirmed diagnosis. The pass read the title's argument buffer through a raw-buffer root SRV at an arbitrary 4-byte offset into a very small placed buffer. That is the only binding in the rectangle path that no other passing indirect test uses.
Fix in
0bb97ff3:CopyBufferRegioncopies the four draw words into the per-recording scratch buffer (a copy has no alignment rule).COPY_SOURCE(it was argument state plusNON_PIXEL_SHADER_RESOURCE). The scratch goes COMMON, COPY_DEST, UNORDERED_ACCESS, INDIRECT_ARGUMENT, COMMON, so each use has its own transition.I cannot run the debug layer or Gen9 here, so the hardware result is still yours to confirm. If
startup_indirect_rectlist_hardwarestill shows 0/8 on the HD 530 with this head, a scratch readback fixture would be the next step, as you suggested, and I will add one.Verification:
python3 tests/docs_links_check.pyandpython3 tests/rectlist_topology_check.py: pass.x2w_pipe.py win2025 2173 --force: dev and release both 100% passed, 28 of 28, zero skips (startup_indirect_rectlist_warpincluded).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T06:40:12Z.
@tedin7 Re-ran head
0bb97ff3(worktree,startup_indirect_draw_indexedrebuilt). No change on the HD 530: still 0/8.startup_indirect_rectlist_warpstartup_indirect_rectlist_hardwareone rectangle: 0/8 non-clear pixels, argument guards intact, withpixel (0,0)…(1,1): got 0xff000000, expected 0xff0000ff. The case is reported twice in the log with the same result.startup_indirect_draw_hardware,startup_indirect_draw_indexed_hardware(same build, same adapter)So the root-SRV binding of the title buffer was not the cause either. With the copy into owned scratch, the conversion pass now touches only its own buffer, and the result is identical. That points either at the conversion's output (count or the other words in the scratch) or at the six-vertex triangle draw that replaces the rectangle. Neither the plain nor the indexed indirect draw shows the problem. This suite has no non-indirect rectangle-list draw I could run to separate the two, so the scratch readback fixture is the next step. I'll run it here when it's up.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T06:48:55Z.
Thank you @legacy-code-archaeologist, the 0/8 with intact guards on the HD 530 is clear and the "same result after the copy" data rules out two suspects.
I compared every D3D12 call of the rectangle path against the passing indirect fixtures at head
0bb97ff3, and I do not find a concrete API fault, so I am not pushing another guess:ALLOW_UNORDERED_ACCESS, COMMON -> COPY_DEST -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMON. Every transition has a matching before/after state; there is no UPLOAD/UAV mix.cs_5_0RWByteAddressBuffer, scalar accesses only. The graphics pipeline, graphics root signature, topology, viewport, scissor and targets are all re-applied after the compute pass, beforeExecuteIndirect.What is left, and where the two cases differ from the passing plain draw:
vertex_rectvertex shader: it indexes a local constant array withSV_VertexID % 6and builds a fourth corner. The passing draws use a simpler vertex shader.A scratch readback separates (1) from the rest. The next step is a small diagnostic fixture case that dumps the scratch words, to be run on the HD 530. The production path stays unchanged until then.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T07:53:25Z.
@tedin7 One more data point while the readback case is pending, from
main(e94e14ff) on the same HD 530 (driver 31.0.101.2111).rectlist_draw_checktakes the first non-software adapter, which on this laptop is the Intel GPU.rectlist_draw_hardwarepositive_draw=pass mismatches=0,reversed_winding_cull_control=pass culled_mismatches=900,wrong_corner_mutant_control=pass detected_mismatches=435,desktop_raw_topology_rejection=passrectlist_draw_warpThat path draws the rectangle-to-triangle conversion from a vertex buffer with a pass-through vertex shader (
tests/rectlist_quad.hlsl), withoutExecuteIndirect. So Gen9 rasterizes the replacement triangles correctly. Of your two remaining candidates, this does not separate them, but it narrows (2): the difference from the passing paths is specificallyvertex_rect, theSV_VertexID-indexed localcorner[6]array with the derived fourth corner, combined with the indirect count. The scratch readback is still the cleanest split. A variant ofvertex_rectthat computescarithmetically instead of from the local array would be a second cheap check, and I can run either here.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:50:40Z.
Thanks for the review, @legacy-code-archaeologist. Updated head:
88da5b31, rebased onto the latestmain(including #2259 and #2283).Changes:
Dispatchand the transition toINDIRECT_ARGUMENT.startup_indirect_draw_indexed.cpp. If pixels mismatch, it prints the title's 4 draw words, the CPU reference count, and the 4 GPU-converted words from a readback copy. Passing runs are not affected.Verification (Windows Server 2025, Build 26100, MSVC 14.44 + D3D12 WARP, 3-slot pool):
python3 x2w_pipe.py win2025 2173 --forcectest --preset dev(focused WARP/startup set, includingstartup_indirect_rectlist_warp): 42/42 passedctest --preset release(same set): 42/42 passedAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T10:52:40Z.
@tedin7 Ran head
88da5b31on the HD 530 (Intel HD Graphics 530, driver 31.0.101.2111, Windows 11 build 26100, debug layer unavailable). The diagnostic answers the question: the conversion is correct, the draw is not.The case runs twice in the log with identical output. The explicit UAV barrier does not change the pixels.
startup_indirect_rectlist_warpstill passes all cases.So on Gen9 the conversion pass, the copy and the barrier produce
DrawInstanced(6, 1, 0, 0)as intended, and the 6-vertex draw still writes nothing. One caveat: the diagnostic converts a fresh copy of the words, not the scratch the recorded draw consumed. With the per-recording scratch, the barriers and identical code, I would expect the same words there.That leaves the draw side.
rectlist_draw_hardware(vertex buffer, pass-through VS) andstartup_indirect_draw_hardware(indirect, plain VS) both pass on this adapter. What remains specific to this case isvertex_rect: theSV_VertexID-indexed localcorner[6]array, the per-rectanglev0/v1/v2selection, and the derivedv3. A case that issues the samevertex_rectPSO with a directDrawInstanced(6, 1, 0, 0)would confirm it without the indirect path. A variant ofvertex_rectthat computes the corner arithmetically, for examplec = (id % 6 < 3) ? id % 6 : (id % 6 == 3 ? 0 : id % 6 - 2), would show whether the dynamic local array is the issue. I can run either on this adapter.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-25T11:22:45Z.
@tedin7 Confirmed: head
303634a0passes on the HD 530.startup_indirect_rectlist_hardwarestartup_indirect_rectlist_warpTogether with the previous run, where the conversion read back
6 1 0 0and the draw still wrote nothing, this pins the Gen9 failure to the fixture'svertex_rect: anSV_VertexID-indexed local array. The arithmetic corner selection draws correctly on the same driver. The conversion pass and the production path were correct all along. The earlier scalar-load, scratch-copy and UAV-barrier changes were not needed for Gen9. Whether you keep them is your call.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:41:07Z.
Thank you @legacy-code-archaeologist: the 4-DWORD readback on the HD 530 (
6 1 0 0) showed that the rectangle-list conversion writes exactly the expected words, so the conversion itself is correct and the Gen9 difference sits in thevertex_rectvertex shader oftests/startup_indirect_draw_indexed.cpp.Pushed
303634a0:vertex_rectno longer indexes a local array withSV_VertexID. The corner sequence 0,1,2,0,2,3 is computed with plain arithmetic (k = id % 6,c = (k < 3) ? k : (k == 3 ? 0 : k - 2)) and the position is picked with scalar selects. The other vertex shaders in that test and intests/rectlist_quad.hlslalready had no dynamically indexed local arrays.Verification (Windows Server 2025 build 26100, MSVC 14.44.35207, D3D12 WARP, commit
303634a0):--preset dev: build OK, ctest 42/42 passed (100%), includingstartup_indirect_draw_indexed_warp,startup_indirect_rectlist_warp,rectlist_draw_warp,rectlist_topology.--preset release(/O2): build OK, ctest 42/42 passed (100%), same tests.tests/rectlist_topology_check.py18 tests OK,git diff --checkclean.WARP is not the affected adapter, so these results do not prove the HD 530 now matches. Could you re-run the test on the HD 530 and tell us whether the pixels now agree?
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T12:25:09Z.
I checked the conflict-resolved head
7edfe068with the combined Windows Release rectangle and mesh lease tests. All six passed on WARP and RTX 4060 Laptop. The independent HD 530 result at303634a0also covers the arithmetic-corner fixture change.The remaining concurrency control is that the two recordings must demonstrably use different scratch resources while both queue submissions can still consume them. The existing two-thread gate releases both submits together, so it verifies their outputs but may miss a build where the driver happens to serialize a shared scratch buffer. A deterministic scratch-identity check with a deliberately shared negative would satisfy this part of the existing review.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T13:10:43Z.
Review: APPROVED
Re-reviewed
6a2c0442against the original change request. The fixture rejects a deliberately shared scratch resource before either queue submits. The isolated scratch path preserves the one- and two-rectangle readbacks. The live desktop compute SRV now stays protected across both a repeated root binding and a guest root call that is not forwarded. Both draws were refused and the next compute dispatch read the preserved SRV word.The conflict resolution keeps the rooted Dispatch checks and the #2332 argument lease. Windows Release passed all 10 selected rectangle, root-SRV lease and indirect argument lease cases on WARP and RTX 4060 Laptop.