Skip to content

Commit c692d01

Browse files
committed
pull from asset-conversion-v3
1 parent fab2b2f commit c692d01

29 files changed

+1031
-285
lines changed

include/nbl/asset/ICPUImage.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class NBL_API2 ICPUImage final : public IImage, public IPreHashed
3333
if(regions && !regions->empty())
3434
cp->regions = core::make_refctd_dynamic_array<decltype(regions)>(*regions);
3535

36-
cp->buffer = (_depth > 0u && buffer) ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(buffer->clone(_depth-1u)) : buffer;
36+
if (_depth > 0u && buffer)
37+
cp->buffer = core::smart_refctd_ptr_static_cast<ICPUBuffer>(buffer->clone(_depth-1u));
38+
else
39+
cp->buffer = buffer;
3740

3841
return cp;
3942
}

include/nbl/builtin/hlsl/bda/__ref.hlsl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
// Copyright (C) 2018-2024 - 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-
5-
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
6-
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
7-
84
#ifndef _NBL_BUILTIN_HLSL_BDA_REF_INCLUDED_
95
#define _NBL_BUILTIN_HLSL_BDA_REF_INCLUDED_
106

7+
#include "nbl/builtin/hlsl/functional.hlsl"
8+
119
namespace nbl
1210
{
1311
namespace hlsl
1412
{
1513
namespace bda
1614
{
1715
template<typename T>
18-
using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer, T>;
16+
using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer,T>;
1917

2018
template<typename T>
2119
struct __ptr;
2220

21+
// TODO: refactor this in terms of `nbl::hlsl::` when they fix the composite struct inline SPIR-V BDA issue
2322
template<typename T, uint32_t alignment, bool _restrict>
2423
struct __base_ref
2524
{
@@ -42,12 +41,12 @@ struct __base_ref
4241

4342
T load()
4443
{
45-
return spirv::load < T, __spv_ptr_t<T>, alignment > (__get_spv_ptr());
44+
return spirv::load<T,alignment>(__get_spv_ptr());
4645
}
4746

4847
void store(const T val)
4948
{
50-
spirv::store < T, __spv_ptr_t<T>, alignment > (__get_spv_ptr(), val);
49+
spirv::store<T,alignment>(__get_spv_ptr(),val);
5150
}
5251
};
5352

include/nbl/builtin/hlsl/bda/bda_accessor.hlsl

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace hlsl
1515
template<typename T>
1616
struct BdaAccessor
1717
{
18+
using type_t = T;
1819
static BdaAccessor<T> create(const bda::__ptr<T> ptr)
1920
{
2021
BdaAccessor<T> accessor;
@@ -28,20 +29,28 @@ struct BdaAccessor
2829
return target.template deref().load();
2930
}
3031

32+
void get(const uint64_t index, NBL_REF_ARG(T) value)
33+
{
34+
bda::__ptr<T> target = ptr + index;
35+
value = target.template deref().load();
36+
}
37+
3138
void set(const uint64_t index, const T value)
3239
{
3340
bda::__ptr<T> target = ptr + index;
3441
return target.template deref().store(value);
3542
}
3643

37-
enable_if_t<is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
44+
template<typename S = T>
45+
enable_if_t<is_same_v<S,T> && is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
3846
atomicAdd(const uint64_t index, const T value)
3947
{
4048
bda::__ptr<T> target = ptr + index;
4149
return glsl::atomicAdd(target.template deref().get_ptr(), value);
4250
}
4351

44-
enable_if_t<is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
52+
template<typename S = T>
53+
enable_if_t<is_same_v<S,T> && is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
4554
atomicSub(const uint64_t index, const T value)
4655
{
4756
bda::__ptr<T> target = ptr + index;
@@ -51,6 +60,40 @@ struct BdaAccessor
5160
bda::__ptr<T> ptr;
5261
};
5362

63+
template<typename T>
64+
struct DoubleBdaAccessor
65+
{
66+
using type_t = T;
67+
static DoubleBdaAccessor<T> create(const bda::__ptr<T> inputPtr, const bda::__ptr<T> outputPtr)
68+
{
69+
DoubleBdaAccessor<T> accessor;
70+
accessor.inputPtr = inputPtr;
71+
accessor.outputPtr = outputPtr;
72+
return accessor;
73+
}
74+
75+
T get(const uint64_t index)
76+
{
77+
bda::__ptr<T> target = inputPtr + index;
78+
return target.template deref().load();
79+
}
80+
81+
void get(const uint64_t index, NBL_REF_ARG(T) value)
82+
{
83+
bda::__ptr<T> target = inputPtr + index;
84+
value = target.template deref().load();
85+
}
86+
87+
void set(const uint64_t index, const T value)
88+
{
89+
bda::__ptr<T> target = outputPtr + index;
90+
return target.template deref().store(value);
91+
}
92+
93+
bda::__ptr<T> inputPtr, outputPtr;
94+
};
95+
96+
5497
}
5598
}
5699

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#define _NBL_BUILTIN_HLSL_BIT_INCLUDED_
33

44

5-
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
5+
#include <nbl/builtin/hlsl/macros.h>
66

77

88
#ifndef __HLSL_VERSION
9-
109
#include <bit>
1110

1211
namespace nbl::hlsl
@@ -25,20 +24,40 @@ NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
2524

2625
}
2726
#else
28-
2927
#include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
3028

3129
namespace nbl
3230
{
3331
namespace hlsl
3432
{
3533

34+
#if 0 // enable this if you run into bit_cast not working for a non fundamental type
35+
template<class T, class U>
36+
enable_if_t<sizeof(T)==sizeof(U)&&(is_scalar_v<T>||is_vector_v<T>)==(is_scalar_v<U>||is_vector_v<U>),T> bit_cast(U val)
37+
{
38+
return spirv::bitcast<T,U>(val);
39+
}
40+
// unfortunately its impossible to deduce Storage Class right now,
41+
// also this function will only work as long as `inout` behaves as `__restrict &` in DXC
42+
template<class T, class U, uint32_t StorageClass>
43+
enable_if_t<sizeof(T)==sizeof(U),T> bit_cast(inout U val)
44+
{
45+
using ptr_u_t = spirv::pointer_t<U,StorageClass>;
46+
// get the address of U
47+
ptr_u_t ptr_u = spirv::copyObject<StorageClass,U>(val);
48+
using ptr_t_t = spirv::pointer_t<T,StorageClass>;
49+
// reinterpret cast the pointers
50+
ptr_t_t ptr_t = spirv::bitcast<ptr_t_t.ptr_u_t>(ptr_u);
51+
// actually load and return the value
52+
return spirv::load<T,ptr_t_t>(ptr_t);
53+
}
54+
#else
3655
template<class T, class U>
37-
T bit_cast(U val)
56+
enable_if_t<sizeof(T)==sizeof(U),T> bit_cast(U val)
3857
{
39-
static_assert(sizeof(T) <= sizeof(U));
40-
return spirv::bitcast<T, U>(val);
58+
return spirv::bitcast<T,U>(val);
4159
}
60+
#endif
4261

4362
template<typename T, typename S>
4463
T rotl(T x, S s);
@@ -94,7 +113,7 @@ uint16_t clz(uint64_t N)
94113
template<>
95114
uint16_t clz<1>(uint64_t N) { return uint16_t(1u-N&1); }
96115

97-
}
116+
} //namespace impl
98117

99118
template<typename T>
100119
uint16_t countl_zero(T n)

include/nbl/builtin/hlsl/complex.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ const static complex_t< SCALAR > multiplies< complex_t< SCALAR > >::identity = {
191191
template<> \
192192
const static complex_t< SCALAR > divides< complex_t< SCALAR > >::identity = { promote< SCALAR , uint32_t>(1), promote< SCALAR , uint32_t>(0)};
193193

194+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t)
195+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t2)
196+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t3)
197+
COMPLEX_ARITHMETIC_IDENTITIES(float16_t4)
194198
COMPLEX_ARITHMETIC_IDENTITIES(float32_t)
195199
COMPLEX_ARITHMETIC_IDENTITIES(float32_t2)
196200
COMPLEX_ARITHMETIC_IDENTITIES(float32_t3)
@@ -287,6 +291,10 @@ COMPLEX_COMPOUND_ASSIGN_IDENTITY(minus, SCALAR) \
287291
COMPLEX_COMPOUND_ASSIGN_IDENTITY(multiplies, SCALAR) \
288292
COMPLEX_COMPOUND_ASSIGN_IDENTITY(divides, SCALAR)
289293

