Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: ClearBufferData + shader_buffer_store

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    7

    ClearBufferData + shader_buffer_store

    Hi,

    I do not understand the behavior of ClearBufferData in my OpenGL 4.3 application. Basically, it seems that clearing a buffer with ClearBufferData then writing into it in shaders causes the buffer to always be empty after the shaders execute.

    Specifically, my application does the following:

    1. ClearBufferData of myBuffer
    2. Make myBuffer resident on the GPU and set it as a uniform in shaders
    3. a. Enable shaders
    3. b. Draw stuff with shaders (each fragment shader writes into myBuffer)
    3. c. Disable shaders
    4. Make myBuffer non resident

    After #4 myBuffer contains all 0's. However, if I do not clear myBuffer (remove #1) then its contents is written by the shaders as I would expect. I've tried putting a Finish() call between the clear and draw, but it has no effect. What is going on here? I'd appreciate any explanation.

    Thanks!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    First, if all you're doing is writing to the buffer, there's no point in clearing it beforehand; you'll just overwrite the cleared data.

    Second, I don't see the part where you put a glMemoryBarrierEXT(GL_SHADER_GLOBAL_ACCESS_BARRIER _BIT_NV) between the clear and the part where you write to it. Without that barrier, OpenGL will not synchronize memory accesses. Also, you need a barrier between when you write the data in your shader and when you read it to ensure that it becomes visible.

Posting Permissions

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