• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    NV_viewport_array2
4
5Name Strings
6
7    GL_NV_viewport_array2
8
9Contact
10
11    Jeff Bolz, NVIDIA Corporation (jbolz 'at' nvidia.com)
12    Pat Brown, NVIDIA Corporation (pbrown 'at' nvidia.com)
13
14Contributors
15
16    Pat Brown, NVIDIA
17    Mathias Heyer, NVIDIA
18
19Status
20
21    Shipping
22
23Version
24
25    Last Modified Date:         March 27, 2015
26    Revision:                   2
27
28Number
29
30    OpenGL Extension #476
31    OpenGL ES Extension #237
32
33Dependencies
34
35    This extension is written against the OpenGL 4.3 specification
36    (Compatibility Profile).
37
38    This extension interacts with the OpenGL ES 3.1 (March 17, 2014)
39    specification.
40
41    If implemented in OpenGL ES, NV_viewport_array, EXT_geometry_shader
42    and EXT_shader_io_blocks are required.
43
44    This extension interacts with EXT_tessellation_shader.
45
46    This extension interacts with NV_geometry_shader_passthrough.
47
48    This extension interacts with NV_gpu_program4.
49
50Overview
51
52    This extension provides new support allowing a single primitive to be
53    broadcast to multiple viewports and/or multiple layers.  A shader output
54    gl_ViewportMask[] is provided, allowing a single primitive to be output to
55    multiple viewports simultaneously.  Also, a new shader option is provided
56    to control whether the effective viewport index is added into gl_Layer.
57    These capabilities allow a single primitive to be output to multiple
58    layers simultaneously.
59
60    The gl_ViewportMask[] output is available in vertex, tessellation
61    control, tessellation evaluation, and geometry shaders. gl_ViewportIndex
62    and gl_Layer are also made available in all these shader stages. The
63    actual viewport index or mask and render target layer values are taken
64    from the last active shader stage from this set of stages.
65
66    This extension is a superset of the GL_AMD_vertex_shader_layer and
67    GL_AMD_vertex_shader_viewport_index extensions, and thus those extension
68    strings are expected to be exported if GL_NV_viewport_array2 is
69    supported. This extension includes the edits for those extensions, recast
70    against the reorganized OpenGL 4.3 specification.
71
72New Procedures and Functions
73
74    None.
75
76New Tokens
77
78    None.
79
80Additions to Chapter 11 of the OpenGL 4.3 (Compatibility Profile) Specification
81(Programmable Vertex Processing)
82
83    Add to Section 11.1.3.10 (Shader Outputs)
84
85    The built-in output variables gl_ViewportIndex, gl_ViewportMask[], and
86    gl_Layer hold the viewport index/mask and render target layer, as described
87    in Section 11.4 (Viewport Index and Layer).
88
89    Add to Section 11.2.1.2.3 (Tessellation Control Shader Outputs)
90
91    The built-in output variables gl_ViewportIndex, gl_ViewportMask[], and
92    gl_Layer hold the viewport index/mask and render target layer, as described
93    in Section 11.4 (Viewport Index and Layer).
94
95    Add to Section 11.2.3.4 (Tessellation Evaluation Shader Outputs)
96
97    The built-in output variables gl_ViewportIndex, gl_ViewportMask[], and
98    gl_Layer hold the viewport index/mask and render target layer, as described
99    in Section 11.4 (Viewport Index and Layer).
100
101    Modify Section 11.3.4.5 (Geometry Shader Outputs)
102
103    Replace the paragraph about gl_ViewportIndex:
104
105    The built-in output variables gl_ViewportIndex, gl_ViewportMask[], and
106    gl_Layer hold the viewport index/mask and render target layer, as described
107    in Section 11.4 (Viewport Index and Layer).
108
109    Replace Section 11.3.4.6 (Layer and Viewport Selection) with new Section
110    11.4 (Layer and Viewport Selection)
111
112    Geometry may be rendered to one of several different layers of cube map
113    textures, three-dimensional textures, or one- or two-dimensional texture
114    arrays. This functionality allows an application to bind an entire complex
115    texture to a framebuffer object, and render primitives to arbitrary layers
116    computed at run time. For example, it can be used render a scene into
117    multiple layers of an array texture in one pass, or to select a particular
118    layer to render to in shader code. The layer to render to is specified by
119    writing to the built-in output variable gl_Layer.  Layered rendering
120    requires the use of framebuffer objects (see section 9.8).
121
122    Shaders may also direct each primitive to zero or more viewports. The
123    destination viewports for a primitive may be selected in the shader by
124    writing to the built-in output variable gl_ViewportIndex (selecting a
125    single viewport) or gl_ViewportMask[] (selecting multiple viewports).
126    This functionality allows a shader to direct its output to different
127    viewports for each primitive, or to draw multiple versions of a primitive
128    into several different viewports.
129
130    The specific vertex of a primitive used to select the rendering layer or
131    viewport index/mask is implementation-dependent and thus portable
132    applications will assign the same layer and viewport index for all
133    vertices in a primitive. The vertex conventions followed for gl_Layer and
134    gl_ViewportIndex/gl_ViewportMask[] may be determined by calling
135    GetIntegerv with the symbolic constants LAYER_PROVOKING_VERTEX and
136    VIEWPORT_INDEX_PROVOKING_VERTEX, respectively. For either query, if the
137    value returned is PROVOKING_VERTEX, then vertex selection follows the
138    convention specified by ProvokingVertex (see section 13.4). If the value
139    returned is FIRST_VERTEX_CONVENTION, selection is always taken from the
140    first vertex of a primitive. If the value returned is
141    LAST_VERTEX_CONVENTION, the selection is always taken from the last vertex
142    of a primitive. If the value returned is UNDEFINED_VERTEX, the selection
143    is not guaranteed to be taken from any specific vertex in the
144    primitive. The vertex considered the provoking vertex for particular
145    primitive types is given in table 13.2.
146
147    The layer selection may be made a function of the viewport index, as
148    described in Section 7.1 of the GLSL specification.
149
150    The viewport index, viewport mask, and layer outputs are available in
151    vertex, tessellation control, tessellation evaluation, and geometry
152    shaders. Only the last active shader stage (in pipeline order) from this
153    list controls the viewport index/mask and layer; outputs in previous
154    shader stages are not used, even if the last stage fails to write one of
155    the outputs.
156
157
158Additions to Chapter 13 of the OpenGL 4.3 (Compatibility Profile) Specification
159(Fixed-Function Vertex Post-Processing)
160
161    Modify Section 13.2 (Transform Feedback), p. 453
162
163    Modify the first paragraph:
164
165    ...The vertices are fed back after vertex color clamping, but before
166    viewport mask expansion, flatshading, and clipping. ...
167
168
169    Modify Section 13.6.1 (Controlling the Viewport)
170
171    Multiple viewports are available and are numbered zero through the value
172    of MAX_VIEWPORTS minus one.  If last active vertex, tessellation, or
173    geometry shader writes to gl_ViewportIndex, the primitive is emitted to
174    the viewport corresponding to the value assigned to gl_ViewportIndex, as
175    taken from an implementation-dependent provoking vertex.  The primitive is
176    then transformed using the state of the selected viewport.  If the value
177    of the viewport index is outside the range zero to the value of
178    MAX_VIEWPORTS minus one, the results of the viewport transformation are
179    undefined.
180
181    If last active vertex, tessellation, or geometry shader writes to
182    gl_ViewportMask[], the primitive is emitted to zero or more viewports.  If
183    bit <i> is set in the mask, the primitive is emitted to viewport <i> and
184    transformed using the state of viewport <i>.  However, each primitive will
185    still be captured by transform feedback and counted by primitive queries
186    only once.  If bits of gl_ViewportMask[] greater than or equal to the
187    value of MAX_VIEWPORTS are set, the number of times the primitive is
188    emitted and which viewport transformations are used are undefined.
189
190    If neither gl_ViewportIndex nor gl_ViewportMask[] are written, the
191    viewport numbered zero is used by the viewport transformation.
192
193
194    Modify Section 14.5.2.1 (Line Stipple)
195
196    (add to the end of the section)
197
198    When rasterizing line segments that could be sent to multiple viewports
199    via the gl_ViewportMask[] built-in geometry shader output (section
200    13.6.1), the line stipple pattern is not guaranteed to be continuous if
201    segments are sent to multiple viewports.  If a line segment is not an
202    independent line segment and is not the first in a series of connected
203    segments (where the stipple counter <s> is reset to 0), the initial value
204    of <s> for the segment is undefined unless that line segment and all
205    previous segments in the series were sent to the same single viewport.
206
207New Implementation Dependent State
208
209    None.
210
211New State
212
213    None.
214
215Additions to the AGL/GLX/WGL Specifications
216
217    None.
218
219GLX Protocol
220
221    None.
222
223Modifications to the OpenGL Shading Language Specification, Version 4.30
224
225    Including the following line in a shader can be used to control the
226    language features described in this extension:
227
228      #extension GL_NV_viewport_array2 : <behavior>
229
230    where <behavior> is as specified in section 3.3.
231
232    New preprocessor #defines are added to the OpenGL Shading Language:
233
234      #define GL_NV_viewport_array2                     1
235
236    Modify Section 7.1 (Built-In Language Variables), p. 116
237
238    Add to the list of vertex shader built-ins:
239
240        out gl_PerVertex {
241            highp int gl_ViewportIndex;
242            highp int gl_ViewportMask[];
243            highp int gl_Layer;
244        };
245
246    Add to the list of geometry shader built-ins:
247
248        out highp int gl_ViewportMask[];
249
250    Add to the list of tessellation control shader built-ins:
251
252        out gl_PerVertex {
253            highp int gl_ViewportIndex;
254            highp int gl_ViewportMask[];
255            highp int gl_Layer;
256        } gl_out[];
257
258    Add to the list of tessellation evaluation shader built-ins:
259
260        out gl_PerVertex {
261            highp int gl_ViewportIndex;
262            highp int gl_ViewportMask[];
263            highp int gl_Layer;
264        };
265
266    Modify descriptions of gl_Layer and gl_ViewportIndex as follows:
267
268    The variable gl_Layer is available as an output variable in the vertex,
269    tessellation, and geometry (VTG) languages and an input variable in the
270    fragment language. In the VTG languages, it is used to select a specific
271    layer (or face and layer of a cube map) of a multi-layer framebuffer
272    attachment. The actual layer used will come from one of the vertices in
273    the primitive being shaded. Which vertex the layer comes from is undefined,
274    so it is best to write the same layer value for all vertices of a
275    primitive. If a shader statically assigns a value to gl_Layer, layered
276    rendering mode is enabled. See section 11.4 "Layer and Viewport Selection"
277    and section 9.4.9 "Layered Framebuffers" of the OpenGL Graphics System
278    Specification for more information. If a shader statically assigns a value
279    to gl_Layer, and there is an execution path through the shader that does
280    not set gl_Layer, then the value of gl_Layer is undefined for executions
281    of the shader that take that path.
282
283    ...
284
285    The input variable gl_Layer in the fragment language will have the same
286    value that was written to the output variable gl_Layer in the VTG
287    languages. If the final VTG stage does not dynamically assign a value to
288    gl_Layer, the value of gl_Layer in the fragment stage will be undefined.
289    If the final VTG stage makes no static assignment to gl_Layer, the input
290    gl_Value in the fragment stage will be zero. Otherwise, the fragment stage
291    will read the same value written by the final VTG stage, even if that value
292    is out of range. If a fragment shader contains a static access to gl_Layer,
293    it will count against the implementation defined limit for the maximum
294    number of inputs to the fragment stage.
295
296    The variable gl_ViewportIndex is available as an output variable in the
297    VTG languages and an input variable in the fragment language. In the
298    geometry language, it provides the index of the viewport to which the next
299    primitive emitted from the geometry shader should be drawn. In the vertex
300    and tessellation languages, it provides the index of the viewport
301    associated with the vertex being shaded. Primitives will undergo viewport
302    transformation and scissor testing using the viewport transformation and
303    scissor rectangle selected by the value of gl_ViewportIndex. The viewport
304    index used will come from one of the vertices in the primitive being
305    shaded. However, which vertex the viewport index comes from is
306    implementation-dependent, so it is best to use the same viewport index for
307    all vertices of the primitive. If the final VTG stage does not assign a
308    value to gl_ViewportIndex or gl_ViewportMask[], viewport transform and
309    scissor rectangle zero will be used. If a shader statically assigns a value
310    to gl_ViewportIndex and there is a path through the shader that does not
311    assign a value to gl_ViewportIndex, the value of gl_ViewportIndex is
312    undefined for executions of the shader that take that path. See section
313    11.4 "Layer and Viewport Selection" of the OpenGL Graphics System
314    Specification for more information.
315
316    The input variable gl_ViewportIndex in the fragment stage will have the
317    same value that was written to the output variable gl_ViewportIndex in the
318    final VTG stage. If the final VTG stage does not dynamically assign to
319    gl_ViewportIndex, the value of gl_ViewportIndex in the fragment shader will
320    be undefined. If the final VTG stage makes no static assignment to
321    gl_ViewportIndex, the fragment stage will read zero. Otherwise, the
322    fragment stage will read the same value written by the final VTG stage,
323    even if that value is out of range. If a fragment shader contains a static
324    access to gl_ViewportIndex, it will count against the implementation
325    defined limit for the maximum number of inputs to the fragment stage.
326
327    The variable gl_ViewportMask[] is available as an output variable in the
328    VTG languages. The array has ceil(v/32) elements where v is the maximum
329    number of viewports supported by the implementation. When a shader writes
330    this variable, bit B of element M controls whether the primitive is
331    emitted to viewport 32*M+B. If gl_ViewportIndex is written by the final
332    VTG stage, then gl_ViewportIndex in the fragment stage will have the same
333    value. If gl_ViewportMask[] is written by the final VTG stage, then
334    gl_ViewportIndex in the fragment stage will have the index of the viewport
335    that was used in generating that fragment.
336
337    If a shader statically assigns a value to gl_ViewportIndex, it may not
338    assign a value to any element of gl_ViewportMask[]. If a shader
339    statically writes a value to any element of gl_ViewportMask[], it may
340    not assign a value to gl_ViewportIndex. That is, a shader may assign
341    values to either gl_ViewportIndex or gl_ViewportMask[], but not
342    both. Multiple shaders linked together must also consistently write just
343    one of these variables.  These incorrect usages all generate compile-time
344    or link-time errors.
345
346    The shader output gl_Layer may be redeclared with a layout qualifer
347    <viewport_relative> as follows:
348
349        layout (viewport_relative) out highp int gl_Layer;
350
351    If gl_Layer is <viewport_relative>, then the viewport index is added to
352    the layer used for rendering (and available in the fragment shader). If
353    the shader writes gl_ViewportMask[], then gl_Layer has a different value
354    for each viewport the primitive is rendered to. If gl_Layer is
355    <viewport_relative> and the shader writes neither gl_ViewportIndex nor
356    gl_ViewportMask[], a link-error will result.
357
358    Modify Section 8.15 (Geometry Shader Functions)
359
360    The function EmitStreamVertex() specifies that a vertex is completed. A
361    vertex is added to the current output primitive in vertex stream <stream>
362    using the current values of all output variables associated with <stream>.
363    These include gl_PointSize, gl_ClipDistance, gl_Layer, gl_Position,
364    gl_PrimitiveID, gl_ViewportIndex, and gl_ViewportMask[]. The values of
365    all output variables for all output streams are undefined after a call to
366    EmitStreamVertex().
367
368Errors
369
370    None.
371
372Interactions with OpenGL ES 3.1
373
374    Unless functionality similar to ARB_provoking_vertex is supported, remove
375    references to PROVOKING_VERTEX and ProvokingVertex().  Also remove
376    reference to 'vertex color clamping'.  The modifications to Line Stippling
377    don't apply.
378
379Interactions with EXT_tessellation_shader
380
381    If implemented on OpenGL ES and EXT_tessellation_shader is not supported,
382    remove all language referring to the tesselation control and tessellation
383    evaluation pipeline stages.
384
385Interactions with NV_geometry_shader_passthrough
386
387    If NV_geometry_shader_passthrough is supported, the NV_gpu_program4 and
388    NV_geometry_program4 language describing the PASSTHROUGH declaration
389    statement should be modified to state that "result.viewportmask" may not
390    be used in such a declaration.
391
392Interactions with NV_gpu_program4
393
394    If NV_gpu_program4 is supported and the "NV_viewport_array2" program
395    option is specified, vertex, tessellation control/evaluation, and geometry
396    program result variable "result.viewportmask" can be used to specify the
397    mask of viewports that the primitive will be emitted to, "result.viewport"
398    can be used to specify the index of the viewport that the primitive will
399    be emitted to, and "result.layer" can be used to specify the layer of a
400    layered framebuffer attachment that the primitive will be emitted to.
401
402    (add the following rule to the NV_gpu_program4 grammar)
403
404    <resultBasic>      ::= ...
405                         | <resPrefix> "viewportmask" arrayMemAbs
406                         | <resPrefix> "viewport"
407                         | <resPrefix> "layer"
408
409    (add the following to the tables of Vertex, Geometry, and Tessellation
410    Control/Eval Program Result Variable Bindings)
411
412      Binding                        Components  Description
413      -----------------------------  ----------  ----------------------------
414      result.viewportmask[]          (v,*,*,*)   viewport array mask
415      result.viewport                (v,*,*,*)   viewport array index
416      result.layer                   (l,*,*,*)   layer for cube/array/3D FBOs
417
418    (add the following to Section 2.X.2, Program Grammar)
419
420    If a result variable binding matches "result.viewportmask", updates to the
421    "x" component of the result variable provide a single integer that serves
422    as a mask of viewport indices. The mask must be written as an integer
423    value; writing a floating-point value will produce undefined results.
424    If the value has bits greater than or equal to MAX_VIEWPORTS set, the
425    number of viewports the primitive is emitted to and which viewports are
426    used are undefined. If the "NV_viewport_array2" program option is not
427    specified, the "result.viewportmask" binding is unavailable.
428
429    If both "result.viewport" and "result.viewportmask" are written,
430    compilation will fail.
431
432    (add the following to Section 2.X.6.Y, Program Options)
433
434    + Viewport Mask (NV_viewport_array2)
435
436    If a vertex, geometry, tessellation control, or tessellation evaluation
437    program specifies the "NV_viewport_array2" option, the result binding
438    "result.viewportmask" will be available to specify the mask of viewports
439    to use for primitive viewport transformations and scissoring as described
440    in section 2.X.2. Additionally, the "result.viewport" and "result.layer"
441    result bindings will be available in these same shader stages.
442
443    If a program specifies the "NV_layer_viewport_relative" option, the
444    result.layer will have the viewport index automatically added to it. If
445    the result.viewportmask is used, the result.layer will be different for
446    each viewport the primitive is emitted to.
447
448Issues
449
450    (1) Where does the viewport mask broadcast occur?
451
452    RESOLVED:  This operation could potentially be performed before or after
453    transform feedback, but feeding back several viewports worth of primitives
454    doesn't seem particularly useful.  This specification applies the viewport
455    mask after transform feedback, and makes primitive queries only count each
456    primitive once.
457
458    Note that it is possible to capture viewport mask shader outputs when
459    transform feedback is active.
460
461    (2) How does the gl_ViewportIndex fragment input behave?
462
463    RESOLVED:  Whether viewport mask or viewport indices are used in VTG
464    shaders, the fragment shader input gl_ViewportIndex will contain the
465    viewport number for the primitive generating each fragment.  If the
466    viewport mask is used to broadcast a single primitive to multiple
467    viewports, and the same pixel is covered by the primitive in each
468    viewport, multiple fragment shader invocations for that pixel will be
469    generated, each with a different value of gl_ViewportIndex.
470
471    This extension provides no gl_ViewportMask[] input, so a fragment shader
472    is not able to see the original viewport mask for the primitive generating
473    the fragment.  If necessary, this value could be passed by a separate
474    shader variable qualified with "flat".
475
476    (3) How does the viewport mask interact with line stipple?
477
478    RESOLVED:  With viewport mask, it's possible to broadcast line strips to
479    multiple viewports.  If line stipple is enabled in the OpenGL
480    compatibility profile, implementations are required to maintain a
481    continuous stipple pattern across the strip.  When primitives are
482    broadcast via viewport mask, implementations will not always be able to
483    buffer an entire strip and send it to each viewport in turn.  So it will
484    often be necessary to break up a long strip, and send segments to
485    alternating viewports.  An implementation could handle this by breaking up
486    the strip and keeping N independent stipple counters, but that seems like
487    overkill.
488
489    We relax normal spec requirements and require a continuous stipple pattern
490    only if the entire strip if sent to exactly one viewport.  If any segment
491    in the strip is sent to multiple viewports, no viewports, or a different
492    viewport than previous segments, the stipple counter for that segment and
493    subsequent segments in the strip is undefined.
494
495    (4) Can a viewport index or mask written by vertex or tessellation shader
496    be read by downstream tessellation or geometry shaders?
497
498    RESOLVED:  No. The fragment shader is able to read the viewport index, but
499    this extension provides no built-in input allowing VTG shaders to see a
500    viewport index or mask written by a previous shader stage.
501
502    (5) Can this extension be used to "kill" primitives in a passthrough
503    geometry shader (NV_geometry_shader_passthrough)?
504
505    RESOLVED:  Yes.  In regular geometry shaders, input primitives can be
506    killed by returning without emitting any vertices.  That's not possible
507    with passthrough geometry shaders, however it is possible to code a
508    passthrough geometry shader like:
509
510      void main()
511      {
512        if (shouldKillPrimitive()) {
513          // Set the viewport mask to zero.  A primitive will still be
514          // emitted from the geometry shader stage, however it will be sent
515          // to no viewports and thus be discarded.  Any other per-primitive
516          // outputs will be undefined.
517          gl_ViewportMask[0] = 0;
518          return;
519        }
520
521        // Since the shader writes the viewport mask in the "kill" path, it
522        // also needs to write it in the non-"kill" path; otherwise, its
523        // value would be undefined and the primitive will be sent to an
524        // undefined set of viewports.  Setting the mask to 1 will always
525        // send a primitive to viewport zero.
526        gl_ViewportMask[0] = 1;
527
528        ...
529      }
530
531    Without the viewport mask or a similar feature, it is not possible to kill
532    primitives in a passthrough geometry shader.
533
534Revision History
535
536    Revision 2, 2015/03/27
537      - Add ES interactions
538
539    Revision 1
540      - Internal revisions.
541