clang 23.0.0git
hlsl_intrinsics.h
Go to the documentation of this file.
1//===----- hlsl_intrinsics.h - HLSL 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_INTRINSICS_H_
10#define _HLSL_HLSL_INTRINSICS_H_
11
13
14namespace hlsl {
15
16// Generated by clang-tblgen from HLSLIntrinsics.td (detail/inline intrinsics).
17#include "hlsl_inline_intrinsics_gen.inc"
18
19//===----------------------------------------------------------------------===//
20// asfloat builtins
21//===----------------------------------------------------------------------===//
22
23/// \fn float asfloat(T Val)
24/// \brief Interprets the bit pattern of x as float point number.
25/// \param Val The input value.
26
27template <typename T, int N>
28constexpr vector<float, N> asfloat(vector<T, N> V) {
30}
31
32template <typename T> constexpr float asfloat(T F) {
34}
35
36//===----------------------------------------------------------------------===//
37// asint builtins
38//===----------------------------------------------------------------------===//
39
40/// \fn int asint(T Val)
41/// \brief Interprets the bit pattern of x as an integer.
42/// \param Val The input value.
43
44template <typename T, int N> constexpr vector<int, N> asint(vector<T, N> V) {
46}
47
48template <typename T> constexpr int asint(T F) {
50}
51
52//===----------------------------------------------------------------------===//
53// asint16 builtins
54//===----------------------------------------------------------------------===//
55
56/// \fn int16_t asint16(T X)
57/// \brief Interprets the bit pattern of \a X as an 16-bit integer.
58/// \param X The input value.
59
60#ifdef __HLSL_ENABLE_16_BIT
61
62template <typename T, int N>
63_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
64constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
65 __detail::is_same<uint16_t, T>::value ||
66 __detail::is_same<half, T>::value,
67 vector<int16_t, N>> asint16(vector<T, N> V) {
69}
70
71template <typename T>
72_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
73constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
74 __detail::is_same<uint16_t, T>::value ||
75 __detail::is_same<half, T>::value,
76 int16_t> asint16(T F) {
78}
79#endif
80
81//===----------------------------------------------------------------------===//
82// asuint builtins
83//===----------------------------------------------------------------------===//
84
85/// \fn uint asuint(T Val)
86/// \brief Interprets the bit pattern of x as an unsigned integer.
87/// \param Val The input value.
88
89template <typename T, int N> constexpr vector<uint, N> asuint(vector<T, N> V) {
91}
92
93template <typename T> constexpr uint asuint(T F) {
95}
96
97//===----------------------------------------------------------------------===//
98// asuint splitdouble builtins
99//===----------------------------------------------------------------------===//
100
101/// \fn void asuint(double D, out uint lowbits, out int highbits)
102/// \brief Split and interprets the lowbits and highbits of double D into uints.
103/// \param D The input double.
104/// \param lowbits The output lowbits of D.
105/// \param highbits The output highbits of D.
106_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
107void asuint(double, out uint, out uint);
108_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
109void asuint(double2, out uint2, out uint2);
110_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
111void asuint(double3, out uint3, out uint3);
112_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
113void asuint(double4, out uint4, out uint4);
114
115//===----------------------------------------------------------------------===//
116// asuint16 builtins
117//===----------------------------------------------------------------------===//
118
119/// \fn uint16_t asuint16(T X)
120/// \brief Interprets the bit pattern of \a X as an 16-bit unsigned integer.
121/// \param X The input value.
122
123#ifdef __HLSL_ENABLE_16_BIT
124
125template <typename T, int N>
126_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
127constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
128 __detail::is_same<uint16_t, T>::value ||
129 __detail::is_same<half, T>::value,
130 vector<uint16_t, N>> asuint16(vector<T, N> V) {
132}
133
134template <typename T>
135_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
136constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
137 __detail::is_same<uint16_t, T>::value ||
138 __detail::is_same<half, T>::value,
139 uint16_t> asuint16(T F) {
141}
142#endif
143
144//===----------------------------------------------------------------------===//
145// distance builtins
146//===----------------------------------------------------------------------===//
147
148/// \fn K distance(T X, T Y)
149/// \brief Returns a distance scalar between \a X and \a Y.
150/// \param X The X input value.
151/// \param Y The Y input value.
152
153template <typename T>
154_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
155const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
156 __detail::is_same<half, T>::value,
157 T> distance(T X, T Y) {
158 return __detail::distance_impl(X, Y);
159}
160
161template <typename T>
162const inline __detail::enable_if_t<
164distance(T X, T Y) {
165 return __detail::distance_impl(X, Y);
166}
167
168template <int N>
169_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
170const inline half distance(__detail::HLSL_FIXED_VECTOR<half, N> X,
171 __detail::HLSL_FIXED_VECTOR<half, N> Y) {
173}
174
175template <int N>
180
181//===----------------------------------------------------------------------===//
182// dot2add builtins
183//===----------------------------------------------------------------------===//
184
185/// \fn float dot2add(half2 A, half2 B, float C)
186/// \brief Dot product of 2 vector of type half and add a float scalar value.
187/// \param A The first input value to dot product.
188/// \param B The second input value to dot product.
189/// \param C The input value added to the dot product.
190
191_HLSL_AVAILABILITY(shadermodel, 6.4)
192const inline float dot2add(half2 A, half2 B, float C) {
193 return __detail::dot2add_impl(A, B, C);
194}
195
196//===----------------------------------------------------------------------===//
197// dst builtins
198//===----------------------------------------------------------------------===//
199
200/// \fn vector<T, 4> dst(vector<T, 4>, vector<T, 4>)
201/// \brief Calculates a distance vector.
202/// \param Src0 [in] Contains the squared distance
203/// \param Src1 [in] Contains the reciprocal distance
204///
205/// Return the computed distance vector
206
207_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
208const inline half4 dst(half4 Src0, half4 Src1) {
209 return __detail::dst_impl(Src0, Src1);
210}
211
212const inline float4 dst(float4 Src0, float4 Src1) {
213 return __detail::dst_impl(Src0, Src1);
214}
215
216const inline double4 dst(double4 Src0, double4 Src1) {
217 return __detail::dst_impl(Src0, Src1);
218}
219
220//===----------------------------------------------------------------------===//
221// faceforward builtin
222//===----------------------------------------------------------------------===//
223
224/// \fn T faceforward(T N, T I, T Ng)
225/// \brief Flips the surface-normal (if needed) to face in a direction opposite
226/// to \a I. Returns the result in terms of \a N.
227/// \param N The resulting floating-point surface-normal vector.
228/// \param I A floating-point, incident vector that points from the view
229/// position to the shading position.
230/// \param Ng A floating-point surface-normal vector.
231///
232/// Return a floating-point, surface normal vector that is facing the view
233/// direction.
234
235template <typename T>
236_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
237const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
238 __detail::is_same<half, T>::value,
239 T> faceforward(T N, T I, T Ng) {
240 return __detail::faceforward_impl(N, I, Ng);
241}
242
243template <typename T>
244const inline __detail::enable_if_t<
246faceforward(T N, T I, T Ng) {
247 return __detail::faceforward_impl(N, I, Ng);
248}
249
250template <int L>
251_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
252const inline __detail::HLSL_FIXED_VECTOR<half, L> faceforward(
253 __detail::HLSL_FIXED_VECTOR<half, L> N,
254 __detail::HLSL_FIXED_VECTOR<half, L> I,
255 __detail::HLSL_FIXED_VECTOR<half, L> Ng) {
256 return __detail::faceforward_impl(N, I, Ng);
257}
258
259template <int L>
266
267//===----------------------------------------------------------------------===//
268// firstbithigh builtins
269//===----------------------------------------------------------------------===//
270
271/// \fn T firstbithigh(T Val)
272/// \brief Returns the location of the first set bit starting from the lowest
273/// order bit and working upward, per component.
274/// \param Val the input value.
275
276#ifdef __HLSL_ENABLE_16_BIT
277
278template <typename T>
279_HLSL_AVAILABILITY(shadermodel, 6.2)
280const inline __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
281 __detail::is_same<uint16_t, T>::value,
282 uint> firstbithigh(T X) {
284}
285
286template <typename T, int N>
287_HLSL_AVAILABILITY(shadermodel, 6.2)
288const
289 inline __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
290 __detail::is_same<uint16_t, T>::value,
291 vector<uint, N>> firstbithigh(vector<T, N> X) {
292 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 16>(X);
293}
294
295#endif
296
297template <typename T>
298const inline __detail::enable_if_t<
303
304template <typename T, int N>
305const inline __detail::enable_if_t<__detail::is_same<int, T>::value ||
307 vector<uint, N>>
308firstbithigh(vector<T, N> X) {
309 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 32>(X);
310}
311
312template <typename T>
313const inline __detail::enable_if_t<__detail::is_same<int64_t, T>::value ||
315 uint>
319
320template <typename T, int N>
321const inline __detail::enable_if_t<__detail::is_same<int64_t, T>::value ||
323 vector<uint, N>>
324firstbithigh(vector<T, N> X) {
325 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 64>(X);
326}
327
328//===----------------------------------------------------------------------===//
329// fmod builtins
330//===----------------------------------------------------------------------===//
331
332/// \fn T fmod(T x, T y)
333/// \brief Returns the linear interpolation of x to y.
334/// \param x [in] The dividend.
335/// \param y [in] The divisor.
336///
337/// Return the floating-point remainder of the x parameter divided by the y
338/// parameter.
339
340template <typename T>
341_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
342const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
343 __detail::is_same<half, T>::value,
344 T> fmod(T X, T Y) {
345 return __detail::fmod_impl(X, Y);
346}
347
348template <typename T>
349const inline __detail::enable_if_t<
351fmod(T X, T Y) {
352 return __detail::fmod_impl(X, Y);
353}
354
355template <int N>
356_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
357const inline __detail::HLSL_FIXED_VECTOR<half, N> fmod(
358 __detail::HLSL_FIXED_VECTOR<half, N> X,
359 __detail::HLSL_FIXED_VECTOR<half, N> Y) {
360 return __detail::fmod_vec_impl(X, Y);
361}
362
363template <int N>
369
370//===----------------------------------------------------------------------===//
371// ldexp builtins
372//===----------------------------------------------------------------------===//
373
374/// \fn T ldexp(T X, T Exp)
375/// \brief Returns the result of multiplying the specified value by two raised
376/// to the power of the specified exponent.
377/// \param X [in] The specified value.
378/// \param Exp [in] The specified exponent.
379///
380/// This function uses the following formula: X * 2^Exp
381
382template <typename T>
383_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
384const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
385 __detail::is_same<half, T>::value,
386 T> ldexp(T X, T Exp) {
387 return __detail::ldexp_impl(X, Exp);
388}
389
390template <typename T>
391const inline __detail::enable_if_t<
393ldexp(T X, T Exp) {
394 return __detail::ldexp_impl(X, Exp);
395}
396
397template <int N>
398_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
399const inline __detail::HLSL_FIXED_VECTOR<half, N> ldexp(
400 __detail::HLSL_FIXED_VECTOR<half, N> X,
401 __detail::HLSL_FIXED_VECTOR<half, N> Exp) {
402 return __detail::ldexp_impl(X, Exp);
403}
404
405template <int N>
411
412//===----------------------------------------------------------------------===//
413// length builtins
414//===----------------------------------------------------------------------===//
415
416/// \fn T length(T x)
417/// \brief Returns the length of the specified floating-point vector.
418/// \param x [in] The vector of floats, or a scalar float.
419///
420/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
421
422template <typename T>
423_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
424const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
425 __detail::is_same<half, T>::value,
426 T> length(T X) {
427 return __detail::length_impl(X);
428}
429
430template <typename T>
431const inline __detail::enable_if_t<
434 return __detail::length_impl(X);
435}
436
437template <int N>
438_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
439const inline half length(__detail::HLSL_FIXED_VECTOR<half, N> X) {
441}
442
443template <int N>
447
448//===----------------------------------------------------------------------===//
449// lit builtins
450//===----------------------------------------------------------------------===//
451
452/// \fn vector<T, 4> lit(T NDotL, T NDotH, T M)
453/// \brief Returns a lighting coefficient vector.
454/// \param NDotL The dot product of the normalized surface normal and the
455/// light vector.
456/// \param NDotH The dot product of the half-angle vector and the surface
457/// normal.
458/// \param M A specular exponent.
459///
460/// This function returns a lighting coefficient vector (ambient, diffuse,
461/// specular, 1).
462
463_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
464const inline half4 lit(half NDotL, half NDotH, half M) {
465 return __detail::lit_impl(NDotL, NDotH, M);
466}
467
468const inline float4 lit(float NDotL, float NDotH, float M) {
469 return __detail::lit_impl(NDotL, NDotH, M);
470}
471
472//===----------------------------------------------------------------------===//
473// D3DCOLORtoUBYTE4 builtin
474//===----------------------------------------------------------------------===//
475
476/// \fn T D3DCOLORtoUBYTE4(T x)
477/// \brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
478/// \param x [in] The floating-point vector4 to convert.
479///
480/// The return value is the UBYTE4 representation of the \a x parameter.
481///
482/// This function swizzles and scales components of the \a x parameter. Use this
483/// function to compensate for the lack of UBYTE4 support in some hardware.
484
488
489//===----------------------------------------------------------------------===//
490// NonUniformResourceIndex builtin
491//===----------------------------------------------------------------------===//
492
493/// \fn uint NonUniformResourceIndex(uint I)
494/// \brief A compiler hint to indicate that a resource index varies across
495/// threads within a wave (i.e., it is non-uniform).
496/// \param I [in] Resource array index
497///
498/// The return value is the \Index parameter.
499///
500/// When indexing into an array of shader resources (e.g., textures, buffers),
501/// some GPU hardware and drivers require the compiler to know whether the index
502/// is uniform (same for all threads) or non-uniform (varies per thread).
503///
504/// Using NonUniformResourceIndex explicitly marks an index as non-uniform,
505/// disabling certain assumptions or optimizations that could lead to incorrect
506/// behavior when dynamically accessing resource arrays with non-uniform
507/// indices.
508
510 return __builtin_hlsl_resource_nonuniformindex(Index);
511}
512
513//===----------------------------------------------------------------------===//
514// reflect builtin
515//===----------------------------------------------------------------------===//
516
517/// \fn T reflect(T I, T N)
518/// \brief Returns a reflection using an incident ray, \a I, and a surface
519/// normal, \a N.
520/// \param I The incident ray.
521/// \param N The surface normal.
522///
523/// The return value is a floating-point vector that represents the reflection
524/// of the incident ray, \a I, off a surface with the normal \a N.
525///
526/// This function calculates the reflection vector using the following formula:
527/// V = I - 2 * N * dot(I N) .
528///
529/// N must already be normalized in order to achieve the desired result.
530///
531/// The operands must all be a scalar or vector whose component type is
532/// floating-point.
533///
534/// Result type and the type of all operands must be the same type.
535
536template <typename T>
537_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
538const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
539 __detail::is_same<half, T>::value,
540 T> reflect(T I, T N) {
541 return __detail::reflect_impl(I, N);
542}
543
544template <typename T>
545const inline __detail::enable_if_t<
547reflect(T I, T N) {
548 return __detail::reflect_impl(I, N);
549}
550
551template <int L>
552_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
553const inline __detail::HLSL_FIXED_VECTOR<half, L> reflect(
554 __detail::HLSL_FIXED_VECTOR<half, L> I,
555 __detail::HLSL_FIXED_VECTOR<half, L> N) {
556 return __detail::reflect_vec_impl(I, N);
557}
558
559template <int L>
565
566//===----------------------------------------------------------------------===//
567// refract builtin
568//===----------------------------------------------------------------------===//
569
570/// \fn T refract(T I, T N, T eta)
571/// \brief Returns a refraction using an entering ray, \a I, a surface
572/// normal, \a N and refraction index \a eta
573/// \param I The entering ray.
574/// \param N The surface normal.
575/// \param eta The refraction index.
576///
577/// The return value is a floating-point vector that represents the refraction
578/// using the refraction index, \a eta, for the direction of the entering ray,
579/// \a I, off a surface with the normal \a N.
580///
581/// This function calculates the refraction vector using the following formulas:
582/// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
583/// if k < 0.0 the result is 0.0
584/// otherwise, the result is eta * I - (eta * dot(N, I) + sqrt(k)) * N
585///
586/// I and N must already be normalized in order to achieve the desired result.
587///
588/// I and N must be a scalar or vector whose component type is
589/// floating-point.
590///
591/// eta must be a 16-bit or 32-bit floating-point scalar.
592///
593/// Result type, the type of I, and the type of N must all be the same type.
594
595template <typename T>
596_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
597const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
598 __detail::is_same<half, T>::value,
599 T> refract(T I, T N, T eta) {
600 return __detail::refract_impl(I, N, eta);
601}
602
603template <typename T>
604const inline __detail::enable_if_t<
606refract(T I, T N, T eta) {
607 return __detail::refract_impl(I, N, eta);
608}
609
610template <int L>
611_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
612const inline __detail::HLSL_FIXED_VECTOR<half, L> refract(
613 __detail::HLSL_FIXED_VECTOR<half, L> I,
614 __detail::HLSL_FIXED_VECTOR<half, L> N, half eta) {
615 return __detail::refract_impl(I, N, eta);
616}
617
618template <int L>
624
625//===----------------------------------------------------------------------===//
626// smoothstep builtin
627//===----------------------------------------------------------------------===//
628
629/// \fn T smoothstep(T Min, T Max, T X)
630/// \brief Returns a smooth Hermite interpolation between 0 and 1, if \a X is in
631/// the range [\a Min, \a Max].
632/// \param Min The minimum range of the x parameter.
633/// \param Max The maximum range of the x parameter.
634/// \param X The specified value to be interpolated.
635///
636/// The return value is 0.0 if \a X ≤ \a Min and 1.0 if \a X ≥ \a Max. When \a
637/// Min < \a X < \a Max, the function performs smooth Hermite interpolation
638/// between 0 and 1.
639
640template <typename T>
641_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
642const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
643 __detail::is_same<half, T>::value,
644 T> smoothstep(T Min, T Max, T X) {
645 return __detail::smoothstep_impl(Min, Max, X);
646}
647
648template <typename T>
649const inline __detail::enable_if_t<
651smoothstep(T Min, T Max, T X) {
652 return __detail::smoothstep_impl(Min, Max, X);
653}
654
655template <int N>
656_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
657const inline __detail::HLSL_FIXED_VECTOR<half, N> smoothstep(
658 __detail::HLSL_FIXED_VECTOR<half, N> Min,
659 __detail::HLSL_FIXED_VECTOR<half, N> Max,
660 __detail::HLSL_FIXED_VECTOR<half, N> X) {
661 return __detail::smoothstep_vec_impl(Min, Max, X);
662}
663
664template <int N>
671
672inline bool CheckAccessFullyMapped(uint Status) {
673 return static_cast<bool>(Status);
674}
675
676//===----------------------------------------------------------------------===//
677// ddx builtin
678//===----------------------------------------------------------------------===//
679
680/// \fn T ddx(T x)
681/// \brief Computes the sum of the absolute values of the partial derivatives
682/// with regard to the x screen space coordinate.
683/// \param x [in] The floating-point scalar or vector to process.
684///
685/// The return value is a floating-point scalar or vector where each element
686/// holds the computation of the matching element in the input.
687
688template <typename T>
689_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
690const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
691 __detail::is_same<half, T>::value,
692 T> ddx(T input) {
693 return __detail::ddx_impl(input);
694}
695
696template <typename T>
697const inline __detail::enable_if_t<
699ddx(T input) {
700 return __detail::ddx_impl(input);
701}
702
703template <int N>
704_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
705const inline __detail::HLSL_FIXED_VECTOR<half, N> ddx(
706 __detail::HLSL_FIXED_VECTOR<half, N> input) {
707 return __detail::ddx_impl(input);
708}
709
710template <int N>
715
716//===----------------------------------------------------------------------===//
717// ddy builtin
718//===----------------------------------------------------------------------===//
719
720/// \fn T ddy(T x)
721/// \brief Computes the sum of the absolute values of the partial derivatives
722/// with regard to the y screen space coordinate.
723/// \param x [in] The floating-point scalar or vector to process.
724///
725/// The return value is a floating-point scalar or vector where each element
726/// holds the computation of the matching element in the input.
727
728template <typename T>
729_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
730const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
731 __detail::is_same<half, T>::value,
732 T> ddy(T input) {
733 return __detail::ddy_impl(input);
734}
735
736template <typename T>
737const inline __detail::enable_if_t<
739ddy(T input) {
740 return __detail::ddy_impl(input);
741}
742
743template <int N>
744_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
745const inline __detail::HLSL_FIXED_VECTOR<half, N> ddy(
746 __detail::HLSL_FIXED_VECTOR<half, N> input) {
747 return __detail::ddy_impl(input);
748}
749
750template <int N>
755
756//===----------------------------------------------------------------------===//
757// fwidth builtin
758//===----------------------------------------------------------------------===//
759
760/// \fn T fwidth(T x)
761/// \brief Computes the sum of the absolute values of the partial derivatives
762/// with regard to the x and y screen space coordinates.
763/// \param x [in] The floating-point scalar or vector to process.
764///
765/// The return value is a floating-point scalar or vector where each element
766/// holds the computation of the matching element in the input.
767
768template <typename T>
769_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
770const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
771 __detail::is_same<half, T>::value,
772 T> fwidth(T input) {
773 return __detail::fwidth_impl(input);
774}
775
776template <typename T>
777const inline __detail::enable_if_t<
779fwidth(T input) {
780 return __detail::fwidth_impl(input);
781}
782
783template <int N>
784_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
785const inline __detail::HLSL_FIXED_VECTOR<half, N> fwidth(
786 __detail::HLSL_FIXED_VECTOR<half, N> input) {
787 return __detail::fwidth_impl(input);
788}
789
790template <int N>
795
796//===----------------------------------------------------------------------===//
797// mul builtins
798//===----------------------------------------------------------------------===//
799
800/// \fn R mul(X x, Y y)
801/// \brief Multiplies x and y using matrix math.
802/// \param x [in] The first input value. If x is a vector, it is treated as a
803/// row vector.
804/// \param y [in] The second input value. If y is a vector, it is treated as a
805/// column vector.
806///
807/// The inner dimension x-columns and y-rows must be equal. The result has the
808/// dimension x-rows x y-columns. When both x and y are vectors, the result is
809/// a dot product (scalar). Scalar operands are multiplied element-wise.
810///
811/// This function supports 9 overloaded forms:
812/// 1. scalar * scalar -> scalar
813/// 2. scalar * vector -> vector
814/// 3. scalar * matrix -> matrix
815/// 4. vector * scalar -> vector
816/// 5. vector * vector -> scalar (dot product)
817/// 6. vector * matrix -> vector
818/// 7. matrix * scalar -> matrix
819/// 8. matrix * vector -> vector
820/// 9. matrix * matrix -> matrix
821
822// Cases 1, 2, 3, 4, 5, and 7 of mul are defined below as
823// header-only implementations because they are elementwise operations and dot
824// products easily expressed in HLSL.
825
826// Cases 6, 8, and 9 are defined in hlsl_alias_intrinsics.h to alias the mul
827// builtin so that they can be lowered to the llvm.matrix.multiply intrinsic
828// which is not exposed directly to HLSL.
829
830// Case 1: scalar * scalar -> scalar
831template <typename T>
832_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
833constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
834 __detail::is_same<half, T>::value,
835 T> mul(T x, T y) {
836 return x * y;
837}
838
839template <typename T>
840constexpr __detail::enable_if_t<
842mul(T x, T y) {
843 return x * y;
844}
845
846// Case 2: scalar * vector -> vector
847template <int N>
848_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
849constexpr vector<half, N> mul(half x, vector<half, N> y) {
850 return x * y;
851}
852
853template <typename T, int N> constexpr vector<T, N> mul(T x, vector<T, N> y) {
854 return x * y;
855}
856
857// Case 3: scalar * matrix -> matrix
858template <int R, int C>
859_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
860constexpr matrix<half, R, C> mul(half x, matrix<half, R, C> y) {
861 return x * y;
862}
863
864template <typename T, int R, int C>
865constexpr matrix<T, R, C> mul(T x, matrix<T, R, C> y) {
866 return x * y;
867}
868
869// Case 4: vector * scalar -> vector
870template <int N>
871_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
872constexpr vector<half, N> mul(vector<half, N> x, half y) {
873 return x * y;
874}
875
876template <typename T, int N> constexpr vector<T, N> mul(vector<T, N> x, T y) {
877 return x * y;
878}
879
880// Case 5: vector * vector -> scalar (dot product)
881template <int N>
882_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
883half mul(vector<half, N> x, vector<half, N> y) {
884 return __detail::mul_vec_impl(x, y);
885}
886
887template <typename T, int N> T mul(vector<T, N> x, vector<T, N> y) {
888 return __detail::mul_vec_impl(x, y);
889}
890
891// Case 7: matrix * scalar -> matrix
892template <int R, int C>
893_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
894constexpr matrix<half, R, C> mul(matrix<half, R, C> x, half y) {
895 return x * y;
896}
897
898template <typename T, int R, int C>
899constexpr matrix<T, R, C> mul(matrix<T, R, C> x, T y) {
900 return x * y;
901}
902
903} // namespace hlsl
904#endif //_HLSL_HLSL_INTRINSICS_H_
#define V(N, I)
#define X(type, name)
Definition Value.h:97
#define _HLSL_BUILTIN_ALIAS(builtin)
#define _HLSL_AVAILABILITY(platform, version)
#define _HLSL_16BIT_AVAILABILITY(environment, version)
constexpr vector< T, N > smoothstep_vec_impl(vector< T, N > Min, vector< T, N > Max, vector< T, N > X)
constexpr T length_impl(T X)
constexpr vector< T, 4 > dst_impl(vector< T, 4 > Src0, vector< T, 4 > Src1)
constexpr T faceforward_impl(T N, T I, T Ng)
constexpr T fwidth_impl(T input)
constexpr vector< T, L > reflect_vec_impl(vector< T, L > I, vector< T, L > N)
constexpr T distance_impl(T X, T Y)
constexpr K firstbithigh_impl(T X)
constexpr T reflect_impl(T I, T N)
constexpr T ldexp_impl(T X, T Exp)
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > distance_vec_impl(vector< T, N > X, vector< T, N > Y)
constexpr T fmod_impl(T X, T Y)
typename enable_if< B, T >::Type enable_if_t
Definition hlsl_detail.h:31
constexpr T ddx_impl(T input)
constexpr int4 d3d_color_to_ubyte4_impl(float4 V)
constexpr T smoothstep_impl(T Min, T Max, T X)
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > length_vec_impl(vector< T, N > X)
constexpr T refract_impl(T I, T N, U Eta)
constexpr float dot2add_impl(half2 a, half2 b, float c)
vector< __detail::enable_if_t<(N > 1 &&N<=4), T >, N > HLSL_FIXED_VECTOR
Definition hlsl_detail.h:49
constexpr vector< T, N > fmod_vec_impl(vector< T, N > X, vector< T, N > Y)
constexpr enable_if_t< sizeof(U)==sizeof(T), vector< U, N > > bit_cast(vector< T, N > V)
Definition hlsl_detail.h:35
constexpr T ddy_impl(T input)
constexpr vector< T, 4 > lit_impl(T NDotL, T NDotH, T M)
constexpr enable_if_t<!is_same< double, T >::value, T > mul_vec_impl(vector< T, N > x, vector< T, N > y)
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_mul) vector< half
unsigned int uint
An unsigned 32-bit integer.
vector< half, 4 > half4
constexpr int4 D3DCOLORtoUBYTE4(float4 V)
constexpr uint32_t NonUniformResourceIndex(uint32_t Index)
A compiler hint to indicate that a resource index varies across threads within a wave (i....
vector< half, 2 > half2
vector< uint, 2 > uint2
bool CheckAccessFullyMapped(uint Status)
vector< float, 4 > float4
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > smoothstep(T Min, T Max, T X)
Returns a smooth Hermite interpolation between 0 and 1, if X is in the range [Min,...
C mul(vector< half, R >, matrix< half, R, C >)
const half4 lit(half NDotL, half NDotH, half M)
const __detail::enable_if_t< __detail::is_same< int, T >::value||__detail::is_same< uint, T >::value, uint > firstbithigh(T X)
Returns the location of the first set bit starting from the lowest order bit and working upward,...
vector< int, 4 > int4
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > fwidth(T input)
Computes the sum of the absolute values of the partial derivatives with regard to the x and y screen ...
constexpr vector< uint, N > asuint(vector< T, N > V)
vector< double, 3 > double3
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > refract(T I, T N, T eta)
Returns a refraction using an entering ray, I, a surface normal, N and refraction index eta.
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > length(T X)
Returns the length of the specified floating-point vector.
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > ldexp(T X, T Exp)
Returns the result of multiplying the specified value by two raised to the power of the specified exp...
vector< uint, 3 > uint3
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > reflect(T I, T N)
Returns a reflection using an incident ray, I, and a surface normal, N.
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > distance(T X, T Y)
Returns a distance scalar between X and Y.
vector< double, 4 > double4
vector< double, 2 > double2
unsigned int uint32_t
vector< uint, 4 > uint4
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > faceforward(T N, T I, T Ng)
Flips the surface-normal (if needed) to face in a direction opposite to I.
const half4 dst(half4 Src0, half4 Src1)
constexpr vector< int, N > asint(vector< T, N > V)
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > fmod(T X, T Y)
Returns the linear interpolation of x to y.
constexpr vector< float, N > asfloat(vector< T, N > V)
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > ddy(T input)
Computes the sum of the absolute values of the partial derivatives with regard to the y screen space ...
const __detail::enable_if_t< __detail::is_arithmetic< T >::Value &&__detail::is_same< half, T >::value, T > ddx(T input)
Computes the sum of the absolute values of the partial derivatives with regard to the x screen space ...
const float dot2add(half2 A, half2 B, float C)
Dot product of 2 vector of type half and add a float scalar value.
static const bool value
Definition hlsl_detail.h:17
#define ldexp(__x, __y)
Definition tgmath.h:868
#define fmod(__x, __y)
Definition tgmath.h:798