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 
22 {
23 public:
25 
27  GA_Size tuplesize, bool isarray,
28  cl::Buffer buffer, cl::Buffer indexbuffer,
29  bool leave_on_gpu = false);
30 
31  virtual ~GA_CEAttribute();
32 
33  void clearBuffers();
34 
35  bool isValid() const
36  {
37  return myBuffer();
38  }
39 
40  int64 getDeviceMemoryUsage() const;
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,
53  GA_StorageClass storage,
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,
64  GA_StorageClass storage,
65  GA_Precision precision,
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:
121 
122  // CPU Buffers:
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.
133 
134  // Number of entries.
139  bool myIsArray;
140 
141  // Whether the buffer has been written to by CE
143 };
144 
145 #endif
int tupleSize() const
bool attributeToOCL(const GA_Detail *gdp, GA_AttributeOwner owner, const char *aname, GA_StorageClass storage, int &tuplesize, bool isarray, bool docopy=true)
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GA_StorageClass
Definition: GA_Types.h:73
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GA_Precision
Definition: GA_Types.h:88
bool attributeToOCL(const GA_Detail *gdp, GA_AttributeOwner owner, const char *aname, GA_StorageClass storage, GA_Precision precision, int &tuplesize, bool isarray, bool docopy=true)
GA_Precision precision() const
#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
cl::Buffer buffer() const
UT_Array< cl_short > myInt16Array
GA_StorageClass storage() const
UT_Array< cl_float > myFloat32Array
bool isWriteBackRequired() const
GA_AttributeSet & getAttributes()
Definition: GA_Detail.h:799
UT_Array< cl_double > myFloat64Array
bool isArray() const
bool isValid() const
long long int64
Definition: SYS_Types.h:116
cl::Buffer myIndexBuffer
GA_StorageClass myStorage
GLenum GLint GLint * precision
Definition: glcorearb.h:1925
UT_Array< fpreal16 > myFloat16Array
GA_AttributeOwner
Definition: GA_Types.h:35
GA_Precision myPrecision
UT_Array< cl_int > myIndexArray
SYS_FORCE_INLINE bool UTisstring(const char *s)
GA_Size entries() const
cl::Buffer indexBuffer() const
Memory buffer interface.
Definition: cl.hpp:1867
Container class for all geometry.
Definition: GA_Detail.h:96
UT_Array< cl_int > myInt32Array
bool oclToAttribute(GA_Detail *gdp, GA_AttributeOwner owner, const char *aname)
cl::Buffer myBuffer
SYS_FORCE_INLINE const GA_Attribute * findAttribute(GA_AttributeScope scope, const UT_StringRef &name, const GA_AttributeOwner search_order[], int search_order_size) const
UT_Array< cl_long > myInt64Array
Definition: format.h:1821
void setWriteBackRequired(bool isrequired)