11 #ifndef __CE_BufferDevice__
12 #define __CE_BufferDevice__
66 initInternal(
b.size(),
false);
67 myBuffer =
b.myBuffer;
80 if constexpr (SYS_IsSame_v<T, V>)
84 if (bytes %
sizeof(V))
86 UT_ASSERT(!
"Buffer does not fit evenly into reinterpreted type. "
87 "Array view was shortened!");
142 bool block =
true)
const;
165 UTswap(a.myBuffer, b.myBuffer);
166 UTswap(a.mySize, b.mySize);
171 void initInternal(
exint size,
bool doalloc=
true);
175 void releaseBuffer();
181 template <
typename T>
187 if (mySize > 0 && doalloc)
194 template <
typename T>
198 initInternal(size,
true);
201 template <
typename T>
206 size_t size = src.
size();
209 if (len >= 0 && len <= size)
214 size_t totalsize = size *
sizeof(
T);
216 context->writeBuffer(myBuffer, totalsize, src.
data(), blocking);
219 template <
typename T>
225 size_t size = mySize;
228 if (len >= 0 && len <= size)
234 size_t totalsize = size *
sizeof(
T);
238 template <
typename T>
246 size_t totalsize = nelem *
sizeof(
T);
248 context->writeBuffer(myBuffer, totalsize, data, blocking);
251 template <
typename T>
257 myBuffer = context->
allocBuffer(mySize *
sizeof(T));
261 template <
typename T>
270 template <
typename T>
275 size_t size = v.
size();
282 size_t totalsize = size *
sizeof(
T);
CE_BufferDevice(CE_BufferDevice< T > &&b) noexcept
GLenum GLuint GLenum GLsizei const GLchar * buf
void reset(cl::Buffer &&buf, exint size=-1)
void setSizeNoInit(exint newsize)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
void initFromArray(const UT_Array< T > &src, exint len=-1, bool block=true)
Initialize from a UT_Array. If len >= 0, only len elements are copied.
void releaseBuffer(cl::Buffer &&buf, bool use_pool=true)
Release the specified buffer, possibly to the CE_MemoryPool.
GLboolean GLboolean GLboolean GLboolean a
void copyFrom(const CE_BufferDevice< T > &b, exint len=-1)
exint size() const
Returns the buffer length.
static CE_Context * getContext(bool gl_shared=true, bool shared_fallback=true)
void readBuffer(const cl::Buffer &buf, size_t size, void *p, bool blocking=true, size_t offset=0)
Read the specified number of bytes from the buffer.
void initFromData(const T *data, exint nelem, bool block=true)
Initialize from raw data block of T elements of length nelem.
#define utZoneScopedFlag(F)
CE_BufferDevice(cl::Buffer &&buf, exint size=-1)
const CE_ArrayView< V > arrayView() const
cl::Buffer allocBuffer(int64 size, bool use_pool=true, bool read=true, bool write=true, uint32 ogl_bind=SYS_UINT32_MAX)
GLboolean GLboolean GLboolean b
CE_BufferDevice()
Empty buffer constructor.
friend void swap(CE_BufferDevice< T > &a, CE_BufferDevice< T > &b)
CE_ArrayView< V > arrayView()
CE_EXTERN_TEMPLATE(CE_BufferDevice< uint8 >)
const cl::Buffer & buffer() const
bool isEmpty() const
Returns true iff there are no occupied elements in the buffer.
CE_BufferDevice(exint size)
Allocated an uninitialized buffer of specified size (if > 0).
void copyBuffer(const cl::Buffer &src, const cl::Buffer &dst, size_t size, size_t src_offset=0, size_t dst_offset=0)
void matchAndCopyToArray(UT_Array< T > &dst, exint len=-1, bool block=true) const