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 static inline void bufferAssert(
const void*
buf,
const char* msg,
const char* file,
int line)
58 #define checkPtr(ptr, msg) \
60 ptrAssert((ptr), (msg), __FILE__, __LINE__); \
63 #define checkBuffer(buf, msg) \
65 bufferAssert((buf), (msg), __FILE__, __LINE__); \
92 , mGpuData(cl::Buffer())
94 if (size > 0) this->
init(size, host);
103 , mCpuData(other.mCpuData)
104 , mGpuData(other.mGpuData)
107 other.mCpuData =
nullptr;
119 mCpuData = other.mCpuData;
120 mGpuData = other.mGpuData;
122 other.mCpuData =
nullptr;
135 void init(uint64_t size,
bool host =
true);
139 uint8_t*
data()
const {
return mCpuData; }
160 uint64_t
size()
const {
return mSize; }
164 bool empty()
const {
return mSize == 0; }
193 mCpuData =
new uint8_t[
size];
194 checkPtr(mCpuData,
"OclDeviceBuffer::init: failed to allocate host buffer");
200 checkBuffer(mGpuData(),
"OclDeviceBuffer::init: failed to allocate device buffer");
209 checkPtr(mCpuData,
"uninitialized cpu data");
210 if (mGpuData() ==
nullptr) {
223 if (mCpuData ==
nullptr) {
224 mCpuData =
new uint8_t[mSize];
226 checkPtr(mCpuData,
"uninitialized cpu data");
228 context->
readBuffer(mGpuData, mSize, mCpuData);
234 if (mGpuData() !=
nullptr) context->
releaseBuffer(std::move(mGpuData));
235 if (mCpuData !=
nullptr)
delete[] mCpuData;
254 uint32_t bit_shift_right = 0);
264 uint32_t buffer_nelem = -1);
274 const bool activateleaves,
275 const uint32_t leafdilation,
278 const BuildT& bgvalue,
283 void** datacacheptr);
285 template <
typename BuildT>
286 static void deleteDataCache(
void* datacacheptr);
GLenum GLuint GLenum GLsizei const GLchar * buf
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(...)
void releaseBuffer(cl::Buffer &&buf, bool use_pool=true)
Release the specified buffer, possibly to the CE_MemoryPool.
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 ...
#define checkBuffer(buf, msg)
OclDeviceBuffer & operator=(const OclDeviceBuffer &)=delete
Disallow copy assignment operation.
static constexpr bool hasDeviceDual
cl::Buffer allocBuffer(int64 size, bool use_pool=true, bool read=true, bool write=true, uint32 ogl_bind=SYS_UINT32_MAX)
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