Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp compat intrinsics refactor #801

Merged
merged 21 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ template<typename Integer>
int bitCount(NBL_CONST_REF_ARG(Integer) val)
{
#ifdef __HLSL_VERSION

return countbits(val);
#else
return glm::bitCount(val);
#endif
Expand All @@ -33,7 +33,7 @@ template<typename T>
vector<T, 3> cross(NBL_CONST_REF_ARG(vector<T, 3>) lhs, NBL_CONST_REF_ARG(vector<T, 3>) rhs)
{
#ifdef __HLSL_VERSION

return spirv::cross(lhs, rhs);
#else
return glm::cross(lhs, rhs);
#endif
Expand All @@ -43,7 +43,7 @@ template<typename T>
T clamp(NBL_CONST_REF_ARG(T) val, NBL_CONST_REF_ARG(T) min, NBL_CONST_REF_ARG(T) max)
{
#ifdef __HLSL_VERSION

return clamp(val, min, max);
#else
return glm::clamp(val, min, max);
#endif
Expand Down Expand Up @@ -185,7 +185,7 @@ template<typename T, uint16_t N, uint16_t M>
inline matrix<T, N, M> inverse(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
{
#ifdef __HLSL_VERSION

return spirv::matrixInverse(m);
#else
return reinterpret_cast<matrix<T, N, M>&>(glm::inverse(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
#endif
Expand All @@ -195,7 +195,7 @@ template<typename T, typename U>
inline T lerp(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y, NBL_CONST_REF_ARG(U) a)
{
#ifdef __HLSL_VERSION

return spirv::fMix(x, y, a);
#else
if constexpr (std::is_same_v<U, bool>)
return a ? y : x;
Expand All @@ -220,7 +220,7 @@ template<typename T, uint16_t N, uint16_t M>
inline matrix<T, M, N> transpose(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
{
#ifdef __HLSL_VERSION

return spirv::transpose(m);
#else
return reinterpret_cast<matrix<T, M, N>&>(glm::transpose(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ template<typename FloatingPoint>
[[vk::ext_instruction( spv::OpIsInf )]]
enable_if_t<is_floating_point_v<FloatingPoint>, bool> isInf(FloatingPoint val);

template<typename Matrix>
[[vk::ext_instruction( spv::OpTranspose )]]
Matrix transpose(NBL_CONST_REF_ARG(Matrix) mat);

}

#endif
Expand Down
12 changes: 12 additions & 0 deletions include/nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ template<typename FloatingPoint>
[[vk::ext_instruction(GLSLstd450::GLSLstd450Floor, "GLSL.std.450")]]
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> floor(FloatingPoint val);

template<typename FloatingPoint>
[[vk::ext_instruction(GLSLstd450::GLSLstd450Cross, "GLSL.std.450")]]
enable_if_t<is_floating_point_v<FloatingPoint>, vector<FloatingPoint, 3> > cross(in vector<FloatingPoint, 3> lhs, in vector<FloatingPoint, 3> rhs);

template<typename FloatingPoint>
[[vk::ext_instruction(GLSLstd450::GLSLstd450FMix, "GLSL.std.450")]]
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fMix(FloatingPoint val);

template<typename SquareMatrix>
[[vk::ext_instruction(GLSLstd450::GLSLstd450Determinant, "GLSL.std.450")]]
SquareMatrix determinant(in SquareMatrix mat);

}
}
}
Expand Down