Memory barrier problems for writing and reading an image

Hello, i’m having a problem trying to reading an image from a fragment shader, first i write into the image in shader porgram A (im just painting blue on the image) then i’m reading from another shader program B to display the image, but the reading part is not getting the right color i’m getting this

[ATTACH=CONFIG]1878[/ATTACH]

This is my application code:


    virtual void Start() override
    {
        shader_w = new Shader("w_img.vert", "w_img.frag");
        shader_r = new Shader("r_img.vert", "r_img.frag");

        glCreateTextures(GL_TEXTURE_2D, 1, &space);
        glTextureStorage2D(space, 1, GL_RGBA32F, 512, 512);
        glBindImageTexture(0, space, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

        glCreateVertexArrays(1, &vertex_array);
        glBindVertexArray(vertex_array);
    }

    virtual void Update() override
    {
        shader_w->use(); // writing shader
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

        glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

        shader_r->use(); // reading shader
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    }

    virtual void End() override
    {
        delete shader_w;
        delete shader_r;
        
        glDeleteTextures(1, &space);

        glDeleteVertexArrays(1, &vertex_array);
    }

and these are my fragment shaders:

// Writing to image


#version 450 core

layout (binding = 0, rgba32f) uniform image2D img;

out vec4 out_color;

void main()
{
        imageStore(img, ivec2(gl_FragCoord.xy), vec4(0.0f, 0.0f, 1.0f, 1.0f));
        memoryBarrier();
}

// Reading from image


#version 450 core

layout (binding = 0, rgba32f) uniform image2D img;

out vec4 out_color;

void main()
{
        vec4 color = imageLoad(img, ivec2(gl_FragCoord.xy));
        memoryBarrier();
        out_color = color;
}

The only way that i get the correct result is if i change the order of the drawing commands and i dont need the memory barriers, like this

// in the Update fuction of above


shader_r->use(); // reading shader
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

shader_w->use(); // writing shader
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Are you Checking for GL errors?

If none, which GPU and drivers?

I already modified the code, just added a callback for error checking:


void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{
    std::cout << "GL CALLBACK: type = " << std::hex << type << ", severity = " << std::hex << severity << ", message = " << message << "
"
    << (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "") << std::endl;
}

virtual void Start() override
{
    glEnable(GL_DEBUG_OUTPUT); // This is the new part
    glDebugMessageCallback(MessageCallback, nullptr); // and this

    shader_w = new Shader("w_img.vert", "w_img.frag");
    shader_r = new Shader("r_img.vert", "r_img.frag");

    glGenTextures(1, &space);
    glBindTexture(GL_TEXTURE_2D, space);
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 512, 512);
    glBindImageTexture(0, space, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

    glGenVertexArrays(1, &vertex_array);
    glBindVertexArray(vertex_array);
}

and there were no errors, but then i checked the drivers and my OS was using the intel graphics card so i changed to the NVIDIA card and the version of the driver is 384.130 with OpenGL 430 so i change the code a little bit as you can see above in the creation of the texture 2D and the VAO (i was using glCreate* of OpenGL 450 and now is glGen* of OpenGL 430). I tested the program but the result is not the blue color , but now, instead of the noisy image that i got, i get a black image, like this:

[ATTACH=CONFIG]1879[/ATTACH]

[QUOTE=Dark Photon;1292834]Are you Checking for GL errors?

If none, which GPU and drivers?[/QUOTE]

Sorry i put my reply below of your reply, can you check my doubt please??

[QUOTE=jacob6;1292836]i changed to the NVIDIA card and the version of the driver is 384.130 with OpenGL 430
so i change the code a little bit …
I tested the program but the result is not the blue color , but now, instead of the noisy image that i got, i get a black image[/QUOTE]

That’s interesting. Consider posting a short, standalone test program that illustrates the problem so we can see exactly what you’re doing and try it locally.

I solved it, well some one helped me, i forgot to turn off the depth test or use a color mask to stop render the first plane in my image writing shader. Thanks anyway!