简体   繁体   中英

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. 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? Whichever texture that was the output on the last glDispatchCompute will later be sampled in a fragment shader.

Order of operation

Listed images

The red squares are test fills made with glTexSubImage3D. Again for troubleshooting purposes.

I've made sure that I'm passing the correct texture format.

Example in RenderDoc

Additionally I'm using glDebugMessageCallback which usually catches all errors so I would assume that there's no problem with the creation code.

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 .

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. If a layered image is being bound, then the entire mipmap level specified by level​ is bound.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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