如何正确设置 SSBO 的提示以从着色器和 cpu 读取和写入?
How to properly set the hint of an SSBO to read and write from both shaders and cpu?
我有一个只有一个 int 的特殊 SSBO,我需要从着色器和 cpu 读取和写入。
我创建的 SSBO 如下:
glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glObjectLabel(GL_BUFFER, ssbo, -1, ("\"SSBO\""));
GLint zero = 0;
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLint), &zero, GL_STATIC_COPY);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);
当我渲染时,glDbeugMessage returns 具有:
OpenGL Event Notification:
Source: GL_DEBUG_SOURCE_API
Type: GL_DEBUG_TYPE_PERFORMANCE
ID: Unkown error code: 131186
Severity: GL_DEBUG_SEVERITY_MEDIUM
Message:
Buffer performance warning: Buffer object "SSBO" (bound to
GL_SHADER_STORAGE_BUFFER, and GL_SHADER_STORAGE_BUFFER (3), usage hint is
GL_DYNAMIC_DRAW) is being copied/moved from VIDEO memory to HOST memory.
这个警告中最重要的是它说 SSBO 有提示:GL_DYNAMIC_DRAW
尽管我试图将提示设置为:GL_STATIC_COPY
所以我的问题是,我应该使用什么提示来防止 OpenGL 警告,以及我如何实际强制使用该提示?
I have a peculiar SSBO with only an int, that I need to read and write from both the shaders and the cpu.
GL_STATIC_COPY
不是这个意思。这意味着您只需分配它并写入一次(STATIC 部分)。这意味着它只会通过 GPU 操作被读取 from/written; CPU 永远不会直接操作数据(COPY 部分)。
所以你使用了错误的提示。
what hint should I use to prevent the OpenGL warning
如果您关心这类事情,那么您需要使用 immutable buffer allocation,而不是旧式的 glBufferData
东西。 "Hints" 不是绑定;这就是为什么他们是 "hints" 而不是 "requirements".
glBufferStorage
提出 要求 。具体来说,它对您对内存的使用提出了要求。如果您不声明可以映射缓冲区以供读取,那么您不能 将其映射为读取。如果您不声明可以通过 glBufferSubData
写入,那么您 不能 。曾经。
选择您需要的最低使用要求集,并在这些限制范围内工作。
我有一个只有一个 int 的特殊 SSBO,我需要从着色器和 cpu 读取和写入。
我创建的 SSBO 如下:
glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glObjectLabel(GL_BUFFER, ssbo, -1, ("\"SSBO\""));
GLint zero = 0;
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLint), &zero, GL_STATIC_COPY);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);
当我渲染时,glDbeugMessage returns 具有:
OpenGL Event Notification:
Source: GL_DEBUG_SOURCE_API
Type: GL_DEBUG_TYPE_PERFORMANCE
ID: Unkown error code: 131186
Severity: GL_DEBUG_SEVERITY_MEDIUM
Message:
Buffer performance warning: Buffer object "SSBO" (bound to
GL_SHADER_STORAGE_BUFFER, and GL_SHADER_STORAGE_BUFFER (3), usage hint is
GL_DYNAMIC_DRAW) is being copied/moved from VIDEO memory to HOST memory.
这个警告中最重要的是它说 SSBO 有提示:GL_DYNAMIC_DRAW
尽管我试图将提示设置为:GL_STATIC_COPY
所以我的问题是,我应该使用什么提示来防止 OpenGL 警告,以及我如何实际强制使用该提示?
I have a peculiar SSBO with only an int, that I need to read and write from both the shaders and the cpu.
GL_STATIC_COPY
不是这个意思。这意味着您只需分配它并写入一次(STATIC 部分)。这意味着它只会通过 GPU 操作被读取 from/written; CPU 永远不会直接操作数据(COPY 部分)。
所以你使用了错误的提示。
what hint should I use to prevent the OpenGL warning
如果您关心这类事情,那么您需要使用 immutable buffer allocation,而不是旧式的 glBufferData
东西。 "Hints" 不是绑定;这就是为什么他们是 "hints" 而不是 "requirements".
glBufferStorage
提出 要求 。具体来说,它对您对内存的使用提出了要求。如果您不声明可以映射缓冲区以供读取,那么您不能 将其映射为读取。如果您不声明可以通过 glBufferSubData
写入,那么您 不能 。曾经。
选择您需要的最低使用要求集,并在这些限制范围内工作。