Hi all,
I’m just wondering if anyone has any experience using CUDA-OpenGL interoperability, specifically with accessing all layers of a GL_TEXTURE_2D_ARRAY texture in CUDA.
What I’ve done so far is, I created the layered texture in OpenGL, register it using cudaGraphicsGLRegisterImage() with GL_TEXTURE_2D_ARRAY target. When I want to use it I map it using cudaGraphicsMapResources() and then get access to the cudaArray* using cudaGraphicsSubResourceGetMappedArray, specifying 0 for both the array index and the mipmap level.
This set up seems to be working. The issue I’m having is that I only seem to be able to access the base level of the array texture (I guess from specifying 0 for the array index?). Is it possible to be able to access all layers from within the kernel using a bound texture reference?
I assume this is possible because the sample simpleLayeredTexture creates 3D cudaArray which is bound to a texture reference of type cudaTextureType2DLayered and it can access all layers in the kernel.
Since both the simpleLayeredTexture sample and my code are binding the cudaArray* to the texture reference of the same type, I can only think of the cudaGraphicsSubResourceGetMappedArray() call as the one causing the issue. Is there any other way of getting a cudaArray* to the array texture?
texture<float4, cudaTextureType2DLayered, cudaReadModeElementType> texture_reference;
cudaGraphicsResource_t hemicube_resource;
Gluint render_texture_array;
glGenTextures(1, &render_texture_array);
glBindTexture(GL_TEXTURE_2D_ARRAY, render_texture_array);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internal_format, texture_width, texture_height, texture_depth, 0, format, type, NULL);
cudaError_t status = cudaSuccess;
status = cudaGraphicsGLRegisterImage(&texture_resource, render_texture_array, GL_TEXTURE_2D_ARRAY, cudaGraphicsMapFlagsReadOnly);
// Render to the render_texture_array
cudaError_t status = cudaGraphicsMapResources(1, &texture_resource, 0);
assert(status == cudaSuccess);
cudaArray* texture_array = NULL;
status = cudaGraphicsSubResourceGetMappedArray(&texture_array, texture_resource, 0, 0);
assert(status == NULL);
cudaChannelFormatDesc channel_description = cudaCreateChannelDescHalf4();
cudaError_t status = cudaBindTextureToArray(texture_reference, texture_array, channel_description);
assert(status == cudaSuccess);
// Launch kernel
cudaError_t status = cudaUnbindTexture(texture_reference);
assert(status == cudaSuccess);
status = cudaGraphicsUnmapResources(1, &hemicube_resource, 0);
assert(status == cudaSuccess);
Thank you
Surya