Skip to content

Commit 2a7953e

Browse files
committed
Fully implemented intrinsics.hlsl
1 parent 75bec97 commit 2a7953e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ template<typename Integer>
2323
int bitCount(NBL_CONST_REF_ARG(Integer) val)
2424
{
2525
#ifdef __HLSL_VERSION
26-
26+
return countbits(val);
2727
#else
2828
return glm::bitCount(val);
2929
#endif
@@ -33,7 +33,7 @@ template<typename T>
3333
vector<T, 3> cross(NBL_CONST_REF_ARG(vector<T, 3>) lhs, NBL_CONST_REF_ARG(vector<T, 3>) rhs)
3434
{
3535
#ifdef __HLSL_VERSION
36-
36+
return spirv::cross(lhs, rhs);
3737
#else
3838
return glm::cross(lhs, rhs);
3939
#endif
@@ -43,7 +43,7 @@ template<typename T>
4343
T clamp(NBL_CONST_REF_ARG(T) val, NBL_CONST_REF_ARG(T) min, NBL_CONST_REF_ARG(T) max)
4444
{
4545
#ifdef __HLSL_VERSION
46-
46+
return clamp(val, min, max);
4747
#else
4848
return glm::clamp(val, min, max);
4949
#endif
@@ -185,7 +185,7 @@ template<typename T, uint16_t N, uint16_t M>
185185
inline matrix<T, N, M> inverse(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
186186
{
187187
#ifdef __HLSL_VERSION
188-
188+
return spirv::matrixInverse(m);
189189
#else
190190
return reinterpret_cast<matrix<T, N, M>&>(glm::inverse(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
191191
#endif
@@ -195,7 +195,7 @@ template<typename T, typename U>
195195
inline T lerp(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)
196196
{
197197
#ifdef __HLSL_VERSION
198-
198+
return spirv::fMix(x, y, a);
199199
#else
200200
if constexpr (std::is_same_v<U, bool>)
201201
return a ? y : x;
@@ -220,7 +220,7 @@ template<typename T, uint16_t N, uint16_t M>
220220
inline matrix<T, M, N> transpose(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
221221
{
222222
#ifdef __HLSL_VERSION
223-
223+
return spirv::transpose(m);
224224
#else
225225
return reinterpret_cast<matrix<T, M, N>&>(glm::transpose(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
226226
#endif

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ template<typename FloatingPoint>
258258
[[vk::ext_instruction( spv::OpIsInf )]]
259259
enable_if_t<is_floating_point_v<FloatingPoint>, bool> isInf(FloatingPoint val);
260260

261+
template<typename Matrix>
262+
[[vk::ext_instruction( spv::OpTranspose )]]
263+
Matrix transpose(NBL_CONST_REF_ARG(Matrix) mat);
264+
261265
}
262266

263267
#endif

include/nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ template<typename FloatingPoint>
3838
[[vk::ext_instruction(GLSLstd450::GLSLstd450Floor, "GLSL.std.450")]]
3939
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> floor(FloatingPoint val);
4040

41+
template<typename FloatingPoint>
42+
[[vk::ext_instruction(GLSLstd450::GLSLstd450Cross, "GLSL.std.450")]]
43+
enable_if_t<is_floating_point_v<FloatingPoint>, vector<FloatingPoint, 3> > cross(in vector<FloatingPoint, 3> lhs, in vector<FloatingPoint, 3> rhs);
44+
45+
template<typename FloatingPoint>
46+
[[vk::ext_instruction(GLSLstd450::GLSLstd450FMix, "GLSL.std.450")]]
47+
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fMix(FloatingPoint val);
48+
49+
template<typename SquareMatrix>
50+
[[vk::ext_instruction(GLSLstd450::GLSLstd450Determinant, "GLSL.std.450")]]
51+
SquareMatrix determinant(in SquareMatrix mat);
52+
4153
}
4254
}
4355
}

0 commit comments

Comments
 (0)