DynamicTexture update() performance question

To avoid more than one DrawCall I think to make my own class that creates DynamicTexture of some size, let’s say 2048x2048 and stores all the game text labels there in its own texture region.

So when I need to change money coins text I clear the region, draw new text and update the texture.

How to mesure the performance of this action, is texture.update() too heavy operation? I think I should find some balance between such textures count (is more DC) and an update frequency?

The worst case: what if I would update my 2048-texture at speed: 1/10 fps to change a text? :grinning_face: That would be too much, right? But how do I know the balance between textures count and performance?

Hey there! the cost of the update is basically to copy from RAM to VRAM. It is not a heavy operation per se:
Babylon.js/packages/dev/core/src/Engines/Extensions/engine.dynamicTexture.ts at master · BabylonJS/Babylon.js

The main contender is texImage2D which is specifically meant for that copy work.

We consider that function fast enough to be used in the hot path.
That being said, if you want to measure it, you can probably just check the frame times from the inspector:

Ideally you want to keep the frame total and GPU frame as small as possible

4 Likes

@Lemcat, here is an example you can use to experiment with. This is a demo I made a while ago for product customization that uses dynamic textures and updates several draw operations while clearing, updating, and drawing to the canvas at 683 x 2048 pixels (I didn’t need a full square due to the mesh I am drawing on) at 60fps while editing the graphics.

The whole scene runs at about 0.45ms to draw the frame and when actively resizing a graphic causing all the layers to redraw, I am just under 1ms to render the frame… again at 60 draws per second. So if you are aiming at redrawing every 10 frames, I doubt you will see much cost in your frame time.

4 Likes