2013-05-10 16:20:45 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) Pixar. All rights reserved.
|
|
|
|
//
|
|
|
|
// This license governs use of the accompanying software. If you
|
|
|
|
// use the software, you accept this license. If you do not accept
|
|
|
|
// the license, do not use the software.
|
|
|
|
//
|
|
|
|
// 1. Definitions
|
|
|
|
// The terms "reproduce," "reproduction," "derivative works," and
|
|
|
|
// "distribution" have the same meaning here as under U.S.
|
|
|
|
// copyright law. A "contribution" is the original software, or
|
|
|
|
// any additions or changes to the software.
|
|
|
|
// A "contributor" is any person or entity that distributes its
|
|
|
|
// contribution under this license.
|
|
|
|
// "Licensed patents" are a contributor's patent claims that read
|
|
|
|
// directly on its contribution.
|
|
|
|
//
|
|
|
|
// 2. Grant of Rights
|
|
|
|
// (A) Copyright Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free copyright license to reproduce its contribution,
|
|
|
|
// prepare derivative works of its contribution, and distribute
|
|
|
|
// its contribution or any derivative works that you create.
|
|
|
|
// (B) Patent Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free license under its licensed patents to make, have
|
|
|
|
// made, use, sell, offer for sale, import, and/or otherwise
|
|
|
|
// dispose of its contribution in the software or derivative works
|
|
|
|
// of the contribution in the software.
|
|
|
|
//
|
|
|
|
// 3. Conditions and Limitations
|
|
|
|
// (A) No Trademark License- This license does not grant you
|
|
|
|
// rights to use any contributor's name, logo, or trademarks.
|
|
|
|
// (B) If you bring a patent claim against any contributor over
|
|
|
|
// patents that you claim are infringed by the software, your
|
|
|
|
// patent license from such contributor to the software ends
|
|
|
|
// automatically.
|
|
|
|
// (C) If you distribute any portion of the software, you must
|
|
|
|
// retain all copyright, patent, trademark, and attribution
|
|
|
|
// notices that are present in the software.
|
|
|
|
// (D) If you distribute any portion of the software in source
|
|
|
|
// code form, you may do so only under this license by including a
|
|
|
|
// complete copy of this license with your distribution. If you
|
|
|
|
// distribute any portion of the software in compiled or object
|
|
|
|
// code form, you may only do so under a license that complies
|
|
|
|
// with this license.
|
|
|
|
// (E) The software is licensed "as-is." You bear the risk of
|
|
|
|
// using it. The contributors give no express warranties,
|
|
|
|
// guarantees or conditions. You may have additional consumer
|
|
|
|
// rights under your local laws which this license cannot change.
|
|
|
|
// To the extent permitted under your local laws, the contributors
|
|
|
|
// exclude the implied warranties of merchantability, fitness for
|
|
|
|
// a particular purpose and non-infringement.
|
|
|
|
//
|
2013-05-22 00:20:22 +00:00
|
|
|
#ifndef OSDUTIL_MESH_BATCH_CL_H
|
|
|
|
#define OSDUTIL_MESH_BATCH_CL_H
|
2013-05-10 16:20:45 +00:00
|
|
|
|
|
|
|
#include "../version.h"
|
2013-05-22 00:20:22 +00:00
|
|
|
#include "../osdutil/batch.h"
|
2013-05-10 16:20:45 +00:00
|
|
|
#include "../osd/clComputeController.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// OsdUtilMeshBatch OpenCL specialized class
|
|
|
|
//
|
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT>
|
|
|
|
class OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController> : public OsdUtilMeshBatchBase<DRAW_CONTEXT> {
|
|
|
|
public:
|
|
|
|
typedef VERTEX_BUFFER VertexBuffer;
|
|
|
|
typedef OsdCLComputeController::ComputeContext ComputeContext;
|
|
|
|
typedef DRAW_CONTEXT DrawContext;
|
|
|
|
typedef OsdCLComputeController ComputeController;
|
|
|
|
typedef OsdUtilMeshBatchBase<DRAW_CONTEXT> Base;
|
|
|
|
|
|
|
|
// XXX: not happy with retaining compute controller..
|
2013-05-16 23:55:53 +00:00
|
|
|
static OsdUtilMeshBatch* Create(ComputeController *computeController,
|
|
|
|
const std::vector<FarMesh<OsdVertex> const * > &meshVector,
|
2013-05-22 00:20:22 +00:00
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData=false);
|
2013-05-10 16:20:45 +00:00
|
|
|
|
|
|
|
virtual ~OsdUtilMeshBatch();
|
|
|
|
|
2013-07-02 18:18:06 +00:00
|
|
|
virtual typename DrawContext::VertexBufferBinding BindVertexBuffer() {
|
|
|
|
if (not _vertexBuffer) return 0;
|
|
|
|
return _vertexBuffer->BindVBO();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual typename DrawContext::VertexBufferBinding BindVaryingBuffer() {
|
|
|
|
if (not _varyingBuffer) return 0;
|
|
|
|
return _varyingBuffer->BindVBO();
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:20:45 +00:00
|
|
|
virtual DrawContext * GetDrawContext() const { return _drawContext; }
|
|
|
|
|
|
|
|
// update API
|
2013-07-02 18:18:06 +00:00
|
|
|
virtual void UpdateCoarseVertices(int meshIndex, const float *data, int numVertices) {
|
|
|
|
|
|
|
|
if (not _vertexBuffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Base::setMeshDirty(meshIndex);
|
|
|
|
|
|
|
|
_vertexBuffer->UpdateData(data, Base::GetVertexOffset(meshIndex), numVertices,
|
|
|
|
_computeController->GetCommandQueue());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UpdateCoarseVaryings(int meshIndex, const float *data, int numVertices) {
|
|
|
|
|
|
|
|
if (not _varyingBuffer)
|
|
|
|
return;
|
2013-05-10 16:20:45 +00:00
|
|
|
|
2013-05-16 23:55:53 +00:00
|
|
|
Base::setMeshDirty(meshIndex);
|
2013-05-10 16:20:45 +00:00
|
|
|
|
2013-07-02 18:18:06 +00:00
|
|
|
_varyingBuffer->UpdateData(data, Base::GetVertexOffset(meshIndex), numVertices,
|
|
|
|
_computeController->GetCommandQueue());
|
2013-05-10 16:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// utility function
|
|
|
|
virtual void FinalizeUpdate() {
|
|
|
|
// create kernel batch for dirty handles
|
|
|
|
|
2013-05-16 23:55:53 +00:00
|
|
|
FarKernelBatchVector batches;
|
2013-05-22 00:20:22 +00:00
|
|
|
Base::populateDirtyKernelBatches(batches);
|
2013-05-10 16:20:45 +00:00
|
|
|
Base::resetMeshDirty();
|
|
|
|
|
|
|
|
_computeController->Refine(_computeContext, batches, _vertexBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
VertexBuffer *GetVertexBuffer() const { return _vertexBuffer; }
|
|
|
|
VertexBuffer *GetVaryingBuffer() const { return _varyingBuffer; }
|
|
|
|
|
|
|
|
private:
|
2013-05-22 02:19:00 +00:00
|
|
|
OsdUtilMeshBatch();
|
|
|
|
|
|
|
|
bool initialize(ComputeController *computeController,
|
|
|
|
OsdUtilMeshBatchEntryVector const &entries,
|
|
|
|
FarMesh<OsdVertex> const *farMultiMesh,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData);
|
2013-05-22 02:19:00 +00:00
|
|
|
|
|
|
|
bool initialize(FarPatchTables const *patchTables,
|
|
|
|
int numVertices,
|
|
|
|
int numPtexFaces,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData);
|
2013-05-16 23:55:53 +00:00
|
|
|
|
2013-05-10 16:20:45 +00:00
|
|
|
ComputeController *_computeController;
|
|
|
|
ComputeContext *_computeContext;
|
|
|
|
|
|
|
|
VertexBuffer *_vertexBuffer, *_varyingBuffer;
|
|
|
|
DrawContext *_drawContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2013-05-16 23:55:53 +00:00
|
|
|
|
2013-05-10 16:20:45 +00:00
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT>
|
2013-05-22 02:19:00 +00:00
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>::OsdUtilMeshBatch() :
|
|
|
|
_computeController(NULL), _computeContext(NULL), _vertexBuffer(NULL), _varyingBuffer(NULL), _drawContext(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT> bool
|
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>::initialize(ComputeController *computeController,
|
|
|
|
OsdUtilMeshBatchEntryVector const &entries,
|
|
|
|
FarMesh<OsdVertex> const *farMultiMesh,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData) {
|
2013-05-22 02:19:00 +00:00
|
|
|
Base::initialize(entries, farMultiMesh->GetNumVertices(), farMultiMesh->GetNumPtexFaces(),
|
|
|
|
numVertexElements, batchIndex);
|
|
|
|
|
|
|
|
_computeController = computeController;
|
2013-05-11 02:35:25 +00:00
|
|
|
|
2013-05-16 23:55:53 +00:00
|
|
|
// copy batches
|
|
|
|
Base::setKernelBatches(farMultiMesh->GetKernelBatches());
|
2013-05-11 02:35:25 +00:00
|
|
|
|
2013-05-10 16:20:45 +00:00
|
|
|
// create compute contexts
|
2013-05-11 02:35:25 +00:00
|
|
|
_computeContext = ComputeContext::Create(farMultiMesh, _computeController->GetContext());
|
|
|
|
|
2013-05-22 02:19:00 +00:00
|
|
|
if (not _computeContext) return false;
|
|
|
|
|
2013-05-16 23:55:53 +00:00
|
|
|
FarPatchTables const * patchTables = farMultiMesh->GetPatchTables();
|
|
|
|
|
2013-05-22 00:20:22 +00:00
|
|
|
_vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL;
|
|
|
|
_varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL;
|
|
|
|
|
2013-07-02 18:18:06 +00:00
|
|
|
_drawContext = DrawContext::Create(patchTables, requireFVarData);
|
2013-05-22 02:19:00 +00:00
|
|
|
|
|
|
|
if (not _drawContext) return false;
|
|
|
|
|
2013-05-22 00:20:22 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
2013-05-22 02:19:00 +00:00
|
|
|
|
|
|
|
return true;
|
2013-05-16 23:55:53 +00:00
|
|
|
}
|
2013-05-11 02:35:25 +00:00
|
|
|
|
2013-05-22 02:19:00 +00:00
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT> bool
|
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>::initialize(FarPatchTables const *patchTables,
|
|
|
|
int numVertices,
|
|
|
|
int numPtexFaces,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData) {
|
2013-05-22 02:19:00 +00:00
|
|
|
Base::initialize(numVertices, numPtexFaces, numVertexElements, batchIndex);
|
2013-05-11 02:35:25 +00:00
|
|
|
|
2013-05-22 00:20:22 +00:00
|
|
|
_vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL;
|
|
|
|
_varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL;
|
|
|
|
|
2013-07-02 18:18:06 +00:00
|
|
|
_drawContext = DrawContext::Create(patchTables, requireFVarData);
|
2013-05-22 02:19:00 +00:00
|
|
|
|
|
|
|
if (not _drawContext) return false;
|
|
|
|
|
2013-05-22 00:20:22 +00:00
|
|
|
_drawContext->UpdateVertexTexture(_vertexBuffer);
|
2013-05-22 02:19:00 +00:00
|
|
|
|
|
|
|
return true;
|
2013-05-10 16:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT>
|
2013-07-02 18:18:06 +00:00
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>::~OsdUtilMeshBatch()
|
|
|
|
{
|
2013-05-10 16:20:45 +00:00
|
|
|
delete _computeContext;
|
|
|
|
delete _drawContext;
|
|
|
|
|
|
|
|
delete _vertexBuffer;
|
|
|
|
delete _varyingBuffer;
|
|
|
|
}
|
|
|
|
|
2013-05-16 23:55:53 +00:00
|
|
|
template <typename VERTEX_BUFFER, typename DRAW_CONTEXT>
|
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController> *
|
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>::Create(ComputeController *computeController,
|
2013-05-22 00:20:22 +00:00
|
|
|
const std::vector<FarMesh<OsdVertex> const * > &meshVector,
|
|
|
|
int numVertexElements,
|
|
|
|
int numVaryingElements,
|
2013-07-02 18:18:06 +00:00
|
|
|
int batchIndex,
|
|
|
|
bool requireFVarData) {
|
2013-05-16 23:55:53 +00:00
|
|
|
std::vector<FarPatchTables::PatchArrayVector> multiFarPatchArray;
|
|
|
|
FarMesh <OsdVertex> *farMultiMesh = createMultiMesh(meshVector, multiFarPatchArray);
|
|
|
|
|
|
|
|
FarPatchTables const * patchTables = farMultiMesh->GetPatchTables();
|
|
|
|
|
|
|
|
// create entries
|
|
|
|
OsdUtilMeshBatchEntryVector entries;
|
|
|
|
createEntries(entries, multiFarPatchArray, patchTables->GetMaxValence(), meshVector);
|
|
|
|
|
|
|
|
OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController> *batch =
|
2013-05-22 02:19:00 +00:00
|
|
|
new OsdUtilMeshBatch<VERTEX_BUFFER, DRAW_CONTEXT, OsdCLComputeController>();
|
|
|
|
|
2013-07-02 18:18:06 +00:00
|
|
|
batch->initialize(computeController, entries, farMultiMesh, numVertexElements, numVaryingElements, batchIndex, requireFVarData);
|
2013-05-16 23:55:53 +00:00
|
|
|
|
|
|
|
delete farMultiMesh;
|
|
|
|
|
|
|
|
return batch;
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:20:45 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2013-05-22 00:20:22 +00:00
|
|
|
#endif /* OSDUTIL_MESH_BATCH_H */
|