Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Low readback performance with PBO , help !!!!!

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    19

    Low readback performance with PBO , help !!!!!

    Hi

    i use a PBO approach to grab a bitmap from my 3d scene . steps are the following :

    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo1);

    glReadPixels(0, 0,bWIDTH,bHEIGHT,GL_BGRA, GL_UNSIGNED_BYTE, 0);

    copymem(glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,GL _READ_ONLY_ARB)^, buffer,BWidth * BHeigh * 4);

    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo2);

    glReadPixels(0, 0,pWIDTH,pHEIGHT ,GL_BGRA, GL_UNSIGNED_BYTE, 0);

    copymem(glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB)^,bitmapbuf, bWidth * bHeigh * 4);
    glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);

    swap(pbo1,pbo2)

    with methode i get 15~25 fps low than a direct :

    glReadPixels(0, 0,pWIDTH,pHEIGHT ,GL_BGRA, GL_UNSIGNED_BYTE, bitmapbuf);

    as i see in many forum the PBO should be more Faster than the glReadPixels one


    my card is : nVidia Geforce 7600 GS
    forceware version : 169.21
    Bus PCI Express x16
    CPU : P4 3.0Ghz



    are there any bad implementation in my PBO code, how can i boost it ?

    help please

    Thanks in Advance

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,401

    Re: Low readback performance with PBO , help !!!!!

    Is this for a screenshot?

    You want to use PBOs when you have something else to do while the transfer is taking place behind the scenes, not when you need the results straight away.

    Check out the PBO spec for some common usage scenarios and example code.

  3. #3
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    318

    Re: Low readback performance with PBO , help !!!!!

    1) Why are you reading the data twice?
    2) Why are you coping data out of PBO? the PBO memory is just fine.
    3) Do not call MapBuffer just after read pixels. There is no benefit of PBO then.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    19

    Re: Low readback performance with PBO , help !!!!!

    Quote Originally Posted by modus
    Is this for a screenshot?

    You want to use PBOs when you have something else to do while the transfer is taking place behind the scenes, not when you need the results straight away.

    Check out the PBO spec for some common usage scenarios and example code.
    yes it is for a screenshot.

    just now i change it to this to acheive a Asynchron readback

    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, imageBuffers[0]);
    glReadPixels(0, 0, imagewidth, imageheight/2, GL_BGRA, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));

    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, imageBuffers[1]);
    glReadPixels(0,imageheight/2,imagewidth,imageheight/2,GL_BGRA,GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));

    // Process partial images. Mapping the buffer waits for
    // outstanding DMA transfers into the buffer to finish.
    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, imageBuffers[0]);
    pboMemory1 = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
    processImage(pboMemory1);

    glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, imageBuffers[1]);
    pboMemory2 = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
    processImage(pboMemory2);

    but still get low performance instead the glreadpixels

    can someone please guide me to the correct steps

    Thanks

  5. #5
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Low readback performance with PBO , help !!!!!

    In current frame bind pbo and do readback.
    In next frame map pbo and copy it's content to sysmem.

    Why this? When app call glReadPixels while pbo is bind, then glReadPixels is nonblocking call. But if you try to map pbo buffer soon after glReadPixels then this glMapBuffers will be blocked until glReadPixels is finished.
    When to call map buffer is hard to tell, because it depends on underlaying hardware, driver, screen size, chipset, ... So the best will be to do that operation (glMapBuffer and memcpy) in next frame.

    Also.. this pbo memory is not cacheable so do not try to do some weird access pattern. Plain memcpy in sysmem buffer is best approach.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    19

    Re: Low readback performance with PBO , help !!!!!

    Thanks for reply

    ok, i am not sure that i get it well but i change my code a bit to :


    index = (index + 1) % 2;
    nextIndex = (index + 1) % 2;

    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
    glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);

    GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);

    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
    GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);

    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);


    but still same problem ... low performance

    any idea, perhaps some code will help me better

    Thanks


  7. #7
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Low readback performance with PBO , help !!!!!

    No.. thats wrong.. see this
    Code :
    // At end of frame before SwapBuffers call
    // to use this... just set bDoScreenShot to true.
    if (bCopyToSysMem)
    {
     bCopyToSysMem = false;
     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo); 
     GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
     memcpy(sysme, src, imgsize);
     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); 
    }
     
    if (bDoScreenShot)
    {
     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pbo); 
     glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);
     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); 
     bCopyToSysMem = true;
     bDoScreenShot = false;
    }
     
    SwapBuffers(...);

    Above code snippet is just for single screenshot!

  8. #8
    Junior Member Newbie
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    19

    Re: Low readback performance with PBO , help !!!!!

    Thanks yooyo for the hints

    your code give a faster result (10~15 fps faster).
    but :s i get a black bitmap it seems that the src is empy :S

    can u tell me what the sysme is ?

    Thanks

  9. #9
    Member Regular Contributor Jackis's Avatar
    Join Date
    Sep 2005
    Location
    Saint-Petersburg, Russia
    Posts
    279

    Re: Low readback performance with PBO , help !!!!!

    yooyo wants to say, that in order to use befits from PBO, you should make asynchronous readbacks. In the code above yooyo advice you to make ReadPixels with PBO on the first frame, but you can use this memory only next frame (or some frames later, maybe 2-3), and only way like that may get you PBO benefit.

  10. #10
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: Low readback performance with PBO , help !!!!!

    Just insert my code before you call SwapBuffers, at end of render frame. Something like...
    Code :
    // this is a very basic render loop
    while (bQuit == false)
    {
     UpdateGame();
     RenderGame();
     // insert my code here
     SwapBuffers(); // present frame
    }

    Quote Originally Posted by PixIn
    can u tell me what the sysme is ?
    sysme is a typo... it should be sysmem
    sysmem is pointer to system memory buffer. Applicatio should allocate this buffer. Size should be SCR_WIDTH * SCR_HEIGHT * BYTES_PER_PIXEL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •