PDA

View Full Version : How to readback PBO to main memory fast?



WatchAndLearn
10-27-2010, 08:18 PM
Hi everyone:
I've created a pixel buffer object(PBO) and modified it with CUDA. Now I want to readback the PBO result to main memory for transfering to other nodes. Is there an efficient method to readback PBO?
I mapped PBO and copy the contents to an array like this:
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_AR B, GL_READ_ONLY_ARB);
int count=0;
for (int i=0 ; i<width; i++)
{
for (int j=0 ; j<height; j++)
{
cpumem[count] = ptr[count];
cpumem[count+1] = ptr[count+1];
cpumem[count+2] = ptr[count+2];
cpumem[count+3] = ptr[count+3];
count += 4;
}
}
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);

I found the map operation was too heavy. Is there another more efficient method to readback PBO? Thanks:)

carsten neumann
10-28-2010, 07:42 AM
Is the mapping the problem or the actual copying? Why are you copying the individual bytes "by hand" instead of just calling memcpy or something like it?

mfort
10-28-2010, 07:56 AM
Using aligned memory and special SSE instruction helps a lot. See this: http://williamchan.ca/portfolio/assembly/ssememcpy/

WatchAndLearn
11-01-2010, 03:51 AM
Thanks a lot, I will try it.