© Copyright 20142017 The Khronos Group Inc. All Rights Reserved.
© Copyright 20142017 The Khronos Group Inc. All Rights Reserved.
This specification is protected by copyright laws and contains material proprietary to the Khronos Group, Inc. It or any components may not be reproduced, republished, distributed, transmitted, displayed, broadcast, or otherwise exploited in any manner without the express prior written permission of Khronos Group. You may use this specification for implementing the functionality therein, without altering or removing any trademark, copyright or other notice from the specification, but the receipt or possession of this specification does not convey any rights to reproduce, disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe, in whole or in part.
Khronos Group grants express permission to any current Promoter, Contributor or Adopter member of Khronos to copy and redistribute UNMODIFIED versions of this specification in any fashion, provided that NO CHARGE is made for the specification and the latest available update of the specification for any version of the API is used whenever possible. Such distributed specification may be reformatted AS LONG AS the contents of the specification are not changed in any way. The specification may be incorporated into a product that is sold as long as such product includes significant independent work developed by the seller. A link to the current version of this specification on the Khronos Group website should be included whenever possible with specification distributions.
Khronos Group makes no, and expressly disclaims any, representations or warranties, express or implied, regarding this specification, including, without limitation, any implied warranties of merchantability or fitness for a particular purpose or noninfringement of any intellectual property. Khronos Group makes no, and expressly disclaims any, warranties, express or implied, regarding the correctness, accuracy, completeness, timeliness, and reliability of the specification. Under no circumstances will the Khronos Group, or any of its Promoters, Contributors or Members or their respective partners, officers, directors, employees, agents, or representatives be liable for any damages, whether direct, indirect, special or consequential damages for lost revenues, lost profits, or otherwise, arising from or in connection with these materials. Khronos, SYCL, SPIR, WebGL, EGL, COLLADA, StreamInput, OpenVX, OpenKCam, glTF, OpenKODE, OpenVG, OpenWF, OpenSL ES, OpenMAX, OpenMAX AL, OpenMAX IL and OpenMAX DL are trademarks and WebCL is a certification mark of the Khronos Group Inc. OpenCL is a trademark of Apple Inc. and OpenGL and OpenML are registered trademarks and the OpenGL ES and OpenGL SC logos are trademarks of Silicon Graphics International used under license by Khronos. All other product names, trademarks, and/or company names are used solely for identification and belong to their respective owners.
1. Introduction
This specifies the GLSL.std.450 extended instruction set. It provides instructions for the GLSL builtin functions that do not directly map to native SPIRV instructions.
Import this extended instruction set using an OpExtInstImport "GLSL.std.450" instruction.
2. Binary Form
Documentation form for each extended instruction:
Extended Instruction Name Instruction description. Result Type will describe the Result Type for the OpExtInst instruction. Number is the extended instruction number to use in the OpExtInst instruction. Operand 1, Operand 2,… are the operands listed for the OpExtInst instruction. Any Capability restrictions. 

Number 
Operand 1 
Operand 2 
… 
Extended instructions:
Round 

1 
<id> 
RoundEven 

2 
<id> 
Trunc 

3 
<id> 
FAbs 

4 
<id> 
SAbs 

5 
<id> 
FSign 

6 
<id> 
SSign 

7 
<id> 
Floor 

8 
<id> 
Ceil 

9 
<id> 
Fract 

10 
<id> 
Radians 

11 
<id> 
Degrees 

12 
<id> 
Sin 

13 
<id> 
Cos 

14 
<id> 
Tan 

15 
<id> 
Asin 

16 
<id> 
Acos 

17 
<id> 
Atan 

18 
<id> 
Sinh 

19 
<id> 
Cosh 

20 
<id> 
Tanh 

21 
<id> 
Asinh 

22 
<id> 
Acosh 

23 
<id> 
Atanh 

24 
<id> 
Atan2 

25 
<id> 
<id> 
Pow 

26 
<id> 
<id> 
Exp 

27 
<id> 
Log 

28 
<id> 
Exp2 

29 
<id> 
Log2 

30 
<id> 
Sqrt 

31 
<id> 
InverseSqrt 

32 
<id> 
Determinant 

33 
<id> 
MatrixInverse 

34 
<id> 
Modf 

35 
<id> 
<id> 
ModfStruct 

36 
<id> 
FMin 

37 
<id> 
<id> 
UMin 

38 
<id> 
<id> 
SMin 

39 
<id> 
<id> 
FMax 

40 
<id> 
<id> 
UMax 

41 
<id> 
<id> 
SMax 

42 
<id> 
<id> 
FClamp 

43 
<id> 
<id> 
<id> 
UClamp 

44 
<id> 
<id> 
<id> 
SClamp 

45 
<id> 
<id> 
<id> 
FMix 

46 
<id> 
<id> 
<id> 
Step 

48 
<id> 
<id> 
SmoothStep 

49 
<id> 
<id> 
<id> 
Fma  The precision of fma can differ from the precision of the expression a * b + c.  fma will be computed with the same precision as any other fma decorated with NoContraction, giving invariant results for the same input values of a, b, and c. 

50 
<id> 
<id> 
<id> 
Frexp x = significand * 2^{exponent} The significand is the result and the exponent is returned through the pointerparameter exp. For a floatingpoint value of zero, the significand and exponent are both zero. For a floatingpoint value that is an infinity or is not a number, the result is undefined. If an implementation supports negative 0, Frexp 0 should result in 0; otherwise it will result in 0. 

51 
<id> 
<id> 
FrexpStruct 

