Jump to content

Reducing gpu memory usage for textures


Kesshi
 Share

Recommended Posts

Currently i'm trying to reduce the gpu memory usage of our app (especially for mobile devices).
I just saw that BabylonJS internally uploads every texture as gl.RGBA to the gpu even if if the source was a jpg or any other image without alpha channel.
https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.engine.ts#L2189

Using gl.RGB in those cases would save 25% of texture memory. I also have some grayscale textures. It would be nice if i could use gl.LUMINANCE to save even more memory. It should be possible to define the desired texture format in my opinion.
Would it make sense to add this as another parameter to the Texture constructor? It has a lot of parameters already ... i don't know if there is a better option without a breaking change.

Link to comment
Share on other sites

KTX, or multi-platform compressed textures that I added for 2.6 are much small in GPU.  Your finding makes my comparisons to regular textures even worse than I thought.

If you make this change, you are going to have to modify a lot more if you make it a parameter.  Maybe, just determine the extension cannot possibly have alpha, and adjust internally.  Otherwise, you are probably going to need to go all the way out to the exporters, since few people actually write Texture constructor code.

Also, when making this change, remember to do it to createCubeTexture() too.

Link to comment
Share on other sites

Compressed textures are good but they are not an option for me in this case (because of our software architecture) but i will keep it in mind for other projects.
I think automatic detection of the format is not a good idea. You would always have to use RGBA for png files even if the png doesn't have an alpha channel.
You would also lose the option to force a conversion. For example:
- you have a png with alpha channel but you don't need it -> use RGB instead of RGBA
- you have a fullcolor image but you want to show it as grayscale -> use LUMINANCE, the browser will convert the image for you

A parameter would be better i think.
I will have a look and see if can make a PR for this (for the engine only, not for the exportes)

Link to comment
Share on other sites

See your PR.  While I do not merge stuff on this repo, one extra line might be good for the general public.

If no format arg is supplied, then test for a '.JPG' extension.  If JPG, then do RGB.  That way you get the benefit without changing all the way back to Blender / 3DS Max, nor complicate things.

Link to comment
Share on other sites

  • 3 weeks later...

See internalformat parameter here.  I have to get in there soon, (before 3.0 comes out).  I added a compressed image type ATC, but could not find any ktx format converter.  I've seen Google is trying to officially remove ATC from WebGL, so I might as well rip it out before KTX gets into a production release.

Will probably add the JPG override described above, If I am not too late.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...