15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    ARB_shader_atomic_counter_ops
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_ARB_shader_atomic_counter_ops
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Daniel Rakos (daniel.rakos 'at' amd.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Daniel Rakos, AMD
165bd8deadSopenharmony_ci    Graham Sellers, AMD
175bd8deadSopenharmony_ci    Piers Daniell, NVIDIA
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ciNotice
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ci    Copyright (c) 2015 The Khronos Group Inc. Copyright terms at
225bd8deadSopenharmony_ci        http://www.khronos.org/registry/speccopyright.html
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ciSpecification Update Policy
255bd8deadSopenharmony_ci
265bd8deadSopenharmony_ci    Khronos-approved extension specifications are updated in response to
275bd8deadSopenharmony_ci    issues and bugs prioritized by the Khronos OpenGL Working Group. For
285bd8deadSopenharmony_ci    extensions which have been promoted to a core Specification, fixes will
295bd8deadSopenharmony_ci    first appear in the latest version of that core Specification, and will
305bd8deadSopenharmony_ci    eventually be backported to the extension document. This policy is
315bd8deadSopenharmony_ci    described in more detail at
325bd8deadSopenharmony_ci        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
335bd8deadSopenharmony_ci
345bd8deadSopenharmony_ciStatus
355bd8deadSopenharmony_ci
365bd8deadSopenharmony_ci    Complete. Approved by the ARB on June 26, 2015.
375bd8deadSopenharmony_ci    Ratified by the Khronos Board of Promoters on August 7, 2015.
385bd8deadSopenharmony_ci
395bd8deadSopenharmony_ciVersion
405bd8deadSopenharmony_ci
415bd8deadSopenharmony_ci    Last Modified Date:         06/11/2015
425bd8deadSopenharmony_ci    Author Revision:            6
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ciNumber
455bd8deadSopenharmony_ci
465bd8deadSopenharmony_ci    ARB Extension #182
475bd8deadSopenharmony_ci
485bd8deadSopenharmony_ciDependencies
495bd8deadSopenharmony_ci
505bd8deadSopenharmony_ci    This extension is written against version 4.50 of the OpenGL Shading
515bd8deadSopenharmony_ci    Language Specification.
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ci    OpenGL 4.2 or ARB_shader_atomic_counters is required.
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci
565bd8deadSopenharmony_ciOverview
575bd8deadSopenharmony_ci
585bd8deadSopenharmony_ci    The ARB_shader_atomic_counters extension introduced atomic counters, but
595bd8deadSopenharmony_ci    it limits list of potential operations that can be performed on them to
605bd8deadSopenharmony_ci    increment, decrement, and query. This extension extends the list of GLSL
615bd8deadSopenharmony_ci    built-in functions that can operate on atomic counters. The list of new
625bd8deadSopenharmony_ci    operations include:
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ci      * Addition and subtraction
655bd8deadSopenharmony_ci      * Minimum and maximum
665bd8deadSopenharmony_ci      * Bitwise operators (AND, OR, XOR, etc.)
675bd8deadSopenharmony_ci      * Exchange, and compare and exchange operators
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ci
705bd8deadSopenharmony_ciNew Procedures and Functions
715bd8deadSopenharmony_ci
725bd8deadSopenharmony_ci    None.
735bd8deadSopenharmony_ci
745bd8deadSopenharmony_ci
755bd8deadSopenharmony_ciNew Tokens
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ci    None.
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ci
805bd8deadSopenharmony_ciModifications to the OpenGL Shading Language Specification, Version 4.50
815bd8deadSopenharmony_ci
825bd8deadSopenharmony_ciAdditions to Chapter 8 of the OpenGL Shading Language Specification
835bd8deadSopenharmony_ci(Built-in Functions)
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ci    Modify Section 8.10, Atomic-Counter Functions
865bd8deadSopenharmony_ci
875bd8deadSopenharmony_ci    (remove second paragraph on p. 173 starting with "The value returned...")
885bd8deadSopenharmony_ci
895bd8deadSopenharmony_ci    (modify third paragraph on p. 173)
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ci    The underlying counter is a 32-bit unsigned integer. The result of
925bd8deadSopenharmony_ci    operations will wrap to [0, 2^32-1].
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ci    (add to the table of atomic counter built-in functions on p. 173)
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
975bd8deadSopenharmony_ci    | Syntax                              | Description                                                      |
985bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
995bd8deadSopenharmony_ci    | uint atomicCounterAddARB(           | Atomically                                                       |
1005bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. adds the value of <data> to the counter for c, and          |
1015bd8deadSopenharmony_ci    |     uint data)                      |   2. returns its value prior to the operation.                   |
1025bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1035bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1045bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1055bd8deadSopenharmony_ci    | uint atomicCounterSubtractARB(      | Atomically                                                       |
1065bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. subtracts the value of <data> from the counter for c, and   |
1075bd8deadSopenharmony_ci    |     uint data)                      |   2. returns its value prior to the operation.                   |
1085bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1095bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1105bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1115bd8deadSopenharmony_ci    | uint atomicCounterMinARB(           | Atomically                                                       |
1125bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter for c to the minimum of the value of the   |
1135bd8deadSopenharmony_ci    |     uint data)                      |      counter and the value of <data>, and                        |
1145bd8deadSopenharmony_ci    |                                     |   2. returns the value prior to the operation.                   |
1155bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1165bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1175bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1185bd8deadSopenharmony_ci    | uint atomicCounterMaxARB(           | Atomically                                                       |
1195bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter for c to the maximum of the value of the   |
1205bd8deadSopenharmony_ci    |     uint data)                      |      counter and the value of <data>, and                        |
1215bd8deadSopenharmony_ci    |                                     |   2. returns the value prior to the operation.                   |
1225bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1235bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1245bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1255bd8deadSopenharmony_ci    | uint atomicCounterAndARB(           | Atomically                                                       |
1265bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter for c to the result of the bitwise AND of  |
1275bd8deadSopenharmony_ci    |     uint data)                      |      the value of the counter and the value of <data>, and       |
1285bd8deadSopenharmony_ci    |                                     |   2. returns the value prior to the operation.                   |
1295bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1305bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1315bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1325bd8deadSopenharmony_ci    | uint atomicCounterOrARB(            | Atomically                                                       |
1335bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter for c to the result of the bitwise OR of   |
1345bd8deadSopenharmony_ci    |     uint data)                      |      the value of the counter and the value of <data>, and       |
1355bd8deadSopenharmony_ci    |                                     |   2. returns the value prior to the operation.                   |
1365bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1375bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1385bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1395bd8deadSopenharmony_ci    | uint atomicCounterXorARB(           | Atomically                                                       |
1405bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter for c to the result of the bitwise XOR of  |
1415bd8deadSopenharmony_ci    |     uint data)                      |      the value of the counter and the value of <data>, and       |
1425bd8deadSopenharmony_ci    |                                     |   2. returns the value prior to the operation.                   |
1435bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1445bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1455bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1465bd8deadSopenharmony_ci    | uint atomicCounterExchangeARB(      | Atomically                                                       |
1475bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. sets the counter value for c to the value of <data>, and    |
1485bd8deadSopenharmony_ci    |     uint data)                      |   2. returns its value prior to the operation.                   |
1495bd8deadSopenharmony_ci    |                                     | These two steps are done atomically with respect to the atomic   |
1505bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1515bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1525bd8deadSopenharmony_ci    | uint atomicCounterCompSwapARB(      | Atomically                                                       |
1535bd8deadSopenharmony_ci    |     atomic_uint c,                  |   1. compares the value of <compare> and the counter value for c,|
1545bd8deadSopenharmony_ci    |     uint compare,                   |   2. if the values are equal, sets the counter value for c to    |
1555bd8deadSopenharmony_ci    |     uint data)                      |      the value of <data>, and                                    |
1565bd8deadSopenharmony_ci    |                                     |   3. returns its value prior to the operation.                   |
1575bd8deadSopenharmony_ci    |                                     | These three steps are done atomically with respect to the atomic |
1585bd8deadSopenharmony_ci    |                                     | counter functions in this table.                                 |
1595bd8deadSopenharmony_ci    +-------------------------------------+------------------------------------------------------------------+
1605bd8deadSopenharmony_ci
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ciErrors
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ci    None.
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ciNew State
1675bd8deadSopenharmony_ci
1685bd8deadSopenharmony_ci    None.
1695bd8deadSopenharmony_ci
1705bd8deadSopenharmony_ciNew Implementation Dependent State
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ci    None.
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ciUsage Examples
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci    Example 1: Appending variable length records to a buffer using a compute shader
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci        // Here we use atomicCounterAdd to ensure that we "allocate" a contiguous list of
1795bd8deadSopenharmony_ci        // elements in the buffer.
1805bd8deadSopenharmony_ci        // Using atomicCounterIncrement cannot mimic this behavior as there is no guarantee
1815bd8deadSopenharmony_ci        // that subsequent calls to atomicCounterIncrement return subsequent counter values.
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ci        layout(binding=0, offset=0) uniform atomic_uint vlrCounter;
1845bd8deadSopenharmony_ci        layout(binding=0, r32ui) uniform imageBuffer vlrBuffer;
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ci        void main()
1875bd8deadSopenharmony_ci        {
1885bd8deadSopenharmony_ci            uint data[...] = ...;
1895bd8deadSopenharmony_ci            uint recordLength = ...;
1905bd8deadSopenharmony_ci
1915bd8deadSopenharmony_ci            uint recordStart = atomicCounterAddARB(vlrCounter, recordLength);
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ci            for (uint i = 0; i < recordLength; ++i)
1945bd8deadSopenharmony_ci            {
1955bd8deadSopenharmony_ci                imageStore(vlrBuffer, recordStart + i, data[i]);
1965bd8deadSopenharmony_ci            }
1975bd8deadSopenharmony_ci        }
1985bd8deadSopenharmony_ci
1995bd8deadSopenharmony_ciIssues
2005bd8deadSopenharmony_ci
2015bd8deadSopenharmony_ci    (1) What additional operations should this extension introduce?
2025bd8deadSopenharmony_ci
2035bd8deadSopenharmony_ci      RESOLVED: The following new operations are generally supported by
2045bd8deadSopenharmony_ci      target hardware:
2055bd8deadSopenharmony_ci        * Addition and subtraction
2065bd8deadSopenharmony_ci        * Minimum and maximum
2075bd8deadSopenharmony_ci        * Bitwise operators (AND, OR, XOR, etc.)
2085bd8deadSopenharmony_ci        * Exchange, and compare and exchange operators
2095bd8deadSopenharmony_ci
2105bd8deadSopenharmony_ci    (2) How the functionality in this extension is different than that
2115bd8deadSopenharmony_ci        introduced by AMD_shader_atomic_counter_ops?
2125bd8deadSopenharmony_ci
2135bd8deadSopenharmony_ci      RESOLVED: In addition to the operations introduced by this extension
2145bd8deadSopenharmony_ci      AMD_shader_atomic_counter_ops also adds support for wrapped increment,
2155bd8deadSopenharmony_ci      wrapped decrement, reverse subtract, and a special masked-or operation.
2165bd8deadSopenharmony_ci      Also, the semantics of the subtract operation is different between this
2175bd8deadSopenharmony_ci      and the AMD extension.
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci    (3) Should the new decrement with wrap and subtract operators match the
2205bd8deadSopenharmony_ci        behavior of the existing decrement operator and return the post-
2215bd8deadSopenharmony_ci        operation value of the counter?
2225bd8deadSopenharmony_ci
2235bd8deadSopenharmony_ci      RESOLVED: Yes, for consistency with the existing functionality.
2245bd8deadSopenharmony_ci
2255bd8deadSopenharmony_ci    (4) Most of the new operations introduced by this extension are already
2265bd8deadSopenharmony_ci        supported on load/store images and shader storage buffers. What benefit
2275bd8deadSopenharmony_ci        the application developer could get from using this extension?
2285bd8deadSopenharmony_ci
2295bd8deadSopenharmony_ci      DISCUSSION: Atomic counter operations can have different performance
2305bd8deadSopenharmony_ci      characteristics than load/store images or shader storage buffers. It is
2315bd8deadSopenharmony_ci      expected that implementations can do atomic counter operations faster.
2325bd8deadSopenharmony_ci
2335bd8deadSopenharmony_ci      RESOLVED: It enables existing operations for atomic counters and also
2345bd8deadSopenharmony_ci      adds completely new operations that are not available for load/store
2355bd8deadSopenharmony_ci      images and shader storage buffers.
2365bd8deadSopenharmony_ci
2375bd8deadSopenharmony_ci    (5) Should the new subtract operator match the behavior of the existing
2385bd8deadSopenharmony_ci        decrement operator and return the post-operation value of the counter?
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci      RESOLVED: No, it returns the value of the counter prior to the operation,
2415bd8deadSopenharmony_ci      just like other atomic counter operations except decrement.
2425bd8deadSopenharmony_ci
2435bd8deadSopenharmony_ciRevision History
2445bd8deadSopenharmony_ci
2455bd8deadSopenharmony_ci    Rev.    Date    Author    Changes
2465bd8deadSopenharmony_ci    ----  --------  --------  -------------------------------------------------
2475bd8deadSopenharmony_ci      6   06/11/15  drakos    Updated resolution of issue (2) and (5) based on
2485bd8deadSopenharmony_ci                              the previous change.
2495bd8deadSopenharmony_ci      5   05/28/15  pdaniell  Modify the return semantics of
2505bd8deadSopenharmony_ci                              atomicCounterSubtractARB to return the result
2515bd8deadSopenharmony_ci                              prior to the operation.
2525bd8deadSopenharmony_ci      4   05/08/15  drakos    Added ARB suffixes to the built-in functions.
2535bd8deadSopenharmony_ci      3   03/18/15  drakos    Removed reverse subtract.
2545bd8deadSopenharmony_ci      2   03/17/15  drakos    Removed wrapped increment, wrapped decrement, and
2555bd8deadSopenharmony_ci                              masked-or operations. Also resolved outstanding
2565bd8deadSopenharmony_ci                              issues.
2575bd8deadSopenharmony_ci      1   02/03/15  drakos    Draft based on AMD_shader_atomic_counter_ops.
2585bd8deadSopenharmony_ci                              Rebased language for GLSL 4.50.
259