Cudabindtexturetoarray deprecated

Can someone please tell me how can I replace cudabindtexturetoarray which is now deprecated I don’t see an alternative in the latest CUDA docs. Want to map an OpenGL texture and use it in a CUDA kernel.

1 Like

Hi,
did you already found a solution?
I’m looking also for this topic but found nothing than this post.

Yes I found it. I hope it helps.

__global__ void kernel(cudaTextureObject_t tex, ...)
{
    ...
    const auto color = tex2D<uchar4>(tex, x, y);
    ...
}

cudaGraphicsResource* cudaHandle = nullptr;
cudaGraphicsGLRegisterImage(&cudaHandle, ...);

auto errorState = cudaGraphicsMapResources(1, &cudaHandle, 0);
cudaArray* cuArray = nullptr;
cudaGraphicsSubResourceGetMappedArray(&cuArray, cudaHandle, 0, 0);

cudaTextureObject_t         tex;
cudaResourceDesc            texRes;
memset(&texRes, 0, sizeof(cudaResourceDesc));

texRes.resType = cudaResourceTypeArray;
texRes.res.array.array = cuArray;

cudaTextureDesc             texDescr;
memset(&texDescr, 0, sizeof(cudaTextureDesc));

texDescr.normalizedCoords = false;
texDescr.filterMode = cudaFilterModePoint;
texDescr.addressMode[0] = cudaAddressModeClamp;
texDescr.addressMode[1] = cudaAddressModeClamp;
texDescr.readMode = cudaReadModeElementType;

cudaCreateTextureObject(&tex, &texRes, &texDescr, NULL);

kernel<<<>>>(tex, ...);

1 Like

Yes!
Thank you!