Texture arrays

New DX10 spec introduce arrays of textures or render targets or any other resource. Of course new GPU ie require for all this features, but what to do with older GPU’s? Is it possible to make some kind of texure arrays on (I hate to say this) DX9 or DX8 hardware?

My idea is limited only on 2D texture arrays.
We can use cube maps which allows to use up to 6 textures on one texture slot, or using stack of 2D textures in one single 3D texture.

Cube maps have 6 textures (+x, +y, +z, -x, -y, -z). Application can bound diffuse texture to +x, normalmap +y, glossmap +z, … and access from shader:

sampler2DArray t;
...
vec4 diffuse = texture2DArray(t[0], texcoord.st);
vec4 normal = texture2DArray(t[1], texcoord.st);

texture2DArray(t[0], texcoord.st) call can be implemented as textureCube(t, vec3(1.0, texcoord.s, texcoord.t))

texture2DArray(t[1], texcoord.st) call can be implemented as textureCube(t, vec3(texcoord.s, 1.0, texcoord.t))

3D texture implementation can be a bit easier than cube texture. We only need nearest filtering along z (or r) texture axis and using unnormalized texture z (or r) coordinate.

texture2DArray(t[0], texcoord.st) call can be implemented as texture3D(t, vec3(texcoord.s, texcoord.t, 0.0))

texture2DArray(t[2], texcoord.st) call can be implemented as texture3D(t, vec3(texcoord.s, texcoord.t, 2.0))

Is it possible to implement this on current hardware and is it worth?

Try it out and tell us :wink: Was that not the motivation behing 3d textures?

Originally posted by yooyo:

Is it possible to implement this on current hardware and is it worth?

It should be emulable using the cube or 3d textures as you suggested, if you have no problem with limitations of that emulation (texture size limits, possible wasting of memory, wraping mode limitations, possible performance hit). Whether it is worth depens on your application, you will need to test it.

Originally posted by Zengar:
Was that not the motivation behing 3d textures?
The 3d textures and texture arrays are designed for somewhat different purposes.

The 3d textures are designed to store a 3d function like the marble pattern or attenuation of the light. For such use it is important that there is some form of interpolation as you move between individual slices. In this case the filtering simultaneously operates on elements from several different slices.

The texture arrays are meant as way to allow per pixel selection of one from several ordinary textures (e.g. one from several different shadowmaps). In this case the interpolation between slices is undesirable and the filtering is applied only to the slice that was selected by the third value.

Wouldn’t that simply work using uniform arrays?

uniform sampler2D t[2];
...
vec4 diffuse = texture2DArray(t[0], texcoord.st);
vec4 normal = texture2DArray(t[1], texcoord.st);

If the hardware doesn’t support a variable index into the array, the driver could transform the access into a branch (if (i == 0) use texture0, else if (i == 1) use texture1 …).

I don’t see why we would need new hardware here, dynamic branching seems enough (even static branching, but that would of course be very slow…). Of course new hardware could increase performance of the texture array access, but at least it would work on old hardware.