294+
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float16_t)
295+
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float16_t2)
296+
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float16_t3)
297+
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float16_t4)
290298
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float32_t)
291299
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float32_t2)
292300
COMPLEX_COMPOUND_ASSIGN_IDENTITIES(float32_t3)
Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,9 @@
11
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
22
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
33

4-
#include <nbl/builtin/hlsl/macros.h>
5-
6-
#ifndef __HLSL_VERSION
7-
#include <type_traits>
8-
#include <bit>
9-
10-
#define ARROW ->
11-
#define NBL_CONSTEXPR constexpr
12-
#define NBL_CONSTEXPR_STATIC constexpr static
13-
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
14-
#define NBL_CONST_MEMBER_FUNC const
15-
16-
#define NBL_ALIAS_TEMPLATE_FUNCTION(origFunctionName, functionAlias) \
17-
template<typename... Args> \
18-
inline auto functionAlias(Args&&... args) -> decltype(origFunctionName(std::forward<Args>(args)...)) \
19-
{ \
20-
return origFunctionName(std::forward<Args>(args)...); \
21-
}
22-
23-
namespace nbl::hlsl
24-
{
25-
26-
template<typename T>
27-
using add_reference = std::add_lvalue_reference<T>;
28-
29-
template<typename T>
30-
using add_pointer = std::add_pointer<T>;
31-
32-
}
33-
34-
// We need variadic macro in order to handle multi parameter templates because the
35-
// preprocessor parses the template parameters as different macro parameters.
36-
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
37-
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
38-
39-
#else
40-
41-
#define ARROW .arrow().
42-
#define NBL_CONSTEXPR const static
43-
#define NBL_CONSTEXPR_STATIC_INLINE const static
44-
#define NBL_CONST_MEMBER_FUNC
45-
46-
namespace nbl
47-
{
48-
namespace hlsl
49-
{
50-
51-
#if 0 // TODO: for later
52-
template<typename T>
53-
struct add_reference
54-
{
55-
using type = ref<T>;
56-
};
57-
template<typename T>
58-
struct add_pointer
59-
{
60-
using type = ptr<T>;
61-
};
62-
#endif
63-
64-
}
65-
}
66-
67-
#define NBL_REF_ARG(...) inout __VA_ARGS__
68-
#define NBL_CONST_REF_ARG(...) const in __VA_ARGS__
69-
70-
#endif
71-
4+
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
725
// it includes vector and matrix
736
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
7+
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
748

