15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci EXT_shader_implicit_conversions 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_EXT_shader_implicit_conversions 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 Slawomir Grajewski, Intel 175bd8deadSopenharmony_ci Contributors to ARB_gpu_shader5 185bd8deadSopenharmony_ci 195bd8deadSopenharmony_ciNotice 205bd8deadSopenharmony_ci 215bd8deadSopenharmony_ci Copyright (c) 2010-2013 The Khronos Group Inc. Copyright terms at 225bd8deadSopenharmony_ci http://www.khronos.org/registry/speccopyright.html 235bd8deadSopenharmony_ci 245bd8deadSopenharmony_ci Portions Copyright (c) 2013-2014 NVIDIA Corporation. 255bd8deadSopenharmony_ci 265bd8deadSopenharmony_ciStatus 275bd8deadSopenharmony_ci 285bd8deadSopenharmony_ci Complete. 295bd8deadSopenharmony_ci 305bd8deadSopenharmony_ciVersion 315bd8deadSopenharmony_ci 325bd8deadSopenharmony_ci Last Modified Date: April 1, 2014 335bd8deadSopenharmony_ci Revision: 6 345bd8deadSopenharmony_ci 355bd8deadSopenharmony_ciNumber 365bd8deadSopenharmony_ci 375bd8deadSopenharmony_ci OpenGL ES Extension #179 385bd8deadSopenharmony_ci 395bd8deadSopenharmony_ciDependencies 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ci OpenGL ES 3.1 and OpenGL ES Shading Language 3.10 are required. 425bd8deadSopenharmony_ci 435bd8deadSopenharmony_ci This specification is written against the OpenGL ES 3.10 Shading 445bd8deadSopenharmony_ci Language (March 17, 2014) Specification. 455bd8deadSopenharmony_ci 465bd8deadSopenharmony_ciOverview 475bd8deadSopenharmony_ci 485bd8deadSopenharmony_ci This extension provides support for implicitly converting signed integer 495bd8deadSopenharmony_ci types to unsigned types, as well as more general implicit conversion and 505bd8deadSopenharmony_ci function overloading infrastructure to support new data types introduced by 515bd8deadSopenharmony_ci other extensions. 525bd8deadSopenharmony_ci 535bd8deadSopenharmony_ciModifications to The OpenGL ES Shading Language Specification, Version 3.10 545bd8deadSopenharmony_ci 555bd8deadSopenharmony_ci Including the following line in a shader can be used to control the 565bd8deadSopenharmony_ci language features described in this extension: 575bd8deadSopenharmony_ci 585bd8deadSopenharmony_ci #extension GL_EXT_shader_implicit_conversions : <behavior> 595bd8deadSopenharmony_ci 605bd8deadSopenharmony_ci where <behavior> is as specified in section 3.4. 615bd8deadSopenharmony_ci 625bd8deadSopenharmony_ci A new preprocessor #define is added to the OpenGL ES Shading Language: 635bd8deadSopenharmony_ci 645bd8deadSopenharmony_ci #define GL_EXT_shader_implicit_conversions 1 655bd8deadSopenharmony_ci 665bd8deadSopenharmony_ci 675bd8deadSopenharmony_ci Add new section 4.1.10 following section 4.1.9 "Arrays": 685bd8deadSopenharmony_ci 695bd8deadSopenharmony_ci 4.1.10 Implicit Conversions 705bd8deadSopenharmony_ci 715bd8deadSopenharmony_ci In some situations, an expression and its type will be implicitly 725bd8deadSopenharmony_ci converted to a different type. The following table shows all allowed 735bd8deadSopenharmony_ci implicit conversions: 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ci Can be implicitly 765bd8deadSopenharmony_ci Type of expression converted to 775bd8deadSopenharmony_ci --------------------- ----------------- 785bd8deadSopenharmony_ci int uint, float 795bd8deadSopenharmony_ci ivec2 uvec2, vec2 805bd8deadSopenharmony_ci ivec3 uvec3, vec3 815bd8deadSopenharmony_ci ivec4 uvec4, vec4 825bd8deadSopenharmony_ci uint float 835bd8deadSopenharmony_ci uvec2 vec2 845bd8deadSopenharmony_ci uvec3 vec3 855bd8deadSopenharmony_ci uvec4 vec4 865bd8deadSopenharmony_ci 875bd8deadSopenharmony_ci No implicit conversions are provided to convert from unsigned to signed 885bd8deadSopenharmony_ci integer types or from floating-point to integer types. There are no 895bd8deadSopenharmony_ci implicit array or structure conversions. 905bd8deadSopenharmony_ci 915bd8deadSopenharmony_ci When an implicit conversion is done, it is not a re-interpretation of 925bd8deadSopenharmony_ci the expression's bit pattern, but a conversion of its value to an 935bd8deadSopenharmony_ci equivalent value in the new type. For example, the integer value -5 will 945bd8deadSopenharmony_ci be converted to the floating-point value -5.0. Integer values having 955bd8deadSopenharmony_ci more bits of precision than a single-precision floating-point mantissa 965bd8deadSopenharmony_ci will lose precision when converted to float. 975bd8deadSopenharmony_ci 985bd8deadSopenharmony_ci When performing implicit conversion for binary operators, there may be 995bd8deadSopenharmony_ci multiple data types to which the two operands can be converted. For 1005bd8deadSopenharmony_ci example, when adding an int value to a uint value, both values can be 1015bd8deadSopenharmony_ci implicitly converted to uint and float. In such cases, a floating-point 1025bd8deadSopenharmony_ci type is chosen if either operand has a floating-point type. Otherwise, 1035bd8deadSopenharmony_ci an unsigned integer type is chosen if either operand has an unsigned 1045bd8deadSopenharmony_ci integer type. Otherwise, a signed integer type is chosen. If operands 1055bd8deadSopenharmony_ci can be implicitly converted to multiple data types deriving from the 1065bd8deadSopenharmony_ci same base data type, the type with the smallest component size is used. 1075bd8deadSopenharmony_ci The conversions in the table above are done only as indicated by other 1085bd8deadSopenharmony_ci sections of this specification. 1095bd8deadSopenharmony_ci 1105bd8deadSopenharmony_ci 1115bd8deadSopenharmony_ci Modify Section 5.9 "Expressions", p. 81: 1125bd8deadSopenharmony_ci 1135bd8deadSopenharmony_ci (modify the specified items in the bulleted list as follows, adding 1145bd8deadSopenharmony_ci support for implicit conversion between signed and unsigned types) 1155bd8deadSopenharmony_ci 1165bd8deadSopenharmony_ci Expressions in the shading language are built from the following: 1175bd8deadSopenharmony_ci 1185bd8deadSopenharmony_ci * The arithmetic binary operators add (+), subtract (-), multiply (*), 1195bd8deadSopenharmony_ci and divide (/) operate on integer and floating-point scalars, vectors, 1205bd8deadSopenharmony_ci and matrices. If the fundamental types in the operands do not match, 1215bd8deadSopenharmony_ci then the conversions from section 4.1.10 "Implicit Conversions" are 1225bd8deadSopenharmony_ci applied to create matching types. All arithmetic binary operators ... 1235bd8deadSopenharmony_ci 1245bd8deadSopenharmony_ci * The operator modulus (%) operates on signed or unsigned integer 1255bd8deadSopenharmony_ci scalars or integer vectors. If the fundamental types of the operands 1265bd8deadSopenharmony_ci do not match, the conversions from Section &4.1.10 "Implicit 1275bd8deadSopenharmony_ci Conversions" are applied to produce matching types. The operands 1285bd8deadSopenharmony_ci cannot be vectors of differing size ... 1295bd8deadSopenharmony_ci 1305bd8deadSopenharmony_ci * The relational operators greater than (>), less than (<), greater than 1315bd8deadSopenharmony_ci or equal (>=), and less than or equal (<=) operate only on scalar 1325bd8deadSopenharmony_ci integer and scalar floating-point expressions. The result is scalar 1335bd8deadSopenharmony_ci Boolean. Either the operands' types must match, or the conversions 1345bd8deadSopenharmony_ci from section 4.1.10 "Implicit Conversions" will be applied to obtain 1355bd8deadSopenharmony_ci matching types. To do component-wise relational comparisons ... 1365bd8deadSopenharmony_ci 1375bd8deadSopenharmony_ci * The equality operators equal (==), and not equal (!=) operate on all 1385bd8deadSopenharmony_ci types. They result in a scalar Boolean. If the operand types do not 1395bd8deadSopenharmony_ci match, then there must be a conversion from section 4.1.10 "Implicit 1405bd8deadSopenharmony_ci Conversions" applied to one operand that can make them match, in which 1415bd8deadSopenharmony_ci case this conversion is done. For vectors, matrices, structures, ... 1425bd8deadSopenharmony_ci 1435bd8deadSopenharmony_ci * The ternary selection operator (?:). It operates on three expressions 1445bd8deadSopenharmony_ci (exp1 ? exp2 : exp3). This operator evaluates the first expression, 1455bd8deadSopenharmony_ci which must result in a scalar Boolean. If the result is true, it 1465bd8deadSopenharmony_ci selects to evaluate the second expression, otherwise it selects to 1475bd8deadSopenharmony_ci evaluate the third expression. Only one of the second and third 1485bd8deadSopenharmony_ci expressions is evaluated. The second and third expressions can be any 1495bd8deadSopenharmony_ci type, as long their types match, or there is a conversion in section 1505bd8deadSopenharmony_ci 4.1.10 "Implicit Conversions" that can be applied to one of the 1515bd8deadSopenharmony_ci expressions to make their types match. This resulting matching type is 1525bd8deadSopenharmony_ci the type of the entire expression. 1535bd8deadSopenharmony_ci 1545bd8deadSopenharmony_ci 1555bd8deadSopenharmony_ci Modify Section 6.1, Function Definitions, p. 88 1565bd8deadSopenharmony_ci 1575bd8deadSopenharmony_ci (modify description of overloading) 1585bd8deadSopenharmony_ci 1595bd8deadSopenharmony_ci Function names can be overloaded. The same function name can be used for 1605bd8deadSopenharmony_ci multiple functions, as long as the parameter types differ. If a function 1615bd8deadSopenharmony_ci name is declared twice with the same parameter types, then the return 1625bd8deadSopenharmony_ci types and all qualifiers must also match, and it is the same function 1635bd8deadSopenharmony_ci being declared. For example, 1645bd8deadSopenharmony_ci 1655bd8deadSopenharmony_ci vec4 f(in vec4 x, out vec4 y); // (A) 1665bd8deadSopenharmony_ci vec4 f(in vec4 x, out uvec4 y); // (B) okay, different argument type 1675bd8deadSopenharmony_ci vec4 f(in ivec4 x, out uvec4 y); // (C) okay, different argument type 1685bd8deadSopenharmony_ci 1695bd8deadSopenharmony_ci int f(in vec4 x, out ivec4 y); // error, only return type differs 1705bd8deadSopenharmony_ci vec4 f(in vec4 x, in vec4 y); // error, only qualifier differs 1715bd8deadSopenharmony_ci vec4 f(const in vec4 x, out vec4 y); // error, only qualifier differs 1725bd8deadSopenharmony_ci 1735bd8deadSopenharmony_ci When function calls are resolved, an exact type match for all the 1745bd8deadSopenharmony_ci arguments is sought. If an exact match is found, all other functions are 1755bd8deadSopenharmony_ci ignored, and the exact match is used. If no exact match is found, then 1765bd8deadSopenharmony_ci the implicit conversions in section 4.1.10 (Implicit Conversions) will 1775bd8deadSopenharmony_ci be applied to find a match. Mismatched types on input parameters ("in" 1785bd8deadSopenharmony_ci or default) must have a conversion from the calling argument type to the 1795bd8deadSopenharmony_ci formal parameter type. Mismatched types on output parameters ("out") 1805bd8deadSopenharmony_ci must have a conversion from the formal parameter type to the calling 1815bd8deadSopenharmony_ci argument type. 1825bd8deadSopenharmony_ci 1835bd8deadSopenharmony_ci If implicit conversions can be used to find more than one matching 1845bd8deadSopenharmony_ci function, a single best-matching function is sought. To determine a best 1855bd8deadSopenharmony_ci match, the conversions between calling argument and formal parameter 1865bd8deadSopenharmony_ci types are compared for each function argument and pair of matching 1875bd8deadSopenharmony_ci functions. After these comparisons are performed, each pair of matching 1885bd8deadSopenharmony_ci functions are compared. A function definition A is considered a better 1895bd8deadSopenharmony_ci match than function definition B if: 1905bd8deadSopenharmony_ci 1915bd8deadSopenharmony_ci * for at least one function argument, the conversion for that argument 1925bd8deadSopenharmony_ci in A is better than the corresponding conversion in B; and 1935bd8deadSopenharmony_ci 1945bd8deadSopenharmony_ci * there is no function argument for which the conversion in B is 1955bd8deadSopenharmony_ci better than the corresponding conversion in A. 1965bd8deadSopenharmony_ci 1975bd8deadSopenharmony_ci If a single function definition is considered a better match than every 1985bd8deadSopenharmony_ci other matching function definition, it will be used. Otherwise, a 1995bd8deadSopenharmony_ci compile-time semantic error for an ambiguous overloaded function call 2005bd8deadSopenharmony_ci occurs. 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci To determine whether the conversion for a single argument in one match 2035bd8deadSopenharmony_ci is better than that for another match, the rule that an exact match is 2045bd8deadSopenharmony_ci better than a match involving any implicit conversion is used. 2055bd8deadSopenharmony_ci 2065bd8deadSopenharmony_ci If this rule does not apply to a particular pair of conversions, 2075bd8deadSopenharmony_ci neither conversion is considered better than the other. 2085bd8deadSopenharmony_ci 2095bd8deadSopenharmony_ci For the function prototypes (A), (B), and (C) above, the following 2105bd8deadSopenharmony_ci examples show how the rules apply to different sets of calling argument 2115bd8deadSopenharmony_ci types: 2125bd8deadSopenharmony_ci 2135bd8deadSopenharmony_ci f(vec4, vec4); // exact match of vec4 f(in vec4 x, out vec4 y) 2145bd8deadSopenharmony_ci f(vec4, uvec4); // exact match of vec4 f(in vec4 x, out ivec4 y) 2155bd8deadSopenharmony_ci f(ivec4, vec4); // NOT matched. All three match by implicit 2165bd8deadSopenharmony_ci // conversion. (C) is better than (A) and (B) 2175bd8deadSopenharmony_ci // on the first argument. (A) is better than 2185bd8deadSopenharmony_ci // (B) and (C). 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ci User-defined functions can have multiple ... 2215bd8deadSopenharmony_ci 2225bd8deadSopenharmony_ci 2235bd8deadSopenharmony_ciNew Implementation Dependent State 2245bd8deadSopenharmony_ci 2255bd8deadSopenharmony_ci None. 2265bd8deadSopenharmony_ci 2275bd8deadSopenharmony_ciIssues 2285bd8deadSopenharmony_ci 2295bd8deadSopenharmony_ci Note: These issues apply specifically to the definition of the 2305bd8deadSopenharmony_ci EXT_shader_implicit_conversions specification, which is based on the 2315bd8deadSopenharmony_ci OpenGL extension ARB_gpu_shader5 as updated in OpenGL 4.x. Resolved issues 2325bd8deadSopenharmony_ci from ARB_gpu_shader5 have been removed, but some remain applicable to this 2335bd8deadSopenharmony_ci extension. ARB_gpu_shader5 can be found in the OpenGL Registry. 2345bd8deadSopenharmony_ci 2355bd8deadSopenharmony_ci (1) What functionality was removed relative to ARB_gpu_shader5? 2365bd8deadSopenharmony_ci 2375bd8deadSopenharmony_ci - everything unrelated to implicit conversions and function overloading. 2385bd8deadSopenharmony_ci - Interactions with features not supported by the underlying 2395bd8deadSopenharmony_ci ES 3.1 API and Shading Language, including: 2405bd8deadSopenharmony_ci * interactions with ARB_gpu_shader_fp64 and NV_gpu_shader, including 2415bd8deadSopenharmony_ci support for double-precision in implicit conversions and function 2425bd8deadSopenharmony_ci overload resolution 2435bd8deadSopenharmony_ci * shading language function overloading rules involving the type 2445bd8deadSopenharmony_ci double 2455bd8deadSopenharmony_ci 2465bd8deadSopenharmony_ci (2) What functionality was changed and added relative to 2475bd8deadSopenharmony_ci ARB_gpu_shader5? 2485bd8deadSopenharmony_ci 2495bd8deadSopenharmony_ci None. 2505bd8deadSopenharmony_ci 2515bd8deadSopenharmony_ci (3) Are the function overloading rules and examples correct? 2525bd8deadSopenharmony_ci 2535bd8deadSopenharmony_ci RESOLVED. Rules 2 and 3 as given in the GLSL 4.40 specification do not 2545bd8deadSopenharmony_ci apply to ESSL, because there are no double types. There is a bug in the 2555bd8deadSopenharmony_ci example 2565bd8deadSopenharmony_ci 2575bd8deadSopenharmony_ci f(vec4, ivec4); // matched to vec4 f(in vec4 x, out vec4 y) 2585bd8deadSopenharmony_ci // (A) better than (B) for 2nd argument 2595bd8deadSopenharmony_ci // argument (rule 2), same on first argument. 2605bd8deadSopenharmony_ci 2615bd8deadSopenharmony_ci both because this example is incorrect WRT the overloading rules 2625bd8deadSopenharmony_ci starting with GLSL 4.00.4, and because the overloading rules in ESSL are 2635bd8deadSopenharmony_ci simpler. This example has been removed (see bug 11178). 2645bd8deadSopenharmony_ci 2655bd8deadSopenharmony_ciRevision History 2665bd8deadSopenharmony_ci 2675bd8deadSopenharmony_ci Revision 1, 2013/11/20 (Daniel Koch) 2685bd8deadSopenharmony_ci - Initial version extracted from EXT_gpu_shader5 rev 2. 2695bd8deadSopenharmony_ci 2705bd8deadSopenharmony_ci Revision 2, 2013/11/21 (Jon Leech) 2715bd8deadSopenharmony_ci - Resolve function overloading issue 7, per bug 11178. 2725bd8deadSopenharmony_ci 2735bd8deadSopenharmony_ci Revision 3, 2013/12/18 (Daniel Koch) 2745bd8deadSopenharmony_ci - minor cleanup 2755bd8deadSopenharmony_ci 2765bd8deadSopenharmony_ci Revision 4, 2014/03/10 (Jon Leech) 2775bd8deadSopenharmony_ci - Rebase on OpenGL ES 3.1 and change suffix to EXT. 2785bd8deadSopenharmony_ci 2795bd8deadSopenharmony_ci Revision 5, 2014/03/26 (Jon Leech) 2805bd8deadSopenharmony_ci - Sync with released ES 3.1 specs. 2815bd8deadSopenharmony_ci 2825bd8deadSopenharmony_ci Revision 6, 2014/04/01 (Daniel Koch) 2835bd8deadSopenharmony_ci - update contributors 284