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 leaveOnGPU = 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 oclToAttribute(GA_Detail *gdp, GA_AttributeOwner owner, const char *aname)
86  {
87  if (!gdp) return false;
88  if (!UTisstring(aname))
89  return false;
90  GA_Attribute *attrib = gdp->getAttributes().findAttribute(owner, aname);
91  if (!attrib)
92  return false;
93  return oclToAttribute(attrib);
94  }
95  bool oclToAttribute(GA_Attribute *attrib);
96 
97  bool isWriteBackRequired() const { return myWriteBackRequired; }
98  void setWriteBackRequired(bool isrequired) { myWriteBackRequired = isrequired; }
99 
100 protected:
101 
102  // GPU Buffers:
103  cl::Buffer myBuffer;
104  cl::Buffer myIndexBuffer;
105 
106  // CPU Buffers:
107  UT_Array<cl_int> myIndexArray;
108  // It would be much more proper to use cl_half here, but that
109  // is not a computable type so it is easy to accidentally cast
110  // fprealy16 to short silently. Instead we rely on bit equivalency.
111  UT_Array<fpreal16> myFloat16Array;
112  UT_Array<cl_float> myFloat32Array;
113  UT_Array<cl_double> myFloat64Array;
114  UT_Array<cl_short> myInt16Array;
115  UT_Array<cl_int> myInt32Array;
116  UT_Array<cl_long> myInt64Array;
117 
118  // Number of entries.
119  GA_Size myEntries;
120  GA_Size myTupleSize;
121  GA_StorageClass myStorage;
122  GA_Precision myPrecision;
123  bool myIsArray;
124 
125  // Whether the buffer has been written to by CE
126  bool myWriteBackRequired;
127 };
128 
129 #else
130 
132 {
133 public:
134 };
135 
136 #endif
137 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
const GA_Attribute * findAttribute(GA_AttributeScope scope, const UT_StringRef &name, const GA_AttributeOwner search_order[], int search_order_size) const
GA_StorageClass
Definition: GA_Types.h:71
GA_Precision
Definition: GA_Types.h:86
#define GA_API
Definition: GA_API.h:14
GLuint buffer
Definition: glcorearb.h:659
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:234
GA_AttributeSet & getAttributes()
Definition: GA_Detail.h:739
GLenum GLint GLint * precision
Definition: glcorearb.h:1924
GA_AttributeOwner
Definition: GA_Types.h:33
SYS_FORCE_INLINE bool UTisstring(const char *s)
Memory buffer interface.
Definition: cl.hpp:1865
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Container class for all geometry.
Definition: GA_Detail.h:95