Skip to content

Commit bb757d8

Browse files
author
devsh
committed
make concepts work
P.S. also make the HLSL `decltype` macro forward perfectly
1 parent 4275c23 commit bb757d8

File tree

6 files changed

+83
-16
lines changed

6 files changed

+83
-16
lines changed

include/nbl/builtin/hlsl/blit/parameters.hlsl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@ struct parameters_t
4444
}
4545
};
4646

47+
struct parameters2_t
48+
{
49+
float32_t3 fScale;
50+
float32_t3 negativeSupportMinusHalf;
51+
float32_t referenceAlpha;
52+
uint32_t kernelWeightsOffsetY;
53+
uint32_t kernelWeightsOffsetZ;
54+
uint32_t inPixelCount;
55+
uint32_t outPixelCount;
56+
57+
uint16_t3 inputDims;
58+
uint16_t3 outputDims;
59+
uint16_t3 windowDims;
60+
uint16_t3 phaseCount;
61+
uint16_t3 preloadRegion;
62+
uint16_t3 iterationRegionXPrefixProducts;
63+
uint16_t3 iterationRegionYPrefixProducts;
64+
uint16_t3 iterationRegionZPrefixProducts;
65+
66+
//! Offset into the shared memory array which tells us from where the second buffer of shared memory begins
67+
//! Given by max(memory_for_preload_region, memory_for_result_of_y_pass)
68+
uint16_t secondScratchOffset;
69+
uint16_t outputTexelsPerWGZ;
70+
71+
uint32_t3 getOutputTexelsPerWG()
72+
{
73+
//! `outputTexelsPerWG.xy` just happens to be in the first components of `iterationRegionsXPrefixProducts` and `iterationRegionYPrefixProducts` --this is
74+
//! the result of how we choose to iterate, i.e. if, in the future, we decide to iterate differently, this needs to change.
75+
return uint32_t3(iterationRegionXPrefixProducts.x, iterationRegionYPrefixProducts.x, outputTexelsPerWGZ);
76+
}
77+
};
78+
4779

4880
}
4981
}

include/nbl/builtin/hlsl/concepts.hlsl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
99
#include <nbl/builtin/hlsl/cpp_compat/matrix.hlsl>
10-
#include <nbl/builtin/hlsl/type_traits.hlsl>
10+
#include <nbl/builtin/hlsl/utility.hlsl>
1111

1212

1313
namespace nbl
@@ -148,20 +148,19 @@ concept matricial = is_matrix<T>::value;
148148
#define NBL_CONCEPT_BEGIN(LOCAL_PARAM_COUNT) namespace BOOST_PP_CAT(__concept__,NBL_CONCEPT_NAME) \
149149
{
150150
//
151-
#define NBL_CONCEPT_PARAM_T(ID,...) ::nbl::hlsl::impl::declval<__VA_ARGS__ >()
151+
#define NBL_CONCEPT_PARAM_T(ID,...) ::nbl::hlsl::experimental::declval<__VA_ARGS__ >()
152152
//
153153
#define NBL_IMPL_CONCEPT_REQ_TYPE(...) ::nbl::hlsl::make_void_t<typename __VA_ARGS__ >
154154
#define NBL_IMPL_CONCEPT_REQ_EXPR(...) ::nbl::hlsl::make_void_t<decltype(__VA_ARGS__)>
155-
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) C<decltype E ,__VA_ARGS__ >
155+
#define NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE(E,C,...) ::nbl::hlsl::enable_if_t<C<decltype E ,__VA_ARGS__ > >
156156
//
157-
#define NBL_IMPL_CONCEPT_SFINAE (typename=void,typename=void,bool=true)
158-
#define NBL_IMPL_CONCEPT_SFINAE_SPEC (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
157+
#define NBL_IMPL_CONCEPT_SFINAE (NBL_IMPL_CONCEPT_REQ_TYPE,NBL_IMPL_CONCEPT_REQ_EXPR,NBL_IMPL_CONCEPT_REQ_EXPR_RET_TYPE)
159158
//
160-
#define NBL_IMPL_CONCEPT_END_DEF(r,unused,i,e) template<NBL_CONCEPT_FULL_TPLT(), BOOST_PP_TUPLE_ELEM(BOOST_PP_SEQ_HEAD(e),NBL_IMPL_CONCEPT_SFINAE)> \
159+
#define NBL_IMPL_CONCEPT_END_DEF(r,unused,i,e) template<NBL_CONCEPT_FULL_TPLT(), typename=void> \
161160
struct BOOST_PP_CAT(__requirement,i) : ::nbl::hlsl::false_type {}; \
162161
template<NBL_CONCEPT_FULL_TPLT()> \
163162
struct BOOST_PP_CAT(__requirement,i)<NBL_CONCEPT_TPLT_PARAMS(), \
164-
NBL_EVAL(BOOST_PP_TUPLE_ELEM(BOOST_PP_SEQ_HEAD(e),NBL_IMPL_CONCEPT_SFINAE_SPEC) BOOST_PP_SEQ_TAIL(e)) \
163+
NBL_EVAL(BOOST_PP_TUPLE_ELEM(BOOST_PP_SEQ_HEAD(e),NBL_IMPL_CONCEPT_SFINAE) BOOST_PP_SEQ_TAIL(e)) \
165164
> : ::nbl::hlsl::true_type {};
166165
//
167166
#define NBL_IMPL_CONCEPT_END_GET(r,unused,i,e) BOOST_PP_EXPR_IF(i,&&) BOOST_PP_CAT(__concept__,NBL_CONCEPT_NAME)::BOOST_PP_CAT(__requirement,i)<NBL_CONCEPT_TPLT_PARAMS()>::value

