OpenGL Shading Language Documentation
https://docs.vulkan.org/glsl/latest/index.html
Built-In Functions
https://docs.vulkan.org/glsl/latest/chapters/builtinfunctions.html
The OpenGL Shading Language defines an assortment of built-in convenience functions for scalar and vector operations. Many of these built-in functions can be used in more than one type of shader, but some are intended to provide a direct mapping to hardware and so are available only for a specific type of shader.
OpenGL Shading Language 定义了一系列用于标量和矢量运算的内置函数。其中许多内置函数可用于多种类型的着色器,但有些旨在提供与硬件的直接映射,因此仅适用于特定类型的着色器。
Many of the functions are similar to the same named ones in common C libraries, but they support vector input as well as the more traditional scalar input.
许多函数与常见 C 库中的同名函数类似,但它们支持向量输入以及更传统的标量输入。
Applications should be encouraged to use the built-in functions rather than do the equivalent computations in their own shader code since the built-in functions are assumed to be optimal (e.g. perhaps supported directly in hardware).
应该鼓励应用程序使用内置函数,而不是在自己的着色器代码中执行等效计算,因为内置函数被认为是最佳的 (例如,可能直接在硬件中支持)。
User code can replace built-in functions with their own if they choose, by simply redeclaring and defining the same name and argument list. Because built-in functions are in a more outer scope than user built-in functions, doing this will hide all built-in functions with the same name as the redeclared function.
如果用户愿意,只需重新声明和定义相同的名称和参数列表,即可用自己的函数替换内置函数。由于内置函数的作用域比用户内置函数更外层,因此这样做会隐藏所有与重新声明的函数同名的内置函数。
When the built-in functions are specified below, where the input arguments (and corresponding output) can be float
, vec2
, vec3
, or vec4
, genFType is used as the argument.
Where the input arguments (and corresponding output) can be int
, ivec2
, ivec3
, or ivec4
, genIType is used as the argument.
Where the input arguments (and corresponding output) can be uint
, uvec2
, uvec3
, or uvec4
, genUType is used as the argument.
Where the input arguments (or corresponding output) can be bool
, bvec2
, bvec3
, or bvec4
, genBType is used as the argument.
Where the input arguments (and corresponding output) can be double
, dvec2
, dvec3
, dvec4
, genDType is used as the argument.
For any specific use of a function, the actual types substituted for genFType, genIType, genUType, or genBType have to have the same number of components for all arguments and for the return type.
对于函数的任何特定用途,替换为 genFType、genIType、genUType 或 genBType 的实际类型必须对所有参数和返回类型具有相同数量的组件。
Similarly, mat is used for any matrix basic type with single-precision
components and dmat is used for any matrix basic type with double-precision
components.
Built-in functions have an effective precision qualification. This qualification cannot be set explicitly and may be different from the precision qualification of the result.
Note: In general, as has been noted, precision qualification is ignored unless targeting Vulkan.
注意:一般来说,如前所述,除非针对 Vulkan,否则精度限定将被忽略。
genFType fma(genFType a, genFType b, genFType c)
genDType fma(genDType a, genDType b, genDType c)
Computes and returns a * b + c
.
In uses where the return value is eventually consumed by a variable declared as precise:
fma()
is considered a single operation, whereas the expression a * b + c
consumed by a variable declared precise is considered two operations.
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()
consumed by a precise variable, giving invariant results for the same input values of a
, b
, and c
.
Otherwise, in the absence of precise consumption, there are no special constraints on the number of operations or difference in precision between fma()
and the expression a * b + c
.
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/