WebGPU + custom render loop not working

As I mentioned in my previous topic I am getting a white screen when I replace new Engine with new WebGPUEngine (and the async init).

I narrowed it down to this diff, where the only change from the playground code is replacing the engine.renderLoop with custom calls to render:

            scene.clearColor = BABYLON.Color4.FromHexString('#006600FF');
            window.renderLoop = function () {
                window.scene.render();
                requestAnimationFrame(window.renderLoop)
            }
            requestAnimationFrame(window.renderLoop)

I uploaded 2 edited playground files here, one for webgl and one with webgpu, both with the custom render loop:

webgl - works
https://jsfiddle.net/fnm1Lsxp/

webgpu - no renders
https://jsfiddle.net/18m7f56w/

You must register your render loop with the engine and not use requestAnimationFrame yourself:

https://jsfiddle.net/21ce8dkw/

I know that works, but the way I wrote it I have full control over my game loop and it needs to support Babylon WebGL as well.

In the docs you mention you want Babylon WebGPU to be backward compatible. Is there a reason direct calls to render() won’t work with WebGPU, or will this be supported in the future?

I think it deserves a mention in the Breaking Changes page at the least.

some context: the project is https://tuggowar.io.The goal is to enable WebGPU in the Electron build of the game.

Some housekeeping is not done when you don’t use runRenderLoop (engine.beginFrame / engine.endFrame are not called for eg). Also, the multi views (canvas) support won’t work, as well as VR as I can see there are some calls to VR functions in the engine._renderLoop wrapper.

So, not using runRenderLoop may work in your case but I’m not sure it is an officially supported way of doing things. @Deltakosh?

In any case, WebGPU needs at the minimum that beginFrame / endFrame be called: you can try to surround your scene.render() call by engine.beginFrame() and engine.endFrame() and see if that works.

For reference, here’s the render loop wrapper of Engine:

If you replicate the content of the runRenderLoop it should be fine (at the very least adding beingFrame and endFrame)

ok, I had no idea. I’ve been calling scene.render() for a long time now :slight_smile:.

I can understand having to call another function that does more than just call scene.render(), but it seems like it should be supported for the user of Babylon to decide the moment and frequency with which to render.

But that’s up to you, I’m sure I will find a way to do that.

As I said: it is ok as long as you call beginframe and endframe :slight_smile:

Yes, I got everything working now, thanks a lot!

WepGPU is very important for my project and I hope you appreciate an early adopter as well :kissing_heart:

1 Like

Of course we do :slight_smile: cc @Evgeni_Popov