Skip to content

d3d12: LEONIDA_LAZY_PSO=1 builds pipelines at their first draw or dispatch and keeps no unedited shader modules (RT-LAZY-PSO) - #511

Open
VibeClauding wants to merge 1 commit into
ProjectLeonida:mainfrom
VibeClauding:cont-lazy-pso
Open

VibeClauding wants to merge 1 commit into
ProjectLeonida:mainfrom
VibeClauding:cont-lazy-pso

Conversation

@VibeClauding

Copy link
Copy Markdown
Contributor

Claimed in #14 as RT-LAZY-PSO.

What and why

Opt-in LEONIDA_LAZY_PSO=1 (off by default, nothing changes without it):

  • Graphics PSOs check the description, pick and read the translated shaders and make the layout as before, but the driver pipeline is built by the first draw that uses it, as variant(0). prepare_draw takes the base pipeline from variant(0) when pipeline is null.
  • Compute PSOs compile at their first dispatch through a new ComputePipeline::build (both dispatch sites in prepare). The subgroup-size request is still decided, recorded (pipeline_subgroup_requests) and reported at creation in both modes.
  • No kept shader modules for stages the runtime does not edit (no f16 link, no D24 depth patch): build() makes each from the library's words for the pipeline it creates and destroys it after (ModuleCleanup). Edited stages keep their module as today.

The retail title creates some 50,000 PSOs before its first frame and draws with far fewer. On a 16 GB RAM + 8 GB pagefile Windows machine (RTX 3070, driver 610.88), building them all eagerly ran the process out of commit between 50 and 300 s into the boot: the driver's copy of every module plus every pipeline. With deferred pipelines and no kept modules, private memory stayed at 11-17 GB and the title's own loading continued instead of stalling behind the compiles. Those measurements were on a forge-based branch with this change and others; this pull request is the change alone, onto main.

Trade-off: a pipeline the driver refuses fails its draw or dispatch (unresolved_resource, logged once) instead of CreatePipelineState, and the first draw with a new PSO pays its compile. That is why it is a switch.

Tests

  • New: d3d12_compute_lazy_pso, d3d12_draw_lazy_pso, d3d12_mesh_lazy_pso: the existing tests run with the switch on (CTest ENVIRONMENT).
  • Full ctest on Windows 11, MSVC, RTX 3070: default mode and with LEONIDA_LAZY_PSO=1 set for the whole run, 302/303 in both. The one failure, d3d12_execute_indirect_validation (5 count-buffer parity rows), fails the same way on unchanged main on this machine.
  • scripts/check_no_game_data.py on the changed files: clean.

Docs: a bullet in docs/d3d12_vulkan.md section 3.6.

AI-assisted (Claude Code); built and tested on the machine above.

…patch and keeps no unedited shader modules (RT-LAZY-PSO)

Graphics PSOs build their driver pipeline as variant(0) at the first draw; compute PSOs compile through
ComputePipeline::build at the first dispatch. A stage the runtime does not edit (no f16 link, no D24 depth patch)
keeps no VkShaderModule: build() makes one from the library's words per pipeline and destroys it after. The compute
subgroup request is still decided and recorded at creation in both modes. Off by default.

Tests: d3d12_compute_lazy_pso, d3d12_draw_lazy_pso, d3d12_mesh_lazy_pso (the existing tests with the switch on).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@towade

towade commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Measured on the retail boot with an AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32029.2010), Windows 11 26300, MSVC 19.44 (CMake + Ninja), i7-14700K, own 1.0.2.1 copy, --trace --trace-d3d12, the executable's network blocked in the firewall. Base: #321 at e0d4fd2b8 with this PR's commit 88658f1b3 cherry-picked on top (two conflicts: CMakeLists.txt kept both test blocks; in d3d12_vulkan_device.cpp I took this PR's compute creation and moved #321's startup pipeline-cache checkpoint into compile_compute). Work folder from main's shaders stage plus old #7529/#7746/#8858, with native_hashes.txt. Counts only.

On AMD's Windows driver the eager PSOs are what holds the boot back, so this switch matters there:

