Atomic Buffer : strange values

Hello there.

I am trying to use atomic buffer, but I have some issues.

I am rendering a cube map with one resolution of 2048 * 2048 (2048 * 2048 * 6 = 25’165’824), so I try to keep the number of fragment performed by fragment shaders with a pre depth pass to optimize the rendering and be sure to don’t have twice time the same pixels performed, and normally, I should get 25 165 824 or smaller, but I got 163 981 519…

Maybe, even if the pre depth pass is performed, few pixels share the same depth value but I think it’s strange…

Thanks to help :-).

Qnoper .

You didn’t explain how you’re rendering to a cubemap. For example, are you using [layered rendering](https://www.opengl.org/wiki/Layered Rendering) or something? You didn’t post your rendering code, so we can’t tell if you are using your pre-pass correctly.

Also, you didn’t post your shader code, so we can’t see if you’ve done things that might impact the recorded value. For example, did you remember to force early-Z tests? Because otherwise, you’ll update the counter even if your depth test fails, since the fragment shader executes before the depth test.

Hello !

I didn’t know the “forcing early-Z tests”, so I have implement it and now it seems to work perfectly, so thank you :-).

Now, I have question about it. I tryed to delete my pre depth pass and use “early-Z tests”, but it seems to be not faster than without pre depth pass.

With pre depth pass, I have to wait 10 ms to render all the scene with lights.
Without, I have to wait 15ms.
And without pre depth pass, but with early-Z tests, I’ve also 15 ms…

This is my code for the pre depth pass and rendering pass :-).

void SceneManager::renderDepthPass()
    {
        //Depth Pass
        global->Model.command->bind(DRAW_INDIRECT);
        global->Model.vaoDepth->bind();
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

            synchronize(); // clear and dispatch
            glMemoryBarrier(GL_COMMAND_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT);
            glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, global->Model.command->numElements(), 0);
    }

    void SceneManager::renderModels()
    {
        // Rendering pass
        global->Model.vao->bind();
        synchronize();
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        glDepthFunc(GL_EQUAL);
        glDepthMask(GL_FALSE);
            glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, global->Model.command->numElements(), 0);
        glDepthFunc(GL_LESS);
        glDepthMask(GL_TRUE);
    }

And when I delete the pre depth pass to use layout(early_fragment_tests) in;

I use this code

void SceneManager::renderModels()
    {
        global->Model.command->bind(DRAW_INDIRECT);

        // Rendering pass
        global->Model.vao->bind();
        synchronize();
            glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, global->Model.command->numElements(), 0);
    }

Synchronize is a function using fencing to wait gpu ^_^.

Thank you so much for your help :-).

Qnoper

Now, I have question about it. I tryed to delete my pre depth pass and use “early-Z tests”, but it seems to be not faster than without pre depth pass.

Why would it be faster?

All turning on early depth tests does is ensure that the depth test is done before the fragment shader. How useful that is depends primarily on the current state of the depth buffer. Without the depth pre-pass to fill in an accurate picture of what pixels are visible, your depth test can’t accurately cull all the pixels out. So if you’ve got some overdraw and render certain things in the wrong order, then you’re going to be drawing the same pixels twice.

Depth pre-pass exists to prevent that. Pre-pass and early-Z are orthogonal.

Okay thanks :).

But if I understand all the things well, it may be better to turn on also early depth? Cause depth test before will be before the fragment computation?

In all cases, thanks for all, you allowed me to understand one thing that I didn’t know