NVIDIA GTX 680 OpenGL Bindless Textures Demo

NVIDIA Bindless texture demo, GeeXLab

1 – Bindless Textures Overview

I spent some time last week to add into GeeXLab the support of bindless textures. Bindless textures is the very cool feature introduced with the GeForce GTX 680.

But what are bindless textures? In 3D programming (OpenGL or Direct3D), to use a texture, you have to bind it to a texture unit. In OpenGL for example, a GeForce GTX 680 has 32 texture units you can use in your GLSL shader programs. That means you can do multi-texturing with a max of 32 textures (which is enough for most cases). If you need more textures, you must re-think your algorithm.

With bindless textures, there’s no longer need to bind a texture to a texture unit. Just create your textures and, quickly said, enable their bindless status (read: make them resident textures). Now you can have more than 32 textures to make your greedy shaders happy.

Here’s the slide for explaining the bindless texture concept:

NVIDIA Bindless texture

Currently, bindless textures are only available in OpenGL applications (like GeeXLab). If you want to dive into bindless texture programming, check out this OpenGL extension: GL_NV_bindless_texture.

OpenGL logo

EVGA GeForce GTX 680
EVGA GeForce GTX 680

2 – Bindless Textures Demo

So what kind of simple demo could I do to show the use of bindless textures? After some tests, I ended up on this mosaic-like demo:

NVIDIA Bindless texture demo, GeeXLab

NVIDIA Bindless texture demo, GeeXLab

This demo simply loads a bunch of textures (here 1024 textures on the screenshot), makes them resident (with glMakeTextureHandleResidentNV()) and draws a simple quad with all textures, using one render call only. An uniform buffer is used to pass all texture handles (a texture handle is an 64-bit unsigned int or uint64_t, NVIDIA extension provides some functions to manage uint64_t uniform variables) to the pixel shader. In this particular demo and thanks to bindless textures, it’s like if the GTX 680 had virtually 1024 texture units

On my EVGA GeForce GTX 680 (with R301.24), the demo runs at 1015 FPS (640×480, default camera settings) and at 790 FPS in full HD resolution (1920×1080).

Here is the GLSL shader (vertex + pixel shader) that renders all textures on the quad:

void main(void)
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
#version 420 compatibility
#extension GL_NV_bindless_texture : require
#extension GL_NV_gpu_shader5 : require // for uint64_t
#define TEX_X 32
#define TEX_Y 32
uniform SamplersNV
{ uint64_t allTheSamplers[NUM_TEXTURES]; };
void main (void)
  vec2 uv = gl_TexCoord[0].st * vec2(TEX_X, TEX_Y);
  int x = int(uv.x);
  int y = int(uv.y);
  int index = y*TEX_Y + x;
  sampler2D s = sampler2D(allTheSamplers[index]);
  gl_FragColor.rgb = texture(s, uv).rgb;
  gl_FragColor.a = 1;	

If you have a GTX 680, GTX 690 or GTX 670, you can download and test the GeeXLab Bindless Textures Demo (left-click to grab the file):
Download GeeXLab Bindless Texture Demo Version 1.0

The demo loads 1024 textures (I created the textures with FRAPS running NVIDIA Alien vs Triangles and NVIDIA Endless City demos) and displays them with one OpenGL render call. To run the demo, just start GXL_NV_Bindless_Texture_Demo.exe.

The source code of the GeeXLab demo is available in the GXL_NV_Bindless_Texture_Demo.xml file.
You have to use GeeXLab 0.4.0 or newer to tweak and hack the demo.

If the OpenGL renderer does not support bindless textures, you should see something like this:

NVIDIA Bindless texture demo on Radeon card, GeeXLab

[ Subscribe to Geeks3D latest news by email ]


↑ Grab this Headline Animator