HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_OSDPatchEval.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: CE_OSDPatchEval.h ( CE Library, C++)
7  *
8  * COMMENTS: OpenSubdiv patch-based evaluation on the limit surface.
9  */
10 
11 #ifndef __CE_OSDPatchEval__
12 #define __CE_OSDPatchEval__
13 
14 #include "CE_API.h"
15 #include "CE_Array.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_Array.h>
19 #include <UT/UT_Span.h>
20 
21 class CE_OSDRefinement;
22 class CE_OSDEvaluator;
23 
24 /// Opaque device-side storage for OSD patch coordinates.
25 /// The underlying element type is internal to CE_OSDPatchEval.C.
27 {
28 public:
29  CE_OSDPatchCoords() = default;
32  {
33  swap(myBuffer, o.myBuffer);
34  UTswap(myElemSize, o.myElemSize);
35  return *this;
36  }
37 
38  exint size() const
39  {
40  return myElemSize ? myBuffer.size() / myElemSize : 0;
41  }
42 
43  const cl::Buffer &buffer() const { return myBuffer.buffer(); }
44  void clear()
45  {
46  myBuffer.reset(cl::Buffer());
47  myElemSize = 0;
48  }
49 
50  template <typename T>
52  {
53  myElemSize = sizeof(T);
54  myBuffer.initFromData(
55  reinterpret_cast<const uint8 *>(src.data()),
56  src.size() * sizeof(T));
57  }
58 
59 private:
60  CE_BufferDevice<uint8> myBuffer;
61  exint myElemSize = 0;
62 };
63 
64 namespace CE_OSDPatchEval
65 {
66  /// Build patch coordinates from ptex face/u/v.
67  /// Must be called successfully before evaluate().
68  /// faces/u/v must have identical lengths.
69  /// Returns false if any entry is invalid (negative face or no patch hit)
70  /// and clears patch_coords.
71  /// For empty input, returns true and clears patch_coords.
73  const CE_OSDRefinement &topo,
74  UT_Span<const int> faces,
77  CE_OSDPatchCoords &patch_coords);
78 
79  /// Optional pre-refinement step for patch evaluation inputs.
80  /// Call before evaluate() when topo has stencil refinement points
81  /// (topo.numRefinedVerts() > 0 && topo.hasStencilCL()).
82  /// coarse is caller-owned and must contain at least
83  /// tuple_size * topo.numCoarseVerts() floats.
84  /// When refinement is needed, refined_data is caller-owned and must be
85  /// pre-allocated to tuple_size * topo.numRefinedVerts() floats.
86  /// When refinement is not needed, returns true and leaves refined_data
87  /// unchanged.
88  /// On failure, returns false.
89  CE_API bool refine(const CE_OSDRefinement &topo,
90  const CE_OSDEvaluator &eval,
91  const cl::Buffer &coarse,
92  CE_FloatArray &refined_data);
93 
94  /// Evaluate coarse data on limit patches.
95  /// Call buildPatchCoords() before evaluate(). If topo has stencil
96  /// refinement points (topo.numRefinedVerts() > 0 && topo.hasStencilCL()),
97  /// refine() must be called successfully before evaluate().
98  /// If patch_coords is empty, evaluate() is a no-op and returns true.
99  /// coarse/out/du/dv are caller-owned.
100  /// out must be pre-allocated to at least
101  /// tuple_size * patch_coords.size() floats.
102  /// du/dv are optional; if provided, they must also be pre-allocated to
103  /// at least tuple_size * patch_coords.size() floats.
104  /// refined_data is ignored when no refinement is needed; otherwise it
105  /// must be non-null and sized to tuple_size * topo.numRefinedVerts().
106  /// On failure, returns false.
107  CE_API bool evaluate(const CE_OSDRefinement &topo,
108  const CE_OSDEvaluator &eval,
109  const cl::Buffer &coarse,
110  const CE_OSDPatchCoords &patch_coords,
111  const CE_FloatArray *refined_data,
112  cl::Buffer &out,
113  cl::Buffer *du,
114  cl::Buffer *dv);
115 }
116 
117 #endif
#define CE_API
Definition: CE_API.h:13
CE_API bool evaluate(const CE_OSDRefinement &topo, const CE_OSDEvaluator &eval, const cl::Buffer &coarse, const CE_OSDPatchCoords &patch_coords, const CE_FloatArray *refined_data, cl::Buffer &out, cl::Buffer *du, cl::Buffer *dv)
void initFromArray(const UT_Array< T > &src)
void UTswap(T &a, T &b)
Definition: UT_Swap.h:35
const GLdouble * v
Definition: glcorearb.h:837
CE_API bool buildPatchCoords(const CE_OSDRefinement &topo, UT_Span< const int > faces, UT_Span< const float > u, UT_Span< const float > v, CE_OSDPatchCoords &patch_coords)
int64 exint
Definition: SYS_Types.h:125
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7440
exint size() const
Definition: UT_Array.h:667
CE_API bool refine(const CE_OSDRefinement &topo, const CE_OSDEvaluator &eval, const cl::Buffer &coarse, CE_FloatArray &refined_data)
HUSD_API bool eval(VtValue &val, T &ret_val)
const cl::Buffer & buffer() const
T * data()
Definition: UT_Array.h:866
Memory buffer interface.
Definition: cl.hpp:1867
CE_OSDPatchCoords & operator=(CE_OSDPatchCoords &&o) noexcept
exint size() const
GLenum src
Definition: glcorearb.h:1793