Hello @Dark_Photon,
I have read your post and merged the part doReadbackFAST function on a qt quick qml application. I have run the implementation on nvidia jetson xavier nx platform for getting 16bit RGB colors as the following:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WaylandEgl::initFastBuffers()
{
if (!buffCreated)
{
pbo_size = mWinHeight * mWinWidth *2;
pixels = new unsigned char[pbo_size];
Readback_buf = (GLchar *) malloc( pbo_size );
glGenBuffers( PBO_COUNT, pboIds );
// Buffer #0: glReadPixels target
GLenum target = GL_PIXEL_PACK_BUFFER;
glBindBuffer( target, pboIds[0] );
glBufferData( target, pbo_size, 0, GL_STATIC_COPY );
glGetBufferParameterui64vNV = (PFNGLGETBUFFERPARAMETERUI64VNVPROC)eglGetProcAddress("glGetBufferParameterui64vNV");
if (!glGetBufferParameterui64vNV)
{
qDebug() << "glGetBufferParameterui64vNV not fouynded!";
return;
}
glMakeBufferResidentNV = (PFNGLMAKEBUFFERRESIDENTNVPROC)eglGetProcAddress("glMakeBufferResidentNV");
if (!glMakeBufferResidentNV)
{
qDebug() << "glMakeBufferResidentNV not fouynded!";
return;
}
glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)eglGetProcAddress("glUnmapBufferARB");
if (!glUnmapBufferARB)
{
qDebug() << "glUnmapBufferARB not fouynded!";
return;
}
glGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC)eglGetProcAddress("glGetBufferSubData");
if (!glGetBufferSubData)
{
qDebug() << "glGetBufferSubData not fouynded!";
return;
}
qDebug() << "Run the optimizatiosn";
GLuint64EXT addr;
glGetBufferParameterui64vNV( target, GL_BUFFER_GPU_ADDRESS_NV, &addr );
glMakeBufferResidentNV( target, GL_READ_ONLY );
// Buffer #1: glCopyBuffer target
target = GL_COPY_WRITE_BUFFER;
glBindBuffer( target, pboIds[1] );
glBufferData( target, pbo_size, 0, GL_STREAM_READ );
glMapBufferRange( target, 0, 1, GL_MAP_WRITE_BIT);
glUnmapBufferARB( target );
glGetBufferParameterui64vNV( target, GL_BUFFER_GPU_ADDRESS_NV, &addr );
glMakeBufferResidentNV ( target, GL_READ_ONLY );
buffCreated = true;
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
}
}
void WaylandEgl::doReadbackFAST()
{
// Work-around for NVidia driver readback crippling on GeForce.
initFastBuffers();
//glFinish();
Timer t1;
t1.start();
// Do a depth readback to BUF OBJ #0
glBindBuffer( GL_PIXEL_PACK_BUFFER, pboIds[0] );
glReadPixels( 0, 0, mWinWidth, mWinHeight,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0 );
t1.stop();
readTime = t1.getElapsedTimeInMilliSec();
t1.start();
// Copy from BUF OBJ #0 to BUF OBJ #1
glBindBuffer( GL_COPY_WRITE_BUFFER, pboIds[1] );
glCopyBufferSubData( GL_PIXEL_PACK_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0,
pbo_size );
// Do the readback from BUF OBJ #1 to app CPU memory
glGetBufferSubData( GL_COPY_WRITE_BUFFER, 0, pbo_size,
Readback_buf );
//sendImage((unsigned char*)Readback_buf,pbo_size);
t1.stop();
processTime = t1.getElapsedTimeInMilliSec();
glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
qDebug() << "Read Time " << readTime;
qDebug() << "Process Time " << processTime;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here are the results for Cpu consumption, read time and process time on both intel linux pc and nvidia jetson xavier nx:
- Intel : 11-12% cpu usage , Read Time: 0.039ms, Process Time:2.014ms
- Nvidia: 28-32% cpu usage, Read Time:3.118 ms, Process Time:1.659 ms
I know that getting RGBA is less cpu consuming and faster but my requirement is getting 16 bit RGB colors.So Do you have any idea how I can reduce the cpu consumption on nvidia jetson xavier nx platform ?
Regards