• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    ARB_shader_atomic_counters
4
5Name Strings
6
7    GL_ARB_shader_atomic_counters
8
9Contact
10
11    Bill Licea-Kane ( bill.licea-kane 'at' amd.com )
12
13Contributors
14
15    Barthold Lichtenbelt, NVIDIA
16    Chris Dodd, NVIDIA
17    Eric Werness, NVIDIA
18    Graham Sellers, AMD
19    Greg Roth, NVIDIA
20    Jeff Bolz, NVIDIA
21    Nick Haemel, AMD
22    Pat Brown, NVIDIA
23    Pierre Boudier, AMD
24    Piers Daniell, NVIDIA
25
26Notice
27
28    Copyright (c) 2011-2013 The Khronos Group Inc. Copyright terms at
29        http://www.khronos.org/registry/speccopyright.html
30
31Specification Update Policy
32
33    Khronos-approved extension specifications are updated in response to
34    issues and bugs prioritized by the Khronos OpenGL Working Group. For
35    extensions which have been promoted to a core Specification, fixes will
36    first appear in the latest version of that core Specification, and will
37    eventually be backported to the extension document. This policy is
38    described in more detail at
39        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
40
41Status
42
43    Complete. Approved by the ARB on 2011/06/20.
44    Approved by the Khronos Promoters on 2011/07/29.
45
46Version
47
48    Last Modified Date: July 30, 2012
49    Author Revision: 31
50
51Number
52
53    ARB Extension #114
54
55Dependencies
56
57    This extension is written against the OpenGL 4.1 (core) specification
58    and the GLSL 4.10.6 specification.
59
60    OpenGL 3.0 is required.
61
62
63Overview
64
65    This extension provides a set of atomic counters.
66
67    This extension provides GLSL built-in functions to
68    query and increment/decrement these atomic counters.
69
70    This enables a shader to write to unique offsets
71    (append to a buffer object) or read from unique offsets
72    (consume from a buffer object).
73
74    Opaque handles to atomic counters are declared
75    at global scope and are qualified with the uniform qualifier.
76
77    Unlike other user-defined uniforms declared at global scope,
78    they take NO storage from the default partition, they have
79    NO location, and they may NOT be set with the Uniform* commands.
80    Atomic counters may also NOT be grouped into uniform blocks.
81
82    Active atomic counters can be discovered by the commands
83    GetUniformIndices, GetActiveUniformName, GetActiveUniform
84    and GetActiveUniformsiv.
85
86    Like samplers, the opaque handles of the atomic counters
87    and are ONLY used in some GLSL built-in functions.
88
89    The atomic counters pointed to by the opaque handles
90    are bound to buffer binding points and buffer offsets
91    through the layout qualifiers in the shading language,
92    or they are implicitly assigned by the compiler.
93
94    Through the OpenGL API, buffer objects may be
95    bound to these binding points with BindBufferBase
96    or BindBufferRange.
97
98    The contents of the atomic counters are stored
99    in the buffer objects.  The contents of atomic
100    counters may be set and queried with buffer object
101    manipulation functions (e.g. BufferData,
102    BufferSubData, MapBuffer or MapBufferRange).
103
104
105IP Status
106
107    No known IP claims.
108
109New Procedures and Functions
110
111    void GetActiveAtomicCounterBufferiv
112      (uint program, uint bufferIndex, enum pname, int *params);
113
114New Types
115
116    None.
117
118New Tokens
119
120    Accepted by the <target> parameter of BindBufferBase and BindBufferRange:
121
122        ATOMIC_COUNTER_BUFFER                           0x92C0
123
124    Accepted by the <pname> parameter of GetBooleani_v, GetIntegeri_v,
125    GetFloati_v, GetDoublei_v, GetInteger64i_v, GetBooleanv, GetIntegerv,
126    GetInteger64v, GetFloatv, GetDoublev, and GetActiveAtomicCounterBufferiv:
127
128       ATOMIC_COUNTER_BUFFER_BINDING                    0x92C1
129
130    Accepted by the <pname> parameter of GetIntegeri_64v:
131
132       ATOMIC_COUNTER_BUFFER_START                      0x92C2
133       ATOMIC_COUNTER_BUFFER_SIZE                       0x92C3
134
135    Accepted by the <pname> parameter of GetActiveAtomicCounterBufferiv:
136
137       ATOMIC_COUNTER_BUFFER_DATA_SIZE                  0x92C4
138       ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS     0x92C5
139       ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES        0x92C6
140       ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER          0x92C7
141       ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER    0x92C8
142       ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9
143       ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER        0x92CA
144       ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER        0x92CB
145
146    Accepted by the <pname> parameter of GetBooleanv, GetIntegerv,
147    GetInteger64v, GetFloatv, and GetDoublev:
148
149       MAX_VERTEX_ATOMIC_COUNTER_BUFFERS                0x92CC
150       MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS          0x92CD
151       MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS       0x92CE
152       MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS              0x92CF
153       MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS              0x92D0
154       MAX_COMBINED_ATOMIC_COUNTER_BUFFERS              0x92D1
155
156       MAX_VERTEX_ATOMIC_COUNTERS                       0x92D2
157       MAX_TESS_CONTROL_ATOMIC_COUNTERS                 0x92D3
158       MAX_TESS_EVALUATION_ATOMIC_COUNTERS              0x92D4
159       MAX_GEOMETRY_ATOMIC_COUNTERS                     0x92D5
160       MAX_FRAGMENT_ATOMIC_COUNTERS                     0x92D6
161       MAX_COMBINED_ATOMIC_COUNTERS                     0x92D7
162
163       MAX_ATOMIC_COUNTER_BUFFER_SIZE                   0x92D8
164       MAX_ATOMIC_COUNTER_BUFFER_BINDINGS               0x92DC
165
166    Accepted by the <pname> parameter of GetProgramiv:
167
168       ACTIVE_ATOMIC_COUNTER_BUFFERS                    0x92D9
169
170    Accepted by the <pname> parameter of GetActiveUniformsiv:
171
172       UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX              0x92DA
173
174    Returned in <params> by GetActiveUniform and GetActiveUniformsiv:
175
176       UNSIGNED_INT_ATOMIC_COUNTER                      0x92DB
177
178
179Additions to Chapter 2 of the OpenGL 4.1 (Core Profile) Specification
180(OpenGL Operation)
181
182Changes to Section 2.9 Buffer Objects
183
184Add to table 2.8 (p. 41)
185
186    Target Name                Purpose              Described in section(s)
187    ---------------------  ----------------------   -----------------------
188    ATOMIC_COUNTER_BUFFER  Atomic counter storage          2.11.8
189
190Changes to Section Binding Buffer Objects to Indexed Targets
191
192Change end of first sentence in section, p. 42
193
194    ...target must be ATOMIC_COUNTER_BUFFER, TRANSFORM_FEEDBACK_BUFFER
195    or UNIFORM_BUFFER.
196
1972.11.7 Uniform Variables
198
199Replace third sentence of paragraph one in the section, p. 72
200beginning with "Uniforms are program..."
201
202    Uniforms, except for subroutine uniforms, are program...
203
204Replace first sentence of paragraph two in the section, p. 72
205beginning with "Sets of uniforms can be..."
206
207    Sets of uniforms, except for samplers, subroutine uniforms and
208    atomic counters, can be grouped into <uniform blocks>.
209
210Modify first sentence of first paragraph, p. 73
211beginning with "The amount of storage..."
212
213    The amount of storage available for uniform variables,
214    except for subroutine uniforms and atomic counters,
215    in the default uniform block...
216
217Modify first sentence of second paragraph, p. 73
218beginning with "When a program..."
219
220    When a program is successfully linked, all active
221    uniforms, except for atomic counters, ...
222
223Insert a pragraph prior to third paragraph, p. 73
224beginning with "Similary, when a program..."
225
226    Similarly, when a program is successfully linked,
227    all active atomic counters are assigned bindings,
228    offsets (and strides for arrays of atomic counters)
229    according to layout rules described below.  Atomic
230    counter uniform buffer objects provide the storage for
231    atomic counters, so the values of atomic counters
232    may be changed by modifying the contents of the
233    buffer object using commands such as BufferData,
234    BufferSubData, MapBuffer, and UnmapBuffer.  Atomic
235    counters are not assigned a location and may not be
236    modified using the Uniform* commands.  The bindings,
237    offsets, and strides belonging to atomic counters
238    of a program object are invalidated and new ones
239    assigned after each successful re-link.
240
241
242Modify the final line on paragraph continuing on p. 74
243ending "or if <name> is associated with a named uniform block."
244
245    ... if <name> is associated with an atomic counter,
246    or if <name> is associated with a named uniform block.
247
248Insert section prior to the last paragraph on p. 76,
249begining with "Each active uniform, whether in a named..."
250
251    In programs with active atomic counter uniforms, each buffer object
252    binding point associated with one or more active atomic counters is
253    considered an active atomic counter buffer.  Information about the set of
254    active atomic counter buffers for a program can be obtained by calling
255
256      void GetActiveAtomicCounterBufferiv
257        ( uint program, uint bufferIndex, enum pname, int *params );
258
259    <program> is the name of a program object for which the
260    command LinkProgram has been issued in the past. It is
261    not necessary for <program> to have been linked successfully.
262    The link could have failed because the number of active
263    active atomic counters exceeded implementation-dependent limits.
264
265    <bufferIndex> specifies the index of an active atomic counter buffer and
266    must be in the range zero to the value of ACTIVE_ATOMIC_COUNTER_BUFFERS-1.
267    The value of ACTIVE_ATOMIC_COUNTER_BUFFERS for <program> indicates the
268    number of active atomic counter buffers and can be queried with
269    GetProgramiv (see section 6.1.12).  If <bufferIndex> is greater than or
270    equal to the value of ACTIVE_ATOMIC_COUNTER_BUFFERS, the error
271    INVALID_VALUE is generated.
272
273    If no error occurs, the parameter(s) specified by <pname> are
274    returned in <params>. Otherwise, nothing will be written to
275    <params>.
276
277    If <pname> is ATOMIC_COUNTER_BUFFER_BINDING, then the index of the atomic
278    counter buffer binding point associated with the active atomic counter
279    buffer <bufferIndex> for <program> is returned.
280
281    If <pname> is ATOMIC_COUNTER_BUFFER_DATA_SIZE, then the
282    implementation-dependent minimum total buffer object size, in
283    basic machine units, required to hold all active atomic counters
284    in the atomic counter buffer identified by
285    <bufferIndex> is returned.
286
287    The total amount of buffer object storage accessible in any
288    given atomic counter buffer is subject to an implementation-dependent
289    limit. The maximum amount of storage accessible to atomic counters,
290    in basic machine units, can be queried by calling GetIntegerv with the constant
291    MAX_ATOMIC_COUNTER_BUFFER_SIZE. If the amount of storage required for a
292    atomic counter buffer exceeds this limit, a program may fail
293    to link.
294
295    If <pname> is ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS, then the
296    number of active atomic counter variables associated with the atomic
297    counter buffer identified by <bufferIndex> is returned.
298
299    If <pname> is ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES,
300    then a list of the active atomic counter indices for the atomic counter
301    buffer identified by <bufferIndex> is returned. The number of
302    elements that will be written to <params> is the value of
303    ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS for <bufferIndex>.
304
305    If <pname> is ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER,
306    ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER,
307    UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER,
308    ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER, or
309    ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER, then a boolean
310    value indicating whether the atomic counter buffer identified by
311    <bufferIndex> is referenced by the vertex, tessellation control,
312    tessellation evaluation, geometry, or fragment programming stages of
313    <program>, respectively, is returned."
314
315Modify first sentence of last paragraph on p. 76,
316beginning with "Each active uniform, whether in a named..."
317
318    Each active uniform, except for subroutine uniforms,
319    whether in a the default block, in a named uniform block, or
320    an atomic counter...
321
322Modify first sentence of the fourth paragraph on p. 77
323beginning with "The name of an active..."
324
325    The name of an active uniform, except for subroutine
326    uniforms, may be querried...
327
328
329Replace the last paragraph on p. 77
330beginning with "Each uniform variable..."
331
332    Each active uniform variable, except subroutine uniforms,
333    is broken down into one or more strings using the "." (dot)
334    and "[]" operators, if necessary, to the point that it is
335    legal to pass each string back into GetUniformIndices.
336
337Modify first sentence of first paragraph on p. 78
338beginning with "Information about active uniforms..."
339
340    Information about active uniforms, except for
341    subroutine uniforms, can be...
342
343Replace the fourth paragraph on p. 78
344beginning with "Each uniform variable..."
345
346    Each active uniform variable, except subroutine uniforms,
347    is broken down into one or more strings using the "." (dot)
348    and "[]" operators, if necessary, to the point that it is
349    legal to pass each string back into GetUniformIndices.
350
351Modify the last paragraph
352
353Add to Table 2.13, p. 81
354
355    Type Name Token              Keyword      Attrib  Xfb
356    ---------------------------  -----------  ------  ---
357    UNSIGNED_INT_ATOMIC_COUNTER  atomic_uint
358
359Modify description of UNIFORM_OFFSET query in GetActiveUniformsiv, p. 82
360
361    If <pname> is UNIFORM_OFFSET, then an array of buffer offsets is returned.
362    For uniforms in a named uniform block, the returned value will be its
363    offset, in basic machine units, relative to the beginning of the uniform
364    block in the buffer object data store.  For atomic counter uniforms, the
365    returned value will be its offset relative to the beginning of its active
366    atomic counter buffer.  For all other uniforms, an offset of -1 will be
367    returned.
368
369    If <pname> is UNIFORM_ARRAY_STRIDE, then an array of strides between array
370    elements in buffer object storage is returned.  For uniforms in named
371    uniform blocks and for uniforms declared as atomic counters, the stride is
372    the difference, in basic machine units, of the offsets of consecutive
373    elements in an array, or zero for uniforms not declared as an array.  For
374    all other uniforms, a stride of -1 will be returned.
375
376Add prior to "Loading Uniform Values In The Default Uniform Block", p. 83
377
378    If <pname> is UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX, then an array
379    identifying the active atomic counter buffer index of each of the uniforms
380    specified by the corresponding array of <uniformIndices> is returned.  For
381    uniforms other than atomic counters, the returned buffer index is -1.  The
382    returned indices can be passed to GetActiveAtomicCounterBufferiv to query
383    properties of the associated buffer, and not necessarily the binding point
384    specified in the uniform declaration.
385
386Modify first sentence of first new paragraph on p. 83
387beginning with "To load values into the uniform variables..."
388
389    To load values into the uniform variables of the default uniform block
390    of the active program object, except for subroutine uniforms and atomic
391    counters, ..."
392
393Modify first sentence of the fifth paragraph on p. 84
394beginning with "For all other uniform types..."
395
396    For all other uniform types, except for subroutine
397    uniforms and atomic counters, ...
398
399
400Add new unnumbered subsections at the end of the section, p. 90
401
402    Atomic Counter Buffers
403
404    The values of atomic counters are backed by buffer object storage.
405    The mechanisms for accessing individual atomic counters in a buffer object
406    and connecting to an atomic counter are described in this section.
407
408    There is a set of implementation-dependent maximums for the number
409    of active atomic counter buffers referenced by each shader. If the
410    number of atomic counter buffers referenced by any shader in the program
411    exceeds its corresponding limit, the program will fail to link. The limits
412    for vertex, tessellation control, tessellation evaluation, geometry, and
413    fragment shaders can be obtained by calling GetIntegerv with pname values
414    of MAX_VERTEX_ATOMIC_COUNTER_BUFFERS, MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS,
415    MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS, MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS,
416    or MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS, respectively.
417
418    Additionally, there is an implementation-dependent limit on the sum of the
419    number of active atomic counter buffers used by each shader of a
420    program. If an atomic counter buffer is used by multiple shaders,
421    each such use counts separately against this combined limit. The combined
422    atomic counter buffer use limit can be obtained by calling
423    GetIntegerv with a <pname> of MAX_COMBINED_ATOMIC_COUNTER_BUFFERS.
424
425    Atomic Counter Buffer Object Storage
426
427    Atomic counters stored in buffer objects are represented in memory
428    as follows:
429
430    * Members of type atomic_uint are extracted from a buffer object by
431    reading a single uint-typed value at the specified offset.
432
433    * Arrays of type atomic_uint are stored in memory by element order,
434    with array element member zero at the lowest offset.  The difference
435    in offsets between each pair of elements in the array in basic machine
436    units is referred to as the array stride, and is constant across the
437    entire array.  The stride can be queried by calling GetIntegerv with
438    a <pname> of UNIFORM_ARRAY_STRIDE after a program is linked.
439
440    Atomic Counter Buffer Bindings
441
442    The value of an active atomic counter is extracted from or written to the
443    data store of a buffer object bound to one of an array of atomic counter
444    buffer binding points. The number of binding points can be queried by
445    calling GetIntegerv with a <pname> of MAX_ATOMIC_COUNTER_BUFFER_BINDINGS.
446
447    Regions of buffer objects are bound as storage for atomic counters by calling
448    one of the commands BindBufferRange or BindBufferBase (see section 2.9.1)
449    with <target> set to ATOMIC_COUNTER_BUFFER. In addition to the general errors
450    described in section 2.9.1, BindBufferBase and BindBufferRange will generate an INVALID_VALUE
451    error if <index> is greater than or equal to the value of MAX_ATOMIC_COUNTER_BUFFER_BINDINGS,
452    and BindBufferRange will generate an INVALID_VALUE error if <offset> is
453    not a multiple of four.
454
455    Each of a program's active atomic counter buffer bindings has a corresponding
456    atomic counter buffer binding point. This binding point is established
457    with the layout qualifier in the shader text, either explicitly or implicitly,
458    as described in the Shading Language specification.
459
460    When executing shaders that access atomic counters, each active atomic
461    counter buffer must be populated with a buffer object with a size no
462    smaller than the minimum required size for that buffer (the value of
463    ATOMIC_COUNTER_BUFFER_DATA_SIZE).  For binding points populated by
464    BindBufferRange, the size in question is the value of the <size>
465    parameter.  If any active atomic counter buffer is not backed by a
466    sufficiently large buffer object, the results of shader execution are
467    undefined, and may result in GL interruption or termination.
468
469
470Add to Section 2.11.11 Shader Execution, p. 102, inserting before Shader Inputs
471
472Atomic Counter Access
473
474    Shaders have the ability to set and get atomic counters.  The maximum number
475    of atomic counters available to shaders are the values of the implementation
476    dependent constants
477
478    * MAX_VERTEX_ATOMIC_COUNTERS (for vertex shaders),
479    * MAX_TESS_CONTROL_ATOMIC_COUNTERS (for tessellation control shaders),
480    * MAX_TESS_EVALUATION_ATOMIC_COUNTERS (for tessellation evaluation shaders),
481    * MAX_GEOMETRY_ATOMIC_COUNTERS (for geometry shaders), and
482    * MAX_FRAGMENT_ATOMIC_COUNTERS (for fragment shaders).
483
484   All active shaders combined cannot use more than the value of
485   MAX_COMBINED_ATOMIC_COUNTERS atomic counters. If more than one
486   pipeline stage accesses the same atomic counter, each such
487   access counts separately against the MAX_COMBINED_ATOMIC_COUNTERS limit.
488
489
490Additions to Chapter 6 of the OpenGL 4.1 (Core Profile) Specification
491(State and State Requests)
492
493Add to the end of section 6.1.8 (Buffer Object Queries)
494
495    To query which buffer objects are bound to the array of transform
496    feedback binding points and will be used when transform feedback is
497    active, call GetIntegeri\_v with <param> set to
498    TRANSFORM_FEEDBACK_BUFFER_BINDING. <index> must be in the range zero to
499    the value of MAX_TRANSFORM_FEEDBACK_BUFFERS minus one. The name of the
500    buffer object bound to <index> is returned in <values>. If no buffer
501    object is bound for <index>, zero is returned in <values>. The error
502    INVALID_VALUE is generated if <index> is greater than or equal to the
503    value of MAX_TRANSFORM_FEEDBACK_BUFFERS.
504
505    To query the starting offset or size of the range of each buffer object
506    binding used for transform feedback, call GetInteger64i_v with <param>
507    set to TRANSFORM_FEEDBACK_BUFFER_START or TRANSFORM_FEEDBACK_BUFFER_SIZE
508    respectively. <index> must be in the range 0 to the value of
509    MAX_TRANSFORM_FEEDBACK_BUFFERS minus one. If the parameter (starting
510    offset or size) was not specified when the buffer object was bound (e.g.
511    if bound with BindBufferBase), or if no buffer object is bound to
512    <index>, zero is returned. The error INVALID_VALUE is generated if
513    <index> is greater than or equal to the value of
514    MAX_TRANSFORM_FEEDBACK_BUFFERS}.
515
516Add to Section 6.1.12, immediately before the description of IsProgramPipeline
517(p. 335)
518
519    If <pname> is ACTIVE_ATOMIC_COUNTER_BUFFERS, the number of active atomic
520    counter buffers used by <program> is returned.
521
522Additions to Appendix A (Invariance)
523
524Add additional sentence to A.3 Invariance Rules, Rule 4 (p. 399)
525
526    Invariance is relaxed for shaders with side effects (such
527    as accessing atomic counters), see A.5, Atomic Counter Invariance.
528
529Add A.5 Atomic Counter Invariance
530
531    When using a program containing atomic counters, the following
532    invariance rules are intended to provide repeatability guarantees
533    but within certain constraints.
534
535    Rule 1  When a single shader type within a program accesses
536    an atomic counter with only atomicCounterIncrement, any individual
537    shader invocation is guaranteed to get a unique value returned.
538
539    Corollary 1 - Also holds true with atomicCounterDecrement.
540
541    Corollary 2 - This does not hold true for atomicCounter
542
543    Corollary 3 - Repeatability is relaxed.  While a unique
544    value is returned to the shader, even given the same
545    initial state vector and buffer contents, it is not guaranteed
546    that the *SAME* unique value will be returned for each individual
547    invocation of a shader (For example, on any single vertex, or
548    any single fragment).  It is wholly the shader writer's
549    responsibility to respect this constraint.
550
551    Rule 2  When two or more shader types within a program
552    access an atomic counter with only atomicCounterIncrement,
553    there is no repeatability of the ordering of operations between
554    stages.  For example, some number of vertices may be processed,
555    then some number of fragments may be processed.
556
557    Corollary 4 - This also holds true with atomicCounterDecrement
558    and atomicCounter.
559
560Additions to Appendix D (Shared Objects and Multiple Contexts)
561
562Modify D.3 (Propagating State Changes)
563
564    (add to list of bullets at the end of the section, p. 467)
565
566    * Rendering commands that trigger shader invocations, where
567      the shader performs built-in atomic counter functions.
568
569New State
570
571Add new table, labeled "Program Object State (cont.)" after Table 6.36, p. 377
572
573                                                             Initial
574    Get Value                         Type  Get Command      Value    Description                Sec.
575    -----------------------           ----  -----------      -------  ------------------------   -----
576    ACTIVE_ATOMIC_COUNTER_BUFFERS     Z+    GetProgramiv     0        Number of active atomic    2.11.7
577                                                                      counter buffers used
578                                                                      by a program
579    ATOMIC_COUNTER_BUFFER_BINDING     nxZ+  GetActiveAtomic- -        Binding point associated   2.11.7
580                                            CounterBufferiv           with an active atomic
581                                                                      counter buffer
582    ATOMIC_COUNTER_BUFFER_DATA_SIZE   nxZ+  GetActiveAtomic- -        Minimum size required by   2.11.7
583                                            CounterBufferiv           an active atomic counter
584                                                                      buffer
585    ATOMIC_COUNTER_BUFFER_ACTIVE_     nxZ+  GetActiveAtomic- -        Number of active atomic    2.11.7
586      ATOMIC_COUNTERS                       CounterBufferiv           counters in an active
587                                                                      atomic counter buffer
588    ATOMIC_COUNTER_BUFFER_ACTIVE_    mxnxZ+ GetActiveAtomic- -        List of active atomic      2.11.7
589      ATOMIC_COUNTER_INDICES                CounterBufferiv           counters in an active
590                                                                      atomic counter buffer
591    ATOMIC_COUNTER_BUFFER_            nxB   GetActiveAtomic- FALSE    Active atomic counter      2.11.7
592      REFERENCED_BY_VERTEX                  CounterBufferiv           buffer has a counter used
593      SHADER                                                          by vertex shaders
594    ATOMIC_COUNTER_BUFFER_            nxB   GetActiveAtomic- FALSE    Active atomic counter      2.11.7
595      REFERENCED_BY_TESS_CONTROL            CounterBufferiv           buffer has a counter used
596      SHADER                                                          by tess. control shaders
597    ATOMIC_COUNTER_BUFFER_            nxB   GetActiveAtomic- FALSE    Active atomic counter      2.11.7
598      REFERENCED_BY_TESS_EVALUTION          CounterBufferiv           buffer has a counter used
599      SHADER                                                          by tess. evaluation shaders
600    ATOMIC_COUNTER_BUFFER_            nxB   GetActiveAtomic- FALSE    Active atomic counter      2.11.7
601      REFERENCED_BY_GEOMETRY                CounterBufferiv           buffer has a counter used
602      SHADER                                                          by geometry shaders
603    ATOMIC_COUNTER_BUFFER_            nxB   GetActiveAtomic- FALSE    Active atomic counter      2.11.7
604      REFERENCED_BY_FRAGMENT                CounterBufferiv           buffer has a counter used
605      SHADER                                                          by fragment shaders
606    UNIFORM_ATOMIC_COUNTER_BUFFER_    nxZ+  GetActive-       -        Active atomic counter      2.11.7
607      INDEX                                 Uniformsiv                buffer associated with an
608                                                                      active uniform
609
610Add new table, labeled "Atomic Counter State", after Table 6.39, p. 380
611
612                                                             Initial
613    Get Value                         Type  Get Command      Value    Description                Sec.
614    -----------------------           ----  -----------      -------  ------------------------   -----
615    ATOMIC_COUNTER_BUFFER_BINDING     Z+    GetIntegerv      0        Current value of generic   2.9.9
616                                                                      atomic counter buffer
617                                                                      binding
618    ATOMIC_COUNTER_BUFFER_BINDING     n*Z+  GetIntegeri_v    0        Buffer object bound        2.9.9
619                                                                      to each atomic counter
620                                                                      buffer binding point
621    ATOMIC_COUNTER_BUFFER_START       n*Z+  GetInteger64i_v  0        Start offset of            2.9.9
622                                                                      binding range for each
623                                                                      atomic counter buffer
624    ATOMIC_COUNTER_BUFFER_SIZE        n*Z+  GetInteger64i_v  0        Size of binding range for  2.9.9
625                                                                      each atomic counter buffer
626
627New Implementation Dependent State
628
629
630Add to Table 6.46, Implementation Dependent Vertex Shader Limits, p. 387:
631
632    Get Value                                  Type  Get Command    Minimum Value  Description                Sec.
633    -----------------------                    ----  -----------    -------------  -------------------------  -----
634    MAX_VERTEX_ATOMIC_COUNTER_BUFFERS          Z+    GetIntegerv    0              Number of atomic counter   2.11.7
635                                                                                   buffers accessed by a
636                                                                                   vertex shader
637    MAX_VERTEX_ATOMIC_COUNTERS                 Z+    GetIntegerv    0              Number of atomic counters  2.11.11
638                                                                                   accessed by a vertex
639                                                                                   shader
640Add to Table 6.47, Implementation Dependent Tesselation Shader Limits, p. 388:
641
642    Get Value                                  Type  Get Command    Minimum Value  Description                Sec.
643    -----------------------                    ----  -----------    -------------  -------------------------  -----
644    MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS    Z+    GetIntegerv    0              Number of atomic counter   2.11.7
645                                                                                   buffers accessed by a
646                                                                                   tesselation control shader
647    MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS Z+    GetIntegerv    0              Number of atomic counter   2.11.7
648                                                                                   buffers accessed by a
649                                                                                   tesselation evaluation shader
650    MAX_TESS_CONTROL_ATOMIC_COUNTERS           Z+    GetIntegerv    0              Number of atomic counters  2.11.11
651                                                                                   accessed by a tesselation
652                                                                                   control shader
653    MAX_TESS_EVALUATION_ATOMIC_COUNTERS        Z+    GetIntegerv    0              Number of atomic counters  2.11.11
654                                                                                   accessed by a tesselation
655                                                                                   evaluation shader
656Add to Table 6.48, Implementation Dependent Geometry Shader Limits, p. 389:
657
658    Get Value                                  Type  Get Command    Minimum Value  Description                Sec.
659    -----------------------                    ----  -----------    -------------  -------------------------  -----
660    MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS        Z+    GetIntegerv    0              Number of atomic counter   2.11.7
661                                                                                   buffers accessed by a
662                                                                                   geometry shader
663    MAX_GEOMETRY_ATOMIC_COUNTERS               Z+    GetIntegerv    0              Number of atomic counters  2.11.11
664                                                                                   accessed by a geometry
665                                                                                   shader
666Add to Table 6.49, Implementation Dependent Fragment Shader Limits, p. 390:
667
668    Get Value                                  Type  Get Command    Minimum Value  Description                Sec.
669    -----------------------                    ----  -----------    -------------  -------------------------  -----
670    MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS        Z+    GetIntegerv    1              Number of atomic counter   2.11.7
671                                                                                   buffers accessed by a
672                                                                                   fragment shader
673    MAX_FRAGMENT_ATOMIC_COUNTERS               Z+    GetIntegerv    8              Number of atomic counters  2.11.11
674                                                                                   accessed by a fragment
675                                                                                   shader
676Add to Table 6.50 Implementation Dependent Aggregate Shader Limits, p. 391:
677
678    Get Value                                  Type  Get Command    Minimum Value  Description                Sec.
679    -----------------------                    ----  -----------    -------------  -------------------------  -----
680    MAX_ATOMIC_COUNTER_BUFFER_BINDINGS         Z+    GetIntegerv    1              Max. number of atomic      2.9.9
681                                                                                   counter buffer bindings
682    MAX_ATOMIC_COUNTER_BUFFER_SIZE             Z+    GetIntegerv    32
683                                                                                   machine units of an
684                                                                                   atomic counter buffer
685    MAX_COMBINED_ATOMIC_COUNTER_BUFFERS        Z+    GetIntegerv    1              Max. number of atomic      2.11.7
686                                                                                   counter buffers per
687                                                                                   program
688    MAX_COMBINED_ATOMIC_COUNTERS               Z+    GetIntegerv    8              Max. number of atomic      2.11.11
689                                                                                   counter uniforms per
690                                                                                   program
691
692
693
694Additions to the OpenGL Shading Langauge 4.10.6 Specification
695
696    Including the following line in a shader can be used to control the
697    language features described in the extension:
698
699      #extension GL_ARB_shader_atomic_counters : <behavior>
700
701    where <behavior> is as specified in section 3.3.
702
703    A new preprocessor #define is added to the OpenGL Shading Language:
704
705      #define GL_ARB_shader_atomic_counters 1
706
707Additions to Chapter 3 of the OpenGL Shading Language 4.10.6 Specification
708
709Add to 3.6 Keywords (pp. 13-15)
710
711    atomic_uint
712
713Additions to Chapter 4 of the OpenGL Shading Language 4.10.6 Specification
714
715Add to Section 4.1 Basic Types
716
717    Unsigned Integer Counter Types (opaque)
718
719    Type         Meaning
720    atomic_uint  a handle for accessing an unsigned integer atomic counter
721
722Insert Section 4.1.8 Atomic Counters (existing 4.1.8 becomes 4.1.9, and so on)
723
724    4.1.8 Atomic Counters
725
726    Atomic Counter types (e.g. atomic_uint) are effectively opaque handles to counters.
727    They are used with the built-in atomic counter functions (described in section 8.10
728    "Atomic Counter Functions") to specify which counter to access.  They can only be
729    declared as function parameters or uniform-qualified global variables.
730
731    Except for array indexing, structure field selection, and parenthesis,
732    counters are not allowed to be operands in expressions.  Counters aggregated into
733    arrays within a shader (using square brackets []) can only be indexed with dynamically
734    uniform integral expressions, otherwise results are undefined.  Counters cannot be
735    treated as l-values; hence cannot be used as out or inout function parameters, nor
736    can they be assigned into.
737
738
739Modify last sentence of first paragraph of section 4.3.5, p. 36
740beginning with "Sampler types cannot..."
741
742    Sampler types and atomic counter types cannot..."
743
744Insert Section 4.3.6 Atomic Counters.  (Existing 4.3.6 becomes 4.3.7, and so on)
745
746    4.3.6  Uniform
747
748    The uniform qualifier is used to declare global opaque handles (to counters)
749    where the handles are the same across the entire primitive being processed.
750    All uniform variables are read-only and are initialized at link time.
751
752    It is an error to write to a uniform-qualified variable.
753
754    For example,
755
756        layout( binding=2, offset=0 ) uniform atomic_uint a;
757
758    will establish that the opaque handle to the atomic counter "a"
759    will be bound to atomic counter buffer binding 2 at offset 0.
760
761    There is an implementation dependent limit to the number of uniforms that
762    can be used for each type of shader and if this is exceeded it will cause a
763    compile-time or link-time error.  Uniform variables that are declared but
764    not used may or may not count against this limit.
765
766    If multiple shaders are linked together, then they will share a single
767    global uniform name space, including within the language as well as across
768    languages.  Hence, the type of uniform variables with the
769    same name must match across all shaders that are linked into a single program.
770
771    It is legal for some shaders to provide a layout qualifier for a uniform
772    variable of the same name, while another shader does not provide
773    a layout qualifier for a uniform variable of the same name, but if provided,
774    all provided layout qualifiers must be equal for a uniform variable of the
775    same name, and if not provided, all implicitly provided layout qualifiers must
776    be equal for a uniform variable of the same name.
777
778
779Add Section 4.3.8.4 Uniform Layout Qualifiers
780
781    Layout qualifiers can be used on uniform declarations.  The uniform qualifier
782    identifiers for uniforms are
783
784    layout-qualifier-id
785        binding = integer-constant
786        offset = integer-constant
787
788    For example,
789
790        layout(binding = 2, offset = 4) uniform atomic_uint foo;
791
792    will establish that the atomic counter foo has a binding to
793    buffer binding point 2 and an offset of 4 basic machine units
794    in that buffer.  The offset will be post-incremented by the
795    size of the uniform (for atomic_uint, 4 basic machine units).
796
797    A subsequent uniform declaration will inherit the binding,
798    and offset (perhaps post-incremented).  For example, a
799    subsequent declaration of,
800
801         uniform atomic_uint bar;
802
803    will establish that the atomic counter bar has a binding to
804    buffer binding point 2 and an offset of 8 basic machine units
805    in that buffer.  The offset will be post-incremented by
806    the size of the uniform (again, for atomic_uint, 4 basic
807    machine units).
808
809    If the limit on the maximum number of bindings is exceeded,
810    or if the limit of the maximum number of counters (either
811    per shader type or combined) is exceeded, it will be a link
812    error.
813
814    It is a compile error to bind an atomic counter with
815    a value greater than or equal to gl_MaxAtomicCounterBindings.
816
817Add Section 4.3.8.3 Uniform Layout Qualifiers prior to
818existing 4.3.8.3 Uniform Block Layout Qualifiers, and renumber
819subsequent sections
820
821    Layout qualifiers can be used on uniform declarations.  The layout
822    qualifiers identifiers for uniforms are
823
824    layout-qualifier-id
825        binding = integer-constant
826        offset = integer-constant
827
828    Uniform layout qualifiers can be declared for global scope or on a single
829    uniform declaration.
830
831    Default layouts are established at global scope for uniforms as
832
833        layout (layout-qualifier-id-list) uniform;
834
835    When this is done, the previous default qualification is first inherited and
836    then overridden as per the override rules listed below.  The result becomes
837    the new default qualification scoped to subsequent uniform block definitions.
838
839    The initial state of compiliation is as if the following were declared:
840
841        layout(binding=0, offset=0) uniform;
842
843    Explicitly declaring this in a shader will return defaults back to their
844    initial state.
845
846    Uniforms can be declared with optional layout qualifiers.  As with global
847    layout declarations, uniform layout qualification first inherits from the
848    current default qualification and then overrides it.
849
850    When multiple arguments are listed in a layout declaration, the affect will
851    be the same as if they were declared one at a time, in order from left to
852    right, each in turn inheriting from and overriding the result from the
853    previous qualification.
854
855    For each uniform element, the then current default layout qualifiers will
856    be applied, together with any prior post-increments of offset, if applicable,
857    then the offset will be post-incremented by the size of the uniform, in
858    basic machine units.
859
860    Uniforms may share the same binding, but if a binding is shared, each
861    offset must be explicitly or implicitly unique.
862
863    For example a valid uniform declarations:
864
865    layout(binding=3, offset=4) uniform;
866
867    uniform atomic_uint                   thunderhead; // offset = 4
868    uniform atomic_uint                   stratogirl;  // offset = 8
869    layout(binding=3) uniform atomic_uint metalman;    // binding matches,
870                                                       // offset = 12
871    layout(offset=20) uniform atomic_uint dynaguy;     // offset = 20
872    uniform atomic_uint                   splashdown;  // offset = 24
873
874
875    Example of an invalid uniform declarations;
876
877    layout(binding=1, offset=0) batman;        // OK
878    layout(binding=2, offset=0) robin;         // OK
879    layout(binding=1, offset=0) catwoman;      // error, offsets
880                                               // must not be shared
881                                               // between batman and
882                                               // catwoman
883
884Additions to Chapter 7 of the OpenGL Shading Language 4.10.6 Specification
885(Built-in Variables)
886
887Add to Section 7.4, Built-In Constants
888
889const int gl_MaxVertexAtomicCounters = 0;          // minimum maximum
890const int gl_MaxTessControlAtomicCounters = 0;     // minimum maximum
891const int gl_MaxTessEvaluationAtomicCounters = 0;  // minimum maximum
892const int gl_MaxGeometryAtomicCounters = 0;        // minimum maximum
893const int gl_MaxFragmentAtomicCounters = 8;        // minimum maximum
894const int gl_MaxCombinedAtomicCounters = 8;        // minimum maximum
895const int gl_MaxAtomicCounterBindings = 1;         // minimum maximum
896
897Additions to Chapter 8 of the OpenGL Shading Language 1.50 Specification
898(Built-in Functions)
899
900Add Section 8.10  Atomic Counter Functions (existing 8.10 becomes 8.11, and so on)
901
902    8.10  Atomic Counter Functions
903
904    Atomic counter functions have exclusive access to any single counter, perform
905    an atomic operation, then release exclusive access to that counter,
906    as-if a single step.
907    Any other atomic counter function may access that single counter only after any
908    earlier atomic operation is completed.
909
910    The value returned by an atomic counter function is the value of
911    an atomic counter, which may be:
912    returned and incremented in an atomic operation,
913    or decremented and returned in an atomic operation,
914    or simply returned.
915
916    The underlying counter is a 32-bit unsigned integer.  Increments and decrements
917    at the limit of the range will wrap to [0, 2^32-1].
918
919
920    Syntax                        Description
921    uint atomicCounterIncrement   Increments <counter> atomically, returning
922      ( atomic_uint counter );    the value prior to the increment operation.
923
924    uint atomicCounterDecrement   Decrements <counter> atomically, returning
925      ( atomic_uint counter );    the value after the decrement operation.
926
927    uint atomicCounter            Returns the value of <counter>.
928      ( atomic_uint counter );
929
930
931Sample Code
932
933    layout( binding=2)            uniform atomic_uint a;
934    layout( binding=2, offset=4 ) uniform atomic_uint b;
935    layout( binding=5, offset=0 ) uniform atomic_uint c;
936
937    // ...
938
939    uint foo = atomicCounterIncrement( a ); // get the counter value, then increment the counter
940                                            // atomic operation
941    uint bar = atomicCounterDecrement( b ); // decrement the counter value, then get the counter
942                                            // atomic operation
943    uint baz = atomicCounter( c );          // get the counter value
944                                            // atomic operation
945
946Issues
947
9481 -  Do we need an indirection table between the counters and the shaders?
949     (Similar to Samplers?  VertexAttribBinding?  Uniform blocks?)
950
951     Yes.  This draft introduces opaque counters similar to samplers.
952     However, there is no Uniform-like API means of setting them to a
953     texture unit or attribute-like API of binding them to a location.
954     Instead, we have uniforms, which are a storage qualifier at
955     global scope, and which use layout qualifiers to bind them
956     to buffer binding points.  A GetActiveUniforms API is
957     used to retrieve the names of the counters, and their
958     bindings, and other useful information.
959
9602 -  What shader stages are these available in?
961
962     Resolved.  All stages.
963
9643 -  Can the counters be operated on in the shading language?
965
966     Resolved:  Not directly.  But indirectly, probably not in
967     any meaningful way.  But there are no restrictions placed on the
968     values once they are returned to the shader.
969
9704 -  Where's issue 4?
971
972     Resolved.  It's here.
973
9745 - Can a single shader both increment and decrement an individual atomic
975    counter?
976
977     Resolved:  Yes, with caveats.  In order to provide a global unique
978     offset, a counter must *either* be incremented or decremented by a
979     shader.  The best way to think of this is that these are UNORDERED
980     increments and decrements.  However, there may be uses for these
981     atomic counters other than providing unique offsets.
982
983     We provide mechanism, not policy.  Shader coding conventions can
984     provide policy - there's little reason for the compiler to be involved
985     in enforcing.
986
9876 - Can multiple shaders in a program both increment and decrement an
988    individual atomic counter?
989
990     Resolved.  Yes, with the same caveats as above.
991
9927 -  Is there a maximum maximum number of counters?
993
994     Resolved.  No, implementations are free to support arbitrarily many
995     counters.  Implementations may set their own limits, though there are
996     specified minimum limits.
997
9988 -  Can a counter be queried, but not incremented/decremented in the shader?
999
1000     Resolved:  Yes.  (It's an increment of zero.  Or a decrement of zero.)
1001     Note that using a get without an increment or decrement will return
1002     a value that is *not* unique.
1003
1004     Again, we provide mechanism, not policy.
1005
10069 -  Can a counter be incremented/decremented by an arbitrary amount?
1007
1008     Resolved:  No.  Only by 1.  (Or 0.)
1009
101010 - Should append counters wrap on zero and overflow?
1011
1012     Resolved:  Wrap.  [0,2^32-1]
1013
101411 - What piece of state owns the atomic counters?
1015
1016     Resolved:  There is no context state, they must be backed
1017     by buffer objects.
1018
101912 - Can the atomic counters be shared between contexts?
1020
1021     Resolved:  Not directly, but they may be shared indirectly by sharing the
1022     buffer objects that back them.
1023
102413 - Should we be able to write atomic counters to a buffer object?
1025
1026     Resolved.  Yes.  (Note that buffer objects can be shared.
1027     The result of updating atomic counters in multiple contexts
1028     backed with the same buffer object is undefined.)
1029
103014 - If indexing an array of atomic_uints, can the index used diverge
1031     in a SIMD implementation?
1032
1033     Resolved.  No.  They must be dynamically uniform, similar
1034     to samplers.
1035
103615 - Should we provide "append buffer" functionality?
1037
1038     Resolved:  Yes, but by providing access to atomic counters.
1039     This provides the mechanism to do "append buffer" functionality,
1040     and more.
1041
104216 - What should this extension be called?
1043
1044     Resolved:  ARB_shader_atomic_counters.  It's primarily a shader
1045     extension, and it provides atomic_counters.
1046
104717 - What happens to shared buffer objects that are updated in
1048     more than one context by data-setting commands, including
1049     the built-in atomic counter functions?
1050
1051     Resolved:  They should follow the same rules as other shared
1052     buffer objects.  (That is, care must be taken when updating
1053     atomic counters in one context and using them in another
1054     context.)  Further, the atomic built-in functions are
1055     atomic in a single context, but there is no guarantee that
1056     they are atomic across contexts.
1057
105818 - Should there be one buffer binding for all counters, or a
1059     buffer binding per counter.
1060
1061     Resolved.  There should be a buffer binding (and offset)
1062     per counter.  Shaders may store multiple atomic counters in
1063     a single buffer binding.
1064
106519 - What about simultaneous use of buffer object at two
1066     binding points, where one is an atomic counter binding point?
1067
1068     Resolved.  We are going to be conservative and make
1069     such use undefined.
1070
107120 - Does atomic_uint type add any value?
1072
1073     Resolved.  Yes.  For a single program text, the opaque
1074     atomic_uint is just syntactic sugar.
1075     However, for multiple shaders bound to a shader target,
1076     only one shader must contain the locations.  This would
1077     permit an implementation to do fast relinking if
1078     a single shader is attached to an existing shader.
1079     (And display lists are just fine for optimizing
1080     texture loads.  [insert silly smiley face])
1081
1082     Also, when we do add api (not yet added) to query active
1083     atomic_uints in a shader, this provides additional benefits.
1084
108521 - Do we need api to query the atomic counter?
1086
1087     Resolved.  Earlier drafts had a traditional indexed get,
1088     which would be useful for debugging but not high performance.
1089     An alternative would be to add a query object to do asynchronos
1090     queries.  But note, that when these counters are backed by
1091     buffer objects, all the GetBufferSubData and/or MapBuffer
1092     just works.
1093
1094     This draft simply nukes the get.  (It is trivial to put it
1095     back in with a caveat.)  The existing buffer api should
1096     be used for high performance client side (cpu) access
1097     to atomic counters.
1098
109922 - Does AtomicCounter reset to zero:
1100     The context default counter state?
1101     The value in a buffer object bound to a counter?
1102     Both?
1103
1104     Resolved.  THERE IS NO DEFAULT CONTEXT STATE, only the
1105     buffer object bound, if any, is set.
1106
110723 - Does a BufferData to a buffer bound to counter set the value of:
1108     The buffer object?  (Obviously)
1109     The context default counter state bound that that buffer?
1110
1111     Resolved.  THERE IS NO DEFAULT CONTEXT STATE.
1112
111324 - Do we want an error (or undefined behavior) that says you
1114     can't draw while a mapped buffer is bound to one of these
1115     counters?
1116
1117     Resolved.  Undefined.
1118
111925 - Is a atomic_uint an "in" or a "uniform"?
1120
1121     Resolved.  "atomic_uint" variables are declared as uniforms at global
1122     scope.
1123
112426 - Can the active atomic counters for one program be stored in more than one
1125     buffer object?
1126
1127     Resolved.  Yes.
1128
112927 - Can atomic counters be grouped into blocks similar to uniform blocks?
1130
1131     Resolved.  No.  However, layout qualifiers can be used in individual
1132     declarations to identify a specific buffer binding point and offset to
1133     use for the counter.
1134
113528 - What API should be used to query information about atomic counters?
1136
1137     Resolved.  GetActiveUniformsiv.  Apart from the common type and count
1138     queries, UNIFORM_OFFSET can be used to query the offset of an atomic
1139     counter, UNIFORM_ARRAY_STRIDE can be used to query the stride in memory
1140     of an array of atomic counters (even though it's always four bytes), and
1141     UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX can be used to query the index of the
1142     active atomic counter buffer associated with the uniform.
1143
1144     No GetActiveUniformsiv query is provided to retrieve the binding point
1145     associated with an atomic counter uniform.  It may be obtained indirectly
1146     by UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX and then using
1147     GetAtomicCounterBufferiv to query the ATOMIC_COUNTER_BUFFER_BINDING for
1148     the returned index.
1149
115029 - What API should we provide to query information about buffer object
1151     storage needed to back atomic counters?
1152
1153     Unresolved.  We will provide an API for querying information about
1154     "active atomic counter buffers" similar to the API we provide for
1155     querying active uniform blocks.  Each set of active atomic counter
1156     uniforms sharing a single binding point corresponds to an active atomic
1157     counter buffer.  An application can query the number of active atomic
1158     counter buffers via GetProgram.  If there are <N> active atomic counter
1159     buffers, it can pass the values 0..<N>-1 to the command
1160     GetAtomicCounterBufferiv to query properties of each buffer.
1161
1162     Consider the following set of active atomic counter uniform declarations
1163     in three different shader types in a program:
1164
1165       [in vertex]
1166       layout(binding = 0, offset = 0) uniform atomic_uint batman;
1167       layout(binding = 3, offset = 4) uniform atomic_uint robin;
1168       [in geometry]
1169       layout(binding = 0, offset = 4) uniform atomic_uint joker;
1170       layout(binding = 6, offset = 124) uniform atomic_uint riddler;
1171       [in fragment]
1172       layout(binding = 7, offset = 0) uniform atomic_uint penguin;
1173
1174     In this example, there are four active atomic counter buffers.  For the
1175     purposes of the GetActiveAtomicCounterBufferiv query, these will be
1176     assigned indices 0, 1, 2, 3.  If the active atomic counter buffers are
1177     sorted by binding point, the atomic counter buffer binding point numbers
1178     returned by calling GetActiveAtomicCounterBufferiv with a <pname> of
1179     ATOMIC_COUNTER_BUFFER_BINDING, will be 0, 3, 6, and 7, respectively.
1180
118130 - The function atomicCounterIncrement() returns the value of the counter
1182     prior to incrementing while atomicCounterDecrement() returns the value
1183     of the counter *after* decrementing.  Is this intentional?
1184
1185     Resolved.  Yes.  One of the intended uses of this programming model is to
1186     be able to atomically add or remove records to an array stored in a
1187     buffer (via ARB_shader_image_load_store).  In this model, we use the
1188     atomic counter to indicate the number of records stored in the buffer and
1189     expect the value to be initialized to zero.  When the first record is
1190     added, it gets an index of zero and increments the counter to one.  If a
1191     later operation wants to remove a record from the end of a buffer with an
1192     associated counter value <N>, we would want to decrement to counter to
1193     <N>-1, but also return the decremented index of <N>-1, which was the
1194     index of the last record in the buffer prior to the decrement.
1195
119631 - What alignment requirements apply to the <offset> and <size> parameters
1197     of BindBufferRange when binding atomic counter buffers?
1198
1199     Resolved.  <offset> must be a multiple of four.  <size> has no required
1200     alignment.  However, if <size> is not four-byte aligned, it will not
1201     possible to store an atomic counter in the last few bytes of the bound
1202     range since the offset of all atomic counters must also be a multiple of
1203     four.
1204
1205Revision History
1206
1207    Revision 1, wwlk, 2009-09-08
1208      - Working Draft
1209    Revision 2, wwlk, 2009-09-08
1210      - updates from feedback
1211    Revision 3, wwlk, 2009-09-09
1212      - (9/9/9, yeah yeah yeah)
1213      - updates from feedback
1214    Revision 4, wwlk, 2009-09-15
1215      - updates from walkthrough
1216      - minor typo update (2.9.10 should be 2.9.9)
1217      - add extension enables and defines to shader spec
1218      - correct function names (add EXT suffix)
1219      - rename extension
1220    Revision 5, wwlk, 2009-09-15
1221      - Clarify buffer objects
1222      - Clarify undersized buffer objects
1223    Revision 6, wwlk, 2009-09-16
1224      - Clarify alignment restrictions for buffer object
1225      - Update built-in function names and descriptions
1226      - Add issue about number of binding points
1227    Revision 7, wwlk, 2010-10-17
1228      - Add opaque ucounter
1229      - add buffer binding and offset per counter
1230    Revision 8, wwlk, 2010-10-28
1231      - make it clear that these use the indexed binding api
1232        (ala transform feedback)
1233      - remove get
1234        (bug 5839, issue 2 in bug, issue 21 in this extension)
1235      - remove fragment restriction
1236        (bug 5839, issue 5 in bug, issue 2 in this extension)
1237      - add issue 4
1238      - add other issues from bug 5839
1239      - Some clarifications from bug 6975
1240   Revision 9, wwlk, 2010-11-30
1241      - added new global qualifier, uniform
1242      - clarified no default context state
1243      - clarified the action of BindBufferRange
1244      - corrected alignment and sizing restrictions
1245      - Still to be done - GetActiveUniforms API!
1246   Revision 10, wwlk, 2010-12-02
1247      - GetActiveUniforms API
1248      - change ucounter -> atomic_uint
1249   Revision 11, wwlk, 2010-12-02
1250      - Removed unnecessary AtomicCounterEXT API.
1251        (use buffer API)
1252   Revision 12, wwlk, 2010-12-03
1253      - Trivial typos
1254   Revision 13, wwlk, 2010-12-03
1255      - More trivial typos
1256   Revision 14, wwlk, 2010-12-03
1257      - Still more trivial typos
1258   Revision 15, wwlk, 2010-12-09
1259      - Still more trivial typos
1260      - Clarifications
1261      - Additional uniform API - next revision
1262        (the obvious additions, but unfortunately
1263         extensive.  Proofing now.)
1264   Revision 16, johnk, 2010-12-17
1265      - Change MAX_ATOMIC_COUNTERS to gl_MaxAtomicCounterBindingsEXT (is that correct?)
1266      - Move that statement from the uniform section to the qualifier section.
1267      - added integer constants to the layout qualifier grammar
1268      - minor grammar and consistency changes going into 4.2 core.
1269    Revision 17, Jon Leech, 2010-12-19
1270      - Change extension name to ARB instead of EXT. Remove _EXT
1271        suffixes on API since this extension is backwards-compatibility
1272        for a core GL 4.2 feature. Probably should remove suffixes on
1273        GLSL interface as well.
1274      - Fix version number for API spec in section headings.
1275    Revision 18, Jon Leech, 2011-01-05
1276      - Fix typos from Bug 7202
1277    Revision 19, wwlk, 2011-04-05
1278      - Uniform API - large rework
1279      - Clarify limits
1280      - Clarify layouts, binding rules, offset rules
1281      - Clarify named uniform blocks
1282      - Clarify unnamed uniform blocks
1283    Revision 20, wwlk, 2011-04-08
1284      - Clarify named uniform blocks with examples
1285      - Make explicit the matching rules for layout (explicit or implicit layout must match)
1286      - Added issue 29, do we need both un-named uniform blocks and uniform blocks?
1287      - Added issue 30, should the un-named uniform blocks be un-named "", or should
1288        they be implicitly named (example, uniform3 for binding to 3)
1289    Revision 21, wwlk, 2011-04-08
1290      - Minor change to invalid uniform block example
1291    Revision 22, wwlk, 2011-05-05
1292      - Major change
1293        uniforms (immutable)
1294    Revision 23, wwlk, 2011-05-05
1295      - Fixed hellacious paragraph, related to bug 7458
1296        "Each active uniform variable ... "." (dot) and "[]" ..."
1297    Revision 24, Jon Leech, 2011-05-08
1298      - Minor formatting/typo cleanup. Fix name of query in state tables.
1299        Remove EXT suffixes from shader constant and function names.
1300    Revision 25, pbrown, 2011-06-18
1301      - Add missing entries in the lists of new functions and tokens.
1302      - Assigned enumerant values for new tokens.
1303      - Minor language clarifications and typo fixes.
1304      - Clarify the two different numbering spaces for buffers used for atomic
1305        counters.  The set of binding points actively referenced by a
1306        particular program are called "active atomic counter buffers"; the set
1307        of binding points in the context to which buffers are attached query
1308        are called "atomic counter bindings" or "binding points".  Related
1309        APIs and tokens use "buffer" for the former and "binding" for the
1310        latter (bug 7723).
1311      - Add GetActiveUniformsiv support for atomic counters, allowing the use
1312        of UNIFORM_OFFSET and UNIFORM_ARRAY_STRIDE, and adding the query
1313        UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX to query the associated active
1314        atomic counter buffer.
1315      - Restructure the atomic counter buffer binding section to more closely
1316        match existing uniform block language; clarify alignment and buffer
1317        size requirements (bug 7722).
1318      - Remove explicit language about a minimum of 8 atomic counter buffers;
1319        already covered by existing queries and state table entries (bug 7722).
1320      - Add GetProgram language for ACTIVE_ATOMIC_COUNTER_BUFFERS.
1321      - Add missing state table entries for program object state and
1322        implementation limits on atomic counter buffer sizes and the combined
1323        active buffer count (bug 7722).
1324      - Clarify that we intended the non-orthogonality where the increment
1325        function returns a value prior to incrementing while the decrement
1326        function returns a value after decrementing (bug 7722).
1327      - Add a few issues and clarify/update some existing ones.
1328    Revision 26, pbrown, 2011-06-20
1329      - Add missing enum assignment for MAX_ATOMIC_COUNTER_BUFFER_BINDINGS.
1330    Revision 27, pbrown, 2011-06-23
1331      - Set a minimum value for MAX_ATOMIC_COUNTER_BUFFER_SIZE (bug 7743).
1332      - Fix typo in state table.
1333    Revision 28, pbrown, 2011-07-27
1334      - Clarify that ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS queries the
1335        number of atomic counter variables (bug 7834).
1336      - Fix tokens MAX_*_ATOMIC_COUNTER_BUFFERS in the state table (bug 7834).
1337      - Fix a couple typos.
1338    Revision 29, Jon Leech, 2011-08-05
1339      - Change minimum MAX_ATOMIC_COUNTER_BUFFER_SIZE value to 32 (bug
1340        7855).
1341    Revision 30, Jon Leech, 2012-04-12
1342      - Add description of atomic buffer object binding queries in section
1343        6.1.8. Correct typo for GetAtomicCounterBufferiv in state table
1344        entries.
1345    Revision 31, Jon Leech, 2012-07-30
1346      - Correct typo ATOMIC_COUNTER_ARRAY_STRIDE -> UNIFORM_ARRAY_STRIDE
1347        (bug 9346).
1348