7 Replies Latest reply on Jul 31, 2012 12:08 PM by sarbrita

    ATI Pinned memory extension crash

    sarbrita

      Hi,

      I am trying to use ATI's pinned memory extension to transfer data fast from GPU to CPU but I am getting crash while reading pixels.

       

      Here is my code.

       

      void getPixelDataFromATIGPU()

      {

          int dataDize = width * height * 4;

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_pinnedMemBuffer);

       

          /* Getting crash here in glReadPixels */

          glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0);

          GLsync s = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

       

          if(glIsSync(s))

          {

              glClientWaitSync(s, GL_SYNC_FLUSH_COMMANDS_BIT, 1000 * 1000 * 1000);

              // Use memory here

          }

       

          // It is now safe to use 'memory'

      }

      /*****************************************************************************/

      void initPinnedMemoryBuffer()

      {

          int dataDize = width * height * 4;

       

          glGenBuffers(1, &m_pinnedMemBuffer);

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_pinnedMemBuffer);

       

          char* memory_temp = new char[dataDize + 0x1000];

          m_pinnedMemory = reinterpret_cast<char*>(unsigned(memory_temp + 0xfff) & (~0xfff));

          glBufferData(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, dataDize, m_pinnedMemory, GL_STREAM_READ);

         

      }

        • Re: ATI Pinned memory extension crash
          gsellers

          Hi,

           

          Once you have created the external memory buffer, you need to bind it to the GL_PIXEL_PACK_BUFFER target. Change these lines in getPixelDataFromATIGPU() from:

           

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, m_pinnedMemBuffer);

           

          to

           

          glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);

          glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pinnedMemBuffer);

           

          Then your sample should work.

           

          Thanks,

           

          Graham

            • Re: ATI Pinned memory extension crash
              sarbrita

              It definitely is not crashing but I still need to compare the data. Another followup question: I can now use the binded buffer to copy pixels from right? I can just use following code every frame:

               

              char data[size];

              memcpy(data, m_memory, size);

               

              In other words..i will get pixel data of every frame in the binded memory buffer. I dont have to rebind new buffer every time?

            • ATI Pinned memory extension crash
              sarbrita

              Thanks Graham..I will give it a shot.