OpenSubdiv/opensubdiv/osd/ompComputeController.cpp
Takahito Tejima 44a7cb6a45 Refactor Far API.
* replace void* of all kernel applications with CONTEXT template parameter.
  It eliminates many static_casts from void* for both far and osd classes.
* move the big switch-cases of far default kernel launches out of Refine so
  that osd controllers can arbitrary mix default kernels and custom kernels.
* change FarKernelBatch::kernelType from enum to int, clients can add
  custom kernel types.
* remove a back-pointer to farmesh from subdivision table.
* untemplate all subdivision table classes and template their compute methods
  instead. Those methods take a typed vertex storage.
* remove an unused argument FarMesh from the constructor of subdivision
  table factories.
2014-03-19 11:44:51 -07:00

268 lines
9.9 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/ompComputeController.h"
#include "../osd/ompKernel.h"
#ifdef OPENSUBDIV_HAS_OPENMP
#include <omp.h>
#endif
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
OsdOmpComputeController::OsdOmpComputeController(int numThreads) {
_numThreads = (numThreads == -1) ? omp_get_num_procs() : numThreads;
}
void
OsdOmpComputeController::ApplyBilinearFaceVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeFace(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyBilinearEdgeVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeBilinearEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyBilinearVertexVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeBilinearVertex(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyCatmarkFaceVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeFace(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyCatmarkEdgeVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyCatmarkVertexVerticesKernelB(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeVertexB(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_IT)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyCatmarkVertexVerticesKernelA1(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
}
void
OsdOmpComputeController::ApplyCatmarkVertexVerticesKernelA2(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
}
void
OsdOmpComputeController::ApplyLoopEdgeVerticesKernel(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyLoopVertexVerticesKernelB(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeLoopVertexB(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_IT)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
}
void
OsdOmpComputeController::ApplyLoopVertexVerticesKernelA1(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
}
void
OsdOmpComputeController::ApplyLoopVertexVerticesKernelA2(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
assert(context);
OsdOmpComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(),
(const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(),
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
}
void
OsdOmpComputeController::ApplyVertexEdits(
FarKernelBatch const &batch, OsdCpuComputeContext *context) const {
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) {
OsdOmpEditVertexAdd(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) {
OsdOmpEditVertexSet(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
OsdOmpComputeController::Synchronize() {
// XXX:
}
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv