[SOLVED] How to manage GPU memory with Playcanvas? Got crash with when GPU memory is at maximum


#1

Hi,

I’m working on a product configurator and it’s possible to load (on demand with loadFromUrl) a lot of models and textures. In fact, the user can load 200Mb+ of data with that.

The problem is that my GPU Memory goes high and eventually kill the GPU memory coming form my Google Chrome tab, causing the canvas to not work anymore.

If I reload the page with the canvas, the memory is release.

So, is there a way to manage the GPU memory with Playcanvas? Is there a flush() and clear() function for that?


#2

Hi @Mystik,

Yes, it is relatively easy to manage what is loaded in memory. Playcanvas by default will load all assets that have the asset.preload property to true during app load time or when they become first required during app play time (e.g. a model needs to be rendered, all materials and textures referenced by it are automatically loaded).

You can use the asset.loaded property to check if something is loaded or not.

What Playcanvas won’t do automatically is unload stuff from memory, but it provides the method to do so in code, asset.unload():

https://developer.playcanvas.com/en/api/pc.Asset.html#unload

Ideally you should aim to have assets loaded in memory that are visible or about to get visible on screen, and afterwards you should unload them to free memory space. You can use the Profiler to monitor the total video memory used.

To reload an asset you unloaded manually you use the load method provided by the AssetRegistry:

https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#load

this.app.assets.load(myAsset);

You can read how Playcanvas handles assets loading here:

https://developer.playcanvas.com/en/user-manual/assets/preloading-and-streaming/


#3

To further reduce the VRAM footprint of your app you should also use in addition to loading/unloading assets, texture compression:

https://developer.playcanvas.com/en/user-manual/assets/textures/


#4

Thank you for your great answers.

Another question about the reload:

To reload an asset you unloaded manually you use the load method provided by the AssetRegistry:

If I’m reloading an asset that was loaded through URL (loadFromUrl), do this will redownload the content or just reload in memory?


#5

Exactly, it will load it from the browser local cache, so no re-downloading is required.


#6

Very interesting! Thank you again.