High GPU Memory consumption when scaling controls down

I’m trying to increase the resolution of some Billboard GUIs that I have placed on a 3D diagram I’m making.
In order to achieve this, I have tried boosting the ‘AdvancedDynamicTexture’ resolution by sizing up my rectangles and textBlocks within, then scaling down the adt. Doing this shows a significant amount(+4GB) of GPU memory consumption for having ~20 billboard GUI’s placed. The only difference there is whether I turn scaling on or off.

Not sure if I’m approaching this from an odd direction, but the scaling shouldn’t make my GPU memory consumption jump like that.

Using V5.0.0-Alpha-1.

Hello and welcome!
can you share a PG that repro what you are seeing?

https://playground.babylonjs.com/#XCPP9Y#4699

This is with just one GUI widget, but it does show a visible increase in GPU memory on my system.
~1GB GPU mem with this example.

I’m not seeing the same numbers:

And this seems fair.
My current texture size is 722x921x10*10 so ~66millions pixels

so size in memory: 66millions * 4 = 253 MB

1 Like

Watch the ‘GPU Process’
You can see it spike when you toggle scaling. with / without the scaling enabled changes the GPU memory usage by ~500MB in my example.

The thing is you have 253Mb for the texture + what the underlying canvas 2d needs so another 253Mb + extra copies when uploading to gl as the memory is not shared and probably some mip mapping adding another 30%. So a GPUMemory of about 500Mb + the equivalent internal one retained by Chrome.

I am actually trying to work with both the Edge and Chrome team to see if there would be a way to share the memory directly in case the canvas is only used by GL but it will take time.

1 Like

Just to clarify that I understand:

You’re saying that this is because when the texture is in memory and scaled, the system keeps multiple copies raw in the GPU memory in addition to the memory of the object in the JS Heap?

I figure that scaling would tell Babylon to raster the image at the scaled down resolution, then pass it over to the GL. That’s why I’m not quite following the high GL memory usage here.

Yes gui works with a 2d canvas to draw shape and texts, so scaling means scaling the source canvas and the corresponding webgl texture as this is not shared memory.

I figure that scaling would tell Babylon to raster the image at the scaled down resolution, then pass it over to the GL. That’s why I’m not quite following the high GL memory usage here.

I am not sure what you mean by scaled down here as you put a parameter to actually increase its size by ten times what it would normally be

Maybe I’m misunderstanding…

AdvancedDynamicTexture.scale(2) should halve the size of the texture, correct? This is what I’m experiencing in the provided example.

Actually scale 10 creates a texture 10 times bigger, to halve it you need scale 0.5

That’s what I would normally think – why is it shrinking the texture? Is it because it’s increasing the source resolution of the ADT and the ADT forces it to shrink to fit in the texture?

Yes let s add @Evgeni_Popov to the thread as he ll have a better feedback than me on the scaling part

scale is a method of DynamicTexture which is doing:

    public scale(ratio: number): void {
        var textureSize = this.getSize();

        textureSize.width *= ratio;
        textureSize.height *= ratio;

        this._recreate(textureSize);
    }

So it is increasing the texture size if you pass a parameter > 1.

Not sure I understand:

as the texture is enlarged.

1 Like

What I am experiencing is that if I pass ‘2’ into scale, it actually shrinks the size of the GUI component.
Is this because scale actually doubles the resolution, and the GUI shrinks it to fit within the bounds of the GUI?

It shrinks because the texture is doubled but your mesh/gui object is still the same size on screen (I assume). If you generate some texts in your texture, you should generate it with twice the font size if you want it to be the same size when you double the texture size.

Yeah, that’s what I understood after going through this thread.
I think there should be some form of warning if someone creates massive textures in an ADT. If it has the capacity to very quickly consume