include/nbl/builtin/hlsl/member_test_macros.hlsl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#ifndef _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
55
#define _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
66

7-
#include <nbl/builtin/hlsl/type_traits.hlsl>
7+
#include <nbl/builtin/hlsl/utility.hlsl>
88
#include <boost/preprocessor.hpp>
99

1010
#ifdef __HLSL_VERSION
@@ -24,9 +24,6 @@ enum e_member_presence
2424
is_const = 1<<2,
2525
};
2626

27-
template<class T>
28-
T declval(){}
29-
3027
template<bool=false>
3128
struct if_2_else_1 : integral_constant<uint32_t,1> {};
3229
template<>
@@ -53,7 +50,7 @@ struct is_static_member_##a<T,typename enable_if<!is_same<decltype(T::a),void>::
5350
template<class T, class=void> \
5451
struct is_member_##a: false_type { using type = void; }; \
5552
template<class T> \
56-
struct is_member_##a<T,typename enable_if<!is_same<decltype(declval<T>().a),void>::value,void>::type> : true_type { using type = decltype(declval<T>().a); }; \
53+
struct is_member_##a<T,typename enable_if<!is_same<decltype(experimental::declval<T>().a),void>::value,void>::type> : true_type { using type = decltype(experimental::declval<T>().a); }; \
5754
} \
5855
template<class T> \
5956
struct has_member_##a { NBL_CONSTEXPR_STATIC_INLINE e_member_presence value = (e_member_presence)(impl::is_member_##a<T>::value + 2*impl::is_static_member_##a<T>::value + 4*is_const<typename impl::is_member_##a<T>::type>::value); }; \
@@ -72,7 +69,7 @@ NBL_GENERATE_MEMBER_TESTER(w)
7269
#define NBL_TYPE_DECLARE(z, n, x) BOOST_PP_COMMA_IF(x) typename Arg##n
7370
#define NBL_TYPE_DECLARE_DEFAULT(z, n, x) BOOST_PP_COMMA_IF(x) typename Arg##n=void
7471
#define NBL_TYPE_FWD(z, n, x) BOOST_PP_COMMA_IF(x) Arg##n
75-
#define NBL_DECLVAL_DECLARE(z, n, x) impl::declval<Arg##n>() BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), x))
72+
#define NBL_DECLVAL_DECLARE(z, n, x) experimental::declval<Arg##n>() BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), x))
7673

7774
#define GENERATE_STATIC_METHOD_TESTER_SPEC(z, n, x) \
7875
template<class T BOOST_PP_REPEAT(n, NBL_TYPE_DECLARE, n)> \
@@ -89,9 +86,9 @@ BOOST_PP_REPEAT(n, GENERATE_STATIC_METHOD_TESTER_SPEC, x)
8986

9087
#define GENERATE_METHOD_TESTER_SPEC(z, n, x) \
9188
template<class T BOOST_PP_REPEAT(n, NBL_TYPE_DECLARE, n)> \
92-
struct has_method_##x<T BOOST_PP_REPEAT(n, NBL_TYPE_FWD, n), typename make_void<decltype(impl::declval<T>().x(BOOST_PP_REPEAT(n, NBL_DECLVAL_DECLARE, n)))>::type> : impl::if_2_else_1<impl::has_static_method_##x<T BOOST_PP_REPEAT(n, NBL_TYPE_FWD, n)>::value> \
89+
struct has_method_##x<T BOOST_PP_REPEAT(n, NBL_TYPE_FWD, n), typename make_void<decltype(experimental::declval<T>().x(BOOST_PP_REPEAT(n, NBL_DECLVAL_DECLARE, n)))>::type> : impl::if_2_else_1<impl::has_static_method_##x<T BOOST_PP_REPEAT(n, NBL_TYPE_FWD, n)>::value> \
9390
{ \
94-
using return_type = decltype(impl::declval<T>().x(BOOST_PP_REPEAT(n, NBL_DECLVAL_DECLARE, n))); \
91+
using return_type = decltype(experimental::declval<T>().x(BOOST_PP_REPEAT(n, NBL_DECLVAL_DECLARE, n))); \
9592
NBL_CONSTEXPR_STATIC_INLINE uint arg_count = n; \
9693
};
9794

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct make_void { using type = void; };
176176

177177
#ifdef __HLSL_VERSION // HLSL
178178

179-
#define decltype(expr) __decltype(expr)
179+
#define decltype(...) __decltype(__VA_ARGS__)
180180

181181
template<class T>
182182
struct type_identity

include/nbl/builtin/hlsl/utility.hlsl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 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_UTILITY_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_UTILITY_INCLUDED_
6+
7+
8+
#include <nbl/builtin/hlsl/type_traits.hlsl>
9+
10+
11+
// for now we only implement declval
12+
namespace nbl
13+
{
14+
namespace hlsl
15+
{
16+
#ifndef __HLSL_VERSION
17+
18+
template<class T>
19+
std::add_rvalue_reference_t<T> declval() noexcept
20+
{
21+
static_assert(false,"Actually calling declval is ill-formed.");
22+
}
23+
24+
#else
25+
26+
namespace experimental
27+
{
28+
29+
template<class T>
30+
T declval() {}
31+
32+
}
33+
34+
#endif
35+
}
36+
}
37+
38+
#endif

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts.hlsl")
256256
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/functional.hlsl")
257257
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/limits.hlsl")
258258
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/type_traits.hlsl")
259+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/utility.hlsl")
259260
#metaprogramming
260261
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/mpl.hlsl")
261262
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/member_test_macros.hlsl")

0 commit comments

Comments
 (0)