9#ifndef _HLSL_HLSL_INTRINSIC_HELPERS_H_
10#define _HLSL_HLSL_INTRINSIC_HELPERS_H_
23 return V.zyxw * 255.001953f;
28template <
typename T,
int N>
31#if (__has_builtin(__builtin_spirv_length))
32 return __builtin_spirv_length(
X);
39constexpr vector<T, 4>
dst_impl(vector<T, 4> Src0, vector<T, 4> Src1) {
40 return {1, Src0[1] * Src1[1], Src0[2], Src1[3]};
47template <
typename T,
int N>
54#if (__has_builtin(__builtin_dx_dot2add))
55 return __builtin_dx_dot2add(a,
b,
c);
62 return I - 2 * N * I * N;
65template <
typename T,
int L>
67#if (__has_builtin(__builtin_spirv_reflect))
68 return __builtin_spirv_reflect(I, N);
70 return I - 2 * N *
dot(I, N);
74template <
typename T,
typename U>
constexpr T
refract_impl(T I, T N,
U Eta) {
75#if (__has_builtin(__builtin_spirv_refract))
76 return __builtin_spirv_refract(I, N, Eta);
79 T K = 1 - Eta * Eta * (1 - Mul * Mul);
80 T Result = (Eta * I - (Eta * Mul +
sqrt(K)) * N);
81 return select<T>(K < 0,
static_cast<T
>(0), Result);
85#if !defined(__DIRECTX__)
86 return __builtin_elementwise_fmod(
X, Y);
95template <
typename T,
int N>
97#if !defined(__DIRECTX__)
98 return __builtin_elementwise_fmod(
X, Y);
100 vector<T, N> div =
X / Y;
101 vector<bool, N> ge = div >= 0;
102 vector<T, N> frc =
frac(
abs(div));
108#if (__has_builtin(__builtin_spirv_smoothstep))
109 return __builtin_spirv_smoothstep(Min, Max,
X);
112 return (3 - 2 * S) * S * S;
116template <
typename T,
int N>
119#if (__has_builtin(__builtin_spirv_smoothstep))
120 return __builtin_spirv_smoothstep(Min, Max,
X);
122 vector<T, N> S =
saturate((
X - Min) / (Max - Min));
123 return (3 - 2 * S) * S * S;
127template <
typename T>
constexpr vector<T, 4>
lit_impl(T NDotL, T NDotH, T M) {
128 bool DiffuseCond = NDotL < 0;
129 T Diffuse =
select<T>(DiffuseCond, 0, NDotL);
130 vector<T, 4> Result = {1, Diffuse, 0, 1};
132 bool SpecularCond =
or(DiffuseCond, (NDotH < 0));
134 T SpecularExp =
exp(
log(NDotH) * M);
135 Result[2] =
select<T>(SpecularCond, 0, SpecularExp);
140#if (__has_builtin(__builtin_spirv_faceforward))
141 return __builtin_spirv_faceforward(N, I, Ng);
148 return exp2(Exp) *
X;
__device__ __2f16 float c
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 vector< T, L > reflect_vec_impl(vector< T, L > I, vector< T, L > N)
constexpr T distance_impl(T X, T Y)
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)
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)
constexpr vector< T, N > fmod_vec_impl(vector< T, N > X, vector< T, N > Y)
constexpr vector< T, 4 > lit_impl(T NDotL, T NDotH, T M)
T select(bool, T, T)
ternary operator.
vector< float, 4 > float4