• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    ARB_shading_language_420pack
4
5Name Strings
6
7    GL_ARB_shading_language_420pack
8
9Contact
10
11    John Kessenich (cepheus 'at' frii.com)
12
13Contributors
14
15    Pat Brown, NVIDIA
16    Jeff Bolz, NVIDIA
17    Pierre Boudier, AMD
18    Piers Daniell, NVIDIA
19    Patrick Doane, Blizzard
20    John Kessenich
21    Daniel Koch, Transgaming
22    Bill Licea-Kane, AMD
23    Barthold Lichtenbelt, NVIDIA
24    Ian Romanick, Intel
25    Bruce Merry, ARM
26    Graham Sellers, AMD
27    Robert Simpson, Qualcomm
28
29Notice
30
31    Copyright (c) 2011-2013 The Khronos Group Inc. Copyright terms at
32        http://www.khronos.org/registry/speccopyright.html
33
34Specification Update Policy
35
36    Khronos-approved extension specifications are updated in response to
37    issues and bugs prioritized by the Khronos OpenGL Working Group. For
38    extensions which have been promoted to a core Specification, fixes will
39    first appear in the latest version of that core Specification, and will
40    eventually be backported to the extension document. This policy is
41    described in more detail at
42        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
43
44Status
45
46    Complete.
47    Approved by the ARB 25-Jul-2011.
48    Approved by the Khronos Promoters on 2011/07/29.
49
50Version
51
52    Last Modified Date: 11-Sep-2014
53    Revision: 4
54
55Number
56
57    ARB Extension #108
58
59Dependencies
60
61    GLSL 1.3 is required for all features.  GLSL 1.4 is required
62    declaring a binding for a uniform block, as uniform blocks were not
63    present until version 1.4.
64
65    This extension interacts with the ARB_shader_image_load_store
66    extension, for assigning locations to image variables.
67
68    References to *patch* are not valid unless tessellation stages are
69    present and enabled.
70
71    While this document is self-contained, clarifying context for how to
72    add the following changes can be seen by looking at version 4.20 of
73    the GLSL specification.
74
75Overview
76
77    This is a language feature only extension formed from changes made
78    to version 4.20 of GLSL.  It includes:
79
80    * Add line-continuation using '\', as in C++.
81
82    * Change from ASCII to UTF-8 for the language character set and also
83      allow any characters inside comments.
84
85    * Allow implicit conversions of return values to the declared type of
86      the function.
87
88    * The *const* keyword can be used to declare variables within a function
89      body with initializer expressions that are not constant expressions.
90
91    * Qualifiers on variable declarations no longer have to follow a strict
92      order. The layout qualifier can be used multiple times, and multiple
93      parameter qualifiers can be used.  However, this is not as
94      straightforward as saying declarations have arbitrary lists of
95      initializers.  Typically, one qualifier from each class of qualifiers
96      is allowed, so care is now taken to classify them and say so.  Then,
97      of these, order restrictions are removed.
98
99    * Add layout qualifier identifier "binding" to bind the location of a
100      uniform block.  This requires version 1.4 of GLSL.  If this extension
101      is used with an earlier version than 1.4, this feature is not present.
102
103    * Add layout qualifier identifier "binding" to bind units to sampler
104      and image variable declarations.
105
106    * Add C-style curly brace initializer lists syntax for initializers.
107      Full initialization of aggregates is required when these are used.
108
109    * Allow ".length()" to be applied to vectors and matrices, returning
110      the number of components or columns.
111
112    * Allow swizzle operations on scalars.
113
114    * Built-in constants for gl_MinProgramTexelOffset and
115      gl_MaxProgramTexelOffset.
116
117IP Status
118
119    No known IP claims.
120
121Additions to Chapter 3 of the OpenGL Shading Language
122
123    Change the opening of 3.1 Character Set to
124
125    "The source character set used for the OpenGL shading languages, outside of
126    comments, is a subset of UTF-8. It includes the following characters:
127
128        "The backslash ( \ ) as the line-continuation character when used as
129         the last character of a line, just before a new line."
130
131    and after the list, referring to all the characters:
132
133    "An error will be given if any other character is used outside a comment.
134
135    "There are no trigraphs. There are no escape sequences or other uses of the
136    backslash beyond use as the line-continuation character."
137
138    At the end of section 3.2, add
139
140    "Line numbers are one more than the number of new lines that have been
141    processed, including counting the new lines that will be removed by the
142    line-continuation character ( \ ).
143
144    "Lines separated by the line-continuation character preceding a new line
145    are concatenated together before either comment processing or preprocessing.
146    No white space is substituted for the line-continuation character. That is,
147    a single token could be formed by the concatenation by taking the characters
148    at the end of one line concatenating them with the characters at the
149    beginning of the next line."
150
151        float f\
152        oo;
153        // forms a single line equivalent to "float foo;"
154        // (assuming '\' is the last character before the new line and "oo" are
155        // the first two characters of the next line)
156
157    Add to the preprocessor:
158
159    "Preprocessing takes places after new lines have been removed by the
160    line-continuation character."
161
162    "Including the following line in a shader will enable module import and
163    related extended language features described in this extension:
164
165        #extension GL_ARB_shading_language_420pack : <behavior>
166
167    where <behavior> is as specified in section 3.3 for the #extension
168    directive."
169
170    A new preprocessor macro is added to the OpenGL Shading Language:
171
172      #define GL_ARB_shading_language_420pack    1
173
174    Add to the section on comments
175
176    "Inside comments, any byte values may be used, except a byte whose value
177    is 0. No errors will be given for the content of comments and no validation
178    on the content of comments need be done.
179
180    "Removal of new lines by the line-continuation character ( \ ) logically
181    occurs before comments are processed. That is, a single-line comment ending
182    in the line-continuation character ( \ ) includes the next line in the
183    comment."
184
185        // a single-line comment containing the next line \
186        a = b; // this is still in the first comment
187
188Additions to Chapter 4 of the OpenGL Shading Language
189
190    Add to the syntax description of integer literals:
191
192    "When tokenizing, the maximal token matching the above will be recognized
193    before a new token is started."
194
195    Add to the syntax description of floating-point literals:
196
197    "When tokenizing, the maximal token matching the above will be recognized
198    before a new token is started."
199
200    Add to the description of .length():
201
202    "This returns a type int."
203
204    Add a new section for initializers
205
206    "Initializers
207
208    "At declaration, an initial value for an aggregate variable may be provided,
209    specified as an equals (=) followed by an initializer. The initializer is
210    either an assignment-expression or a list of initializers enclosed in curly
211    braces.  The grammar for the initializer is:
212
213        initializer :
214            assignment-expression
215            { initializer-list }
216            { initializer-list , }
217
218        initializer-list :
219            initializer
220            initializer-list , initializer
221
222    "The assignment-expression is a normal expression except that a comma ( , )
223    outside parentheses is interpreted as the end of the initializer, not as the
224    sequence operator. As explained in more detail below, this allows creation
225    of nested initializers: The aggregate and its initializer must exactly match
226    in terms of nesting, number of components/elements/members present at each
227    level, and types of components/elements/members.
228
229    "An assignment-expression in an initializer must be either the same type as
230    the object it initializes or be a type that can be converted to the object's
231    type according to section 4.1.10 "Implicit Conversions". Since these include
232    constructors, an aggregate can be initialized by either a constructor or an
233    initializer list; an element in an initializer list can be a constructor.
234
235    "If an initializer is a list of initializers enclosed in curly braces, the
236    variable being declared must be a vector, a matrix, an array, or a
237    structure.
238
239        int i = { 1 }; // illegal, i is not an aggregate
240
241    "A list of initializers enclosed in a matching set of curly braces is
242    applied to one aggregate. This may be the variable being declared or an
243    aggregate contained in the variable being declared. Individual
244    initializers from the initializer list are applied to the elements/members
245    of the aggregate, in order.
246
247    "If the aggregate has a vector type, initializers from the list are applied
248    to the components of the vector, in order, starting with component 0. The
249    number of initializers must match the number of components.
250
251    "If the aggregate has a matrix type, initializers from the list must be
252    vector initializers and are applied to the columns of the matrix, in order,
253    starting with column 0. The number of initializers must match the number of
254    columns.
255
256    "If the aggregate has a structure type, initializers from the list are
257    applied to the members of the structure, in the order declared in the
258    structure, starting with the first member. The number of initializers must
259    match the number of members.
260
261    "Applying these rules, the following matrix declarations are equivalent:
262
263        mat2x2 a = mat2( vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) );
264        mat2x2 b = { vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) };
265        mat2x2 c = { { 1.0, 0.0 }, { 0.0, 1.0 } };
266
267    "All of the following declarations are illegal.
268
269        float a[2] = { 3.4, 4.2, 5.0 }; // illegal
270        vec2 b = { 1.0, 2.0, 3.0 }; // illegal
271        mat3x3 c = { vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0) }; // illegal
272        mat2x2 d = { 1.0, 0.0, 0.0, 1.0 }; // illegal, can't flatten nesting
273        struct {
274            float a;
275            int b;
276        } e = { 1.2, 2, 3 }; // illegal
277
278    "In all cases, the innermost initializer (i.e., not a list of initializers
279    enclosed in curly braces) applied to an object must have the same type as
280    the object being initialized or be a type that can be converted to the
281    object's type according to section 4.1.10 "Implicit Conversions". In the
282    latter case, an implicit conversion will be done on the initializer before
283    the assignment is done. All of the following declarations are illegal.
284
285        int a = true; // illegal
286        vec4 b[2] = { vec4(0.0), 1.0 }; // illegal
287        mat4x2 c = { vec3(0.0), vec3(1.0) }; // illegal
288
289        struct S1 {
290            vec4 a;
291            vec4 b;
292        };
293
294        struct {
295            float s;
296            float t;
297        } d[] = { S1(vec4(0.0), vec4(1.1)) }; // illegal
298
299    "If an initializer (of either form) is provided for an unsized array, the
300    size of the array is determined by the number of top-level (non-nested)
301    initializers within the initializer. All of the following declarations
302    create arrays explicitly sized with five elements:
303
304        float a[] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
305        float b[] = { 3.4, 4.2, 5.0, 5.2, 1.1 };
306        float c[] = a; // c is explicitly size 5
307        float d[5] = b; // means the same thing
308
309    "It is an error to have too few or too many initializers in an initializer
310    list for the aggregate being initialized. That is, all elements of an array,
311    all members of a structure, all columns of a matrix, and all components of a
312    vector must have exactly one initializer expression present, with no
313    unconsumed initializers.
314
315    Change the definition of the storage qualifier *const* in the table:
316
317        const    |     a variable whose value cannot be changed
318
319    Change the definition of storage qualifiers to only include the following
320    rows
321
322        const
323        in
324        out
325        attribute
326        uniform
327        varying
328
329    (Removing "centroid in", "sample in", "centroid out", "sample out",
330    "centroid varying", "patch in", and "patch out".)
331
332    and with this introduction:
333
334    "Variable declarations may have at most one storage qualifier specified in
335    front of the type."
336
337    and make a new class "Auxiliary Storage Qualifier" to contain
338
339        Auxiliary Storage | Meaning
340        Qualifier         |
341        -----------------   -------
342        centroid          | centroid-based interpolation
343        sample            | per-sample interpolation
344        patch             | per-tessellation-patch attributes
345
346    add that
347
348    "Some input and output qualified variables can be qualified with at most one
349    additional auxiliary storage qualifier.
350
351    "Not all combinations of qualification are allowed. Which variable types can
352    have which qualifiers are specifically defined in upcoming sections."
353
354    Removing
355
356    "These interpolation qualifiers may only precede the qualifiers in,
357    centroid in, sample in, out, centroid out, or sample out in a
358    declaration."
359
360    Change the last paragraph in this section to say
361
362    "Initializers in global declarations may only be used in declarations of
363    global variables with no storage qualifier, with a *const* qualifier or
364    with a uniform qualifier...."
365
366    Change the Constant Qualifier section to instead say
367
368    "Named compile-time constants or read-only variables can be declared using
369    the const qualifier.  The const qualifier can be used with any of the
370    non-void transparent basic data types, as well as with structures and arrays
371    of these. It is an error to write to a const variable outside of its
372    declaration, so they must be initialized when declared.  For example,
373
374        const vec3 zAxis = vec3 (0.0, 0.0, 1.0);
375        const float ceiling = a + b; // a and b not necessarily constants
376
377    "Structure members may not be qualified with *const*. Structure variables
378    can be declared as *const*, and initialized with a structure constructor or
379    initializer.
380
381    "Initializers for *const* declarations at global scope must be
382    constant expressions..."
383
384    In the Constant Expressions section, change the *const* bullet to say
385
386        * a variable declared with the const qualifier and an initializer,
387          where the initializer is a constant expression
388
389    and add the bullet
390
391        * valid use of the length() method on a sized object, whether or not the
392          object itself is constant
393
394    Add to "Inputs" section
395
396    "It is an error to use any auxiliary or interpolation qualifiers on a vertex
397    shader input."
398
399    "Applying the *patch* qualifier to inputs can only be done in tessellation
400    evaluation shaders."
401
402    "The auxiliary storage qualifiers *centroid* and *sample* can also be
403    applied, as well as the interpolation qualifiers *flat*, *noperspective*,
404    and *smooth*."
405
406    Change all occurances of "patch in qualifier" to "patch qualifier" or
407    "patch in qualifiers". Similarly for any occurances of "patch out",
408    "centroid in", "sample in", "centroid out", and "sample out", through-out
409    the specification.
410
411    Also change
412
413    "Fragment shader inputs get per-fragment values, typically interpolated
414    from a previous stage's outputs. They are declared in fragment shaders
415    with the in storage qualifier, the centroid in storage qualifier, ..."
416
417    to
418
419    "Fragment shader inputs get per-fragment values, typically interpolated
420    from a previous stage's outputs. They are declared in fragment shaders
421    with the in storage qualifier.  The auxiliary storage qualifiers centroid
422    and sample can also be applied, as well as the interpolation qualifiers
423    flat, noperspective, and smooth..."
424
425    Change
426
427    "They are declared in fragment shaders with the in storage qualifier, the
428    centroid in storage qualifier, or the deprecated varying and centroid
429    varying storage qualifiers."
430
431    to
432
433    "They are declared in fragment shaders with the in storage qualifier or the
434    deprecated varying storage qualifier."
435
436    Add to the "Outputs" section
437
438    "A variable also cannot be declared with both the *in* and the *out*
439    qualifiers."
440
441    Change
442
443    "Vertex, tessellation evaluation, and geometry output variables output
444    per-vertex data and are declared using the out, centroid out, or sample out
445    storage qualifiers"
446
447    to
448
449    "Vertex, tessellation evaluation, and geometry output variables output
450    per-vertex data and are declared using the out storage qualifier"
451
452    Change
453
454    "It is an error to use patch out in a vertex, tessellation evaluation,
455    or geometry shader."
456
457    to
458
459    "Applying *patch* to an output can only be done in a tessellation control
460    shader."
461
462    Change
463
464    "Per vertex output variables are arrayed (see arrayed under 4.3.4 Inputs)
465    and declared using out or centroid out storage qualifiers."
466
467    to
468
469    "Per-vertex output variables are arrayed and declared using the *out*
470    qualifier without the *patch* qualifier.  Per-patch output variables are
471    declared using the *patch* and *out* storage qualifiers."
472
473    Add
474
475    "It is an error to use auxiliary storage qualifiers or interpolation
476    qualifiers on an output in a fragment shader."
477
478    Modify Interface Blocks with new relaxed qualifier rules:
479
480    "If optional qualifiers are used, they can include interpolation qualifiers,
481    auxiliary storage qualifiers, and storage qualifiers..."
482
483    Add to Layout Qualifiers:
484
485    "More than one layout qualifier may appear in a single declaration. If the
486    same layout-qualifier-name occurs in multiple layout qualifiers for the same
487    declaration, the last one overrides the former ones."
488
489    Add to Uniform Block Layout Qualifiers, if the base language version is 1.4
490    or above:
491
492        layout-qualifier-id
493            binding = integer-constant
494
495    "The binding identifier specifies the uniform buffer binding point
496    corresponding to the uniform block, which will be used to obtain the
497    values of the member variables of the block. It is an error to specify the
498    binding identifier for the global scope or for block member declarations.
499    Any uniform block declared without a binding identifier is initially
500    assigned to block binding point zero. After a program is linked, the
501    binding points used for uniform blocks declared with or without a binding
502    identifier can be updated by the OpenGL API.
503
504    "If the binding identifier is used with a uniform block instanced as an
505    array then the first element of the array takes the specified block binding
506    and each subsequent element takes the next consecutive uniform block
507    binding point.
508
509    "If the binding point for any uniform block instance is less than zero, or
510    greater than or equal to the implementation-dependent maximum number of
511    uniform buffer bindings, a compilation error will occur.  When the binding
512    identifier is used with a uniform block instanced as an array of size N,
513    all elements of the array from binding through binding + N - 1 must be
514    within this range."
515
516    Add for sampler and image layout qualifiers:
517
518    Note: The "image" variable aspect of this interacts with
519    ARB_shader_image_load_store and only applies if the extension
520    ARB_shader_image_load_store is enabled.
521
522    "Uniform layout qualifiers can be used to bind opaque uniform variables to
523    specific buffers or units.  Texture image units can be bound to samplers
524    and image units can be bound to images.
525
526        layout-qualifier-id
527            binding = integer-constant
528
529    "The identifier binding specifies which unit will be bound. Any uniform
530    sampler or image variable declared without a binding qualifier is
531    initially bound to unit zero. After a program is linked, the unit
532    referenced by a sampler or image uniform variable declared with or
533    without a binding identifier can be updated by the OpenGL API.
534
535    "If the binding identifier is used with an array, the first element of the
536    array takes the specified unit and each subsequent element takes the next
537    consecutive unit.
538
539    If the binding is less than zero, or greater than or equal to the
540    implementation-dependent maximum supported number of units, a compilation
541    error will occur. When the binding identifier is used with an array of size
542    N, all elements of the array from binding through binding + N - 1 must be
543    within this range."
544
545    Change the "Interpolation" section to be the "Interplotation Qualifiers"
546    section and change the first paragraph to now be the following.
547
548    "Inputs and outputs that could be interpolated can be further qualified by
549    at most one of the following interpolation qualifiers:
550
551        Qualifier          Meaning
552        ---------          -------
553        smooth             perspective correct interpolation
554        flat               no interpolation
555        noperspective      linear interpolation
556
557    "The presence of and type of interpolation is controlled by the above
558    interpolation qualifiers as well as the auxiliary storage qualifiers
559    *centroid* and *sample*. The auxiliary storage qualifier *patch* is not
560    used for interpolation; it is an error to use interpolation qualifiers with
561    *patch*.
562
563    Add the following parameter qualifier
564
565        Qualifier          Meaning
566        ---------          -------
567        const              for function parameters that cannot be written to
568
569    and note that precision qualifiers are also allowed on parameters.
570
571    Delete the following sentence in the "Invariant Qualifier" section:
572
573    "The invariant qualifier must appear before any interpolation qualifiers
574    or storage qualifiers when combined with a declaration."
575
576    Replace the "Order of Qualification" section with the following
577
578    4.11 "Order and Repetition of Qualification"
579
580    "When multiple qualifiers are present in a variable or parameter
581    declaration, they may appear in any order, but they must all appear before
582    the type. The layout qualifier is the only qualifier that can appear more
583    than once. Further, a declaration can have at most one storage qualifier,
584    at most one auxiliary storage qualifier, and at most one interpolation
585    qualifier. If inout is used, neither in nor out may be used.  Multiple
586    memory qualifiers can be used. Any violation of these rules will cause a
587    compile-time error."
588
589Additions to Chapter 5 of the OpenGL Shading Language
590
591    Change the section title "Vector Components" to be "Vector and Scalar
592    Components and Length".  In that section do the following.
593
594    Change first sentence to "The names of the components of a vector or
595    scalar are denoted by a single letter."
596
597    Add the following last sentence to its paragraph:
598
599    "The component names x, r, and s are, for example, synonyms for the same
600    (first) component in a vector.  They are also the names of the only
601    component in a scalar."
602
603    Add to the example
604
605        float height;
606        height.x // is legal
607        height.y // is illegal
608
609    and to the third example
610
611        float f = 1.2;
612        vec4 dup = f.xxxx; // dup = (1.2, 1.2, 1.2, 1.2)
613
614    "This notation is more concise than the constructor syntax. To form an
615    r-value, it can be applied to any expression that results in a vector or
616    scalar r-value. Any resulting vector of any operation must be a valid
617    vector in the language; hence the following is illegal:"
618
619        vec4 f;
620        vec4 g = pos.xyzwxy.xyzw; // illegal; pos.xyzwxy is non-existent "vec6"
621
622    Add to the end of this section:
623
624    "The *length* method may be applied to vectors (but not scalars). The
625    result is the number of components in the vector. For example,
626
627        vec3 v;
628        const int L = v.length();
629
630    "sets the constant L to 3. The type returned by .length() on a vector is
631    *int*."
632
633    Add to the Matrix Components section:
634
635    "The length method may be applied to matrices. The result is the number
636    of columns of the matrix. For example,
637
638        mat3x4 v;
639        const int L = v.length();
640
641    "sets the constant L to 3. The type returned by .length() on a matrix
642    is *int*."
643
644Additions to Chapter 6 of the OpenGL Shading Language
645
646    Add to the "Function Definitions" section the following functionality
647    regarding function return values:
648
649    "If the type of returnValue does not match returnType, there must be an
650    implicit conversion in section 4.1.10 "Implicit Conversions" that
651    converts the type of returnValue to returnType, or a compile error will
652    result."
653
654    and the clarifations:
655
656    "A void function can only use return without a return argument, even if
657    the return argument has void type. Return statements only accept values:
658
659        void func1() { }
660        void func2() { return func1(); } // illegal return statement
661
662    "Only a precision qualifier is allowed on the return type of a function.
663    Formal parameters can have parameter, precision, and memory qualifiers,
664    but no other qualifiers."
665
666    Under the section "Function Calling Conventions" change to the *inout*
667    bullet:
668
669        * "The keyword *inout* is used as a qualifier to denote the parameter
670          is to be both copied in and copied out. It means the same thing as
671          specifying both in and out."
672
673    and the following grammar changes:  Delete the const-qualifier parts of
674    the existing grammar and instead use
675
676        parameter-qualifiers :
677            empty
678            list of parameter-qualifier
679
680        parameter-qualifier :
681            empty
682            const
683            in
684            out
685            inout
686            memory qualifier
687            precision qualifier
688
689Additions to Chapter 7 of the OpenGL Shading Language
690
691    Add to the built-in constants
692
693        const int gl_MinProgramTexelOffset = -7;
694        const int gl_MaxProgramTexelOffset = 8;
695
696Additions to Chapter 9 of the OpenGL Shading Language
697
698    TBD.
699
700Conformance Tests
701
702    Verify that the following two vectors are identical:
703
704        vec4 a = vec4(1.0);
705        vec4 b = (1.0).xxxx;
706
707    Verify that the following generates a compilation error:
708
709        vec2 a = 1.xx;
710
711    Verify that the following two vectors are identical:
712
713        vec2 a = (1).xx;
714        vec2 b = vec2(1.0);
715
716    Verify that the following two arrays are identical:
717
718        vec4 a[] = vec4 [] (vec4(1.2), vec4(0.0), vec4(0.0), vec4(0.0),
719                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(2.4),
720                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0),
721                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(3.6));
722        vec4 b[] =        { vec4(1.2), vec4(0.0), vec4(0.0), vec4(0.0),
723                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(2.4),
724                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0),
725                            vec4(0.0), vec4(0.0), vec4(0.0), vec4(3.6) };
726
727    Verify that the following two arrays are identical:
728
729        vec4 a[12] = vec4 [] (vec4(1.2), vec4(0.0), vec4(0.0), vec4(0.0),
730                              vec4(0.0), vec4(0.0), vec4(0.0), vec4(2.4),
731                              vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0));
732        vec4 b[12] =        { vec4(1.2), vec4(0.0), vec4(0.0), vec4(0.0),
733                              vec4(0.0), vec4(0.0), vec4(0.0), vec4(2.4) };
734
735    Verify that the following three matrices are identical:
736
737        mat2x2 a = mat2(  vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) );
738        mat2x2 b =      { vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) };
739        mat2x2 c =      {     { 1.0, 0.0 },     { 0.0, 1.0 } };
740
741    Verify that the following generates a compliation error:
742
743        float a[2] = { 1.0, 2.0, 3.0 };
744
745    Verify that the following generates a compliation error:
746
747        mat2x2 d = { 1.0, 0.0, 0.0, 1.0 };
748
749
750    Verify that the output of the following fragment shader is (0, 1, 0, 1):
751
752    #version 410
753    #extension GL_ARB_shading_language_420pack: require
754    out vec4 color;
755    void main()
756    {
757        color = (vec2(0).length() == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
758    }
759
760    Repeat the above test with vec2(0).length() replaced by ivec2(0).length().
761
762    Repeat the above test with vec2(0).length() replaced by uvec2(0).length().
763
764    Repeat the above test with vec2(0).length() replaced by bvec2(0).length().
765
766    Repeat the above test with vec2(0).length() replaced by dvec2(0).length().
767
768
769    Verify that the output of the following fragment shader is (0, 1, 0, 1):
770
771    #version 410
772    #extension GL_ARB_shading_language_420pack: require
773    out vec4 color;
774    void main()
775    {
776        color = (vec3(0).length() == 3) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
777    }
778
779    Repeat the above test with vec3(0).length() replaced by ivec3(0).length().
780
781    Repeat the above test with vec3(0).length() replaced by uvec3(0).length().
782
783    Repeat the above test with vec3(0).length() replaced by bvec3(0).length().
784
785    Repeat the above test with vec3(0).length() replaced by dvec3(0).length().
786
787
788    Verify that the output of the following fragment shader is (0, 1, 0, 1):
789
790    #version 410
791    #extension GL_ARB_shading_language_420pack: require
792    out vec4 color;
793    void main()
794    {
795        color = (vec4(0).length() == 4) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
796    }
797
798    Repeat the above test with vec4(0).length() replaced by ivec4(0).length().
799
800    Repeat the above test with vec4(0).length() replaced by uvec4(0).length().
801
802    Repeat the above test with vec4(0).length() replaced by bvec4(0).length().
803
804    Repeat the above test with vec4(0).length() replaced by dvec4(0).length().
805
806
807    Verify that the output of the following fragment shader is (0, 1, 0, 1):
808
809    #version 410
810    #extension GL_ARB_shading_language_420pack: require
811    out vec4 color;
812    void main()
813    {
814        color = (mat2(0).length() == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
815    }
816
817    Repeat the above test with mat2(0).length() replaced by mat2x2(0).length().
818
819    Repeat the above test with mat2(0).length() replaced by dmat2x2(0).length().
820
821    Repeat the above test with mat2(0).length() replaced by mat2x3(0).length().
822
823    Repeat the above test with mat2(0).length() replaced by dmat2x3(0).length().
824
825    Repeat the above test with mat2(0).length() replaced by mat2x4(0).length().
826
827    Repeat the above test with mat2(0).length() replaced by dmat2x4(0).length().
828
829
830    Verify that the output of the following fragment shader is (0, 1, 0, 1):
831
832    #version 410
833    #extension GL_ARB_shading_language_420pack: require
834    out vec4 color;
835    void main()
836    {
837        color = (mat3(0).length() == 3) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
838    }
839
840    Repeat the above test with mat3(0).length() replaced by mat3x2(0).length().
841
842    Repeat the above test with mat3(0).length() replaced by dmat3x2(0).length().
843
844    Repeat the above test with mat3(0).length() replaced by mat3x3(0).length().
845
846    Repeat the above test with mat3(0).length() replaced by dmat3x3(0).length().
847
848    Repeat the above test with mat3(0).length() replaced by mat3x4(0).length().
849
850    Repeat the above test with mat3(0).length() replaced by dmat3x4(0).length().
851
852
853    Verify that the output of the following fragment shader is (0, 1, 0, 1):
854
855    #version 410
856    #extension GL_ARB_shading_language_420pack: require
857    out vec4 color;
858    void main()
859    {
860        color = (mat4(0).length() == 4) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
861    }
862
863    Repeat the above test with mat4(0).length() replaced by mat4x2(0).length().
864
865    Repeat the above test with mat4(0).length() replaced by dmat4x2(0).length().
866
867    Repeat the above test with mat4(0).length() replaced by mat4x3(0).length().
868
869    Repeat the above test with mat4(0).length() replaced by dmat4x3(0).length().
870
871    Repeat the above test with mat4(0).length() replaced by mat4x4(0).length().
872
873    Repeat the above test with mat4(0).length() replaced by dmat4x4(0).length().
874
875
876    Verify that the output of the following fragment shader is (0, 1, 0, 1):
877
878    #version 410
879    #extension GL_ARB_shading_language_420pack: require
880    out vec4 color;
881    void main()
882    {
883        color = (mat2(0)[0].length() == 2)
884            ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
885    }
886
887    Repeat the above test with mat2(0)[0].length() replaced by
888    mat2x2(0)[0].length().
889
890    Repeat the above test with mat2(0)[0].length() replaced by
891    dmat2x2(0)[0].length().
892
893    Repeat the above test with mat2(0)[0].length() replaced by
894    mat3x2(0)[0].length().
895
896    Repeat the above test with mat2(0)[0].length() replaced by
897    dmat3x2(0)[0].length().
898
899    Repeat the above test with mat2(0)[0].length() replaced by
900    mat4x2(0)[0].length().
901
902    Repeat the above test with mat2(0)[0].length() replaced by
903    dmat4x2(0)[0].length().
904
905
906    Verify that the output of the following fragment shader is (0, 1, 0, 1):
907
908    #version 410
909    #extension GL_ARB_shading_language_420pack: require
910    out vec4 color;
911    void main()
912    {
913        color = (mat3(0)[0].length() == 3)
914            ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
915    }
916
917    Repeat the above test with mat3(0)[0].length() replaced by
918    mat2x3(0)[0].length().
919
920    Repeat the above test with mat3(0)[0].length() replaced by
921    dmat2x3(0)[0].length().
922
923    Repeat the above test with mat3(0)[0].length() replaced by
924    mat3x3(0)[0].length().
925
926    Repeat the above test with mat3(0)[0].length() replaced by
927    dmat3x3(0)[0].length().
928
929    Repeat the above test with mat3(0)[0].length() replaced by
930    mat4x3(0)[0].length().
931
932    Repeat the above test with mat3(0)[0].length() replaced by
933    dmat4x3(0)[0].length().
934
935
936    Verify that the output of the following fragment shader is (0, 1, 0, 1):
937
938    #version 410
939    #extension GL_ARB_shading_language_420pack: require
940    out vec4 color;
941    void main()
942    {
943        color = (mat4(0)[0].length() == 4)
944            ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
945    }
946
947    Repeat the above test with mat4(0)[0].length() replaced by
948    mat2x4(0)[0].length().
949
950    Repeat the above test with mat4(0)[0].length() replaced by
951    dmat2x4(0)[0].length().
952
953    Repeat the above test with mat4(0)[0].length() replaced by
954    mat3x4(0)[0].length().
955
956    Repeat the above test with mat4(0)[0].length() replaced by
957    dmat3x4(0)[0].length().
958
959    Repeat the above test with mat4(0)[0].length() replaced by
960    mat4x4(0)[0].length().
961
962    Repeat the above test with mat4(0)[0].length() replaced by
963    dmat4x4(0)[0].length().
964
965
966    Verify that the following shader generates a compilation error:
967
968    #version 410
969    #extension GL_ARB_shading_language_420pack: require
970    out vec4 color;
971    void main()
972    {
973        float v;
974        int l = v.length();
975        color = vec4(1, 0, 0, 1);
976    }
977
978    Repeat the above test with "float v" replaced by "int v".
979
980    Repeat the above test with "float v" replaced by "uint v".
981
982    Repeat the above test with "float v" replaced by "bool v".
983
984    Repeat the above test with "float v" replaced by "double v".
985
986
987    Verify that the following shader compiles without error:
988
989    #version 410
990    #extension GL_ARB_shading_language_420pack: require
991    void main()
992    {
993        float b[vec2(0).length()];
994    }
995
996    Repeat the above test with vec2(0).length() replaced by ivec2(0).length().
997
998    Repeat the above test with vec2(0).length() replaced by uvec2(0).length().
999
1000    Repeat the above test with vec2(0).length() replaced by bvec2(0).length().
1001
1002    Repeat the above test with vec2(0).length() replaced by dvec2(0).length().
1003
1004    Repeat the above test with vec2(0).length() replaced by ivec3(0).length().
1005
1006    Repeat the above test with vec2(0).length() replaced by uvec3(0).length().
1007
1008    Repeat the above test with vec2(0).length() replaced by bvec3(0).length().
1009
1010    Repeat the above test with vec2(0).length() replaced by dvec3(0).length().
1011
1012    Repeat the above test with vec2(0).length() replaced by ivec4(0).length().
1013
1014    Repeat the above test with vec2(0).length() replaced by uvec4(0).length().
1015
1016    Repeat the above test with vec2(0).length() replaced by bvec4(0).length().
1017
1018    Repeat the above test with vec2(0).length() replaced by dvec4(0).length().
1019
1020    Repeat the above test with vec2(0).length() replaced by mat2(0).length().
1021
1022    Repeat the above test with vec2(0).length() replaced by mat2x2(0).length().
1023
1024    Repeat the above test with vec2(0).length() replaced by mat2x3(0).length().
1025
1026    Repeat the above test with vec2(0).length() replaced by mat2x4(0).length().
1027
1028    Repeat the above test with vec2(0).length() replaced by mat3(0).length().
1029
1030    Repeat the above test with vec2(0).length() replaced by mat3x2(0).length().
1031
1032    Repeat the above test with vec2(0).length() replaced by mat3x3(0).length().
1033
1034    Repeat the above test with vec2(0).length() replaced by mat3x4(0).length().
1035
1036    Repeat the above test with vec2(0).length() replaced by mat4(0).length().
1037
1038    Repeat the above test with vec2(0).length() replaced by mat4x2(0).length().
1039
1040    Repeat the above test with vec2(0).length() replaced by mat4x3(0).length().
1041
1042    Repeat the above test with vec2(0).length() replaced by mat4x4(0).length().
1043
1044    Repeat the above test with vec2(0).length() replaced by dmat2(0).length().
1045
1046    Repeat the above test with vec2(0).length() replaced by dmat2x2(0).length().
1047
1048    Repeat the above test with vec2(0).length() replaced by dmat2x3(0).length().
1049
1050    Repeat the above test with vec2(0).length() replaced by dmat2x4(0).length().
1051
1052    Repeat the above test with vec2(0).length() replaced by dmat3(0).length().
1053
1054    Repeat the above test with vec2(0).length() replaced by dmat3x2(0).length().
1055
1056    Repeat the above test with vec2(0).length() replaced by dmat3x3(0).length().
1057
1058    Repeat the above test with vec2(0).length() replaced by dmat3x4(0).length().
1059
1060    Repeat the above test with vec2(0).length() replaced by dmat4(0).length().
1061
1062    Repeat the above test with vec2(0).length() replaced by dmat4x2(0).length().
1063
1064    Repeat the above test with vec2(0).length() replaced by dmat4x3(0).length().
1065
1066    Repeat the above test with vec2(0).length() replaced by dmat4x4(0).length().
1067
1068    More TBD.
1069
1070Issues
1071
1072    1) How is the ambiguity of swizzling an integer literal resolved?
1073
1074        RESOLVED: Greedy lexing. The sequence "5.x" will be interpreted
1075        as the floating-point literal 5.0 followed by the identifier "x".
1076
1077    2) Should the array subscript operator be applicable to scalars as it is
1078       to vectors?
1079
1080        RESOLVED: NO.  In conduction with the rest of the features of this
1081        extension, this would allow writing generic code such as:
1082
1083            #define SUM_COMPONENTS(value, result) \
1084                do {
1085                    for (int i = 0; i < (value).length(); i++)
1086                        result += (value)[i];
1087                } while (0)
1088
1089        However, using macros in this fashion is a poor approximation
1090        of generic functions.  Until a better mechanism is added to
1091        GLSL, there is little utility in array accesses to scalars or
1092        single component vectors.
1093
1094    3) Should vectors and matrices also be able to use initializer lists?
1095
1096        RESOLVED: YES.  Many places in the language treat vectors as 2, 3, or
1097        4 element arrays of a scalar type.  Matrices are often treated as
1098        arrays of vector types.  Continuing that treatment here is logical.
1099
1100    4) What happens when an explicitly sized array is initialized with too few
1101       elements?  Is it allowed?
1102
1103        RESOLVED: DISALLOWED.  In C/C++ this is allowed.  The uninitialized
1104        elements are implicitly initialized to the appropriate reprensentation
1105        of zero.  However, the belief is that this enables a variety of
1106        programming errors that are difficult to debug on a GPU.
1107
1108    5) Can scalars be initialized using an initializer list?
1109
1110        RESOLVED: NO. In C/C++ this is allowed.  The ISO C99 specification
1111        specifically say, "The initializer for a scalar shall be a single
1112        expression, optionally enclosed in braces."  However, this may
1113        pose problems if / when a vec1 type is added.
1114
1115    6) Are initializer lists for vectors flexible in the same way that vector
1116       constructors are?  Specifically, is the initialzier list for 'c',
1117       below, legal?
1118
1119        vec2 a = vec2(2, 3);
1120        vec4 b = vec4(1, a, 4);   // b = { 1, 2, 3, 4 }
1121        vec4 c = { 1, a, 4 };     // Legal?
1122
1123        RESOLVED: NO.  In C++ there is a distinction between a constructor
1124        and an initializer list.  If you had vec2 and vec4 classes in C++, a
1125        constructor 'vec4(float, vec2, float)' might exist, but the
1126        initializer list for 'c' would not be legal.
1127
1128    7) Does adding *const* for read-only variables effect array sizing?
1129
1130    RESOLVED.  No. Array sizing changes are not part of this proposal.  Array
1131    sizing rules stay the same, where sizes must be compile-time constants,
1132    whether or not the keyword 'const' was involved, just like it always has
1133    been.  The following was and still is disallowed:
1134
1135        "void foo(const s) { int a[s]; }",
1136
1137    as will be
1138
1139        "void foo() { const s = exp; int a[s]; }".
1140
1141    8)  Should we allow non-compile-time constant initializers for const at
1142    global scope as well?
1143
1144        RESOLVED.  No.  Would make linking more difficult.
1145
1146    9) Do we want to add the new C++ constexpr for declaring constant
1147    functions?
1148
1149        RESOLVED.  No, not yet, could be a potential performance benefit in the
1150        future, but treat as a separate extension.  Note that most built-in
1151        functions are already understood to be "constexpr".  This has been
1152        submitted into bugzilla.
1153
1154    10) What combinations of interpolation qualifiers are allowed?  Before,
1155    you could take one of smooth, flat, and noperspective and combine that with
1156    one of centroid, sample, or patch.  What do combinations do we actually
1157    want?  Do we want multiple intances of a single qualifier allowed?
1158    (E.g. two layout qualifiers, or "in out"?)
1159
1160        RESOLVED.  Allow multiple "layout".  Not anything else.
1161
1162    11) Should we allow multiple block declarations to use the same
1163    binding point?  For example:
1164           layout(binding = 3) uniform Block1 { ... };
1165           layout(binding = 3) uniform Block2 { ... };
1166
1167       RESOLVED: There is no reason to disallow this usage; in particular,
1168       existing UBO shaders effectively declare all blocks with
1169       "layout(block = 0)".
1170
1171    12) Should the qualifier be called "location", "block" or "binding"?
1172
1173       RESOLVED: The qualifier is called "binding" because it makes it more
1174       clear what parameter of UniformBlockBinding that this qualifier
1175       affects. "block" could be confused with either the
1176       <uniformBlockIndex> or <uniformBlockBinding> and "location" might be
1177       confused with the current uses of the qualifier "location" for
1178       attribute locations or it could be confused with uses of "location"
1179       for uniform variable location, which blocks don't have.
1180
1181    13) Should sampler initialization use a layout(binding) qualifier
1182       instead of specifying a uniform initializer?
1183
1184       RESOLVED: Revision #4 of the sampler initialization spec uses a
1185       layout(binding) qualifier for sampler uniforms. This is more
1186       forward looking and makes the spec more consistent with
1187       ARB_uniform_block_binding_initialization and
1188       ARB_shader_atomic_counters.
1189
1190Revision History
1191
1192    Revision 4, 11-Sep-2014 (pbrown)
1193      - Fix minor typo.
1194    Revision 3, 13-May-2014 (John Kessenich)
1195      - Resolve bug 10593.
1196    Revision 2, 25-Jul-2011 (John Kessenich)
1197      - Mark as complete and approved.
1198      - Tidy up some formating and non-raw-text quote marks.
1199      - Pull in the initializers for images, to completely subsume
1200        GL_ARB_uniform_sampler_initialization.
1201      - Point out image and patch dependencies.
1202    Revision 1, 5-Jul-2011 (John Kessenich)
1203      - Initial version.  Formed by combing the content of the
1204        4.20 draft specification and the content of draft
1205        extensions:
1206        * ARB_shading_language_vec1
1207        * ARB_shading_language_relaxed_qualifiers
1208        * ARB_shading_language_length
1209        * ARB_shading_language_initializer_list
1210        * GL_ARB_uniform_block_binding_initialization
1211        * GL_ARB_uniform_sampler_initialization (just sampler binding)
1212        Issues were carried across and renumbered.
1213        Conformance tests were carried over.
1214
1215