mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-12-03 08:21:03 +00:00
297 lines
11 KiB
C++
297 lines
11 KiB
C++
//
|
|
// Copyright 2013 Pixar
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
// with the following modification; you may not use this file except in
|
|
// compliance with the Apache License and the following modification to it:
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
//
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
//
|
|
// You may obtain a copy of the Apache License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the Apache License with the above modification is
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
// language governing permissions and limitations under the Apache License.
|
|
//
|
|
|
|
#include "../osd/cpuComputeContext.h"
|
|
#include "../osd/tbbComputeController.h"
|
|
#include "../osd/tbbKernel.h"
|
|
|
|
#ifdef OPENSUBDIV_HAS_TBB
|
|
#include <tbb/task_scheduler_init.h>
|
|
#endif
|
|
|
|
namespace OpenSubdiv {
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
OsdTbbComputeController::OsdTbbComputeController(int numThreads) {
|
|
_numThreads = numThreads;
|
|
if(_numThreads == -1)
|
|
tbb::task_scheduler_init init;
|
|
else
|
|
tbb::task_scheduler_init init(numThreads);
|
|
}
|
|
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyBilinearFaceVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeFace(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::F_IT)->GetBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::F_ITa)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyBilinearEdgeVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeBilinearEdge(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::E_IT)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyBilinearVertexVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeBilinearVertex(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyCatmarkFaceVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeFace(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::F_IT)->GetBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::F_ITa)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyCatmarkEdgeVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeEdge(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::E_IT)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::E_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelB(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeVertexB(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_IT)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelA1(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeVertexA(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelA2(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeVertexA(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyLoopEdgeVerticesKernel(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeEdge(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::E_IT)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::E_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyLoopVertexVerticesKernelB(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeLoopVertexB(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_IT)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyLoopVertexVerticesKernelA1(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeVertexA(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyLoopVertexVerticesKernelA2(
|
|
FarKernelBatch const &batch, void *clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
OsdTbbComputeVertexA(
|
|
context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
context->GetCurrentVaryingBuffer(),
|
|
(const int*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_ITa)->GetBuffer(),
|
|
(const float*)context->GetTable(FarSubdivisionTables<OsdVertex>::V_W)->GetBuffer(),
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::ApplyVertexEdits(
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
OsdCpuComputeContext * context =
|
|
static_cast<OsdCpuComputeContext*>(clientdata);
|
|
assert(context);
|
|
|
|
const OsdCpuHEditTable *edit = context->GetEditTable(batch.GetTableIndex());
|
|
assert(edit);
|
|
|
|
const OsdCpuTable * primvarIndices = edit->GetPrimvarIndices();
|
|
const OsdCpuTable * editValues = edit->GetEditValues();
|
|
|
|
if (edit->GetOperation() == FarVertexEdit::Add) {
|
|
OsdTbbEditVertexAdd(context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
edit->GetPrimvarOffset(),
|
|
edit->GetPrimvarWidth(),
|
|
batch.GetVertexOffset(),
|
|
batch.GetTableOffset(),
|
|
batch.GetStart(),
|
|
batch.GetEnd(),
|
|
static_cast<unsigned int*>(primvarIndices->GetBuffer()),
|
|
static_cast<float*>(editValues->GetBuffer()));
|
|
} else if (edit->GetOperation() == FarVertexEdit::Set) {
|
|
OsdTbbEditVertexSet(context->GetVertexDescriptor(),
|
|
context->GetCurrentVertexBuffer(),
|
|
edit->GetPrimvarOffset(),
|
|
edit->GetPrimvarWidth(),
|
|
batch.GetVertexOffset(),
|
|
batch.GetTableOffset(),
|
|
batch.GetStart(),
|
|
batch.GetEnd(),
|
|
static_cast<unsigned int*>(primvarIndices->GetBuffer()),
|
|
static_cast<float*>(editValues->GetBuffer()));
|
|
}
|
|
}
|
|
|
|
void
|
|
OsdTbbComputeController::Synchronize() {
|
|
// XXX:
|
|
}
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
} // end namespace OpenSubdiv
|
|
|