Skip to content

D3D12.X: rectangle-list variants build off the game's threads - #49

Merged
ThatRecompDev merged 2 commits into
ThatRecompDev:mainfrom
Sr-0w:d3d12x/rectangle-variants-off-game-thread
Nov 25, 2026
Merged

ThatRecompDev merged 2 commits into
ThatRecompDev:mainfrom
Sr-0w:d3d12x/rectangle-variants-off-game-thread

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A rectangle-list draw built its pipeline's variant on the drawing thread, outside the compile budget and outside the list of compiles in flight. The variant of a tiled-lighting pipeline (VS_TiledLighting linked to its TL_PS) is a full compile of its pixel program.

What a game run showed

In a run that reached the opening cutscene, the game's 30 s hang watchdog fired. The --watch-hang dumps at 5, 15 and 25 s (with the operation history of #47) showed:

  • The game's frame thread waited on its "last worker done" event.
  • Four of the five job workers had finished and gone back to waiting.
  • The fifth worker sat Running in CreatePipelineState, inside amdxc64.dll, in all three dumps. Its stack went through a JIT-compiled loader frame.
  • At the same time, eight fivestar pipeline build threads were in the driver. They matched the eight budgeted compiles in flight, all of them tiled-lighting pipelines taking 1 to 21 s each.

So the worker was a ninth, untracked driver compile on a game thread. Of the loader's direct pipeline creations, the only one that runs at draw time on the game's thread with no budget is the rectangle-list variant. That attribution is inferred, not read from a frame: the stack walk stops at the JIT frame.

Change

  • RectanglePipelines.Variant no longer builds. The first call for a pipeline starts the build on a thread of its own and returns Pending. The build goes through CompileBudget.Enter/Exit.
  • A build that finishes after its pipeline address was Remembered again is released.
  • RectangleDraws.BeforeDraw now returns true while the variant is pending. The draw shims (slots 12, 13) then skip the draw, the same policy as for a stand-in not built yet. They check this before the breadcrumb and timing work.
  • The rectangle-list count line now includes the draws skipped while a variant built.

Tests: the two rectangle-list tests now check that the first draw is skipped and draws nothing, and that after WaitBuilt the draw covers the whole rectangle. Loader tests and architecture rules pass. Docs are updated in d3d12x-shim.md (Rectangle lists).

🤖 Generated with Claude Code

@ThatRecompDev

ThatRecompDev commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

nice, getting that 25 s compile off the game thread makes a lot of sense, and skipping the draw while it's pending matches what we already do for pending pipelines.

two things before merging though:

moving BeforeDraw above CopyTwin breaks --depth-twins. CopyTwin resets VariantBound and rebinds the game's pipeline, so after a twin copy the draw goes out with the plain pipeline again (half rectangles). could you keep the "still building -> skip" check up front, but do the actual bind after CopyTwin like before?

Finish runs on a bare thread with no catch, so anything thrown in Build (a program load, the rect-gs compiler) would take the whole process down. it used to land in UnmanagedGuard. a catch that logs once and stores 0 would do it.

smaller stuff: a thread per pipeline is a lot, PipelineBuildQueue would fit nicer. and Variant can start a second build if Finish lands between the _variants and _building checks (re-check _variants in Start).

otherwise looks good

Sr-0w and others added 2 commits November 25, 2026 22:15
A rectangle-list draw built its pipeline's variant on the drawing
thread, outside the compile budget and the in-flight list. The variant
of a tiled-lighting pipeline is a full compile of its pixel program.
In a run that reached the opening cutscene, a game job thread sat in
CreatePipelineState inside the driver's compiler for over 25 s: a
ninth driver compile next to the eight budgeted builds in flight, all
of them tiled-lighting pipelines taking 1 to 21 s each. The frame
waited for that job, and the game's 30 s hang watchdog ended the run.

The first draw now starts the variant's build on a thread of its own,
within the compile budget, and is skipped; later draws bind the variant
once it is built. A build that finishes after its pipeline address
was remembered again is released. The rectangle-list count line adds
the draws skipped while a variant built.

Test: the first rectangle-list draw is skipped and draws nothing; once
the variant is built, the draw covers the whole rectangle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d after the depth-twin copy

Review of ThatRecompDev#49:
- A draw checks first whether its variant still builds (RectangleDraws.Building) and is skipped then; the variant
  is bound right before the draw as before, after CopyTwin, which binds the game's pipeline again (--depth-twins).
- Variants are urgent creations on the pipeline build queue, not a thread each.
- A build that throws is reported once and keeps 0 (drawn as triangles): it no longer ends the build thread.
- Start checks the variants again once its build is registered: a build that finished between Variant's two
  lookups no longer starts a second one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Sr-0w
Sr-0w force-pushed the d3d12x/rectangle-variants-off-game-thread branch from 30034b3 to a041f48 Compare November 25, 2026 21:19
@Sr-0w

Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all four points are addressed (rebased on main):

  • depth twins: the draw first checks RectangleDraws.Building, which only decides the skip and starts the build. The bind stays in BeforeDraw at its old place, after CopyTwin.
  • no catch: Finish catches, reports once (rect-throw-<vertex>) and keeps 0, so the draw goes out as triangles. New test A_variant_build_that_throws_draws_the_rectangle_as_triangles: the library throws on load, the build thread survives, and the second draw is drawn as triangles.
  • one thread per pipeline: variants are now urgent creations on the factory's PipelineBuildQueue (the build queue is created before RectanglePipelines and passed to it).
  • double build: after registering its build, Start checks _variants again. If a build finished in between, it drops its own and returns the built variant.

Loader tests: 367 passed, 1 failed. The failure is ProgramCodeTests.A_pipeline_stream_points_at_the_program_without_a_copy_and_keeps_it_alive, which fails the same way on main here (local Debug build, code.IsAlive stays true), so it's unrelated.

@Sr-0w

Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

In game (recorded runs, RX 7800 XT)

  • Before (main + the other open PRs, without this one): the run ended at about 375 s on the game's 30 s main-loop watchdog. The frame thread was waiting on its job workers. One of them was compiling a rectangle-list variant synchronously in CreatePipelineState on the game's own thread, while the pipeline build threads were already full of 15–40 s tiled-lighting compiles.
  • After: 600 s with no watchdog and 0 faults. The game gets past the loading screens into the opening in-engine cinematic:
    • loading screens at 30 fps up to about 230 s;
    • world rendering from about 250 s, first at 4–6 fps, then 9–14 fps;
    • the credits play over the rendered scene until the end of the run.

The fps that remain are bounded by the driver-compile backlog (about 2,100 pipelines queued) and by GPU time (50–85 ms per frame on the direct queue). Neither comes from this change.

@ThatRecompDev
ThatRecompDev merged commit bc83e03 into ThatRecompDev:main Nov 25, 2026
0 of 2 checks passed
ThatRecompDev added a commit that referenced this pull request Nov 25, 2026
@ThatRecompDev

Copy link
Copy Markdown
Owner

thanks, this is great. the pending check before CopyTwin with the bind after it, the catch in Finish, the shared PipelineBuildQueue and the re-check in Start are all exactly right, and the throwing-library test is a nice way to cover the catch.

merged (566a88d), with one blank line added for the statement grouping rule.

a few non-blocking notes for later: the heavy tiled-lighting variants go on the normal builds queue, so they skip the heavy-build memory check stand-ins get. RestoreCompute calls BeforeDraw without the Building check, which can fire the "no rectangle-list variant" warning while a build is running. and the ManualResetEventSlim per build is never disposed

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.

2 participants