759
#endif
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_BASIC_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_BASIC_INCLUDED_
3+
4+
#include <nbl/builtin/hlsl/macros.h>
5+
6+
#ifndef __HLSL_VERSION
7+
#include <type_traits>
8+
9+
#define ARROW ->
10+
#define NBL_CONSTEXPR constexpr // TODO: rename to NBL_CONSTEXPR_VAR
11+
#define NBL_CONSTEXPR_FUNC constexpr
12+
#define NBL_CONSTEXPR_STATIC constexpr static
13+
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
14+
#define NBL_CONST_MEMBER_FUNC const
15+
16+
namespace nbl::hlsl
17+
{
18+
template<typename T, typename U>
19+
T _static_cast(U v)
20+
{
21+
return static_cast<T>(v);
22+
}
23+
24+
template<typename T>
25+
using add_reference = std::add_lvalue_reference<T>;
26+
27+
template<typename T>
28+
using add_pointer = std::add_pointer<T>;
29+
30+
}
31+
32+
// We need variadic macro in order to handle multi parameter templates because the
33+
// preprocessor parses the template parameters as different macro parameters.
34+
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
35+
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
36+
37+
#else
38+
39+
#define ARROW .arrow().
40+
#define NBL_CONSTEXPR const static // TODO: rename to NBL_CONSTEXPR_VAR
41+
#define NBL_CONSTEXPR_FUNC
42+
#define NBL_CONSTEXPR_STATIC const static
43+
#define NBL_CONSTEXPR_STATIC_INLINE const static
44+
#define NBL_CONST_MEMBER_FUNC
45+
46+
namespace nbl
47+
{
48+
namespace hlsl
49+
{
50+
template<typename T, typename U>
51+
T _static_cast(U v)
52+
{
53+
return (T)v;
54+
}
55+
56+
#if 0 // TODO: for later
57+
template<typename T>
58+
struct add_reference
59+
{
60+
using type = ref<T>;
61+
};
62+
template<typename T>
63+
struct add_pointer
64+
{
65+
using type = ptr<T>;
66+
};
67+
#endif
68+
69+
}
70+
}
71+
72+
#define NBL_REF_ARG(...) inout __VA_ARGS__
73+
#define NBL_CONST_REF_ARG(...) const in __VA_ARGS__
74+
75+
#endif
76+
77+
#endif

0 commit comments

Comments
 (0)