HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_CEAttribute.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: GA_CEAttribute.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  * A GA_Attribute backed on the Compute Engine
10  */
11 
12 #ifndef __GA_CEAttribute__
13 #define __GA_CEAttribute__
14 
15 #include "GA_API.h"
16 
17 #include <CE/CE_Context.h>
18 #include "GA_Detail.h"
19 #include "GA_Attribute.h"
20 
21 #ifdef CE_ENABLED
22 
24 {
25 public:
27 
29  GA_Size tuplesize, bool isarray,
30  cl::Buffer buffer, cl::Buffer indexbuffer,
31  bool leave_on_gpu = false);
32 
33  virtual ~GA_CEAttribute();
34 
35  void clearBuffers();
36 
37  bool isValid() const
38  {
39  return myBuffer();
40  }
41 
42  cl::Buffer buffer() const { return myBuffer; }
43  cl::Buffer indexBuffer() const { return myIndexBuffer; }
44  GA_Size entries() const { return myEntries; }
45  int tupleSize() const { return myTupleSize; }
46  GA_StorageClass storage() const { return myStorage; }
47  GA_Precision precision() const { return myPrecision; }
48  bool isArray() const { return myIsArray; }
49 
50  bool attributeToOCL(const GA_Detail *gdp,
51  GA_AttributeOwner owner,
52  const char *aname,
54  int &tuplesize,
55  bool isarray,
56  bool docopy = true)
57  {
58  return attributeToOCL(gdp, owner, aname, storage, GA_PRECISION_32,
59  tuplesize, isarray, docopy);
60  }
61  bool attributeToOCL(const GA_Detail *gdp,
62  GA_AttributeOwner owner,
63  const char *aname,
66  int &tuplesize,
67  bool isarray,
68  bool docopy = true)
69  {
70  if (!gdp) return false;
71  if (!UTisstring(aname))
72  return false;
73  const GA_Attribute *attrib = gdp->getAttributes().findAttribute(owner, aname);
74  if (!attrib)
75  return false;
76  return attributeToOCL(attrib, storage, precision, tuplesize, isarray, docopy);
77  }
78  bool attributeToOCL(const GA_Attribute *attrib,
79  GA_StorageClass storage,
80  GA_Precision precision,
81  int &tuplesize,
82  bool isarray,
83  bool docopy = true);
84 
85  bool intToOCL(const UT_Array<int64> &data,
86  GA_StorageClass storage,
87  GA_Precision precision,
88  bool docopy = true);
89 
90  bool intArrayToOCL(const UT_Array<UT_Array<int64>> &data,
91  GA_StorageClass storage,
92  GA_Precision precision,
93  bool docopy = true);
94 
95  bool packedIntArrayToOCL(
97  GA_StorageClass storage,
98  GA_Precision precision,
99  bool docopy = true);
100 
101  bool oclToAttribute(GA_Detail *gdp, GA_AttributeOwner owner, const char *aname)
102  {
103  if (!gdp) return false;
104  if (!UTisstring(aname))
105  return false;
106  GA_Attribute *attrib = gdp->getAttributes().findAttribute(owner, aname);
107  if (!attrib)
108  return false;
109  return oclToAttribute(attrib);
110  }
111  bool oclToAttribute(GA_Attribute *attrib);
112 
113  bool isWriteBackRequired() const { return myWriteBackRequired; }
114  void setWriteBackRequired(bool isrequired) { myWriteBackRequired = isrequired; }
115 
116 protected:
117 
118  // GPU Buffers:
119  cl::Buffer myBuffer;
120  cl::Buffer myIndexBuffer;
121 
122  // CPU Buffers:
123  UT_Array<cl_int> myIndexArray;
124  // It would be much more proper to use cl_half here, but that
125  // is not a computable type so it is easy to accidentally cast
126  // fprealy16 to short silently. Instead we rely on bit equivalency.
127  UT_Array<fpreal16> myFloat16Array;
128  UT_Array<cl_float> myFloat32Array;
129  UT_Array<cl_double> myFloat64Array;
130  UT_Array<cl_short> myInt16Array;
131  UT_Array<cl_int> myInt32Array;
132  UT_Array<cl_long> myInt64Array;
133 
134  // Number of entries.
135  GA_Size myEntries;
136  GA_Size myTupleSize;
137  GA_StorageClass myStorage;
138  GA_Precision myPrecision;
139  bool myIsArray;
140 
141  // Whether the buffer has been written to by CE
142  bool myWriteBackRequired;
143 };
144 
145 #else
146 
148 {
149 public:
150 };
151 
152 #endif
153 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
__hostdev__ bool isValid(GridType gridType, GridClass gridClass)
return true if the combination of GridType and GridClass is valid.
Definition: NanoVDB.h:860
GA_StorageClass
Definition: GA_Types.h:73
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GA_Precision
Definition: GA_Types.h:88
#define GA_API
Definition: GA_API.h:14
GLuint buffer
Definition: glcorearb.h:660
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
Definition: core.h:760
GA_AttributeSet & getAttributes()
Definition: GA_Detail.h:799
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
GA_AttributeOwner
Definition: GA_Types.h:35
SYS_FORCE_INLINE bool UTisstring(const char *s)
Memory buffer interface.
Definition: cl.hpp:1867
Container class for all geometry.
Definition: GA_Detail.h:96
SYS_FORCE_INLINE const GA_Attribute * findAttribute(GA_AttributeScope scope, const UT_StringRef &name, const GA_AttributeOwner search_order[], int search_order_size) const
Definition: format.h:895