clang 23.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>
149_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
150vector<T, 2> select(vector<bool, 2>, vector<T, 2>, vector<T, 2>);
151
152template <typename T>
153_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
154vector<T, 3> select(vector<bool, 3>, vector<T, 3>, vector<T, 3>);
155
156template <typename T>
157_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
158vector<T, 4> select(vector<bool, 4>, vector<T, 4>, vector<T, 4>);
159
160/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, T TrueVal,
161/// vector<T,Sz> FalseVals)
162/// \brief ternary operator for vectors. All vectors must be the same size.
163/// \param Conds The Condition input values.
164/// \param TrueVal The scalar value to splat from when conditions are true.
165/// \param FalseVals The vector values are chosen from when conditions are
166/// false.
167
168template <typename T>
169_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
170vector<T, 2> select(vector<bool, 2>, T, vector<T, 2>);
171
172template <typename T>
173_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
174vector<T, 3> select(vector<bool, 3>, T, vector<T, 3>);
175
176template <typename T>
177_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
178vector<T, 4> select(vector<bool, 4>, T, vector<T, 4>);
179
180/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
181/// T FalseVal)
182/// \brief ternary operator for vectors. All vectors must be the same size.
183/// \param Conds The Condition input values.
184/// \param TrueVals The vector values are chosen from when conditions are true.
185/// \param FalseVal The scalar value to splat from when conditions are false.
186
187template <typename T>
188_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
189vector<T, 2> select(vector<bool, 2>, vector<T, 2>, T);
190
191template <typename T>
192_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
193vector<T, 3> select(vector<bool, 3>, vector<T, 3>, T);
194
195template <typename T>
196_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
197vector<T, 4> select(vector<bool, 4>, vector<T, 4>, T);
198
199/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
200/// T FalseVal)
201/// \brief ternary operator for vectors. All vectors must be the same size.
202/// \param Conds The Condition input values.
203/// \param TrueVal The scalar value to splat from when conditions are true.
204/// \param FalseVal The scalar value to splat from when conditions are false.
205
206template <typename T>
207_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
208__detail::enable_if_t<__detail::is_arithmetic<T>::Value, vector<T, 2>> select(
209 vector<bool, 2>, T, T);
210
211template <typename T>
212_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
213__detail::enable_if_t<__detail::is_arithmetic<T>::Value, vector<T, 3>> select(
214 vector<bool, 3>, T, T);
215
216template <typename T>
217_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
218__detail::enable_if_t<__detail::is_arithmetic<T>::Value, vector<T, 4>> select(
219 vector<bool, 4>, T, T);
220
221} // namespace hlsl
222#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 >)