Help me for cudaGraphicsGLRegisterImage

struct cudaGraphicsResource *resource;

void createTexture(unsigned int width1, unsigned int height1)
{

	glGenTextures(1,&textureID[0]);
	glBindTexture( GL_TEXTURE_2D, textureID[0]);
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width1 , height1, 0,
					GL_RGBA,GL_FLOAT,NULL);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEA

R);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEA
R);
glBindTexture( GL_TEXTURE_2D, 0);

	cutilSafeCall(cudaGraphicsGLRegisterImage(&resource, textureID[0],GL_TEXTURE_2D, cudaGraphicsMapFlagsNone));   <---------- OK

}

int runCuda()
{

	float4 *dptr=NULL;
	size_t num_bytes; 
	cutilSafeCall(cudaGraphicsMapResources(1, &resource, 0));     <-----   OK

	cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&dptr,&num_bytes,resource));   <------ Runtime API Error  = unspecified driver  

                                                                                                                                                                                                 error  (WHY?)                  
             

            ......................................

            ......................................

            return 0;

}

Help me!!! :confused: :confused:

can you post a correct example ? memory allocation,registration,mapping…thank

Currently cuda does not support mapping of textures with normalized 8-bit components, only float and unnormalized integer formats are supported.

N.

can you post a correct example ? Please… with float or integer…thank you

cudaGraphicsResourceGetMappedPointer is used for buffer objects while you need to use cudaGraphicsSubResourceGetMappedArray for mapping textures.

struct cudaGraphicsResource *resource;

.............................

void createTexture(unsigned int width1, unsigned int height1)

{

glGenTextures(1,&textureID[0]);

glBindTexture( GL_TEXTURE_2D, textureID[0]);

glTexImage2D( GL_TEXTURE_2D, 0,GL_RGBA32F, width1 , height1, 0, GL_RGBA,GL_FLOAT,NULL);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

glBindTexture( GL_TEXTURE_2D, 0);

cutilSafeCall(cudaGraphicsGLRegisterImage(&resource, textureID[0],GL_TEXTURE_2D, cudaGraphicsMapFlagsNone));

}

...........................

int runCuda()

{

cudaArray* array;

cudaGraphicsMapResources (1, &resource,0);

cudaGraphicsSubResourceGetMappedArray (&array, resource, 0, 0);

return 0;

}

N.

thanks so much for your answer!!! I will try to use your code :-)

My problem is :

I should write to GL texture in each frames.

My solution was using a PBO (Pixel Buffer Object)…

glGenBuffers(1,&pboID[0]);

	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboID[0]);

	glBufferData(GL_PIXEL_UNPACK_BUFFER, size1, NULL,  GL_DYNAMIC_DRAW);

	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

	cutilSafeCall(cudaGraphicsGLRegisterBuffer(&pbo_res1, pboID[0], cudaGraphicsMapFlagsNone));

void runCuda()

{

	uchar4 *dptr=NULL;

	size_t num_bytes; 

	cutilSafeCall(cudaGraphicsMapResources(1, &pbo_res1, 0));

	cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&dptr,&num_bytes,pbo_res1));

	launch_cudaRotProcess(dptr);

	cutilSafeCall(cudaGraphicsUnmapResources(1,&pbo_res1, 0));

}

void display()

{

runCuda();

		cutilSafeCall( cudaThreadSynchronize() );

		glBindTexture(GL_TEXTURE_2D, textureID[0]);

		

		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboID[0]);

		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,

					GL_RGBA, GL_UNSIGNED_BYTE, NULL);

		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

		glBindTexture(GL_TEXTURE_2D, 0);

}

Is this correct? Do you know a performing way? I’m a beginner and I’m searching for the best solution :confused:

THANK YOU!!!

Yep, that looks like the best option yet.

If I remember correctly, for 8bit/component color textures the data is actually stored as GL_BGRA internally. If you could use that component ordering instead, you might save some time as the driver does not need to swizzle the bytes when performing the texsubimage.
I’m not sure if it’ll make much difference on current hardware but I did notice a significant improvement in the past.

PS. For floating point textures the internal component ordering is also GL_RGBA

N.