- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直无法将数据发送到SSBO以供计算着色器使用。不幸的是,我和khronos docs say "TODO"无法使它们的示例代码正常工作,并且人们似乎在做些细微的事情Example 1 Example 2 Example 3-有人可以帮忙吗?
(我摘录了我认为不相关的代码的其他部分-but the entire codebase is here。这是到目前为止的内容:
SSBO用一些数据初始化
std::vector<glm::vec4> data = { glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec4(1.0, 0.0, 0.0, 1.0) };
GLuint SSBO;
glGenBuffers(1, &SSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, data.size() * sizeof(glm::vec4), &data[0], GL_DYNAMIC_DRAW);
//the khronos docs put this line in
//glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, SSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
更新循环
s_Data.compute_shader.use();
-- snip: bind a texture --
int ssbo_binding = 1;
int block_index = glGetProgramResourceIndex(s_Data.compute_shader.ID, GL_SHADER_STORAGE_BLOCK, "bufferData");
glShaderStorageBlockBinding(s_Data.compute_shader.ID, block_index, ssbo_binding );
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ssbo_binding, SSBO);
glDispatchCompute( X workers, Y workers, 1);
//Synchronize all writes to the framebuffer image
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
// Reset bindings
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ssbo_binding, 0);
glBindImageTexture(0, 0, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
glUseProgram(0);
-- snip: render output texture to screen --
计算着色器
#version 430 core
layout(binding = 0, rgba16f) uniform image2D outTexture;
layout(std430, binding = 1 ) readonly buffer bufferData
{
vec4 data[];
};
layout (local_size_x = 16, local_size_y = 8) in;
void main(void) {
ivec2 px = ivec2(gl_GlobalInvocationID.xy);
ivec2 size = imageSize(outTexture);
vec3 color;
if(data.length() > 0)
{
//green = data
color = vec3(0.2, 0.6, 0.2);
} else
{
//red = bad
color = vec3(0.6, 0.2, 0.2);
}
imageStore(outTexture, px, vec4(color, 1.0));
}
目前,我的屏幕显示为红色,表示没有数据通过SSBO发送。
最佳答案
我在计算着色器中发现了问题。
.length()返回错误的值。我查询了data [0]和data [1],它们在计算着色器中返回了正确设置的值-因此这就是问题所在(但我不一定有解决方案)
关于c++ - OpenGL为计算着色器设置SSBO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63209756/
我想要一个在输出缓冲区中写入 1 的计算着色器。我编译着色器并将其附加到程序,没有问题,然后调用glDispatchCompute()函数并等待计算着色器结束。但当我看到数组时,只有 0。 谁能告诉我
“着色器存储缓冲区对象”(SSBO)和图像加载存储操作之间有什么区别 什么时候应该使用一个而不是另一个? 它们都可以进行原子操作,我假设它们存储在相同类型的内存中。而且无论它们是否存储在相同类型的内存
我看到这篇文章指出原子计数器缓冲区和 SSBO 中的原子变量之间的性能没有差异: https://software.intel.com/en-us/articles/opengl-performanc
这是OpenGL and loading/reading data in AoSoA (hybrid SoA) format之后的一个问题. 我正在尝试使用着色器存储缓冲区对象 (SSBO) 来存储在
我正在尝试进行一些数据压缩实验。我正在尝试将 3D 纹理压缩到哈希表中以避免存储空的体积信息。 为此,我编写了散列函数和检索函数(它们在不同的着色器中): struct Voxel { int
我从 Khronos wiki 中获取了以下 SSBO 声明: struct ssbo_data_t { int foo; float bar[42]; float baz[M
我目前正在使用 UBO 在 OpenGL 4.3 中进行渲染,以将我所有的常量数据存储在 GPU 上。 (诸如 Material 描述、矩阵等之类的东西)。它可以工作,但是 UBO 的小尺寸(我的实现
我不确定哪种结构布局最适合我的应用程序:共享、打包、std140、std430。我并不是要求对每个信息进行解释,这些信息很容易找到,只是很难弄清楚每个信息对供应商兼容性/性能的影响。如果 shared
我一直在尝试初始化 SSBO 并将其传递给计算着色器。 int ssbo = glGenBuffers(); FloatBuffer buff = BufferUtils.createFloatBuf
在着色器中指定“location = x”来指定着色器存储或统一缓冲区绑定(bind)点时,该数字可以是任何值吗?这个绑定(bind)点是否独立于当前绑定(bind)的着色器? 是否可以在绑定(bin
我有一个名为 sparseMatrix 的 SSBO 以及以下操作顺序: void callerFunc() { func1(); func2(); } /* Clear buffer
几天来,我一直在为计算着色器和缓冲区苦苦挣扎。我查看了它们的多个使用示例,例如“The OpenGL redbook 8th edition”和线程“OpenGL vertices in shader
在我的应用程序中,我添加了两盏灯。一个在 (0,0,2),第二个在 (2,0,0)。这是我得到的(x、y、z 轴分别由红色、绿色和蓝色线表示): 注意只有第一盏灯亮着,第二盏灯没亮。我使我的应用程序核
我有一个 SSBO,它存储屏幕上每个像素的 vec4 颜色值,并在主循环之前由计算着色器预先填充值。 我现在正在尝试在屏幕上获取这些数据,我猜这涉及使用片段着色器(尽管如果您知道更好的方法,我愿意接受
我试图通过一个非常基本的示例来弄清楚 SSBO 是如何工作的。顶点着色器: #version 430 layout(location = 0) in vec2 Vertex; void main()
我在着色器中向 SSBO 写入了一些顶点数据。然后我想将写入 SSBO 的数据用作 VBO。这些将用于下一次绘制调用。如何才能做到这一点? 这是,我现在是怎么做的,但它仍然是段错误: int new_
我有一个只有一个 int 的特殊 SSBO,我需要从着色器和 cpu 读取和写入。 我按如下方式创建了所述 SSBO: glGenBuffers(1, &ssbo); glBindBuffer(GL_
我正在尝试将一组 glm::uvec4 发送到我的 SSBO。有可能还是我应该使用其他方法? 我正在使用实例化绘图并告诉 OpenGL 绘制 X 个实例(取决于可以变化的 glm::uvec4 大小)
我可以同时将单个 opengl 缓冲区绑定(bind)到多个索引目标(SSBO 目标)吗? 例如,假设我的着色器有两个具有不同绑定(bind)索引的不同统一 block 。如果我需要的信息位于同一个缓
在 article on Imagination's website ,我已阅读以下段落: For example, there are no glUniform*() equivalent entr
我是一名优秀的程序员,十分优秀!