cpuEvaluator.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef OPENSUBDIV3_OSD_CPU_EVALUATOR_H
26 #define OPENSUBDIV3_OSD_CPU_EVALUATOR_H
27 
28 #include "../version.h"
29 
30 #include <cstddef>
31 #include <vector>
32 #include "../osd/bufferDescriptor.h"
33 #include "../osd/types.h"
34 
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
37 
38 namespace Osd {
39 
40 class CpuEvaluator {
41 public:
47 
72  template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
73  static bool EvalStencils(
74  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
75  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
76  STENCIL_TABLE const *stencilTable,
77  const CpuEvaluator *instance = NULL,
78  void * deviceContext = NULL) {
79 
80  (void)instance; // unused
81  (void)deviceContext; // unused
82 
83  if (stencilTable->GetNumStencils() == 0)
84  return false;
85 
86  return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
87  dstBuffer->BindCpuBuffer(), dstDesc,
88  &stencilTable->GetSizes()[0],
89  &stencilTable->GetOffsets()[0],
90  &stencilTable->GetControlIndices()[0],
91  &stencilTable->GetWeights()[0],
92  /*start = */ 0,
93  /*end = */ stencilTable->GetNumStencils());
94  }
95 
123  static bool EvalStencils(
124  const float *src, BufferDescriptor const &srcDesc,
125  float *dst, BufferDescriptor const &dstDesc,
126  const int * sizes,
127  const int * offsets,
128  const int * indices,
129  const float * weights,
130  int start, int end);
131 
169  template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
170  static bool EvalStencils(
171  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
172  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
173  DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
174  DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
175  STENCIL_TABLE const *stencilTable,
176  const CpuEvaluator *instance = NULL,
177  void * deviceContext = NULL) {
178 
179  (void)instance; // unused
180  (void)deviceContext; // unused
181 
182  return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
183  dstBuffer->BindCpuBuffer(), dstDesc,
184  duBuffer->BindCpuBuffer(), duDesc,
185  dvBuffer->BindCpuBuffer(), dvDesc,
186  &stencilTable->GetSizes()[0],
187  &stencilTable->GetOffsets()[0],
188  &stencilTable->GetControlIndices()[0],
189  &stencilTable->GetWeights()[0],
190  &stencilTable->GetDuWeights()[0],
191  &stencilTable->GetDvWeights()[0],
192  /*start = */ 0,
193  /*end = */ stencilTable->GetNumStencils());
194  }
195 
236  static bool EvalStencils(
237  const float *src, BufferDescriptor const &srcDesc,
238  float *dst, BufferDescriptor const &dstDesc,
239  float *du, BufferDescriptor const &duDesc,
240  float *dv, BufferDescriptor const &dvDesc,
241  const int * sizes,
242  const int * offsets,
243  const int * indices,
244  const float * weights,
245  const float * duWeights,
246  const float * dvWeights,
247  int start, int end);
248 
254 
283  template <typename SRC_BUFFER, typename DST_BUFFER,
284  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
285  static bool EvalPatches(
286  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
287  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
288  int numPatchCoords,
289  PATCHCOORD_BUFFER *patchCoords,
290  PATCH_TABLE *patchTable,
291  CpuEvaluator const *instance = NULL,
292  void * deviceContext = NULL) {
293 
294  (void)instance; // unused
295  (void)deviceContext; // unused
296 
297  return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
298  dstBuffer->BindCpuBuffer(), dstDesc,
299  numPatchCoords,
300  (const PatchCoord*)patchCoords->BindCpuBuffer(),
301  patchTable->GetPatchArrayBuffer(),
302  patchTable->GetPatchIndexBuffer(),
303  patchTable->GetPatchParamBuffer());
304  }
305 
346  template <typename SRC_BUFFER, typename DST_BUFFER,
347  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
348  static bool EvalPatches(
349  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
350  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
351  DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
352  DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
353  int numPatchCoords,
354  PATCHCOORD_BUFFER *patchCoords,
355  PATCH_TABLE *patchTable,
356  CpuEvaluator const *instance = NULL,
357  void * deviceContext = NULL) {
358  (void)instance; // unused
359  (void)deviceContext; // unused
360 
361  // XXX: PatchCoords is somewhat abusing vertex primvar buffer interop.
362  // ideally all buffer classes should have templated by datatype
363  // so that downcast isn't needed there.
364  // (e.g. Osd::CpuBuffer<PatchCoord> )
365  //
366  return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
367  dstBuffer->BindCpuBuffer(), dstDesc,
368  duBuffer->BindCpuBuffer(), duDesc,
369  dvBuffer->BindCpuBuffer(), dvDesc,
370  numPatchCoords,
371  (const PatchCoord*)patchCoords->BindCpuBuffer(),
372  patchTable->GetPatchArrayBuffer(),
373  patchTable->GetPatchIndexBuffer(),
374  patchTable->GetPatchParamBuffer());
375  }
376 
404  static bool EvalPatches(
405  const float *src, BufferDescriptor const &srcDesc,
406  float *dst, BufferDescriptor const &dstDesc,
407  int numPatchCoords,
408  const PatchCoord *patchCoords,
409  const PatchArray *patchArrays,
410  const int *patchIndexBuffer,
411  const PatchParam *patchParamBuffer);
412 
450  static bool EvalPatches(
451  const float *src, BufferDescriptor const &srcDesc,
452  float *dst, BufferDescriptor const &dstDesc,
453  float *du, BufferDescriptor const &duDesc,
454  float *dv, BufferDescriptor const &dvDesc,
455  int numPatchCoords,
456  PatchCoord const *patchCoords,
457  PatchArray const *patchArrays,
458  const int *patchIndexBuffer,
459  PatchParam const *patchParamBuffer);
460 
466 
468  static void Synchronize(void * /*deviceContext = NULL*/) {
469  // nothing.
470  }
471 };
472 
473 
474 } // end namespace Osd
475 
476 } // end namespace OPENSUBDIV_VERSION
477 using namespace OPENSUBDIV_VERSION;
478 
479 } // end namespace OpenSubdiv
480 
481 
482 #endif // OPENSUBDIV3_OSD_CPU_EVALUATOR_H
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers. Almost all Osd Evaluator APIs take BufferDescriptors along with device-specific buffer objects.
Coordinates set on a patch table.
Definition: types.h:40
static void Synchronize(void *)
synchronize all asynchronous computation invoked on this device.
Definition: cpuEvaluator.h:468
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, DST_BUFFER *duBuffer, BufferDescriptor const &duDesc, DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc, STENCIL_TABLE const *stencilTable, const CpuEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function with derivatives. This function has a same signature as other d...
Definition: cpuEvaluator.h:170
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, DST_BUFFER *duBuffer, BufferDescriptor const &duDesc, DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, CpuEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function with derivatives. This function has a same signature as other device kern...
Definition: cpuEvaluator.h:348
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, const CpuEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function. This function has a same signature as other device kernels hav...
Definition: cpuEvaluator.h:73
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, CpuEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: cpuEvaluator.h:285