Skip to content

d3d12x: persistent on-disk pipeline library caching and coalesced descriptor heap staging - #1006

Open
UnkwnDev wants to merge 3 commits into
xcl-dev:mainfrom
UnkwnDev:arc-pso-library
Open

UnkwnDev wants to merge 3 commits into
xcl-dev:mainfrom
UnkwnDev:arc-pso-library

Conversation

@UnkwnDev

@UnkwnDev UnkwnDev commented Nov 24, 2026 •

Copy link
Copy Markdown

This pull request implements persistent on-disk pipeline state library caching (ID3D12PipelineLibrary1) and coalesced descriptor heap staging in D3D12.X:

  1. Persistent on-disk pipeline library caching:
    In crates/xcl/src/hle/d3d12x/pipeline_library.rs, introduces an ID3D12PipelineLibrary1 caching layer to persist driver-compiled hardware PSOs under %LOCALAPPDATA%\xcl\pso\host-pipelines.bin.
    In translated_graphics_pso and translated_compute_pso (crates/xcl/src/hle/d3d12x/real.rs), compiled pipelines are looked up by a 128-bit hash across deterministic root signature content (note_root_signature), translated shader bytecodes, samplers, and fixed-size pipeline state fields including InputLayout and NodeMask. D3D12_BLEND_DESC, D3D12_DEPTH_STENCIL_DESC, and D3D12_RASTERIZER_DESC are hashed explicitly field-by-field to ignore alignment padding.
    save(now) checks pending store counts and SAVE_INTERVAL_MS before taking SAVE_IO, and present.rs calls save_async() so periodic frame-present saves dispatch a bounded background save thread rather than serializing and writing on the present thread. Forced shutdown/close paths continue using synchronous save(true). Telemetry summary logging at exit (log_summary()) reports graphics/compute load and store counts. Empty pipeline library creation passes a null slice pointer for clean fallback under vkd3d-proton / Wine.

  2. Coalesced descriptor heap staging:
    In crates/xcl/src/hle/d3d12x/console_heap.rs, copy_range batches multi-slot descriptor copies by calculating destination addresses and indices directly, splitting at 256-slot PAGE_SLOTS boundaries and clamping to remaining heap capacity on both source and destination heaps.

Rebased onto origin/main (568e7db), integrating pipeline_library load/store with create_graphics_pso_cached in real.rs, currently at commit 8d0d2a1.

Tested

  • Hardware: Intel Arc A770 16GB (Driver 32.0.101.9175), Windows 11 Pro 64-bit, MSVC 14.44.35207
  • Verified at head 8d0d2a1:
    • cargo test -p xcl --lib pipeline_library -- --test-threads=1: 8 passed, 0 failed
    • cargo test -p xcl --lib hle::d3d12x::real -- --test-threads=1: 46 passed, 0 failed
    • cargo check -p xcl --tests: passed
    • (cargo test -p xcl --lib console_heap -- --test-threads=1: 7 passed at 2727c0d; console_heap.rs unchanged in 8d0d2a1)

Regression run
Prior revision 19381fbd reported by @Toons29 on AMD Radeon RX 9070 (smoke rerun needed on head 8d0d2a1):

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 19381fbd91c689b948774a5f6c15b8a233998047
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

Not tested

  • scripts/smoke.ps1 at head 8d0d2a1 (no retail title on author machine)
  • Windows 10 versions older than build 19041

AI use

  • Antigravity (Gemini 4 Hydrogen) and Claude Code assisted with pipeline state hashing, lock ordering, descriptor heap range copying, and test verification.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 run: the new pipeline-library corruption test fails deterministically under Wine.

