15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    ARB_shader_draw_parameters
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_ARB_shader_draw_parameters
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Graham Sellers (graham.sellers 'at' amd.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Piers Daniell, NVIDIA
165bd8deadSopenharmony_ci    Daniel Rakos, AMD
175bd8deadSopenharmony_ci    Christophe Riccio, OpenGL Garden (!)
185bd8deadSopenharmony_ci    Daniel Koch, NVIDIA
195bd8deadSopenharmony_ci
205bd8deadSopenharmony_ciNotice
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ci    Copyright (c) 2013 The Khronos Group Inc. Copyright terms at
235bd8deadSopenharmony_ci        http://www.khronos.org/registry/speccopyright.html
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ciSpecification Update Policy
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ci    Khronos-approved extension specifications are updated in response to
285bd8deadSopenharmony_ci    issues and bugs prioritized by the Khronos OpenGL Working Group. For
295bd8deadSopenharmony_ci    extensions which have been promoted to a core Specification, fixes will
305bd8deadSopenharmony_ci    first appear in the latest version of that core Specification, and will
315bd8deadSopenharmony_ci    eventually be backported to the extension document. This policy is
325bd8deadSopenharmony_ci    described in more detail at
335bd8deadSopenharmony_ci        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ciStatus
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    Complete. Approved by the ARB on June 3, 2013.
385bd8deadSopenharmony_ci    Ratified by the Khronos Board of Promoters on July 19, 2013.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ciVersion
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ci    Last Modified Date: 29 May 2017
435bd8deadSopenharmony_ci    Revision: 4
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ciNumber
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ci    ARB Extension #156
485bd8deadSopenharmony_ci
495bd8deadSopenharmony_ciDependencies
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci    OpenGL 3.1 is required.
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ci    This extension is written against Version 4.3 of the Core Profile OpenGL
545bd8deadSopenharmony_ci    Specification, dated February 14, 2013 and Version 4.30 of the OpenGL
555bd8deadSopenharmony_ci    Shading Language Specification, dated February 7, 2013.
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    The presence of the GL_ARB_multi_draw_indirect extension affects the
585bd8deadSopenharmony_ci    definition of this extension.
595bd8deadSopenharmony_ci
605bd8deadSopenharmony_ci    The GL_ARB_indirect_parameters extension affects the definition of this
615bd8deadSopenharmony_ci    extension.
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ciOverview
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ci        In unextended GL, vertex shaders have inputs named gl_VertexID and
665bd8deadSopenharmony_ci    gl_InstanceID, which contain, respectively the index of the vertex and
675bd8deadSopenharmony_ci    instance. The value of gl_VertexID is the implicitly passed index of the
685bd8deadSopenharmony_ci    vertex being processed, which includes the value of baseVertex, for those
695bd8deadSopenharmony_ci    commands that accept it. Meanwhile, gl_InstanceID is the integer index
705bd8deadSopenharmony_ci    of the current instance being processed, but, even for commands that
715bd8deadSopenharmony_ci    accept a baseInstance parameter, it does not include the value of this
725bd8deadSopenharmony_ci    argument. Furthermore, the equivalents to these variables in other
735bd8deadSopenharmony_ci    graphics APIs do not necessarily follow these conventions. The reason for
745bd8deadSopenharmony_ci    this inconsistency is that there are legitimate use cases for both
755bd8deadSopenharmony_ci    inclusion and exclusion of the baseVertex or baseInstance parameters
765bd8deadSopenharmony_ci    in gl_VertexID and gl_InstanceID, respectively.
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci        Rather than change the semantics of either built-in variable, this
795bd8deadSopenharmony_ci    extension adds two new built-in variables to the GL shading language,
805bd8deadSopenharmony_ci    gl_BaseVertexARB and gl_BaseInstanceARB, which contain the values passed
815bd8deadSopenharmony_ci    in the baseVertex and baseInstance parameters, respectively. Shaders
825bd8deadSopenharmony_ci    provided by the application may use these variables to offset gl_VertexID
835bd8deadSopenharmony_ci    or gl_InstanceID if desired, or use them for any other purpose.
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ci        Additionally, this extension adds a further built-in variable, gl_DrawID
865bd8deadSopenharmony_ci    to the shading language. This variable contains the index of the draw
875bd8deadSopenharmony_ci    currently being processed by a Multi* variant of a drawing command (such
885bd8deadSopenharmony_ci    as MultiDrawElements or MultiDrawArraysIndirect).
895bd8deadSopenharmony_ci
905bd8deadSopenharmony_ciNew Procedures and Functions
915bd8deadSopenharmony_ci
925bd8deadSopenharmony_ci    None.
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ciNew Tokens
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci    None.
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ciIP Status
995bd8deadSopenharmony_ci
1005bd8deadSopenharmony_ci    No known IP claims.
1015bd8deadSopenharmony_ci
1025bd8deadSopenharmony_ciAdditions to Chapter 10 of the OpenGL Core Profile Specification, "Vertex
1035bd8deadSopenharmony_ciSpecification and Drawing Commands"
1045bd8deadSopenharmony_ci
1055bd8deadSopenharmony_ci    Add the following after the pseudo-code describing MultiDrawArrays on
1065bd8deadSopenharmony_ci    p.310:
1075bd8deadSopenharmony_ci
1085bd8deadSopenharmony_ci        The index of the draw (<i> in the above pseudo-code) may be read by
1095bd8deadSopenharmony_ci    a vertex shader as <gl_DrawIDARB>, as described in Section 11.1.3.9.
1105bd8deadSopenharmony_ci
1115bd8deadSopenharmony_ci    Add the following after the pseudo-code describing MultiDrawArraysIndirect
1125bd8deadSopenharmony_ci    on p.311:
1135bd8deadSopenharmony_ci
1145bd8deadSopenharmony_ci        The index of the draw (<i> in the above pseudo-code) may be read by
1155bd8deadSopenharmony_ci    a vertex shader as <gl_DrawIDARB>, as described in Section 11.1.3.9.
1165bd8deadSopenharmony_ci
1175bd8deadSopenharmony_ci    Add the following after the pseudo-code describing MultiDrawElements on
1185bd8deadSopenharmony_ci    p.313:
1195bd8deadSopenharmony_ci
1205bd8deadSopenharmony_ci        The index of the draw (<i> in the above pseudo-code) may be read by
1215bd8deadSopenharmony_ci    a vertex shader as <gl_DrawIDARB>, as described in Section 11.1.3.9.
1225bd8deadSopenharmony_ci
1235bd8deadSopenharmony_ci    Add the following after the pseudo-code describing
1245bd8deadSopenharmony_ci    MultiDrawElementsIndirect on p.316:
1255bd8deadSopenharmony_ci
1265bd8deadSopenharmony_ci        The index of the draw (<i> in the above pseudo-code) may be read by
1275bd8deadSopenharmony_ci    a vertex shader as <gl_DrawIDARB>, as described in Section 11.1.3.9.
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ci    Add the following after the pseudo-code describing
1305bd8deadSopenharmony_ci    MultiDrawElementsBaseVertex on p.316:
1315bd8deadSopenharmony_ci
1325bd8deadSopenharmony_ci        The index of the draw (<i> in the above pseudo-code) may be read by
1335bd8deadSopenharmony_ci    a vertex shader as <gl_DrawIDARB>, as described in Section 11.1.3.9.
1345bd8deadSopenharmony_ci
1355bd8deadSopenharmony_ciAdditions to Chapter 11 of the OpenGL Core Profile Specification, "Programmable
1365bd8deadSopenharmony_ciVertex Processing"
1375bd8deadSopenharmony_ci
1385bd8deadSopenharmony_ci    In Section 11.1.1, "Vertex Attributes", in the description of
1395bd8deadSopenharmony_ci    GetActiveAttrib, state that gl_DrawIDARB is enumerated:
1405bd8deadSopenharmony_ci
1415bd8deadSopenharmony_ci        For GetActiveAttrib, all active vertex shader input variables are
1425bd8deadSopenharmony_ci    enumerated, including the special built-in inputs gl_VertexID,
1435bd8deadSopenharmony_ci    gl_BaseVertexARB, gl_InstanceID, gl_BaseInstanceARB, and gl_DrawIDARB.
1445bd8deadSopenharmony_ci
1455bd8deadSopenharmony_ci    Replace the paragraphs describing gl_VertexID and gl_InstanceID in Section
1465bd8deadSopenharmony_ci    11.1.3.9, "Shader Inputs" with the following:
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ci        Besides having access to vertex attributes and uniform variables,
1495bd8deadSopenharmony_ci    vertex shaders can access the read-only built-in variables gl_VertexID,
1505bd8deadSopenharmony_ci    gl_InstanceID, gl_BaseVertexARB, gl_BaseInstanceARB and gl_DrawIDARB.
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ci        <gl_VertexID> holds ... (retain original language)
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci        <gl_BaseVertexARB> holds the integer value passed to the <baseVertex>
1555bd8deadSopenharmony_ci    parameter to the command that resulted in the current shader invocation.
1565bd8deadSopenharmony_ci    In the case where the command has no <baseVertex> parameter, the value
1575bd8deadSopenharmony_ci    of <gl_BaseVertexARB> is zero.
1585bd8deadSopenharmony_ci
1595bd8deadSopenharmony_ci        <gl_InstanceID> holds ... (retain original language)
1605bd8deadSopenharmony_ci
1615bd8deadSopenharmony_ci        <gl_BaseInstanceARB> holds the integer value passed to the
1625bd8deadSopenharmony_ci    <baseInstance> parameter to the command that resulted in the current
1635bd8deadSopenharmony_ci    shader invocation. In the case where the command has no <baseInstance>
1645bd8deadSopenharmony_ci    parameter, the value of <gl_BaseInstanceARB> is zero.
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ci    Add the following paragraph after the above discussion of <gl_InstanceID>:
1675bd8deadSopenharmony_ci
1685bd8deadSopenharmony_ci        <gl_DrawIDARB> holds the integer draw number the current draw being
1695bd8deadSopenharmony_ci    processed by the shader invocation. It is dynamically uniform. In
1705bd8deadSopenharmony_ci    MultiDraw* variants, this is the zero-based index of the draw within the
1715bd8deadSopenharmony_ci    list of draws processed by the command. In non-MultiDraw* commands, the
1725bd8deadSopenharmony_ci    value of <gl_DrawIDARB> is always zero.
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ciErrors
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci    None.
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ciNew State
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci    None.
1815bd8deadSopenharmony_ci
1825bd8deadSopenharmony_ciModifications to Chapter 7 of the OpenGL Shading Language Specification,
1835bd8deadSopenharmony_ciVersion 4.30.
1845bd8deadSopenharmony_ci
1855bd8deadSopenharmony_ci    Including the following line in a shader can be used to control the
1865bd8deadSopenharmony_ci    language features described in this extension:
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ci        #extension GL_ARB_shader_draw_parameters : <behavior>
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    where <behavior> is as described in Section 3.3.
1915bd8deadSopenharmony_ci
1925bd8deadSopenharmony_ci    A new preprocessor #define is added to the OpenGL Shading Language:
1935bd8deadSopenharmony_ci
1945bd8deadSopenharmony_ci      #define GL_ARB_shader_draw_parameters     1
1955bd8deadSopenharmony_ci
1965bd8deadSopenharmony_ci    In Section 7.1, "Built-in Language Variables", add the following to the
1975bd8deadSopenharmony_ci    list of input variables to a vertex shader, p.110:
1985bd8deadSopenharmony_ci
1995bd8deadSopenharmony_ci        in int      gl_DrawIDARB;
2005bd8deadSopenharmony_ci        in int      gl_BaseVertexARB;
2015bd8deadSopenharmony_ci        in int      gl_BaseInstanceARB;
2025bd8deadSopenharmony_ci
2035bd8deadSopenharmony_ci    Add the following paragraph after the description of gl_InstanceID, p.114:
2045bd8deadSopenharmony_ci
2055bd8deadSopenharmony_ci        The variable <gl_DrawIDARB> is a vertex language input variable that
2065bd8deadSopenharmony_ci    holds the integer index of the drawing command to which the current vertex
2075bd8deadSopenharmony_ci    belongs (see "Shader Inputs" in section 11.1.3.9 of the OpenGL Graphics
2085bd8deadSopenharmony_ci    System Specification). If the vertex is not invoked by a Multi* form of
2095bd8deadSopenharmony_ci    a draw command, then the value of gl_DrawIDARB is zero.
2105bd8deadSopenharmony_ci
2115bd8deadSopenharmony_ci        The variable <gl_BaseVertexARB> is a vertex language input variable
2125bd8deadSopenharmony_ci    that holds the integer value passed to the <baseVertex> parameter of the
2135bd8deadSopenharmony_ci    command that resulted in the current shader invocation (see "Shader Inputs"
2145bd8deadSopenharmony_ci    in section 11.1.3.9 of the OpenGL Graphics System Specification).
2155bd8deadSopenharmony_ci
2165bd8deadSopenharmony_ci        The variable <gl_BaseInstanceARB> is a vertex language input variable
2175bd8deadSopenharmony_ci    that holds the integer value passed to the <baseInstance> parameter of
2185bd8deadSopenharmony_ci    the command that resulted in the current shader invocation (see "Shader
2195bd8deadSopenharmony_ci    Inputs" in section 11.1.3.9 of the OpenGL Graphics System Specification).
2205bd8deadSopenharmony_ci
2215bd8deadSopenharmony_ciUsage Examples
2225bd8deadSopenharmony_ci
2235bd8deadSopenharmony_ci--- Example 1 ---
2245bd8deadSopenharmony_ci--- Using a different transformation matrix per draw ---
2255bd8deadSopenharmony_ci--- Some draws can share the same matrix ---
2265bd8deadSopenharmony_ci
2275bd8deadSopenharmony_ci    layout(binding = INDIRECTION) uniform indirection
2285bd8deadSopenharmony_ci    {
2295bd8deadSopenharmony_ci        int Transform[MAX_DRAW];
2305bd8deadSopenharmony_ci    } Indirection;
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ci    layout(binding = TRANSFORM0) uniform transform
2335bd8deadSopenharmony_ci    {
2345bd8deadSopenharmony_ci        mat4 MVP[MAX_DRAW];
2355bd8deadSopenharmony_ci    } Transform;
2365bd8deadSopenharmony_ci
2375bd8deadSopenharmony_ci    layout(location = POSITION) in vec3 Position;
2385bd8deadSopenharmony_ci    layout(location = TEXCOORD) in vec3 Texcoord;
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci    out gl_PerVertex
2415bd8deadSopenharmony_ci    {
2425bd8deadSopenharmony_ci        vec4 gl_Position;
2435bd8deadSopenharmony_ci    };
2445bd8deadSopenharmony_ci
2455bd8deadSopenharmony_ci    out block
2465bd8deadSopenharmony_ci    {
2475bd8deadSopenharmony_ci        vec2 Texcoord;
2485bd8deadSopenharmony_ci    } Out;
2495bd8deadSopenharmony_ci
2505bd8deadSopenharmony_ci    void main()
2515bd8deadSopenharmony_ci    {
2525bd8deadSopenharmony_ci        Out.Texcoord = Texcoord.st;
2535bd8deadSopenharmony_ci        gl_Position = Transform.MVP[Indirection.Transform[gl_DrawIDARB]] *
2545bd8deadSopenharmony_ci                      vec4(Position, 1.0);
2555bd8deadSopenharmony_ci    }
2565bd8deadSopenharmony_ci
2575bd8deadSopenharmony_ciDependencies on GL_ARB_multi_draw_indirect
2585bd8deadSopenharmony_ci
2595bd8deadSopenharmony_ci    If GL_ARB_multi_draw_indirect is not supported, remove the language added
2605bd8deadSopenharmony_ci    after the pseudo-code describing MultiDrawArraysIndirect and
2615bd8deadSopenharmony_ci    MultiDrawElementsIndirect.
2625bd8deadSopenharmony_ci
2635bd8deadSopenharmony_ciDependencies on GL_ARB_indirect_parameters
2645bd8deadSopenharmony_ci
2655bd8deadSopenharmony_ci    Whilst not a true dependency, it should be noted that the additional
2665bd8deadSopenharmony_ci    commands introduced by ARB_indirect_parameters affect the value of
2675bd8deadSopenharmony_ci    gl_DrawIDARB.
2685bd8deadSopenharmony_ci
2695bd8deadSopenharmony_ciIssues
2705bd8deadSopenharmony_ci
2715bd8deadSopenharmony_ci    1) -
2725bd8deadSopenharmony_ci
2735bd8deadSopenharmony_ci    2) -
2745bd8deadSopenharmony_ci
2755bd8deadSopenharmony_ci    3) What is the value of gl_DrawIDARB for non-Multi* draws?
2765bd8deadSopenharmony_ci
2775bd8deadSopenharmony_ci       RESOLVED: Zero.
2785bd8deadSopenharmony_ci
2795bd8deadSopenharmony_ci    4) Do we need language to clarify that gl_DrawIDARB is a dynamically
2805bd8deadSopenharmony_ci       uniform expression?
2815bd8deadSopenharmony_ci
2825bd8deadSopenharmony_ci       RESOLVED: Yes, this allows accessing resources per-draw.
2835bd8deadSopenharmony_ci
2845bd8deadSopenharmony_ci    5) -
2855bd8deadSopenharmony_ci
2865bd8deadSopenharmony_ci    6) -
2875bd8deadSopenharmony_ci
2885bd8deadSopenharmony_ciRevision History
2895bd8deadSopenharmony_ci
2905bd8deadSopenharmony_ci    Rev.    Date      Author    Changes
2915bd8deadSopenharmony_ci    ----  --------    --------  -----------------------------------------
2925bd8deadSopenharmony_ci
2935bd8deadSopenharmony_ci     1    05/16/2013  gsellers  Initial draft
2945bd8deadSopenharmony_ci     2    05/29/2013  gsellers  Add descriptions of gl_BaseVertexARB and
2955bd8deadSopenharmony_ci                                gl_BaseInstanceARB.
2965bd8deadSopenharmony_ci                                Document pseudo-dependency on
2975bd8deadSopenharmony_ci                                ARB_indirect_parameters.
2985bd8deadSopenharmony_ci     3    06/05/2013  gsellers  Remove controls over gl_VertexID and
2995bd8deadSopenharmony_ci                                gl_InstanceID, leaving only the
3005bd8deadSopenharmony_ci                                gl_BaseVertexARB and gl_BaseInstanceARB
3015bd8deadSopenharmony_ci                                variables. gl_DrawIDARB is unmodified.
3025bd8deadSopenharmony_ci                                Issues 1, 2, 5 and 6 become non-issues as
3035bd8deadSopenharmony_ci                                a result.
3045bd8deadSopenharmony_ci     4    05/29/2017  dgkoch    remove edit reference to non-existant
3055bd8deadSopenharmony_ci                                MultiDrawElementsInstancedBaseInstance function.
3065bd8deadSopenharmony_ci                                Fix typos.
3075bd8deadSopenharmony_ci
308