PDA

View Full Version : texture memory



frantic
03-27-2011, 06:50 AM
Hello all, first time here,

I was trying save GPU memory when loading texture mipmaps to higher levels (low resolution) first. To my amazement the GPU memory (using GPU-Z) had increased to the full texture size as if loading all mipmaps including the high resolution ones.
i am using s3tc/dxtc compressed textures.

is this behaviour expected, or is there a trick to allocate only the memory for the actual loaded levels ?

i was counting on that to also delete high res levels (when no longer used), specifying null as the level pointer, is there another way to acheive this without deleting the whole texture ?

thanks

mhagain
03-27-2011, 08:03 AM
Specifying a NULL pointer doesn't reduce memory usage: http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

In GL version 1.1 or greater, data may be a null pointer. In this case, texture memory is allocated to accommodate a texture of width width and height height.
The thing about textures is that mipmap levels don't exist in isolation. With the exception a texture that only contains level 0, you must specify all mipmap levels or the resulting texture object is incomplete.

Roundabout now I'm wondering if you've profiled your application and determined that excessive texture memory usage is a problem.

frantic
03-27-2011, 11:01 AM
Hi,

thanks, i thought that much.
as i recall for the texture to be complete all mipmaps from base lod (can be > 0) until max lod should exist(loaded). that is why i thought that not loading the 0 lod will not allocate it.

anyways i am using over 1GB of textures, all of them very big (2kX2k rgba). i need some mechanism to load only the levels i need without allocating the whole texture , and a way to release unused high-res levels without the need to generate and reload a new texture. anybody can help here, please. reference to code would be much appreciated.

thanks in advance,
frantic

Alfonse Reinheart
03-27-2011, 01:55 PM
Don't call glTexImage* for a mipmap until you have texture data to upload. It's really that simple.

There's no rule in OpenGL that says you must call glTexImage* for the highest mipmap layer. Just set your GL_TEXTURE_BASE_LOD and GL_TEXTURE_MAX_LOD values to exclude mipmap levels that you haven't loaded yet.

frantic
03-27-2011, 08:35 PM
that is exactly what i am doing, but the problem is the memory for lod 0 is allocated anyways. i am trying to avoid that as i have many many large textures.

Alfonse Reinheart
03-27-2011, 09:03 PM
Oh. Well, I guess there's nothing you can do about it. There's no way to tell it not to allocate more memory than you specifically asked for.

Ilian Dinev
03-28-2011, 02:39 AM
So, create "smaller" versions of the textures (with their own GLuint names/handles), where lod0 is i.e lod3 of the file-original. On demand, create the bigger version, and copy via cpu or PBO/FBO texels from the smaller version; load from file lods 0..2

frantic
03-28-2011, 03:46 AM
yep,
I guess no other solution.

is there a way to copy directly between textures ?

thanks, frantic

Aleksandar
03-28-2011, 07:24 AM
If you are targeting NV hardware, then: NV_copy_image (GL/WGL/GLX).
I'm note sure whether AMD supports it.

This extension enables efficient image data transfer between image
objects (i.e. textures and renderbuffers) without the need to bind
the objects or otherwise configure the rendering pipeline. The
WGL and GLX versions allow copying between images in different
contexts, even if those contexts are in different sharelists or
even on different physical devices.

frantic
03-28-2011, 12:46 PM
thanks, looks promising