简体   繁体   English

OpenGL Compute Shader:写入纹理似乎什么也没做

[英]OpenGL Compute Shader: Writing to texture seemingly does nothing

I've found a handful of similar problems posted around the web an it would appear that I'm already doing what the solutions suggest.我在网上发现了一些类似的问题,看起来我已经在按照解决方案的建议进行操作了。

To summarize the problem;总结问题; despite the compute shader running and no errors being present, no change is being made to the texture it's supposedly writing to.尽管计算着色器正在运行并且没有出现错误,但它应该写入的纹理没有发生任何变化。

The compute shader code.计算着色器代码。 It was intended to do something else but for the sake of troubleshooting it simply fills the output texture with ones.它原本打算做其他事情,但为了排除故障,它只是用一个填充输出纹理。

#version 430 core

layout(local_size_x = 4 local_size_y = 4, local_size_z = 4) in;

layout(r32f) uniform readonly  image3D inputDensityField;
layout(r32f) uniform writeonly image3D outputDensityField;

uniform vec4  paintColor;
uniform vec3  paintPoint;
uniform float paintRadius;
uniform float paintDensity;

void main()
{
    ivec3 cellIndex = ivec3(gl_GlobalInvocationID);
    imageStore(outputDensityField, cellIndex, vec4(1.0, 1.0, 1.0, 1.0));
}

I'm binding the textures to the compute shader like so.我像这样将纹理绑定到计算着色器。

s32 uniformID = glGetUniformLocation(programID, name);
u32 bindIndex = 0; // 1 for the other texture.
glUseProgram(programID);
glUniform1i(uniformID, bindIndex);
glUseProgram(0);

The dispatch looks something like this.调度看起来像这样。

glUseProgram(programID);

glBindImageTexture(0, inputTexID,  0, GL_FALSE, 0, GL_READ_ONLY,  GL_R32F);
glBindImageTexture(1, outputTexID, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F);

glDispatchCompute(groupDim.x, groupDim.y, groupDim.z);
glMemoryBarrier(GL_ALL_BARRIER_BITS);

glUseProgram(0);

Inspecting through RenderDoc does not reveal any errors.通过 RenderDoc 检查不会发现任何错误。 The textures seem to have been bound correctly, although they are both displayed in RenderDoc as outputs which I would assume is an error on RenderDoc's part?纹理似乎已正确绑定,尽管它们都在 RenderDoc 中显示为输出,我认为这是 RenderDoc 部分的错误? Whichever texture that was the output on the last glDispatchCompute will later be sampled in a fragment shader.最后一个 glDispatchCompute 输出的纹理将在片段着色器中采样。

Order of operation操作顺序

Listed images列出的图像

The red squares are test fills made with glTexSubImage3D.红色方块是使用 glTexSubImage3D 制作的测试填充。 Again for troubleshooting purposes.再次用于故障排除目的。

I've made sure that I'm passing the correct texture format.我确保我传递了正确的纹理格式。

Example in RenderDoc RenderDoc 中的示例

Additionally I'm using glDebugMessageCallback which usually catches all errors so I would assume that there's no problem with the creation code.此外,我正在使用 glDebugMessageCallback ,它通常会捕获所有错误,所以我假设创建代码没有问题。

Apologies if the information provided is a bit incoherent.抱歉,如果提供的信息有点不连贯。 Showing everything would make a very long post and I'm unsure which parts are the most relevant to show.展示所有内容会写一个很长的帖子,我不确定哪些部分与展示最相关。

I've found a solution!我找到了解决方案! Apparently, in the case of a 3D texture, you need to pass GL_TRUE for layered in glBindImageTexture .显然,在 3D 纹理的情况下,您需要传递 GL_TRUE 以在glBindImageTexture分层

https://www.khronos.org/opengl/wiki/Image_Load_Store https://www.khronos.org/opengl/wiki/Image_Load_Store

Image bindings can be layered or non-layered, which is determined by layered​.图像绑定可以是分层的也可以是非分层的,这由分层决定。 If layered​ is GL_TRUE, then texture​ must be an Array Texture (of some type), a Cubemap Texture, or a 3D Texture.如果 layered​ 是 GL_TRUE,则纹理​必须是数组纹理(某种类型)、立方体贴图纹理或 3D 纹理。 If a layered image is being bound, then the entire mipmap level specified by level​ is bound.如果正在绑定分层图像,则绑定 level​ 指定的整个 mipmap 级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM