1Name 2 3 NV_stereo_view_rendering 4 5Name Strings 6 7 GL_NV_stereo_view_rendering 8 9Contact 10 11 Kedarnath Thangudu, NVIDIA Corporation (kthangudu 'at' nvidia.com) 12 13Contributors 14 15 Mark Kilgard, NVIDIA Corporation 16 Pat Brown, NVIDIA Corporation 17 Jason Schmidt, NVIDIA Corporation 18 19Status 20 21 Shipping in NVIDIA release 367.XX drivers and up. 22 23Version 24 25 Last Modified Date: November 25, 2017 26 NVIDIA Revision: 3 27 28Number 29 30 OpenGL Extension #489 31 OpenGL ES Extension #296 32 33Dependencies 34 35 This extension is written against OpenGL 4.5 Specification 36 (Compatibility Profile). 37 38 This extension interacts with the OpenGL ES 3.1 Specification. 39 40 The extension requires NV_viewport_array2. 41 42 This extension interacts with NV_gpu_program4 and NV_gpu_program5. 43 44 This extension interacts with EXT_tessellation_shader. 45 46Overview 47 48 Virtual reality (VR) applications often render a single logical scene 49 from multiple views corresponding to a pair of eyes. The views (eyes) are 50 separated by a fixed offset in the X direction. 51 52 Traditionally, multiple views are rendered via multiple rendering passes. 53 This is expensive for the GPU because the objects in the scene must be 54 transformed, rasterized, shaded, and fragment processed redundantly. This 55 is expensive for the CPU because the scene graph needs to be visited 56 multiple times and driver validation happens for each view. Rendering N 57 passes tends to take N times longer than a single pass. 58 59 This extension provides a mechanism to render binocular (stereo) views 60 from a single stream of OpenGL rendering commands. Vertex, tessellation, 61 and geometry (VTG) shaders can output two positions for each vertex 62 corresponding to the two eye views. A built-in "gl_SecondaryPositionNV" 63 is added to specify the second position. The positions from each view may 64 be sent to different viewports and/or layers. A built-in 65 "gl_SecondaryViewportMaskNV[]" is also added to specify the viewport mask 66 for the second view. A new layout-qualifier "secondary_view_offset" is 67 added for built-in output "gl_Layer" which allows for the geometry from 68 each view to be sent to different layers for rendering. 69 70New Procedures and Functions 71 72 None. 73 74New Tokens 75 76 None. 77 78Additions to Chapter 11 of the OpenGL 4.5 (Compatibility Profile) Specification 79(Programmable Vertex Processing) 80 81 Add to Section 11.1.3.10 (Shader Outputs) 82 83 The built-in output variables gl_SecondaryPositionNV and 84 gl_SecondaryViewportMaskNV[] hold the homogeneous vertex position and the 85 viewport mask for the secondary view, as described in Section 11.5 86 (Stereo Offsetted Rendering). 87 88 [Section 11.2 of the OpenGL 4.5 specification corresponds to 89 Section 11.1ts of the OpenGL ES 3.1 specification, and 90 Section 11.3 of the OpenGL 4.5 specification corresponds to 91 Section 11.1gs of the OpenGL ES 3.1 specification] 92 93 In Section 11.2.1.2.2 (Tessellation Control Shader Inputs), modify the 94 line describing members of gl_in[] to include gl_SecondaryPositionNV 95 96 The members of each element of the gl_in[] array are gl_Position, 97 gl_SecondaryPositionNV, gl_PointSize, ... 98 99 Add to Section 11.2.1.2.3 (Tessellation Control Shader Outputs) 100 101 The built-in output variables gl_SecondaryPositionNV and 102 gl_SecondaryViewportMaskNV[] hold the homogeneous vertex position and the 103 viewport mask for the secondary view, as described in Section 11.5 104 (Stereo Offsetted Rendering). 105 106 In Section 11.2.3.3 (Tessellation Evaluation Shader Outputs), modify the 107 line describing members of gl_in[] to include gl_SecondaryPositionNV 108 109 The members of each element of the gl_in[] array are gl_Position, 110 gl_SecondaryPositionNV, gl_PointSize, ... 111 112 Add to Section 11.2.3.4 (Tessellation Evaluation Shader Outputs) 113 114 The built-in output variables gl_SecondaryPositionNV and 115 gl_SecondaryViewportMaskNV[] hold the homogeneous vertex position and the 116 viewport mask for the secondary view, as described in Section 11.5 117 (Stereo Offsetted Rendering). 118 119 In Section 11.3.4.4 (Geometry Shader Inputs), add to the list of members 120 of gl_in[] 121 122 The members of each element of the gl_in[] array are: 123 ... 124 * Structure member gl_SecondaryPositionNV holds the per-vertex position 125 of the secondary view, written by the upstream shader to the built-in 126 output variable gl_SecondaryPositionNV. Note that writing to 127 gl_SecondaryPositionNV from either the upstream or geometry shader is 128 optional (also see section 7.1("Built-In Variables") of the OpenGL 129 Shading Language Specification). 130 131 Add to Section 11.2.3.5 (Geometry Shader Outputs) 132 133 The built-in output variables gl_SecondaryPositionNV and 134 gl_SecondaryViewportMaskNV[] hold the homogeneous vertex position and the 135 viewport mask for the secondary view, as described in Section 11.5 136 (Stereo Offsetted Rendering). 137 138 139 Modify Section 11.4 (Layer and Viewport Selection) to include 140 gl_SecondaryViewportMaskNV[] wherever gl_ViewportMask[] is mentioned. 141 142 Add a new Section 11.5 (Stereo Offsetted Rendering) 143 144 Application may render a single logical scene from two views, 145 corresponding to a pair of eyes, that are separated only in the X 146 direction by fixed offset. Vertex, tessellation, and geometry (VTG) 147 shaders may compute and write the vertex coordinates for each of the pair 148 of stereo views. The input/output built-ins "gl_Position" and 149 "gl_SecondaryPositionNV" may be used to read/write the positions 150 corresponding to the primary and secondary views respectively. Only the 151 "x" coordinate is expected to differ between these views, so the "yzw" 152 coordinates for secondary position are also obtained from the "gl_Position" 153 and writes to "gl_SecondaryPositionNV.yzw" are ignored. 154 155 VTG shaders may also write to "gl_SecondaryViewportMaskNV[]" to specify a 156 viewport mask for primitives in the secondary view. If 157 "gl_SecondaryViewportMaskNV[]" is not specified, "gl_ViewportMask[]" will 158 be used as the viewport mask for primitives from both views. 159 160 Primitives from each view may be sent to different layers as described 161 in Section 7.1 of the GLSL specification. 162 163Additions to Chapter 13 of the OpenGL 4.5 (Compatibility Profile) 164Specification (Fixed-Function Vertex Post-Processing) 165 166 Modify Section 13.2 (Transform Feedback), p. 453 [section 12.1 in OpenGL ES] 167 168 Modify the first paragraph: 169 170 ...The vertices are fed back after vertex color clamping, but before 171 viewport mask expansion, stereo view expansion, flat-shading, and 172 clipping. ... 173 174 Modify Section 13.6.1 (Controlling the Viewport) 175 [section 12.5.1 in OpenGL ES] to include 176 gl_SecondaryViewportMaskNV[] wherever gl_ViewportMask[] is mentioned. 177 178 179New Implementation Dependent State 180 181 None. 182 183New State 184 185 None. 186 187Additions to the AGL/GLX/WGL/EGL Specifications 188 189 None. 190 191GLX Protocol 192 193 None. 194 195Modifications to the OpenGL Shading Language Specification, Version 4.50 196 197 Including the following line in a shader can be used to control the 198 language features described in this extension: 199 200 #extension GL_NV_stereo_view_rendering : <behavior> 201 202 where <behavior> is as specified in section 3.3 203 204 New preprocessor #defines are added to the OpenGL Shading Language: 205 206 #define GL_NV_stereo_view_rendering 1 207 208 Modify Section 7.1 (Built-In Language Variables), p. 118 209 210 Add to the list of vertex shader built-ins: 211 212 out gl_PerVertex { 213 highp vec4 gl_SecondaryPositionNV; 214 highp int gl_SecondaryViewportMaskNV[]; 215 }; 216 217 Add to the list of geometry shader built-ins: 218 219 in gl_PerVertex { 220 highp vec4 gl_SecondaryPositionNV; 221 } gl_in[]; 222 223 out gl_PerVertex { 224 highp vec4 gl_SecondaryPositionNV; 225 highp int gl_SecondaryViewportMaskNV[]; 226 }; 227 228 Add to the list of tessellation control shader built-ins: 229 230 in gl_PerVertex { 231 highp vec4 gl_SecondaryPositionNV; 232 } gl_in[gl_MaxPatchVertices]; 233 234 out gl_PerVertex { 235 highp vec4 gl_SecondaryPositionNV; 236 highp int gl_SecondaryViewportMaskNV[]; 237 } gl_out[]; 238 239 Add to the list of tessellation evaluation shader built-ins: 240 241 in gl_PerVertex { 242 highp vec4 gl_SecondaryPositionNV; 243 } gl_in[gl_MaxPatchVertices]; 244 245 out gl_PerVertex { 246 highp vec4 gl_SecondaryPositionNV; 247 highp int gl_SecondaryViewportMaskNV[]; 248 }; 249 250 Add the following descriptions for gl_SecondaryPositionNV and 251 gl_SecondaryViewportMaskNV[]: 252 253 The output variables gl_SecondaryPositionNV and gl_SecondaryViewportMaskNV[] 254 are available in vertex, tessellation, and geometry languages to specify 255 the position and the viewport mask for the secondary view respectively. 256 The input variable gl_SecondaryPositionNV is available in the tessellation 257 and geometry languages to read the secondary position written by a 258 previous shader stage. See section 11.5 ("Stereo Offsetted Rendering") of 259 the OpenGL 4.5 specification for more information. 260 261 262 Add the following to the description of gl_Layer 263 264 The shader output gl_Layer may be redeclared with the following layout 265 qualifier which is available in vertex, tessellation, and geometry 266 shaders: 267 268 layout-qualifier-id 269 secondary_view_offset = integer-constant-expression 270 271 along with the <viewport-relative> layout qualifier introduced in 272 NV_viewport_array2. When using layered rendering, the layout qualifier 273 <secondary_view_offset> may be used to indicate the layer offset for the 274 primitives in the second view. If gl_Layer is redeclared with both 275 <viewport_relative> and <secondary_view_offset>, the layer used for 276 rendering the primitives of the second view is computed by first adding 277 the viewport index and then the offset value specified by 278 <secondary_view_offset>. 279 280 281Errors 282 283 None. 284 285Interactions with EXT_tessellation_shader 286 287 If implemented on OpenGL ES and EXT_tessellation_shader is not supported, 288 remove all language referring to the tessellation control and tessellation 289 evaluation pipeline stages. 290 291Interactions with NV_gpu_program4 and NV_gpu_program5 292 293 If NV_gpu_program4 is supported and the "NV_stereo_view_rendering" program 294 option is specified, vertex, tessellation control/evaluation, and geometry 295 program result variable "result.secondaryposition" can be used to specify 296 the vertex's position coordinates from the second view and 297 "result.secondaryviewportmask[]" can be used to specify the mask of 298 viewports that the primitives from the second view will be emitted to. When 299 this program option is specified in tessellation control/evaluation, and/or 300 geometry programs, a vertex attribute "vertex[m].secondaryposition" is also 301 available to read the secondary position computed in a previous shader 302 stage. 303 304 Modify Section 2.X.2 of NV_gpu_program4, Program Grammar 305 306 (add the following rule to the NV_gpu_program4 grammar for Geometry and 307 Tessellation Control/Eval programs) 308 309 <attribBasic> ::= ... 310 | <vtxPrefix> "secondaryposition" 311 312 (add the following rule to the NV_gpu_program4 grammar for Vertex, 313 Geometry, and Tessellation Control/Eval programs) 314 315 <declaration> ::= ... 316 | "SECONDARY_VIEW_LAYER_OFFSET" <optSign> <int> 317 318 <resultBasic> ::= ... 319 | <resPrefix> "secondaryposition" 320 | <resPrefix> "secondaryviewportmask" arrayMemAbs 321 322 (add the following to the tables of Geometry and Tessellation 323 Control/Eval Program Attribute Bindings) 324 325 Binding Components Description 326 --------------------------- ---------- --------------------------- 327 vertex[m].secondaryposition (x,y,z,w) object coordinates for the 328 second view 329 330 (add the following subsection to section 2.X.3.2 of NV_gpu_program4, 331 Program Attribute Variables) 332 333 If an attribute binding in a geometry/tessellation program matches 334 "vertex[m].secondaryposition", the "x" component of the attribute provides 335 the "x" coordinate for the secondary view position. The "y", "z", and "w" 336 components will be the same as the "y", "z", and "w" components of 337 "vertex[m].position". 338 339 340 (add the following to the tables of Vertex, Geometry, and Tessellation 341 Control/Eval Program Result Variable Bindings) 342 343 Binding Components Description 344 ----------------------------- ---------- ---------------------------- 345 result.secondaryposition (x,y,z,w) object coordinates for the 346 second view 347 result.secondaryviewportmask[] (v,-,-,-) viewport array mask for the 348 second view 349 350 (add the following subsection to section 2.X.3.5 of NV_gpu_program4, 351 Program Results.) 352 353 If a result variable binding matches "result.secondaryposition", updates 354 to the "x" component of the result variable provide the "x" coordinate for 355 the position from the secondary view. The y, z, and w coordinates for the 356 secondary view position are expected to be the same as the primary 357 position and are taken from the "result.position". Updates to y, z, and w 358 components of "result.secondaryposition" are ignored. 359 360 If a result variable binding matches "result.secondaryviewportmask[]", 361 updates to the "x" component of the result variable provide a single 362 integer that serves as a mask of viewport indices for the secondary 363 view. The mask must be written as an integer value; writing a floating- 364 point value will produce undefined results. If the value has bits greater 365 than or equal to MAX_VIEWPORTS set, the number of viewports the primitive 366 is emitted to and which viewports are used undefined. If a program 367 specifies "NV_stereo_view_rendering" program option and does not write the 368 "result.secondaryviewportmask[]", then "result.viewportmask[]" will be 369 used as the viewport mask for both the views. 370 371 If the "NV_stereo_view_rendering" program option is not specified, the 372 "result.secondaryposition" and "result.secondaryviewportmask[]" bindings 373 are unavailable. 374 375 (add the following to Section 2.X.6.Y, Program Options) 376 377 + Stereo Offsetted Rendering (NV_stereo_view_rendering) 378 379 If a vertex, geometry, tessellation control, or tessellation evaluation 380 program specifies the "NV_stereo_view_rendering" option, the result 381 bindings "result.secondaryposition" and "result.secondaryviewportmask[]" 382 will be available to specify the secondary position and viewportmask 383 respectively. 384 385 (add the following to Section 2.X.7.Y, Program Declarations) 386 387 + Layer Offset for the Secondary View (NV_SECONDARY_VIEW_LAYER_OFFSET) 388 389 The NV_SECONDARY_VIEW_LAYER_OFFSET statement declares the layer offset 390 value to be added to the "result.layer" for the secondary view. If the 391 program also specifies the "NV_layer_viewport_relative" option, both the 392 viewport index and the above offset are added to the "result.layer" for 393 the second view. 394 395Issues 396 397 (1) Where does the stereo view expansion occur? 398 399 RESOLVED: This operation occurs right before viewport mask expansion 400 (NV_viewport_array2). The primary primitive is broadcast to different 401 viewports based on the viewport id/viewport mask followed by the secondary 402 primitive. This specification applies the stereo view expansion after 403 transform feedback, and makes all primitive queries except for clipping 404 primitives only count each primitive once. Clipping primitives' queries 405 count the primitives once for each view. 406 407 (2) Do we need "gl_SecondaryViewportIdNV" for the second view? 408 409 RESOLVED: No. "gl_SecondaryViewportMaskNV[]" should cover that functionality. 410 411 (3) Should the secondary position be readable from the tessellation 412 control/evaluation and geometry shaders? 413 414 RESOLVED: Yes. If the secondary position is written by the vertex shader, 415 tessellation shader should be able to read position to evaluate the 416 interpolated positions for the second view. 417 418Revision History 419 420 Revision 3 2017/11/25 (pbrown) 421 - Add to the OpenGL ES Extension Registry 422 Revision 2 2017/02/21 (jaschmidt) 423 - Formally add OpenGL ES interactions 424 Revision 1 425 - Internal revisions. 426