How to use eglFrame to CudaArray by texObject ?

I can get frames from EGLFrame by cuGraphicsResourceGetMappedEglFrame() function . And then I want to bind the TexObject by use cuTexObjectCreate function , but it did not work. I have seen the demo in the histogram with using surface like below :

// Create a surface from the luminance plane
CUDA_RESOURCE_DESC cudaResourceDesc;
memset(&cudaResourceDesc, 0, sizeof(cudaResourceDesc));
cudaResourceDesc.resType = CU_RESOURCE_TYPE_ARRAY;
cudaResourceDesc.res.array.hArray = cudaEGLFrame.frame.pArray[0];
CUsurfObject cudaSurfObj = 0;
cuResult = cuSurfObjectCreate(&cudaSurfObj, &cudaResourceDesc);

is there any demo or tutorial to tell me how to use it?

I have use cudaMemcpy2DArrayToArray() function to copy EGLframe.frame.pArray[0] to another cuArray, and then use TexRef, it did work, but it took long time to copy data by cudaMemcpyDeviceToDevice.


We don’t have cuTexObjectCreate() sample directly.

Please check this document to find the required structure:

And follow the procedure in histogram sample. (should be similar)


Hi, AastaLLL,

Thanks for your response, I have try again with texObject, and it did work. But I have two question to ask you .

First, I declared an array CUtexObject texObj[8] pass to the function, and fetch like this:
yuv = tex2D(texObj[i], x, y)
it occured error. if it cann’t pass pointer ?

Second, would it take long time to create an Object and destroy per frame ? I have seen histogram demo, it do every frame to create object and destroy…


  1. Please check if tex2D() support Driver API(CUxxx).
    If not, please transfer CUtexObject to Runtime API first(cudaxxx).

  2. If memory change location, creation is needed.
    In real use-case, we usually allocate a big buffer. Ex. 10-frames.

So we need to create texture object for the first 10 frames
From 11-th image, the texture object can be reused and no creation is needed.


Hi, AastaLLL

Thanks for your answer. I have sloved the first problem.

For the second question : One frame has three surface(YUV), so I have to declare three Object, and I have 8 cameras parallel, so I have to declare 24 texObject . if I allocate 10 frames, I have to create 240 Object ? If so, is there any example I can learn ? Or is there another way I can do with it convenient?


We don’t have a sample to demonstrate this use-case.
This issue is related to general object management and doesn’t have particular limitation to take care.

You can manage it as you used to.

Note that going from “1” to “2” is a big step in itself. If you don’t want to manage “10” then at least using “2” is likely going to help.

Hi, AastaLLL and snarky

Thanks for your answer, I will try it.