11 #ifndef __CE_VDBCreate__
12 #define __CE_VDBCreate__
35 static inline void ptrAssert(
const void*
ptr,
const char* msg,
const char* file,
int line)
49 #define checkPtr(ptr, msg) \
51 ptrAssert((ptr), (msg), __FILE__, __LINE__); \
78 , mGpuData(cl::Buffer())
80 if (size > 0) this->
init(size, host);
89 , mCpuData(other.mCpuData)
90 , mGpuData(other.mGpuData)
93 other.mCpuData =
nullptr;
105 mCpuData = other.mCpuData;
106 mGpuData = other.mGpuData;
108 other.mCpuData =
nullptr;
121 void init(uint64_t size,
bool host =
true);
125 uint8_t*
data()
const {
return mCpuData; }
146 uint64_t
size()
const {
return mSize; }
150 bool empty()
const {
return mSize == 0; }
179 mCpuData =
new uint8_t[
size];
180 checkPtr(mCpuData,
"OclDeviceBuffer::init: failed to allocate host buffer");
186 checkPtr(mGpuData(),
"OclDeviceBuffer::init: failed to allocate device buffer");
195 checkPtr(mCpuData,
"uninitialized cpu data");
196 if (mGpuData() ==
nullptr) {
199 checkPtr(mGpuData(),
"uninitialized gpu data");
208 checkPtr(mGpuData(),
"uninitialized gpu data");
209 if (mCpuData ==
nullptr) {
210 mCpuData =
new uint8_t[mSize];
212 checkPtr(mCpuData,
"uninitialized cpu data");
214 context->
readBuffer(mGpuData, mSize, mCpuData);
220 if (mGpuData() !=
nullptr) context->
releaseBuffer(std::move(mGpuData));
221 if (mCpuData !=
nullptr)
delete[] mCpuData;
240 uint32_t bit_shift_right = 0);
250 uint32_t buffer_nelem = -1);
260 const uint32_t leafdilation,
263 const BuildT& bgvalue,
265 exint& tilestartcount,
266 void** datacacheptr);
268 template <
typename BuildT>
269 static void deleteDataCache(
void* datacacheptr);
void releaseBuffer(cl::Buffer &&buf)
Release the specified buffer, possibly to the CE_MemoryPool.
const cl::Buffer & deviceData() const
Retuns a cl::Buffer ref to the device/GPU buffer managed by this allocator.
GridClass
Classes (superset of OpenVDB) that are currently supported by NanoVDB.
#define checkPtr(ptr, msg)
#define UTdebugFormatCd(...)
OclDeviceBuffer(uint64_t size=0, bool host=true)
Constructor.
uint8_t * data() const
Retuns a raw pointer to the host/CPU buffer managed by this allocator.
OclDeviceBuffer & operator=(OclDeviceBuffer &&other) noexcept
Move copy assignment operation.
void init(uint64_t size, bool host=true)
Initialize buffer.
void writeBuffer(const cl::Buffer &buf, size_t size, const void *p, bool blocking=true, size_t offset=0)
Write the specified number of bytes to the buffer.
Defines GridHandle, which manages a host, and possibly a device, memory buffer containing one or more...
uint64_t size() const
Returns the size in bytes of the raw memory buffer managed by this allocator.
This class serves to manage a buffer containing one or more NanoVDB Grids.
#define NANOVDB_DATA_ALIGNMENT
static CE_Context * getContext(bool gl_shared=true, bool shared_fallback=true)
~OclDeviceBuffer()
Destructor frees memory on both the host and device.
Implements a light-weight self-contained VDB data-structure in a single file! In other words...
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.
static OclDeviceBuffer create(uint64_t size, bool host=true)
Static factory method that return an instance of this buffer.
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
OclDeviceBuffer & operator=(const OclDeviceBuffer &)=delete
Disallow copy assignment operation.
static constexpr bool hasDeviceDual
bool isEmpty() const
Returns true if this allocator is empty, i.e. has no allocated memory.
void clear()
De-allocate all memory managed by this allocator and set all pointers to NULL.
void deviceUpload(void *stream=nullptr, bool sync=true)
Upload this buffer from the host to the device, i.e. CPU -> GPU.
GLenum GLsizei GLsizei GLint * values
void deviceDownload(void *stream=nullptr, bool sync=true)
Upload this buffer from the device to the host, i.e. GPU -> CPU.
OclDeviceBuffer(OclDeviceBuffer &&other) noexcept
Move copy-constructor.
bool empty() const
Returns true if this allocator is empty, i.e. has no allocated memory.
png_structrp int png_fixed_point red
cl::Buffer allocBuffer(int64 size, bool usePool=true, bool read=true, bool write=true, uint32 ogl_bind=SYS_UINT32_MAX)