phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.09k stars 7.1k forks source link

3.60.0-beta.18 Phaser.GameObjects.Text batching broken #6367

Closed ndee85 closed 1 year ago

ndee85 commented 1 year ago

Version

Description

Batching for Phaser.GameObjects.Text seems to be broken in Beta 18. In 3.55.2 it is working fine, where texts are batched together and drawn in a single drawcall. Not so in Beta 18. Every new text objects creates a single drawcall. Found this with spector.js.

Example Test Code

    # adding/removing some text will increase/decrease the draw count. Every new text creates a new drawcall
    let text = new Phaser.GameObjects.Text(this.scene, 50, 50, "Hello World",{fontFamily:"Arial", fontSize:"30px"})
    this.scene.add.existing(text);
    let text2 = new Phaser.GameObjects.Text(this.scene, 50, 100, "Hello World",{fontFamily:"Arial", fontSize:"30px"})
    this.scene.add.existing(text2);
    let text3 = new Phaser.GameObjects.Text(this.scene, 50, 150, "Hello World",{fontFamily:"Arial", fontSize:"30px"})
    this.scene.add.existing(text3);

Additional Information

photonstorm commented 1 year ago

Working fine here: https://labs.phaser.io/view.html?src=src/bugs/6367%20text.js&v=dev

image

Text objects will only batch together up to the maximum texture count under the Multi Pipeline, as each of them uses a unique texture, just like in 3.55. Under the Mobile Pipeline they will be a drawcall each, as is everything else. They're never batched beyond the texture limit though (which is typically 16 texture units)

ndee85 commented 1 year ago

Hi, thanks for the quick response. I will try and isolate the problem on monday and see if the issue is occuring in combination with something else.

Will update the issue on monday.

ndee85 commented 1 year ago

Hi Rich, I just tried to see in which situations it works and it which not. It seems to work fine when running in Desktop mode. As soon as setting chrome dev tools to mobile and reload the page, it will break the batch. Here is what spector has to say: (Mobile) image image

(Desktop) image image

You said that there is a limit of 16 for some mobile devices. But we have only 3 elements. So I thing that this issue is caused by something else. I see a difference in the commands. PHASER_SINGLE_VS is called on mobile. On Desktop PHASER_MULTI_VS is called.

photonstorm commented 1 year ago

This is working correctly. On Mobile we use the new single batch renderer, which is massively faster than the multi pipeline one which is optimized for desktop GPUs. Mobile GPUs need handling very differently.

Yes, there are more draw calls, but they're all faster than the combined batch draw.

You can force mobile to use the multi pipeline if you like, but I'd strongly recommend against it unless you like tanking performance on iOS especially. See related threads about this

From the Change Log:

Mobile Pipeline

ndee85 commented 1 year ago

Thank you for your detailed clarification!