strategy for glMakeTextureHandleNonResidentARB(...)

hi,

i’ve just read about how to use GL_ARB_bindless_texture, he key is to make a texture “resident” before using it in shaders. “resident” means that it is on the “server-side” memory (gpu). i tried to figure out how to query how much gpu memory is “remaining” but apparently that is not possible in openGL (right?). so, the question is: what to do if i have many big textures ? at first i’d just let them all be resident … but is there a guideline on how to temporary make textures non-resident ?

let’s say i want to draw 20 different models with many textures that exceed the video memory of my graphics card. should i divide the batches in smaller parts, and if so how many ?

thanks in advance !!

As part of the GL spec, no. However, some of the GPU driver vendors have provided extensions to help with this. For instance:

[ul]
[li]NVidia: NVX_gpu_memory_info [/li][li]AMD: ATI_meminfo [/li][/ul]

I’ve used the former (not the latter), and it’s pretty useful. Besides telling you how much device (GPU) memory is installed, it tells you how much is still available, and how much the GPU/GL driver has had to spill (evict) off the GPU back onto CPU memory since a given point in time. If you see evicted counting up, that’s a strong indicator that you are overrunning GPU memory.

NVidia has also recently released these extensions in their GL drivers:

[ul]
[li]NV_query_resource [/li][li]NV_query_resource_tag [/li][/ul]

which provide memory consumption at the per-object level rather than for all of GPU memory. Haven’t used these yet, but I plan to soon.

so, the question is: what to do if i have many big textures ? … let’s say i want to draw 20 different models with many textures that exceed the video memory of my graphics card. should i divide the batches in smaller parts, and if so how many ?

That’s going to depend on your application. First thing is to get the minimal available GPU memory you need to fit into, and estimate whether everything will just fit as-is. Just use simple heuristics on GPU texture size. Ensure that you’re using GPU texture compression sensibly to save space and bandwidth, not just using RGB8 and RGBA8 for everything.

If your textures (along with all your buffer objects, framebuffers, and other GPU resources) won’t fit, then…

With bindless texture, there’s less of a reason to have super-big texture arrays to batch things together. So you probably don’t need those anymore.

Do you have a lot of textures with very high pixel dimensions? You only need the highest-res MIPmap levels when those textures are going to be very large in screen-space (and if your screen space dimensions in pixels are large). So perhaps you consider paging in LODs progressively based on how large they can be on-screen (or never, depending on your screen dimensions).

Or do you just have a lot of textures and that’s the problem? Perhaps you need to implement some runtime paging support to dynamically load from disk and upload to the GPU just those textures that could be needed around the eyepoint at any given time.

To your main question though:

strategy for glMakeTextureHandleNonResidentARB(…)

I’d be very leery of expecting any/all GL drivers to so something that performs really well when you flip textures between resident and non-resident. When the driver pages textures between CPU and GPU memory (e.g. when you’re overrunning GPU memory), the results are not pretty. Long frame hangs while the driver goes out-to-lunch moving data around en-mass.

Instead, I’d suggest the strategy of creating what textures you need (those that you know should fit in GPU memory), make them resident, and be done with it.