Skip to content

D3D12.X: a draw waits at most 4 s for a pipeline still building (#232) - #267

Draft
heretic1321 wants to merge 1 commit into
ivall:mainfrom
heretic1321:fix/retail-null-write-232
Draft

heretic1321 wants to merge 1 commit into
ivall:mainfrom
heretic1321:fix/retail-null-write-232

Conversation

@heretic1321

@heretic1321 heretic1321 commented Nov 23, 2026 •

Copy link
Copy Markdown

Part of #232. This is a hypothesis with instrumentation. I have not run the title, and I have no NVIDIA card. Rebased on 4017f8f. Updated for Kalmarv's review; the per-point answers are under Review.

Root cause (hypothesis)

Change (pso_async.rs, bind.rs, real.rs)

  • pso_async::resolve_for_draw, used by graphics_bound and execute_indirect. A graphics pipeline that is still building goes to the workers, never into the title's thread. Each draw waits for it at most XCL_PSO_WAIT_MS (default 4000; 0 = no limit, the old behaviour). Past that the draw goes with the stand-in.
  • execute_indirect with a pipeline that is not translated (a PC pipeline, a stand-in past the limit, a failed build) binds the title's graphics root signature first, as graphics_bound does.
  • Draws that went with a stand-in are counted in report.json → d3d12.standin_draws and logged.
  • Compute pipelines are still waited for, as before.
  • Any pipeline wait of ≥ 2 s logs the thread, the pipeline and where it was built (up to 32 lines).

Review (Kalmarv, on b5c9057)

  1. ExecuteIndirect without the title's root signature: fixed. The not-translated branch now binds rs_gfx before pc(…). It does this for every pipeline in that branch, not only stand-ins, the same as graphics_bound. Binding the graphics root signature changes no compute state, so an indirect dispatch with a PC compute pipeline is unaffected. Test: bind::tests::execute_indirect_with_a_stand_in_binds_the_titles_root_signature_first records the call order on a fake list and checks that SetGraphicsRootSignature(rs) comes before ExecuteIndirect. It fails without the fix (only ExecuteIndirect is recorded).
  2. A shared remainder per present, ~2× the limit: replaced with a limit per draw. Each draw gets the whole XCL_PSO_WAIT_MS, with no shared state and no tie to PresentX. Why per draw rather than per thread:
    • It removes the race (concurrent draws each took the full remainder). It removes the refill coupling (one budget before the first present, a fresh one after another thread's present).
    • No pipeline is lost because an earlier draw used up the budget, which was your 2 s row.
    • A per-thread budget still needs a refill event. The title's recording threads don't present, so the refill would again come from another thread's PresentX.
    • Cost: one thread that draws N new, slow pipelines back to back can be held N × limit. Each of those draws logs one line, and XCL_PSO_WAIT_MS=1 makes the total about N ms.
  3. Threshold: 4 s is a safety margin, not a measured threshold. I can't derive it soundly from the decode:
  4. Collision with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214's test module: fixed. Mine is now mod draw_wait_tests. If D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 lands first, resolve_within should call enqueue(p.clone()) instead of its own sent swap + send, so that a pipeline first sent by a draw is counted in QUEUED (the third number of background_pipelines). My earlier account of D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 described an older head: f007d4a does not change resolve_wait.
  5. A draw past the limit is lost, not delayed. It goes to the GPU with the stand-in, draws nothing, and nothing replays it. Later draws use the real pipeline once it is built. Before this push it showed only in the log and was counted as a DRAWS_PC draw, indistinguishable in report.json from a draw with a PC pipeline. It is now counted on its own in report.json → d3d12.standin_draws. Also as you noted: the build is no longer taken by the thread that needs it, so it waits its turn behind everything queued at SetPipelineState. With a deep queue, or D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214's two driver slots on NVIDIA, the limit buys less progress on the pipeline being drawn.

Overlaps

What the reporter must verify on the 4070 Ti
On plain main + this branch, with no local #203 / #211 / #215 merges, release build, the same package:

  1. XCL_NETWORK=0 XCL_ACTIVITY=1 xcl run <game>. Check whether +0x2215c35 still happens, and note the presents and d3d12.standin_draws in report.json.
  2. Search the log for waited .* for (graphics|compute) pipeline and not built after. A long compute wait right before the crash points at the compute side, which this PR does not change.
  3. XCL_PSO_WAIT_MS=1: draws don't wait for pipeline builds at all. If the crash still comes with this, draw waits are not what the watchdog sees.
  4. XCL_PSO_WAIT_MS=0 (the old unbounded wait). If the crash comes back only here, this is the cause.
  5. If it still crashes: with a debugger, break at 0x142215C35 and dump 4 KiB at 0x146844A20 (the decode's timer table: 57 slots × 72 B). The slot with the oldest non-zero timestamp names the stalled subsystem, and the difference to now gives the threshold's unit. Or attach XCL_THREAD_DUMP_AT=40,65 dumps.

Tested

  • Linux host (no Windows, no GPU), Rust stable, head 043d1f7 on 4017f8f: AR_x86_64_pc_windows_msvc=llvm-ar cargo check --release --workspace --target x86_64-pc-windows-msvc exit 0, no warnings, and the same with --tests exit 0.
  • pso_async.rs unchanged in a throwaway Linux crate, with stubs only for the log macros, compile_threads, present::activity and the COM release: draw_wait_tests 2 passed, 0 failed. Sabotage check (previous head, same wait logic): with the old resolve_wait path put back, the draw runs the blocked build itself and the test hangs (killed by timeout 30).
  • bind::tests::execute_indirect_with_a_stand_in_binds_the_titles_root_signature_first compiles; I did not run it (Windows only).
  • This head merged with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 at f007d4a (merge without conflicts): AR_x86_64_pc_windows_msvc=llvm-ar cargo check --release -p xcl --lib --tests --target x86_64-pc-windows-msvc exit 0 (the E0428 from the two mod tests is gone). Not run.
  • Kalmarv ran the previous head (b5c9057) on an RTX 5070 Ti; see the review. Those numbers are not for this head.

Not tested

AI use

  • Antigravity with Claude Opus 5.5: read the issues, the review, the code and the overlapping PRs, wrote the change, the tests and this description. I reviewed the diff.

@Kalmarv

Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Review of b5c9057 against main 9ab7d76. The limit does what the description says in a synthetic frame (numbers below). Five things I would change or settle before it goes in.

1. The 4 s default is not tied to a known threshold.

2. ExecuteIndirect past the limit goes to D3D12 without the title's root signature.

  • execute_indirect returns pc(…) as soon as the pipeline is not a translated one (bind.rs:220). graphics_bound binds rs_gfx first in the same situation (bind.rs:389), with the comment that a draw without a root signature is invalid and faults on WARP. set_graphics_root_signature only records it.
  • On main an indirect draw reaches that branch with a stand-in only when its build failed. With this PR every indirect draw past the limit does.
  • This is from reading. I did not run an indirect draw.
  • At 043d1f7 (2026-11-23): fixed. The branch binds rs_gfx before pc(…). The new execute_indirect_with_a_stand_in_binds_the_titles_root_signature_first passes on Windows, and fails with the binding taken out (only ExecuteIndirect is recorded).

3. Merged with #214 (f007d4a) the tests do not compile.

4. The limit is one budget per present interval for the whole process, not per draw or per thread.

  • A draw reads what is left before it waits and adds what it used afterwards. Draws on several threads that start before the first one returns each get the whole remainder, so a frame can be held for up to twice the limit (from the code, not run).
  • The budget refills only at PresentX. Everything drawn before the first present shares one 4 s. A thread that records while another thread keeps presenting gets a new 4 s after every present, so it can still be held for 4 s per unbuilt pipeline, back to back (also from the code).
  • A build shorter than the limit can still lose, because the second draw of a frame only gets what the first left. In the last row of the table the second pipeline needed 2 s and had 2 s left: it was built in time on the RTX 5070 Ti and drawn with its stand-in in the same run on WARP.
  • At 043d1f7 (2026-11-23): the shared budget is gone, so the three bullets above no longer apply: every draw call now waits up to the limit on its own. That makes the limit per draw call, not per pipeline or per frame. Draws on one unbuilt pipeline wait one after another until it is built, so a frame with a few draws per pipeline is held as long as on main. Same synthetic frame, two 10 s builds, on WARP: with 1 draw per pipeline the draws take 4.01 s and 4.01 s and the frame 8.03 s; with 4 draws per pipeline they take 4.00, 4.01, 1.99, 0.00 s for each pipeline and the frame 20.01 s, which is main's time in the table below. With XCL_PSO_WAIT_MS=1 the same 8 draws take 0.12 s in all. Remembering per pipeline that its wait was used up would keep the hold at one limit per pipeline.

5. A draw past the limit is lost, not delayed.

  • It is issued with the stand-in (title's root signature bound, counted as DRAWS_PC) and draws nothing. Nothing replays it when the pipeline arrives. Later draws use the real pipeline.
  • The description says this. Two things it does not say: report.json cannot tell these draws from draws with PC pipelines (only the log lines can), and a graphics build is no longer taken by the thread that needs it, so it waits its turn behind everything queued at SetPipelineState. With a deep queue, or D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214's two driver slots on NVIDIA, the budget buys less than 4 s of progress on the pipeline being drawn.
  • At 043d1f7 (2026-11-23): these draws are now counted on their own (report.json → d3d12.standin_draws) and the log line says the draw is lost. The remark about queue order is unchanged, and the description now states it.

Tested

Synthetic frame, the same test on both trees (bind::tests, local, not in the PR): two graphics pipelines whose builds take a fixed time (the job sleeps, then hands over a pipeline made beforehand) are first drawn in one frame through set_pipeline_state / draw_instanced on a title list of a real D3D12 device. Times are the two draw calls and the whole frame (record, execute, fence).

Tree Builds XCL_PSO_WAIT_MS Draw 1 Draw 2 Frame
main 9ab7d76 10 s – 10.00 s 10.00 s 20.01 s
b5c9057 10 s default 4.01 s 0.00 s 4.01 s
b5c9057 10 s 0 10.00 s 10.00 s 20.00 s
b5c9057 10 s 1000 1.01 s 0.00 s 1.01 s
b5c9057 2 s default 2.00 s 2.00 s 4.00 s

Not tested

  • The retail game, on any card. Whether a draw wait is what stalls its frames is still the PR's hypothesis.
  • The watchdog's threshold: I read the public threads only.
  • Translated pipelines: the test's real pipeline is a PC one, so the next frame gets it through SetPipelineState. The rebind in bind_abi after a stand-in draw in the same list is from reading.
  • ExecuteIndirect, mesh and two-pass pipelines, more than one drawing thread.
  • A real slow driver build (the delay is a sleep), a deep worker queue, and this PR together with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214's driver slots.
  • AMD and Intel.

🤖 Claude Fable 5.2

@vladbondarenko97

Copy link
Copy Markdown

Tested on an NVIDIA RTX 3080 Ti (Windows 11 10.0.26300, driver 32.0.16.2124, DXC 1.9.2602.17, package 1.0.2.1 verified by hash). Built this branch on top of 9ab7d76 (merge clean, -X theirs; both commits applied) and ran with XCL_NETWORK=0, XCL_ACTIVITY=1, lazy pipelines (default), frame dumps on.

Result: the run still dies at the early assert before any frame — this PR does not change it here.

  • report.json: presents: 0, frame_boundaries: 0, shaders.unique: 0, translated_pipelines: 0, failed_pipelines: 0, called_stubs: []
  • Crash: unhandled exception 0x80000003 in game_scarlett_master.exe+0x2237178, rax=0 rbx=0 rcx=0 rdx=0x66 r8=0x7efefefefefefeff r9=0x7f656f712d2f6073, vtable game+0x677c997; stack +0x677c997, +0x579105c, +0x700b71d, +0x53ec0f0, +0x4fac3d7
  • Same signature as plain 9ab7d76 and 60565c4 on this card, and the same first-chance exception under an unrelated clean-room layer (already reported in Retail GTA VI: early assert 0x80000003 at title+0x2237178 on an RTX 3080 Ti, 0 presents, reproducible on main 9ab7d76 #301). So on this host the failure predates any pipeline build this PR could wait on.

Two data points that may matter for the hypothesis:

Happy to run any revision of this PR on the 3080 Ti and return reports/traces. AI-assisted (Claude Code CLI via a model proxy).

Part of ivall#232. The null write at title+0x2215c35 is the retail game's
watchdog (`*(int *)0 = 0` after a stale watched timestamp, decoded in
ivall#232; one 23 s call set it off in ivall#156), not a bad pointer from the
layer: it fires when a watched thread of the title stops posting.

With lazy pipelines a graphics pipeline is sent to the workers at its
first SetPipelineState (`resolve_for_bind` -> `resolve`), and then
`bind::graphics_bound` / `execute_indirect` call `resolve_wait`: that
waits for the build without any limit, and runs it in the title's own
thread when no worker has taken it yet. An NVIDIA driver takes 10-17 s
for one big translated pixel shader (ivall#156 measurements), so a frame
that binds a few new ones holds the title's thread for that long.

Now each draw sends the build to the workers and waits at most 4 s
(`XCL_PSO_WAIT_MS`, 0 = no limit as before; per draw, so no draw gets
only what another left). Past it the draw goes with the stand-in and is
lost: counted in report.json (`d3d12.standin_draws`) and logged. An
indirect draw with a stand-in gets the title's graphics root signature
first, as direct draws do. Compute pipelines are still waited for. Any
pipeline wait of 2 s or more is logged with the thread. 4 s is a safety
margin, not a measured watchdog threshold.

Assisted-by: Antigravity (Claude Opus 5.5)
@heretic1321
heretic1321 force-pushed the fix/retail-null-write-232 branch from b5c9057 to 043d1f7 Compare November 23, 2026 23:13
@heretic1321 heretic1321 changed the title D3D12.X: draws wait at most 4 s a frame for pipelines still building (#232) D3D12.X: a draw waits at most 4 s for a pipeline still building (#232) Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants