Dramatic increase in WebGPU startup time (whenReady)

Hi everyone,

Thought I’d share this to potentially save you some headaches. :face_with_head_bandage:

I have been migrating from WebGL to WebGPU and encountered a massive increase :collision: in my game startup time. From a default timing report I already got the culprit: scene.executeWhenReady

But why? I had just ported all shaders to wgsl and there should not have been any glsl-to-wgsl transpiling stuff going on (which is slow).

What nailed was this debug code :

export default function Override(BABYLON, win) {
  BABYLON.Scene.prototype.isReady = function(checkRenderTargets = true) { ... }
  BABYLON.Engine.prototype.areAllEffectsReady = function() { ... }
  
  //e.g.
  BABYLON.WebGPUEngine.prototype.areAllEffectsReady = function() {
    for (const key in this._compiledEffects) {
      const effect = this._compiledEffects[key];

      if (!effect.isReady()) {
        if(typeof effect.name === "string") report("effects:"+effect.name)
        else report("effects:"+effect.name.fragment+"/"+effect.name.vertex);
        return false;
      }
    }

    return true;   
  }
}

This way you know what is taking so long in executeWhenReady.You log a debug message (or whatever) whenever any of the function is about to return false / set return var to false. I do this per call, so that I will get a sorted history. And there I got the perpetrator: weaponSwingTrail nodeMaterial :open_mouth:

Since it is a node material it does not live in the shaders directory and so I missed to port it. The moment I set material.shaderLanguage = Engine.ShaderLanguage.WGSL, startup time was on par with WebGL.

Phew, I was about to rage quite a ditch WebGPU :grin:

Best wishes
Joe

**Don’t forget to turn off the debug code :face_with_crossed_out_eyes:

4 Likes

cc @Evgeni_Popov (please be patient he is on vacation:))

Uhm, wait. The post was meant to be a tip. Did not want to complain about Babylon or anything :face_with_peeking_eye: I guess the tl;dr is: look for leftover GLSL shaders if your WebGPU startup time is comparably higher.

Yay Evgeni :beach_with_umbrella: :tropical_drink: :smiley:

1 Like

Good catch. The slow startup was caused by one missed node material (weaponswingTrail) still using the wrong shader setup. Setting it to WGSL fixed the issue and restored normal performance.