52 
<id> 
Ldexp significand * 2^{exponent} If this product is too large to be represented in the floatingpoint type, the result is undefined. If exp is greater than +128 (single precision) or +1024 (double precision), the result undefined. If exp is less than 126 (single precision) or 1022 (double precision), the result may be flushed to zero. Additionally, splitting the value into a significand and exponent using frexp and then reconstructing a floatingpoint value using ldexp should yield the original input for zero and all finite nondenormalized values. 

53 
<id> 
<id> 
PackSnorm4x8 The conversion for component c of v to fixed point is done as follows: round(clamp(c, 1, +1) * 127.0) The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits. 

54 
<id> 
PackUnorm4x8 The conversion for component c of v to fixed point is done as follows: round(clamp(c, 0, +1) * 255.0) The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits. 

55 
<id> 
PackSnorm2x16 The conversion for component c of v to fixed point is done as follows: round(clamp(c, 1, +1) * 32767.0) The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits. 

56 
<id> 
PackUnorm2x16 The conversion for component c of v to fixed point is done as follows: round(clamp(c, 0, +1) * 65535.0) The first component of the vector will be written to the least significant bits of the output; the last component will be written to the most significant bits. 

57 
<id> 
PackHalf2x16 

58 
<id> 
PackDouble2x32 

59 
<id> 
UnpackSnorm2x16 clamp(f / 32767.0, 1, +1) The first component of the result will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits. 

60 
<id> 
UnpackUnorm2x16 f / 65535.0 The first component of the result will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits. 

61 
<id> 
UnpackHalf2x16 The first component of the vector is obtained from the 16 leastsignificant bits of v; the second component is obtained from the 16 mostsignificant bits of v. 

62 
<id> 
UnpackSnorm4x8 clamp(f / 127.0, 1, +1) The first component of the result will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits. 

63 
<id> 
UnpackUnorm4x8 f / 255.0 The first component of the result will be extracted from the least significant bits of the input; the last component will be extracted from the most significant bits. 

64 
<id> 
UnpackDouble2x32 

65 
<id> 
Length 

66 
<id> 
Distance 

67 
<id> 
<id> 
Cross x[1] * y[2]  y[1] * x[2] x[2] * y[0]  y[2] * x[0] x[0] * y[1]  y[0] * x[1] 

68 
<id> 
<id> 
Normalize 

69 
<id> 
FaceForward 

70 
<id> 
<id> 
<id> 
Reflect I  2 * dot(N, I) * N N must already be normalized in order to achieve the desired result. 

71 
<id> 
<id> 
Refract k = 1.0  eta * eta * (1.0  dot(N, I) * dot(N, I)) if k < 0.0 the result is 0.0 otherwise, the result is eta * I  (eta * dot(N, I) + sqrt(k)) * N The input parameters for the incident vector I and the surface normal N must already be normalized to get the desired results. 

72 
<id> 
<id> 
<id> 
FindILsb 

73 
<id> 
FindSMsb 

74 
<id> 
FindUMsb 

75 
<id> 
InterpolateAtCentroid 

76 
<id> 
InterpolateAtSample 

77 
<id> 
<id> 
InterpolateAtOffset 

78 
<id> 
<id> 
NMin 

79 
<id> 
<id> 
NMax 

80 
<id> 
<id> 
NClamp 

81 
<id> 
<id> 
<id> 
3. Appendix A: Changes
3.1. Changes from Version 0.99, Revision 1

Fork the revision stream, changes section, etc. from the core specification, so this specification has its own, starting numbering at revision 1. This document now lives independently.

Added integer versions of abs, sign, min, max, and clamp.

Removed floatBitsToInt, floatBitsToUint, intBitsToFloat, and uintBitsToFloat; these can be handled with OpBitcast.

Removed fTransform, not needed.

Fixed internal bugs

13721: Add OpTypeStructresult versions of Modf and Frexp: ModfStruct and FrexpStruct.


Fixed public bugs

1322: GLSL.std.450 frexp wasn’t saying the exp argument was a pointer to the result

3.2. Changes from Version 0.99, Revision 2

Moved AddCarry, SubBorrow, and MulExtended type of instructions to the core specification.

Added integer variant of Mix, creating FMix and IMix (14480).

Modified spellings to be more regular (14614).
3.3. Changes from Version 0.99, Revision 3

Add "N" version of Min, Max, and Clamp, creating a version that favors nonNaN operands over NaN operands.

Bug 15452 Remove IMix.

Bug 15300 Be more consistent that the InterpolateAt instructions take a pointer.

Bug 14548 Document the Capability needed for Double2x32 and InterpolateAt instructions.
3.4. Changes from Version 1.00, Revision 1

Bug 14548 Document the Capability needed for UnpackDouble2x32.
3.5. Changes from Version 1.00, Revision 2

Change precise to NoContraction
3.6. Changes from Version 1.00, Revision 3

Allow both 16bit and 32bit floatingpoint types in most places where before only 32bit floatingpoint types were allowed. This does not effect whether 16bit floating point types are allowed, which is selected independently. Since 16bit types were historically disallowed, this is a backward compatible change.

Fix Khronos internal issue #109: be more clear for NMin/NMax: If both operands are NaN, the result is a NaN.
3.7. Changes from Version 1.00, Revision 4

Be clear about UnpackHalf2x16 denorm rules.
3.8. Changes from Version 1.00, Revision 5
Fixed:

Khronos SPIRV Issue #211: As with FindSMsb and FindUMsb, FindILsb needs 32bit components.
3.9. Changes from Version 1.00, Revision 6
Fixed:

Khronos SPIRV Issue #337: The component types of the operands for Refract must all be the same.

Khronos SPIRV Issue #331: Correct the types in ModfStruct.