tbbEvaluator.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_TBB_EVALUATOR_H
26 #define OPENSUBDIV3_OSD_TBB_EVALUATOR_H
27 
28 #include "../version.h"
29 #include "../osd/types.h"
30 #include "../osd/bufferDescriptor.h"
31 #include "../far/patchTable.h"
32 
33 #include <cstddef>
34 
35 namespace OpenSubdiv {
36 namespace OPENSUBDIV_VERSION {
37 
38 namespace Osd {
39 
40 class TbbEvaluator {
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  TbbEvaluator const *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 TbbEvaluator *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 
237  static bool EvalStencils(
238  const float *src, BufferDescriptor const &srcDesc,
239  float *dst, BufferDescriptor const &dstDesc,
240  float *du, BufferDescriptor const &duDesc,
241  float *dv, BufferDescriptor const &dvDesc,
242  const int * sizes,
243  const int * offsets,
244  const int * indices,
245  const float * weights,
246  const float * duWeights,
247  const float * dvWeights,
248  int start, int end);
249 
255 
282  template <typename SRC_BUFFER, typename DST_BUFFER,
283  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
284  static bool EvalPatches(
285  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
286  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
287  int numPatchCoords,
288  PATCHCOORD_BUFFER *patchCoords,
289  PATCH_TABLE *patchTable,
290  TbbEvaluator const *instance = NULL,
291  void * deviceContext = NULL) {
292 
293  (void)instance; // unused
294  (void)deviceContext; // unused
295 
296  return EvalPatches(srcBuffer->BindCpuBuffer(),
297  srcDesc,
298  dstBuffer->BindCpuBuffer(),
299  dstDesc,
300  numPatchCoords,
301  (const PatchCoord*)patchCoords->BindCpuBuffer(),
302  patchTable->GetPatchArrayBuffer(),
303  patchTable->GetPatchIndexBuffer(),
304  patchTable->GetPatchParamBuffer());
305  }
306 
345  template <typename SRC_BUFFER, typename DST_BUFFER,
346  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
347  static bool EvalPatches(
348  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
349  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
350  DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
351  DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
352  int numPatchCoords,
353  PATCHCOORD_BUFFER *patchCoords,
354  PATCH_TABLE *patchTable,
355  TbbEvaluator const *instance = NULL,
356  void * deviceContext = NULL) {
357 
358  (void)instance; // unused
359  (void)deviceContext; // unused
360 
361  return EvalPatches(
362  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  const PatchCoord *patchCoords,
453  const PatchArray *patchArrays,
454  const int *patchIndexBuffer,
455  const PatchParam *patchParamBuffer);
456 
483  template <typename SRC_BUFFER, typename DST_BUFFER,
484  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
485  static bool EvalPatchesVarying(
486  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
487  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
488  int numPatchCoords,
489  PATCHCOORD_BUFFER *patchCoords,
490  PATCH_TABLE *patchTable,
491  TbbEvaluator const *instance = NULL,
492  void * deviceContext = NULL) {
493 
494  (void)instance; // unused
495  (void)deviceContext; // unused
496 
497  return EvalPatches(srcBuffer->BindCpuBuffer(),
498  srcDesc,
499  dstBuffer->BindCpuBuffer(),
500  dstDesc,
501  numPatchCoords,
502  (const PatchCoord*)patchCoords->BindCpuBuffer(),
503  patchTable->GetVaryingPatchArrayBuffer(),
504  patchTable->GetVaryingPatchIndexBuffer(),
505  patchTable->GetPatchParamBuffer());
506  }
507 
536  template <typename SRC_BUFFER, typename DST_BUFFER,
537  typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
539  SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
540  DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
541  int numPatchCoords,
542  PATCHCOORD_BUFFER *patchCoords,
543  PATCH_TABLE *patchTable,
544  int fvarChannel,
545  TbbEvaluator const *instance = NULL,
546  void * deviceContext = NULL) {
547 
548  (void)instance; // unused
549  (void)deviceContext; // unused
550 
551  return EvalPatches(srcBuffer->BindCpuBuffer(),
552  srcDesc,
553  dstBuffer->BindCpuBuffer(),
554  dstDesc,
555  numPatchCoords,
556  (const PatchCoord*)patchCoords->BindCpuBuffer(),
557  patchTable->GetFVarPatchArrayBuffer(fvarChannel),
558  patchTable->GetFVarPatchIndexBuffer(fvarChannel),
559  patchTable->GetFVarPatchParamBuffer(fvarChannel));
560  }
561 
567 
569  static void Synchronize(void *deviceContext = NULL);
570 
576  static void SetNumThreads(int numThreads);
577 };
578 
579 
580 } // end namespace Osd
581 
582 } // end namespace OPENSUBDIV_VERSION
583 using namespace OPENSUBDIV_VERSION;
584 
585 } // end namespace OpenSubdiv
586 
587 
588 #endif // OPENSUBDIV3_OSD_TBB_EVALUATOR_H
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, TbbEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function with derivatives. This function has a same signature as other device kern...
Definition: tbbEvaluator.h:347
static bool EvalPatchesFaceVarying(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, int fvarChannel, TbbEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: tbbEvaluator.h:538
static bool EvalStencils(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, STENCIL_TABLE const *stencilTable, TbbEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function. This function has a same signature as other device kernels hav...
Definition: tbbEvaluator.h:73
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 TbbEvaluator *instance=NULL, void *deviceContext=NULL)
Generic static eval stencils function with derivatives. This function has a same signature as other d...
Definition: tbbEvaluator.h:170
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.
static bool EvalPatches(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, TbbEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: tbbEvaluator.h:284
static void Synchronize(void *deviceContext=NULL)
synchronize all asynchronous computation invoked on this device.
static void SetNumThreads(int numThreads)
initialize tbb task schedular (optional: client may use tbb::task_scheduler_init) ...
Coordinates set on a patch table.
Definition: types.h:40
static bool EvalPatchesVarying(SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc, DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc, int numPatchCoords, PATCHCOORD_BUFFER *patchCoords, PATCH_TABLE *patchTable, TbbEvaluator const *instance=NULL, void *deviceContext=NULL)
Generic limit eval function. This function has a same signature as other device kernels have so that ...
Definition: tbbEvaluator.h:485