Debian Codegraph @

clang/lib/Headers/hlsl/hlsl_intrinsics.h

raw
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
12 #include "hlsl/hlsl_intrinsic_helpers.h"
13
14 namespace hlsl {
15
16 //===----------------------------------------------------------------------===//
17 // asfloat builtins
18 //===----------------------------------------------------------------------===//
19
20 /// \fn float asfloat(T Val)
21 /// \brief Interprets the bit pattern of x as float point number.
22 /// \param Val The input value.
23
24 template <typename T, int N>
25 constexpr vector<float, N> asfloat(vector<T, N> V) {
26 return __detail::bit_cast<float, T, N>(V);
27 }
28
29 template <typename T> constexpr float asfloat(T F) {
30 return __detail::bit_cast<float, T>(F);
31 }
32
33 //===----------------------------------------------------------------------===//
34 // asint builtins
35 //===----------------------------------------------------------------------===//
36
37 /// \fn int asint(T Val)
38 /// \brief Interprets the bit pattern of x as an integer.
39 /// \param Val The input value.
40
41 template <typename T, int N> constexpr vector<int, N> asint(vector<T, N> V) {
42 return __detail::bit_cast<int, T, N>(V);
43 }
44
45 template <typename T> constexpr int asint(T F) {
46 return __detail::bit_cast<int, T>(F);
47 }
48
49 //===----------------------------------------------------------------------===//
50 // asint16 builtins
51 //===----------------------------------------------------------------------===//
52
53 /// \fn int16_t asint16(T X)
54 /// \brief Interprets the bit pattern of \a X as an 16-bit integer.
55 /// \param X The input value.
56
57 #ifdef __HLSL_ENABLE_16_BIT
58
59 template <typename T, int N>
60 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
61 constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
62 __detail::is_same<uint16_t, T>::value ||
63 __detail::is_same<half, T>::value,
64 vector<int16_t, N>> asint16(vector<T, N> V) {
65 return __detail::bit_cast<int16_t, T, N>(V);
66 }
67
68 template <typename T>
69 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
70 constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
71 __detail::is_same<uint16_t, T>::value ||
72 __detail::is_same<half, T>::value,
73 int16_t> asint16(T F) {
74 return __detail::bit_cast<int16_t, T>(F);
75 }
76 #endif
77
78 //===----------------------------------------------------------------------===//
79 // asuint builtins
80 //===----------------------------------------------------------------------===//
81
82 /// \fn uint asuint(T Val)
83 /// \brief Interprets the bit pattern of x as an unsigned integer.
84 /// \param Val The input value.
85
86 template <typename T, int N> constexpr vector<uint, N> asuint(vector<T, N> V) {
87 return __detail::bit_cast<uint, T, N>(V);
88 }
89
90 template <typename T> constexpr uint asuint(T F) {
91 return __detail::bit_cast<uint, T>(F);
92 }
93
94 //===----------------------------------------------------------------------===//
95 // asuint splitdouble builtins
96 //===----------------------------------------------------------------------===//
97
98 /// \fn void asuint(double D, out uint lowbits, out int highbits)
99 /// \brief Split and interprets the lowbits and highbits of double D into uints.
100 /// \param D The input double.
101 /// \param lowbits The output lowbits of D.
102 /// \param highbits The output highbits of D.
103 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
104 void asuint(double, out uint, out uint);
105 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
106 void asuint(double2, out uint2, out uint2);
107 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
108 void asuint(double3, out uint3, out uint3);
109 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
110 void asuint(double4, out uint4, out uint4);
111
112 //===----------------------------------------------------------------------===//
113 // asuint16 builtins
114 //===----------------------------------------------------------------------===//
115
116 /// \fn uint16_t asuint16(T X)
117 /// \brief Interprets the bit pattern of \a X as an 16-bit unsigned integer.
118 /// \param X The input value.
119
120 #ifdef __HLSL_ENABLE_16_BIT
121
122 template <typename T, int N>
123 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
124 constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
125 __detail::is_same<uint16_t, T>::value ||
126 __detail::is_same<half, T>::value,
127 vector<uint16_t, N>> asuint16(vector<T, N> V) {
128 return __detail::bit_cast<uint16_t, T, N>(V);
129 }
130
131 template <typename T>
132 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
133 constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
134 __detail::is_same<uint16_t, T>::value ||
135 __detail::is_same<half, T>::value,
136 uint16_t> asuint16(T F) {
137 return __detail::bit_cast<uint16_t, T>(F);
138 }
139 #endif
140
141 //===----------------------------------------------------------------------===//
142 // distance builtins
143 //===----------------------------------------------------------------------===//
144
145 /// \fn K distance(T X, T Y)
146 /// \brief Returns a distance scalar between \a X and \a Y.
147 /// \param X The X input value.
148 /// \param Y The Y input value.
149
150 template <typename T>
151 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
152 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
153 __detail::is_same<half, T>::value,
154 T> distance(T X, T Y) {
155 return __detail::distance_impl(X, Y);
156 }
157
158 template <typename T>
159 const inline __detail::enable_if_t<
160 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
161 distance(T X, T Y) {
162 return __detail::distance_impl(X, Y);
163 }
164
165 template <int N>
166 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
167 const inline half distance(__detail::HLSL_FIXED_VECTOR<half, N> X,
168 __detail::HLSL_FIXED_VECTOR<half, N> Y) {
169 return __detail::distance_vec_impl(X, Y);
170 }
171
172 template <int N>
173 const inline float distance(__detail::HLSL_FIXED_VECTOR<float, N> X,
174 __detail::HLSL_FIXED_VECTOR<float, N> Y) {
175 return __detail::distance_vec_impl(X, Y);
176 }
177
178 //===----------------------------------------------------------------------===//
179 // dot2add builtins
180 //===----------------------------------------------------------------------===//
181
182 /// \fn float dot2add(half2 A, half2 B, float C)
183 /// \brief Dot product of 2 vector of type half and add a float scalar value.
184 /// \param A The first input value to dot product.
185 /// \param B The second input value to dot product.
186 /// \param C The input value added to the dot product.
187
188 _HLSL_AVAILABILITY(shadermodel, 6.4)
189 const inline float dot2add(half2 A, half2 B, float C) {
190 return __detail::dot2add_impl(A, B, C);
191 }
192
193 //===----------------------------------------------------------------------===//
194 // dst builtins
195 //===----------------------------------------------------------------------===//
196
197 /// \fn vector<T, 4> dst(vector<T, 4>, vector<T, 4>)
198 /// \brief Calculates a distance vector.
199 /// \param Src0 [in] Contains the squared distance
200 /// \param Src1 [in] Contains the reciprocal distance
201 ///
202 /// Return the computed distance vector
203
204 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
205 const inline half4 dst(half4 Src0, half4 Src1) {
206 return __detail::dst_impl(Src0, Src1);
207 }
208
209 const inline float4 dst(float4 Src0, float4 Src1) {
210 return __detail::dst_impl(Src0, Src1);
211 }
212
213 const inline double4 dst(double4 Src0, double4 Src1) {
214 return __detail::dst_impl(Src0, Src1);
215 }
216
217 //===----------------------------------------------------------------------===//
218 // faceforward builtin
219 //===----------------------------------------------------------------------===//
220
221 /// \fn T faceforward(T N, T I, T Ng)
222 /// \brief Flips the surface-normal (if needed) to face in a direction opposite
223 /// to \a I. Returns the result in terms of \a N.
224 /// \param N The resulting floating-point surface-normal vector.
225 /// \param I A floating-point, incident vector that points from the view
226 /// position to the shading position.
227 /// \param Ng A floating-point surface-normal vector.
228 ///
229 /// Return a floating-point, surface normal vector that is facing the view
230 /// direction.
231
232 template <typename T>
233 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
234 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
235 __detail::is_same<half, T>::value,
236 T> faceforward(T N, T I, T Ng) {
237 return __detail::faceforward_impl(N, I, Ng);
238 }
239
240 template <typename T>
241 const inline __detail::enable_if_t<
242 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
243 faceforward(T N, T I, T Ng) {
244 return __detail::faceforward_impl(N, I, Ng);
245 }
246
247 template <int L>
248 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
249 const inline __detail::HLSL_FIXED_VECTOR<half, L> faceforward(
250 __detail::HLSL_FIXED_VECTOR<half, L> N,
251 __detail::HLSL_FIXED_VECTOR<half, L> I,
252 __detail::HLSL_FIXED_VECTOR<half, L> Ng) {
253 return __detail::faceforward_impl(N, I, Ng);
254 }
255
256 template <int L>
257 const inline __detail::HLSL_FIXED_VECTOR<float, L>
258 faceforward(__detail::HLSL_FIXED_VECTOR<float, L> N,
259 __detail::HLSL_FIXED_VECTOR<float, L> I,
260 __detail::HLSL_FIXED_VECTOR<float, L> Ng) {
261 return __detail::faceforward_impl(N, I, Ng);
262 }
263
264 //===----------------------------------------------------------------------===//
265 // firstbithigh builtins
266 //===----------------------------------------------------------------------===//
267
268 /// \fn T firstbithigh(T Val)
269 /// \brief Returns the location of the first set bit starting from the lowest
270 /// order bit and working upward, per component.
271 /// \param Val the input value.
272
273 #ifdef __HLSL_ENABLE_16_BIT
274
275 template <typename T>
276 _HLSL_AVAILABILITY(shadermodel, 6.2)
277 const inline __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
278 __detail::is_same<uint16_t, T>::value,
279 uint> firstbithigh(T X) {
280 return __detail::firstbithigh_impl<uint, T, 16>(X);
281 }
282
283 template <typename T, int N>
284 _HLSL_AVAILABILITY(shadermodel, 6.2)
285 const
286 inline __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
287 __detail::is_same<uint16_t, T>::value,
288 vector<uint, N>> firstbithigh(vector<T, N> X) {
289 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 16>(X);
290 }
291
292 #endif
293
294 template <typename T>
295 const inline __detail::enable_if_t<
296 __detail::is_same<int, T>::value || __detail::is_same<uint, T>::value, uint>
297 firstbithigh(T X) {
298 return __detail::firstbithigh_impl<uint, T, 32>(X);
299 }
300
301 template <typename T, int N>
302 const inline __detail::enable_if_t<__detail::is_same<int, T>::value ||
303 __detail::is_same<uint, T>::value,
304 vector<uint, N>>
305 firstbithigh(vector<T, N> X) {
306 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 32>(X);
307 }
308
309 template <typename T>
310 const inline __detail::enable_if_t<__detail::is_same<int64_t, T>::value ||
311 __detail::is_same<uint64_t, T>::value,
312 uint>
313 firstbithigh(T X) {
314 return __detail::firstbithigh_impl<uint, T, 64>(X);
315 }
316
317 template <typename T, int N>
318 const inline __detail::enable_if_t<__detail::is_same<int64_t, T>::value ||
319 __detail::is_same<uint64_t, T>::value,
320 vector<uint, N>>
321 firstbithigh(vector<T, N> X) {
322 return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 64>(X);
323 }
324
325 //===----------------------------------------------------------------------===//
326 // fmod builtins
327 //===----------------------------------------------------------------------===//
328
329 /// \fn T fmod(T x, T y)
330 /// \brief Returns the linear interpolation of x to y.
331 /// \param x [in] The dividend.
332 /// \param y [in] The divisor.
333 ///
334 /// Return the floating-point remainder of the x parameter divided by the y
335 /// parameter.
336
337 template <typename T>
338 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
339 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
340 __detail::is_same<half, T>::value,
341 T> fmod(T X, T Y) {
342 return __detail::fmod_impl(X, Y);
343 }
344
345 template <typename T>
346 const inline __detail::enable_if_t<
347 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
348 fmod(T X, T Y) {
349 return __detail::fmod_impl(X, Y);
350 }
351
352 template <int N>
353 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
354 const inline __detail::HLSL_FIXED_VECTOR<half, N> fmod(
355 __detail::HLSL_FIXED_VECTOR<half, N> X,
356 __detail::HLSL_FIXED_VECTOR<half, N> Y) {
357 return __detail::fmod_vec_impl(X, Y);
358 }
359
360 template <int N>
361 const inline __detail::HLSL_FIXED_VECTOR<float, N>
362 fmod(__detail::HLSL_FIXED_VECTOR<float, N> X,
363 __detail::HLSL_FIXED_VECTOR<float, N> Y) {
364 return __detail::fmod_vec_impl(X, Y);
365 }
366
367 //===----------------------------------------------------------------------===//
368 // ldexp builtins
369 //===----------------------------------------------------------------------===//
370
371 /// \fn T ldexp(T X, T Exp)
372 /// \brief Returns the result of multiplying the specified value by two raised
373 /// to the power of the specified exponent.
374 /// \param X [in] The specified value.
375 /// \param Exp [in] The specified exponent.
376 ///
377 /// This function uses the following formula: X * 2^Exp
378
379 template <typename T>
380 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
381 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
382 __detail::is_same<half, T>::value,
383 T> ldexp(T X, T Exp) {
384 return __detail::ldexp_impl(X, Exp);
385 }
386
387 template <typename T>
388 const inline __detail::enable_if_t<
389 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
390 ldexp(T X, T Exp) {
391 return __detail::ldexp_impl(X, Exp);
392 }
393
394 template <int N>
395 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
396 const inline __detail::HLSL_FIXED_VECTOR<half, N> ldexp(
397 __detail::HLSL_FIXED_VECTOR<half, N> X,
398 __detail::HLSL_FIXED_VECTOR<half, N> Exp) {
399 return __detail::ldexp_impl(X, Exp);
400 }
401
402 template <int N>
403 const inline __detail::HLSL_FIXED_VECTOR<float, N>
404 ldexp(__detail::HLSL_FIXED_VECTOR<float, N> X,
405 __detail::HLSL_FIXED_VECTOR<float, N> Exp) {
406 return __detail::ldexp_impl(X, Exp);
407 }
408
409 //===----------------------------------------------------------------------===//
410 // length builtins
411 //===----------------------------------------------------------------------===//
412
413 /// \fn T length(T x)
414 /// \brief Returns the length of the specified floating-point vector.
415 /// \param x [in] The vector of floats, or a scalar float.
416 ///
417 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
418
419 template <typename T>
420 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
421 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
422 __detail::is_same<half, T>::value,
423 T> length(T X) {
424 return __detail::length_impl(X);
425 }
426
427 template <typename T>
428 const inline __detail::enable_if_t<
429 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
430 length(T X) {
431 return __detail::length_impl(X);
432 }
433
434 template <int N>
435 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
436 const inline half length(__detail::HLSL_FIXED_VECTOR<half, N> X) {
437 return __detail::length_vec_impl(X);
438 }
439
440 template <int N>
441 const inline float length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
442 return __detail::length_vec_impl(X);
443 }
444
445 //===----------------------------------------------------------------------===//
446 // lit builtins
447 //===----------------------------------------------------------------------===//
448
449 /// \fn vector<T, 4> lit(T NDotL, T NDotH, T M)
450 /// \brief Returns a lighting coefficient vector.
451 /// \param NDotL The dot product of the normalized surface normal and the
452 /// light vector.
453 /// \param NDotH The dot product of the half-angle vector and the surface
454 /// normal.
455 /// \param M A specular exponent.
456 ///
457 /// This function returns a lighting coefficient vector (ambient, diffuse,
458 /// specular, 1).
459
460 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
461 const inline half4 lit(half NDotL, half NDotH, half M) {
462 return __detail::lit_impl(NDotL, NDotH, M);
463 }
464
465 const inline float4 lit(float NDotL, float NDotH, float M) {
466 return __detail::lit_impl(NDotL, NDotH, M);
467 }
468
469 //===----------------------------------------------------------------------===//
470 // D3DCOLORtoUBYTE4 builtin
471 //===----------------------------------------------------------------------===//
472
473 /// \fn T D3DCOLORtoUBYTE4(T x)
474 /// \brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
475 /// \param x [in] The floating-point vector4 to convert.
476 ///
477 /// The return value is the UBYTE4 representation of the \a x parameter.
478 ///
479 /// This function swizzles and scales components of the \a x parameter. Use this
480 /// function to compensate for the lack of UBYTE4 support in some hardware.
481
482 constexpr int4 D3DCOLORtoUBYTE4(float4 V) {
483 return __detail::d3d_color_to_ubyte4_impl(V);
484 }
485
486 //===----------------------------------------------------------------------===//
487 // NonUniformResourceIndex builtin
488 //===----------------------------------------------------------------------===//
489
490 /// \fn uint NonUniformResourceIndex(uint I)
491 /// \brief A compiler hint to indicate that a resource index varies across
492 /// threads within a wave (i.e., it is non-uniform).
493 /// \param I [in] Resource array index
494 ///
495 /// The return value is the \Index parameter.
496 ///
497 /// When indexing into an array of shader resources (e.g., textures, buffers),
498 /// some GPU hardware and drivers require the compiler to know whether the index
499 /// is uniform (same for all threads) or non-uniform (varies per thread).
500 ///
501 /// Using NonUniformResourceIndex explicitly marks an index as non-uniform,
502 /// disabling certain assumptions or optimizations that could lead to incorrect
503 /// behavior when dynamically accessing resource arrays with non-uniform
504 /// indices.
505
506 constexpr uint32_t NonUniformResourceIndex(uint32_t Index) {
507 return __builtin_hlsl_resource_nonuniformindex(Index);
508 }
509
510 //===----------------------------------------------------------------------===//
511 // reflect builtin
512 //===----------------------------------------------------------------------===//
513
514 /// \fn T reflect(T I, T N)
515 /// \brief Returns a reflection using an incident ray, \a I, and a surface
516 /// normal, \a N.
517 /// \param I The incident ray.
518 /// \param N The surface normal.
519 ///
520 /// The return value is a floating-point vector that represents the reflection
521 /// of the incident ray, \a I, off a surface with the normal \a N.
522 ///
523 /// This function calculates the reflection vector using the following formula:
524 /// V = I - 2 * N * dot(I N) .
525 ///
526 /// N must already be normalized in order to achieve the desired result.
527 ///
528 /// The operands must all be a scalar or vector whose component type is
529 /// floating-point.
530 ///
531 /// Result type and the type of all operands must be the same type.
532
533 template <typename T>
534 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
535 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
536 __detail::is_same<half, T>::value,
537 T> reflect(T I, T N) {
538 return __detail::reflect_impl(I, N);
539 }
540
541 template <typename T>
542 const inline __detail::enable_if_t<
543 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
544 reflect(T I, T N) {
545 return __detail::reflect_impl(I, N);
546 }
547
548 template <int L>
549 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
550 const inline __detail::HLSL_FIXED_VECTOR<half, L> reflect(
551 __detail::HLSL_FIXED_VECTOR<half, L> I,
552 __detail::HLSL_FIXED_VECTOR<half, L> N) {
553 return __detail::reflect_vec_impl(I, N);
554 }
555
556 template <int L>
557 const inline __detail::HLSL_FIXED_VECTOR<float, L>
558 reflect(__detail::HLSL_FIXED_VECTOR<float, L> I,
559 __detail::HLSL_FIXED_VECTOR<float, L> N) {
560 return __detail::reflect_vec_impl(I, N);
561 }
562
563 //===----------------------------------------------------------------------===//
564 // refract builtin
565 //===----------------------------------------------------------------------===//
566
567 /// \fn T refract(T I, T N, T eta)
568 /// \brief Returns a refraction using an entering ray, \a I, a surface
569 /// normal, \a N and refraction index \a eta
570 /// \param I The entering ray.
571 /// \param N The surface normal.
572 /// \param eta The refraction index.
573 ///
574 /// The return value is a floating-point vector that represents the refraction
575 /// using the refraction index, \a eta, for the direction of the entering ray,
576 /// \a I, off a surface with the normal \a N.
577 ///
578 /// This function calculates the refraction vector using the following formulas:
579 /// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
580 /// if k < 0.0 the result is 0.0
581 /// otherwise, the result is eta * I - (eta * dot(N, I) + sqrt(k)) * N
582 ///
583 /// I and N must already be normalized in order to achieve the desired result.
584 ///
585 /// I and N must be a scalar or vector whose component type is
586 /// floating-point.
587 ///
588 /// eta must be a 16-bit or 32-bit floating-point scalar.
589 ///
590 /// Result type, the type of I, and the type of N must all be the same type.
591
592 template <typename T>
593 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
594 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
595 __detail::is_same<half, T>::value,
596 T> refract(T I, T N, T eta) {
597 return __detail::refract_impl(I, N, eta);
598 }
599
600 template <typename T>
601 const inline __detail::enable_if_t<
602 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
603 refract(T I, T N, T eta) {
604 return __detail::refract_impl(I, N, eta);
605 }
606
607 template <int L>
608 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
609 const inline __detail::HLSL_FIXED_VECTOR<half, L> refract(
610 __detail::HLSL_FIXED_VECTOR<half, L> I,
611 __detail::HLSL_FIXED_VECTOR<half, L> N, half eta) {
612 return __detail::refract_impl(I, N, eta);
613 }
614
615 template <int L>
616 const inline __detail::HLSL_FIXED_VECTOR<float, L>
617 refract(__detail::HLSL_FIXED_VECTOR<float, L> I,
618 __detail::HLSL_FIXED_VECTOR<float, L> N, float eta) {
619 return __detail::refract_impl(I, N, eta);
620 }
621
622 //===----------------------------------------------------------------------===//
623 // smoothstep builtin
624 //===----------------------------------------------------------------------===//
625
626 /// \fn T smoothstep(T Min, T Max, T X)
627 /// \brief Returns a smooth Hermite interpolation between 0 and 1, if \a X is in
628 /// the range [\a Min, \a Max].
629 /// \param Min The minimum range of the x parameter.
630 /// \param Max The maximum range of the x parameter.
631 /// \param X The specified value to be interpolated.
632 ///
633 /// The return value is 0.0 if \a X ≤ \a Min and 1.0 if \a X ≥ \a Max. When \a
634 /// Min < \a X < \a Max, the function performs smooth Hermite interpolation
635 /// between 0 and 1.
636
637 template <typename T>
638 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
639 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
640 __detail::is_same<half, T>::value,
641 T> smoothstep(T Min, T Max, T X) {
642 return __detail::smoothstep_impl(Min, Max, X);
643 }
644
645 template <typename T>
646 const inline __detail::enable_if_t<
647 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
648 smoothstep(T Min, T Max, T X) {
649 return __detail::smoothstep_impl(Min, Max, X);
650 }
651
652 template <int N>
653 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
654 const inline __detail::HLSL_FIXED_VECTOR<half, N> smoothstep(
655 __detail::HLSL_FIXED_VECTOR<half, N> Min,
656 __detail::HLSL_FIXED_VECTOR<half, N> Max,
657 __detail::HLSL_FIXED_VECTOR<half, N> X) {
658 return __detail::smoothstep_vec_impl(Min, Max, X);
659 }
660
661 template <int N>
662 const inline __detail::HLSL_FIXED_VECTOR<float, N>
663 smoothstep(__detail::HLSL_FIXED_VECTOR<float, N> Min,
664 __detail::HLSL_FIXED_VECTOR<float, N> Max,
665 __detail::HLSL_FIXED_VECTOR<float, N> X) {
666 return __detail::smoothstep_vec_impl(Min, Max, X);
667 }
668
669 inline bool CheckAccessFullyMapped(uint Status) {
670 return static_cast<bool>(Status);
671 }
672
673 //===----------------------------------------------------------------------===//
674 // ddx builtin
675 //===----------------------------------------------------------------------===//
676
677 /// \fn T ddx(T x)
678 /// \brief Computes the sum of the absolute values of the partial derivatives
679 /// with regard to the x screen space coordinate.
680 /// \param x [in] The floating-point scalar or vector to process.
681 ///
682 /// The return value is a floating-point scalar or vector where each element
683 /// holds the computation of the matching element in the input.
684
685 template <typename T>
686 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
687 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
688 __detail::is_same<half, T>::value,
689 T> ddx(T input) {
690 return __detail::ddx_impl(input);
691 }
692
693 template <typename T>
694 const inline __detail::enable_if_t<
695 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
696 ddx(T input) {
697 return __detail::ddx_impl(input);
698 }
699
700 template <int N>
701 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
702 const inline __detail::HLSL_FIXED_VECTOR<half, N> ddx(
703 __detail::HLSL_FIXED_VECTOR<half, N> input) {
704 return __detail::ddx_impl(input);
705 }
706
707 template <int N>
708 const inline __detail::HLSL_FIXED_VECTOR<float, N>
709 ddx(__detail::HLSL_FIXED_VECTOR<float, N> input) {
710 return __detail::ddx_impl(input);
711 }
712
713 //===----------------------------------------------------------------------===//
714 // ddy builtin
715 //===----------------------------------------------------------------------===//
716
717 /// \fn T ddy(T x)
718 /// \brief Computes the sum of the absolute values of the partial derivatives
719 /// with regard to the y screen space coordinate.
720 /// \param x [in] The floating-point scalar or vector to process.
721 ///
722 /// The return value is a floating-point scalar or vector where each element
723 /// holds the computation of the matching element in the input.
724
725 template <typename T>
726 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
727 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
728 __detail::is_same<half, T>::value,
729 T> ddy(T input) {
730 return __detail::ddy_impl(input);
731 }
732
733 template <typename T>
734 const inline __detail::enable_if_t<
735 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
736 ddy(T input) {
737 return __detail::ddy_impl(input);
738 }
739
740 template <int N>
741 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
742 const inline __detail::HLSL_FIXED_VECTOR<half, N> ddy(
743 __detail::HLSL_FIXED_VECTOR<half, N> input) {
744 return __detail::ddy_impl(input);
745 }
746
747 template <int N>
748 const inline __detail::HLSL_FIXED_VECTOR<float, N>
749 ddy(__detail::HLSL_FIXED_VECTOR<float, N> input) {
750 return __detail::ddy_impl(input);
751 }
752
753 //===----------------------------------------------------------------------===//
754 // fwidth builtin
755 //===----------------------------------------------------------------------===//
756
757 /// \fn T fwidth(T x)
758 /// \brief Computes the sum of the absolute values of the partial derivatives
759 /// with regard to the x and y screen space coordinates.
760 /// \param x [in] The floating-point scalar or vector to process.
761 ///
762 /// The return value is a floating-point scalar or vector where each element
763 /// holds the computation of the matching element in the input.
764
765 template <typename T>
766 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
767 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
768 __detail::is_same<half, T>::value,
769 T> fwidth(T input) {
770 return __detail::fwidth_impl(input);
771 }
772
773 template <typename T>
774 const inline __detail::enable_if_t<
775 __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
776 fwidth(T input) {
777 return __detail::fwidth_impl(input);
778 }
779
780 template <int N>
781 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
782 const inline __detail::HLSL_FIXED_VECTOR<half, N> fwidth(
783 __detail::HLSL_FIXED_VECTOR<half, N> input) {
784 return __detail::fwidth_impl(input);
785 }
786
787 template <int N>
788 const inline __detail::HLSL_FIXED_VECTOR<float, N>
789 fwidth(__detail::HLSL_FIXED_VECTOR<float, N> input) {
790 return __detail::fwidth_impl(input);
791 }
792
793 } // namespace hlsl
794 #endif //_HLSL_HLSL_INTRINSICS_H_