2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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:
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-08-22 23:22:08 +00:00
|
|
|
//
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../osd/glslComputeController.h"
|
|
|
|
#include "../osd/glslComputeContext.h"
|
|
|
|
#include "../osd/glslKernelBundle.h"
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2013-06-10 22:54:40 +00:00
|
|
|
#include "../osd/opengl.h"
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
OsdGLSLComputeController::OsdGLSLComputeController() {
|
|
|
|
}
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
OsdGLSLComputeController::~OsdGLSLComputeController() {
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
for (std::vector<OsdGLSLComputeKernelBundle*>::iterator it =
|
|
|
|
_kernelRegistry.begin();
|
|
|
|
it != _kernelRegistry.end(); ++it) {
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void
|
|
|
|
OsdGLSLComputeController::Synchronize() {
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glFinish();
|
|
|
|
}
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
OsdGLSLComputeKernelBundle *
|
|
|
|
OsdGLSLComputeController::getKernels(int numVertexElements,
|
|
|
|
int numVaryingElements) {
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
std::vector<OsdGLSLComputeKernelBundle*>::iterator it =
|
|
|
|
std::find_if(_kernelRegistry.begin(), _kernelRegistry.end(),
|
|
|
|
OsdGLSLComputeKernelBundle::Match(numVertexElements,
|
|
|
|
numVaryingElements));
|
|
|
|
if (it != _kernelRegistry.end()) {
|
|
|
|
return *it;
|
|
|
|
} else {
|
|
|
|
OsdGLSLComputeKernelBundle *kernelBundle =
|
|
|
|
new OsdGLSLComputeKernelBundle();
|
|
|
|
_kernelRegistry.push_back(kernelBundle);
|
|
|
|
kernelBundle->Compile(numVertexElements, numVaryingElements);
|
|
|
|
return kernelBundle;
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 23:22:08 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyBilinearFaceVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyBilinearFaceVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyBilinearEdgeVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyBilinearEdgeVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyBilinearVertexVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyBilinearVertexVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyCatmarkFaceVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyCatmarkFaceVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyCatmarkEdgeVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyCatmarkEdgeVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelB(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyCatmarkVertexVerticesKernelB(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA1(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyCatmarkVertexVerticesKernelA(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA2(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyCatmarkVertexVerticesKernelA(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyLoopEdgeVerticesKernel(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyLoopEdgeVerticesKernel(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyLoopVertexVerticesKernelB(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyLoopVertexVerticesKernelB(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA1(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyLoopVertexVerticesKernelA(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), false);
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA2(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
|
|
|
kernelBundle->ApplyLoopVertexVerticesKernelA(
|
2013-05-07 00:50:58 +00:00
|
|
|
batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), true);
|
2013-03-08 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsdGLSLComputeController::ApplyVertexEdits(
|
|
|
|
FarKernelBatch const &batch, void * clientdata) const {
|
|
|
|
|
|
|
|
OsdGLSLComputeContext * context =
|
|
|
|
static_cast<OsdGLSLComputeContext*>(clientdata);
|
|
|
|
assert(context);
|
|
|
|
|
|
|
|
OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle();
|
|
|
|
|
2013-05-07 00:50:58 +00:00
|
|
|
const OsdGLSLComputeHEditTable * edit = context->GetEditTable(batch.GetTableIndex());
|
2013-03-08 01:50:15 +00:00
|
|
|
assert(edit);
|
|
|
|
|
2013-05-07 00:50:58 +00:00
|
|
|
context->BindEditShaderStorageBuffers(batch.GetTableIndex());
|
2013-03-08 01:50:15 +00:00
|
|
|
|
|
|
|
int primvarOffset = edit->GetPrimvarOffset();
|
|
|
|
int primvarWidth = edit->GetPrimvarWidth();
|
|
|
|
|
|
|
|
if (edit->GetOperation() == FarVertexEdit::Add) {
|
2013-05-07 00:50:58 +00:00
|
|
|
kernelBundle->ApplyEditAdd( primvarOffset,
|
|
|
|
primvarWidth,
|
|
|
|
batch.GetVertexOffset(),
|
|
|
|
batch.GetTableOffset(),
|
|
|
|
batch.GetStart(),
|
|
|
|
batch.GetEnd());
|
2013-03-08 01:50:15 +00:00
|
|
|
} else {
|
|
|
|
// XXX: edit SET is not implemented yet.
|
|
|
|
}
|
|
|
|
|
|
|
|
context->UnbindEditShaderStorageBuffers();
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|