Skip to content

Commit f7c05ad

Browse files
Merge pull request #732 from Devsh-Graphics-Programming/double_bda_accessor
Adds new DoubleBdaAccessor
2 parents 22fd9d1 + f9d6c1a commit f7c05ad

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ struct BdaAccessor
4141
return target.template deref().store(value);
4242
}
4343

44-
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>
4546
atomicAdd(const uint64_t index, const T value)
4647
{
4748
bda::__ptr<T> target = ptr + index;
4849
return glsl::atomicAdd(target.template deref().get_ptr(), value);
4950
}
5051

51-
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>
5254
atomicSub(const uint64_t index, const T value)
5355
{
5456
bda::__ptr<T> target = ptr + index;
@@ -58,6 +60,40 @@ struct BdaAccessor
5860
bda::__ptr<T> ptr;
5961
};
6062

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+
6197
}
6298
}
6399

0 commit comments

Comments
 (0)