Reputation: 481
I'm using an atomic counter which has it's own buffer and i want to clear that counter in some other pass. So is it good to bind the buffer as shader storage buffer to clear it and then, in a second pass use it as atomic counter buffer? Also i would like to ask if it's even ok to use the same buffer as shader storage buffer and as atomic counter buffer at the same time in the same shader, let's say, 4 bytes at the start are intended only for the atomic counter, while in the same buffer is other data which is read/modified.
Upvotes: 3
Views: 488
Reputation: 733
You can use the same buffer with different targets, but you have to manage alignment requirements yourself (All params for glGet
with ALIGNMENT
in their names).
Then you can invalidate a range with InvalidateBufferSubData
as a performance hint (the GPU doesn't have to preserve content you will clear) and clear the range with ClearBufferSubData
.
For better performance I would advise using double or triple buffering for the atomic counters, or any data that are often cleared or updated.
Upvotes: 2