Shaders: retain pipeline-library file buffers without copying #3158
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3158"
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?
Imported from ivall/xcl. Originally posted by storrmzz on 2026-11-28T13:59:19Z.
Loading a native pipeline library currently reads a
Vec<u8>and copies the entire payload intoArc<[u8]>. Retain the original allocation inArc<Vec<u8>>instead, reducing temporary CPU memory and copy work during preparation and warm startup. The library still owns the bytes for its full COM lifetime.What is in it
pipeline_libraryandwarm_library; keep the file format and driver validation unchanged.Tested
Rebase validation (2026-11-29)
00b4e95ec249fa4fc3253a28cd72bbf9dbcda316, rebased onto maind8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0. Same Windows PC/toolchain as below.cargo build --workspace --jobs 2: passed.cargo test -p xcl --lib shaders::pipeline_library::tests --jobs 2 -- --test-threads=1 --nocapture: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 2502 filtered out; finished in 4.54s Explicit SKIPPED: 0.cargo test -p xcl --lib shaders::warm_library::tests --jobs 2 -- --test-threads=1 --nocapture: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 2505 filtered out; finished in 0.29s Explicit SKIPPED: 0.git diff --check: passed. Full workspace suite, performance measurements and paired retail smoke were not rerun on this rebased head; earlier results below apply only to their named revisions.Earlier revision results (historical; not the rebased head)
43b32ac33dbbbafed74be95f244aef54b3eaaf2a:cargo build --workspace --jobs 2passed.cargo test --workspace --no-fail-fast --jobs 2 -- --test-threads=4 --nocapture: 2,132 passed, 9 failed, 48 ignored. Unchanged maine13d6250432d486502971781e9589a330e548d24, same commands: 2,131 passed, 9 failed, 48 ignored; the same nine tests failed. This is not a clean full-suite result.cargo bench -p xcl --bench '*' --jobs 2 -- --test: all four optimized benchmark targets completed their smoke cases successfully (not a timing comparison).cargo test -p xcl --lib shaders:: --jobs 2 -- --test-threads=1 --nocapture: 54 passed, 0 failed, 0 ignored, including two early-return skips (missing sample RPF / Developer Mode). The new allocation/lifetime test passed on the GPU; against the original implementation it failed atretain the original allocation(0 passed, 1 failed).XCL_SAMPLE_*inputs are unset; sample-dependent early returns are not coverage.std::fs::readplus shared-buffer construction, two runs of nine alternating pairs per size (rustc -O, median):This measures synthetic file loading and ownership transfer, not driver compilation, game loading, FPS, process commit or VRAM. Byte equality was checked outside the timer.
Failures reproduced on unchanged main
gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1gpu::dxil::module::split::tests::dispatch_chain_oversized_loop_matches_wholegpu::dxil::module::split::tests::dispatch_chain_wave32_live_loopsgpu::dxil::module::split::tests::dispatch_chain_wave64_live_loops_and_exchangegpu::dxil::msaa_tests::direct_msaa_loads_precede_get_dimensionsgpu::recomp::heap_window_tests::gpu_heap_flat_reads_match_guarded_and_root_outputgpu::recomp::tests::gpu_compute_mode_dispatch_abitest_title_runs_and_game_folder_is_untouchedtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsThe test-title failure reports a post-Wait32/64 write mismatch; the two-pass cache test reports retained two-pass state. The shader failures are also present without this change.
Standalone benchmark reproduction
Save as
library-buffer-probe.rs, compile withrustc -O --edition=2021 library-buffer-probe.rs, then run twice. Peak values count incremental live Rust allocator requests, excluding the existing comparison fixture. The buffers are synthetic, not serialized driver libraries; driver parsing is covered by the GPU tests rather than this benchmark.Regression run
Not run: no retail title is available on this machine. Draft pending paired
scripts/smoke.ps1runs on main and this exact PR head.Not tested
AI use
This PR was created with AI assistance from OpenAI Codex (GPT-6).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:38:42Z.
Triage (#1607) – head
00b4e95No open or merged PR makes this change, and main still stores the library as
Arc<[u8]>(pipeline_library.rsNativeLibrary::_serialized/open_shared, warm_library.rsReady).Vec<u8>intoArc<[u8]>does copy the whole buffer, so keepingArc<Vec<u8>>does save that copy.No problems found in the diff. The branch conflicts with main, where warm_library.rs has since been restructured (
validateno longer takes the device), so it needs a rebase. The README sentence describes an internal allocation detail, not something users can act on.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:02:10Z.
Review (head
00b4e95, diff read, not a merge-check; draft, conflicts with main,PR descriptionred: no smoke blocks):7599439b("validate prepared libraries on the runtime device") changedwarm_library.rs:validate(path, expected)no longer takes a device or opens the library,Readygaineddriverandmigration, andactivate()goes throughReady/open_shared. So thevalidatehunk (~69-75) no longer applies. Main still holds the bytes asArc<[u8]>(pipeline_library.rs~160-185,warm_library.rs~60, ~194, ~253), so the copy this removes is still there after a rebase.Vecis freed after the copy); what's saved is one memcpy and a short peak of one library's size at load. A library size and load time before and after would show whether it matters.CreatePipelineLibraryreads a dword past the blob (#2859). Dropping theArcheader moves where the data sits in its allocation, so which file lengths expose the overread changes.geometry_tests::msg_gs_done_emits_in_dxil,lower_mem::stage_guard_tests::geometry_export_rejected) failed on main3b6a91edtoo.Fine:
libraryis declared before_serialized(~162-163), so it drops first. The buffer is never mutated:NativeLibraryholds a clone, soget_mutcan't succeed. The new GPU test checks pointer identity and loads a pipeline after the other owners are gone.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.