run (same build, same work folder) time D3D12 calls pipeline states PresentX end
switch off, warm driver cache (my run on #321) 300 s 72,665 51,256 526 still running, pipeline creation to the last log lines
LEONIDA_LAZY_PSO=1 14 s 78,064 50,481 12 GPU address arena full (raise LEONIDA_ARENA_MB), then CreateCommittedResource3 fails and the title asserts
LEONIDA_LAZY_PSO=1, LEONIDA_ARENA_MB=2048 18 s 82,984 54,596 18 GetResourceAllocationInfo format not supported yet: 118, then the title's int3

So the ~51,000 PSOs that took the whole 300 s now go by in about 14 s, and the boot reaches later stops: the 256 MB default arena first, then format 118 in GetResourceAllocationInfo (the same kind of stop as format 65 / A8_UNORM in Tyrannys' run on #321). CreateLifetimeTracker unsupported grows from 10,241 to 26,076, which is the title getting further, not new failures.

One thing to watch when this meets a rectangle-list path (not a defect of this PR on main, which has no such path yet): with the switch on, 242 CreatePipelineState calls fail with ... cannot be drawn as a rectangle list: the vertex shader is not a SPIR-V module; with it off, none fail. In create_graphics the lazy branch clears stage.words (// a lazy stage reads its words again at build time) before #321's rect_list block reads vs_stage.words for rect_list_geometry, so that block gets an empty vector. Whichever lands second (this or the rect-list support) should read the VS words before they are cleared, or reload them there.

Not run: this PR's three new *_lazy_pso CTests (not built here), Intel (the UHD 770 stops at slot 41 before any of this on #321), and a memory curve.

AI-assisted (Claude Code).

LloydNicholson added a commit to LloydNicholson/leonida-cont that referenced this pull request Nov 24, 2026
… lazy PSOs, console formats, XG, title memory)

Measured on the retail boot under Wine 11.22 (RX 9060 XT, RADV): it now creates 10,000+ slot 57 pipelines, runs
its loading frame loop at ~2.5-4 GB, and, with the hang check held off (LEONIDA_SLOW_STARTUP=1), starts real
rendering at ~120 s. Frames are still black, and that run stops at game+0x13360a3 (a game object with a garbage
vtable; not caused by anything below that was tested).

From open pull requests (applied as patches, conflicts resolved here):
- ProjectLeonida#511 (VibeClauding): LEONIDA_LAZY_PSO=1, pipelines built at first draw/dispatch. Local fix on top: the rect-list
  path's VS words were cleared before rect_list_geometry read them, refusing every rectangle-list PSO; the compute
  compile keeps this branch's host-stall scope.
- ProjectLeonida#496 (Rüzgar Koray Genç): console pipeline-stream numbering (24 = mesh shader).
- ProjectLeonida#461 (oscarlosu-lab): xg_xs texture layout and computer (ported from Marvisak/VIctory, GPL-3.0).
- Draft ProjectLeonida#321 (Mumogg, 237f9e0): vertex/index views in title CPU memory copied into a ring (title_memory).

Local fixes:
- Slot 57 pipeline blob elements: +0x00 is SemanticIndex, +0x08 InputSlot (swapped before; docs/fspx.md and the
  device_proxy test updated). ~4,900 "input layout does not feed COLOR1" refusals were this.
- FSPX graphics stages that read their code base use the kind-6 program as code (was empty -> E_OUTOFMEMORY).
- Console formats 118/119/120 (hypothesis: D16_UNORM_S8_UINT family) aliased to the D24S8 family at the device's
  entry points.
- Depth-stencil + UAV stand-in extended to slots 108, 127 and the slot-133 texture fallback; a UAV initial state on
  such a texture starts in COMMON. Slot 108 logs refusals (the title asserts its answer is below 4 GiB).
- 8-bit RGBA/BGRA render targets accept a UNORM/sRGB view without a castable list.
- Fence slot 12 mirrors refreshed by one poller thread (LEONIDA_FENCE_MIRROR=tp keeps the thread-pool waits, which
  queued on Wine's wait-queue lock); xs_proxy_mock tests run in tp mode.
- Slot-133 shadow buffers keep their VirtualQuery layout between refreshes (178 MB: 70 ms -> ~8.5 ms) and the
  refresh counts as a host stall.

Diagnostics and experiments (off unless noted):
- LEONIDA_DRAW_DIAG=1: per-present draw counts and per-draw pipeline/target/depth/viewport/vb0 for early frames.
- Slot 57 refusal layout dump and created/failed totals; refused RTV and committed-resource details; failed
  ExecuteCommandLists names its vulkan_replay.h line (on by default, test-branch lines).
- LEONIDA_SLOW_STARTUP=1: guest Sleep of 1-2.1 s lasts 2.1 s, so the startup hang check never counts (hides hangs).
- LEONIDA_XG_NO_COPY=1: texture computer slots 8/9 copy nothing.

Co-authored-by: VibeClauding <360230414+VibeClauding@users.noreply.github.com>
Co-authored-by: Rüzgar Koray Genç <koray_genc1@hotmail.com>
Co-authored-by: oscarlosu-lab <251827664+oscarlosu-lab@users.noreply.github.com>
Co-authored-by: Mumogg <104529023+Mumogg@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…es at their first draw or dispatch and keeps no unedited shader modules (RT-LAZY-PSO)
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nd multi-scissor rendering (1..16 viewports/scissors)

Resolved against ProjectLeonida#499's emit_graphics_pass, ProjectLeonida#469's depth bounds and ProjectLeonida#511's lazy modules: the viewport/scissor setup moves into emit_graphics_pass, the pipeline's dynamic-state list keeps DEPTH_BOUNDS and picks the *_WITH_COUNT states, and ProjectLeonida#499's ExecuteIndirect draws now carry the bound depth bounds and viewports like record_draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@akimfomin

Copy link
Copy Markdown
Contributor

I used PortBridge to independently replay towade’s rectangle-list finding and the order already used in LloydNicholson’s integration. At rectangle PR #207 head 21dc3889280d, the standalone rect_list_geometry helper produced 511 words from a 79-word synthetic vertex module. Releasing the words before the call reproduced the vertex shader is not a SPIR-V module. Calling the helper before releasing them produced the same 511 words byte for byte. The input and both generated modules passed spirv-val --target-env vulkan1.1.

The remaining integration check is d3d12_rect_list with LEONIDA_LAZY_PSO=0 and 1, including pixel readback. This replay covers the generator and word lifetime in isolation. AI-assisted with Codex.

@BadgersMC

Copy link
Copy Markdown
Contributor

Native Windows pixel-readback follow-up to the standalone reproduction. I merged #207 21dc3889 and #511 88658f1b onto main 21625bca locally. Both merges were clean.

State LEONIDA_LAZY_PSO=0 LEONIDA_LAZY_PSO=1
Combined PRs CreateGraphicsPipelineState fails with the vertex shader is not a SPIR-V module Same failure
With the vertex-word lifetime guard from LloydNicholson's integration Passes pixel readback Passes pixel readback

I applied only the guard that keeps vs_stage.words alive for rect_list_geometry. In both modes the fixture checked 4,096/4,096 pixels for the rectangle and each rotated right-angle case, 2,156 drawn pixels for the skewed triangle, and 4,096/4,096 exact pixels for the quad. d3d12_translated_draw and replay_quad_list also passed in both modes. No Vulkan validation errors in the two readback tests. The two hand-written test shaders passed spirv-val.

Windows 11 build 26100, RTX 3060 Ti driver 610.88, MSVC 19.44, LLVM 23.1.5, Khronos validation 1.4.369 with LEONIDA_VK_VALIDATION=1. AI-assisted synthetic tests, no game files.

@akimfomin

Copy link
Copy Markdown
Contributor

@towade Would you be willing to run the synthetic d3d12_rect_list check on your Windows/Vulkan setup once there is a combined revision for #511 and #207? Running it with LEONIDA_LAZY_PSO=0 and 1 on the same commit would show whether both paths return the expected pixels. PortBridge reproduced the word-lifetime failure you found and checked the corrected order in isolation. Shared test plan. Please note the exact combined commit and both outcomes if you have time.

@DesertGamer

DesertGamer commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Retail check of LEONIDA_LAZY_PSO=1 on a second NVIDIA machine (Windows 11, RTX 5070, driver 617.14, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy, 200 s limit). Base stack: main 21625bc + #641 + #427 + #727 + #602 + #387 + #357 + #432, which reaches the frame loop without lazy PSOs (400,154 PresentX ok).

stack PresentX ok D3D12 calls stops at
base + this PR, LEONIDA_LAZY_PSO=1 10,016 447,408 the title's int3 after GetResourceAllocationInfo format not supported yet: 118 (#588)
+ #588 6,186 310,020 GPU address arena full, then slot 133 fails
+ #588 + #772, LEONIDA_ARENA_MB=4095 6,417 323,948 no emulation exists for wave64 (4 ps, 3 vs)

So on this machine the lazy path does what the description says and moves the first stop from the title's start-up to the depth format, then the arena, then wave64 graphics shaders; no device loss in any of the three runs, and no exception other than the title's own int3. I did not look at #207 together with this PR (DadaCap's report about the rectangle-list path); #207 alone on the base stack, without lazy PSOs, reached the loop (473,041 PresentX ok).

AI-assisted: yes (Claude Code, Sonnet 5.5)

@towade

towade commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

checked: 88658f1b3 on current main (d0da7dade), Windows 11 26300, MSVC 19.44 (CMake + Ninja), on an AMD Radeon RX 9070 XT (RDNA4, 32.0.32029.2010) and an Intel UHD 770 (Xe-LP, 32.0.101.7092), picked with LEONIDA_VK_DEVICE.

RX 9070 XT UHD 770
d3d12_compute_lazy_pso, d3d12_draw_lazy_pso pass pass
d3d12_mesh_lazy_pso pass skipped (no VK_EXT_mesh_shader)
full ctest, LEONIDA_LAZY_PSO=1 303 of 308 298 of 308
full ctest, unset 303 of 308, the same 5 failures 298 of 308, the same 10 failures

The failures are the same tests with and without the variable, so the lazy path adds none. On Intel they are sparse/tiled resources, DXR and some formats; on AMD they are vk_queue_query_sync, d3d12_texture_tiles, d3d12_execute_indirect_validation, d3d12_clear and d3d12_pipeline_library_host.

Retail, with this PR on main plus the open boot pull requests (ladder on #14), the lazy path gets the RX 9070 XT past the start-up compiles to 84,585 calls and 55,257 pipeline states, with no device loss.

For the rectangle-list interaction, see my note on #682: the same stage.words = {} ordering applies there.

AI-assisted (Claude Code).

@Dezmonius

Copy link
Copy Markdown
Contributor

Independent eager/lazy A/B on Windows 10 22H2 (19045), RTX 5070 / NVIDIA 610.88, MSVC 19.51.36256, Vulkan with Khronos validation 1.4.369. Tested the same binaries in separate processes with LEONIDA_LAZY_PSO=0 and =1.

Synthetic results only. This run did not measure retail startup or memory consumption. No game files. AI-assisted (Codex).

@Snooozs

Snooozs commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent check. Windows 10 Pro 22H2 (19045), VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, merged onto main 82a2aab without conflicts, test targets rebuilt; RTX 5060 Ti (621.01) and a Ryzen 7 7700 iGPU (1002:164E, AMD 31.0.22044.1). On the iGPU the pipeline tests fail on plain main too (128 push-constant bytes), so they say nothing there.

RTX 5060 Ti, each without and with LEONIDA_LAZY_PSO=1: d3d12_compute_test, d3d12_draw_test and d3d12_mesh_test all exit 0 with 0 VUID lines, as on main.

Synthetic tests only, no game files. AI-assisted (Claude Code): I read the diff and ran the tests on that machine.

@akimfomin

Copy link
Copy Markdown
Contributor

PortBridge connected this PR to SceneGate VI's changing-color readback control. I applied that method to the offscreen Vulkan fixture at 88658f1b3fcdca2231358c18d09253a213dc8533.

On RTX 4070 Ti SUPER, Windows 11 build 28000, driver 617.14, both LEONIDA_LAZY_PSO=0 and =1 passed 3/3 runs. Every run checked 32 frames × 4,096 RGBA8 pixels. Omitting draw 8 returned 44 at frame 7, pixel (0,0), in 3/3 controls per mode. The fixture also passed both modes with the new check disabled. The local LLVM-MinGW build used an aggregate-return ABI adapter and an abort-on-use swapchain stub for the offscreen path.

The test-only patch and reproduction guide use the existing d3d12_draw_test target. An independent AMD run with the standard build would help confirm the result. Synthetic inputs. AI-assisted.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants