Name ARB_conservative_depth Name String GL_ARB_conservative_depth Contact Graham Sellers, AMD (graham.sellers 'at' amd.com) Contributors Pierre Boudier, AMD Graham Sellers, AMD Notice Copyright (c) 2011-2013 The Khronos Group Inc. Copyright terms at http://www.khronos.org/registry/speccopyright.html Specification Update Policy Khronos-approved extension specifications are updated in response to issues and bugs prioritized by the Khronos OpenGL Working Group. For extensions which have been promoted to a core Specification, fixes will first appear in the latest version of that core Specification, and will eventually be backported to the extension document. This policy is described in more detail at https://www.khronos.org/registry/OpenGL/docs/update_policy.php Status Complete. Approved by the ARB on 2011/06/20. Approved by the Khronos Promoters on 2011/07/29. Version Last Modified Date: 06/20/2010 Author Revision: 6 Number ARB Extension #111 Dependencies OpenGL 3.0 is required. This extension is written against the OpenGL Shading Language Version 4.00. Overview There is a common optimization for hardware accelerated implementation of OpenGL which relies on an early depth test to be run before the fragment shader so that the shader evaluation can be skipped if the fragment ends up being discarded because it is occluded. This optimization does not affect the final rendering, and is typically possible when the fragment does not change the depth programmatically. (i.e.: it does not write to the built-in gl_FragDepth output). There are, however a class of operations on the depth in the shader which could still be performed while allowing the early depth test to operate. This extension allows the application to pass enough information to the GL implementation to activate such optimizations safely. New Procedures and Functions None. New Tokens None. Additions to the AGL/GLX/WGL Specifications None. Modifications to the OpenGL Shading Language Specification version 1.50.9 Additions to Chapter 1 of the OpenGL Shading Language 4.00.08 Specification (Introduction) None. Additions to Chapter 2 of the OpenGL Shading Language 4.00.08 Specification (Overview of OpenGL Shading) None. Additions to Chapter 3 of the OpenGL Shading Language 4.00.08 Specification (Basics) Add a new Section 3.3.x, GL_ARB_conservative_depth Extension Including the following line in a shader can be used to control the language features described in this extension: #extension GL_ARB_conservative_depth: where is as described in section 3.3. A new preprocessor #define is added to the OpenGL Shading Language: #define GL_ARB_conservative_depth 1 Additions to Chapter 4 of the OpenGL Shading Language 4.00.08 Specification (Variables and Types) Modify Section 4.3.8.2 (Output Layout Qualifiers) page 47 Modify the paragraph beginning: "Fragment shaders allow output layout qualifiers only..." Fragment shaders allow output layout qualifiers only on the interface out, or for the purposes of redeclaring the built-in variable gl_FragDepth (ses Section 7.2, Fragment Shader Special Variables). Insert the following before the paragraph beginning: "Geometry shaders can have three types of output layout qualifiers..." The built-in fragment shader variable gl_FragDepth may be redeclared using one of the following layout qualifiers. layout-qualifier-id depth_any depth_greater depth_less depth_unchanged For example: layout (depth_greater) out float gl_FragDepth; The layout qualifier for gl_FragDepth specifies constraints on the final value of gl_FragDepth written by any shader invocation. GL implementations may perform optimizations assuming that the depth test fails (or passes) for a given fragment if all values of gl_FragDepth consistent with the layout qualifier would fail (or pass). If the final value of gl_FragDepth is inconsistent with its layout qualifier, the result of the depth test for the corresponding fragment is undefined. However, no error will be generated in this case. When the depth test passes and depth writes are enabled, the value written to the depth buffer is always the value of gl_FragDepth, whether or not it is consistent with the layout qualifier. By default, gl_FragDepth assumes the layout qualifier. When the layout qualifier for gl_FragDepth is , the shader compiler will note any assignment to gl_FragDepth modifying it in an unknown way, and depth testing will always be performed after the shader has executed. When the layout qualifier is "depth_greater", the GL will assume that the final value of gl_FragDepth is greater than or equal to the fragment's interpolated depth value, as given by the component of gl_FragCoord. When the layout qualifier is , the GL will assume that any modification of gl_FragDepth will only decrease its value. When the layout qualifier is , the shader compiler will honor any modification to gl_FragDepth, but the rest of the GL assume that gl_FragDepth is not assigned a new value. Redeclarations of gl_FragDepth are performed as follows: // redeclaration that changes nothing is allowed out float gl_FragDepth; // assume it may be modified in any way layout (depth_any) out float gl_FragDepth; // assume it may be modified such that its value will only increase layout (depth_greater) out float gl_FragDepth; // assume it may be modified such that its value will only decrease layout (depth_less) out float gl_FragDepth; // assume it will not be modified layout (depth_unchanged) out float gl_FragDepth; If gl_FragDepth is redeclared in any fragment shader in a program, it must be redeclared in all fragment shaders in that program that have static assignments to gl_FragDepth. All redeclarations of gl_FragDepth in all fragment shaders in a single program must have the same set of qualifiers. Within any shader, the first redeclarations of gl_FragDepth must appear before any use of gl_FragDepth. The built-in gl_FragDepth is only predeclared in fragment shaders, so redeclaring it in any other shader language will be illegal. Revision History Rev. Date Author Changes ---- -------- -------- ----------------------------------------- 6 6/20/2011 wwlk approved by ARB 5 1/27/2011 johnk Update with edits from reviews of the core spec. 4 12/17/2010 johnk Correct gl_Depth -> gl_FragDepth Make the code examples fit within the width of actual paper. 3 04/01/2010 gsellers Minor cleanup. Update to GLSL 4.00. 2 12/01/2009 gsellers Internal updates 1 11/03/2009 pboudier Initial draft