22#define _NBL_BUILTIN_HLSL_EMULATED_MATRIX_T_HLSL_INCLUDED_
33
44#include <nbl/builtin/hlsl/portable/float64_t.hlsl>
5+ #include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
56
67namespace nbl
78{
@@ -20,7 +21,7 @@ struct emulated_matrix
2021
2122 vec_t rows[RowCount];
2223
23- transposed_t getTransposed ()
24+ transposed_t getTransposed () NBL_CONST_MEMBER_FUNC
2425 {
2526 static nbl::hlsl::array_get<typename this_t::vec_t, T> getter;
2627 static nbl::hlsl::array_set<typename transposed_t::vec_t, T> setter;
@@ -47,8 +48,29 @@ using emulated_matrix_t4x4 = emulated_matrix<EmulatedType, 4, 4>;
4748template<typename EmulatedType>
4849using emulated_matrix_t3x4 = emulated_matrix<EmulatedType, 3 , 4 >;
4950
51+ // i choose to implement it this way because of this DXC bug: https://github.com/microsoft/DirectXShaderCompiler/issues/7007
52+ #define DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION (ROW_COUNT, COLUMN_COUNT) \
53+ template<typename T> \
54+ struct matrix_traits<emulated_matrix<T, ROW_COUNT, COLUMN_COUNT> > \
55+ { \
56+ using scalar_type = T; \
57+ using row_type = vector <T, COLUMN_COUNT>; \
58+ using transposed_type = emulated_matrix<T, COLUMN_COUNT, ROW_COUNT>; \
59+ NBL_CONSTEXPR_STATIC_INLINE uint32_t RowCount = ROW_COUNT; \
60+ NBL_CONSTEXPR_STATIC_INLINE uint32_t ColumnCount = COLUMN_COUNT; \
61+ NBL_CONSTEXPR_STATIC_INLINE bool Square = RowCount == ColumnCount; \
62+ };
63+
64+ DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION (2 , 2 )
65+ DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION (3 , 3 )
66+ DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION (4 , 4 )
67+ DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION (3 , 4 )
68+
69+ #undef DEFINE_MATRIX_TRAITS_TEMPLATE_SPECIALIZATION
70+
5071namespace emulated_matrix_impl
5172{
73+ // TODO: move to cpp_compat/impl/intrinsics_impl.hlsl
5274template<typename LhsT, typename RhsT>
5375struct mul_helper
5476{
@@ -77,8 +99,24 @@ struct mul_helper<emulated_matrix<ComponentT, RowCount, ColumnCount>, emulated_v
7799 return output;
78100 }
79101};
102+
103+ }
104+
105+ namespace cpp_compat_intrinsics_impl
106+ {
107+ template<typename T, int N, int M>
108+ struct transpose_helper<emulated_matrix<T, N, M> >
109+ {
110+ using transposed_t = typename matrix_traits<emulated_matrix<T, N, M> >::transposed_type;
111+
112+ static transposed_t transpose (NBL_CONST_REF_ARG (emulated_matrix<T, N, M>) m)
113+ {
114+ return m.getTransposed ();
115+ }
116+ };
80117}
81118
119+ // TODO: move to cpp_compat/intrinsics.hlsl
82120// TODO: concepts, to ensure that LhsT is a matrix and RhsT is a vector type
83121template<typename MatT, typename VecT>
84122VecT mul (MatT mat, VecT vec)
0 commit comments