Skip to content

Commit ce9ca3d

Browse files
Merge pull request #801 from Devsh-Graphics-Programming/cpp_compat_intrinsics_refactor
Cpp compat intrinsics refactor
2 parents b700c8d + 7528d4e commit ce9ca3d

File tree

17 files changed

+865
-169
lines changed

17 files changed

+865
-169
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef _NBL_BUILTIN_HLSL_ARRAY_ACCESSORS_HLSL_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_ARRAY_ACCESSORS_HLSL_INCLUDED_
3+
4+
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
5+
6+
namespace nbl
7+
{
8+
namespace hlsl
9+
{
10+
template<typename ArrayType, typename ComponentType, typename I = uint32_t>
11+
struct array_get
12+
{
13+
ComponentType operator()(NBL_CONST_REF_ARG(ArrayType) arr, const I ix) NBL_CONST_MEMBER_FUNC
14+
{
15+
return arr[ix];
16+
}
17+
};
18+
19+
template<typename ArrayType, typename ComponentType, typename I = uint32_t>
20+
struct array_set
21+
{
22+
void operator()(NBL_REF_ARG(ArrayType) arr, I index, ComponentType val) NBL_CONST_MEMBER_FUNC
23+
{
24+
arr[index] = val;
25+
}
26+
};
27+
}
28+
}
29+
30+
#endif

include/nbl/builtin/hlsl/cpp_compat.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
55
// it includes vector and matrix
6-
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
6+
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
77
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
88

99
#endif

include/nbl/builtin/hlsl/cpp_compat/basic.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ namespace nbl::hlsl
5555

5656
// We need variadic macro in order to handle multi parameter templates because the
5757
// preprocessor parses the template parameters as different macro parameters.
58-
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
59-
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
58+
#define NBL_REF_ARG(...) __VA_ARGS__&
59+
#define NBL_CONST_REF_ARG(...) const __VA_ARGS__&
60+
61+
// NOTE: implementation below will mess up template parameter deduction
62+
//#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
63+
//#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
6064

6165
#else
6266

0 commit comments

Comments
 (0)