1
$\begingroup$

I have created a too large buffer with some vertex data (position, normal vector...).

Within the render pipeline, I want to append new data to the end of the currently used buffer. To do this, I thought of binding this buffer as GL_ARRAY_BUFFER and GL_SHADER_STORAGE_BUFFER at the same time.

Within the geometry shader, I only want to modify this buffer after the last vertex information used by this render call. So no input data will be changed.

Is this allowed? Or do I HAVE to create a second separate buffer in which I store the generated data?

$\endgroup$
7
  • $\begingroup$ The only real issue for doing this under opengl is the whether or not opengl is going to being able to figure out the memory barriers. What version of OpenGL are you using? Since OpenGL 4.6 you can issue an explicit memory barrier. $\endgroup$
    – pmw1234
    Commented Mar 7 at 11:35
  • $\begingroup$ Not sure where I came up with 4.6, at any rate look into barriers to help with this. $\endgroup$
    – pmw1234
    Commented Mar 7 at 11:59
  • $\begingroup$ I don't need any barriers, because the memory which will be changed is appart from the input memory (memory index 0 till 10000 is used as vbo input, 10001 till 20000 is used to store new values). I am using the latest openGL version $\endgroup$
    – Thomas
    Commented Mar 7 at 12:52
  • $\begingroup$ I am only interested in knowing if this is allowed... On my GPU it seems to work. But I must been sure, if this is working on other GPUs as well... $\endgroup$
    – Thomas
    Commented Mar 7 at 12:53
  • $\begingroup$ Barriers aren't needed for the write, the question is will the write be done before the next read, the previous frame may still be writing when the frame that needs the data wants to read it. Unless there are no readers which begs the question. $\endgroup$
    – pmw1234
    Commented Mar 7 at 12:59

1 Answer 1

1
$\begingroup$

Buffer sharing like this is a common practice in OpenGL, in Vulkan it is even encouraged. So there should be no spec reason that this isn't allowed.

However there is still a chance that everything looks good on GPU A but on GPU B frames don't render correctly. This can happen if OpenGL doesn't handle the barrier between the two correctly. So one frame is still writing the data while another frame sneaks in and starts reading it.

OpenGL will "probably" get it right, but I would give a long hard look at memory barrier requirements in GL just to make sure.

$\endgroup$
1
  • $\begingroup$ I remember trying to use a buffer both as a vertex buffer in a draw call and as a transform feedback buffer for that draw call (of course, with a target range outside of what was used for rendering) and it certainly didn't work. Now a shader storage buffer mght be more flexible, but I could still imagine the driver not liking you to mess with a buffer that you currently render from, especially since you can't really tell the GL which region of the buffer you actually access when rendering (at least with indexed drawing and without glBindVertexBuffer). $\endgroup$ Commented Apr 11 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.