Skip to content

Commit f7c4846

Browse files
Merge pull request #821 from Devsh-Graphics-Programming/new_tgmath
New tgmath but against master
2 parents 105a553 + 2b861ea commit f7c4846

31 files changed

+3001
-737
lines changed

include/nbl/builtin/hlsl/bitreverse.hlsl

Lines changed: 0 additions & 47 deletions
This file was deleted.

include/nbl/builtin/hlsl/concepts.hlsl

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ concept NBL_CONCEPT_NAME = requires BOOST_PP_EXPR_IF(LOCAL_PARAM_COUNT,(BOOST_PP
6868
//
6969
#define NBL_IMPL_CONCEPT_REQ_TYPE(...) typename __VA_ARGS__;
7070
#define NBL_IMPL_CONCEPT_REQ_EXPR(...) __VA_ARGS__;
71-
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) {E}; C<decltype E,__VA_ARGS__ >;
71+
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) {E}; C<decltype E __VA_OPT__(,) __VA_ARGS__ >;
7272
//
7373
#define NBL_IMPL_CONCEPT (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
7474
//
@@ -77,56 +77,8 @@ concept NBL_CONCEPT_NAME = requires BOOST_PP_EXPR_IF(LOCAL_PARAM_COUNT,(BOOST_PP
7777
#define NBL_CONCEPT_END(SEQ) BOOST_PP_SEQ_FOR_EACH_I(NBL_IMPL_CONCEPT_END_DEF, DUMMY, SEQ) \
7878
}
7979

80-
81-
#include <concepts>
82-
83-
// Alias some of the std concepts in nbl. As this is C++20 only, we don't need to use
84-
// the macros here.
85-
template <typename T, typename U>
86-
concept same_as = std::same_as<T, U>;
87-
88-
template <typename D, typename B>
89-
concept derived_from = std::derived_from<D, B>;
90-
91-
template <typename F, typename T>
92-
concept convertible_to = std::convertible_to<F, T>;
93-
94-
template <typename T, typename F>
95-
concept assignable_from = std::assignable_from<T, F>;
96-
97-
template <typename T, typename U>
98-
concept common_with = std::common_with<T, U>;
99-
100-
template <typename T>
101-
concept integral = std::integral<T>;
102-
103-
template <typename T>
104-
concept signed_integral = std::signed_integral<T>;
105-
106-
template <typename T>
107-
concept unsigned_integral = std::unsigned_integral<T>;
108-
109-
template <typename T>
110-
concept floating_point = std::floating_point<T>;
111-
112-
113-
// Some other useful concepts.
114-
115-
template<typename T, typename... Ts>
116-
concept any_of = (same_as<T, Ts> || ...);
117-
118-
template <typename T>
119-
concept scalar = floating_point<T> || integral<T>;
120-
121-
template <typename T>
122-
concept vectorial = is_vector<T>::value;
123-
124-
template <typename T>
125-
concept matricial = is_matrix<T>::value;
126-
12780
#else
12881

129-
13082
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
13183
#define NBL_BOOL_CONCEPT NBL_CONSTEXPR bool
13284

@@ -144,7 +96,6 @@ concept matricial = is_matrix<T>::value;
14496
// condition, use instead of the closing `>` of a function template
14597
#define NBL_FUNC_REQUIRES(...) ,::nbl::hlsl::enable_if_t<(__VA_ARGS__),bool> = true>
14698

147-
14899
//
149100
#define NBL_CONCEPT_BEGIN(LOCAL_PARAM_COUNT) namespace BOOST_PP_CAT(__concept__,NBL_CONCEPT_NAME) \
150101
{
@@ -153,7 +104,7 @@ concept matricial = is_matrix<T>::value;
153104
//
154105
#define NBL_IMPL_CONCEPT_REQ_TYPE(...) ::nbl::hlsl::make_void_t<typename __VA_ARGS__ >
155106
#define NBL_IMPL_CONCEPT_REQ_EXPR(...) ::nbl::hlsl::make_void_t<decltype(__VA_ARGS__)>
156-
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) ::nbl::hlsl::enable_if_t<C<decltype E ,__VA_ARGS__ > >
107+
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) ::nbl::hlsl::enable_if_t<C<decltype E __VA_OPT__(,) __VA_ARGS__ > >
157108
//
158109
#define NBL_IMPL_CONCEPT_SFINAE (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
159110
//
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_CORE_HLSL_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_CORE_HLSL_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
10+
#include <nbl/builtin/hlsl/type_traits.hlsl>
11+
12+
namespace nbl
13+
{
14+
namespace hlsl
15+
{
16+
namespace concepts
17+
{
18+
19+
template<typename T, typename U>
20+
NBL_BOOL_CONCEPT same_as = is_same_v<T, U>;
21+
22+
template<typename T>
23+
NBL_BOOL_CONCEPT Integral = nbl::hlsl::is_integral_v<T>;
24+
25+
template<typename T>
26+
NBL_BOOL_CONCEPT SignedIntegral = nbl::hlsl::is_signed_v<T> && nbl::hlsl::is_integral_v<T>;
27+
28+
template<typename T>
29+
NBL_BOOL_CONCEPT UnsignedIntegral = !nbl::hlsl::is_signed_v<T> && ::nbl::hlsl::is_integral_v<T>;
30+
31+
template<typename T>
32+
NBL_BOOL_CONCEPT FloatingPoint = nbl::hlsl::is_floating_point_v<T>;
33+
34+
template<typename T>
35+
NBL_BOOL_CONCEPT Boolean = nbl::hlsl::is_same_v<T, bool> || (nbl::hlsl::is_vector_v<T> && nbl::hlsl::is_same_v<typename vector_traits<T>::scalar_type, bool>);
36+
37+
template <typename T>
38+
NBL_BOOL_CONCEPT Scalar = nbl::hlsl::is_scalar_v<T>;
39+
40+
template<typename T>
41+
NBL_BOOL_CONCEPT IntegralScalar = nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
42+
43+
template<typename T>
44+
NBL_BOOL_CONCEPT SignedIntegralScalar = nbl::hlsl::is_signed_v<T> && nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
45+
46+
template<typename T>
47+
NBL_BOOL_CONCEPT UnsignedIntegralScalar = !nbl::hlsl::is_signed_v<T> && ::nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
48+
49+
template<typename T>
50+
NBL_BOOL_CONCEPT FloatingPointScalar = nbl::hlsl::is_floating_point_v<T> && nbl::hlsl::is_scalar_v<T>;
51+
52+
template<typename T>
53+
NBL_BOOL_CONCEPT BooleanScalar = concepts::Boolean<T> && nbl::hlsl::is_scalar_v<T>;
54+
55+
// TODO: implement when hlsl::is_base_of is done
56+
//#define NBL_CONCEPT_NAME DerivedFrom
57+
// ...
58+
59+
// TODO: implement when hlsl::is_converible is done
60+
//#define NBL_CONCEPT_NAME ConvertibleTo
61+
// ...
62+
63+
// TODO?
64+
//#define NBL_CONCEPT_NAME AssignableFrom
65+
66+
// TODO?
67+
//template <typename T, typename U>
68+
//concept common_with = std::common_with<T, U>;
69+
70+
namespace impl
71+
{
72+
template<typename T>
73+
struct is_emulating_floating_point_scalar
74+
{
75+
NBL_CONSTEXPR_STATIC_INLINE bool value = FloatingPointScalar<T>;
76+
};
77+
}
78+
79+
//! Floating point types are native floating point types or types that imitate native floating point types (for example emulated_float64_t)
80+
template<typename T>
81+
NBL_BOOL_CONCEPT FloatingPointLikeScalar = impl::is_emulating_floating_point_scalar<T>::value;
82+
83+
}
84+
}
85+
}
86+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_HLSL_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_HLSL_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
namespace concepts
16+
{
17+
18+
template<typename T>
19+
NBL_BOOL_CONCEPT Matrix = is_matrix<T>::value;
20+
21+
template<typename T>
22+
NBL_BOOL_CONCEPT Matricial = matrix_traits<T>::IsMatrix;
23+
24+
}
25+
}
26+
}
27+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_HLSL_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_HLSL_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
#include <nbl/builtin/hlsl/concepts/core.hlsl>
10+
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
11+
#include <nbl/builtin/hlsl/type_traits.hlsl>
12+
13+
namespace nbl
14+
{
15+
namespace hlsl
16+
{
17+
namespace concepts
18+
{
19+
20+
//! Concept for native vectors.
21+
template<typename T>
22+
NBL_BOOL_CONCEPT Vector = is_vector<T>::value;
23+
template<typename T>
24+
NBL_BOOL_CONCEPT FloatingPointVector = concepts::Vector<T> && concepts::FloatingPointScalar<typename vector_traits<T>::scalar_type>;
25+
template<typename T>
26+
NBL_BOOL_CONCEPT IntVector = concepts::Vector<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
27+
template<typename T>
28+
NBL_BOOL_CONCEPT SignedIntVector = concepts::Vector<T> && concepts::SignedIntegralScalar<typename vector_traits<T>::scalar_type>;
29+
30+
//! Concept for native vectors and vector like structs.
31+
template<typename T>
32+
NBL_BOOL_CONCEPT Vectorial = vector_traits<T>::IsVector;
33+
34+
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
35+
36+
template<typename T>
37+
NBL_BOOL_CONCEPT FloatingPointVectorial = concepts::Vectorial<T> && concepts::FloatingPointScalar<typename vector_traits<T>::scalar_type>;
38+
template<typename T>
39+
NBL_BOOL_CONCEPT FloatingPointLikeVectorial = concepts::Vectorial<T> && concepts::FloatingPointLikeScalar<typename vector_traits<T>::scalar_type>;
40+
template<typename T>
41+
NBL_BOOL_CONCEPT IntVectorial = concepts::Vectorial<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
42+
template<typename T>
43+
NBL_BOOL_CONCEPT SignedIntVectorial = concepts::Vectorial<T> && concepts::SignedIntegralScalar<typename vector_traits<T>::scalar_type>;
44+
45+
}
46+
47+
template<typename Vectorial>
48+
NBL_PARTIAL_REQ_TOP(concepts::Vectorial<Vectorial>)
49+
struct extent<Vectorial, 0 NBL_PARTIAL_REQ_BOT(concepts::Vectorial<Vectorial>) > : integral_constant<uint64_t, vector_traits<Vectorial>::Dimension> {};
50+
51+
}
52+
}
53+
#endif

0 commit comments

Comments
 (0)