ompEvaluator.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_OMP_EVALUATOR_H
26 #define OPENSUBDIV3_OSD_OMP_EVALUATOR_H
27 
28 #include "../version.h"
29 
30 #include <cstddef>
31 #include "../osd/types.h"
32 #include "../osd/bufferDescriptor.h"
33 
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
36 
37 namespace Osd {
38 
39 class OmpEvaluator {
40 public:
46 
71  template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
72  static bool EvalStencils(
73  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
74  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
75  STENCIL_TABLE const *stencilTable,
76  const OmpEvaluator *instance = NULL,
77  void * deviceContext = NULL) {
78 
79  (void)instance; // unused
80  (void)deviceContext; // unused
81 
82  return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
83  dstBuffer->BindCpuBuffer(), dstDesc,
84  &stencilTable->GetSizes()[0],
85  &stencilTable->GetOffsets()[0],
86  &stencilTable->GetControlIndices()[0],
87  &stencilTable->GetWeights()[0],
88  /*start = */ 0,
89  /*end = */ stencilTable->GetNumStencils());
90  }
91 
119  static bool EvalStencils(
120  const float *src, BufferDescriptor const &srcDesc,
121  float *dst, BufferDescriptor const &dstDesc,
122  const int * sizes,
123  const int * offsets,
124  const int * indices,
125  const float * weights,
126  int start, int end);
127 
165  template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
166  static bool EvalStencils(
167  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
168  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
169  DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
170  DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
171  STENCIL_TABLE const *stencilTable,
172  const OmpEvaluator *instance = NULL,
173  void * deviceContext = NULL) {
174 
175  (void)instance; // unused
176  (void)deviceContext; // unused
177 
178  return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
179  dstBuffer->BindCpuBuffer(), dstDesc,
180  duBuffer->BindCpuBuffer(), duDesc,
181  dvBuffer->BindCpuBuffer(), dvDesc,
182  &stencilTable->GetSizes()[0],
183  &stencilTable->GetOffsets()[0],
184  &stencilTable->GetControlIndices()[0],
185  &stencilTable->GetWeights()[0],
186  &stencilTable->GetDuWeights()[0],
187  &stencilTable->GetDvWeights()[0],
188  /*start = */ 0,
189  /*end = */ stencilTable->GetNumStencils());
190  }
191 
232  static bool EvalStencils(
233  const float *src, BufferDescriptor const &srcDesc,
234  float *dst, BufferDescriptor const &dstDesc,
235  float *du, BufferDescriptor const &duDesc,
236  float *dv, BufferDescriptor const &dvDesc,
237  const int * sizes,
238  const int * offsets,
239  const int * indices,
240  const float * weights,
241  const float * duWeights,
242  const float * dvWeights,
243  int start, int end);
244 
250 
279  template <typename SRC_BUFFER, typename DST_BUFFER,
280  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
281  static bool EvalPatches(
282  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
283  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
284  int numPatchCoords,
285  PATCHCOORD_BUFFER *patchCoords,
286  PATCH_TABLE *patchTable,
287  OmpEvaluator const *instance = NULL,
288  void * deviceContext = NULL) {
289 
290  (void)instance; // unused
291  (void)deviceContext; // unused
292 
293  return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
294  dstBuffer->BindCpuBuffer(), dstDesc,
295  numPatchCoords,
296  (const PatchCoord*)patchCoords->BindCpuBuffer(),
297  patchTable->GetPatchArrayBuffer(),
298  patchTable->GetPatchIndexBuffer(),
299  patchTable->GetPatchParamBuffer());
300  }
301 
342  template <typename SRC_BUFFER, typename DST_BUFFER,
343  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
344  static bool EvalPatches(
345  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
346  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
347  DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
348  DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
349  int numPatchCoords,
350  PATCHCOORD_BUFFER *patchCoords,
351  PATCH_TABLE *patchTable,
352  OmpEvaluator const *instance = NULL,
353  void * deviceContext = NULL) {
354  (void)instance; // unused
355  (void)deviceContext; // unused
356 
357  // XXX: PatchCoords is somewhat abusing vertex primvar buffer interop.
358  // ideally all buffer classes should have templated by datatype
359  // so that downcast isn't needed there.
360  // (e.g. Osd::CpuBuffer<PatchCoord> )
361  //
362  return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
363  dstBuffer->BindCpuBuffer(), dstDesc,
364  duBuffer->BindCpuBuffer(), duDesc,
365  dvBuffer->BindCpuBuffer(), dvDesc,
366  numPatchCoords,
367  (const PatchCoord*)patchCoords->BindCpuBuffer(),
368  patchTable->GetPatchArrayBuffer(),
369  patchTable->GetPatchIndexBuffer(),
370  patchTable->GetPatchParamBuffer());
371  }
372 
400  static bool EvalPatches(
401  const float *src, BufferDescriptor const &srcDesc,
402  float *dst, BufferDescriptor const &dstDesc,
403  int numPatchCoords,
404  const PatchCoord *patchCoords,
405  const PatchArray *patchArrays,
406  const int *patchIndexBuffer,
407  const PatchParam *patchParamBuffer);
408 
446  static bool EvalPatches(
447  const float *src, BufferDescriptor const &srcDesc,
448  float *dst, BufferDescriptor const &dstDesc,
449  float *du, BufferDescriptor const &duDesc,
450  float *dv, BufferDescriptor const &dvDesc,
451  int numPatchCoords,
452  PatchCoord const *patchCoords,
453  PatchArray const *patchArrays,
454  const int *patchIndexBuffer,
455  PatchParam const *patchParamBuffer);
456 
462 
463  static void Synchronize(void *deviceContext = NULL);
464 
465  static void SetNumThreads(int numThreads);
466 };
467 
468 
469 } // end namespace Osd
470 
471 } // end namespace OPENSUBDIV_VERSION
472 using namespace OPENSUBDIV_VERSION;
473 
474 } // end namespace OpenSubdiv
475 
476 
477 #endif // OPENSUBDIV3_OSD_OMP_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 *deviceContext=NULL)
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 OmpEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function with derivatives. This function has a same signature as other d...
Definition: ompEvaluator.h:166
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, const OmpEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function. This function has a same signature as other device kernels hav...
Definition: ompEvaluator.h:72
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, OmpEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function with derivatives. This function has a same signature as other device kern...
Definition: ompEvaluator.h:344
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, OmpEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: ompEvaluator.h:281