Skip to content

Commit fc9b4d4

Browse files
committed
Added matrix_traits.hlsl
1 parent 3b9658b commit fc9b4d4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef _NBL_BUILTIN_HLSL_MATRIX_UTILS_MATRIX_TRAITS_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_MATRIX_UTILS_MATRIX_TRAITS_INCLUDED_
3+
4+
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
5+
6+
namespace nbl
7+
{
8+
namespace hlsl
9+
{
10+
11+
template<typename MatT>
12+
struct matrix_traits;
13+
14+
// i choose to implement it this way because of this DXC bug: https://github.com/microsoft/DirectXShaderCompiler/issues/7007
15+
#define DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION(ROW_COUNT, COLUMN_COUNT) \
16+
template<typename T> \
17+
struct matrix_traits<matrix<T, ROW_COUNT, COLUMN_COUNT> > \
18+
{ \
19+
using scalar_type = T; \
20+
using row_type = vector<T, COLUMN_COUNT>; \
21+
NBL_CONSTEXPR_STATIC_INLINE uint32_t RowCount = ROW_COUNT; \
22+
NBL_CONSTEXPR_STATIC_INLINE uint32_t ColumnCount = COLUMN_COUNT; \
23+
NBL_CONSTEXPR_STATIC_INLINE bool Square = RowCount == ColumnCount; \
24+
};
25+
26+
DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION(2, 2)
27+
DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION(3, 3)
28+
DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION(4, 4)
29+
DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION(3, 4)
30+
31+
// TODO: when this bug: https://github.com/microsoft/DirectXShaderCompiler/issues/7007 is fixed, uncomment and delete template specializations
32+
/*template<typename T, uint32_t N, uint32_t M>
33+
struct matrix_traits<matrix<T,N,M> >
34+
{
35+
using scalar_type = T;
36+
NBL_CONSTEXPR_STATIC_INLINE uint32_t RowCount = ROW_COUNT;
37+
NBL_CONSTEXPR_STATIC_INLINE uint32_t ColumnCount = COLUMN_COUNT;
38+
NBL_CONSTEXPR_STATIC_INLINE bool Square = RowCount == ColumnCount;
39+
};
40+
*/
41+
42+
}
43+
}
44+
45+
#endif

0 commit comments

Comments
 (0)