@@ -63,6 +63,29 @@ DEFINE_BUILTIN_VECTOR_SPECIALIZATION(float64_t, BUILTIN_VECTOR_SPECIALIZATION_RE
63
63
#undef BUILTIN_VECTOR_SPECIALIZATION_RET_VAL
64
64
#undef DEFINE_BUILTIN_VECTOR_SPECIALIZATION
65
65
66
+ template<typename T NBL_STRUCT_CONSTRAINABLE>
67
+ struct cross_helper;
68
+
69
+ //! this specialization will work only with hlsl::vector<T, 3> type
70
+ template<typename FloatingPointVector>
71
+ NBL_PARTIAL_REQ_TOP (hlsl::is_floating_point_v<FloatingPointVector> && hlsl::is_vector_v<FloatingPointVector> && (vector_traits<FloatingPointVector>::Dimension == 3 ))
72
+ struct cross_helper<FloatingPointVector NBL_PARTIAL_REQ_BOT (hlsl::is_floating_point_v<FloatingPointVector>&& hlsl::is_vector_v<FloatingPointVector>&& (vector_traits<FloatingPointVector>::Dimension == 3 )) >
73
+ {
74
+ static FloatingPointVector __call (NBL_CONST_REF_ARG (FloatingPointVector) lhs, NBL_CONST_REF_ARG (FloatingPointVector) rhs)
75
+ {
76
+ #ifdef __HLSL_VERSION
77
+ return spirv::cross (lhs, rhs);
78
+ #else
79
+ FloatingPointVector output;
80
+ output.x = lhs[1 ] * rhs[2 ] - rhs[1 ] * lhs[2 ];
81
+ output.y = lhs[2 ] * rhs[0 ] - rhs[2 ] * lhs[0 ];
82
+ output.z = lhs[0 ] * rhs[1 ] - rhs[0 ] * lhs[1 ];
83
+
84
+ return output;
85
+ #endif
86
+ }
87
+ };
88
+
66
89
template<typename Integer>
67
90
struct find_msb_helper;
68
91
@@ -455,6 +478,23 @@ struct bitCount_helper<EnumT>
455
478
};
456
479
#endif
457
480
481
+ template<typename Vector NBL_STRUCT_CONSTRAINABLE>
482
+ struct length_helper;
483
+
484
+ template<typename Vector>
485
+ NBL_PARTIAL_REQ_TOP (hlsl::is_floating_point_v<Vector>&& hlsl::is_vector_v<Vector>)
486
+ struct length_helper<Vector NBL_PARTIAL_REQ_BOT (hlsl::is_floating_point_v<Vector>&& hlsl::is_vector_v<Vector>) >
487
+ {
488
+ static inline typename vector_traits<Vector>::scalar_type __call (NBL_CONST_REF_ARG (Vector) vec)
489
+ {
490
+ #ifdef __HLSL_VERSION
491
+ return spirv::length (vec);
492
+ #else
493
+ return std::sqrt (dot_helper<Vector>::__call (vec, vec));
494
+ #endif
495
+ }
496
+ };
497
+
458
498
template<typename Vector NBL_STRUCT_CONSTRAINABLE>
459
499
struct normalize_helper;
460
500
@@ -465,9 +505,9 @@ struct normalize_helper<Vector NBL_PARTIAL_REQ_BOT(hlsl::is_floating_point_v<Vec
465
505
static inline Vector __call (NBL_CONST_REF_ARG (Vector) vec)
466
506
{
467
507
#ifdef __HLSL_VERSION
468
- return normalize (vec);
508
+ return spirv:: normalize (vec);
469
509
#else
470
- return vec / std:: sqrt (dot_helper <Vector>::__call (vec, vec) );
510
+ return vec / length_helper <Vector>::__call (vec);
471
511
#endif
472
512
}
473
513
};
0 commit comments