Skip to content

Commit 274e56f

Browse files
committed
Integrated concepts into tgmath.hlsl and intrinsics.hlsl
1 parent f99ad10 commit 274e56f

File tree

12 files changed

+688
-229
lines changed

12 files changed

+688
-229
lines changed

include/nbl/builtin/hlsl/concepts.hlsl

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,50 +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-
12180
#else
12281

123-
12482
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
12583
#define NBL_BOOL_CONCEPT NBL_CONSTEXPR bool
12684

@@ -138,7 +96,6 @@ concept scalar = floating_point<T> || integral<T>;
13896
// condition, use instead of the closing `>` of a function template
13997
#define NBL_FUNC_REQUIRES(...) ,::nbl::hlsl::enable_if_t<(__VA_ARGS__),bool> = true>
14098

141-
14299
//
143100
#define NBL_CONCEPT_BEGIN(LOCAL_PARAM_COUNT) namespace BOOST_PP_CAT(__concept__,NBL_CONCEPT_NAME) \
144101
{
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
#ifdef __cpp_concepts // CPP
20+
21+
#include <concepts>
22+
23+
// Alias some of the std concepts in nbl. As this is C++20 only, we don't need to use
24+
// the macros here.
25+
template <typename T, typename U>
26+
concept same_as = std::same_as<T, U>;
27+
28+
template <typename D, typename B>
29+
concept derived_from = std::derived_from<D, B>;
30+
31+
template <typename F, typename T>
32+
concept convertible_to = std::convertible_to<F, T>;
33+
34+
template <typename T, typename F>
35+
concept assignable_from = std::assignable_from<T, F>;
36+
37+
template <typename T, typename U>
38+
concept common_with = std::common_with<T, U>;
39+
40+
template <typename T>
41+
concept integral = std::integral<T>;
42+
43+
template <typename T>
44+
concept signed_integral = std::signed_integral<T>;
45+
46+
template <typename T>
47+
concept unsigned_integral = std::unsigned_integral<T>;
48+
49+
template <typename T>
50+
concept floating_point = std::floating_point<T>;
51+
52+
// Some other useful concepts.
53+
54+
template<typename T, typename... Ts>
55+
concept any_of = (same_as<T, Ts> || ...);
56+
57+
template <typename T>
58+
concept scalar = floating_point<T> || integral<T>;
59+
60+
#elif defined(__HLSL_VERSION) // HLSL
61+
62+
template<typename T, typename U>
63+
NBL_BOOL_CONCEPT same_as = is_same_v<T, U>;
64+
65+
// TODO: implement when hlsl::is_base_of is done
66+
//#define NBL_CONCEPT_NAME derived_from
67+
// ...
68+
69+
// TODO: implement when hlsl::is_converible is done
70+
//#define NBL_CONCEPT_NAME convertible_to
71+
// ...
72+
73+
// TODO?
74+
//#define NBL_CONCEPT_NAME assignable_from
75+
76+
// TODO?
77+
//template <typename T, typename U>
78+
//concept common_with = std::common_with<T, U>;
79+
80+
template<typename T>
81+
NBL_BOOL_CONCEPT integral = nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
82+
83+
template<typename T>
84+
NBL_BOOL_CONCEPT signed_integral = nbl::hlsl::is_signed_v<T> && nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
85+
86+
template<typename T>
87+
NBL_BOOL_CONCEPT unsigned_integral = !nbl::hlsl::is_signed_v<T> && ::nbl::hlsl::is_integral_v<T> && nbl::hlsl::is_scalar_v<T>;
88+
89+
template<typename T>
90+
NBL_BOOL_CONCEPT floating_point = nbl::hlsl::is_floating_point_v<T> && nbl::hlsl::is_scalar_v<T>;
91+
92+
#endif
93+
94+
}
95+
}
96+
}
97+
#endif

include/nbl/builtin/hlsl/concepts/matrix.hlsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_INCLUDED_
5-
#define _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_INCLUDED_
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_HLSL_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_MATRIX_HLSL_INCLUDED_
66

