D3D12.X: rectangle-list variants build off the game's threads #49
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ThatRecompDev--five-star-recomp!49
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/49/head"
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?
@Sr-0w on GitHub · 2026-11-25 17:51 UTC · original
Sr-0w:d3d12x/rectangle-variants-off-game-thread→main· +225 −26 · 8 files · 2 commits · merged 2026-11-25 22:11 UTCA 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-hangdumps at 5, 15 and 25 s (with the operation history of #47) showed:CreatePipelineState, insideamdxc64.dll, in all three dumps. Its stack went through a JIT-compiled loader frame.fivestar pipeline buildthreads 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.Variantno longer builds. The first call for a pipeline starts the build on a thread of its own and returnsPending. The build goes throughCompileBudget.Enter/Exit.Remembered again is released.RectangleDraws.BeforeDrawnow 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.Tests: the two rectangle-list tests now check that the first draw is skipped and draws nothing, and that after
WaitBuiltthe draw covers the whole rectangle. Loader tests and architecture rules pass. Docs are updated ind3d12x-shim.md(Rectangle lists).🤖 Generated with Claude Code
@ThatRecompDev on GitHub · 2026-11-25 19:08 UTC · original · edited 2026-11-25 19:09 UTC
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 on GitHub · 2026-11-25 21:19 UTC · original
Thanks, all four points are addressed (rebased on main):
RectangleDraws.Building, which only decides the skip and starts the build. The bind stays inBeforeDrawat its old place, afterCopyTwin.Finishcatches, reports once (rect-throw-<vertex>) and keeps 0, so the draw goes out as triangles. New testA_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.PipelineBuildQueue(the build queue is created beforeRectanglePipelinesand passed to it).Startchecks_variantsagain. 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.IsAlivestays true), so it's unrelated.@Sr-0w on GitHub · 2026-11-25 21:58 UTC · original
In game (recorded runs, RX 7800 XT)
CreatePipelineStateon the game's own thread, while the pipeline build threads were already full of 15–40 s tiled-lighting compiles.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 on GitHub · 2026-11-25 22:11 UTC · original
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