1Name 2 3 NV_texture_barrier 4 5Name Strings 6 7 GL_NV_texture_barrier 8 9Contact 10 11 Jeff Bolz, NVIDIA Corporation (jbolz 'at' nvidia.com) 12 13Contributors 14 15 Mark Kilgard, NVIDIA 16 Shazia Rahman, NVIDIA 17 18Status 19 20 Shipping (August 2009, Release 190) 21 22Version 23 24 Last Modified Date: September 29, 2016 25 NVIDIA Revision: 4 26 27Number 28 29 OpenGL Extension #381 30 OpenGL ES Extension #271 31 32Dependencies 33 34 This extension is written against the OpenGL 3.0 specification. 35 36 Also written based on the wording of the OpenGL ES 3.2 specification. 37 38Overview 39 40 This extension relaxes the restrictions on rendering to a currently 41 bound texture and provides a mechanism to avoid read-after-write 42 hazards. 43 44New Procedures and Functions 45 46 void TextureBarrierNV(void); 47 48New Tokens 49 50 None. 51 52Additions to Chapter 2 of the OpenGL 3.0 Specification (OpenGL Operation) 53 54 None. 55 56Additions to Chapter 3 of the OpenGL 3.0 Specification (Rasterization) 57 58 None. 59 60Additions to Chapter 4 of the OpenGL 3.0 Specification (Per-Fragment 61Operations and the Frame Buffer) 62 63 Modify Section 4.4.3, Rendering When an Image of a Bound Texture Object 64 is Also Attached to the Framebuffer, p. 288 65 66 (Replace the complicated set of conditions with the following) 67 68 Specifically, the values of rendered fragments are undefined if any 69 shader stage fetches texels and the same texels are written via fragment 70 shader outputs, even if the reads and writes are not in the same Draw 71 call, unless any of the following exceptions apply: 72 73 - The reads and writes are from/to disjoint sets of texels (after 74 accounting for texture filtering rules). 75 76 - There is only a single read and write of each texel, and the read is in 77 the fragment shader invocation that writes the same texel (e.g. using 78 "texelFetch2D(sampler, ivec2(gl_FragCoord.xy), 0);"). 79 80 - If a texel has been written, then in order to safely read the result 81 a texel fetch must be in a subsequent Draw separated by the command 82 83 void TextureBarrierNV(void); 84 85 TextureBarrierNV() will guarantee that writes have completed and caches 86 have been invalidated before subsequent Draws are executed. 87 88Additions to Chapter 5 of the OpenGL 3.0 Specification (Special Functions) 89 90 None. 91 92Additions to Chapter 6 of the OpenGL 3.0 Specification (State and 93State Requests) 94 95 None. 96 97Additions to the AGL/GLX/WGL Specifications 98 99 None 100 101Additions to Chapter 9 of the OpenGL ES 3.2 Specification (Framebuffers 102and Framebuffer Objects) 103 104 Modify section 9.3.1, Rendering Feedback Loops: 105 106 (Replace the complicated 2nd and 3rd paragraphs 107 "Specifically... ...only be executed conditionally." with the 108 following) 109 110 Specifically, the values of rendered fragments are undefined if any 111 shader stage fetches texels and the same texels are written via fragment 112 shader outputs, even if the reads and writes are not in the same Draw 113 call, unless any of the following exceptions apply: 114 115 - The reads and writes are from/to disjoint sets of texels (after 116 accounting for texture filtering rules). 117 118 - There is only a single read and write of each texel, and the read is in 119 the fragment shader invocation that writes the same texel (e.g. using 120 "texelFetch2D(sampler, ivec2(gl_FragCoord.xy), 0);"). 121 122 - If a texel has been written, then in order to safely read the result 123 a texel fetch must be in a subsequent Draw separated by the command 124 125 void TextureBarrierNV(void); 126 127 TextureBarrierNV() will guarantee that writes have completed and caches 128 have been invalidated before subsequent Draws are executed. 129 130Errors 131 132New State 133 134 None. 135 136New Implementation Dependent State 137 138 None. 139 140GLX Protocol 141 142 The following rendering command is sent to the server as 143 a glXRender request: 144 145 TextureBarrierNV 146 147 2 4 rendering command length 148 2 4348 rendering command opcode 149 150Issues 151 152 (1) What algorithms can take advantage of TextureBarrierNV? 153 154 This can be used to accomplish a limited form of programmable blending 155 for applications where a single Draw call does not self-intersect, by 156 binding the same texture as both render target and texture and applying 157 blending operations in the fragment shader. Additionally, bounding-box 158 optimizations can be used to minimize the number of TextureBarrierNV 159 calls between Draws. For example: 160 161 dirtybbox.empty(); 162 foreach (object in scene) { 163 if (dirtybbox.intersects(object.bbox())) { 164 TextureBarrierNV(); 165 dirtybbox.empty(); 166 } 167 object.draw(); 168 dirtybbox = bound(dirtybbox, object.bbox()); 169 } 170 171 Another application is to render-to-texture algorithms that ping-pong 172 between two textures, using the result of one rendering pass as the input 173 to the next. Existing mechanisms require expensive FBO Binds, DrawBuffer 174 changes, or FBO attachment changes to safely swap the render target and 175 texture. With texture barriers, layered geometry shader rendering, and 176 texture arrays, an application can very cheaply ping-pong between two 177 layers of a single texture. i.e. 178 179 X = 0; 180 // Bind the array texture to a texture unit 181 // Attach the array texture to an FBO using FramebufferTexture3D 182 while (!done) { 183 // Stuff X in a constant, vertex attrib, etc. 184 Draw - 185 Texturing from layer X; 186 Writing gl_Layer = 1 - X in the geometry shader; 187 188 TextureBarrierNV(); 189 X = 1 - X; 190 } 191 192 However, be warned that this requires geometry shaders and hence adds 193 the overhead that all geometry must pass through an additional program 194 stage, so an application using large amounts of geometry could become 195 geometry-limited or more shader-limited. 196 197 (2) Does this support OpenGL ES? 198 199 RESOLVED: Yes. ES specification language has been added, written 200 against the OpenGL 3.2 specification. The added language is 201 identical to the regular OpenGL language. 202 203 As this specification has no dependencies other than assuming 204 framebuffer objects, this extension could support any version of ES 205 from 2.0 up. However the texelFetch operation for fetching from a 206 texture is introduced by OpenGL ES 3.0's GLSL or the NV_gpu_shader4 207 extension. 208 209Revision History 210 211 Rev. Date Author Changes 212 ---- -------- -------- ----------------------------------------- 213 1 jbolz Initial revision. 214 2 mjk Assign number. 215 3 srahman Add glx protocol specification. 216 4 9/29/16 mjk Add ES support 217