15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    ARB_shading_language_packing
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_ARB_shading_language_packing
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Pat Brown, NVIDIA Corporation (pbrown 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Barthold Lichtenbelt, NVIDIA
165bd8deadSopenharmony_ci    Chris Dodd, NVIDIA
175bd8deadSopenharmony_ci    Daniel Koch, Transgaming
185bd8deadSopenharmony_ci    Eric Werness, NVIDIA
195bd8deadSopenharmony_ci    Greg Roth, NVIDIA
205bd8deadSopenharmony_ci    Jeff Bolz, NVIDIA
215bd8deadSopenharmony_ci    Piers Daniell, NVIDIA
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ciNotice
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ci    Copyright (c) 2011-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 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_ciStatus
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    Complete. Approved by the ARB on 2011/06/20.
415bd8deadSopenharmony_ci    Approved by the Khronos Promoters on 2011/07/29.
425bd8deadSopenharmony_ci
435bd8deadSopenharmony_ciVersion
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ci    Last Modified Date:         06/13/2011
465bd8deadSopenharmony_ci    Revision:                   5
475bd8deadSopenharmony_ci
485bd8deadSopenharmony_ciNumber
495bd8deadSopenharmony_ci
505bd8deadSopenharmony_ci    ARB Extension #116
515bd8deadSopenharmony_ci
525bd8deadSopenharmony_ciDependencies
535bd8deadSopenharmony_ci
545bd8deadSopenharmony_ci    This extension is written against version 4.1 (revision 09) of the OpenGL
555bd8deadSopenharmony_ci    Shading Language Specification.
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ciOverview
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ci    This extension provides the GLSL built-in functions to convert a 32-bit
605bd8deadSopenharmony_ci    unsigned integer holding a pair of 16-bit floating-point values to or from
615bd8deadSopenharmony_ci    a two-component floating-point vector (vec2).  
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ci    This mechanism allows GLSL shaders to read and write 16-bit floating-point
645bd8deadSopenharmony_ci    encodings (via 32-bit unsigned integers) without introducing a full set of
655bd8deadSopenharmony_ci    16-bit floating-point data types.
665bd8deadSopenharmony_ci
675bd8deadSopenharmony_ci    This extension also adds the GLSL built-in packing functions included in
685bd8deadSopenharmony_ci    GLSL version 4.00 and the ARB_gpu_shader5 extension which pack and unpack
695bd8deadSopenharmony_ci    vectors of small fixed-point data types into a larger scalar. By putting
705bd8deadSopenharmony_ci    these packing functions in this separate extension it allows
715bd8deadSopenharmony_ci    implementations to provide these functions in hardware that supports them
725bd8deadSopenharmony_ci    independent of the other ARB_gpu_shader5 features.
735bd8deadSopenharmony_ci    
745bd8deadSopenharmony_ci    In addition to the packing functions from ARB_gpu_shader5 this extension
755bd8deadSopenharmony_ci    also adds the missing [un]packSnorm2x16 for completeness.
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ciNew Procedures and Functions
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ci    None.
805bd8deadSopenharmony_ci
815bd8deadSopenharmony_ciNew Tokens
825bd8deadSopenharmony_ci
835bd8deadSopenharmony_ci    None.     
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ciModifications to the OpenGL API Specification
865bd8deadSopenharmony_ci
875bd8deadSopenharmony_ci    None.
885bd8deadSopenharmony_ci
895bd8deadSopenharmony_ciModifications to The OpenGL Shading Language Specification, Version 4.10
905bd8deadSopenharmony_ci(Revision 6)
915bd8deadSopenharmony_ci
925bd8deadSopenharmony_ci    Including the following line in a shader can be used to control the
935bd8deadSopenharmony_ci    language features described in this extension:
945bd8deadSopenharmony_ci
955bd8deadSopenharmony_ci      #extension GL_ARB_shading_language_packing : <behavior>
965bd8deadSopenharmony_ci
975bd8deadSopenharmony_ci    where <behavior> is as specified in section 3.3.
985bd8deadSopenharmony_ci
995bd8deadSopenharmony_ci    New preprocessor #defines are added to the OpenGL Shading Language:
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci      #define GL_ARB_shading_language_packing    1
1025bd8deadSopenharmony_ci
1035bd8deadSopenharmony_ci    Modify Section 8.4, Floating-Point Pack and Unpack Functions
1045bd8deadSopenharmony_ci    
1055bd8deadSopenharmony_ci    (add support for general packing functions)
1065bd8deadSopenharmony_ci
1075bd8deadSopenharmony_ci    Syntax:
1085bd8deadSopenharmony_ci
1095bd8deadSopenharmony_ci      uint      packUnorm2x16(vec2 v);
1105bd8deadSopenharmony_ci      uint      packSnorm2x16(vec2 v);
1115bd8deadSopenharmony_ci      uint      packUnorm4x8(vec4 v);
1125bd8deadSopenharmony_ci      uint      packSnorm4x8(vec4 v);
1135bd8deadSopenharmony_ci
1145bd8deadSopenharmony_ci      vec2      unpackUnorm2x16(uint v);
1155bd8deadSopenharmony_ci      vec2      unpackSnorm2x16(uint v);
1165bd8deadSopenharmony_ci      vec4      unpackUnorm4x8(uint v);
1175bd8deadSopenharmony_ci      vec4      unpackSnorm4x8(uint v);
1185bd8deadSopenharmony_ci
1195bd8deadSopenharmony_ci    The functions packUnorm2x16(), packSnorm2x16(), packUnorm4x8(), and
1205bd8deadSopenharmony_ci    packSnorm4x8() first convert each component of a two- or four-component
1215bd8deadSopenharmony_ci    vector of normalized floating-point values into 8- or 16-bit integer
1225bd8deadSopenharmony_ci    values.  Then, the results are packed into a 32-bit unsigned integer.
1235bd8deadSopenharmony_ci    The first component of the vector will be written to the least
1245bd8deadSopenharmony_ci    significant bits of the output; the last component will be written to
1255bd8deadSopenharmony_ci    the most significant bits.
1265bd8deadSopenharmony_ci
1275bd8deadSopenharmony_ci    The functions unpackUnorm2x16(), unpackSnorm2x16(), unpackUnorm4x8(),
1285bd8deadSopenharmony_ci    and unpackSnorm4x8() first unpacks a single 32-bit unsigned integer into
1295bd8deadSopenharmony_ci    a pair of 16-bit unsigned integers, a pair of 16-bit signed integers,
1305bd8deadSopenharmony_ci    four 8-bit unsigned integers, or four 8-bit signed integers.  Then, each
1315bd8deadSopenharmony_ci    component is converted to a normalized floating-point value to generate a
1325bd8deadSopenharmony_ci    two- or four-component vector.  The first component of the vector will be
1335bd8deadSopenharmony_ci    extracted from the least significant bits of the input; the last
1345bd8deadSopenharmony_ci    component will be extracted from the most significant bits.
1355bd8deadSopenharmony_ci
1365bd8deadSopenharmony_ci    The conversion between fixed- and normalized floating-point values will be
1375bd8deadSopenharmony_ci    performed as below.
1385bd8deadSopenharmony_ci
1395bd8deadSopenharmony_ci      function          conversion
1405bd8deadSopenharmony_ci      ---------------   -----------------------------------------------------
1415bd8deadSopenharmony_ci      packUnorm2x16     fixed_val = round(clamp(float_val, 0, +1) * 65535.0);
1425bd8deadSopenharmony_ci      packSnorm2x16     fixed_val = round(clamp(float_val, -1, +1) * 32767.0);
1435bd8deadSopenharmony_ci      packUnorm4x8      fixed_val = round(clamp(float_val, 0, +1) * 255.0);
1445bd8deadSopenharmony_ci      packSnorm4x8      fixed_val = round(clamp(float_val, -1, +1) * 127.0);
1455bd8deadSopenharmony_ci      unpackUnorm2x16   float_val = fixed_val / 65535.0;
1465bd8deadSopenharmony_ci      unpackSnorm2x16   float_val = clamp(fixed_val / 32767.0, -1, +1);
1475bd8deadSopenharmony_ci      unpackUnorm4x8    float_val = fixed_val / 255.0;
1485bd8deadSopenharmony_ci      unpackSnorm4x8    float_val = clamp(fixed_val / 127.0, -1, +1);
1495bd8deadSopenharmony_ci
1505bd8deadSopenharmony_ci    (add support for 16-bit floating-point packing and unpacking functions)
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ci    Syntax:
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci      uint      packHalf2x16(vec2 v);
1555bd8deadSopenharmony_ci      vec2      unpackHalf2x16(uint v);
1565bd8deadSopenharmony_ci
1575bd8deadSopenharmony_ci    The function packHalf2x16() returns an unsigned integer obtained by
1585bd8deadSopenharmony_ci    converting the components of a two-component floating-point vector to the
1595bd8deadSopenharmony_ci    16-bit floating-point representation found in the OpenGL Specification,
1605bd8deadSopenharmony_ci    and then packing these two 16-bit integers into a 32-bit unsigned integer.
1615bd8deadSopenharmony_ci    The first vector component specifies the 16 least-significant bits of the
1625bd8deadSopenharmony_ci    result; the second component specifies the 16 most-significant bits.
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ci    The function unpackHalf2x16() returns a two-component floating-point
1655bd8deadSopenharmony_ci    vector with components obtained by unpacking a 32-bit unsigned integer into a
1665bd8deadSopenharmony_ci    pair of 16-bit values, interpreting those values as 16-bit floating-point
1675bd8deadSopenharmony_ci    numbers according to the OpenGL Specification, and converting them to
1685bd8deadSopenharmony_ci    32-bit floating-point values.  The first component of the vector is
1695bd8deadSopenharmony_ci    obtained from the 16 least-significant bits of v; the second
1705bd8deadSopenharmony_ci    component is obtained from the 16 most-significant bits of v.
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ciGLX Protocol
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ci    None.
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ciErrors
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci    None.
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ciNew State
1815bd8deadSopenharmony_ci
1825bd8deadSopenharmony_ci    None.
1835bd8deadSopenharmony_ci
1845bd8deadSopenharmony_ciNew Implementation Dependent State
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ci    None.
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ciIssues
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    (1) What should this extension be called?
1915bd8deadSopenharmony_ci
1925bd8deadSopenharmony_ci      RESOLVED:  Proposed name is "ARB_shading_language_pack2h" (i.e., pack
1935bd8deadSopenharmony_ci      two half components).
1945bd8deadSopenharmony_ci
1955bd8deadSopenharmony_ci    (2) This functionality is also provided in the NV_gpu_shader5 extension.
1965bd8deadSopenharmony_ci    Why provide a separate extension?
1975bd8deadSopenharmony_ci
1985bd8deadSopenharmony_ci      RESOLVED:  This extension provides an additional pack/unpack function on
1995bd8deadSopenharmony_ci      top of those added in GLSL 4.00 without requiring that implementors
2005bd8deadSopenharmony_ci      provide the entirety of NV_gpu_shader5.
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci    (3) Should we provide a different set of function names to disambiguate
2035bd8deadSopenharmony_ci    from the similar NV_gpu_shader5 versions (which use the "f16vec2" type to
2045bd8deadSopenharmony_ci    represent a pair of fp16 values)?  If not, what happens if both this
2055bd8deadSopenharmony_ci    extension and NV_gpu_shader5 are enabled?
2065bd8deadSopenharmony_ci
2075bd8deadSopenharmony_ci      RESOLVED:  The functions in this extension will be called "packHalf2x16"
2085bd8deadSopenharmony_ci      and "unpackHalf2x16", which matches the convention of the other
2095bd8deadSopenharmony_ci      pack/unpack functions in GLSL 4.10 closely enough.  For example,
2105bd8deadSopenharmony_ci      packUnorm2x16() packs a pair of 16-bit unsigned normalized integers into
2115bd8deadSopenharmony_ci      a 32-bit unsigned integer.
2125bd8deadSopenharmony_ci
2135bd8deadSopenharmony_ci      Had we used the same names as in NV_gpu_shader5, there would be a
2145bd8deadSopenharmony_ci      conflict in the definitions -- the unpacked type here is "vec2", while
2155bd8deadSopenharmony_ci      the unpacked type in NV_gpu_shader5 is "f16vec2" (a two-component vector
2165bd8deadSopenharmony_ci      with explicit 16-bit floating-point types).  This conflict poses a
2175bd8deadSopenharmony_ci      problem if both extensions are enabled, and would also arise if future
2185bd8deadSopenharmony_ci      GLSL versions chose to add explicit fp16 types.  For the pack functions,
2195bd8deadSopenharmony_ci      an implementation supporting both versions could resolve via function
2205bd8deadSopenharmony_ci      overloading:
2215bd8deadSopenharmony_ci
2225bd8deadSopenharmony_ci        uint      packFloat2x16(vec2 v);
2235bd8deadSopenharmony_ci        uint      packFloat2x16(f16vec2 v);
2245bd8deadSopenharmony_ci
2255bd8deadSopenharmony_ci      Unfortunately, function overloading is not possible for the return type
2265bd8deadSopenharmony_ci      of the pack function.  One could resolve this by providing only:
2275bd8deadSopenharmony_ci
2285bd8deadSopenharmony_ci        f16vec2   unpackFloat2x16(uint v);
2295bd8deadSopenharmony_ci
2305bd8deadSopenharmony_ci      If a shader included code like:
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ci        vec2 unpacked = unpackFloat2x16(uint_value);
2335bd8deadSopenharmony_ci
2345bd8deadSopenharmony_ci      the unpacked value would be returned as f16vec2 data.  However, that
2355bd8deadSopenharmony_ci      could be implicitly converted to vec2 if implicit conversions from fp16
2365bd8deadSopenharmony_ci      to fp32 were supported.  Such behavior would be consistent with what we
2375bd8deadSopenharmony_ci      did for ARB_gpu_shader_fp64, where fp32 values can be implicitly
2385bd8deadSopenharmony_ci      converted to fp64.
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci    (4) The packing functions introduced in ARB_gpu_shader5 may be available
2415bd8deadSopenharmony_ci    on hardware that doesn't support the other features from ARB_gpu_shader5.
2425bd8deadSopenharmony_ci    How can an implementation expose those packing functions?
2435bd8deadSopenharmony_ci    
2445bd8deadSopenharmony_ci      RESOLVED: Added all the ARB_gpu_shader5 packing functions to revision
2455bd8deadSopenharmony_ci      #5 of this spec; [un]packUnorm2x16, [un]packUnorm4x8 and
2465bd8deadSopenharmony_ci      [un]packSnorm4x8.
2475bd8deadSopenharmony_ci    
2485bd8deadSopenharmony_ci    (5) Should we also provide a [un]packSnorm2x16 packing function, which
2495bd8deadSopenharmony_ci    was not included in ARB_gpu_shader5?
2505bd8deadSopenharmony_ci    
2515bd8deadSopenharmony_ci      RESOLVED: Yes, these functions have been added for completeness. They
2525bd8deadSopenharmony_ci      have been added to revision #5 of this extension and the extension has
2535bd8deadSopenharmony_ci      been renamed from _pack2h to _packing to encompass all these packing
2545bd8deadSopenharmony_ci      functions.
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ciRevision History
2575bd8deadSopenharmony_ci
2585bd8deadSopenharmony_ci    Rev.    Date      Author    Changes
2595bd8deadSopenharmony_ci    ----  ----------  --------  ---------------------------------------------
2605bd8deadSopenharmony_ci     5    06/13/11    pdaniell  Rename the spec to ARB_shading_language_packing
2615bd8deadSopenharmony_ci                                and incorporate all the packing functions into
2625bd8deadSopenharmony_ci                                this spec, including the [un]packSnorm2x16
2635bd8deadSopenharmony_ci                                functions, which have no extension spec.
2645bd8deadSopenharmony_ci     
2655bd8deadSopenharmony_ci     4    12/17/10    johnk     Put in the pack/unpack section instead of 
2665bd8deadSopenharmony_ci                                common functions.  Change a reference to double.
2675bd8deadSopenharmony_ci
2685bd8deadSopenharmony_ci     3    12/12/2010  pbrown    Rename the pack/unpack functions to avoid
2695bd8deadSopenharmony_ci                                conflict with NV_gpu_shader5 names (bug
2705bd8deadSopenharmony_ci                                6858).  Renamed last part of extension name
2715bd8deadSopenharmony_ci                                from "pack2f" to "pack2h" to match the 
2725bd8deadSopenharmony_ci                                function name change.
2735bd8deadSopenharmony_ci
2745bd8deadSopenharmony_ci     2    11/08/2010  pbrown    Fix minor errata in the first draft (bug 
2755bd8deadSopenharmony_ci                                6999).
2765bd8deadSopenharmony_ci
2775bd8deadSopenharmony_ci     1    10/20/2010  pbrown    Internal revision.
278