Behemyth
Behemyth

Reputation: 305

Copying a SSBO Into Another SSBO

It recently came to my attention that glCopyBufferSubData is not applicable to Shader Storage Buffer Objects as the extension excludes mention of it. To make sure, I tested this by printing out the mapped buffers and the new SSBO contained repetitive nonsense showing that this was the case. Without having to create a custom compute shader to do this, is there any way to copy the data on the GPU from a command issued from the CPU similar to what glCopyBufferSubData would do for other buffer types?

Upvotes: 0

Views: 1074

Answers (1)

Christian Rau
Christian Rau

Reputation: 45948

The function glCopyBufferSubData works on buffer objects. A buffer object in itself is nothing special, all buffer objects are the same. Only when binding a buffer object as a shader storage buffer it is used as a shader storage buffer. But if not used as a shader storage buffer, it is just a plain buffer object. So your assumption that glCopyBufferSubData doesn't work on shader storage buffers is plain wrong, it works on buffers, no matter for what you use those buffers later on. The only reason the extension doesn't mention SSBOs is, that SSBOs didn't exist when the copy_buffer extension was introduced, but this functionality is completely orthogonal to SSBOs.

The reason it doesn't work for you is to be searched elsewhere. Maybe you can't use GL_SHADER_STORAGE_BUFFER as a valid target for glCopyBufferSubData, but that isn't required anyway, just bind the buffer to another target, e.g. GL_COPY_READ_BUFFER or GL_COPY_WRITE_BUFFER. Another error source might be that writes from a shader into an SSBO are not necessarily synchronized with following read operations and you might need an additional glMemoryBarrier if copying the data right after computing it.

But to make it clear, glCopyBufferSubData works on any kind of buffer and the target you bind a buffer to is absolutely not tied to the buffer object and its data itself. You can perfectly use an SSBO to compute some data into and then render it as a VBO and so on.

Upvotes: 3

Related Questions