clang 24.0.0git
hlsl_alias_intrinsics.h
Go to the documentation of this file.
1//===--- hlsl_alias_intrinsics.h - HLSL alias definitions for intrinsics --===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _HLSL_HLSL_ALIAS_INTRINSICS_H_
10#define _HLSL_HLSL_ALIAS_INTRINSICS_H_
11
12namespace hlsl {
13
14// Note: Functions in this file are sorted alphabetically, then grouped by base
15// element type, and the element types are sorted by size, then singed integer,
16// unsigned integer and floating point. Keeping this ordering consistent will
17// help keep this file manageable as it grows.
18
19#define _HLSL_BUILTIN_ALIAS(builtin) \
20 __attribute__((clang_builtin_alias(builtin)))
21#define _HLSL_AVAILABILITY(platform, version) \
22 __attribute__((availability(platform, introduced = version)))
23#define _HLSL_AVAILABILITY_STAGE(platform, version, stage) \
24 __attribute__(( \
25 availability(platform, introduced = version, environment = stage)))
26
27#ifdef __HLSL_ENABLE_16_BIT
28#define _HLSL_16BIT_AVAILABILITY(platform, version, ...) \
29 __attribute__((availability(platform, introduced = version)))
30#define _HLSL_16BIT_AVAILABILITY_STAGE(platform, version, stage) \
31 __attribute__(( \
32 availability(platform, introduced = version, environment = stage)))
33#define _HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT() \
34 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
35#else
36#define _HLSL_16BIT_AVAILABILITY(platform, version, ...) \
37 __VA_OPT__(_HLSL_AVAILABILITY(platform, __VA_ARGS__))
38#define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
39#define _HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
40#endif
41
42// Generated by clang-tblgen from HLSLIntrinsics.td (alias intrinsics).
43#include "hlsl_alias_intrinsics_gen.inc"
44
45//===----------------------------------------------------------------------===//
46// mul builtins
47//===----------------------------------------------------------------------===//
48
49/// \fn R mul(X x, Y y)
50/// \brief Multiplies x and y using matrix math.
51/// \param x [in] The first input value. If x is a vector, it is treated as a
52/// row vector.
53/// \param y [in] The second input value. If y is a vector, it is treated as a
54/// column vector.
55///
56/// The inner dimension x-columns and y-rows must be equal. The result has the
57/// dimension x-rows x y-columns. When both x and y are vectors, the result is
58/// a dot product (scalar). Scalar operands are multiplied element-wise.
59///
60/// This function supports 9 overloaded forms:
61/// 1. scalar * scalar -> scalar
62/// 2. scalar * vector -> vector
63/// 3. scalar * matrix -> matrix
64/// 4. vector * scalar -> vector
65/// 5. vector * vector -> scalar (dot product)
66/// 6. vector * matrix -> vector
67/// 7. matrix * scalar -> matrix
68/// 8. matrix * vector -> vector
69/// 9. matrix * matrix -> matrix
70
71// Cases 1, 2, 3, 4, 5, and 7 of mul are defined in hlsl_intrinsics.h as
72// header-only implementations because they are elementwise operations and dot
73// products easily expressed in HLSL.
74
75// Cases 6, 8, and 9 are defined below to alias the mul builtin so that they can
76// be lowered to the llvm.matrix.multiply intrinsic which is not exposed
77// directly to HLSL.
78
79// Case 6: vector * matrix -> vector
80template <int R, int C>
82_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul) vector<half, C> mul(vector<half, R>,
83 matrix<half, R, C>);
84
85template <typename T, int R, int C>
86_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul)
87vector<T, C> mul(vector<T, R>, matrix<T, R, C>);
88
89// Case 8: matrix * vector -> vector
90template <int R, int C>
92_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul) vector<half, R> mul(matrix<half, R, C>,
93 vector<half, C>);
94
95template <typename T, int R, int C>
96_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul)
97vector<T, R> mul(matrix<T, R, C>, vector<T, C>);
98
99// Case 9: matrix * matrix -> matrix
100template <int R, int K, int C>
102_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul) matrix<half, R, C> mul(
103 matrix<half, R, K>, matrix<half, K, C>);
104
105template <typename T, int R, int K, int C>
106_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul)
107matrix<T, R, C> mul(matrix<T, R, K>, matrix<T, K, C>);
108
109//===----------------------------------------------------------------------===//
110// transpose builtins
111//===----------------------------------------------------------------------===//
112
113/// \fn matrix<T, C, R> transpose(matrix<T, R, C> x)
114/// \brief Returns the transpose of the input matrix.
115/// \param x [in] The input matrix.
116
117template <int R, int C>
118_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
119_HLSL_BUILTIN_ALIAS(__builtin_hlsl_transpose) matrix<half, C, R> transpose(
120 matrix<half, R, C>);
121
122template <typename T, int R, int C>
123_HLSL_BUILTIN_ALIAS(__builtin_hlsl_transpose)
124matrix<T, C, R> transpose(matrix<T, R, C>);
125
126//===----------------------------------------------------------------------===//
127// select builtins
128//===----------------------------------------------------------------------===//
129
130/// \fn T select(bool Cond, T TrueVal, T FalseVal)
131/// \brief ternary operator.
132/// \param Cond The Condition input value.
133/// \param TrueVal The Value returned if Cond is true.
134/// \param FalseVal The Value returned if Cond is false.
135
136template <typename T>
137_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
138T select(bool, T, T);
139
140/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
141/// vector<T,Sz> FalseVals)
142/// \brief ternary operator for vectors. All vectors must be the same size.
143/// \param Conds The Condition input values.
144/// \param TrueVals The vector values are chosen from when conditions are true.
145/// \param FalseVals The vector values are chosen from when conditions are
146/// false.
147
148template <typename T, int N>
149_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
150vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, vector<T, N>,
151 vector<T, N>);
152
153/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, T TrueVal,
154/// vector<T,Sz> FalseVals)
155/// \brief ternary operator for vectors. All vectors must be the same size.
156/// \param Conds The Condition input values.
157/// \param TrueVal The scalar value to splat from when conditions are true.
158/// \param FalseVals The vector values are chosen from when conditions are
159/// false.
160
161template <typename T, int N>
162_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
163vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, T,
164 vector<T, N>);
165
166/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
167/// T FalseVal)
168/// \brief ternary operator for vectors. All vectors must be the same size.
169/// \param Conds The Condition input values.
170/// \param TrueVals The vector values are chosen from when conditions are true.
171/// \param FalseVal The scalar value to splat from when conditions are false.
172
173template <typename T, int N>
174_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
175vector<T, N> select(__detail::type_identity_t<vector<bool, N>>, vector<T, N>,
176 T);
177
178/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, T TrueVals,
179/// T FalseVal)
180/// \brief ternary operator for vectors. All vectors must be the same size.
181/// \param Conds The Condition input values.
182/// \param TrueVal The scalar value to splat from when conditions are true.
183/// \param FalseVal The scalar value to splat from when conditions are false.
184
185template <typename T, typename U, int N>
186__detail::enable_if_t<(N > 1 && __detail::is_arithmetic<T>::Value),
187 vector<T, N>>
188select(vector<U, N> Conds, T TrueVal, T FalseVal) {
189 return __builtin_hlsl_select((vector<bool, N>)Conds, TrueVal, FalseVal);
190}
191
192} // namespace hlsl
193#endif //_HLSL_HLSL_ALIAS_INTRINSICS_H_
#define _HLSL_16BIT_AVAILABILITY(platform, version,...)
#define _HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul) vector< half
T select(bool, T, T)
ternary operator.
C mul(vector< half, R >, matrix< half, R, C >)
R transpose(matrix< half, R, C >)