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

Open
opened 2026-11-26 20:18:17 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/511
Author: @VibeClauding
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: cont-lazy-pso


📝 Commits (1)

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

📊 Changes

4 files changed (+182 additions, -37 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+8 -0)
📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+151 -33)
📝 runtime/src/vulkan_replay.h (+14 -4)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/511 **Author:** [@VibeClauding](https://github.com/VibeClauding) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `cont-lazy-pso` --- ### 📝 Commits (1) - [`88658f1`](https://github.com/ubiquitarianism/leonida/commit/88658f1b3fcdca2231358c18d09253a213dc8533) d3d12: LEONIDA_LAZY_PSO=1 builds pipelines at their first draw or dispatch and keeps no unedited shader modules (RT-LAZY-PSO) ### 📊 Changes **4 files changed** (+182 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+8 -0) 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+151 -33) 📝 `runtime/src/vulkan_replay.h` (+14 -4) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#559
No description provided.