Skip to content

Commit f65c674

Browse files
committed
Adds new DoubleBdaAccessor
1 parent 22fd9d1 commit f65c674

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

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

Lines changed: 54 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,56 @@ 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+
template<typename S = T>
94+
enable_if_t<is_same_v<S,T> && is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
95+
atomicAdd(const uint64_t index, const T value)
96+
{
97+
bda::__ptr<T> target = outputPtr + index;
98+
return glsl::atomicAdd(target.template deref().get_ptr(), value);
99+
}
100+
101+
template<typename S = T>
102+
enable_if_t<is_same_v<S,T> && is_integral<T>::value && (sizeof(T) == 4 || sizeof(T) == 8), T>
103+
atomicSub(const uint64_t index, const T value)
104+
{
105+
bda::__ptr<T> target = outputPtr + index;
106+
return glsl::atomicSub(target.template deref().get_ptr(), value);
107+
}
108+
109+
bda::__ptr<T> inputPtr, outputPtr;
110+
};
111+
112+
61113
}
62114
}
63115

0 commit comments

Comments
 (0)