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 "../osd/bufferDescriptor.h"
32 #include "../osd/types.h"
33
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
36
37 namespace Osd {
38
39 class CpuEvaluator {
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 CpuEvaluator *instance = NULL,
77 void * deviceContext = NULL) {
78
79 (void)instance; // unused
80 (void)deviceContext; // unused
81
82 if (stencilTable->GetNumStencils() == 0)
83 return false;
84
85 return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
86 dstBuffer->BindCpuBuffer(), dstDesc,
87 &stencilTable->GetSizes()[0],
88 &stencilTable->GetOffsets()[0],
89 &stencilTable->GetControlIndices()[0],
90 &stencilTable->GetWeights()[0],
91 /*start = */ 0,
92 /*end = */ stencilTable->GetNumStencils());
93 }
94
122 static bool EvalStencils(
123 const float *src, BufferDescriptor const &srcDesc,
124 float *dst, BufferDescriptor const &dstDesc,
125 const int * sizes,
126 const int * offsets,
127 const int * indices,
128 const float * weights,
129 int start, int end);
130
168 template <typename SRC_BUFFER, typename DST_BUFFER, typename STENCIL_TABLE>
169 static bool EvalStencils(
170 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
171 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
172 DST_BUFFER *duBuffer, BufferDescriptor const &duDesc,
173 DST_BUFFER *dvBuffer, BufferDescriptor const &dvDesc,
174 STENCIL_TABLE const *stencilTable,
175 const CpuEvaluator *instance = NULL,
176 void * deviceContext = NULL) {
177
178 (void)instance; // unused
179 (void)deviceContext; // unused
180
181 return EvalStencils(srcBuffer->BindCpuBuffer(), srcDesc,
182 dstBuffer->BindCpuBuffer(), dstDesc,
183 duBuffer->BindCpuBuffer(), duDesc,
184 dvBuffer->BindCpuBuffer(), dvDesc,
185 &stencilTable->GetSizes()[0],
186 &stencilTable->GetOffsets()[0],
187 &stencilTable->GetControlIndices()[0],
188 &stencilTable->GetWeights()[0],
189 &stencilTable->GetDuWeights()[0],
190 &stencilTable->GetDvWeights()[0],
191 /*start = */ 0,
192 /*end = */ stencilTable->GetNumStencils());
193 }
194
235 static bool EvalStencils(
236 const float *src, BufferDescriptor const &srcDesc,
237 float *dst, BufferDescriptor const &dstDesc,
238 float *du, BufferDescriptor const &duDesc,
239 float *dv, BufferDescriptor const &dvDesc,
240 const int * sizes,
241 const int * offsets,
242 const int * indices,
243 const float * weights,
244 const float * duWeights,
245 const float * dvWeights,
246 int start, int end);
247
253
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 CpuEvaluator const *instance = NULL,
291 void * deviceContext = NULL) {
292
293 (void)instance; // unused
294 (void)deviceContext; // unused
295
296 return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
297 dstBuffer->BindCpuBuffer(), dstDesc,
298 numPatchCoords,
299 (const PatchCoord*)patchCoords->BindCpuBuffer(),
300 patchTable->GetPatchArrayBuffer(),
301 patchTable->GetPatchIndexBuffer(),
302 patchTable->GetPatchParamBuffer());
303 }
304
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 CpuEvaluator const *instance = NULL,
356 void * deviceContext = NULL) {
357 (void)instance; // unused
358 (void)deviceContext; // unused
359
360 // XXX: PatchCoords is somewhat abusing vertex primvar buffer interop.
361 // ideally all buffer classes should have templated by datatype
362 // so that downcast isn't needed there.
363 // (e.g. Osd::CpuBuffer<PatchCoord> )
364 //
365 return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
366 dstBuffer->BindCpuBuffer(), dstDesc,
367 duBuffer->BindCpuBuffer(), duDesc,
368 dvBuffer->BindCpuBuffer(), dvDesc,
369 numPatchCoords,
370 (const PatchCoord*)patchCoords->BindCpuBuffer(),
371 patchTable->GetPatchArrayBuffer(),
372 patchTable->GetPatchIndexBuffer(),
373 patchTable->GetPatchParamBuffer());
374 }
375
403 static bool EvalPatches(
404 const float *src, BufferDescriptor const &srcDesc,
405 float *dst, BufferDescriptor const &dstDesc,
406 int numPatchCoords,
407 const PatchCoord *patchCoords,
408 const PatchArray *patchArrays,
409 const int *patchIndexBuffer,
410 const PatchParam *patchParamBuffer);
411
449 static bool EvalPatches(
450 const float *src, BufferDescriptor const &srcDesc,
451 float *dst, BufferDescriptor const &dstDesc,
452 float *du, BufferDescriptor const &duDesc,
453 float *dv, BufferDescriptor const &dvDesc,
454 int numPatchCoords,
455 PatchCoord const *patchCoords,
456 PatchArray const *patchArrays,
457 const int *patchIndexBuffer,
458 PatchParam const *patchParamBuffer);
459
488 template <typename SRC_BUFFER, typename DST_BUFFER,
489 typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
490 static bool EvalPatchesVarying(
491 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
492 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
493 int numPatchCoords,
494 PATCHCOORD_BUFFER *patchCoords,
495 PATCH_TABLE *patchTable,
496 CpuEvaluator const *instance = NULL,
497 void * deviceContext = NULL) {
498
499 (void)instance; // unused
500 (void)deviceContext; // unused
501
502 return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
503 dstBuffer->BindCpuBuffer(), dstDesc,
504 numPatchCoords,
505 (const PatchCoord*)patchCoords->BindCpuBuffer(),
506 patchTable->GetVaryingPatchArrayBuffer(),
507 patchTable->GetVaryingPatchIndexBuffer(),
508 patchTable->GetPatchParamBuffer());
509 }
510
541 template <typename SRC_BUFFER, typename DST_BUFFER,
542 typename PATCHCOORD_BUFFER, typename PATCH_TABLE>
543 static bool EvalPatchesFaceVarying(
544 SRC_BUFFER *srcBuffer, BufferDescriptor const &srcDesc,
545 DST_BUFFER *dstBuffer, BufferDescriptor const &dstDesc,
546 int numPatchCoords,
547 PATCHCOORD_BUFFER *patchCoords,
548 PATCH_TABLE *patchTable,
549 int fvarChannel,
550 CpuEvaluator const *instance = NULL,
551 void * deviceContext = NULL) {
552
553 (void)instance; // unused
554 (void)deviceContext; // unused
555
556 return EvalPatches(srcBuffer->BindCpuBuffer(), srcDesc,
557 dstBuffer->BindCpuBuffer(), dstDesc,
558 numPatchCoords,
559 (const PatchCoord*)patchCoords->BindCpuBuffer(),
560 patchTable->GetFVarPatchArrayBuffer(fvarChannel),
561 patchTable->GetFVarPatchIndexBuffer(fvarChannel),
562 patchTable->GetFVarPatchParamBuffer(fvarChannel));
563 }
564
570
572 static void Synchronize(void * /*deviceContext = NULL*/) {
573 // nothing.
574 }
575 };
576
577
578 } // end namespace Osd
579
580 } // end namespace OPENSUBDIV_VERSION
581 using namespace OPENSUBDIV_VERSION;
582
583 } // end namespace OpenSubdiv
584
585
586 #endif // OPENSUBDIV3_OSD_CPU_EVALUATOR_H
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchParam
Definition: types.h:93
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalPatchesVarying
static bool EvalPatchesVarying(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:490
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchArray
Definition: types.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalStencils
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:169
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::Synchronize
static void Synchronize(void *)
synchronize all asynchronous computation invoked on this device.
Definition: cpuEvaluator.h:572
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalPatchesFaceVarying
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, 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:543
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
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.
Definition: bufferDescriptor.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalStencils
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:72
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalPatches
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:347
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator::EvalPatches
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:284
OpenSubdiv
Definition: error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Osd::PatchCoord
Coordinates set on a patch table.
Definition: types.h:40
OpenSubdiv::OPENSUBDIV_VERSION::Osd::CpuEvaluator
Definition: cpuEvaluator.h:39