2013-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2013-09-11 23:05:14 +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:
|
2013-09-11 23:05:14 +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.
|
2013-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2013-09-11 23:05:14 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-09-11 23:05:14 +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.
|
2013-09-11 23:05:14 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FAR_TBB_EVALSTENCILS_CONTROLLER_H
|
|
|
|
#define FAR_TBB_EVALSTENCILS_CONTROLLER_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "../osd/cpuEvalStencilsContext.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief CPU stencils evaluation controller
|
|
|
|
///
|
|
|
|
/// OsdCpuStencilsController is a compute controller class to launch
|
|
|
|
/// single threaded CPU stencil evalution kernels.
|
|
|
|
///
|
|
|
|
/// Controller entities execute requests from Context instances that they share
|
|
|
|
/// common interfaces with. Controllers are attached to discrete compute devices
|
|
|
|
/// and share the devices resources with Context entities.
|
|
|
|
///
|
|
|
|
class OsdTbbEvalStencilsController {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// \brief Constructor.
|
|
|
|
///
|
|
|
|
/// @param numThreads specifies how many openmp parallel threads to use.
|
|
|
|
/// -1 attempts to use all available processors.
|
|
|
|
///
|
|
|
|
OsdTbbEvalStencilsController(int numThreads=-1);
|
|
|
|
|
|
|
|
/// \brief Destructor.
|
|
|
|
~OsdTbbEvalStencilsController();
|
|
|
|
|
|
|
|
|
|
|
|
/// \brief Applies stencil weights to the control vertex data
|
|
|
|
///
|
|
|
|
/// Applies the stencil weights to the control vertex data to evaluate the
|
|
|
|
/// interpolated limit positions at the parametric locations of the stencils
|
|
|
|
///
|
|
|
|
/// @param context the OsdCpuEvalStencilsContext with the stencil weights
|
|
|
|
///
|
|
|
|
/// @param controlDataDesc vertex buffer descriptor for the control vertex data
|
|
|
|
///
|
|
|
|
/// @param controlVertices vertex buffer with the control vertices data
|
|
|
|
///
|
|
|
|
/// @param outputDataDesc vertex buffer descriptor for the output vertex data
|
|
|
|
///
|
|
|
|
/// @param outputData output vertex buffer for the interpolated data
|
|
|
|
///
|
|
|
|
template<class CONTROL_BUFFER, class OUTPUT_BUFFER>
|
|
|
|
int UpdateValues( OsdCpuEvalStencilsContext * context,
|
|
|
|
OsdVertexBufferDescriptor const & controlDataDesc, CONTROL_BUFFER *controlVertices,
|
|
|
|
OsdVertexBufferDescriptor const & outputDataDesc, OUTPUT_BUFFER *outputData ) {
|
|
|
|
|
|
|
|
if (not context->GetStencilTables()->GetNumStencils())
|
|
|
|
return 0;
|
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
bindControlData( controlDataDesc, controlVertices );
|
2013-09-11 23:05:14 +00:00
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
bindOutputData( outputDataDesc, outputData );
|
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
int n = _UpdateValues( context );
|
2014-05-10 21:49:15 +00:00
|
|
|
|
|
|
|
unbind();
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Applies derivative stencil weights to the control vertex data
|
|
|
|
///
|
|
|
|
/// Computes the U and V derivative stencils to the control vertex data at
|
|
|
|
/// the parametric locations contained in each stencil
|
|
|
|
///
|
|
|
|
/// @param context the OsdCpuEvalStencilsContext with the stencil weights
|
|
|
|
///
|
|
|
|
/// @param controlDataDesc vertex buffer descriptor for the control vertex data
|
|
|
|
///
|
|
|
|
/// @param controlVertices vertex buffer with the control vertices data
|
|
|
|
///
|
|
|
|
/// @param outputDuDesc vertex buffer descriptor for the U derivative output data
|
|
|
|
///
|
|
|
|
/// @param outputDuData output vertex buffer for the U derivative data
|
|
|
|
///
|
|
|
|
/// @param outputDvDesc vertex buffer descriptor for the V deriv output data
|
|
|
|
///
|
|
|
|
/// @param outputDvData output vertex buffer for the V derivative data
|
|
|
|
///
|
|
|
|
template<class CONTROL_BUFFER, class OUTPUT_BUFFER>
|
|
|
|
int UpdateDerivs( OsdCpuEvalStencilsContext * context,
|
|
|
|
OsdVertexBufferDescriptor const & controlDataDesc, CONTROL_BUFFER *controlVertices,
|
|
|
|
OsdVertexBufferDescriptor const & outputDuDesc, OUTPUT_BUFFER *outputDuData,
|
|
|
|
OsdVertexBufferDescriptor const & outputDvDesc, OUTPUT_BUFFER *outputDvData ) {
|
|
|
|
|
|
|
|
if (not context->GetStencilTables()->GetNumStencils())
|
|
|
|
return 0;
|
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
bindControlData( controlDataDesc, controlVertices );
|
2013-09-11 23:05:14 +00:00
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
bindOutputDerivData( outputDuDesc, outputDuData, outputDvDesc, outputDvData );
|
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
int n = _UpdateDerivs( context );
|
2014-05-10 21:49:15 +00:00
|
|
|
|
|
|
|
unbind();
|
2013-09-11 23:05:14 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Waits until all running subdivision kernels finish.
|
|
|
|
void Synchronize();
|
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/// \brief Binds control vertex data buffer
|
|
|
|
template<class VERTEX_BUFFER>
|
|
|
|
void bindControlData(OsdVertexBufferDescriptor const & controlDataDesc, VERTEX_BUFFER *controlData ) {
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
_currentBindState.controlData = controlData ? controlData->BindCpuBuffer() : 0;
|
|
|
|
_currentBindState.controlDataDesc = controlDataDesc;
|
2014-05-10 21:49:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Binds output vertex data buffer
|
|
|
|
template<class VERTEX_BUFFER>
|
|
|
|
void bindOutputData( OsdVertexBufferDescriptor const & outputDataDesc, VERTEX_BUFFER *outputData ) {
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
_currentBindState.outputData = outputData ? outputData->BindCpuBuffer() : 0;
|
|
|
|
_currentBindState.outputDataDesc = outputDataDesc;
|
2014-05-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Binds output derivative vertex data buffer
|
|
|
|
template<class VERTEX_BUFFER>
|
|
|
|
void bindOutputDerivData( OsdVertexBufferDescriptor const & outputDuDesc, VERTEX_BUFFER *outputDu,
|
|
|
|
OsdVertexBufferDescriptor const & outputDvDesc, VERTEX_BUFFER *outputDv ) {
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
_currentBindState.outputUDeriv = outputDu ? outputDu ->BindCpuBuffer() : 0;
|
|
|
|
_currentBindState.outputVDeriv = outputDv ? outputDv->BindCpuBuffer() : 0;
|
|
|
|
_currentBindState.outputDuDesc = outputDuDesc;
|
|
|
|
_currentBindState.outputDvDesc = outputDvDesc;
|
2014-05-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Unbinds any previously bound vertex and varying data buffers.
|
|
|
|
void unbind() {
|
2014-05-10 23:38:13 +00:00
|
|
|
_currentBindState.Reset();
|
2014-05-10 21:49:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 23:05:14 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
int _UpdateValues( OsdCpuEvalStencilsContext * context );
|
|
|
|
int _UpdateDerivs( OsdCpuEvalStencilsContext * context );
|
|
|
|
|
|
|
|
int _numThreads;
|
2014-05-10 21:49:15 +00:00
|
|
|
|
|
|
|
// Bind state is a transitional state during refinement.
|
|
|
|
// It doesn't take an ownership of vertex buffers.
|
|
|
|
struct BindState {
|
|
|
|
|
2014-05-10 23:38:13 +00:00
|
|
|
BindState() : controlData(0), outputData(0), outputUDeriv(0), outputVDeriv(0) { }
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
controlData = outputData = outputUDeriv = outputVDeriv = NULL;
|
|
|
|
controlDataDesc.Reset();
|
|
|
|
outputDataDesc.Reset();
|
|
|
|
outputDuDesc.Reset();
|
|
|
|
outputDvDesc.Reset();
|
|
|
|
}
|
|
|
|
|
2014-05-10 21:49:15 +00:00
|
|
|
// transient mesh data
|
2014-05-10 23:38:13 +00:00
|
|
|
OsdVertexBufferDescriptor controlDataDesc,
|
|
|
|
outputDataDesc,
|
|
|
|
outputDuDesc,
|
|
|
|
outputDvDesc;
|
|
|
|
|
|
|
|
float * controlData,
|
|
|
|
* outputData,
|
|
|
|
* outputUDeriv,
|
|
|
|
* outputVDeriv;
|
2014-05-10 21:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BindState _currentBindState;
|
2013-09-11 23:05:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif // FAR_TBB_EVALSTENCILS_CONTROLLER_H
|