perf: compile scene shaders off-thread before the first frame
I warm the world's programs with renderer.compileAsync() at the end of the async build, with the composer's scene target bound so tone mapping and output colour space key the same programs the composer draws with, and with hidden subtrees revealed so the light count matches the frame-0 warm render. The wait is capped at 2.5 s; the warm render stays as the safety net for the post passes, texture uploads and anything a slow or extension-less driver left. Test builds report renderer.info.programs, and a browser spec pins zero program growth after frame 0. On the Intel ARL laptop the frame-0 task drops from ~1.74 s to ~0.34 s with a pixel-identical first frame; measurements in docs/overnight/compile-async-results.md.
This commit is contained in:
@@ -15,6 +15,11 @@ export interface PostProcessor extends GpuRenderTargetReporter {
|
||||
setDynamics(acceleration: number, dawn?: number): void;
|
||||
setLens(state: LensState): void;
|
||||
render(scene: unknown, camera: unknown): void;
|
||||
/**
|
||||
* The off-screen target the scene pass draws into. Bind it while compiling
|
||||
* scene programs: three keys tone mapping and output colour space on it.
|
||||
*/
|
||||
sceneTarget(): unknown;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
@@ -28,6 +33,8 @@ interface RenderTargetLike {
|
||||
interface ComposerLike {
|
||||
renderTarget1?: RenderTargetLike;
|
||||
renderTarget2?: RenderTargetLike;
|
||||
/** RenderPass (needsSwap false) draws the scene into this target. */
|
||||
readBuffer?: unknown;
|
||||
addPass(pass: unknown): void;
|
||||
setPixelRatio(pixelRatio: number): void;
|
||||
setSize(width: number, height: number): void;
|
||||
@@ -146,6 +153,9 @@ export function createPostProcessor(
|
||||
renderPass.camera = camera;
|
||||
composer.render();
|
||||
},
|
||||
sceneTarget() {
|
||||
return composer.readBuffer ?? composer.renderTarget2 ?? null;
|
||||
},
|
||||
dispose() {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
|
||||
Reference in New Issue
Block a user