Repository navigation
perf: compile pipelines on first use and prewarm them in parallel - #177
Merged
proggeramlug merged 2 commits intoNov 6, 2026
Merged
proggeramlug merged 2 commits into
proggeramlug merged 2 commits into
Conversation
Renderer::new created every pipeline of every feature up front, one after another: 57 pipelines and 10.8 s on an M1 Max with a cold Metal shader cache (first launch after install or an OS/driver update), of which a game at the Medium preset used 16. Path tracing, hardware-RT probes, the GPU-driven renderer and the rest compiled whether or not they ever ran. - renderer/lazy_pipeline.rs: LazyRenderPipeline / LazyComputePipeline keep an owned copy of the descriptor (modules and layouts are refcounted handles) and compile on first Deref. Creation sites change one call; use sites deref-coerce. Correctness doesn't depend on any list: whatever a frame draws is built on first use. - Renderer::prewarm_pipelines: when the settings that select pipelines change (first frame, a quality preset, a feature toggled at runtime), the pipelines those settings use compile on background threads; a draw waits only for the one it needs. Conditions measured per preset with a pipeline-use trace. No-op on wasm (wgpu objects aren't Send there). - BLOOM_PIPELINE_LOG=1 prints each compile, its time and whether it ran on a prewarm thread or made a frame wait. Measured (M1 Max, MTL_SHADER_CACHE_SIZE=0 for cold): cold initWindow 11.4 s -> 0.5 s, then ~0.9 s in the first 3D frame warm initWindow 0.6-0.9 s -> 0.33 s tuichess 3D at Medium and High: every pipeline it draws is prewarmed, none compiles on the render thread BRDF LUT at build time: build.rs includes brdf_lut.rs and writes the 256x256 table to OUT_DIR once per build (1.7 s, only when the generator changes); the renderer embeds it. Computing it at startup took ~0.4 s on an M1 Max at every launch, more on phones and the single-threaded web build. A test checks the embedded table against the generator. Profiler: a label can cover several passes (the bloom mip chain), and on tile-based GPUs consecutive passes overlap (the next pass's vertex work starts while the previous pass's fragments run), so summing their intervals counted the same GPU time several times: bloom read 5.4 ms for 0.8 ms of work, 49 ms inside a 13 ms frame in a real scene. Per-label GPU time and the frame totals are now the union of the intervals; CPU frame totals too (phases nest: queue_submit runs inside render_total).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
proggeramlug
changed the base branch from
fix/apple-platforms-and-ffi
to
codex/rendering-wip-integrated-20260727
November 6, 2026 15:47
…0260727' into perf/lazy-pipelines-startup # Conflicts: # native/shared/src/renderer/mod.rs
proggeramlug
merged commit Nov 6, 2026
30b3426
into
codex/rendering-wip-integrated-20260727
1 check passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #176.
Problem
Renderer::newcreated every pipeline of every feature up front, one after another. That's 57 pipelines, and 10.8 s on an M1 Max with a cold Metal shader cache: a user's first launch after installing, or after an OS or driver update. A game at the Medium preset used 16 of them. Path tracing, hardware-RT probes, the GPU-driven renderer and the rest compiled whether they ever ran or not.Changes
renderer/lazy_pipeline.rs:LazyRenderPipelineandLazyComputePipelinekeep an owned copy of their descriptor (modules and layouts are refcounted handles) and compile on firstDeref. Each creation site changes one call, and use sites deref-coerce. Correctness doesn't depend on any list: whatever a frame draws is built on first use.Renderer::prewarm_pipelines: when the settings that select pipelines change (the first frame, a quality preset, a feature toggled at runtime), the pipelines those settings use compile on background threads. A draw waits only for the pipeline it needs. The conditions come from a pipeline-use trace taken per preset (Off, Low, Medium, High, Ultra). Prewarming does nothing on wasm, where wgpu objects aren'tSend.BLOOM_PIPELINE_LOG=1: prints each compile with its time, and whether it ran on a prewarm thread or made a frame wait.build.rsincludesbrdf_lut.rsand writes the 256x256 table toOUT_DIR(1.7 s, only when the generator changes). Computing it at startup cost about 0.4 s on an M1 Max at every launch, and more on phones and the single-threaded web build. A test checks the embedded table against the generator.Measured (M1 Max; cold =
MTL_SHADER_CACHE_SIZE=0)initWindowinitWindowTests
cargo test --release --libinnative/shared: 489 passed. New tests cover the lazy pipelines (build once, prewarm with a racing first use), the union timing and the embedded BRDF table.cargo check --target wasm32-unknown-unknowninnative/web.Not in this PR
#[cfg], which a build script evaluates for the host.