Texture array

Still…trying to figure out how texture works…

I plan to use an array of texture references…I understand that currently the texture reference variable has to be declared as static. So, maybe i am not able to dynamically allocate texture references like:

[codebox]tex = (texture<float, 3, cudaReadModeElementType>*)malloc(sizeof(texture<float, 3, cudaReadModeElementType>) * n);[/codebox]

within any functions or subroutines.

However, even if i declare an array of texture references in global scale as

[codebox]texture<float, 3, cudaReadModeElementType> tex[10]; // 3D texture[/codebox]

I am still not able to bind its element to CUDA array using

[codebox]cutilSafeCall(cudaBindTextureToArray(tex[i], cudaArrayList[i], channelDesc));[/codebox]

The error message is “invalid texture reference”. I am able to bind a texture variable declared not as a element of an array, though.

So, does anyone have an idea why this happens? or it is just not possible to use an “array of texture reference”?

I think you will find that despite looking like a templated type, the compiler doesn’t support textures in arrays or structures or anything else that you might expect to be able to do with a type. Texture references currently have to be declared “statically” at file scope for everything to work. Amongst other things, nvcc is generating inline assembler for the texture read calls and it seems to require integral values resolvable during preprocessing or the first compiler pass work correctly.

Thank you for your prompt reply, avidday!

Yes…i guess there is no way to use texture array as i found some old post in the forum mentioning about it. They suggest using a large texture to hold everything… I’ll try to work in this way, but i can imagine it should be hard for 3D textures…

BTW, I think the nvcc should add at least a warning in future version if people are declaring an array of textures.

Texture array is not possible… You can try using “token pasting” gymnastics in the code to make it easier…