HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_VDBGrid.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CE_VDBGrid.h ( CE Library, C++)
7  *
8  * COMMENTS: Compute Engine Grid.
9  */
10 
11 #ifndef __CE_VDBGrid__
12 #define __CE_VDBGrid__
13 
14 #include "CE_API.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_VectorTypes.h>
19 #include <UT/UT_VDBUtils.h>
20 
21 #include <SYS/SYS_Types.h>
22 
23 #include <openvdb/Platform.h>
24 #include <openvdb/openvdb.h>
25 
26 #include "CE_BufferHost.h"
27 
29 {
30 public:
33  {
34  releaseBuffer();
35  };
36 
38 
39  /// Return the underlying OpenCL buffer that can be used in kernel
40  /// invocations.
41  const cl::Buffer &buffer() const { return myBuffer; }
42  exint bufferSize() const { return myBufferSize; }
43 
45  {
46  if (isValid()) return bufferSize();
47  return 0;
48  }
49 
50  /// Deep copy from another grid into this,
51  /// if readsrc is false, will only allocate matching size.
52  void copy(const CE_VDBGrid &src, bool readsrc = true);
53 
54  UT_VDBType storageType() const { return myStorageType; }
55 
56  /// If the current OpenCL buffer is valid.
57  bool hasBuffer() const { return (myBuffer() != 0);}
58  bool isValid() const { return (myBuffer() != 0);}
59 
60  /// Initialize the CE_VDBGrid from the supplied VDB grid.
61  void initFromVDB(const openvdb::GridBase &grid);
62 
63  /// Builds a CPU buffer from the VDB provided:
64  /// The result is SYSamalloc so must be SYSafreed.
65  static void *allocAlignedBufferFromVDB(const openvdb::GridBase &grid,
66  exint &size);
67 
68  /// Initialize the CE_VDBGrid from the supplied buffers of a nanovdb.
69  void initFromDeviceBuffers(
70  cl::Buffer gridbuffer, exint gridsize,
71  UT_VDBType storagetype);
72 
73  /// Replaces the map transform with the provided one.
74  void updateTransform(const UT_Matrix3D &xform,
75  const UT_Vector3D &center,
76  const UT_Vector3D &voxelsize,
77  double taper);
78 
79  /// Initialize from a memory pointer and size.
80  /// This will blocking-write to GPU data.
81  void initFromBuffers(const void *data, exint datasize,
82  UT_VDBType storagetype);
83  /// Initialize from a given size, allocating only assuming
84  /// later code will write to it..
85  void initFromSize(exint datasize,
86  UT_VDBType storagetype);
87 
88  /// Utility function to build an tilestart array from a grid.
89  static void buildTileStartsArray(UT_Array<UT_Vector3i> &starts,
90  exint &leafcount,
91  exint &lowercount,
92  exint &uppercount,
93  const openvdb::GridBase &grid);
94 
95  /// Utility function to build an tilestart array from a nanovdb on cpu.
96  static void buildTileStartsArray(UT_Array<UT_Vector3i> &starts,
97  exint &leafcount,
98  exint &lowercount,
99  exint &uppercount,
100  const CE_BufferHostByte &cpugrid);
101 
102  /// Create a VDB grid from the CE VDB grid
103  openvdb::GridBase::Ptr createVDB() const;
104 
105  /// Create a VDB grid from generic memory.
106  /// NanoVDB requires 32 byte aligned buffers.
107  static openvdb::GridBase::Ptr createVDBFromAlignedBuffer(const void *data, exint datasize);
108 
109 protected:
110 
111  void releaseBuffer();
112 
114  exint myBufferSize = -1;
115 
116  UT_VDBType myStorageType = UT_VDB_INVALID;
117 };
118 
119 #endif
120 
#define CE_API
Definition: CE_API.h:13
bool isValid() const
Definition: CE_VDBGrid.h:58
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
int64 exint
Definition: SYS_Types.h:125
UT_VDBType
Definition: UT_VDBUtils.h:25
GLuint buffer
Definition: glcorearb.h:660
exint bufferSize() const
Definition: CE_VDBGrid.h:42
exint getDeviceMemoryUsage() const
Definition: CE_VDBGrid.h:44
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
UT_VDBType storageType() const
Definition: CE_VDBGrid.h:54
GLsizeiptr size
Definition: glcorearb.h:664
cl::Buffer myBuffer
Definition: CE_VDBGrid.h:113
Memory buffer interface.
Definition: cl.hpp:1867
bool hasBuffer() const
If the current OpenCL buffer is valid.
Definition: CE_VDBGrid.h:57
Definition: format.h:1821
GLenum src
Definition: glcorearb.h:1793