Skip to content

Commit c4c4766

Browse files
committed
fix: only drain WGSL shader include loaders for WGSL effects
LoadPendingIncludesAsync was called unconditionally in effect.ts for all effects. In the CDN bundle, all WGSL shader modules execute at load time and push their include loaders to _PendingIncludesLoaders. The first GLSL/WebGL effect created would then drain the entire WGSL loader queue before proceeding, stalling shader initialization until hundreds of dynamic imports resolved. This caused visual timing regressions in 24 WebGL2 visualization tests. Fix: gate the call on ShaderLanguage.WGSL so only WGSL effects process the include queue. GLSL effects still get LoadPendingIncludesAsync via their extraInitializationsAsync callback (in each material's shader loading code) for any WGSL includes that happen to be pending at that point.
1 parent 3385578 commit c4c4766

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/dev/core/src/Materials/effect.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,15 @@ export class Effect implements IDisposable {
427427
await extraInitializationsAsync();
428428
}
429429

430-
// Eagerly load all pending shader includes so that ProcessIncludes is synchronous.
431-
// The WGSL processor is a singleton that stores per-effect state; async include resolution
432-
// would allow another effect's Initialize() to overwrite that state mid-processing.
433-
await EngineShaderStore.LoadPendingIncludesAsync();
430+
// For WGSL effects, eagerly load all pending shader includes so that ProcessIncludes
431+
// is synchronous. The WGSL processor is a singleton that stores per-effect state;
432+
// async include resolution would allow another effect's Initialize() to overwrite
433+
// that state mid-processing. GLSL effects do not use _PendingIncludesLoaders and
434+
// must not drain the WGSL queue (which stalls the first GLSL effect until all WGSL
435+
// includes have resolved, causing visual timing regressions in tests).
436+
if (this._shaderLanguage === ShaderLanguage.WGSL) {
437+
await EngineShaderStore.LoadPendingIncludesAsync();
438+
}
434439

435440
this._processingContext = shaderProcessingContext || this._engine._getShaderProcessingContext(this._shaderLanguage, false);
436441

0 commit comments

Comments
 (0)