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 14

Thread: efficiently clear buffers

  1. #1
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    289

    efficiently clear buffers

    Hi,
    I am working on a project utilizing EXT_shader_image_load_store functionality to write buffer objects during rendering. What i am missing from OpenGL is a way to efficiently clear the buffers between invocations. For textures I am going the way of attaching them to a FBO and calling glClearBuffer(), which i think is Ok but still not clean enough.

    With buffers i am forced to go the way of dummy rendering passes using fullscreen geometry to clear the buffers. Very ugly and IMO quite inefficient. D3D11 has ID3D11DeviceContext::ClearUnorderedAccessView{}() functions to do this, OpenGL badly requires such functionality.

    Am I missing a more efficient way for clearing buffer objects?

    Regards
    -chris

  2. #2
    Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    466

    Re: efficiently clear buffers

    Am I missing a more efficient way for clearing buffer objects?
    As far as I understand you these are not buffer objects. Are you talking about FBO ? If so, if glClearBuffer is too slow for you, you can try a CopyTexSubImage which seems fast, but unsure if it's faster than clearing the buffer. If you have no texture attached to the FBO, then I think you have no other choice but glClearBuffer.

  3. #3
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    289

    Re: efficiently clear buffers

    These are buffer objects. I am using the texture buffer functionality to directly access them in the shaders. For texture images the FBO way is fast enough, but for actual buffer objects i need to run a shader which then fills the buffer with the wanted clear value.

  4. #4
    Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    466

    Re: efficiently clear buffers

    Sorry for this stupid question again, but:

    why you clear buffers with glClearBuffer when you have textures, and why can't you call glClearBuffer when you have a buffer ?

    I'm certainly missing a point, but which one...

  5. #5
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    289

    Re: efficiently clear buffers

    The glClearBuffer API is there for clearing color attachments of a FBO (i.e. textures or render buffers). So there is no way to actually clear a buffer object (e.g. pixel buffer).

    We now have the functionality to do random writes to buffer objects from a shader, not just fixed writes to textures or render buffers. So we are missing a functionality to clear buffer objects directly.

  6. #6
    Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    466

    Re: efficiently clear buffers

    I think you can use asynchronism to do a more quick clear.

    According to: http://www.opengl.org/registry/specs...fer_object.txt

    when using glDrawPixels with a pixel pack buffer object, glDrawPixels may return prior to image unpacking because future modification of the buffer data requires explicit commands
    So, with having 2 PBOs, swapping from one to another between each frame, and clearing the current unused while writting to the current used, it lmight result in performance increase. It's very not pretty, but if I understood well the specs, it should work.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,721

    Re: efficiently clear buffers

    So we are missing a functionality to clear buffer objects directly.
    Clearing a buffer object means writing the "clear" value to all of its bytes. Which you can do easily enough with glBufferSubData. There's no need for a special API for this.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    652

    Re: efficiently clear buffers

    Which you can do easily enough with glBufferSubData. There's no need for a special API for this.
    This is like suggesting to use memcpy() instead of memset() to clear memory. Not very efficient, wouldn't you agree?

  9. #9
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Germany
    Posts
    289

    Re: efficiently clear buffers

    Quote Originally Posted by skynet
    Which you can do easily enough with glBufferSubData. There's no need for a special API for this.
    This is like suggesting to use memcpy() instead of memset() to clear memory. Not very efficient, wouldn't you agree?
    That is exactly my point. There are ways, but they are not the most efficient. And clearing a very large buffer using BufferSubData requires either multiple calls or a very large buffer containing the clear values.

    Besides the fact, that we have a way to clear textures using the FBO detour it would be nice to be able to clear textures easier in times of direct write access though shader_image_load_store.

  10. #10
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,721

    Re: efficiently clear buffers

    This is like suggesting to use memcpy() instead of memset() to clear memory. Not very efficient, wouldn't you agree?
    That assumes that there is an equivalent to "memset" in the GPU's hardware. That is, that a driver implementation of "memset" wouldn't simply allocate a block of memory and do a DMA. I don't know why GPUs would need a way to clear buffers to some particular value; it's not like this is a common operation.

    Clearing render targets is a different thing altogether. The format of the data is 100% controlled by the driver. Indeed, the number of ways to change such an object is generally quite small, limited to glDrawPixels and rendering functions (yes, if the render target happens to be a texture, you can use glTex[Sub]Image, but then you're accessing it as a texture, not a render target). Whereas the format of the data in a buffer object is 100% controlled by the user.

    And how exactly would you specify any such buffer clearing operation? Uses of buffers can consider "words" (for the purposes of this conversation, the smallest useful data size) to be anything from one byte to 16 bytes (a GLSL vec4). Or even 64 bytes if your data happens to be matrices. If you want to "clear" a buffer, why shouldn't you be able to clear it to the identity matrix?

    So what would this function look like?

Posting Permissions

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