perf(gpu,pipeline): speed up pipeline compilation, caching, and startup queuing #552
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/gamingwithhomie--larp!552
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-552"
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?
@professional-pussy-eater on GitHub · 2026-12-06 02:25 UTC · original
professional-pussy-eater:pipeline-compilation-improvements→main· +1762 −460 · 7 files · 2 commits · openOptimize cold and warm D3D12 pipeline compilation while keeping existing on-disk shader caches, scoped PSO blob caches, and pipeline catalog files byte-for-byte compatible.
Changes:
Root signature & geometry shader caching + zero-alloc warmup skip (
pipeline/host.rs):(ID3D12RootSignature, Arc<[u8]>)by exact root layout and device using a thread-local scratch key, avoiding repeatedD3D12SerializeVersionedRootSignatureandCreateRootSignaturecalls.GraphicsState::describe()in aOnceLock<String>and format directly into a pre-sized buffer.code_bytes()DXIL copies and" quad mask"allocations by hashing&[u8]slices directly into stack[u8; 32]hex names (blobs::name_hex_with_suffix).blobs::skip_if_warming_on_diskbefore constructingPlan,Vec<Stage>,D3D12_GRAPHICS_PIPELINE_STATE_DESC, or label strings.rect_list_gsDXIL by(vs_hash, ps_hash, quad)and gateHostPipeline.stateformatting behindfeature = "diagnostics".Sharded blob directory index & multi-threaded writers (
pipeline/blobs.rs):Shards) backed byread_dirscans to replace ~100k+ per-filemetadata()/ENOENTsyscalls, and track created shard subdirectories to avoid repeatedcreate_dir_all.[header, blob]in a singlewrite_allvia reusable scratch buffers, updating the shard index before removing entries frompending.flush_queuesoLARP_PRELOAD=1exits promptly once blobs flush.Parallel catalog loading & smart queue scheduling (
pipeline/make.rs,pipeline/created.rs):created-shaders.bincontainers in parallel, store each listed record's stream subobjects in one flat buffer instead of per-subobjectVec<u8>allocations, buildPendingentries in parallel waves, interleave graphics by primary shader hash, and batchSHARED/QUEUEinsertions.>= 96 KiB, largest-first) and total compute workers while graphics pipelines are queued so graphics stream in parallel without thrashing memory/L3/driver compiler, while keeping idle workers busy draining remaining compute once graphics finish.Shader::translating) and scan a bounded 32-entry window inQueue::popto avoid workerOnceLockconvoys.Single-pass GFX10 store analysis & cache helpers (
pipeline.rs,larp-pipeline/src/cache.rs):stores,stores_by_address, andstores_imagesinto a singlestore_flags()pass that decodes GFX10 bytecode once instead of 3x.larp_pipeline::Cacheand addCacheKey::from_slices,Cache::read, andCache::put.Testing:
GraphicsState::describe()equivalence/caching,name_with_suffixhash equivalence, sharded blob persistence/reopen, bounded heavy-compute scheduling, anti-convoy skipping, shader interleaving, andCacheKey::from_slices.cargo test -p larp-pipeline -p larp-gpu,cargo check -p larp-gpu --features diagnostics, andcargo build --release -p larp.Optimize cold and warm D3D12 pipeline compilation while keeping existing on-disk shader caches, scoped PSO blob caches, and pipeline catalog files byte-for-byte compatible. Changes: - Root signature & geometry shader caching + zero-alloc warmup skip (`pipeline/host.rs`): - Cache `(ID3D12RootSignature, Arc<[u8]>)` by exact root layout and device using a thread-local scratch key, avoiding repeated `D3D12SerializeVersionedRootSignature` and `CreateRootSignature` calls. - Cache `GraphicsState::describe()` in a `OnceLock<String>` and format directly into a pre-sized buffer. - Eliminate per-pipeline `code_bytes()` DXIL copies and `" quad mask"` allocations by hashing `&[u8]` slices directly into stack `[u8; 32]` hex names (`blobs::name_hex_with_suffix`). - Check `blobs::skip_if_warming_on_disk` before constructing `Plan`, `Vec<Stage>`, `D3D12_GRAPHICS_PIPELINE_STATE_DESC`, or label strings. - Cache synthesized `rect_list_gs` DXIL by `(vs_hash, ps_hash, quad)` and gate `HostPipeline.state` formatting behind `feature = "diagnostics"`. - Sharded blob directory index & multi-threaded writers (`pipeline/blobs.rs`): - Add a lazy 256-bucket directory index (`Shards`) backed by `read_dir` scans to replace ~100k+ per-file `metadata()` / `ENOENT` syscalls, and track created shard subdirectories to avoid repeated `create_dir_all`. - Compute blob header BLAKE3 checksums on compiling worker threads while blobs are hot in CPU cache instead of serializing hashing on one writer. - Replace the single blob writer thread with a 2-4 thread writer pool writing `[header, blob]` in a single `write_all` via reusable scratch buffers, updating the shard index before removing entries from `pending`. - Add `flush_queue` so `LARP_PRELOAD=1` exits promptly once blobs flush. - Parallel catalog loading & smart queue scheduling (`pipeline/make.rs`, `pipeline/created.rs`): - Read catalog files concurrently, hash `created-shaders.bin` containers in parallel, store each listed record's stream subobjects in one flat buffer instead of per-subobject `Vec<u8>` allocations, build `Pending` entries in parallel waves, interleave graphics by primary shader hash, and batch `SHARED` / `QUEUE` insertions. - Cap concurrent heavy compute compiles (`>= 96 KiB`, largest-first) and total compute workers while graphics pipelines are queued so graphics stream in parallel without thrashing memory/L3/driver compiler, while keeping idle workers busy draining remaining compute once graphics finish. - Track active shader translation (`Shader::translating`) and scan a bounded 32-entry window in `Queue::pop` to avoid worker `OnceLock` convoys. - Single-pass GFX10 store analysis & cache helpers (`pipeline.rs`, `larp-pipeline/src/cache.rs`): - Merge `stores`, `stores_by_address`, and `stores_images` into a single `store_flags()` pass that decodes GFX10 bytecode once instead of 3x. - Cache shard directory creation in `larp_pipeline::Cache` and add `CacheKey::from_slices`, `Cache::read`, and `Cache::put`. Testing: - Added unit tests for `GraphicsState::describe()` equivalence/caching, `name_with_suffix` hash equivalence, sharded blob persistence/reopen, bounded heavy-compute scheduling, anti-convoy skipping, shader interleaving, and `CacheKey::from_slices`. - Verified `cargo test -p larp-pipeline -p larp-gpu`, `cargo check -p larp-gpu --features diagnostics`, and `cargo build --release -p larp`.@christopear on GitHub · 2026-12-06 02:48 UTC · original
Independent Proton result for the shard index
I timed just
Store::on_diskin the parent (459db13) and this change (3d7c1f4). The first lookup pass over a populated directory benefits substantially when most keys are queried. For a smaller subset, the first scan costs about as much as the direct lookups here.Median elapsed milliseconds across six fresh processes per version, alternating which version ran first in each pair. Every pass returned the expected hit count.
The first full pass ranged from 1,161–1,848 ms on the parent and 58–150 ms here. The first sparse ranges overlap (71–138 and 50–95 ms). I wouldn't infer a sparse regression from that difference. Each workload starts with a fresh Store. The repeat reuses its index.
Windows MSVC release test under Proton Experimental, one caller, synthetic framed entries on memory-backed storage. Files were freshly written before timing, so filesystem caches were warm. This isolates lookup and index construction. It excludes queue scheduling, reading blob payloads, driver creation and gameplay. A useful next measurement would be worker wall time when multiple workers first touch the same shards.
Separately, on a clean build of the PR head under Proton, 37 larp-gpu library tests and one larp-pipeline library test passed, plus five opt-in D3D12 tests. I skipped the native Windows identity test and the populated-cache timing test.
Reproduction for either revision
Append this test to
crates/larp-gpu/src/pipeline/blobs/tests.rsand run the release larp-gpu library test filtered tocompare_shard_lookupwith--nocapture. The printed times are microseconds.@professional-pussy-eater on GitHub · 2026-12-06 02:59 UTC · original
Thanks for the independent Proton benchmark and D3D12 test verification!
Prompted by your note on multi-worker contention, I also removed a global mutex bottleneck on warm lookups in
blobs.rs:Store::on_disk()andread()now check anAcquire/ReleaseAtomicUsizelength mirror before acquiringpending'sMutex(skipping the lock completely when nothing is pending persistence).Here are the native Windows MSVC release measurements comparing parent (
459db13) vs this PR across single-caller and multi-worker workloads (including worst-case lockstep same-shard collisions where all workers hit00..ffin lockstep behind aBarrier):Median wall-clock milliseconds across 6 fresh processes per version (alternating parent/PR order), 8,192 synthetic framed entries per process, every pass verified against expected hit counts:
Key takeaways:
26.58 msacross the 256 independentOnceLockshards).Reproduction for either revision
Append to
crates/larp-gpu/src/pipeline/blobs/tests.rsand run in release withcompare_shard_lookup_mt --ignored --nocapture: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.