如何在不收到缓冲区性能警告的情况下将内存从 SSBO 复制到 CPU?

How to copy memory from an SSBO to CPU without getting a buffer performance warning?

我正在使用计算着色器生成地形值。我创建了我的 SSBO,我调度了计算着色器,然后我想将存储在 SSBO 中的值复制到 CPU 端内存中,以便我可以进一步使用它。代码完美运行,我复制到我的 CPU 侧缓冲区没有任何问题,但是我收到性能警告,这让我觉得我没有正确复制计算着色器内存。我在同时使用 glGetBufferSubDataglMapBuffer 时遇到同样的问题。这是警告:

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

这是有问题的代码

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);
}

将内存从 SSBO 复制到 CPU 而不会导致性能损失 + 警告的正确方法是什么?

在文档中找出我自己的答案,我已经切换到使用 immutable storage. Instead of using glBufferData I instead am using glBufferStorage

所以

glBufferData(GL_SHADER_STORAGE_BUFFER, (mSize*mSize*mSize)*sizeof(float), mData, GL_STREAM_READ);

变成

glBufferStorage(GL_SHADER_STORAGE_BUFFER, (mSize*mSize*mSize)*sizeof(float), NULL, GL_CLIENT_STORAGE_BIT | GL_MAP_READ_BIT);

我已经给了它明确的标志让我映射它并提示缓冲区存储的实现应该来自客户端内存。现在当我打电话给

glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, (mSize*mSize*mSize)*sizeof(float), mData);

我没有收到任何性能警告