Page 1 of 1

GLSL header to force Early-Z

Posted: Sat May 27, 2017 8:05 am
by devsh
You put this after your "#version 400" or other declaration at the very top of the fragment shader

Code: Select all

 
#extension GL_ARB_conservative_depth: require
 
#if __VERSION__>=420
layout(early_fragment_tests) in;
#else
    #extension GL_ARB_shader_image_load_store: enable
 
    #ifdef GL_ARB_shader_image_load_store
        layout(early_fragment_tests) in;
    #else
        #extension GL_EXT_shader_image_load_store: enable
 
        #ifdef GL_EXT_shader_image_load_store
            layout(early_fragment_tests) in;
        #else
            layout (depth_unchanged) out float gl_FragDepth;
        #endif // GL_EXT_shader_image_load_store
    #endif // GL_ARB_shader_image_load_store
#endif // __VERSION__
 
if you're tagetting lower than GL 4.0, (same rule about positioning at the top of the file and just after version).

Code: Select all

 
#if __VERSION__>=420
layout(early_fragment_tests) in;
#else
    #extension GL_ARB_shader_image_load_store: enable
 
    #ifdef GL_ARB_shader_image_load_store
        layout(early_fragment_tests) in;
    #else
        #extension GL_EXT_shader_image_load_store: enable
 
        #ifdef GL_EXT_shader_image_load_store
            layout(early_fragment_tests) in;
        #else
            #extension GL_ARB_conservative_depth: enable
            
            #ifdef GL_ARB_conservative_depth
                layout (depth_unchanged) out float gl_FragDepth;
            #endif // GL_ARB_conservative_depth
        #endif // GL_EXT_shader_image_load_store
    #endif // GL_ARB_shader_image_load_store
#endif // __VERSION__
 

Re: GLSL header to force Early-Z

Posted: Mon Feb 05, 2018 6:50 pm
by devsh
I wrote a compendium of corner-cases for Hi-Z and Early-Z covering almost all common combinations of Depth/Stencil Function/Mask settings which may gently caress-up the performance of your displacement-mapping shaders.
https://github.com/buildaworldnet/Irrli ... benchmarks