Skip to content

Commit ec6a8d4

Browse files
Merge pull request #857 from Devsh-Graphics-Programming/concepts_fix
Fix the circular dependency between concepts and type_traits
2 parents 0ecda6a + 3bd30c9 commit ec6a8d4

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

include/nbl/builtin/hlsl/concepts.hlsl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _NBL_BUILTIN_HLSL_CONCEPTS_INCLUDED_
66

77

8+
#include <nbl/builtin/hlsl/concepts/impl/base.hlsl>
89
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
910
#include <nbl/builtin/hlsl/cpp_compat/matrix.hlsl>
1011
#include <nbl/builtin/hlsl/utility.hlsl>
@@ -37,15 +38,9 @@ namespace concepts
3738
//! Now diverge
3839
#ifdef __cpp_concepts
3940

40-
41-
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
42-
#define NBL_BOOL_CONCEPT concept
43-
4441
// for struct definitions, use instead of closing `>` on the primary template parameter list
4542
#define NBL_PRIMARY_REQUIRES(...) > requires (__VA_ARGS__)
4643

47-
// to put right before the closing `>` of the primary template definition, otherwise `NBL_PARTIAL_REQUIRES` wont work on specializations
48-
#define NBL_STRUCT_CONSTRAINABLE
4944
// NOTE: C++20 requires and C++11 enable_if have to be in different places! ITS OF UTTMOST IMPORTANCE YOUR REQUIRE CLAUSES ARE IDENTICAL FOR BOTH MACROS
5045
// put just after the closing `>` on the partial template specialization `template` declaration e.g. `template<typename U, typename V, typename T> NBL_PARTIAL_REQ_TOP(SomeCond<U>)
5146
#define NBL_PARTIAL_REQ_TOP(...) requires (__VA_ARGS__)
@@ -79,14 +74,9 @@ concept NBL_CONCEPT_NAME = requires BOOST_PP_EXPR_IF(LOCAL_PARAM_COUNT,(BOOST_PP
7974

8075
#else
8176

82-
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
83-
#define NBL_BOOL_CONCEPT NBL_CONSTEXPR bool
84-
8577
// for struct definitions, use instead of closing `>` on the primary template parameter list
8678
#define NBL_PRIMARY_REQUIRES(...) ,typename __requires=::nbl::hlsl::enable_if_t<(__VA_ARGS__),void> >
8779

88-
// to put right before the closing `>` of the primary template definition, otherwise `NBL_PARTIAL_REQUIRES` wont work on specializations
89-
#define NBL_STRUCT_CONSTRAINABLE ,typename __requires=void
9080
// NOTE: C++20 requires and C++11 enable_if have to be in different places! ITS OF UTTMOST IMPORTANCE YOUR REQUIRE CLAUSES ARE IDENTICAL FOR BOTH MACROS
9181
// put just after the closing `>` on the partial template specialization `template` declaration e.g. `template<typename U, typename V, typename T> NBL_PARTIAL_REQ_TOP(SomeCond<U>)
9282
#define NBL_PARTIAL_REQ_TOP(...)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2023-2024 - 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_IMPL_BASE_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_CONCEPTS_IMPL_BASE_INCLUDED_
6+
7+
namespace nbl
8+
{
9+
namespace hlsl
10+
{
11+
namespace concepts
12+
{
13+
14+
//! Now diverge
15+
#ifdef __cpp_concepts
16+
17+
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
18+
#define NBL_BOOL_CONCEPT concept
19+
20+
// to put right before the closing `>` of the primary template definition, otherwise `NBL_PARTIAL_REQUIRES` wont work on specializations
21+
#define NBL_STRUCT_CONSTRAINABLE
22+
23+
#else
24+
25+
// to define a concept using `concept Name = SomeContexprBoolCondition<T>;`
26+
#define NBL_BOOL_CONCEPT NBL_CONSTEXPR bool
27+
28+
// to put right before the closing `>` of the primary template definition, otherwise `NBL_PARTIAL_REQUIRES` wont work on specializations
29+
#define NBL_STRUCT_CONSTRAINABLE ,typename __requires=void
30+
31+
#endif
32+
}
33+
}
34+
}
35+
36+
#endif

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ concept is_scoped_enum = std::is_enum_v<E> && !std::is_convertible_v<E, std::und
1313
#endif
1414

1515
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
16-
#include <nbl/builtin/hlsl/concepts.hlsl>
16+
// Include only concept stuff that does not rely on type_traits
17+
#include <nbl/builtin/hlsl/concepts/impl/base.hlsl>
1718

1819
// Since HLSL currently doesnt allow type aliases we declare them as seperate structs thus they are (WORKAROUND)s
1920
/*

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/glsl_compat/subgroup_shuffle.
257257
#stdlib
258258
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/algorithm.hlsl")
259259
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/bit.hlsl")
260+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/impl/base.hlsl")
260261
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts.hlsl")
261262
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/functional.hlsl")
262263
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/limits.hlsl")

0 commit comments

Comments
 (0)