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 
28  virtual ~GA_CEAttribute();
29 
30  void clearBuffers();
31 
32  bool isValid() const
33  {
34  return myBuffer();
35  }
36 
37  cl::Buffer buffer() const { return myBuffer; }
38  cl::Buffer indexBuffer() const { return myIndexBuffer; }
39  GA_Size entries() const { return myEntries; }
40  int tupleSize() const { return myTupleSize; }
41  GA_StorageClass storage() const { return myStorage; }
42  GA_Precision precision() const { return myPrecision; }
43  bool isArray() const { return myIsArray; }
44 
45  bool attributeToOCL(const GA_Detail *gdp,
46  GA_AttributeOwner owner,
47  const char *aname,
49  int &tuplesize,
50  bool isarray,
51  bool docopy = true)
52  {
53  return attributeToOCL(gdp, owner, aname, storage, GA_PRECISION_32,
54  tuplesize, isarray, docopy);
55  }
56  bool attributeToOCL(const GA_Detail *gdp,
57  GA_AttributeOwner owner,
58  const char *aname,
61  int &tuplesize,
62  bool isarray,
63  bool docopy = true)
64  {
65  if (!gdp) return false;
66  if (!UTisstring(aname))
67  return false;
68  const GA_Attribute *attrib = gdp->getAttributes().findAttribute(owner, aname);
69  if (!attrib)
70  return false;
71  return attributeToOCL(attrib, storage, precision, tuplesize, isarray, docopy);
72  }
73  bool attributeToOCL(const GA_Attribute *attrib,
74  GA_StorageClass storage,
75  GA_Precision precision,
76  int &tuplesize,
77  bool isarray,
78  bool docopy = true);
79 
80  bool oclToAttribute(GA_Detail *gdp, GA_AttributeOwner owner, const char *aname)
81  {
82  if (!gdp) return false;
83  if (!UTisstring(aname))
84  return false;
85  GA_Attribute *attrib = gdp->getAttributes().findAttribute(owner, aname);
86  if (!attrib)
87  return false;
88  return oclToAttribute(attrib);
89  }
90  bool oclToAttribute(GA_Attribute *attrib);
91 
92  bool isWriteBackRequired() const { return myWriteBackRequired; }
93  void setWriteBackRequired(bool isrequired) { myWriteBackRequired = isrequired; }
94 
95 protected:
96 
97  // GPU Buffers:
98  cl::Buffer myBuffer;
99  cl::Buffer myIndexBuffer;
100 
101  // CPU Buffers:
102  UT_Array<cl_int> myIndexArray;
103  // It would be much more proper to use cl_half here, but that
104  // is not a computable type so it is easy to accidentally cast
105  // fprealy16 to short silently. Instead we rely on bit equivalency.
106  UT_Array<fpreal16> myFloat16Array;
107  UT_Array<cl_float> myFloat32Array;
108  UT_Array<cl_double> myFloat64Array;
109  UT_Array<cl_short> myInt16Array;
110  UT_Array<cl_int> myInt32Array;
111  UT_Array<cl_long> myInt64Array;
112 
113  // Number of entries.
114  GA_Size myEntries;
115  GA_Size myTupleSize;
116  GA_StorageClass myStorage;
117  GA_Precision myPrecision;
118  bool myIsArray;
119 
120  // Whether the buffer has been written to by CE
121  bool myWriteBackRequired;
122 };
123 
124 #else
125 
127 {
128 public:
129 };
130 
131 #endif
132 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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:70
GA_Precision
Definition: GA_Types.h:84
#define GA_API
Definition: GA_API.h:12
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:231
GLuint buffer
Definition: glew.h:1680
GA_AttributeSet & getAttributes()
Definition: GA_Detail.h:739
GA_AttributeOwner
Definition: GA_Types.h:33
SYS_FORCE_INLINE bool UTisstring(const char *s)
Definition: UT_String.h:57
Memory buffer interface.
Definition: cl.hpp:1863
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Container class for all geometry.
Definition: GA_Detail.h:95
GLenum GLint GLint * precision
Definition: glew.h:3500