Merged state: head onto main, clean merge, full suite 729 passed / 12 failed / 41 ignored; 11 known Wine-lane failures + mirror flake (#42 / #718) and one extra:

  • hle::d3d12x::pipeline_library::tests::corrupted_blob_falls_back_to_empty_library - fails 2/2 in isolation, panic at crates/xcl/src/hle/d3d12x/pipeline_library.rs:309: library created after rejection.

Reading: the test corrupts the on-disk blob, expects the loader to reject it and start empty; on this rig the loader path apparently produces/accepts a library after rejection. Could be Wine path/fs behavior (file still seen as valid at open time, or the reject path keyed on something environment-dependent), or a real ordering hole in the reject-and-recreate path. Deterministic here, so easy to reproduce on a Wine lane if you want a second datapoint.

The rest of the new pipeline_library tests pass on this rig, including the persistence round-trips.

Counts only, no game data.

Not tested: retail titles (none here), Windows, RDNA4.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@UnkwnDev

Copy link
Copy Markdown
Author

Thanks for catching this.

The root cause was Rust slice passing semantics interacting with vkd3d-proton. In open(), creating the fallback empty library called device.CreatePipelineLibrary(&[]). In windows-rs, an empty slice passes �s_ptr(), which evaluates to a non-null dangling pointer (

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib pipeline: 10 passed, 0 failed — includes the new pipeline_library tests (corrupted_blob_falls_back_to_empty_library verified: a bad on-disk blob logs the rejection and starts fresh).
  • Scope note: ~438 changed lines, slightly over the ~400-line guideline; the caching + heap-staging changes may want splitting, maintainer's call. A retail smoke run is probably still needed before merge per CONTRIBUTING (runtime change).

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@SlopTart

Copy link
Copy Markdown

Fix verification from the Wine/RDNA3 lane: re-merged the updated head dfcd403 onto current main and re-ran corrupted_blob_falls_back_to_empty_library, which failed 2/2 for me at the previous head (my comment above, panic library created after rejection at pipeline_library.rs:309).

It now passes in isolation on the merged lane (3c335f4, release profile). The empty-slice dangling-pointer explanation matches what I saw on the Wine side too: the rejection log fired but the "empty" library came back as a valid creation.

Fixed on this axis. Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@vladbondarenko97 vladbondarenko97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two problems I checked against the head (dfcd403) and main (930e8b4):

1. The pipeline library cannot hit in a later run. graphics_pso_name and compute_pso_name in pipeline_library.rs mix in rs_ptr, the raw COM pointer of desc.pRootSignature:

let rs_ptr = desc.pRootSignature.as_ref().map_or(0, |rs| windows::core::Interface::as_raw(rs) as usize as u64);
h1 = (h1 ^ rs_ptr).wrapping_mul(0x100_0000_01b3);

That address is different in every process, so a name stored by one run never matches in the next, and the persistent library always misses. Hashing the root signature's serialized blob (or the hash XCL already uses for the root signature, e.g. the [SHADER] rootsig <hash> value) would keep the names stable.

2. copy_range writes the wrong descriptor index when a copy crosses a 256-slot page. For view heaps, slot() (console_heap.rs:331–338 on main) gives each page its own place in the shared heap: index = first + 2 * (k - k0), with first per page from page_of. copy_range instead computes dst.index + k * 2 for every k, as if the shared heap were contiguous across pages. Once dst.k + k crosses into the next page, w[0] gets an index in the wrong place of the shared heap, and the shader reads another descriptor. There is also no check that dst.k + n stays inside the heap (h.n) before writing dst.at + k * step.

Calling slot() (or page_of) per destination slot when the range crosses a page, or splitting the copy at page boundaries, would fix both.

Review assisted by Claude Code (Claude Opus 5.5); I checked both points against the code above. Not run.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of dfcd403, 3 runs of 130 s in a row of a retail title: the library was saved and loaded again, but no pipeline was taken from it in either rerun, so the second and third runs were no faster than the first.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton 3.1 with the relaxed-vtable patch from #175 and a local dxil-spirv patch, VKD3D_CONFIG=ignore_shared_fence. RTX 4070 12 GB (driver 615.71.09, 32-lane waves), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), DXC 1.9.2609.5, XCL_NETWORK=0, XCL_PSO_PRELOAD=0. Retail title 1.0.2.1, the first-run screens completed once and no story progress, one A press at 44.8 s through XCL_PRESS_AT. dfcd403 merged onto main 67a3735 + #684 (e56dbc3) without conflicts. No host-pipelines.bin existed before run 1.

Tested

  • cargo test --release -p xcl --lib for pipeline_library and console_heap under Wine, on the merge: 7 passed, 0 failed.
run 1 (no library yet) run 2 run 3
loaded host pipeline library at start – 2,832 B 5,600 B
last saved pipeline library line 2,832 B, 0 graphics loaded, 0 compute loaded 5,600 B, 0 graphics loaded, 0 compute loaded 8,176 B, 0 graphics loaded, 0 compute loaded
loaded … PSO from pipeline library lines 0 0 0
compute PSO with the translated console CS lines 344 344 399
burst of pipeline creation ([SHADER] lines) 60 s to 70 s 60 s to 70 s 60 s to 70 s
last 2 s with a present 100.2 s 102.1 s 99.1 s

The stall after 100 s is the one of #662 in all three; in run 2 one compute pipeline of 1,108,268 B of DXIL was being built from 101 s to 128 s. The file grew by about the same amount each run.

Read

  • pipeline_library.rs:118 and :132: the name of a pipeline mixes in pRootSignature's raw interface pointer. That is an address of this run, not the root signature's content, so the next run only finds a pipeline if its root signature happens to land at the same address. I think this is why nothing was loaded and why the file grows each run instead of settling, but I could not read the names out of vkd3d-proton's blob to show it; LoadGraphicsPipeline failing for another reason under vkd3d-proton would look the same in these logs. The description says the hash covers root signatures; would hashing the root signature's bytes be what was meant?
  • pipeline_library.rs:102 (graphics_pso_name): of the pipeline's state the name takes the topology type, the number of render targets, the depth format, the sample count and the cull mode. Two pipelines of the same shaders that differ only in blend state, depth test or a render target's format get one name. What does LoadGraphicsPipeline do then on the drivers you tested: refuse the mismatching description, or hand back the stored pipeline?
  • console_heap.rs:417 (copy_range): the loop it replaces resolved every slot of the range with slot() and left out one that is in no heap; this one resolves the first and computes the rest. Can a title's count run past the end of its heap here? If it can, the copy now writes there.

Not tested: a native D3D12 driver, where the library stores real driver blobs (8 KB after three runs of about 500 translated pipelines each (report.json: 477, 476, 540) suggests vkd3d-proton stores next to nothing here); the preload of #690 on; the rest of the test suite; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the tree, ran the tests and the title three times with XCL_PRESS_AT, compared the logs and wrote this report.

@UnkwnDev

Copy link
Copy Markdown
Author

Thank you for the detailed profiling and analysis (@Royalflamejlh). All three points have been addressed in commit \2e6c458:

  1. Deterministic root signature hashing across process runs:

    • As you correctly identified, hashing the transient raw COM interface pointer address caused each fresh application launch to generate new PSO names under ASLR, preventing warm library lookups and causing the cache file to grow with duplicate driver entries on reruns.
    • We introduced
      ote_root_signature(raw: usize, hash: u64)\ and
      oot_signature_hash(rs). Root signatures now record their deterministic content hash (from their serialized bytecode for title-created signatures, and from static sampler keys and parameters for XCL ABI signatures). In subsequent runs, \pRootSignature\ resolves to its deterministic content hash regardless of host memory address.
  2. Differentiating full pipeline state:

    • Expanded \graphics_pso_name\ to hash all fixed-size POD pipeline state fields: \BlendState, \RasterizerState, \DepthStencilState, all active \RTVFormats, \DSVFormat, \SampleMask, \SampleDesc, and \Flags. Pipelines differing in blend mode, depth/stencil test, or target formats will not collide on the same cache name.
  3. **Heap bounds check in \copy_range**:

    • \Slot\ now tracks
      emaining\ capacity to the end of the heap (\h.n.saturating_sub(k)).
    • \copy_range\ and \copy_console_slots\ clamp
      = n.min(src.remaining).min(dst.remaining), preventing out-of-bounds copies if a title requests a range exceeding its allocated heap.

@Royalflamejlh

Royalflamejlh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@UnkwnDev 2e6c458 fixes the names: in two reruns on Linux (Wine + vkd3d-proton) + NVIDIA the library was loaded, its pipelines were taken from it and the file stopped growing. What it holds is only what the title made before its last save, though, and here that leaves out nearly all the compute pipelines of the world load (327 of 334 in run 1), which were built again in each rerun.

Setup: as in my comment above, except: 2e6c458 merged onto main b7aa9f3 + #684 (e56dbc3) without conflicts, runs of 125 s, and the A press came at 16 s instead of 44.8 s, so the times are not comparable with that comment's. No host-pipelines.bin existed before run 1.

Tested

  • cargo test --release -p xcl --lib for pipeline_library and console_heap under Wine, on the merge: 7 passed, 0 failed.
run 1 (no library yet) run 2 run 3
loaded host pipeline library at start – 7,184 B 7,184 B
saved pipeline library lines 4, the last at 86.3 s: 7,184 B none none
the first 5 translated pipelines built loaded from the library (4 graphics, 1 compute) loaded from the library (4 graphics, 1 compute)
compute pipelines built before 70 s 8 0 0
compute pipelines built from 70 s on 334 344 382
last 2 s with a present 87.4 s 88.4 s 76.1 s
the title's null write at game+0x23cf683 116.5 s 118.5 s 105.5 s

With dfcd403 the file grew from 2,832 to 8,176 B over three runs and nothing was loaded.

Run 3 followed a 3 minute offline shader pass on this machine that filled other caches, so its earlier end is not the library's doing. One more start between runs 2 and 3 ended at 32.9 s in the fault that #751 is about (msvcrt.dll+0xa52b under title_textures::subresources); it is not in the table.

Read

  • pipeline_library.rs:248 (save) runs from present.rs:755 at most every 20 s, and at a clean exit (present.rs:318, loader.rs:415). In run 1 the last save was at 86.3 s, 327 of the 334 world-load compute pipelines were made after it, the last present was at 87.4 s and the run ended in the title's watchdog. So those pipelines never reached the file, and run 2 built 344 again. Would a save that does not depend on a present (after a number of stores, or from the worker that stored) be in scope here?
  • pipeline_library.rs:264: a save with nothing added returns before the log line, so a rerun that loads everything prints no count of what it loaded. I counted loads from the builds that were missing. One line at exit with the two counters would let a tester see the hit rate.
  • pipeline_library.rs:117: a root signature that was never noted hashes to 0. The four note_root_signature calls are in real.rs (:3402, :3423, :4990, :5002 on the merge). No pipeline reaches a name that way on this tree: the three callers of the two name functions (real.rs:3587, :3986, :4004) take the root signature from abi_rs_for (:3580, :3962), which notes it on both of its paths (:3402, :3423).
  • pipeline_library.rs:140 and :150 hash the raw bytes of D3D12_BLEND_DESC and D3D12_DEPTH_STENCIL_DESC, padding included (3 bytes after each RenderTargetWriteMask, 2 after StencilWriteMask). Here the names were stable (the file did not grow), so the padding was the same from run to run on this path; I did not check that it must be.

Not tested: a native D3D12 driver, where the library stores real driver blobs (the 7,184 B file holds 36 pipelines, 21 graphics and 15 compute, at 112 B of blob each, so vkd3d-proton stores next to nothing here; compute builds took under 1 s in all in run 1, and about 34 s in run 2: two took 19.2 s and 14.4 s (902 KB and 727 KB of DXIL) and finished at 107.2 s and 121.6 s, after the last present, and the other 342 took 0.5 s together); the heap clamp in copy_range in a title run (its test passes); AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the new commit, built the tree, ran the tests and the runs, compared the logs and wrote this reply.

Edited 2026-11-24: the Not tested line said the library held "about 140" pipelines (it holds 36) and gave run 1's compute build time without run 2's; the third Read point was a question, which the tree answers. Nothing else changed.

@UnkwnDev

Copy link
Copy Markdown
Author

@Royalflamejlh Thanks for the detailed profile and trace analysis. We have updated the branch with commit 8dbf4cb addressing all three points:

  1. Batch store save trigger:
    store_graphics and store_compute now trigger save(false) whenever a batch of 16 new pipelines accumulates (BATCH_SAVE_THRESHOLD = 16). In save(), batch_ready bypasses the 20s interval throttle so world-loading compute pipelines compiled in the background without active frame presentation are flushed directly to disk. In addition, report::write_final() now flushes the library on termination to ensure trailing pipelines are persisted.

  2. Structure padding sanitization:
    Rather than hashing raw byte slices of descriptor structs, hash_blend_desc, hash_depth_stencil_desc, and hash_rasterizer_desc explicitly hash individual fields. This prevents undefined padding bytes (such as the 3 alignment bytes following each RenderTargetWriteMask and 2 bytes following StencilWriteMask) from affecting name hashes across compilers and platforms. Verified via unit test padding_bytes_do_not_affect_pipeline_hash.

  3. Telemetry summary logging:
    Added log_summary() which outputs D3D12.X: pipeline library summary: {gl} graphics loaded, {cl} compute loaded, {gs} graphics stored, {cs} compute stored. This runs on save(true) during clean exit, window close, and report::write_final(), making cache hit rates visible on runs where zero new pipelines were stored.

@UnkwnDev

Copy link
Copy Markdown
Author

Thanks for the thorough review and catch.

  1. Root signature hashing:
    graphics_pso_name and compute_pso_name now incorporate deterministic root signature content hashes (note_root_signature) rather than ephemeral COM pointer addresses. The content hash is recorded at root signature creation and remains stable across process lifetimes and ASLR.

  2. copy_range page boundary handling:
    In crates/xcl/src/hle/d3d12x/console_heap.rs, copy_range now splits multi-slot copies across PAGE_SLOTS (256-slot) boundaries, querying slot() for each run so destination descriptors are renumbered using each page's distinct GLOBAL shared heap allocation. Range copying is clamped to remaining heap capacity for both source and destination heaps. Added a test in console_heap.rs verifying that descriptors copied across the page boundary receive the correct page-1 indices.

Tested clean at head a771990 (cargo test -p xcl pipeline_library: 6/6 passed; cargo test -p xcl console_heap: 4/4 passed).

@UnkwnDev

Copy link
Copy Markdown
Author

Updated branch at 19381fb following a self-review pass:

  1. InputLayout and NodeMask hashing: graphics_pso_name in crates/xcl/src/hle/d3d12x/pipeline_library.rs now hashes all D3D12_INPUT_ELEMENT_DESC fields (SemanticName, SemanticIndex, Format, InputSlot, AlignedByteOffset, InputSlotClass, InstanceDataStepRate) plus NodeMask so graphics pipelines differing only in vertex input layout do not collide. Also forwarded non-console GS bytecode to graphics_pso_name in crates/xcl/src/hle/d3d12x/real.rs.
  2. Save I/O serialization: save() now acquires SAVE_IO across library serialization and write_atomically() so concurrent batch-threshold saves and present/shutdown saves cannot race on remove_file/rename or overwrite newer snapshots with older ones.
  3. Trace parity: load_graphics cache hits now also record PSO_SHADERS under XCL_TRACE_FRAME.

Verified at 19381fb: cargo test -p xcl --lib pipeline_library (7/7 passed), console_heap (4/4 passed), real (28/28 passed). Note: scripts/smoke.ps1 still needs to be re-run against 19381fb to update the regression block.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

@UnkwnDev 19381fb does it: on Linux (Wine + vkd3d-proton) + NVIDIA the world load's compute pipelines now reach the file and the next run loads them. Three runs in a row from no library, by the new summary line: run 2 loaded 103 graphics and 224 compute pipelines, run 3 loaded 118 and 293, and 5 compute pipelines were still built.

Setup: as in my first comment, except: 19381fb merged onto main c160d86 + #684 (e56dbc3) without conflicts, runs of 125 s, the A press at 16.2 to 18.5 s, all three after the 3 minute offline shader pass my last reply mentions. No host-pipelines.bin existed before run 1.

Tested

  • cargo test --release -p xcl --lib for pipeline_library and console_heap under Wine, on the merge: 11 passed, 0 failed.
run 1 (no library yet) run 2 run 3
loaded host pipeline library at start – 72,128 B 93,320 B
saved pipeline library lines (after the last present) 26 (5) 8 (2) 1 (1)
the file after the run 72,128 B 93,320 B 95,096 B
summary: graphics / compute loaded 0 / 1 103 / 224 118 / 293
summary: graphics / compute stored 106 / 258 28 / 79 5 / 4
compute pipelines built by the driver 261 80 5
last 2 s with a present 84.1 s 78.1 s 84.6 s
the title's null write at game+0x23cf683 113.6 s 106.6 s 114.0 s

The summary line came at the end of each run, which here is the title's watchdog, so report::write_final is reached on that way out too.

The runs did not get shorter as more was loaded: run 2 ended 7.0 s sooner than run 1, run 3 0.4 s later. My guess at why: the file holds about 200 B for each pipeline under vkd3d-proton, too little to be the driver's compiled code, so a load would still leave the driver its work; I did not time a load. What ends these runs is the stall of #662; the 5 compute pipelines run 3 still had to build took 34.1 s between them, and one that is still building when the watchdog fires cannot be stored.

Read

  • pipeline_library.rs:370: save takes SAVE_IO before the check for nothing added at :374, and present.rs:755 calls it on every present. So while a batch save from a build thread serializes and writes, each present waits for that write. With a 95 KB file I would not expect it to show here; I did not time it. Would it on a native driver, where the file is large? The two cheap checks could come before the lock.
  • pipeline_library.rs:289, :330 and :377: every 16 stores the whole library is serialized and written again, on the thread that built the sixteenth. Here that was 21 of run 1's 26 writes, of at most 70.5 KB. Has it been timed where a pipeline's blob is megabytes?

Not tested: a native D3D12 driver; the copy_range change in a title run (its tests pass); the preload of #690 on; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the new commits, built the tree, ran the tests and the three runs, compared the logs and wrote this reply.

Posted without review by a person: the account owner was away and reads replies later.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 19381fbd on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 19381fbd91c689b948774a5f6c15b8a233998047
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@UnkwnDev

Copy link
Copy Markdown
Author

@Royalflamejlh @Toons29 Applied the lock-ordering refinement from review and rebased onto origin/main (568e7db) at commit 2727c0d (merging create_graphics_pso_cached with pipeline_library load/store in real.rs):

  • pipeline_library::save(now) now performs the cheap pending-count / SAVE_INTERVAL_MS checks before touching SAVE_IO, and non-forced present-frame saves (!now) use SAVE_IO.try_lock() so frame presentation never stalls behind a background batch write.
  • Re-verified at 2727c0d: pipeline_library (7 passed), console_heap (7 passed), hle::d3d12x::real (46 passed), cargo check -p xcl --tests clean.

A fresh scripts/smoke.ps1 run will be needed on 2727c0d since the branch was updated and rebased after 19381fbd.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

@UnkwnDev 2727c0d does what you say for the point I raised: save(false) now returns before SAVE_IO when nothing is pending, or when fewer than 16 are and the last save was under 20 s ago, and otherwise only tries the lock (pipeline_library.rs:364 to :380), so a present no longer waits for another thread's write. It still writes the file itself when it gets to a due save first (the run's first, 16 pending, or 20 s since the last): the present thread made 17 of the 96 saves in these runs, each the run's first or 20 to 25 s after the one before. On Linux (Wine + vkd3d-proton) + NVIDIA the library still saves and loads across runs.

Setup: as in my earlier comments, except: 2727c0d merged onto main 568e7db + #684 (e56dbc3), 100 s runs, A pressed at 16.2 to 18.5 s. No host-pipelines.bin before runs 1, 4 and 5.

Tested

run 1 (no library) run 2 run 3 run 4 (no library) run 5 (no library)
library at start – 3,624 B 69,752 B – –
summary: graphics / compute loaded (no summary, below) 10 / 9 86 / 226 0 / 3 0 / 1
compute pipelines built by the driver 8 250 66 333 283
last 2 s with a present 81.5 s 86.4 s 82.9 s 76.4 s 80.1 s
  • Runs 4 and 5 started with no file, so their 3 and 1 compute loads were of pipelines stored earlier in the same run.
  • Run 1 ended at 82.5 s with process ends with status 0x3 from inside d3d12core.dll (vkd3d-proton), before the summary line, on the thread that had built all 8 of its compute pipelines (the last at 55.6 s), not the present thread. That was 1 s after its last present; the other four began the world load's burst of compute builds near their last presents, at 76 to 84 s, and run 1 had built none of it: its 8 builds match the 10 and 9 that runs 4 and 5 made before their bursts. Wine's error channel was off in run 1 and its console shows no message before the end; runs 4 and 5 repeated its start from no library with it on and did not end that way. Four other runs here have ended with status 3 since 23 Nov, all on another card, a tree without this pull request and winevulkan.dll at the top of the stack. One run in five is too few to say whether it is the change.

Not tested: the unit tests at 2727c0d; whether a loaded pipeline saves the driver's time here; Windows; AMD and Intel.

AI use: Claude Code (Claude Opus 5.5) read the change, ran the title and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@UnkwnDev

Copy link
Copy Markdown
Author

@Royalflamejlh Good observation on the present thread still performing due saves when it reached the 20 s / 16-pending threshold first (17 of 96 saves). Pushed commit 8d0d2a1 so present.rs now calls pipeline_library::save_async(), which runs the atomic save_due pre-check and dispatches a single-flight xcl-pso-save background thread when due. Frame presentation now performs zero serialization or file I/O, while shutdown paths keep synchronous save(true). Re-verified pipeline_library (8/8), hle::d3d12x::real (46/46), and cargo check -p xcl --tests.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

@UnkwnDev 8d0d2a1 does it: on Linux (Wine + vkd3d-proton) + NVIDIA the present thread made 0 of the library's saves in 2 runs (31 and 3 saves), and the next run still loaded what the first saved.

Setup: as in my earlier comments, except: 8d0d2a1 merged onto main 568e7db + #684, 100 s runs, XCL_PSO_PRELOAD=0, WINEDEBUG=err+all,fixme-all, A pressed at 16.4 s in both runs. No host-pipelines.bin before run 1.

Tested

run 1 (no library) run 2
library at start – 88,960 B
saves on the present thread 0 0
saves on a thread that logs nothing else, a new one each time 5 2
saves on build threads 25 0
save at XCL_RUN_SECONDS (100.0 s) 1 1
summary: graphics / compute loaded 0 / 3 123 / 324
compute pipelines built by the driver 321 3
last 2 s with a present 74.6 s 82.7 s
  • Build threads still write the file themselves: store_pipeline calls save(false) once 16 are pending (pipeline_library.rs:324), which made 25 of run 1's 31 saves, between 72.9 and 73.6 s.
  • A run between these two is left out: it ran while another job was filling this machine's disk, its log has seven gaps of 4 to 14 s in the 2 s activity line, and the title took none of four A presses (no gamepad buttons line, 590 frames on the start screen). It loaded the same 88,960 B and stored nothing, so run 2 began with run 1's file.

Not tested: the suite at this head; a run that ends other than by XCL_RUN_SECONDS (a crash, the title's watchdog); Windows; AMD and Intel.

AI use: Claude Code (Claude Opus 5.5) read the change, ran the title and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@UnkwnDev

Copy link
Copy Markdown
Author

Rebased onto origin/main (0829441) and pushed commit 7866911 addressing the remaining review points:

  1. Non-blocking threshold saves (@Royalflamejlh):

    • store_pipeline in crates/xcl/src/hle/d3d12x/pipeline_library.rs now triggers save_async() instead of synchronous save(false) at BATCH_SAVE_THRESHOLD (16), so build threads no longer serialize or write host-pipelines.bin inline.
    • save_async() coordinates a SAVE_REQUESTED flag with BG_SAVING so stores arriving while write_atomically is in flight are drained by the xcl-pso-save worker; synchronous save(true) remains only on shutdown/flush paths (WM_CLOSE, DLL_PROCESS_DETACH, report::write_final).
  2. Root signature hashing (@vladbondarenko97):

    • Verified graphics_pso_name and compute_pso_name use root_signature_hash / note_root_signature (no raw COM pointer addresses hashed). Also preserved the empty-fallback root signature hash in dev_create_root_signature, noted dispatch_chain::build root signatures, preserved dred::label on graphics library cache hits, and added unit test root_signature_hash_is_stable_across_com_pointers.
  3. Paged copy_range and bounds checks (@vladbondarenko97):

    • Updated copy_range in crates/xcl/src/hle/d3d12x/console_heap.rs to split across both PAGE_SLOTS (256-slot view pages) and SAMPLER_PAGE_SLOTS (8-slot sampler pages from origin/main), clamp n to src.remaining.min(dst.remaining), reject mismatched src.sampler != dst.sampler, and resolve unmapped sampler slots per-slot so exhausted shared sampler heaps keep reserved index 0.
    • Added unit test copy_range_crosses_noncontiguous_pages_and_clamps_oob verifying cross-page descriptor index mapping across non-contiguous view and sampler pages as well as OOB source/destination clamping.

Verified after the final edit on Windows (Intel Arc A770):

  • cargo test -p xcl --lib pipeline_library -- --test-threads=1: 9 passed, 0 failed
  • cargo test -p xcl --lib console_heap -- --test-threads=1: 10 passed, 0 failed
  • cargo test -p xcl --lib hle::d3d12x::real -- --test-threads=1: 57 passed, 0 failed
  • cargo clippy --workspace --all-targets --locked: zero errors or new warnings in our touched lines/files (full -- -D warnings fails on pre-existing origin/main lints such as clippy::approx_constant in lower_valu.rs, lower_wide.rs, and recomp/lower.rs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants