Skip to content

Commit

Permalink
Merge pull request #801 from Devsh-Graphics-Programming/cpp_compat_in…
Browse files Browse the repository at this point in the history
…trinsics_refactor

Cpp compat intrinsics refactor
  • Loading branch information
devshgraphicsprogramming authored Dec 18, 2024
2 parents b700c8d + 7528d4e commit ce9ca3d
Show file tree
Hide file tree
Showing 17 changed files with 865 additions and 169 deletions.
2 changes: 1 addition & 1 deletion examples_tests
30 changes: 30 additions & 0 deletions include/nbl/builtin/hlsl/array_accessors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef _NBL_BUILTIN_HLSL_ARRAY_ACCESSORS_HLSL_INCLUDED_
#define _NBL_BUILTIN_HLSL_ARRAY_ACCESSORS_HLSL_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat/basic.h>

namespace nbl
{
namespace hlsl
{
template<typename ArrayType, typename ComponentType, typename I = uint32_t>
struct array_get
{
ComponentType operator()(NBL_CONST_REF_ARG(ArrayType) arr, const I ix) NBL_CONST_MEMBER_FUNC
{
return arr[ix];
}
};

template<typename ArrayType, typename ComponentType, typename I = uint32_t>
struct array_set
{
void operator()(NBL_REF_ARG(ArrayType) arr, I index, ComponentType val) NBL_CONST_MEMBER_FUNC
{
arr[index] = val;
}
};
}
}

#endif
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/cpp_compat.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <nbl/builtin/hlsl/cpp_compat/basic.h>
// it includes vector and matrix
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>

#endif
8 changes: 6 additions & 2 deletions include/nbl/builtin/hlsl/cpp_compat/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ namespace nbl::hlsl

// We need variadic macro in order to handle multi parameter templates because the
// preprocessor parses the template parameters as different macro parameters.
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
#define NBL_REF_ARG(...) __VA_ARGS__&
#define NBL_CONST_REF_ARG(...) const __VA_ARGS__&

// NOTE: implementation below will mess up template parameter deduction
//#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
//#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type

#else

Expand Down
Loading

0 comments on commit ce9ca3d

Please sign in to comment.