15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci OES_shader_io_blocks 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName String 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_OES_shader_io_blocks 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContact 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Jon Leech (oddhack 'at' sonic.net) 125bd8deadSopenharmony_ci Daniel Koch, NVIDIA (dkoch 'at' nvidia.com) 135bd8deadSopenharmony_ci 145bd8deadSopenharmony_ciContributors 155bd8deadSopenharmony_ci 165bd8deadSopenharmony_ci Daniel Koch, NVIDIA (dkoch 'at' nvidia.com) 175bd8deadSopenharmony_ci Pat Brown, NVIDIA (pbrown 'at' nvidia.com) 185bd8deadSopenharmony_ci Slawomir Grajewski, Intel 195bd8deadSopenharmony_ci Graham Connor, Imagination 205bd8deadSopenharmony_ci Ben Bowman, Imagination 215bd8deadSopenharmony_ci Jonathan Putsman, Imagination 225bd8deadSopenharmony_ci 235bd8deadSopenharmony_ciNotice 245bd8deadSopenharmony_ci 255bd8deadSopenharmony_ci Copyright (c) 2008-2013 The Khronos Group Inc. Copyright terms at 265bd8deadSopenharmony_ci http://www.khronos.org/registry/speccopyright.html 275bd8deadSopenharmony_ci 285bd8deadSopenharmony_ciSpecification Update Policy 295bd8deadSopenharmony_ci 305bd8deadSopenharmony_ci Khronos-approved extension specifications are updated in response to 315bd8deadSopenharmony_ci issues and bugs prioritized by the Khronos OpenGL ES Working Group. For 325bd8deadSopenharmony_ci extensions which have been promoted to a core Specification, fixes will 335bd8deadSopenharmony_ci first appear in the latest version of that core Specification, and will 345bd8deadSopenharmony_ci eventually be backported to the extension document. This policy is 355bd8deadSopenharmony_ci described in more detail at 365bd8deadSopenharmony_ci https://www.khronos.org/registry/OpenGL/docs/update_policy.php 375bd8deadSopenharmony_ci 385bd8deadSopenharmony_ci Portions Copyright (c) 2013-2014 NVIDIA Corporation. 395bd8deadSopenharmony_ci 405bd8deadSopenharmony_ciStatus 415bd8deadSopenharmony_ci 425bd8deadSopenharmony_ci Approved by the OpenGL ES Working Group 435bd8deadSopenharmony_ci Ratified by the Khronos Board of Promoters on November 7, 2014 445bd8deadSopenharmony_ci 455bd8deadSopenharmony_ciVersion 465bd8deadSopenharmony_ci 475bd8deadSopenharmony_ci Last Modified Date: October 8, 2014 485bd8deadSopenharmony_ci Revision: 2 495bd8deadSopenharmony_ci 505bd8deadSopenharmony_ciNumber 515bd8deadSopenharmony_ci 525bd8deadSopenharmony_ci OpenGL ES Extension #213 535bd8deadSopenharmony_ci 545bd8deadSopenharmony_ciDependencies 555bd8deadSopenharmony_ci 565bd8deadSopenharmony_ci OpenGL ES 3.1 and OpenGL ES Shading Language 3.10 are required. 575bd8deadSopenharmony_ci 585bd8deadSopenharmony_ci This specification is written against the OpenGL ES 3.1 (March 17, 595bd8deadSopenharmony_ci 2014) and OpenGL ES 3.10 Shading Language (March 17, 2014) 605bd8deadSopenharmony_ci Specifications. 615bd8deadSopenharmony_ci 625bd8deadSopenharmony_ci OES_shader_multisample_interpolation trivially affects the definition of 635bd8deadSopenharmony_ci this extension. 645bd8deadSopenharmony_ci 655bd8deadSopenharmony_ci OES_geometry_shader and EXT_geometry_shader interact with this extension. 665bd8deadSopenharmony_ci 675bd8deadSopenharmony_ci OES_tessellation_shader and EXT_tessellation_shader interact with this 685bd8deadSopenharmony_ci extension. 695bd8deadSopenharmony_ci 705bd8deadSopenharmony_ciOverview 715bd8deadSopenharmony_ci 725bd8deadSopenharmony_ci This extension extends the functionality of interface blocks to 735bd8deadSopenharmony_ci support input and output interfaces in the OpenGL ES Shading Language. 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ci Input and output interface blocks are used for forming the 765bd8deadSopenharmony_ci interfaces between vertex, tessellation control, tessellation 775bd8deadSopenharmony_ci evaluation, geometry and fragment shaders. This accommodates passing 785bd8deadSopenharmony_ci arrays between stages, which otherwise would require multi-dimensional 795bd8deadSopenharmony_ci array support for tessellation control outputs and for tessellation 805bd8deadSopenharmony_ci control, tessellation evaluation, and geometry shader inputs. 815bd8deadSopenharmony_ci 825bd8deadSopenharmony_ci This extension provides support for application defined 835bd8deadSopenharmony_ci interface blocks which are used for passing application-specific 845bd8deadSopenharmony_ci information between shader stages. 855bd8deadSopenharmony_ci 865bd8deadSopenharmony_ci This extension moves the built-in "per-vertex" in/out variables 875bd8deadSopenharmony_ci to a new built-in gl_PerVertex block. This is necessary for 885bd8deadSopenharmony_ci tessellation and geometry shaders which require a separate 895bd8deadSopenharmony_ci instance for each vertex, but it can also be useful for vertex 905bd8deadSopenharmony_ci shaders. 915bd8deadSopenharmony_ci 925bd8deadSopenharmony_ci Finally, this extension allows the redeclaration of the 935bd8deadSopenharmony_ci gl_PerVertex block in order to reduce the set of variables that must 945bd8deadSopenharmony_ci be passed between shaders. 955bd8deadSopenharmony_ci 965bd8deadSopenharmony_ciNew Procedures and Functions 975bd8deadSopenharmony_ci 985bd8deadSopenharmony_ci None 995bd8deadSopenharmony_ci 1005bd8deadSopenharmony_ciNew Tokens 1015bd8deadSopenharmony_ci 1025bd8deadSopenharmony_ci None 1035bd8deadSopenharmony_ci 1045bd8deadSopenharmony_ciAdditions to Chapter 7 of the OpenGL ES 3.1 Specification (Programs and Shaders) 1055bd8deadSopenharmony_ci 1065bd8deadSopenharmony_ci Modify section 7.4.1 "Shader Interface Matching": 1075bd8deadSopenharmony_ci 1085bd8deadSopenharmony_ci When multiple shader stages are active, the outputs of one stage form an 1095bd8deadSopenharmony_ci interface with the inputs of the next stage. At each such interface, 1105bd8deadSopenharmony_ci shader inputs are matched up against outputs from the previous stage: 1115bd8deadSopenharmony_ci 1125bd8deadSopenharmony_ci * An output block is considered to match an input block in the 1135bd8deadSopenharmony_ci subsequent shader if the two blocks have the same block name, and 1145bd8deadSopenharmony_ci the members of the block match exactly in name, type, qualification, 1155bd8deadSopenharmony_ci and declaration order. 1165bd8deadSopenharmony_ci 1175bd8deadSopenharmony_ci * An output variable is considered to match an input variable in the 1185bd8deadSopenharmony_ci subsequent shader if: 1195bd8deadSopenharmony_ci 1205bd8deadSopenharmony_ci - the two variables match in name, type, and qualification; or 1215bd8deadSopenharmony_ci 1225bd8deadSopenharmony_ci - the two variables are declared with the same location layout 1235bd8deadSopenharmony_ci qualifier and match in type and qualification. 1245bd8deadSopenharmony_ci 1255bd8deadSopenharmony_ci Variables or block members declared as structures are considered to 1265bd8deadSopenharmony_ci match in type if and only if structure members match in name, type, 1275bd8deadSopenharmony_ci qualification, and declaration order. Variables or block members 1285bd8deadSopenharmony_ci declared as arrays are considered to match in type only if both 1295bd8deadSopenharmony_ci declarations specify the same element type and array size. The rules for 1305bd8deadSopenharmony_ci determining if variables or block members match in qualification are 1315bd8deadSopenharmony_ci found in the OpenGL ES Shading Language Specification. 1325bd8deadSopenharmony_ci 1335bd8deadSopenharmony_ci For program objects containing multiple shaders, LinkProgram will check 1345bd8deadSopenharmony_ci for mismatches on interfaces between shader stages in the program being 1355bd8deadSopenharmony_ci linked and generate a link error if a mismatch is detected. A link error 1365bd8deadSopenharmony_ci will be generated if any statically referenced input variable or block 1375bd8deadSopenharmony_ci does not have a matching output. 1385bd8deadSopenharmony_ci 1395bd8deadSopenharmony_ci With separable program objects ... 1405bd8deadSopenharmony_ci 1415bd8deadSopenharmony_ci At an interface between program objects, the set of inputs and outputs 1425bd8deadSopenharmony_ci are considered to match exactly if and only if: 1435bd8deadSopenharmony_ci 1445bd8deadSopenharmony_ci * Every declared input block or variable has a matching output, 1455bd8deadSopenharmony_ci as described above. 1465bd8deadSopenharmony_ci 1475bd8deadSopenharmony_ci * There are no output blocks or user-defined output variables declared 1485bd8deadSopenharmony_ci without a matching input block or variable declaration. 1495bd8deadSopenharmony_ci 1505bd8deadSopenharmony_ci * All matched input and output variables (in a block or otherwise) have 1515bd8deadSopenharmony_ci identical precision qualification. 1525bd8deadSopenharmony_ci 1535bd8deadSopenharmony_ci When the set of inputs and outputs ... 1545bd8deadSopenharmony_ci 1555bd8deadSopenharmony_ci When using any built-in input or output in the gl_PerVertex block in 1565bd8deadSopenharmony_ci separable program objects, shader code may redeclare that block prior 1575bd8deadSopenharmony_ci to use. If the shader does not redeclare the block, the intrinsically 1585bd8deadSopenharmony_ci declared definition of that block will be used. 1595bd8deadSopenharmony_ci 1605bd8deadSopenharmony_ci A separable program will fail to link if: 1615bd8deadSopenharmony_ci 1625bd8deadSopenharmony_ci * the shader uses a built-in block member not found in the 1635bd8deadSopenharmony_ci (re)declaration of that block. 1645bd8deadSopenharmony_ci 1655bd8deadSopenharmony_ci There is one exception to this rule described below. 1665bd8deadSopenharmony_ci 1675bd8deadSopenharmony_ci As described above, an exact interface match requires matching built-in 1685bd8deadSopenharmony_ci input and output blocks. At an interface between two non-fragment shader 1695bd8deadSopenharmony_ci stages, the gl_PerVertex input and output blocks are considered to match 1705bd8deadSopenharmony_ci if and only if the block members match exactly in name, type, 1715bd8deadSopenharmony_ci qualification, and declaration order. At an interface involving the 1725bd8deadSopenharmony_ci fragment shader stage, the presence or absence of any built-in output 1735bd8deadSopenharmony_ci does not affect interface matching. At an interface involving the 1745bd8deadSopenharmony_ci vertex shader stage, built-in outputs not found in a block in the 1755bd8deadSopenharmony_ci vertex shader are considered to match the corresponding inputs found 1765bd8deadSopenharmony_ci in the gl_PerVertex input block of the subsequent non-fragment stage, 1775bd8deadSopenharmony_ci provided they match in precision qualification. 1785bd8deadSopenharmony_ci 1795bd8deadSopenharmony_ci Built-in inputs or outputs not found in blocks do not affect interface 1805bd8deadSopenharmony_ci matching. Any such built-in inputs are well-defined unless they are 1815bd8deadSopenharmony_ci derived from built-in outputs not written by the previous shader stage. 1825bd8deadSopenharmony_ci 1835bd8deadSopenharmony_ciNew State 1845bd8deadSopenharmony_ci 1855bd8deadSopenharmony_ci None 1865bd8deadSopenharmony_ci 1875bd8deadSopenharmony_ciNew Implementation Dependent State 1885bd8deadSopenharmony_ci 1895bd8deadSopenharmony_ci None 1905bd8deadSopenharmony_ci 1915bd8deadSopenharmony_ciAdditions to the OpenGL ES Shading Language 3.10 Specification 1925bd8deadSopenharmony_ci 1935bd8deadSopenharmony_ci Including the following line in a shader can be used to control the 1945bd8deadSopenharmony_ci language features described in this extension: 1955bd8deadSopenharmony_ci 1965bd8deadSopenharmony_ci #extension GL_OES_shader_io_blocks : <behavior> 1975bd8deadSopenharmony_ci 1985bd8deadSopenharmony_ci where <behavior> is as specified in section 3.4. 1995bd8deadSopenharmony_ci 2005bd8deadSopenharmony_ci A new preprocessor #define is added to the OpenGL ES Shading Language: 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci #define GL_OES_shader_io_blocks 1 2035bd8deadSopenharmony_ci 2045bd8deadSopenharmony_ci If the OES_geometry_shader extension is enabled, the 2055bd8deadSopenharmony_ci OES_shader_io_blocks extension is also implicitly enabled. 2065bd8deadSopenharmony_ci 2075bd8deadSopenharmony_ci If the OES_tessellation_shader extension is enabled, the 2085bd8deadSopenharmony_ci OES_shader_io_blocks extension is also implicitly enabled. 2095bd8deadSopenharmony_ci 2105bd8deadSopenharmony_ci 2115bd8deadSopenharmony_ci Modify section 3.8 "Identifiers:" 2125bd8deadSopenharmony_ci 2135bd8deadSopenharmony_ci Replace the second paragraph with the following: 2145bd8deadSopenharmony_ci 2155bd8deadSopenharmony_ci Identifiers starting with "gl_" are reserved for use by OpenGL ES, and 2165bd8deadSopenharmony_ci may not be declared in a shader as either a variable or a function; this 2175bd8deadSopenharmony_ci results in a compile-time error. However, as noted in the specification, 2185bd8deadSopenharmony_ci there are some cases where previously declared variables can be redeclared, 2195bd8deadSopenharmony_ci and predeclared "gl_" names are allowed to be redeclared in a shader only 2205bd8deadSopenharmony_ci for these specific purposes. More generally, it is a compile-time error to 2215bd8deadSopenharmony_ci redeclare a variable, including those starting "gl_". 2225bd8deadSopenharmony_ci 2235bd8deadSopenharmony_ci 2245bd8deadSopenharmony_ci Modify section 4.3.4 "Input Variables": 2255bd8deadSopenharmony_ci 2265bd8deadSopenharmony_ci Add following the first paragraph on p. 39: 2275bd8deadSopenharmony_ci 2285bd8deadSopenharmony_ci ... superfluous declarations of input variables. 2295bd8deadSopenharmony_ci 2305bd8deadSopenharmony_ci Only the input variables that are statically read need to be written by 2315bd8deadSopenharmony_ci the previous stage; it is allowed to have superfluous declarations of 2325bd8deadSopenharmony_ci input variables. This is shown in the following table. 2335bd8deadSopenharmony_ci 2345bd8deadSopenharmony_ci[?? clarify this is for internal interfaces only] 2355bd8deadSopenharmony_ci ----------------------------------------------------------------------------------- 2365bd8deadSopenharmony_ci | | Consuming Shader (input variables) | 2375bd8deadSopenharmony_ci | Treatment of Mismatched +---------------------------------------------------+ 2385bd8deadSopenharmony_ci | Input Variables | No | Declared but | Declared and | 2395bd8deadSopenharmony_ci | | Declaration | no Static Use | Static Use | 2405bd8deadSopenharmony_ci +-----------------------------+-------------+---------------+---------------------| 2415bd8deadSopenharmony_ci | | No Declaration | Allowed | Allowed | Link-Time Error | 2425bd8deadSopenharmony_ci | Generating |----------------+-------------+---------------+---------------------| 2435bd8deadSopenharmony_ci | Shader | Declared but | Allowed | Allowed | Allowed (values | 2445bd8deadSopenharmony_ci | (output | no Static Use | | | are undefined) | 2455bd8deadSopenharmony_ci | variables) |----------------+-------------+---------------+---------------------| 2465bd8deadSopenharmony_ci | | Declared and | | | Allowed (values are | 2475bd8deadSopenharmony_ci | | Static Use | Allowed | Allowed | potentially undef.) | 2485bd8deadSopenharmony_ci | | | | | | 2495bd8deadSopenharmony_ci ----------------------------------------------------------------------------------- 2505bd8deadSopenharmony_ci 2515bd8deadSopenharmony_ci Consumption errors are based on static use only. Compilation may 2525bd8deadSopenharmony_ci generate a warning, but not an error, for any dynamic use the compiler 2535bd8deadSopenharmony_ci can deduce that might cause consumption of undefined values. 2545bd8deadSopenharmony_ci 2555bd8deadSopenharmony_ci See section 7 "Built-in Variables" ... 2565bd8deadSopenharmony_ci 2575bd8deadSopenharmony_ci 2585bd8deadSopenharmony_ci (Modify the first paragraph, starting "The output of the vertex shader", 2595bd8deadSopenharmony_ci on p. 41): 2605bd8deadSopenharmony_ci 2615bd8deadSopenharmony_ci The fragment shader inputs form an interface with the last active shader 2625bd8deadSopenharmony_ci in the vertex processing pipeline. For this interface, the last active 2635bd8deadSopenharmony_ci shader stage output variables and fragment shader input variables of the 2645bd8deadSopenharmony_ci same name must match in type and qualification, with a few exceptions... 2655bd8deadSopenharmony_ci 2665bd8deadSopenharmony_ci 2675bd8deadSopenharmony_ci (Modify the third paragraph on p. 41): 2685bd8deadSopenharmony_ci 2695bd8deadSopenharmony_ci Shaders can ensure matches across such interfaces either by using input 2705bd8deadSopenharmony_ci and output layout qualifiers (sections 4.4.1 "Input Layout Qualifiers" 2715bd8deadSopenharmony_ci and 4.4.2 "Output Layout Qualifiers") or by using identical input and 2725bd8deadSopenharmony_ci output declarations of blocks or variables. Complete rules for interface 2735bd8deadSopenharmony_ci matching are found ... 2745bd8deadSopenharmony_ci 2755bd8deadSopenharmony_ci 2765bd8deadSopenharmony_ci Modify section 4.3.9 "Interface Blocks": 2775bd8deadSopenharmony_ci 2785bd8deadSopenharmony_ci Input, output, uniform, and buffer variable declarations can be grouped 2795bd8deadSopenharmony_ci into named interface blocks to provide coarser granularity backing than 2805bd8deadSopenharmony_ci is achievable with individual declarations. They can have an optional 2815bd8deadSopenharmony_ci instance name, used in the shader to reference their members. An output 2825bd8deadSopenharmony_ci block of one programmable stage is backed by a corresponding input block 2835bd8deadSopenharmony_ci in the subsequent programmable stage. A uniform block is backed by the 2845bd8deadSopenharmony_ci application with a buffer object. A block of buffer variables, called a 2855bd8deadSopenharmony_ci shader storage block, is also backed by the application with a buffer 2865bd8deadSopenharmony_ci object. It is a compile-time error to have an input block in a vertex 2875bd8deadSopenharmony_ci shader or an output block in a fragment shader; these uses are reserved 2885bd8deadSopenharmony_ci for future use. 2895bd8deadSopenharmony_ci 2905bd8deadSopenharmony_ci An interface block is started by an "in", "out", "uniform", or "buffer" 2915bd8deadSopenharmony_ci keyword, followed by a block name, followed by an open curly brace ( { ) 2925bd8deadSopenharmony_ci as follows: 2935bd8deadSopenharmony_ci 2945bd8deadSopenharmony_ci (modify the grammar rules after the third paragraph) 2955bd8deadSopenharmony_ci 2965bd8deadSopenharmony_ci interface-block: 2975bd8deadSopenharmony_ci layout-qualifier_opt interface-storage-qualifier block-name 2985bd8deadSopenharmony_ci { member-list } instance-name_opt ; 2995bd8deadSopenharmony_ci 3005bd8deadSopenharmony_ci interface-storage-qualifier: 3015bd8deadSopenharmony_ci in 3025bd8deadSopenharmony_ci out 3035bd8deadSopenharmony_ci uniform 3045bd8deadSopenharmony_ci buffer 3055bd8deadSopenharmony_ci 3065bd8deadSopenharmony_ci ... 3075bd8deadSopenharmony_ci 3085bd8deadSopenharmony_ci Each of the above elements ... 3095bd8deadSopenharmony_ci 3105bd8deadSopenharmony_ci ... with four uniforms grouped inside it. 3115bd8deadSopenharmony_ci 3125bd8deadSopenharmony_ci Types and declarators are the same as for other input, output, uniform, 3135bd8deadSopenharmony_ci and buffer variable declarations outside blocks, with these exceptions: 3145bd8deadSopenharmony_ci 3155bd8deadSopenharmony_ci * opaque types are not allowed 3165bd8deadSopenharmony_ci * structure definitions cannot be nested inside a block 3175bd8deadSopenharmony_ci 3185bd8deadSopenharmony_ci Any of these would result in a compile-time error. Otherwise, built-in 3195bd8deadSopenharmony_ci types, previously declared structures, and arrays of these are allowed 3205bd8deadSopenharmony_ci as the type of a declarator in the same manner they are allowed outside 3215bd8deadSopenharmony_ci a block. 3225bd8deadSopenharmony_ci 3235bd8deadSopenharmony_ci If no optional qualifier is used in a member-declaration, the 3245bd8deadSopenharmony_ci qualification of the variable is just in, out, uniform, or buffer as 3255bd8deadSopenharmony_ci determined by interface-storage-qualifier. If optional qualifiers are 3265bd8deadSopenharmony_ci used, they can include interpolation qualifiers and storage qualifiers, 3275bd8deadSopenharmony_ci and they must declare an input, output, or uniform variable consistent 3285bd8deadSopenharmony_ci with the interface qualifier of the block: input, output, uniform, and 3295bd8deadSopenharmony_ci buffer variables can only be declared in in, out, uniform, and shader 3305bd8deadSopenharmony_ci storage blocks, respectively. 3315bd8deadSopenharmony_ci 3325bd8deadSopenharmony_ci Repeating the "in", "out", "uniform", or "buffer" interface qualifier 3335bd8deadSopenharmony_ci for a member's storage qualifier is optional. "centroid in" and "sample 3345bd8deadSopenharmony_ci in" variables are consistent with "in" blocks, and "centroid out" and 3355bd8deadSopenharmony_ci "sample out" variables are consistent with "out" blocks. 3365bd8deadSopenharmony_ci 3375bd8deadSopenharmony_ci A <shader interface> is defined to be one of these: 3385bd8deadSopenharmony_ci 3395bd8deadSopenharmony_ci * All the uniform variables of a program. This spans all compilation 3405bd8deadSopenharmony_ci units linked together within one program. 3415bd8deadSopenharmony_ci * All the buffer blocks declared in a program. 3425bd8deadSopenharmony_ci * The boundary between adjacent programmable pipeline stages: This 3435bd8deadSopenharmony_ci spans all the outputs declared in all compilation units of the 3445bd8deadSopenharmony_ci first stage and all the inputs declared in all compilation units 3455bd8deadSopenharmony_ci of the second stage. Note that the fragment shader is considered 3465bd8deadSopenharmony_ci to have a shared boundary with the previous adjacent stage even 3475bd8deadSopenharmony_ci though in practice, all values passed from prior stages to the 3485bd8deadSopenharmony_ci fragment shader first pass through the rasterizer and 3495bd8deadSopenharmony_ci interpolator. 3505bd8deadSopenharmony_ci 3515bd8deadSopenharmony_ci The block name (block-name) is used to match interfaces: an output block 3525bd8deadSopenharmony_ci of one pipeline stage will be matched to an input block with the same 3535bd8deadSopenharmony_ci name in the subsequent pipeline stage. For uniform or shader storage 3545bd8deadSopenharmony_ci blocks, the application uses the block name to identify the block. Block 3555bd8deadSopenharmony_ci names have no other use within a shader beyond interface matching; it is 3565bd8deadSopenharmony_ci a compile-time error to use a block name at global scope for anything 3575bd8deadSopenharmony_ci other than as a block name (e.g., use of a block name for a global 3585bd8deadSopenharmony_ci variable name or function name is currently reserved). It is a 3595bd8deadSopenharmony_ci compile-time error to use the same block name for more than one block 3605bd8deadSopenharmony_ci declaration in the same shader interface (as defined above) within one 3615bd8deadSopenharmony_ci shader, even if the block contents are identical. 3625bd8deadSopenharmony_ci 3635bd8deadSopenharmony_ci Matched block names within a shader interface (as defined above) must 3645bd8deadSopenharmony_ci match in terms of having the same number of declarations with the same 3655bd8deadSopenharmony_ci sequence of types, precisions, and the same sequence of member names, as 3665bd8deadSopenharmony_ci well as having the same member-wise layout qualification (see next 3675bd8deadSopenharmony_ci section). Matched uniform block names (but not input or output block 3685bd8deadSopenharmony_ci names) must also either all be lacking an instance name or all having an 3695bd8deadSopenharmony_ci instance name, putting their members at the same scoping level. When 3705bd8deadSopenharmony_ci instance names are present on matched block names, it is allowed for the 3715bd8deadSopenharmony_ci instance names to differ; they need not match for the blocks to match. 3725bd8deadSopenharmony_ci Furthermore, if a matching block is declared as an array, then the array 3735bd8deadSopenharmony_ci sizes must also match (or follow array matching rules for the interface 3745bd8deadSopenharmony_ci between a vertex and a geometry shader). Any mismatch will generate a 3755bd8deadSopenharmony_ci link-time error. A block name is allowed to have different definitions 3765bd8deadSopenharmony_ci in different interfaces within the same shader, allowing, for example, 3775bd8deadSopenharmony_ci an input block and output block to have the same name. 3785bd8deadSopenharmony_ci 3795bd8deadSopenharmony_ci If an instance name (instance-name) is not used, the names declared 3805bd8deadSopenharmony_ci inside the block are scoped at the global level and accessed as if they 3815bd8deadSopenharmony_ci were declared outside the block. If an instance name is used, then it 3825bd8deadSopenharmony_ci puts all the members inside a scope within its own name space, accessed 3835bd8deadSopenharmony_ci with the field selector ( . ) operator (analogously to structures). For 3845bd8deadSopenharmony_ci example, 3855bd8deadSopenharmony_ci 3865bd8deadSopenharmony_ci uniform Transform_1 3875bd8deadSopenharmony_ci { 3885bd8deadSopenharmony_ci mat4 modelview; // API will use "modelview" 3895bd8deadSopenharmony_ci } 3905bd8deadSopenharmony_ci uniform Transform_2 3915bd8deadSopenharmony_ci { 3925bd8deadSopenharmony_ci mat4 projection; // API will use "Transform_2.projection" 3935bd8deadSopenharmony_ci } transform_2; // instance name 3945bd8deadSopenharmony_ci mat4 projection; // different than transform_2.projection 3955bd8deadSopenharmony_ci mat4 modelview; // illegal, already defined 3965bd8deadSopenharmony_ci 3975bd8deadSopenharmony_ci Outside the shading language (i.e., in the API), members are similarly 3985bd8deadSopenharmony_ci identified except the block name is always used in place of the instance 3995bd8deadSopenharmony_ci name (API accesses are to interfaces, not to shaders). If there is no 4005bd8deadSopenharmony_ci instance name, then the API does not use the block name to access a 4015bd8deadSopenharmony_ci member, just the member name. 4025bd8deadSopenharmony_ci 4035bd8deadSopenharmony_ci Within an interface, all declarations of the same global name must be 4045bd8deadSopenharmony_ci for the same object and must match in type and in whether they declare a 4055bd8deadSopenharmony_ci variable or member of a block with no instance name. The API also needs 4065bd8deadSopenharmony_ci this name to uniquely identify an object in the interface. It is a 4075bd8deadSopenharmony_ci link-time error if any particular interface contains 4085bd8deadSopenharmony_ci 4095bd8deadSopenharmony_ci * two different blocks, each having no instance name, and each 4105bd8deadSopenharmony_ci having a member of the same name, or 4115bd8deadSopenharmony_ci * a variable outside a block, and a block with no instance name, 4125bd8deadSopenharmony_ci where the variable has the same name as a member in the block. 4135bd8deadSopenharmony_ci 4145bd8deadSopenharmony_ci out Vertex { 4155bd8deadSopenharmony_ci vec4 Position; // API transform/feedback will use "Vertex.Position" 4165bd8deadSopenharmony_ci vec2 Texture; 4175bd8deadSopenharmony_ci } Coords; // shader will use "Coords.Position" 4185bd8deadSopenharmony_ci out Vertex2 { 4195bd8deadSopenharmony_ci vec4 Color; // API will use "Color" 4205bd8deadSopenharmony_ci float Color2; 4215bd8deadSopenharmony_ci }; 4225bd8deadSopenharmony_ci // in same program as Vertex2 above: 4235bd8deadSopenharmony_ci out Vertex3 { 4245bd8deadSopenharmony_ci float Intensity; 4255bd8deadSopenharmony_ci vec4 Color; // ERROR, name collision with Color in Vertex2 4265bd8deadSopenharmony_ci }; 4275bd8deadSopenharmony_ci float Color2; // ERROR, collides with Color2 in Vertex2 4285bd8deadSopenharmony_ci 4295bd8deadSopenharmony_ci For blocks declared as arrays, the array index must also be included 4305bd8deadSopenharmony_ci when accessing members, as in this example 4315bd8deadSopenharmony_ci 4325bd8deadSopenharmony_ci uniform Transform { // API uses "Transform[2]" to refer to instance 2 4335bd8deadSopenharmony_ci mat4 ModelViewMatrix; 4345bd8deadSopenharmony_ci mat4 ModelViewProjectionMatrix; 4355bd8deadSopenharmony_ci float Deformation; 4365bd8deadSopenharmony_ci } transforms[4]; 4375bd8deadSopenharmony_ci ... 4385bd8deadSopenharmony_ci ... = transforms[2].ModelViewMatrix; // shader access of instance 2 4395bd8deadSopenharmony_ci // API uses "Transform.ModelViewMatrix" to query an offset or other query 4405bd8deadSopenharmony_ci 4415bd8deadSopenharmony_ci For uniform or shader storage blocks declared as an array, each 4425bd8deadSopenharmony_ci individual array element corresponds to a separate buffer object, 4435bd8deadSopenharmony_ci backing one instance of the block. As the array size indicates the 4445bd8deadSopenharmony_ci number of buffer objects needed, uniform and shader storage block array 4455bd8deadSopenharmony_ci declarations must specify an array size. All indices used to index a 4465bd8deadSopenharmony_ci uniform or shader storage block array must be constant integral 4475bd8deadSopenharmony_ci expressions. 4485bd8deadSopenharmony_ci 4495bd8deadSopenharmony_ci When using OpenGL ES API entry points to identify the name of an 4505bd8deadSopenharmony_ci individual block in an array of blocks, the name string must include an 4515bd8deadSopenharmony_ci array index (e.g., Transform[2]). When using OpenGL ES API entry points 4525bd8deadSopenharmony_ci to refer to offsets or other characteristics of a block member, an array 4535bd8deadSopenharmony_ci index must not be specified (e.g., Transform.ModelViewMatrix). 4545bd8deadSopenharmony_ci 4555bd8deadSopenharmony_ci There are implementation dependent limits on the number of uniform 4565bd8deadSopenharmony_ci blocks and the number of shader storage blocks that can be used per 4575bd8deadSopenharmony_ci stage. If either limit is exceeded, it will cause a link-time error. 4585bd8deadSopenharmony_ci 4595bd8deadSopenharmony_ci 4605bd8deadSopenharmony_ci Modify section 4.4 "Layout Qualifiers": 4615bd8deadSopenharmony_ci 4625bd8deadSopenharmony_ci Layout qualifiers can appear in several forms of declaration. They can 4635bd8deadSopenharmony_ci appear as part of an interface block definition or block member, as 4645bd8deadSopenharmony_ci shown in the grammar in the previous section. They can also appear with 4655bd8deadSopenharmony_ci just an interface qualifier (a storage qualifier that is "in", "out", or 4665bd8deadSopenharmony_ci "uniform") to establish layouts of other declarations made with that 4675bd8deadSopenharmony_ci interface qualifier: 4685bd8deadSopenharmony_ci 4695bd8deadSopenharmony_ci layout-qualifier interface-qualifier ; 4705bd8deadSopenharmony_ci 4715bd8deadSopenharmony_ci ... 4725bd8deadSopenharmony_ci 4735bd8deadSopenharmony_ci The layout-qualifier expands to 4745bd8deadSopenharmony_ci 4755bd8deadSopenharmony_ci layout-qualifier : 4765bd8deadSopenharmony_ci layout ( layout-qualifier-id-list ) 4775bd8deadSopenharmony_ci 4785bd8deadSopenharmony_ci layout-qualifier-id-list : 4795bd8deadSopenharmony_ci layout-qualifier-id 4805bd8deadSopenharmony_ci layout-qualifier-id , layout-qualifier-id-list 4815bd8deadSopenharmony_ci 4825bd8deadSopenharmony_ci layout-qualifier-id 4835bd8deadSopenharmony_ci layout-qualifier-name 4845bd8deadSopenharmony_ci layout-qualifier-name = layout-qualifier-value 4855bd8deadSopenharmony_ci 4865bd8deadSopenharmony_ci The tokens used for layout-qualifier-name are identifiers, not keywords. 4875bd8deadSopenharmony_ci Generally, they can be listed in any order. Order-dependent meanings 4885bd8deadSopenharmony_ci exist only if explicitly called out below. Similarly, these identifiers 4895bd8deadSopenharmony_ci are not case sensitive, unless explicitly noted otherwise. 4905bd8deadSopenharmony_ci 4915bd8deadSopenharmony_ci More than one layout qualifier may appear in a single declaration. 4925bd8deadSopenharmony_ci Additionally, the same layout-qualifier-name can occur multiple times 4935bd8deadSopenharmony_ci within a layout qualifier or across multiple layout qualifiers in the 4945bd8deadSopenharmony_ci same declaration. When the same layout-qualifier-name occurs multiple 4955bd8deadSopenharmony_ci times, in a single declaration, the last occurrence overrides the former 4965bd8deadSopenharmony_ci occurrence(s). Further, if such a layout-qualifier-name will effect 4975bd8deadSopenharmony_ci subsequent declarations or other observable behavior, it is only the 4985bd8deadSopenharmony_ci last occurrence that will have any effect, behaving as if the earlier 4995bd8deadSopenharmony_ci occurrence(s) within the declaration are not present. This is also true 5005bd8deadSopenharmony_ci for overriding layout-qualifier-names, where one overrides the other 5015bd8deadSopenharmony_ci (e.g., row_major vs. column_major); only the last occurrence has any 5025bd8deadSopenharmony_ci effect. 5035bd8deadSopenharmony_ci 5045bd8deadSopenharmony_ci [[ The last paragraph of this section in GLSL 4.40 and the really nice 5055bd8deadSopenharmony_ci table of layout qualifiers from different stages could be inserted 5065bd8deadSopenharmony_ci at this point, but aren't necessary. ]] 5075bd8deadSopenharmony_ci 5085bd8deadSopenharmony_ci 4.4.1 Input Layout Qualifiers 5095bd8deadSopenharmony_ci 5105bd8deadSopenharmony_ci Some input layout qualifiers apply to all shader languages and some 5115bd8deadSopenharmony_ci apply only to specific languages. The latter are discussed in separate 5125bd8deadSopenharmony_ci sections below. 5135bd8deadSopenharmony_ci 5145bd8deadSopenharmony_ci All shaders, except compute shaders, allow "location" layout qualifiers 5155bd8deadSopenharmony_ci on input variable declarations, input block declarations, and input 5165bd8deadSopenharmony_ci block member declarations. 5175bd8deadSopenharmony_ci 5185bd8deadSopenharmony_ci The layout qualifier identifier for inputs is: 5195bd8deadSopenharmony_ci 5205bd8deadSopenharmony_ci layout-qualifier-id 5215bd8deadSopenharmony_ci location = integer-constant 5225bd8deadSopenharmony_ci 5235bd8deadSopenharmony_ci Only one argument is accepted. For example, 5245bd8deadSopenharmony_ci 5255bd8deadSopenharmony_ci layout(location = 3) in vec4 normal; 5265bd8deadSopenharmony_ci 5275bd8deadSopenharmony_ci will establish that the shader input <normal> is assigned to vector 5285bd8deadSopenharmony_ci location number 3. For vertex shader inputs, the location specifies the 5295bd8deadSopenharmony_ci number of the vertex attribute from which input values are taken. For 5305bd8deadSopenharmony_ci inputs of all other shader types, the location specifies a vector number 5315bd8deadSopenharmony_ci that can be used to match against outputs from a previous shader stage, 5325bd8deadSopenharmony_ci even if that shader is in a different program object. 5335bd8deadSopenharmony_ci 5345bd8deadSopenharmony_ci The following language describes how many locations are consumed by a 5355bd8deadSopenharmony_ci given type. However, geometry shader inputs, tessellation control shader 5365bd8deadSopenharmony_ci inputs and outputs, and tessellation evaluation inputs all have an 5375bd8deadSopenharmony_ci additional level of arrayness relative to other shader inputs and outputs. 5385bd8deadSopenharmony_ci This outer array level is removed from the type before considering how 5395bd8deadSopenharmony_ci many locations the type consumes. 5405bd8deadSopenharmony_ci 5415bd8deadSopenharmony_ci If a shader input is any scalar or vector type, it will consume a single 5425bd8deadSopenharmony_ci location. 5435bd8deadSopenharmony_ci 5445bd8deadSopenharmony_ci If the declared input (after potentially removing an outer array level as 5455bd8deadSopenharmony_ci just described above) is an array of size <n> and each of the elements 5465bd8deadSopenharmony_ci takes <m> locations, it will be assigned <m> * <n> consecutive locations 5475bd8deadSopenharmony_ci starting with the location specified. For example, 5485bd8deadSopenharmony_ci 5495bd8deadSopenharmony_ci layout (location = 6) in vec4 colors[3]; 5505bd8deadSopenharmony_ci 5515bd8deadSopenharmony_ci will establish that the shader input <colors> is assigned to vector 5525bd8deadSopenharmony_ci location numbers 6, 7, and 8. 5535bd8deadSopenharmony_ci 5545bd8deadSopenharmony_ci If the declared input is an <n> x <m> matrix, it will be assigned multiple 5555bd8deadSopenharmony_ci locations starting with the location specified. The number of locations 5565bd8deadSopenharmony_ci assigned for each matrix will be the same as for an <n>-element array of 5575bd8deadSopenharmony_ci <m>-component vectors. For example, 5585bd8deadSopenharmony_ci 5595bd8deadSopenharmony_ci layout (location = 9) in mat4 transforms[2]; 5605bd8deadSopenharmony_ci 5615bd8deadSopenharmony_ci will establish that shader input <transforms> is assigned to vector 5625bd8deadSopenharmony_ci locations 9-16, with <transforms[0]> being assigned to locations 9-12, 5635bd8deadSopenharmony_ci and <transforms[1]> being assigned to locations 13-16. 5645bd8deadSopenharmony_ci 5655bd8deadSopenharmony_ci If the declared input is a structure or block, its members will be 5665bd8deadSopenharmony_ci assigned consecutive locations in their order of declaration, with the 5675bd8deadSopenharmony_ci first member assigned the location provided in the layout qualifier. For 5685bd8deadSopenharmony_ci a structure, this process applies to the entire structure. It is a 5695bd8deadSopenharmony_ci compile-time error to use a location qualifier on a member of a 5705bd8deadSopenharmony_ci structure. For a block, this process applies to the entire block, or 5715bd8deadSopenharmony_ci until the first member is reached that has a location layout qualifier. 5725bd8deadSopenharmony_ci When a block member is declared with a location qualifier, its location 5735bd8deadSopenharmony_ci comes from that qualifier: The member's location qualifier overrides the 5745bd8deadSopenharmony_ci block-level declaration. Subsequent members are again assigned 5755bd8deadSopenharmony_ci consecutive locations, based on the newest location, until the next 5765bd8deadSopenharmony_ci member declared with a location qualifier. The values used for locations 5775bd8deadSopenharmony_ci do not have to be declared in increasing order. 5785bd8deadSopenharmony_ci 5795bd8deadSopenharmony_ci If a block has no block-level location layout qualifier, it is required 5805bd8deadSopenharmony_ci that either all or none of its members have a location layout qualifier, 5815bd8deadSopenharmony_ci or a compile-time error results. 5825bd8deadSopenharmony_ci 5835bd8deadSopenharmony_ci The locations consumed by block and structure members are determined by 5845bd8deadSopenharmony_ci applying the rules above recursively as though the structure member were 5855bd8deadSopenharmony_ci declared as an input variable of the same type. For example: 5865bd8deadSopenharmony_ci 5875bd8deadSopenharmony_ci layout(location = 3) in struct S { 5885bd8deadSopenharmony_ci vec3 a; // gets location 3 5895bd8deadSopenharmony_ci mat2 b; // gets locations 4 and 5 5905bd8deadSopenharmony_ci vec4 c[2]; // gets locations 6 and 7 5915bd8deadSopenharmony_ci layout (location = 8) vec2 A; // ERROR, can't use on struct member 5925bd8deadSopenharmony_ci } s; 5935bd8deadSopenharmony_ci 5945bd8deadSopenharmony_ci layout(location = 4) in block { 5955bd8deadSopenharmony_ci vec4 d; // gets location 4 5965bd8deadSopenharmony_ci vec4 e; // gets location 5 5975bd8deadSopenharmony_ci layout(location = 7) vec4 f; // gets location 7 5985bd8deadSopenharmony_ci vec4 g; // gets location 8 5995bd8deadSopenharmony_ci layout (location = 1) vec4 h; // gets location 1 6005bd8deadSopenharmony_ci vec4 i; // gets location 2 6015bd8deadSopenharmony_ci vec4 j; // gets location 3 6025bd8deadSopenharmony_ci vec4 k; // ERROR, location 4 already used 6035bd8deadSopenharmony_ci }; 6045bd8deadSopenharmony_ci 6055bd8deadSopenharmony_ci The number of input locations available to a shader is limited. For 6065bd8deadSopenharmony_ci vertex shaders, the limit is the advertised number of vertex attributes. 6075bd8deadSopenharmony_ci For all other shaders, the limit is implementation-dependent and must be 6085bd8deadSopenharmony_ci no less than one fourth of the advertised maximum input component count. 6095bd8deadSopenharmony_ci A program will fail to link if any attached shader uses a location 6105bd8deadSopenharmony_ci greater than or equal to the number of supported locations, unless 6115bd8deadSopenharmony_ci device-dependent optimizations are able to make the program fit within 6125bd8deadSopenharmony_ci available hardware resources. 6135bd8deadSopenharmony_ci 6145bd8deadSopenharmony_ci A program will fail to link if explicit location assignments leave the 6155bd8deadSopenharmony_ci linker unable to find space for other variables without explicit 6165bd8deadSopenharmony_ci assignments. 6175bd8deadSopenharmony_ci 6185bd8deadSopenharmony_ci For the purposes of determining if a non-vertex input matches an output 6195bd8deadSopenharmony_ci from a previous shader stage, the location layout qualifier (if any) 6205bd8deadSopenharmony_ci must match. 6215bd8deadSopenharmony_ci 6225bd8deadSopenharmony_ci If a vertex shader input variable with no location assigned in the 6235bd8deadSopenharmony_ci shader text has a location specified through the OpenGL ES API, the 6245bd8deadSopenharmony_ci API-assigned location will be used. Otherwise, such variables will 6255bd8deadSopenharmony_ci be assigned a location by the linker. See section 2.11.5 "Vertex 6265bd8deadSopenharmony_ci Attributes" of the OpenGL ES 3.1 Graphics System Specification for 6275bd8deadSopenharmony_ci more details. 6285bd8deadSopenharmony_ci 6295bd8deadSopenharmony_ci It is an error if more than one input or element of a matrix input is 6305bd8deadSopenharmony_ci bound to the same location. 6315bd8deadSopenharmony_ci 6325bd8deadSopenharmony_ci 6335bd8deadSopenharmony_ci Add new subsection 4.4.1.fs: 6345bd8deadSopenharmony_ci 6355bd8deadSopenharmony_ci 4.4.1.fs Fragment Shader Inputs 6365bd8deadSopenharmony_ci 6375bd8deadSopenharmony_ci Fragment shaders can have an input layout for redeclaring the built-in 6385bd8deadSopenharmony_ci variable gl_FragCoord: 6395bd8deadSopenharmony_ci 6405bd8deadSopenharmony_ci in vec4 gl_FragCoord; // redeclaration that changes nothing is allowed 6415bd8deadSopenharmony_ci 6425bd8deadSopenharmony_ci The built-in gl_FragCoord is only predeclared in fragment shaders, so 6435bd8deadSopenharmony_ci redeclaring it in any other shader language results in a compile-time 6445bd8deadSopenharmony_ci error. 6455bd8deadSopenharmony_ci 6465bd8deadSopenharmony_ci Fragment shaders also allow the following layout qualifier on "in" only 6475bd8deadSopenharmony_ci (not with variable declarations) 6485bd8deadSopenharmony_ci 6495bd8deadSopenharmony_ci layout-qualifier-id 6505bd8deadSopenharmony_ci early_fragment_tests 6515bd8deadSopenharmony_ci 6525bd8deadSopenharmony_ci to request that fragment tests be performed before fragment shader 6535bd8deadSopenharmony_ci execution, as described in section 3.9.2 "Early Fragment Tests" of the 6545bd8deadSopenharmony_ci OpenGL ES Specification. 6555bd8deadSopenharmony_ci 6565bd8deadSopenharmony_ci For example, specifying 6575bd8deadSopenharmony_ci 6585bd8deadSopenharmony_ci layout(early_fragment_tests) in; 6595bd8deadSopenharmony_ci 6605bd8deadSopenharmony_ci will make per-fragment tests be performed before fragment shader 6615bd8deadSopenharmony_ci execution. In addition, it is an error to statically write to 6625bd8deadSopenharmony_ci gl_FragDepth in the fragment shader. 6635bd8deadSopenharmony_ci 6645bd8deadSopenharmony_ci If this is not declared, per-fragment tests will be performed after 6655bd8deadSopenharmony_ci fragment shader execution. 6665bd8deadSopenharmony_ci 6675bd8deadSopenharmony_ci 4.4.1.1 Compute Shader Inputs ... 6685bd8deadSopenharmony_ci 6695bd8deadSopenharmony_ci 6705bd8deadSopenharmony_ci Replace section 4.4.2 6715bd8deadSopenharmony_ci 6725bd8deadSopenharmony_ci 4.4.2 Output Layout Qualifiers 6735bd8deadSopenharmony_ci 6745bd8deadSopenharmony_ci Some output layout qualifiers apply to all shader languages and some 6755bd8deadSopenharmony_ci apply only to specific languages. The latter are discussed in separate 6765bd8deadSopenharmony_ci sections below. 6775bd8deadSopenharmony_ci 6785bd8deadSopenharmony_ci As with input layout qualifiers, all shaders except compute shaders 6795bd8deadSopenharmony_ci allow location layout qualifiers on output variable declarations, output 6805bd8deadSopenharmony_ci block declarations, and output block member declarations. 6815bd8deadSopenharmony_ci 6825bd8deadSopenharmony_ci The layout qualifier identifier for outputs is: 6835bd8deadSopenharmony_ci 6845bd8deadSopenharmony_ci layout-qualifier-id 6855bd8deadSopenharmony_ci location = integer-constant 6865bd8deadSopenharmony_ci 6875bd8deadSopenharmony_ci The usage and rules for applying the location qualifier to blocks and 6885bd8deadSopenharmony_ci structures are exactly as described in section 4.4.1 "Input Layout 6895bd8deadSopenharmony_ci Qualifiers". 6905bd8deadSopenharmony_ci 6915bd8deadSopenharmony_ci 6925bd8deadSopenharmony_ci This qualifier may appear at most once with a declaration. For example, 6935bd8deadSopenharmony_ci 6945bd8deadSopenharmony_ci layout(location = 3) out vec4 color; 6955bd8deadSopenharmony_ci 6965bd8deadSopenharmony_ci will establish that the fragment shader output color is assigned to 6975bd8deadSopenharmony_ci fragment color 3. 6985bd8deadSopenharmony_ci 6995bd8deadSopenharmony_ci For fragment shader outputs, the location specifies the color output 7005bd8deadSopenharmony_ci number receiving the values of the output. For outputs of all other 7015bd8deadSopenharmony_ci shader stages, the location specifies a vector number that can be used 7025bd8deadSopenharmony_ci to match against inputs in a subsequent shader stage, even if that 7035bd8deadSopenharmony_ci shader is in a different program object. 7045bd8deadSopenharmony_ci 7055bd8deadSopenharmony_ci Declared outputs of scalar or vector type consume a single location. 7065bd8deadSopenharmony_ci 7075bd8deadSopenharmony_ci If the declared output is an array, it will be assigned consecutive 7085bd8deadSopenharmony_ci locations starting with the location specified. For example, 7095bd8deadSopenharmony_ci 7105bd8deadSopenharmony_ci layout(location = 2) out vec4 colors[3]; 7115bd8deadSopenharmony_ci 7125bd8deadSopenharmony_ci will establish that <colors> is assigned to vector location numbers 2, 7135bd8deadSopenharmony_ci 3, and 4. 7145bd8deadSopenharmony_ci 7155bd8deadSopenharmony_ci If the declared output is an n x m matrix, it will be assigned multiple 7165bd8deadSopenharmony_ci locations starting with the location specified. The number of locations 7175bd8deadSopenharmony_ci assigned will be the same as for an n-element array of m-component 7185bd8deadSopenharmony_ci vectors. 7195bd8deadSopenharmony_ci 7205bd8deadSopenharmony_ci If the declared output is a structure, its members will be assigned 7215bd8deadSopenharmony_ci consecutive locations in the order of declaration, with the first member 7225bd8deadSopenharmony_ci assigned the location specified for the structure. The number of 7235bd8deadSopenharmony_ci locations consumed by a structure member is determined by applying the 7245bd8deadSopenharmony_ci rules above recursively as though the structure member were declared as 7255bd8deadSopenharmony_ci an output variable of the same type. 7265bd8deadSopenharmony_ci 7275bd8deadSopenharmony_ci Location layout qualifiers may be used on output variables declared as 7285bd8deadSopenharmony_ci structures, but it is a compile-time error to use them on individual 7295bd8deadSopenharmony_ci members. Location layout qualifiers may be used on output blocks and 7305bd8deadSopenharmony_ci output block members. 7315bd8deadSopenharmony_ci 7325bd8deadSopenharmony_ci The number of output locations available to a shader is limited. For 7335bd8deadSopenharmony_ci fragment shaders, the limit is the advertised number of draw buffers. 7345bd8deadSopenharmony_ci For all other shaders, the limit is implementation-dependent and must be 7355bd8deadSopenharmony_ci no less than one fourth of the advertised maximum output component 7365bd8deadSopenharmony_ci count (compute shaders have no outputs.) A program will fail to link if 7375bd8deadSopenharmony_ci any attached shader uses a location greater than or equal to the number 7385bd8deadSopenharmony_ci of supported locations, unless device-dependent optimizations are able 7395bd8deadSopenharmony_ci to make the program fit within available hardware resources. 7405bd8deadSopenharmony_ci Compile-time errors may also be given if at compile time it is known the 7415bd8deadSopenharmony_ci link will fail. A negative output location will result in a compile-time 7425bd8deadSopenharmony_ci error. 7435bd8deadSopenharmony_ci 7445bd8deadSopenharmony_ci A program will fail to link if any of the following occur: 7455bd8deadSopenharmony_ci 7465bd8deadSopenharmony_ci * any two fragment shader output variables are assigned to the same 7475bd8deadSopenharmony_ci location 7485bd8deadSopenharmony_ci * if any two output variables from the same vertex stage are assigned 7495bd8deadSopenharmony_ci to the same location. 7505bd8deadSopenharmony_ci 7515bd8deadSopenharmony_ci For all shader types, a program will fail to link if explicit location 7525bd8deadSopenharmony_ci assignments leave the linker unable to find space for other variables 7535bd8deadSopenharmony_ci without explicit assignments. 7545bd8deadSopenharmony_ci 7555bd8deadSopenharmony_ci If an output variable has no location assigned in the shader text, it 7565bd8deadSopenharmony_ci will be assigned a location by the linker. See section 3.9.2 "Shader 7575bd8deadSopenharmony_ci Execution" of the OpenGL ES Specification for more details. 7585bd8deadSopenharmony_ci 7595bd8deadSopenharmony_ci For the purposes of determining if a non-fragment output matches an 7605bd8deadSopenharmony_ci input from a subsequent shader stage, the location layout qualifier (if 7615bd8deadSopenharmony_ci any) must match. 7625bd8deadSopenharmony_ci 7635bd8deadSopenharmony_ci 7645bd8deadSopenharmony_ci (Add new subsection 4.4.2.fs): 7655bd8deadSopenharmony_ci 7665bd8deadSopenharmony_ci 4.4.2.fs Fragment Outputs 7675bd8deadSopenharmony_ci 7685bd8deadSopenharmony_ci Fragment shaders can have an output layout for redeclaring the built-in 7695bd8deadSopenharmony_ci variable gl_FragDepth: 7705bd8deadSopenharmony_ci 7715bd8deadSopenharmony_ci out float gl_FragDepth; // redeclaration that changes nothing is allowed 7725bd8deadSopenharmony_ci 7735bd8deadSopenharmony_ci The built-in gl_FragDepth is only predeclared in fragment shaders, so 7745bd8deadSopenharmony_ci redeclaring it in any other shader language results in a compile-time 7755bd8deadSopenharmony_ci error. 7765bd8deadSopenharmony_ci 7775bd8deadSopenharmony_ci 7785bd8deadSopenharmony_ci (Remove subsection 4.5.1 "Linking of Vertex Outputs and Fragment 7795bd8deadSopenharmony_ci Inputs". Note that the table from this section is moved to section 7805bd8deadSopenharmony_ci 4.3.4, while most of the interface matching language is now dealt with 7815bd8deadSopenharmony_ci in "Shader Interface Matching" in the OpenGL ES Specification as 7825bd8deadSopenharmony_ci modified by this extension.) 7835bd8deadSopenharmony_ci 7845bd8deadSopenharmony_ci 7855bd8deadSopenharmony_ci (Modify the first two paragraphs of section 7.1 "Vertex Shader Special 7865bd8deadSopenharmony_ci Variables", moving one paragraph up one level to the introduction of 7875bd8deadSopenharmony_ci chapter 7): 7885bd8deadSopenharmony_ci 7895bd8deadSopenharmony_ci 7 Built-in Variables 7905bd8deadSopenharmony_ci 7915bd8deadSopenharmony_ci Some OpenGL operations occur in fixed functionality and need to provide 7925bd8deadSopenharmony_ci values to or receive values from shader executables. Shaders communicate 7935bd8deadSopenharmony_ci with fixed-function OpenGL pipeline stages, and optionally with other 7945bd8deadSopenharmony_ci shader executables, through the use of built-in input and output 7955bd8deadSopenharmony_ci variables. 7965bd8deadSopenharmony_ci 7975bd8deadSopenharmony_ci 7.1 Vertex Shader Special Variables 7985bd8deadSopenharmony_ci 7995bd8deadSopenharmony_ci In the vertex language, the built-ins are intrinsically declared as 8005bd8deadSopenharmony_ci follows: 8015bd8deadSopenharmony_ci 8025bd8deadSopenharmony_ci in highp int gl_VertexID; 8035bd8deadSopenharmony_ci in highp int gl_InstanceID; 8045bd8deadSopenharmony_ci 8055bd8deadSopenharmony_ci out gl_PerVertex { 8065bd8deadSopenharmony_ci highp vec4 gl_Position; 8075bd8deadSopenharmony_ci highp float gl_PointSize; 8085bd8deadSopenharmony_ci }; 8095bd8deadSopenharmony_ci 8105bd8deadSopenharmony_ci The variable gl_Position is intended for writing the homogeneous vertex 8115bd8deadSopenharmony_ci position. It can be written at any time during shader execution. This 8125bd8deadSopenharmony_ci value will be used by the following shader stage, or if there are no 8135bd8deadSopenharmony_ci other shaders prior to the fragment shader, by primitive assembly, 8145bd8deadSopenharmony_ci clipping, culling, and other fixed functionality operations that operate 8155bd8deadSopenharmony_ci on primitives after vertex processing has occurred. Its value is 8165bd8deadSopenharmony_ci undefined after vertex processing if the vertex shader does not write 8175bd8deadSopenharmony_ci gl_Position. 8185bd8deadSopenharmony_ci 8195bd8deadSopenharmony_ci The variable gl_PointSize ... 8205bd8deadSopenharmony_ci 8215bd8deadSopenharmony_ci Add a new section 7.io following section 7.3 "Built-In Uniform State": 8225bd8deadSopenharmony_ci 8235bd8deadSopenharmony_ci 7.io Redeclaring Built-in Blocks 8245bd8deadSopenharmony_ci 8255bd8deadSopenharmony_ci The gl_PerVertex block can be redeclared in a shader to explicitly 8265bd8deadSopenharmony_ci indicate what subset of the members will be used. This is necessary to 8275bd8deadSopenharmony_ci establish the interface between multiple programs. If the gl_PerVertex 8285bd8deadSopenharmony_ci block is not redefined in a given program, the intrinsically declared 8295bd8deadSopenharmony_ci definition of that block is used for the program interface. 8305bd8deadSopenharmony_ci 8315bd8deadSopenharmony_ci For example: 8325bd8deadSopenharmony_ci 8335bd8deadSopenharmony_ci out gl_PerVertex { 8345bd8deadSopenharmony_ci highp vec4 gl_Position; // will use gl_Position 8355bd8deadSopenharmony_ci highp float gl_PointSize; // will use gl_PointSize 8365bd8deadSopenharmony_ci highp vec4 t; // error, only gl_PerVertex members allowed 8375bd8deadSopenharmony_ci }; // no other members of gl_PerVertex will be used 8385bd8deadSopenharmony_ci 8395bd8deadSopenharmony_ci This establishes the output interface the shader will use with the 8405bd8deadSopenharmony_ci subsequent pipeline stage. It must be a subset of the built-in members 8415bd8deadSopenharmony_ci of gl_PerVertex. Such a redeclaration can also add the invariant 8425bd8deadSopenharmony_ci qualifier and interpolation qualifiers. 8435bd8deadSopenharmony_ci 8445bd8deadSopenharmony_ci Other layout qualifiers, like location, cannot be added to such a 8455bd8deadSopenharmony_ci redeclaration, unless specifically stated. 8465bd8deadSopenharmony_ci 8475bd8deadSopenharmony_ci If a built-in interface block is redeclared, it must appear in the 8485bd8deadSopenharmony_ci shader before any use of any member included in the built-in 8495bd8deadSopenharmony_ci declaration, or a compile-time error will result. It is also a 8505bd8deadSopenharmony_ci compile-time error to redeclare the block more than once or to redeclare 8515bd8deadSopenharmony_ci a built-in block and then use a member from that built-in block that was 8525bd8deadSopenharmony_ci not included in the redeclaration. Also, if a built-in interface block 8535bd8deadSopenharmony_ci is redeclared, no member of the built-in declaration can be redeclared 8545bd8deadSopenharmony_ci outside the block redeclaration. If multiple shaders using members of a 8555bd8deadSopenharmony_ci built-in block belonging to the same interface are linked together in 8565bd8deadSopenharmony_ci the same program, they must all redeclare the built-in block in the same 8575bd8deadSopenharmony_ci way, as described in section 4.3.7 "Interface Blocks" for interface 8585bd8deadSopenharmony_ci block matching, or a link-time error will result. It will also be a 8595bd8deadSopenharmony_ci link-time error if some shaders in a program redeclare a specific 8605bd8deadSopenharmony_ci built-in interface block while another shader in that program does not 8615bd8deadSopenharmony_ci redeclare that interface block yet still uses a member of that interface 8625bd8deadSopenharmony_ci block. If a built-in block interface is formed across shaders in 8635bd8deadSopenharmony_ci different programs, the shaders must all redeclare the built-in block in 8645bd8deadSopenharmony_ci the same way (as described for a single program), or the values passed 8655bd8deadSopenharmony_ci along the interface are undefined. 8665bd8deadSopenharmony_ci 8675bd8deadSopenharmony_ciDependencies on OES_shader_multisample_interpolation 8685bd8deadSopenharmony_ci 8695bd8deadSopenharmony_ci If OES_shader_multisample_interpolation is not supported, references to 8705bd8deadSopenharmony_ci "sample in", "sample out" and the extension should be ignored. 8715bd8deadSopenharmony_ci 8725bd8deadSopenharmony_ciDependencies on OES_geometry_shader and EXT_geometry_shader 8735bd8deadSopenharmony_ci 8745bd8deadSopenharmony_ci If OES_geometry_shader or EXT_geometry_shader is enabled, this extension 8755bd8deadSopenharmony_ci is implicitly enabled for geometry shaders. 8765bd8deadSopenharmony_ci 8775bd8deadSopenharmony_ci If OES_geometry_shader or EXT_geometry_shader is not supported, ignore all 8785bd8deadSopenharmony_ci references to geometry shaders. 8795bd8deadSopenharmony_ci 8805bd8deadSopenharmony_ciDependencies on OES_tessellation_shader and EXT_tessellation_shader 8815bd8deadSopenharmony_ci 8825bd8deadSopenharmony_ci If OES_tessellation_shader or EXT_tessellation_shader is enabled, this 8835bd8deadSopenharmony_ci extension is implicitly enabled for tessellation control and evaluation 8845bd8deadSopenharmony_ci shaders. 8855bd8deadSopenharmony_ci 8865bd8deadSopenharmony_ci If OES_tessellation_shader or EXT_tessellation_shaders is not supported, 8875bd8deadSopenharmony_ci ignore all references to tessellation shaders. 8885bd8deadSopenharmony_ci 8895bd8deadSopenharmony_ciIssues 8905bd8deadSopenharmony_ci 8915bd8deadSopenharmony_ci (1) What functionality was removed from interface blocks relative to 8925bd8deadSopenharmony_ci GL 4.4? 8935bd8deadSopenharmony_ci 8945bd8deadSopenharmony_ci - Interactions with features not supported by the underlying 8955bd8deadSopenharmony_ci ES 3.1 API and Shading Language, including: 8965bd8deadSopenharmony_ci * gl_ClipDistance shader inputs and outputs. 8975bd8deadSopenharmony_ci * "component" layout 8985bd8deadSopenharmony_ci * location aliasing 8995bd8deadSopenharmony_ci * fragment shader output "index" layout 9005bd8deadSopenharmony_ci * fragment shader gl_FragDepth layout "depth*" qualifiers 9015bd8deadSopenharmony_ci * double-precision scalars and vectors 9025bd8deadSopenharmony_ci * matching across shader stages with different qualifiers (other 9035bd8deadSopenharmony_ci than precision and "in"/"out"). 9045bd8deadSopenharmony_ci * References allowing or assuming more than one shader object per 9055bd8deadSopenharmony_ci pipeline stage. 9065bd8deadSopenharmony_ci * gl_PerFragment is not added (only exists in compatibility profile). 9075bd8deadSopenharmony_ci 9085bd8deadSopenharmony_ci (2) What functionality was changed and added relative to interface blocks 9095bd8deadSopenharmony_ci in GL 4.4? 9105bd8deadSopenharmony_ci 9115bd8deadSopenharmony_ci - separable shaders are not required to redeclare the gl_PerVertex block. 9125bd8deadSopenharmony_ci - clarifications on types allowed for vertex and fragment shader inputs 9135bd8deadSopenharmony_ci from ES 3.0. 9145bd8deadSopenharmony_ci 9155bd8deadSopenharmony_ci (3) Are any grammar additions required in chapter 9? 9165bd8deadSopenharmony_ci 9175bd8deadSopenharmony_ci There may be something needed for supporting interface blocks on in/out 9185bd8deadSopenharmony_ci declarations, but I believe not, since the existing GLSL-ES 3.10 grammar 9195bd8deadSopenharmony_ci already has these as storage_qualifier tokens. 9205bd8deadSopenharmony_ci 9215bd8deadSopenharmony_ci (4) Shader Interface Matching rules have been updated to relax precision 9225bd8deadSopenharmony_ci matching on shader outputs and inputs, as previously required in ES 9235bd8deadSopenharmony_ci 3.0. This was changed during 3.1 development but is now proposed to 9245bd8deadSopenharmony_ci return to 3.0 behavior, matching this extension. 9255bd8deadSopenharmony_ci 9265bd8deadSopenharmony_ci RESOLVED. Per Bug 11189, when using a program that contains both sides 9275bd8deadSopenharmony_ci of an interface, the precision qualifier on inputs/outputs does not need 9285bd8deadSopenharmony_ci to match. However for two separable programs, the precision qualifiers 9295bd8deadSopenharmony_ci on inputs/outputs are required to match on the external interfaces. 9305bd8deadSopenharmony_ci Failing to do so results in a validation error. 9315bd8deadSopenharmony_ci 9325bd8deadSopenharmony_ci (5) In section 4.3.7 "Interface Matching", the corresponding part of 9335bd8deadSopenharmony_ci desktop GLSL 4.40 (pp. 49-50) has some material that's very 9345bd8deadSopenharmony_ci different than GLSL-ES language. Still need to review its 9355bd8deadSopenharmony_ci applicability here. 9365bd8deadSopenharmony_ci 9375bd8deadSopenharmony_ci UNRESOLVED. This should be addressed by rebasing on the ES 3.1 specs. 9385bd8deadSopenharmony_ci 9395bd8deadSopenharmony_ci (6) Should we allow re-declaring the gl_PerVertex block? 9405bd8deadSopenharmony_ci 9415bd8deadSopenharmony_ci DISCUSSION: If we do, we need to update Section 3.8 with language from 9425bd8deadSopenharmony_ci Section 3.7 in the GLSL 4.4 spec about redeclaring 'gl_' variables. 9435bd8deadSopenharmony_ci If we don't, applications will always pay the space for gl_PointSize, 9445bd8deadSopenharmony_ci and would never be able to have 'invariant' or different interpolation 9455bd8deadSopenharmony_ci or precision qualifiers on vertex, tessellation, or geometry shader 9465bd8deadSopenharmony_ci built-in outputs. This seems undesirable. 9475bd8deadSopenharmony_ci 9485bd8deadSopenharmony_ci RESOLVED: Yes. Section 3.8 updated. 9495bd8deadSopenharmony_ci 9505bd8deadSopenharmony_ci (7) What is the behavior of LinkProgram with respect to gl_PerVertex 9515bd8deadSopenharmony_ci blocks? 9525bd8deadSopenharmony_ci 9535bd8deadSopenharmony_ci DISCUSSION: 9545bd8deadSopenharmony_ci a) When using monolithic programs, gl_PerVertex does not need to be 9555bd8deadSopenharmony_ci redeclared in any shader stage. 9565bd8deadSopenharmony_ci 9575bd8deadSopenharmony_ci b) When using separable programs with only OpenGL ES 3.1-level 9585bd8deadSopenharmony_ci functionality (vertex and fragment only), gl_PerVertex does not need to 9595bd8deadSopenharmony_ci be redeclared. In fact, gl_PerVertex can't be redeclared, since no 9605bd8deadSopenharmony_ci language mechanism exists in unextended ES 3.1 to do so. Adding such a 9615bd8deadSopenharmony_ci requirement merely due to the presence of this extension would break 9625bd8deadSopenharmony_ci valid OpenGL ES 3.1-level applications. The lack of a redeclaration 9635bd8deadSopenharmony_ci requirement in OpenGL ES 3.1 is a difference relative to OpenGL 4.1, 9645bd8deadSopenharmony_ci but the reasons why we added this requirement in OpenGL 4.1 (many 9655bd8deadSopenharmony_ci shader stages, a larger set of built-ins, and the desire to be able to 9665bd8deadSopenharmony_ci treat gl_PerVertex members like other "regular" varyings) don't exist 9675bd8deadSopenharmony_ci in unextended ES 3.1. 9685bd8deadSopenharmony_ci 9695bd8deadSopenharmony_ci c) When using separable programs, any shader with the ability to redeclare 9705bd8deadSopenharmony_ci gl_PerVertex could require redeclaration when any of its members are 9715bd8deadSopenharmony_ci used. This would be mostly compatible with OpenGL 4.1, which requires 9725bd8deadSopenharmony_ci all stages to redeclare and provides the ability to do so in all 9735bd8deadSopenharmony_ci stages. However, since the intrinsically declared gl_PerVertex blocks 9745bd8deadSopenharmony_ci are actually fairly small in ES, redeclaring gl_PerVertex is optional 9755bd8deadSopenharmony_ci in ES. The basic rules here are: 9765bd8deadSopenharmony_ci 9775bd8deadSopenharmony_ci - gl_PerVertex exists iff OES_shader_io_blocks is enabled. 9785bd8deadSopenharmony_ci - OES_shader_io_blocks is always enabled if OES_geometry_shader 9795bd8deadSopenharmony_ci or OES_tesselation_shader is enabled. 9805bd8deadSopenharmony_ci - OES_shader_io_blocks can be optionally enabled for VS and FS. 9815bd8deadSopenharmony_ci 9825bd8deadSopenharmony_ci (8) What happens when you use the following together in a program 9835bd8deadSopenharmony_ci pipeline? 9845bd8deadSopenharmony_ci - a separable vertex-only program A which doesn't enable 9855bd8deadSopenharmony_ci OES_shader_io_blocks, and 9865bd8deadSopenharmony_ci - a separable program B containing a tessellation or geometry shader 9875bd8deadSopenharmony_ci 9885bd8deadSopenharmony_ci DISCUSSION: This was not an issue in OpenGL because separable shaders 9895bd8deadSopenharmony_ci were added (in GL 4.1) after geometry shaders and input blocks were 9905bd8deadSopenharmony_ci added (in GL 3.2), so any separable program with a vertex shader could 9915bd8deadSopenharmony_ci redeclare gl_PerVertex. There are basically 3 options: 9925bd8deadSopenharmony_ci 9935bd8deadSopenharmony_ci a) Driver has to make any combination of VS outputs in A and redeclared 9945bd8deadSopenharmony_ci input gl_PerVertex block in B work correctly. 9955bd8deadSopenharmony_ci b) Lack of redeclaring gl_PerVertex in A implies interface mismatch with 9965bd8deadSopenharmony_ci redeclared gl_PerVertex in B. Per the standard rules, if there is no 9975bd8deadSopenharmony_ci complete interface match, all inputs are undefined except for 9985bd8deadSopenharmony_ci individual variables that match by location, just as with user- 9995bd8deadSopenharmony_ci defined variables. Built-ins can't be assigned numeric locations, so 10005bd8deadSopenharmony_ci would be considered not to match. 10015bd8deadSopenharmony_ci c) It is an error. The vertex shader must be modified to support 10025bd8deadSopenharmony_ci being used in combination with geometry and tessellation shaders. 10035bd8deadSopenharmony_ci 10045bd8deadSopenharmony_ci RESOLVED: (a) There will only be one or at most two (if 10055bd8deadSopenharmony_ci OES_geometry_point_size is enabled) outputs from the vertex shader 10065bd8deadSopenharmony_ci that would need to be matched up with the gl_PerVertex block in the 10075bd8deadSopenharmony_ci next shader. It doesn't seem onerous to just make it work, and it is 10085bd8deadSopenharmony_ci desirable to be able to just drop a geometry shader into an otherwise 10095bd8deadSopenharmony_ci valid ES 3.1 application without modifying the vertex shader. 10105bd8deadSopenharmony_ci 10115bd8deadSopenharmony_ci (9) Why are there so many edits to section 4.4.1 and 4.4.2 and what 10125bd8deadSopenharmony_ci really changed? 10135bd8deadSopenharmony_ci 10145bd8deadSopenharmony_ci Some of this is due to restructuring to create subsections specific to 10155bd8deadSopenharmony_ci different shader stages, some appears to be correct (but potentially 10165bd8deadSopenharmony_ci redundant) language from GLSL 4.40, and some is useful block-related 10175bd8deadSopenharmony_ci language. 10185bd8deadSopenharmony_ci 10195bd8deadSopenharmony_ci (10) One of the new matching requirements for ES 3.1 is that 10205bd8deadSopenharmony_ci interpolation qualifies don't need to match. Is that true for block 10215bd8deadSopenharmony_ci members as well, or just loose variables? 10225bd8deadSopenharmony_ci 10235bd8deadSopenharmony_ci RESOLVED. This is true for block members as well. 10245bd8deadSopenharmony_ci In general, we'll allow the same rules for matching variables and 10255bd8deadSopenharmony_ci block members. Then a block matches iff the block members match. 10265bd8deadSopenharmony_ci 10275bd8deadSopenharmony_ci[?? still need to apply/verify edits for this]. 10285bd8deadSopenharmony_ci 10295bd8deadSopenharmony_ciRevision History 10305bd8deadSopenharmony_ci 10315bd8deadSopenharmony_ci Rev. Date Author Changes 10325bd8deadSopenharmony_ci ---- -------- --------- ------------------------------------------------- 10335bd8deadSopenharmony_ci 10345bd8deadSopenharmony_ci 2 08/10/2014 olson Removed contradictory language forbidding 10355bd8deadSopenharmony_ci location layout qualifiers on output blocks 10365bd8deadSopenharmony_ci or output block members (Bug 12831) 10375bd8deadSopenharmony_ci 1 06/18/2014 dkoch Initial OES version based on EXT. 10385bd8deadSopenharmony_ci No functional changes. 1039