'How to copy memory from an SSBO to CPU without getting a buffer performance warning?
I'm using a compute shader to generate terrain values. I create my SSBO, I dispatch the compute shader and then I want to copy the values stored in the SSBO into CPU side memory so that I can use it further on. The code works perfectly, I copy into my CPU side buffer with no issues, however I get a performance warning, which made me think I am not copying the compute shader memory correctly. I get the same issue when using both glGetBufferSubData and glMapBuffer. Here is the warning:
Debug message (131186): Buffer performance warning: Buffer object 1 (bound to GL_SHADER_STORAGE_BUFFER, and GL_SHADER_STORAGE_BUFFER (3), usage hint is GL_STREAM_READ) is being copied/moved from VIDEO memory to HOST memory.
Source: API
Type: Performance
Severity: medium
Here is the offending code
void Terrain::generate()
{
glGenBuffers(1, &mSSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, mSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, (mSize*mSize*mSize)*sizeof(float), mData, GL_STREAM_READ);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mSSBO);
mGenerator.use();
mGenerator.setInt("tSize", mSize);
glDispatchCompute(mSize, mSize, mSize);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
// Line that triggers the warning
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, (mSize*mSize*mSize)*sizeof(float), mData);
}
What is the correct way to copy memory from an SSBO to the CPU without incurring performance penalties + warnings?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
