Skip to content

Commit 99b478b

Browse files
committed
Moved every GLSL.std.450 intrinsic spriv function from spriv_intrinsics/core.hlsl to spirv_intrinsics/GLSL.std.450.hlsl
1 parent fc9b4d4 commit 99b478b

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,21 @@ inline T floor(NBL_CONST_REF_ARG(T) val)
190190

191191
}
192192

193+
// TODO: for clearer error messages, use concepts to ensure that input type is a square matrix
193194
// inverse not defined cause its implemented via hidden friend
194-
template<typename T, uint16_t N, uint16_t M>
195-
inline matrix<T, N, M> inverse(NBL_CONST_REF_ARG(matrix<T, N, M>) m)
195+
template<typename T, uint16_t N>
196+
inline matrix<T, N, N> inverse(NBL_CONST_REF_ARG(matrix<T, N, N>) m)
196197
{
197198
#ifdef __HLSL_VERSION
198199
return spirv::matrixInverse(m);
199200
#else
200-
return reinterpret_cast<matrix<T, N, M>&>(glm::inverse(reinterpret_cast<typename matrix<T, N, M>::Base const&>(m)));
201+
return reinterpret_cast<matrix<T, N, N>&>(glm::inverse(reinterpret_cast<typename matrix<T, N, N>::Base const&>(m)));
201202
#endif
202203
}
203204

204205
namespace cpp_compat_intrinsics_impl
205206
{
206-
207-
// TODO: concept requiring T to be a float
207+
// TODO: concept requiring T to be a float when U is not bool
208208
template<typename T, typename U>
209209
struct lerp_helper
210210
{

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#ifdef __HLSL_VERSION // TODO: AnastZIuk fix public search paths so we don't choke
99
#include "spirv/unified1/spirv.hpp"
10-
#include "spirv/unified1/GLSL.std.450.h"
1110
#endif
1211

1312
#include "nbl/builtin/hlsl/type_traits.hlsl"
@@ -188,21 +187,6 @@ template<typename T, typename P>
188187
[[vk::ext_instruction(spv::OpStore)]]
189188
enable_if_t<is_spirv_type_v<P>,void> store(P pointer, T obj);
190189

191-
//! Std 450 Extended set operations
192-
193-
template<typename SquareMatrix>
194-
[[vk::ext_instruction(GLSLstd450MatrixInverse, "GLSL.std.450")]]
195-
SquareMatrix matrixInverse(NBL_CONST_REF_ARG(SquareMatrix) mat);
196-
197-
[[vk::ext_instruction(GLSLstd450UnpackSnorm2x16, "GLSL.std.450")]]
198-
float32_t2 unpackSnorm2x16(uint32_t p);
199-
200-
[[vk::ext_instruction(GLSLstd450UnpackSnorm4x8, "GLSL.std.450")]]
201-
float32_t4 unpackSnorm4x8(uint32_t p);
202-
203-
[[vk::ext_instruction(GLSLstd450UnpackUnorm4x8, "GLSL.std.450")]]
204-
float32_t4 unpackUnorm4x8(uint32_t p);
205-
206190
// Memory Semantics link here: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Semantics_-id-
207191

208192
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_memory_semantics_id

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ namespace spirv
1313
{
1414

1515
// Find MSB and LSB restricted to 32-bit width component types https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html
16-
1716
template<typename Integral>
1817
[[vk::ext_instruction(GLSLstd450::GLSLstd450FindILsb, "GLSL.std.450")]]
19-
enable_if_t<is_integral_v<Integral> && (sizeof(scalar_type_t<Integral>) == 4), Integral> findILsb(Integral value);
18+
enable_if_t<is_integral_v<Integral> && (sizeof(scalar_type_t<Integral>) == 4 && !is_matrix_v<Integral>), Integral> findILsb(Integral value);
2019

2120
[[vk::ext_instruction(GLSLstd450::GLSLstd450FindSMsb, "GLSL.std.450")]]
2221
int32_t findSMsb(int32_t value);
@@ -26,28 +25,41 @@ uint32_t findUMsb(uint32_t value);
2625

2726
template<typename FloatingPoint>
2827
[[vk::ext_instruction(GLSLstd450::GLSLstd450Exp2, "GLSL.std.450")]]
29-
enable_if_t<is_floating_point<FloatingPoint>::value, FloatingPoint> exp2(FloatingPoint val);
28+
enable_if_t<is_floating_point<FloatingPoint>::value && !is_matrix_v<FloatingPoint>, FloatingPoint> exp2(FloatingPoint val);
3029

3130
template<typename FloatingPoint>
3231
[[vk::ext_instruction(GLSLstd450::GLSLstd450InverseSqrt, "GLSL.std.450")]]
33-
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> inverseSqrt(FloatingPoint val);
32+
enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> inverseSqrt(FloatingPoint val);
3433

3534
template<typename FloatingPoint>
3635
[[vk::ext_instruction(GLSLstd450::GLSLstd450Floor, "GLSL.std.450")]]
37-
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> floor(FloatingPoint val);
36+
enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> floor(FloatingPoint val);
3837

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

4342
template<typename FloatingPoint>
4443
[[vk::ext_instruction(GLSLstd450::GLSLstd450FMix, "GLSL.std.450")]]
45-
enable_if_t<is_floating_point_v<FloatingPoint>, FloatingPoint> fMix(FloatingPoint val, FloatingPoint min, FloatingPoint max);
44+
enable_if_t<is_floating_point_v<FloatingPoint> && !is_matrix_v<FloatingPoint>, FloatingPoint> fMix(FloatingPoint val, FloatingPoint min, FloatingPoint max);
4645

4746
template<typename T, int N>
4847
[[vk::ext_instruction(GLSLstd450::GLSLstd450Determinant, "GLSL.std.450")]]
4948
T determinant(in matrix<T, N, N> mat);
5049

50+
template<typename T, int N>
51+
[[vk::ext_instruction(GLSLstd450MatrixInverse, "GLSL.std.450")]]
52+
matrix<T, N, N> matrixInverse(in matrix<T, N, N> mat);
53+
54+
[[vk::ext_instruction(GLSLstd450UnpackSnorm2x16, "GLSL.std.450")]]
55+
float32_t2 unpackSnorm2x16(uint32_t p);
56+
57+
[[vk::ext_instruction(GLSLstd450UnpackSnorm4x8, "GLSL.std.450")]]
58+
float32_t4 unpackSnorm4x8(uint32_t p);
59+
60+
[[vk::ext_instruction(GLSLstd450UnpackUnorm4x8, "GLSL.std.450")]]
61+
float32_t4 unpackUnorm4x8(uint32_t p);
62+
5163
}
5264
}
5365
}

0 commit comments

Comments
 (0)