HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Blend.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: GU_Blend.h (C++)
7  *
8  * COMMENTS: Functions for blending between details.
9  *
10  */
11 
12 
13  #ifndef __GU_BLEND_H__
14 #define __GU_BLEND_H__
15 
16 #include "GU_API.h"
17 
18 #include <CE/CE_BufferDevice.h>
19 #include <CE/CE_Context.h>
20 #include <GA/GA_CEAttribute.h>
21 #include <GA/GA_IndexMap.h>
22 #include <GA/GA_Names.h>
23 #include <GA/GA_Types.h>
24 #include <UT/UT_Array.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <SYS/SYS_Types.h>
27 
28 class GA_Attribute;
29 class GA_Group;
30 class GA_Range;
31 class GU_Detail;
32 class UT_OptionsHolder;
33 class UT_StringRef;
34 
35 enum class GU_VoxelBlend
36 {
37  None,
39  ByVoxelPos,
40  Advected
41 };
42 
43 enum class GU_MaskMode
44 {
45  None,
48 };
49 
50 namespace GU_Blend
51 {
53 {
58 };
59 template <typename T>
61 {
66 };
67 
69 {
71  bool myHasIdAttribMapping = false;
72  bool myIdAttribDataIdIsSame = false;
73 };
74 
75 struct MaskData
76 {
79  int mySource;
80 };
81 
82 // OpenCL delta mode
83 enum DeltaModeOCL : uint8_t
84 {
87 };
88 
89 // Compressed Sparse
91 {
96 };
97 
99 {
100 public:
102 
103  GU_API void initPerFrameOCL(
104  bool use_opencl,
105  const GA_IndexMap *index_map,
106  DeltaModeOCL dense_mode = DENSE_MODE);
107 
108  void clearOCL();
109 
111  const UT_Array<UT_Array<float>> &cpu_deltas,
112  const UT_Array<UT_Array<int>> &page_offsets,
113  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
114  int num_shapes,
115  int tuple_size);
116 
118  const UT_Array<UT_Array<float>> &cpu_deltas,
119  const UT_Array<UT_Array<int>> &page_offsets,
120  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
121  int num_shapes,
122  int tuple_size);
123 
124  void prepareWeightsOCL(const float *cpu_weights, int num_shapes);
125 
126  void setCopyKernelArgOCL(GA_Attribute *data_attrib, int num_tuples);
127  void setSparseKernelArgOCL(GA_Attribute *data_attrib, int num_tuple);
129  GA_Attribute *data_attrib,
130  int num_tuples,
131  int num_shapes);
132 
133  void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples);
134  void applySparseDeltaOCL(
135  GA_Attribute *data_attrib,
136  int num_shape,
137  int num_tuple);
138  void applyDenseDeltaOCL(
139  GA_Attribute *data_attrib,
140  int num_shapes,
141  int num_tuples);
142 
143  void setRedoDeltaOCL(bool redo_delta) { myRedoDelta = redo_delta; }
144 
145  bool useOCL() { return myUseOCL; }
146  bool isInitOCL() { return myInitOCL; }
147  DeltaModeOCL deltaModeOCL() { return myDeltaModeOCL; }
148  bool switchDeltaModeOCL() { return mySwitchDeltaModeOCL; }
149  bool redoDelta() { return myRedoDelta; }
150  bool isDeltaBufferEmpty() { return myIsDeltaEmpty; }
151 
152 private:
153  bool myUseOCL;
154  bool myInitOCL;
155  DeltaModeOCL myDeltaModeOCL;
156  bool mySwitchDeltaModeOCL;
157  bool myRedoDelta;
158  bool myIsDeltaEmpty;
159 
160  GA_DataId mySrcDataID;
161  exint myNpts;
162  exint myNumHeaders;
163 
164  const GA_IndexMap *myPtMap;
165 
166  cl::Program myOCLProgram;
167  cl::Kernel myApplyDeltaKernel;
168 
169  GA_CEAttributePtr mySrcCEAttrib;
170  GA_CEAttributeAccessorPtr mySrcCEAccessorPtr;
171 
172  CE_BufferDevice<float> myDeltasBuffer;
173  CE_BufferDevice<SparseHeader> myCSHeadersBufffer;
174  CE_BufferDevice<int> myPointIndicesBuffer;
175  CE_BufferDevice<float> myWeightsBuffer;
176 };
177 
178 /// This cache can be used to accelerate successive blends. However,
179 /// it is all references to *external* data.
180 /// It also does *NOT* detect if the id attribute names change, so the
181 /// caller is expected to clear the cache in that case.
183 {
184 public:
195 };
196 template <typename T>
198 {
199 public:
209 };
210 }
211 
212 /// If deleteUnmatched is true, points that don't have a match to interpolate with are deleted.
213 /// If deleteUnmatched is false but unmatchedGroupName is given (non-NULL), then these points
214 /// are instead put into a point group of the specified name.
215 /// Note that points of volume and VDB primitives are neither deleted nor put into the group.
216 GU_API void GUblend(
217  GU_Detail *dest, const GU_Detail *source, fpreal weight,
218  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
219  bool doslerp = true, bool usevforpinterp = false, float timestep = (1/24.0),
220  GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL, const char *velname = "vel",
221  float advdt = 1, bool deleteUnmatched = false, const char *unmatchedGroupName = NULL);
222 
223 /// If deleteUnmatched is non-zero, points that have fewer than that many interpolation sources
224 /// are deleted from the output (or put into the specified group if unmatchedGroupName is not
225 /// NULL).
226 /// NOTE: Advected volume interpolation is necessarily linear; in that case, volweight is needed to determine
227 /// which detail to blend with and by how much.
228 GU_API void GUblend(
229  GU_Detail *dest, const GU_Detail *gdps[], const float *weights, int size, const GA_Group *group,
230  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
231  bool doslerp = true, GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL,
232  bool is_differencing = true, bool dosparse = false,
233  float timestep = (1/24.0), const char *velname = "vel", float advdt = 1, fpreal volweight = 0,
234  int deleteUnmatched = 0, const char *unmatchedGroupName = NULL,
235  const GU_Blend::MaskData * mask_data = NULL,
236  float total = 1);
237 
238 /// Blend the attribute values for the given range, with an optional mapping to
239 /// different offsets in the second detail.
240 /// If set, the weights and mapping arrays should be at least as long as attrib0's offset
241 /// map (attrib0.getIndexMap().offsetSize()).
242 /// @{
243 GU_API void GUblendRange(
244  GA_Attribute &attrib0,
245  const GA_Attribute &attrib1,
246  const GA_Range &range0,
247  float weight,
248  const UT_Array<GA_Offset> *mapping);
249 
250 GU_API void GUblendRange(
251  GA_Attribute &attrib0,
252  const GA_Attribute &attrib1,
253  const GA_Range &range0,
254  const UT_Array<float> &weights,
255  const UT_Array<GA_Offset> *mapping);
256 /// @}
257 
258 /// Calculate the blend weight for an in-between shape given the channel weight
259 /// and a list of all in-between weights
261  float channel_weight,
262  const UT_Array<float> &inbetween_weights,
263  int inbetween_idx);
264 
265 
266 /// Blend float entries from 2 geometry dict detail attributes.
267 /// This assumes the attributes have the same attribute name on both geometries.
268 /// The `keys` argument is an array of string containing a key to match at each level.
269 /// This was implemented to blend a float 'value' entry inside a nested dict.
271  GU_Detail *gdp,
272  const GU_Detail *gdp1,
273  const UT_StringHolder &attribute,
274  const UT_StringArray &keys,
275  const fpreal64 blend);
276 
277 GU_API bool GUblendDict(
278  UT_OptionsHolder &opt0,
279  const UT_OptionsHolder &opt1,
280  const UT_StringArray &keys,
281  const fpreal64 blend);
282 #endif
UT_Array< GA_Offset > myArrayOfOffsets
Definition: GU_Blend.h:70
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
UT_SharedPtr< GA_CEAttribute > GA_CEAttributePtr
Definition: GA_Attribute.h:56
Definition of a geometry attribute.
Definition: GA_Attribute.h:203
void prepareDenseDeltasOCL(const UT_Array< UT_Array< float >> &cpu_deltas, const UT_Array< UT_Array< int >> &page_offsets, const UT_Array< UT_Array< std::pair< GA_PageNum, exint >>> &page_starts, int num_shapes, int tuple_size)
void prepareWeightsOCL(const float *cpu_weights, int num_shapes)
UT_Array< PerAttribData > * myVertexArrayOfPerAttribData
Definition: GU_Blend.h:187
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:188
UT_Array< UT_Array< int > > myArrayOfPageOffsets
Definition: GU_Blend.h:63
int64 GA_DataId
Definition: GA_Types.h:703
UT_Array< PerAttribDataT< T > > * myPtArrayOfPerAttribData
Definition: GU_Blend.h:200
UT_Array< PerAttribData > * myPtArrayOfPerAttribData
Definition: GU_Blend.h:185
int64 exint
Definition: SYS_Types.h:125
UT_Array< UT_Array< std::pair< GA_PageNum, exint > > > myArrayOfPageStarts
Definition: GU_Blend.h:64
UT_Array< int64 > * myPrimListDataIds
Definition: GU_Blend.h:206
GU_API bool GUblendDict(UT_OptionsHolder &opt0, const UT_OptionsHolder &opt1, const UT_StringArray &keys, const fpreal64 blend)
void setRedoDeltaOCL(bool redo_delta)
Definition: GU_Blend.h:143
UT_Array< PerAttribDataT< T > > * myVertexArrayOfPerAttribData
Definition: GU_Blend.h:202
A range of elements in an index-map.
Definition: GA_Range.h:42
CachedItemsOCL * myCachedItemsOCL
Definition: GU_Blend.h:194
GA_API const UT_StringHolder name
double fpreal64
Definition: SYS_Types.h:201
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4949
UT_Array< UT_Array< int > > myArrayOfPageOffsets
Definition: GU_Blend.h:55
UT_Array< int64 > * myPrimListDataIds
Definition: GU_Blend.h:191
GU_API float GUgetInbetweenWeight(float channel_weight, const UT_Array< float > &inbetween_weights, int inbetween_idx)
DeltaModeOCL deltaModeOCL()
Definition: GU_Blend.h:147
GA_PageNum pageNum
Definition: GU_Blend.h:93
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
UT_Array< UT_Array< std::pair< GA_PageNum, exint > > > myArrayOfPageStarts
Definition: GU_Blend.h:56
UT_Array< PerAttribData > * myPrimArrayOfPerAttribData
Definition: GU_Blend.h:186
GU_MaskMode myMode
Definition: GU_Blend.h:77
long long int64
Definition: SYS_Types.h:116
GU_MaskMode
Definition: GU_Blend.h:43
#define GU_API
Definition: GU_API.h:14
GU_API bool GUblendDetailDict(GU_Detail *gdp, const GU_Detail *gdp1, const UT_StringHolder &attribute, const UT_StringArray &keys, const fpreal64 blend)
GLushort pattern
Definition: glad.h:2583
GA_API const UT_StringHolder id
GU_VoxelBlend
Definition: GU_Blend.h:35
UT_Array< int64 > * myPtTopoDataIds
Definition: GU_Blend.h:190
void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples)
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:203
UT_SharedPtr< GA_CEAttributeAccessor > GA_CEAttributeAccessorPtr
Definition: GA_Attribute.h:59
GU_API void GUblendRange(GA_Attribute &attrib0, const GA_Attribute &attrib1, const GA_Range &range0, float weight, const UT_Array< GA_Offset > *mapping)
void setCopyKernelArgOCL(GA_Attribute *data_attrib, int num_tuples)
GLsizeiptr size
Definition: glcorearb.h:664
void setSparseKernelArgOCL(GA_Attribute *data_attrib, int num_tuple)
UT_Array< int64 > myArrayOfDataId
Definition: GU_Blend.h:57
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_Array< int64 > myArrayOfDataId
Definition: GU_Blend.h:65
GA_Size GA_PageNum
Definition: GA_Types.h:656
UT_StringRef myAttribName
Definition: GU_Blend.h:78
void applyDenseDeltaOCL(GA_Attribute *data_attrib, int num_shapes, int num_tuples)
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
void setDenseKernelArgOCL(GA_Attribute *data_attrib, int num_tuples, int num_shapes)
DeltaModeOCL
Definition: GU_Blend.h:83
int64 * myPrimIdDataId
Definition: GU_Blend.h:193
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2544
void prepareSparseDeltasOCL(const UT_Array< UT_Array< float >> &cpu_deltas, const UT_Array< UT_Array< int >> &page_offsets, const UT_Array< UT_Array< std::pair< GA_PageNum, exint >>> &page_starts, int num_shapes, int tuple_size)
UT_Array< PerAttribDataT< T > > * myPrimArrayOfPerAttribData
Definition: GU_Blend.h:201
UT_Array< UT_Array< T > > myArrayOfDeltas
Definition: GU_Blend.h:62
UT_Array< int64 > * myPtTopoDataIds
Definition: GU_Blend.h:205
GU_API void initPerFrameOCL(bool use_opencl, const GA_IndexMap *index_map, DeltaModeOCL dense_mode=DENSE_MODE)
void applySparseDeltaOCL(GA_Attribute *data_attrib, int num_shape, int num_tuple)
Program interface that implements cl_program.
Definition: cl.hpp:2649
UT_Array< UT_Array< float > > myArrayOfDeltas
Definition: GU_Blend.h:54
GU_API void GUblend(GU_Detail *dest, const GU_Detail *source, fpreal weight, const char *pattern="*", const UT_StringRef &ptidattr=GA_Names::id, const UT_StringRef &primidattr=GA_Names::name, bool doslerp=true, bool usevforpinterp=false, float timestep=(1/24.0), GU_VoxelBlend dovoxel=GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items=NULL, const char *velname="vel", float advdt=1, bool deleteUnmatched=false, const char *unmatchedGroupName=NULL)
UT_Array< PerMappingData > * myPrimArrayOfPerMappingData
Definition: GU_Blend.h:189
UT_Array< PerMappingData > * myPrimArrayOfPerMappingData
Definition: GU_Blend.h:204