77

88
#include <nbl/builtin/hlsl/concepts.hlsl>
@@ -28,10 +28,15 @@ NBL_CONCEPT_END(
2828
((NBL_CONCEPT_REQ_TYPE)(matrix_traits<T>::transposed_type))
2929
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matrix_traits<T>::RowCount), ::nbl::hlsl::is_integral_v))
3030
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matrix_traits<T>::ColumnCount), ::nbl::hlsl::is_integral_v))
31-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matrix_traits<T>::Square), ::nbl::hlsl::is_same_v, bool))
31+
// TODO: fix
32+
//((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((matrix_traits<T>::Square), ::nbl::hlsl::is_same_v, bool))
3233
);
3334
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
3435

36+
#undef NBL_CONCEPT_NAME
37+
#undef NBL_CONCEPT_TPLT_PRM_KINDS
38+
#undef NBL_CONCEPT_TPLT_PRM_NAMES
39+
3540
}
3641
}
3742
}

include/nbl/builtin/hlsl/concepts/vector.hlsl

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (C) 2024-2025 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_INCLUDED_
5-
#define _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_INCLUDED_
4+
#ifndef _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_HLSL_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_VECTOR_HLSL_INCLUDED_
66

77

88
#include <nbl/builtin/hlsl/concepts.hlsl>
9+
#include <nbl/builtin/hlsl/concepts/core.hlsl>
910
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
1011
#include <nbl/builtin/hlsl/type_traits.hlsl>
1112

@@ -16,23 +17,43 @@ namespace hlsl
1617
namespace concepts
1718
{
1819

20+
//! Concept for native vectors.
1921
template<typename T>
2022
NBL_BOOL_CONCEPT Vector = is_vector<T>::value;
23+
template<typename T>
24+
NBL_BOOL_CONCEPT FloatingPointVector = concepts::Vector<T> && concepts::floating_point<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::signed_integral<typename vector_traits<T>::scalar_type>;
29+
30+
//! Concept for native vectors and vector like structs.
31+
//! The only requirement for a structure to be Vectorial is that a correct template specialization of the `vector_traits` structure should be created for it.
32+
//#define NBL_CONCEPT_NAME Vectorial
33+
//#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
34+
//#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
35+
//
36+
//NBL_CONCEPT_BEGIN(0)
37+
//NBL_CONCEPT_END
38+
//(
39+
// ((NBL_CONCEPT_REQ_TYPE)(vector_traits<T>::scalar_type))
40+
// ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((vector_traits<T>::Dimension), ::nbl::hlsl::is_integral_v))
41+
// // TODO: fix
42+
// //((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((vector_traits<T>::IsVector), ::nbl::hlsl::is_same_v, bool))
43+
//) && vector_traits<T>::isVector;
2144

22-
// declare concept
23-
#define NBL_CONCEPT_NAME Vectorial
24-
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
25-
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
26-
27-
NBL_CONCEPT_BEGIN(0)
28-
NBL_CONCEPT_END
29-
(
30-
((NBL_CONCEPT_REQ_TYPE)(vector_traits<T>::scalar_type))
31-
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((vector_traits<T>::Dimension), ::nbl::hlsl::is_integral_v))
32-
);
45+
template<typename T>
46+
NBL_BOOL_CONCEPT Vectorial = vector_traits<T>::IsVector;
3347

3448
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
3549

50+
template<typename T>
51+
NBL_BOOL_CONCEPT FloatingPointVectorial = concepts::Vectorial<T> && concepts::floating_point<typename vector_traits<T>::scalar_type>;
52+
template<typename T>
53+
NBL_BOOL_CONCEPT IntVectorial = concepts::Vectorial<T> && (is_integral_v<typename vector_traits<T>::scalar_type>);
54+
template<typename T>
55+
NBL_BOOL_CONCEPT SignedIntVectorial = concepts::Vectorial<T> && concepts::signed_integral<typename vector_traits<T>::scalar_type>;
56+
3657
}
3758
}
3859
}

0 commit comments

Comments
 (0)