GLSL header to force Early-Z

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

GLSL header to force Early-Z

Post 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__
 
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: GLSL header to force Early-Z

Post 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
Post Reply