From 44a7cb6a45c4a455a5f73510e2bc71a647c12ec9 Mon Sep 17 00:00:00 2001 From: Takahito Tejima Date: Wed, 19 Mar 2014 11:44:51 -0700 Subject: [PATCH] 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. --- examples/limitEval/main.cpp | 2 +- examples/osdPolySmooth/osdPolySmooth.cpp | 2 +- opensubdiv/far/bilinearSubdivisionTables.h | 71 ++-- .../far/bilinearSubdivisionTablesFactory.h | 12 +- opensubdiv/far/catmarkSubdivisionTables.h | 100 +++--- .../far/catmarkSubdivisionTablesFactory.h | 12 +- opensubdiv/far/dispatcher.h | 336 ++++++++++-------- opensubdiv/far/kernelBatch.h | 9 +- opensubdiv/far/loopSubdivisionTables.h | 80 ++--- opensubdiv/far/loopSubdivisionTablesFactory.h | 14 +- opensubdiv/far/mesh.h | 9 +- opensubdiv/far/meshFactory.h | 6 +- opensubdiv/far/multiMeshFactory.h | 52 +-- opensubdiv/far/subdivisionTables.h | 39 +- opensubdiv/far/vertexEditTables.h | 36 +- opensubdiv/far/vertexEditTablesFactory.h | 10 +- opensubdiv/osd/clComputeContext.cpp | 23 +- opensubdiv/osd/clComputeContext.h | 3 +- opensubdiv/osd/clComputeController.cpp | 96 ++--- opensubdiv/osd/clComputeController.h | 33 +- opensubdiv/osd/cpuComputeContext.cpp | 22 +- opensubdiv/osd/cpuComputeContext.h | 4 +- opensubdiv/osd/cpuComputeController.cpp | 100 ++---- opensubdiv/osd/cpuComputeController.h | 33 +- opensubdiv/osd/cudaComputeContext.cpp | 24 +- opensubdiv/osd/cudaComputeContext.h | 4 +- opensubdiv/osd/cudaComputeController.cpp | 100 ++---- opensubdiv/osd/cudaComputeController.h | 33 +- opensubdiv/osd/d3d11ComputeContext.cpp | 43 ++- opensubdiv/osd/d3d11ComputeContext.h | 5 +- opensubdiv/osd/d3d11ComputeController.cpp | 52 +-- opensubdiv/osd/d3d11ComputeController.h | 30 +- opensubdiv/osd/drawContext.cpp | 2 +- opensubdiv/osd/gcdComputeController.cpp | 102 ++---- opensubdiv/osd/gcdComputeController.h | 33 +- opensubdiv/osd/glDrawContext.cpp | 2 +- opensubdiv/osd/glslComputeContext.cpp | 44 +-- opensubdiv/osd/glslComputeContext.h | 3 +- opensubdiv/osd/glslComputeController.cpp | 52 +-- opensubdiv/osd/glslComputeController.h | 33 +- opensubdiv/osd/glslKernelBundle.cpp | 14 +- opensubdiv/osd/glslKernelBundle.h | 2 +- .../glslTransformFeedbackComputeContext.cpp | 57 +-- .../osd/glslTransformFeedbackComputeContext.h | 5 +- ...glslTransformFeedbackComputeController.cpp | 52 +-- .../glslTransformFeedbackComputeController.h | 33 +- .../osd/glslTransformFeedbackKernelBundle.cpp | 14 +- .../osd/glslTransformFeedbackKernelBundle.h | 2 +- opensubdiv/osd/ompComputeController.cpp | 100 ++---- opensubdiv/osd/ompComputeController.h | 33 +- opensubdiv/osd/tbbComputeController.cpp | 102 ++---- opensubdiv/osd/tbbComputeController.h | 33 +- opensubdiv/osdutil/refiner.cpp | 3 +- python/osd/subdivider.cpp | 5 +- regression/far_regression/main.cpp | 9 +- 55 files changed, 941 insertions(+), 1189 deletions(-) mode change 100644 => 100755 opensubdiv/osd/d3d11ComputeController.h diff --git a/examples/limitEval/main.cpp b/examples/limitEval/main.cpp index 770ddbeb..f20010ac 100644 --- a/examples/limitEval/main.cpp +++ b/examples/limitEval/main.cpp @@ -82,7 +82,7 @@ typedef HbrHalfedge OsdHbrHalfedge; typedef FarMesh OsdFarMesh; typedef FarMeshFactory OsdFarMeshFactory; -typedef FarSubdivisionTables OsdFarMeshSubdivision; +typedef FarSubdivisionTables OsdFarMeshSubdivision; //------------------------------------------------------------------------------ struct SimpleShape { diff --git a/examples/osdPolySmooth/osdPolySmooth.cpp b/examples/osdPolySmooth/osdPolySmooth.cpp index 0b4ff3f8..b4b57022 100644 --- a/examples/osdPolySmooth/osdPolySmooth.cpp +++ b/examples/osdPolySmooth/osdPolySmooth.cpp @@ -523,7 +523,7 @@ MStatus convertOsdFarToMayaMeshData( int numPolygons = farPatchTables->GetNumFaces(); // use the highest level stored in the patch tables const unsigned int *polygonConnects_orig = farPatchTables->GetFaceVertices(); // use the highest level stored in the patch tables - const OpenSubdiv::FarSubdivisionTables *farSubdivTables = farMesh->GetSubdivisionTables(); + const OpenSubdiv::FarSubdivisionTables *farSubdivTables = farMesh->GetSubdivisionTables(); unsigned int numVertices = farSubdivTables->GetNumVertices(subdivisionLevel); unsigned int vertexOffset = farSubdivTables->GetFirstVertexOffset(subdivisionLevel); diff --git a/opensubdiv/far/bilinearSubdivisionTables.h b/opensubdiv/far/bilinearSubdivisionTables.h index 3d852ba3..463cdf9b 100644 --- a/opensubdiv/far/bilinearSubdivisionTables.h +++ b/opensubdiv/far/bilinearSubdivisionTables.h @@ -42,7 +42,7 @@ namespace OPENSUBDIV_VERSION { /// structure. The advantage of this representation is its ability to be executed /// in a massively parallel environment without data dependencies. /// -template class FarBilinearSubdivisionTables : public FarSubdivisionTables { +class FarBilinearSubdivisionTables : public FarSubdivisionTables { public: @@ -51,56 +51,57 @@ public: virtual int GetNumTables() const { return 7; } /// \brief Returns the subdivision scheme of the tables - virtual typename FarSubdivisionTables::Scheme GetScheme() const { - return FarSubdivisionTables::BILINEAR; + virtual FarSubdivisionTables::Scheme GetScheme() const { + return FarSubdivisionTables::BILINEAR; } private: template friend class FarBilinearSubdivisionTablesFactory; template friend class FarMultiMeshFactory; - template friend class FarComputeController; + friend class FarComputeController; - FarBilinearSubdivisionTables( FarMesh * mesh, int maxlevel ); + FarBilinearSubdivisionTables( int maxlevel ); // Compute-kernel applied to vertices resulting from the refinement of a face. - void computeFacePoints(int vertexOffset, int tableOffset, int start, int end, void * clientdata) const; + template + void computeFacePoints(int vertexOffset, int tableOffset, int start, int end, U *vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of an edge. - void computeEdgePoints(int vertexOffset, int tableOffset, int start, int end, void * clientdata) const; + template + void computeEdgePoints(int vertexOffset, int tableOffset, int start, int end, U *vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of a vertex - void computeVertexPoints(int vertexOffset, int tableOffset, int start, int end, void * clientdata) const; + template + void computeVertexPoints(int vertexOffset, int tableOffset, int start, int end, U *vsrc) const; }; -template -FarBilinearSubdivisionTables::FarBilinearSubdivisionTables( FarMesh * mesh, int maxlevel ) : - FarSubdivisionTables(mesh, maxlevel) -{ } +inline +FarBilinearSubdivisionTables::FarBilinearSubdivisionTables( int maxlevel) : + FarSubdivisionTables(maxlevel) { +} + // // Face-vertices compute Kernel - completely re-entrant // template void -FarBilinearSubdivisionTables::computeFacePoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarBilinearSubdivisionTables::computeFacePoints( int offset, int tableOffset, int start, int end, U *vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int h = this->_F_ITa[2*i ], n = this->_F_ITa[2*i+1]; float weight = 1.0f/n; for (int j=0; jAddWithWeight( vsrc[ this->_F_IT[h+j] ], weight, clientdata ); - vdst->AddVaryingWithWeight( vsrc[ this->_F_IT[h+j] ], weight, clientdata ); + vdst->AddWithWeight( vsrc[ this->_F_IT[h+j] ], weight ); + vdst->AddVaryingWithWeight( vsrc[ this->_F_IT[h+j] ], weight ); } } } @@ -110,25 +111,22 @@ FarBilinearSubdivisionTables::computeFacePoints( int offset, int tableOffset, // template void -FarBilinearSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarBilinearSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, U *vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int eidx0 = this->_E_IT[2*i+0], eidx1 = this->_E_IT[2*i+1]; - vdst->AddWithWeight( vsrc[eidx0], 0.5f, clientdata ); - vdst->AddWithWeight( vsrc[eidx1], 0.5f, clientdata ); + vdst->AddWithWeight( vsrc[eidx0], 0.5f ); + vdst->AddWithWeight( vsrc[eidx1], 0.5f ); - vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f, clientdata ); - vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f ); + vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f ); } } @@ -137,21 +135,18 @@ FarBilinearSubdivisionTables::computeEdgePoints( int offset, int tableOffset // template void -FarBilinearSubdivisionTables::computeVertexPoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarBilinearSubdivisionTables::computeVertexPoints( int offset, int tableOffset, int start, int end, U *vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int p = this->_V_ITa[i]; // index of the parent vertex - vdst->AddWithWeight( vsrc[p], 1.0f, clientdata ); - vdst->AddVaryingWithWeight( vsrc[p], 1.0f, clientdata ); + vdst->AddWithWeight( vsrc[p], 1.0f ); + vdst->AddVaryingWithWeight( vsrc[p], 1.0f ); } } diff --git a/opensubdiv/far/bilinearSubdivisionTablesFactory.h b/opensubdiv/far/bilinearSubdivisionTablesFactory.h index 3104c5d9..e95263c0 100644 --- a/opensubdiv/far/bilinearSubdivisionTablesFactory.h +++ b/opensubdiv/far/bilinearSubdivisionTablesFactory.h @@ -51,21 +51,19 @@ protected: /// /// @param meshFactory a valid FarMeshFactory instance /// - /// @param farMesh - /// /// @param batches a vector of Kernel refinement batches : the factory /// will reserve and append refinement tasks /// - static FarBilinearSubdivisionTables * Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector *batches ); + static FarBilinearSubdivisionTables * Create( FarMeshFactory * meshFactory, FarKernelBatchVector *batches ); }; // This factory walks the Hbr vertices and accumulates the weights and adjacency // (valance) information specific to the bilinear subdivision scheme. The results // are stored in a FarBilinearSubdivisionTable -template FarBilinearSubdivisionTables * -FarBilinearSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector * batches ) { +template FarBilinearSubdivisionTables * +FarBilinearSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarKernelBatchVector * batches ) { - assert( meshFactory and farMesh ); + assert( meshFactory ); int maxlevel = meshFactory->GetMaxLevel(); @@ -73,7 +71,7 @@ FarBilinearSubdivisionTablesFactory::Create( FarMeshFactory * meshFact FarSubdivisionTablesFactory tablesFactory( meshFactory->GetHbrMesh(), maxlevel, remap ); - FarBilinearSubdivisionTables * result = new FarBilinearSubdivisionTables(farMesh, maxlevel); + FarBilinearSubdivisionTables * result = new FarBilinearSubdivisionTables(maxlevel); // Allocate memory for the indexing tables result->_F_ITa.resize(tablesFactory.GetNumFaceVerticesTotal(maxlevel)*2); diff --git a/opensubdiv/far/catmarkSubdivisionTables.h b/opensubdiv/far/catmarkSubdivisionTables.h index de86a00f..5c306223 100644 --- a/opensubdiv/far/catmarkSubdivisionTables.h +++ b/opensubdiv/far/catmarkSubdivisionTables.h @@ -42,7 +42,7 @@ namespace OPENSUBDIV_VERSION { /// structure. The advantage of this representation is its ability to be executed /// in a massively parallel environment without data dependencies. /// -template class FarCatmarkSubdivisionTables : public FarSubdivisionTables { +class FarCatmarkSubdivisionTables : public FarSubdivisionTables { public: @@ -51,62 +51,63 @@ public: virtual int GetNumTables() const { return 7; } /// \brief Returns the subdivision scheme of the tables - virtual typename FarSubdivisionTables::Scheme GetScheme() const { - return FarSubdivisionTables::CATMARK; + virtual FarSubdivisionTables::Scheme GetScheme() const { + return FarSubdivisionTables::CATMARK; } private: template friend class FarCatmarkSubdivisionTablesFactory; template friend class FarMultiMeshFactory; - template friend class FarComputeController; + friend class FarComputeController; // Private constructor called by factory - FarCatmarkSubdivisionTables( FarMesh * mesh, int maxlevel ); + FarCatmarkSubdivisionTables( int maxlevel ); // Compute-kernel applied to vertices resulting from the refinement of a face. - void computeFacePoints(int offset, int level, int start, int end, void * clientdata) const; + template + void computeFacePoints(int offset, int level, int start, int end, U * vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of an edge. - void computeEdgePoints(int offset, int level, int start, int end, void * clientdata) const; + template + void computeEdgePoints(int offset, int level, int start, int end, U * vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of a vertex // Kernel "A" Handles the k_Smooth and k_Dart rules - void computeVertexPointsA(int offset, bool pass, int level, int start, int end, void * clientdata) const; + template + void computeVertexPointsA(int offset, bool pass, int level, int start, int end, U * vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of a vertex // Kernel "B" Handles the k_Crease and k_Corner rules - void computeVertexPointsB(int offset, int level, int start, int end, void * clientdata) const; + template + void computeVertexPointsB(int offset, int level, int start, int end, U * vsrc) const; }; -template -FarCatmarkSubdivisionTables::FarCatmarkSubdivisionTables( FarMesh * mesh, int maxlevel ) : - FarSubdivisionTables(mesh, maxlevel) -{ } +inline +FarCatmarkSubdivisionTables::FarCatmarkSubdivisionTables( int maxlevel ) : + FarSubdivisionTables(maxlevel) { +} // // Face-vertices compute Kernel - completely re-entrant // template void -FarCatmarkSubdivisionTables::computeFacePoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarCatmarkSubdivisionTables::computeFacePoints( int offset, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int h = this->_F_ITa[2*i ], n = this->_F_ITa[2*i+1]; float weight = 1.0f/n; for (int j=0; jAddWithWeight( vsrc[ this->_F_IT[h+j] ], weight, clientdata ); - vdst->AddVaryingWithWeight( vsrc[ this->_F_IT[h+j] ], weight, clientdata ); + vdst->AddWithWeight( vsrc[ this->_F_IT[h+j] ], weight ); + vdst->AddVaryingWithWeight( vsrc[ this->_F_IT[h+j] ], weight ); } } } @@ -116,16 +117,13 @@ FarCatmarkSubdivisionTables::computeFacePoints( int offset, int tableOffset, // template void -FarCatmarkSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarCatmarkSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int eidx0 = this->_E_IT[4*i+0], eidx1 = this->_E_IT[4*i+1], @@ -135,19 +133,19 @@ FarCatmarkSubdivisionTables::computeEdgePoints( int offset, int tableOffset, float vertWeight = this->_E_W[i*2+0]; // Fully sharp edge : vertWeight = 0.5f - vdst->AddWithWeight( vsrc[eidx0], vertWeight, clientdata ); - vdst->AddWithWeight( vsrc[eidx1], vertWeight, clientdata ); + vdst->AddWithWeight( vsrc[eidx0], vertWeight ); + vdst->AddWithWeight( vsrc[eidx1], vertWeight ); if (eidx2!=-1) { // Apply fractional sharpness float faceWeight = this->_E_W[i*2+1]; - vdst->AddWithWeight( vsrc[eidx2], faceWeight, clientdata ); - vdst->AddWithWeight( vsrc[eidx3], faceWeight, clientdata ); + vdst->AddWithWeight( vsrc[eidx2], faceWeight ); + vdst->AddWithWeight( vsrc[eidx3], faceWeight ); } - vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f, clientdata ); - vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f ); + vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f ); } } @@ -157,17 +155,14 @@ FarCatmarkSubdivisionTables::computeEdgePoints( int offset, int tableOffset, // multi-pass kernel handling k_Crease and k_Corner rules template void -FarCatmarkSubdivisionTables::computeVertexPointsA( int offset, bool pass, int tableOffset, int start, int end, void * clientdata ) const { +FarCatmarkSubdivisionTables::computeVertexPointsA( int offset, bool pass, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int n=this->_V_ITa[5*i+1], // number of vertices in the _VO_IT array (valence) p=this->_V_ITa[5*i+2], // index of the parent vertex @@ -186,29 +181,26 @@ FarCatmarkSubdivisionTables::computeVertexPointsA( int offset, bool pass, int // won't be null, so we use a -1 valence to detect that particular case if (eidx0==-1 or (pass==false and (n==-1)) ) { // k_Corner case - vdst->AddWithWeight( vsrc[p], weight, clientdata ); + vdst->AddWithWeight( vsrc[p], weight ); } else { // k_Crease case - vdst->AddWithWeight( vsrc[p], weight * 0.75f, clientdata ); - vdst->AddWithWeight( vsrc[eidx0], weight * 0.125f, clientdata ); - vdst->AddWithWeight( vsrc[eidx1], weight * 0.125f, clientdata ); + vdst->AddWithWeight( vsrc[p], weight * 0.75f ); + vdst->AddWithWeight( vsrc[eidx0], weight * 0.125f ); + vdst->AddWithWeight( vsrc[eidx1], weight * 0.125f ); } - vdst->AddVaryingWithWeight( vsrc[p], 1.0f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[p], 1.0f ); } } // multi-pass kernel handling k_Dart and k_Smooth rules template void -FarCatmarkSubdivisionTables::computeVertexPointsB( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarCatmarkSubdivisionTables::computeVertexPointsB( int offset, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int h = this->_V_ITa[5*i ], // offset of the vertices in the _V0_IT array n = this->_V_ITa[5*i+1], // number of vertices in the _VO_IT array (valence) @@ -218,13 +210,13 @@ FarCatmarkSubdivisionTables::computeVertexPointsB( int offset, int tableOffse wp = 1.0f/(n*n), wv = (n-2.0f)*n*wp; - vdst->AddWithWeight( vsrc[p], weight * wv, clientdata ); + vdst->AddWithWeight( vsrc[p], weight * wv ); for (int j=0; jAddWithWeight( vsrc[this->_V_IT[h+j*2 ]], weight * wp, clientdata ); - vdst->AddWithWeight( vsrc[this->_V_IT[h+j*2+1]], weight * wp, clientdata ); + vdst->AddWithWeight( vsrc[this->_V_IT[h+j*2 ]], weight * wp ); + vdst->AddWithWeight( vsrc[this->_V_IT[h+j*2+1]], weight * wp ); } - vdst->AddVaryingWithWeight( vsrc[p], 1.0f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[p], 1.0f ); } } diff --git a/opensubdiv/far/catmarkSubdivisionTablesFactory.h b/opensubdiv/far/catmarkSubdivisionTablesFactory.h index 529e7aa8..8b4c531f 100644 --- a/opensubdiv/far/catmarkSubdivisionTablesFactory.h +++ b/opensubdiv/far/catmarkSubdivisionTablesFactory.h @@ -52,21 +52,19 @@ protected: /// /// @param meshFactory a valid FarMeshFactory instance /// - /// @param farMesh - /// /// @param batches a vector of Kernel refinement batches : the factory /// will reserve and append refinement tasks /// - static FarCatmarkSubdivisionTables * Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector *batches ); + static FarCatmarkSubdivisionTables * Create( FarMeshFactory * meshFactory, FarKernelBatchVector *batches ); }; // This factory walks the Hbr vertices and accumulates the weights and adjacency // (valance) information specific to the catmark subdivision scheme. The results // are stored in a FarCatmarkSubdivisionTable. -template FarCatmarkSubdivisionTables * -FarCatmarkSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector *batches ) { +template FarCatmarkSubdivisionTables * +FarCatmarkSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarKernelBatchVector *batches ) { - assert( meshFactory and farMesh ); + assert( meshFactory ); int maxlevel = meshFactory->GetMaxLevel(); @@ -74,7 +72,7 @@ FarCatmarkSubdivisionTablesFactory::Create( FarMeshFactory * meshFacto FarSubdivisionTablesFactory tablesFactory( meshFactory->GetHbrMesh(), maxlevel, remap ); - FarCatmarkSubdivisionTables * result = new FarCatmarkSubdivisionTables(farMesh, maxlevel); + FarCatmarkSubdivisionTables * result = new FarCatmarkSubdivisionTables(maxlevel); // Allocate memory for the indexing tables result->_F_ITa.resize(tablesFactory.GetNumFaceVerticesTotal(maxlevel)*2); diff --git a/opensubdiv/far/dispatcher.h b/opensubdiv/far/dispatcher.h index c541b219..21bb8b73 100644 --- a/opensubdiv/far/dispatcher.h +++ b/opensubdiv/far/dispatcher.h @@ -27,7 +27,6 @@ #include "../version.h" -#include "../far/mesh.h" #include "../far/bilinearSubdivisionTables.h" #include "../far/catmarkSubdivisionTables.h" #include "../far/loopSubdivisionTables.h" @@ -54,72 +53,98 @@ namespace OPENSUBDIV_VERSION { /// class FarDispatcher { public: - /// \brief Launches the processing of a vector of kernel batches + /// \brief Launches the processing of a kernel batch + /// returns true if the batch is handled, otherwise returns false (i.e. user defined kernel) /// /// @param controller refinement controller implementation /// + /// @param context refinement context implementation + /// + /// @param batch a batch of kernel that need to be processed + /// + template + static bool ApplyKernel(CONTROLLER const *controller, CONTEXT *context, FarKernelBatch const &batch); + + /// \brief Launches the processing of a vector of kernel batches + /// this is a convenient API for controllers which don't have any user defined kernels. + /// + /// @param controller refinement controller implementation + /// + /// @param context refinement context implementation (vertex array and subdivision tables) + /// passed to the controller. + /// /// @param batches batches of kernels that need to be processed /// /// @param maxlevel process vertex batches up to this level /// - /// @param clientdata custom client data passed to the controller - /// - template - static void Refine(CONTROLLER const *controller, FarKernelBatchVector const & batches, int maxlevel, void * clientdata=0); + template + static void Refine(CONTROLLER const *controller, CONTEXT *context, FarKernelBatchVector const & batches, int maxlevel); + }; -template void -FarDispatcher::Refine(CONTROLLER const *controller, FarKernelBatchVector const & batches, int maxlevel, void * clientdata) { +template bool +FarDispatcher::ApplyKernel(CONTROLLER const *controller, CONTEXT *context, FarKernelBatch const &batch) { + + switch(batch.GetKernelType()) { + case FarKernelBatch::CATMARK_FACE_VERTEX: + controller->ApplyCatmarkFaceVerticesKernel(batch, context); + break; + case FarKernelBatch::CATMARK_EDGE_VERTEX: + controller->ApplyCatmarkEdgeVerticesKernel(batch, context); + break; + case FarKernelBatch::CATMARK_VERT_VERTEX_B: + controller->ApplyCatmarkVertexVerticesKernelB(batch, context); + break; + case FarKernelBatch::CATMARK_VERT_VERTEX_A1: + controller->ApplyCatmarkVertexVerticesKernelA1(batch, context); + break; + case FarKernelBatch::CATMARK_VERT_VERTEX_A2: + controller->ApplyCatmarkVertexVerticesKernelA2(batch, context); + break; + + case FarKernelBatch::LOOP_EDGE_VERTEX: + controller->ApplyLoopEdgeVerticesKernel(batch, context); + break; + case FarKernelBatch::LOOP_VERT_VERTEX_B: + controller->ApplyLoopVertexVerticesKernelB(batch, context); + break; + case FarKernelBatch::LOOP_VERT_VERTEX_A1: + controller->ApplyLoopVertexVerticesKernelA1(batch, context); + break; + case FarKernelBatch::LOOP_VERT_VERTEX_A2: + controller->ApplyLoopVertexVerticesKernelA2(batch, context); + break; + + case FarKernelBatch::BILINEAR_FACE_VERTEX: + controller->ApplyBilinearFaceVerticesKernel(batch, context); + break; + case FarKernelBatch::BILINEAR_EDGE_VERTEX: + controller->ApplyBilinearEdgeVerticesKernel(batch, context); + break; + case FarKernelBatch::BILINEAR_VERT_VERTEX: + controller->ApplyBilinearVertexVerticesKernel(batch, context); + break; + + case FarKernelBatch::HIERARCHICAL_EDIT: + controller->ApplyVertexEdits(batch, context); + break; + + default: // user defined kernel type + return false; + } + + return true; +} + +template void +FarDispatcher::Refine(CONTROLLER const *controller, CONTEXT *context, FarKernelBatchVector const & batches, int maxlevel) { for (int i = 0; i < (int)batches.size(); ++i) { const FarKernelBatch &batch = batches[i]; if (maxlevel >= 0 && batch.GetLevel() >= maxlevel) continue; - switch(batch.GetKernelType()) { - case FarKernelBatch::CATMARK_FACE_VERTEX: - controller->ApplyCatmarkFaceVerticesKernel(batch, clientdata); - break; - case FarKernelBatch::CATMARK_EDGE_VERTEX: - controller->ApplyCatmarkEdgeVerticesKernel(batch, clientdata); - break; - case FarKernelBatch::CATMARK_VERT_VERTEX_B: - controller->ApplyCatmarkVertexVerticesKernelB(batch, clientdata); - break; - case FarKernelBatch::CATMARK_VERT_VERTEX_A1: - controller->ApplyCatmarkVertexVerticesKernelA1(batch, clientdata); - break; - case FarKernelBatch::CATMARK_VERT_VERTEX_A2: - controller->ApplyCatmarkVertexVerticesKernelA2(batch, clientdata); - break; - - case FarKernelBatch::LOOP_EDGE_VERTEX: - controller->ApplyLoopEdgeVerticesKernel(batch, clientdata); - break; - case FarKernelBatch::LOOP_VERT_VERTEX_B: - controller->ApplyLoopVertexVerticesKernelB(batch, clientdata); - break; - case FarKernelBatch::LOOP_VERT_VERTEX_A1: - controller->ApplyLoopVertexVerticesKernelA1(batch, clientdata); - break; - case FarKernelBatch::LOOP_VERT_VERTEX_A2: - controller->ApplyLoopVertexVerticesKernelA2(batch, clientdata); - break; - - case FarKernelBatch::BILINEAR_FACE_VERTEX: - controller->ApplyBilinearFaceVerticesKernel(batch, clientdata); - break; - case FarKernelBatch::BILINEAR_EDGE_VERTEX: - controller->ApplyBilinearEdgeVerticesKernel(batch, clientdata); - break; - case FarKernelBatch::BILINEAR_VERT_VERTEX: - controller->ApplyBilinearVertexVerticesKernel(batch, clientdata); - break; - - case FarKernelBatch::HIERARCHICAL_EDIT: - controller->ApplyVertexEdits(batch, clientdata); - break; - } + ApplyKernel(controller, context, batch); } } @@ -129,92 +154,101 @@ FarDispatcher::Refine(CONTROLLER const *controller, FarKernelBatchVector const & /// /// This is Far's default implementation of a kernal batch controller. /// -template class FarComputeController { public: - void Refine(FarMesh * mesh, int maxlevel=-1) const; + template + void Refine(CONTEXT * context, int maxlevel=-1) const; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; + template + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + template + void ApplyVertexEdits(FarKernelBatch const &batch, CONTEXT *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; - - static FarComputeController _DefaultController; - private: }; -template FarComputeController FarComputeController::_DefaultController; +template void +FarComputeController::Refine(CONTEXT *context, int maxlevel) const { -template void -FarComputeController::Refine(FarMesh *mesh, int maxlevel) const { + FarDispatcher::Refine(this, context, context->GetKernelBatches(), maxlevel); - FarDispatcher::Refine(this, mesh->GetKernelBatches(), maxlevel, mesh); } -template void -FarComputeController::ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarBilinearSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarBilinearSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); subdivision->computeFacePoints( batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarBilinearSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarBilinearSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); subdivision->computeEdgePoints( batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarBilinearSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarBilinearSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -222,16 +256,16 @@ FarComputeController::ApplyBilinearVertexVerticesKernel(FarKernelBatch const batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarCatmarkSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarCatmarkSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -239,16 +273,16 @@ FarComputeController::ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &ba batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarCatmarkSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarCatmarkSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -256,16 +290,16 @@ FarComputeController::ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &ba batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarCatmarkSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarCatmarkSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -273,16 +307,16 @@ FarComputeController::ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarCatmarkSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarCatmarkSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -291,16 +325,16 @@ FarComputeController::ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarCatmarkSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarCatmarkSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -309,16 +343,16 @@ FarComputeController::ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarLoopSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarLoopSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -326,16 +360,16 @@ FarComputeController::ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarLoopSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarLoopSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -343,16 +377,16 @@ FarComputeController::ApplyLoopVertexVerticesKernelB(FarKernelBatch const &ba batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarLoopSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarLoopSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -361,16 +395,16 @@ FarComputeController::ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &b batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } -template void -FarComputeController::ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarLoopSubdivisionTables const * subdivision = - reinterpret_cast const *>(mesh->GetSubdivisionTables()); + FarLoopSubdivisionTables const * subdivision = + reinterpret_cast(context->GetSubdivisionTables()); assert(subdivision); @@ -379,15 +413,15 @@ FarComputeController::ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &b batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata); + vsrc ); } -template void -FarComputeController::ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const { +template void +FarComputeController::ApplyVertexEdits(FarKernelBatch const &batch, CONTEXT *context) const { - FarMesh * mesh = static_cast *>(clientdata); + typename CONTEXT::VertexType *vsrc = &context->GetVertices().at(0); - FarVertexEditTables const * vertEdit = mesh->GetVertexEdit(); + FarVertexEditTables const * vertEdit = context->GetVertexEdit(); if (vertEdit) vertEdit->computeVertexEdits( batch.GetTableIndex(), @@ -395,7 +429,7 @@ FarComputeController::ApplyVertexEdits(FarKernelBatch const &batch, void * cl batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), - clientdata ); + vsrc ); } } // end namespace OPENSUBDIV_VERSION diff --git a/opensubdiv/far/kernelBatch.h b/opensubdiv/far/kernelBatch.h index 97e31963..a4bc0249 100644 --- a/opensubdiv/far/kernelBatch.h +++ b/opensubdiv/far/kernelBatch.h @@ -65,7 +65,7 @@ class FarKernelBatch { public: enum KernelType { - CATMARK_FACE_VERTEX, + CATMARK_FACE_VERTEX = 1, CATMARK_EDGE_VERTEX, CATMARK_VERT_VERTEX_A1, CATMARK_VERT_VERTEX_A2, @@ -78,6 +78,7 @@ public: BILINEAR_EDGE_VERTEX, BILINEAR_VERT_VERTEX, HIERARCHICAL_EDIT, + USER_DEFINED_KERNEL_START }; /// \brief Constructor. @@ -98,7 +99,7 @@ public: /// /// @param meshIndex XXXX /// - FarKernelBatch( KernelType kernelType, + FarKernelBatch( int kernelType, int level, int tableIndex, int start, @@ -117,7 +118,7 @@ public: } /// \brief Returns the type of kernel to apply to the vertices in the batch. - KernelType GetKernelType() const { + int GetKernelType() const { return _kernelType; } @@ -192,7 +193,7 @@ private: friend class FarKernelBatchFactory; template friend class FarMultiMeshFactory; - KernelType _kernelType; + int _kernelType; int _level; int _tableIndex; int _start; diff --git a/opensubdiv/far/loopSubdivisionTables.h b/opensubdiv/far/loopSubdivisionTables.h index da9b04b5..41bd010d 100644 --- a/opensubdiv/far/loopSubdivisionTables.h +++ b/opensubdiv/far/loopSubdivisionTables.h @@ -43,54 +43,54 @@ namespace OPENSUBDIV_VERSION { /// structure. The advantage of this representation is its ability to be executed /// in a massively parallel environment without data dependencies. /// -template class FarLoopSubdivisionTables : public FarSubdivisionTables { +class FarLoopSubdivisionTables : public FarSubdivisionTables { public: /// \brief Returns the subdivision scheme of the tables - virtual typename FarSubdivisionTables::Scheme GetScheme() const { - return FarSubdivisionTables::LOOP; + virtual FarSubdivisionTables::Scheme GetScheme() const { + return FarSubdivisionTables::LOOP; } private: template friend class FarLoopSubdivisionTablesFactory; template friend class FarMultiMeshFactory; - template friend class FarComputeController; + friend class FarComputeController; - FarLoopSubdivisionTables( FarMesh * mesh, int maxlevel ); + FarLoopSubdivisionTables( int maxlevel ); // Compute-kernel applied to vertices resulting from the refinement of an edge. - void computeEdgePoints(int offset, int level, int start, int end, void * clientdata) const; + template + void computeEdgePoints(int offset, int level, int start, int end, U *vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of a vertex // Kernel "A" Handles the k_Smooth and k_Dart rules - void computeVertexPointsA(int offset, bool pass, int level, int start, int end, void * clientdata) const; + template + void computeVertexPointsA(int offset, bool pass, int level, int start, int end, U *vsrc) const; // Compute-kernel applied to vertices resulting from the refinement of a vertex // Kernel "B" Handles the k_Crease and k_Corner rules - void computeVertexPointsB(int offset,int level, int start, int end, void * clientdata) const; + template + void computeVertexPointsB(int offset,int level, int start, int end, U *vsrc) const; }; -template -FarLoopSubdivisionTables::FarLoopSubdivisionTables( FarMesh * mesh, int maxlevel ) : - FarSubdivisionTables(mesh, maxlevel) -{ } +inline +FarLoopSubdivisionTables::FarLoopSubdivisionTables( int maxlevel ) : + FarSubdivisionTables(maxlevel) { +} // // Edge-vertices compute Kernel - completely re-entrant // template void -FarLoopSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarLoopSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int eidx0 = this->_E_IT[4*i+0], eidx1 = this->_E_IT[4*i+1], @@ -100,19 +100,19 @@ FarLoopSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int float endPtWeight = this->_E_W[i*2+0]; // Fully sharp edge : endPtWeight = 0.5f - vdst->AddWithWeight( vsrc[eidx0], endPtWeight, clientdata ); - vdst->AddWithWeight( vsrc[eidx1], endPtWeight, clientdata ); + vdst->AddWithWeight( vsrc[eidx0], endPtWeight ); + vdst->AddWithWeight( vsrc[eidx1], endPtWeight ); if (eidx2!=-1) { // Apply fractional sharpness float oppPtWeight = this->_E_W[i*2+1]; - vdst->AddWithWeight( vsrc[eidx2], oppPtWeight, clientdata ); - vdst->AddWithWeight( vsrc[eidx3], oppPtWeight, clientdata ); + vdst->AddWithWeight( vsrc[eidx2], oppPtWeight ); + vdst->AddWithWeight( vsrc[eidx3], oppPtWeight ); } - vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f, clientdata ); - vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[eidx0], 0.5f ); + vdst->AddVaryingWithWeight( vsrc[eidx1], 0.5f ); } } @@ -122,17 +122,14 @@ FarLoopSubdivisionTables::computeEdgePoints( int offset, int tableOffset, int // multi-pass kernel handling k_Crease and k_Corner rules template void -FarLoopSubdivisionTables::computeVertexPointsA( int offset, bool pass, int tableOffset, int start, int end, void * clientdata ) const { +FarLoopSubdivisionTables::computeVertexPointsA( int offset, bool pass, int tableOffset, int start, int end, U * vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int n=this->_V_ITa[5*i+1], // number of vertices in the _VO_IT array (valence) p=this->_V_ITa[5*i+2], // index of the parent vertex @@ -151,29 +148,26 @@ FarLoopSubdivisionTables::computeVertexPointsA( int offset, bool pass, int ta // won't be null, so we use a -1 valence to detect that particular case if (eidx0==-1 or (pass==false and (n==-1)) ) { // k_Corner case - vdst->AddWithWeight( vsrc[p], weight, clientdata ); + vdst->AddWithWeight( vsrc[p], weight ); } else { // k_Crease case - vdst->AddWithWeight( vsrc[p], weight * 0.75f, clientdata ); - vdst->AddWithWeight( vsrc[eidx0], weight * 0.125f, clientdata ); - vdst->AddWithWeight( vsrc[eidx1], weight * 0.125f, clientdata ); + vdst->AddWithWeight( vsrc[p], weight * 0.75f ); + vdst->AddWithWeight( vsrc[eidx0], weight * 0.125f ); + vdst->AddWithWeight( vsrc[eidx1], weight * 0.125f ); } - vdst->AddVaryingWithWeight( vsrc[p], 1.0f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[p], 1.0f ); } } // multi-pass kernel handling k_Dart and k_Smooth rules template void -FarLoopSubdivisionTables::computeVertexPointsB( int offset, int tableOffset, int start, int end, void * clientdata ) const { +FarLoopSubdivisionTables::computeVertexPointsB( int offset, int tableOffset, int start, int end, U *vsrc ) const { - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0), - * vdst = vsrc + offset + start; + U * vdst = vsrc + offset + start; for (int i=start+tableOffset; iClear(clientdata); + vdst->Clear(); int h = this->_V_ITa[5*i ], // offset of the vertices in the _V0_IT array n = this->_V_ITa[5*i+1], // number of vertices in the _VO_IT array (valence) @@ -185,12 +179,12 @@ FarLoopSubdivisionTables::computeVertexPointsB( int offset, int tableOffset, beta = beta*beta; beta = (0.625f-beta)*wp; - vdst->AddWithWeight( vsrc[p], weight * (1.0f-(beta*n)), clientdata); + vdst->AddWithWeight( vsrc[p], weight * (1.0f-(beta*n))); for (int j=0; jAddWithWeight( vsrc[this->_V_IT[h+j]], weight * beta ); - vdst->AddVaryingWithWeight( vsrc[p], 1.0f, clientdata ); + vdst->AddVaryingWithWeight( vsrc[p], 1.0f ); } } diff --git a/opensubdiv/far/loopSubdivisionTablesFactory.h b/opensubdiv/far/loopSubdivisionTablesFactory.h index c9af9a65..40d87d7b 100644 --- a/opensubdiv/far/loopSubdivisionTablesFactory.h +++ b/opensubdiv/far/loopSubdivisionTablesFactory.h @@ -52,21 +52,19 @@ protected: /// /// @param meshFactory a valid FarMeshFactory instance /// - /// @param farMesh - /// /// @param batches a vector of Kernel refinement batches : the factory /// will reserve and append refinement tasks /// - static FarLoopSubdivisionTables * Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector * batches ); + static FarLoopSubdivisionTables * Create( FarMeshFactory * meshFactory, FarKernelBatchVector * batches ); }; // This factory walks the Hbr vertices and accumulates the weights and adjacency // (valance) information specific to the loop subdivision scheme. The results -// are stored in a FarLoopSubdivisionTable. -template FarLoopSubdivisionTables * -FarLoopSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarMesh * farMesh, FarKernelBatchVector * batches ) { +// are stored in a FarLoopSubdivisionTable. +template FarLoopSubdivisionTables * +FarLoopSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarKernelBatchVector * batches ) { - assert( meshFactory and farMesh ); + assert( meshFactory ); int maxlevel = meshFactory->GetMaxLevel(); @@ -74,7 +72,7 @@ FarLoopSubdivisionTablesFactory::Create( FarMeshFactory * meshFactory, FarSubdivisionTablesFactory tablesFactory( meshFactory->GetHbrMesh(), maxlevel, remap ); - FarLoopSubdivisionTables * result = new FarLoopSubdivisionTables(farMesh, maxlevel); + FarLoopSubdivisionTables * result = new FarLoopSubdivisionTables(maxlevel); // Allocate memory for the indexing tables result->_E_IT.resize(tablesFactory.GetNumEdgeVerticesTotal(maxlevel)*4); diff --git a/opensubdiv/far/mesh.h b/opensubdiv/far/mesh.h index db570982..c9b1ead2 100644 --- a/opensubdiv/far/mesh.h +++ b/opensubdiv/far/mesh.h @@ -48,11 +48,12 @@ namespace OPENSUBDIV_VERSION { /// template class FarMesh { public: + typedef U VertexType; ~FarMesh(); /// \brief Returns the subdivision method - FarSubdivisionTables const * GetSubdivisionTables() const { return _subdivisionTables; } + FarSubdivisionTables const * GetSubdivisionTables() const { return _subdivisionTables; } /// \brief Returns patch tables FarPatchTables const * GetPatchTables() const { return _patchTables; } @@ -73,7 +74,7 @@ public: int GetTotalFVarWidth() const { return _totalFVarWidth; } /// \brief Returns vertex edit tables - FarVertexEditTables const * GetVertexEdit() const { return _vertexEditTables; } + FarVertexEditTables const * GetVertexEdit() const { return _vertexEditTables; } /// \brief Returns the total number of vertices in the mesh across across all depths int GetNumPtexFaces() const { return _numPtexFaces; } @@ -99,13 +100,13 @@ private: FarMesh & operator = (FarMesh const &); // subdivision method used in this mesh - FarSubdivisionTables * _subdivisionTables; + FarSubdivisionTables * _subdivisionTables; // tables of vertex indices for feature adaptive patches FarPatchTables * _patchTables; // hierarchical vertex edit tables - FarVertexEditTables * _vertexEditTables; + FarVertexEditTables * _vertexEditTables; // kernel execution batches FarKernelBatchVector _batches; diff --git a/opensubdiv/far/meshFactory.h b/opensubdiv/far/meshFactory.h index faa72913..de16d34e 100644 --- a/opensubdiv/far/meshFactory.h +++ b/opensubdiv/far/meshFactory.h @@ -701,11 +701,11 @@ FarMeshFactory::Create( bool requireFVarData ) { FarMesh * result = new FarMesh(); if ( isBilinear( GetHbrMesh() ) ) { - result->_subdivisionTables = FarBilinearSubdivisionTablesFactory::Create(this, result, &result->_batches); + result->_subdivisionTables = FarBilinearSubdivisionTablesFactory::Create(this, &result->_batches); } else if ( isCatmark( GetHbrMesh() ) ) { - result->_subdivisionTables = FarCatmarkSubdivisionTablesFactory::Create(this, result, &result->_batches); + result->_subdivisionTables = FarCatmarkSubdivisionTablesFactory::Create(this, &result->_batches); } else if ( isLoop(GetHbrMesh()) ) { - result->_subdivisionTables = FarLoopSubdivisionTablesFactory::Create(this, result, &result->_batches); + result->_subdivisionTables = FarLoopSubdivisionTablesFactory::Create(this, &result->_batches); } else assert(0); assert(result->_subdivisionTables); diff --git a/opensubdiv/far/multiMeshFactory.h b/opensubdiv/far/multiMeshFactory.h index 00883755..2568bab4 100644 --- a/opensubdiv/far/multiMeshFactory.h +++ b/opensubdiv/far/multiMeshFactory.h @@ -68,7 +68,7 @@ public: private: // splice subdivision tables - FarSubdivisionTables * spliceSubdivisionTables(FarMesh *farmesh, FarMeshVector const &meshes); + FarSubdivisionTables * spliceSubdivisionTables(FarMesh *farmesh, FarMeshVector const &meshes); // splice patch tables FarPatchTables * splicePatchTables(FarMeshVector const &meshes, bool hasFVarData); @@ -82,7 +82,7 @@ private: std::vector const &vertexOffsets); // splice hierarchical edit tables - FarVertexEditTables * spliceVertexEditTables(FarMesh *farmesh, FarMeshVector const &meshes); + FarVertexEditTables * spliceVertexEditTables(FarMeshVector const &meshes); int _maxlevel; int _maxvalence; @@ -100,7 +100,7 @@ FarMultiMeshFactory::Create(std::vector const *> const &meshes) int totalFVarWidth = meshes[0]->GetTotalFVarWidth(); - typename FarSubdivisionTables::Scheme scheme = + typename FarSubdivisionTables::Scheme scheme = meshes[0]->GetSubdivisionTables()->GetScheme(); _maxlevel = 0; @@ -137,7 +137,7 @@ FarMultiMeshFactory::Create(std::vector const *> const &meshes) result->_patchTables = splicePatchTables(meshes, totalFVarWidth > 0); // splice vertex edit tables - result->_vertexEditTables = spliceVertexEditTables(result, meshes); + result->_vertexEditTables = spliceVertexEditTables(meshes); // count total num vertices, numptex faces int numVertices = 0, numPtexFaces = 0; @@ -221,7 +221,7 @@ copyWithOffsetVertexValence(IT dst_iterator, V const &src, int srcMaxValence, in return dst_iterator; } -template FarSubdivisionTables * +template FarSubdivisionTables * FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshVector const &meshes) { // count total table size @@ -229,7 +229,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV size_t total_E_IT = 0, total_E_W = 0; size_t total_V_ITa = 0, total_V_IT = 0, total_V_W = 0; for (size_t i = 0; i < meshes.size(); ++i) { - FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); + FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); assert(tables); total_F_ITa += tables->Get_F_ITa().size(); @@ -241,21 +241,21 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV total_V_W += tables->Get_V_W().size(); } - FarSubdivisionTables *result = NULL; - typename FarSubdivisionTables::Scheme scheme = + FarSubdivisionTables *result = NULL; + typename FarSubdivisionTables::Scheme scheme = meshes[0]->GetSubdivisionTables()->GetScheme(); switch (scheme) { - case FarSubdivisionTables::CATMARK: - result = new FarCatmarkSubdivisionTables(farMesh, _maxlevel); + case FarSubdivisionTables::CATMARK: + result = new FarCatmarkSubdivisionTables(_maxlevel); _isLoop = false; break; - case FarSubdivisionTables::LOOP: - result = new FarLoopSubdivisionTables(farMesh, _maxlevel); + case FarSubdivisionTables::LOOP: + result = new FarLoopSubdivisionTables(_maxlevel); _isLoop = true; break; - case FarSubdivisionTables::BILINEAR: - result = new FarBilinearSubdivisionTables(farMesh, _maxlevel); + case FarSubdivisionTables::BILINEAR: + result = new FarBilinearSubdivisionTables(_maxlevel); _isLoop = false; break; default: @@ -286,7 +286,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV int evOffset = 0; int vvOffset = 0; for (size_t i = 0; i < meshes.size(); ++i) { - FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); + FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); assert(tables); vertexOffsets.push_back(vertexOffset); @@ -301,8 +301,8 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV fvOffset += (int)tables->Get_F_ITa().size()/2; V_IToffset += (int)tables->Get_V_IT().size(); - if (scheme == FarSubdivisionTables::CATMARK or - scheme == FarSubdivisionTables::LOOP) { + if (scheme == FarSubdivisionTables::CATMARK or + scheme == FarSubdivisionTables::LOOP) { evOffset += (int)tables->Get_E_IT().size()/4; vvOffset += (int)tables->Get_V_ITa().size()/5; @@ -319,7 +319,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV std::vector::iterator V_IT = result->_V_IT.begin(); for (size_t i = 0; i < meshes.size(); ++i) { - FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); + FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); int vertexOffset = vertexOffsets[i]; // remap F_IT, V_IT tables @@ -335,7 +335,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV std::vector::iterator V_ITa = result->_V_ITa.begin(); for (size_t i = 0; i < meshes.size(); ++i) { - FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); + FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); // copy face tables F_ITa = copyWithOffsetF_ITa(F_ITa, tables->Get_F_ITa(), F_IToffsets[i]); @@ -345,8 +345,8 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV E_W = copyWithOffset(E_W, tables->Get_E_W(), 0); // copy vert tables - if (scheme == FarSubdivisionTables::CATMARK or - scheme == FarSubdivisionTables::LOOP) { + if (scheme == FarSubdivisionTables::CATMARK or + scheme == FarSubdivisionTables::LOOP) { V_ITa = copyWithOffsetV_ITa(V_ITa, tables->Get_V_ITa(), V_IToffsets[i], vertexOffsets[i]); } else { @@ -398,7 +398,7 @@ FarMultiMeshFactory::spliceSubdivisionTables(FarMesh *farMesh, FarMeshV // count verts offsets result->_vertsOffsets.resize(_maxlevel+2); for (size_t i = 0; i < meshes.size(); ++i) { - FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); + FarSubdivisionTables const * tables = meshes[i]->GetSubdivisionTables(); for (size_t j = 0; j < tables->_vertsOffsets.size(); ++j) { result->_vertsOffsets[j] += tables->_vertsOffsets[j]; } @@ -616,14 +616,14 @@ FarMultiMeshFactory::splicePatchTables(FarMeshVector const &meshes, bool h return result; } -template FarVertexEditTables * -FarMultiMeshFactory::spliceVertexEditTables(FarMesh *farMesh, FarMeshVector const &meshes) { +template FarVertexEditTables * +FarMultiMeshFactory::spliceVertexEditTables(FarMeshVector const &meshes) { - FarVertexEditTables * result = new FarVertexEditTables(farMesh); + FarVertexEditTables * result = new FarVertexEditTables(); // at this moment, don't merge vertex edit tables (separate batch) for (size_t i = 0; i < meshes.size(); ++i) { - const FarVertexEditTables *vertexEditTables = meshes[i]->GetVertexEdit(); + const FarVertexEditTables *vertexEditTables = meshes[i]->GetVertexEdit(); if (not vertexEditTables) continue; // copy each edit batch XXX:inefficient copy diff --git a/opensubdiv/far/subdivisionTables.h b/opensubdiv/far/subdivisionTables.h index c03499f3..289ff055 100644 --- a/opensubdiv/far/subdivisionTables.h +++ b/opensubdiv/far/subdivisionTables.h @@ -34,8 +34,6 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { -template class FarMesh; - /// \brief FarSubdivisionTables are a serialized topological data representation. /// /// Subdivision tables store the indexing tables required in order to compute @@ -62,7 +60,7 @@ template class FarMesh; /// For more details see : "Feature Adaptive GPU Rendering of Catmull-Clark /// Subdivision Surfaces" (p.3 - par. 3.2) /// -template class FarSubdivisionTables { +class FarSubdivisionTables { public: @@ -88,7 +86,7 @@ public: }; /// \brief Destructor - virtual ~FarSubdivisionTables() {} + virtual ~FarSubdivisionTables() {} /// \brief Return the highest level of subdivision possible with these tables int GetMaxLevel() const { return (int)(_vertsOffsets.size()-1); } @@ -96,9 +94,6 @@ public: /// \brief Memory required to store the indexing tables int GetMemoryUsed() const; - /// \brief Pointer back to the mesh owning the table - FarMesh * GetMesh() { return _mesh; } - /// \brief The index of the first vertex that belongs to the level of subdivision /// represented by this set of FarCatmarkSubdivisionTables int GetFirstVertexOffset( int level ) const; @@ -148,10 +143,7 @@ protected: template friend class FarMeshFactory; template friend class FarMultiMeshFactory; - FarSubdivisionTables( FarMesh * mesh, int maxlevel ); - - // mesh that owns this subdivisionTable - FarMesh * _mesh; + FarSubdivisionTables( int maxlevel ); std::vector _F_ITa; // vertices from face refinement std::vector _F_IT; // indices of face vertices @@ -166,22 +158,21 @@ protected: std::vector _vertsOffsets; // offset to the first vertex of each level }; -template -FarSubdivisionTables::FarSubdivisionTables( FarMesh * mesh, int maxlevel ) : - _mesh(mesh), +inline +FarSubdivisionTables::FarSubdivisionTables( int maxlevel ) : _vertsOffsets(maxlevel+2, 0) { assert( maxlevel > 0 ); } -template int -FarSubdivisionTables::GetFirstVertexOffset( int level ) const { +inline int +FarSubdivisionTables::GetFirstVertexOffset( int level ) const { assert(level>=0 and level<(int)_vertsOffsets.size()); return _vertsOffsets[level]; } -template int -FarSubdivisionTables::GetNumVertices( ) const { +inline int +FarSubdivisionTables::GetNumVertices( ) const { if (_vertsOffsets.empty()) { return 0; } else { @@ -191,20 +182,20 @@ FarSubdivisionTables::GetNumVertices( ) const { } } -template int -FarSubdivisionTables::GetNumVertices( int level ) const { +inline int +FarSubdivisionTables::GetNumVertices( int level ) const { assert(level>=0 and level<((int)_vertsOffsets.size()-1)); return _vertsOffsets[level+1] - _vertsOffsets[level]; } -template int -FarSubdivisionTables::GetNumVerticesTotal( int level ) const { +inline int +FarSubdivisionTables::GetNumVerticesTotal( int level ) const { assert(level>=0 and level<((int)_vertsOffsets.size()-1)); return _vertsOffsets[level+1]; } -template int -FarSubdivisionTables::GetMemoryUsed() const { +inline int +FarSubdivisionTables::GetMemoryUsed() const { return (int)(_F_ITa.size() * sizeof(int) + _F_IT.size() * sizeof(unsigned int) + _E_IT.size() * sizeof(int) + diff --git a/opensubdiv/far/vertexEditTables.h b/opensubdiv/far/vertexEditTables.h index e3f7582d..cb525906 100644 --- a/opensubdiv/far/vertexEditTables.h +++ b/opensubdiv/far/vertexEditTables.h @@ -34,8 +34,6 @@ namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { -template class FarMesh; - /// \brief A serialized container for hierarchical edits. /// /// Some of the hierarchical edits are resolved into the vertex weights computed @@ -66,7 +64,7 @@ public: const float* GetEdit() const { return _edit; } private: - template friend class FarVertexEditTables; + friend class FarVertexEditTables; FarVertexEdit(Operation op, int index, int width) : _op(op), _edit(0), _index(index), _width(width) @@ -80,10 +78,10 @@ private: _width; }; -template class FarVertexEditTables { +class FarVertexEditTables { public: /// \brief Constructor - FarVertexEditTables( FarMesh * mesh ); + FarVertexEditTables( ) { } // Note : Subtract type edits are converted into Adds in order to save kernel calls. @@ -97,6 +95,7 @@ public: void Append(int level, int vertexID, const float *values, bool negate); /// \brief Compute-kernel applied to vertices + template void ApplyVertexEdits(U * vsrc, int offset, int tableOffset, int start, int end) const; // Edit tables accessors @@ -144,13 +143,11 @@ public: private: template friend class FarVertexEditTablesFactory; template friend class FarMultiMeshFactory; - template friend class FarComputeController; + friend class FarComputeController; // Compute-kernel that applies the edits - void computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, void *clientdata) const; - - // mesh that owns this vertexEditTable - FarMesh * _mesh; + template + void computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, CONTEXT *context) const; #if defined(__GNUC__) // XXX(dyu): seems like there is a compiler bug in g++ that requires @@ -160,16 +157,16 @@ public: std::vector _batches; }; -template -FarVertexEditTables::VertexEditBatch::VertexEditBatch(int index, int width, FarVertexEdit::Operation op) : +inline +FarVertexEditTables::VertexEditBatch::VertexEditBatch(int index, int width, FarVertexEdit::Operation operation) : _primvarIndex(index), _primvarWidth(width), - _op(op) { + _op(operation) { } template void -FarVertexEditTables::VertexEditBatch::ApplyVertexEdits(U * vsrc, int vertexOffset, int tableOffset, int start, int end) const +FarVertexEditTables::VertexEditBatch::ApplyVertexEdits(U * vsrc, int vertexOffset, int tableOffset, int start, int end) const { int primvarWidth = GetPrimvarWidth(); assert(tableOffset+end <= (int)_vertIndices.size()); @@ -185,17 +182,8 @@ FarVertexEditTables::VertexEditBatch::ApplyVertexEdits(U * vsrc, int vertexOf } } -template -FarVertexEditTables::FarVertexEditTables( FarMesh * mesh ) : - _mesh(mesh) { -} - template void -FarVertexEditTables::computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, void *clientdata) const { - - assert(this->_mesh); - - U * vsrc = &this->_mesh->GetVertices().at(0); +FarVertexEditTables::computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, U * vsrc) const { _batches[tableIndex].ApplyVertexEdits(vsrc, offset, tableOffset, start, end); } diff --git a/opensubdiv/far/vertexEditTablesFactory.h b/opensubdiv/far/vertexEditTablesFactory.h index bb509ec5..dbb4bd96 100644 --- a/opensubdiv/far/vertexEditTablesFactory.h +++ b/opensubdiv/far/vertexEditTablesFactory.h @@ -53,7 +53,7 @@ protected: static void insertHEditBatch(FarKernelBatchVector *batches, int batchIndex, int batchLevel, int batchCount, int tableOffset); /// \brief Creates a FarVertexEditTables instance. - static FarVertexEditTables * Create( FarMeshFactory const * factory, FarMesh * mesh, FarKernelBatchVector *batches, int maxlevel ); + static FarVertexEditTables * Create( FarMeshFactory const * factory, FarMesh * mesh, FarKernelBatchVector *batches, int maxlevel ); }; template bool @@ -76,12 +76,12 @@ FarVertexEditTablesFactory::insertHEditBatch(FarKernelBatchVector *batches, batches->insert(it, FarKernelBatch( FarKernelBatch::HIERARCHICAL_EDIT, batchLevel+1, batchIndex, 0, batchCount, tableOffset, 0) ); } -template FarVertexEditTables * +template FarVertexEditTables * FarVertexEditTablesFactory::Create( FarMeshFactory const * factory, FarMesh * mesh, FarKernelBatchVector *batches, int maxlevel ) { assert( factory and mesh ); - FarVertexEditTables * result = new FarVertexEditTables(mesh); + FarVertexEditTables* result = new FarVertexEditTables(); std::vector*> const & hEdits = factory->_hbrMesh->GetHierarchicalEdits(); @@ -127,7 +127,7 @@ FarVertexEditTablesFactory::Create( FarMeshFactory const * factory, Fa if (batchIndex == -1) { // create new batch batchIndex = (int)result->_batches.size(); - result->_batches.push_back(typename FarVertexEditTables::VertexEditBatch(vedit->GetIndex(), vedit->GetWidth(), op)); + result->_batches.push_back(typename FarVertexEditTables::VertexEditBatch(vedit->GetIndex(), vedit->GetWidth(), op)); batchSizes.push_back(0); } batchSizes[batchIndex]++; @@ -162,7 +162,7 @@ FarVertexEditTablesFactory::Create( FarMeshFactory const * factory, Fa int batchIndex = batchIndices[i]; int & batchLevel = currentLevels[batchIndex]; int & batchCount = currentCounts[batchIndex]; - typename FarVertexEditTables::VertexEditBatch &batch = result->_batches[batchIndex]; + typename FarVertexEditTables::VertexEditBatch &batch = result->_batches[batchIndex]; // if a new batch is needed if (batchLevel != level-1) { diff --git a/opensubdiv/osd/clComputeContext.cpp b/opensubdiv/osd/clComputeContext.cpp index 6bcb94a0..e57d4747 100644 --- a/opensubdiv/osd/clComputeContext.cpp +++ b/opensubdiv/osd/clComputeContext.cpp @@ -52,7 +52,7 @@ OsdCLTable::GetDevicePtr() const { // ----------------------------------------------------------------------------- OsdCLHEditTable::OsdCLHEditTable( - const FarVertexEditTables::VertexEditBatch &batch, + const FarVertexEditTables::VertexEditBatch &batch, cl_context clContext) : _primvarIndicesTable(new OsdCLTable(batch.GetVertexIndices(), clContext)), _editValuesTable(new OsdCLTable(batch.GetValues(), clContext)) { @@ -104,30 +104,29 @@ OsdCLComputeContext::OsdCLComputeContext(FarMesh const *farMesh, cl_context clContext) : _clQueue(NULL), _kernelBundle(NULL) { - FarSubdivisionTables const * farTables = - farMesh->GetSubdivisionTables(); + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables _tables.resize(farTables->GetNumTables(), 0); - _tables[FarSubdivisionTables::E_IT] = new OsdCLTable(farTables->Get_E_IT(), clContext); - _tables[FarSubdivisionTables::V_IT] = new OsdCLTable(farTables->Get_V_IT(), clContext); - _tables[FarSubdivisionTables::V_ITa] = new OsdCLTable(farTables->Get_V_ITa(), clContext); - _tables[FarSubdivisionTables::E_W] = new OsdCLTable(farTables->Get_E_W(), clContext); - _tables[FarSubdivisionTables::V_W] = new OsdCLTable(farTables->Get_V_W(), clContext); + _tables[FarSubdivisionTables::E_IT] = new OsdCLTable(farTables->Get_E_IT(), clContext); + _tables[FarSubdivisionTables::V_IT] = new OsdCLTable(farTables->Get_V_IT(), clContext); + _tables[FarSubdivisionTables::V_ITa] = new OsdCLTable(farTables->Get_V_ITa(), clContext); + _tables[FarSubdivisionTables::E_W] = new OsdCLTable(farTables->Get_E_W(), clContext); + _tables[FarSubdivisionTables::V_W] = new OsdCLTable(farTables->Get_V_W(), clContext); if (farTables->GetNumTables() > 5) { - _tables[FarSubdivisionTables::F_IT] = new OsdCLTable(farTables->Get_F_IT(), clContext); - _tables[FarSubdivisionTables::F_ITa] = new OsdCLTable(farTables->Get_F_ITa(), clContext); + _tables[FarSubdivisionTables::F_IT] = new OsdCLTable(farTables->Get_F_IT(), clContext); + _tables[FarSubdivisionTables::F_ITa] = new OsdCLTable(farTables->Get_F_ITa(), clContext); } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(new OsdCLHEditTable(edit, clContext)); } diff --git a/opensubdiv/osd/clComputeContext.h b/opensubdiv/osd/clComputeContext.h index 9dc43037..a11670be 100644 --- a/opensubdiv/osd/clComputeContext.h +++ b/opensubdiv/osd/clComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" #include "../osd/nonCopyable.h" @@ -64,7 +65,7 @@ private: class OsdCLHEditTable : OsdNonCopyable { public: - OsdCLHEditTable(const FarVertexEditTables:: + OsdCLHEditTable(const FarVertexEditTables:: VertexEditBatch &batch, cl_context clContext); virtual ~OsdCLHEditTable(); diff --git a/opensubdiv/osd/clComputeController.cpp b/opensubdiv/osd/clComputeController.cpp index 5e4460ac..d77555ef 100644 --- a/opensubdiv/osd/clComputeController.cpp +++ b/opensubdiv/osd/clComputeController.cpp @@ -92,17 +92,15 @@ OsdCLComputeController::getKernelBundle(int numVertexElements, void OsdCLComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - ApplyCatmarkFaceVerticesKernel(batch, clientdata); + ApplyCatmarkFaceVerticesKernel(batch, context); } void OsdCLComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -111,7 +109,7 @@ OsdCLComputeController::ApplyBilinearEdgeVerticesKernel( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); + cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -128,10 +126,8 @@ OsdCLComputeController::ApplyBilinearEdgeVerticesKernel( void OsdCLComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -140,7 +136,7 @@ OsdCLComputeController::ApplyBilinearVertexVerticesKernel( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -157,10 +153,8 @@ OsdCLComputeController::ApplyBilinearVertexVerticesKernel( void OsdCLComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -169,8 +163,8 @@ OsdCLComputeController::ApplyCatmarkFaceVerticesKernel( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem F_IT = context->GetTable(FarSubdivisionTables::F_IT)->GetDevicePtr(); - cl_mem F_ITa = context->GetTable(FarSubdivisionTables::F_ITa)->GetDevicePtr(); + cl_mem F_IT = context->GetTable(FarSubdivisionTables::F_IT)->GetDevicePtr(); + cl_mem F_ITa = context->GetTable(FarSubdivisionTables::F_ITa)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -189,10 +183,8 @@ OsdCLComputeController::ApplyCatmarkFaceVerticesKernel( void OsdCLComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -201,8 +193,8 @@ OsdCLComputeController::ApplyCatmarkEdgeVerticesKernel( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); - cl_mem E_W = context->GetTable(FarSubdivisionTables::E_W)->GetDevicePtr(); + cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); + cl_mem E_W = context->GetTable(FarSubdivisionTables::E_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -221,10 +213,8 @@ OsdCLComputeController::ApplyCatmarkEdgeVerticesKernel( void OsdCLComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -233,9 +223,9 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelB( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_IT = context->GetTable(FarSubdivisionTables::V_IT)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_IT = context->GetTable(FarSubdivisionTables::V_IT)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -255,10 +245,8 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelB( void OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -268,8 +256,8 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA1( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -289,10 +277,8 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA1( void OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -302,8 +288,8 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA2( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -323,10 +309,8 @@ OsdCLComputeController::ApplyCatmarkVertexVerticesKernelA2( void OsdCLComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -335,8 +319,8 @@ OsdCLComputeController::ApplyLoopEdgeVerticesKernel( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); - cl_mem E_W = context->GetTable(FarSubdivisionTables::E_W)->GetDevicePtr(); + cl_mem E_IT = context->GetTable(FarSubdivisionTables::E_IT)->GetDevicePtr(); + cl_mem E_W = context->GetTable(FarSubdivisionTables::E_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -355,10 +339,8 @@ OsdCLComputeController::ApplyLoopEdgeVerticesKernel( void OsdCLComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -367,9 +349,9 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelB( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_IT = context->GetTable(FarSubdivisionTables::V_IT)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_IT = context->GetTable(FarSubdivisionTables::V_IT)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -389,10 +371,8 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelB( void OsdCLComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -402,8 +382,8 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelA1( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -423,10 +403,8 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelA1( void OsdCLComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; @@ -436,8 +414,8 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelA2( cl_mem vertexBuffer = context->GetCurrentVertexBuffer(); cl_mem varyingBuffer = context->GetCurrentVaryingBuffer(); - cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); - cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); + cl_mem V_ITa = context->GetTable(FarSubdivisionTables::V_ITa)->GetDevicePtr(); + cl_mem V_W = context->GetTable(FarSubdivisionTables::V_W)->GetDevicePtr(); clSetKernelArg(kernel, 0, sizeof(cl_mem), &vertexBuffer); clSetKernelArg(kernel, 1, sizeof(cl_mem), &varyingBuffer); @@ -457,10 +435,8 @@ OsdCLComputeController::ApplyLoopVertexVerticesKernelA2( void OsdCLComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCLComputeContext *context) const { - OsdCLComputeContext * context = - static_cast(clientdata); assert(context); cl_int ciErrNum; diff --git a/opensubdiv/osd/clComputeController.h b/opensubdiv/osd/clComputeController.h index 59128be3..afc280c9 100644 --- a/opensubdiv/osd/clComputeController.h +++ b/opensubdiv/osd/clComputeController.h @@ -93,10 +93,9 @@ public: context->SetKernelBundle(getKernelBundle(numVertexElements, numVaryingElements)); context->Bind(vertexBuffer, varyingBuffer, _clQueue); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -128,34 +127,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; OsdCLKernelBundle * getKernelBundle(int numVertexElements, diff --git a/opensubdiv/osd/cpuComputeContext.cpp b/opensubdiv/osd/cpuComputeContext.cpp index d336129a..83389c1d 100644 --- a/opensubdiv/osd/cpuComputeContext.cpp +++ b/opensubdiv/osd/cpuComputeContext.cpp @@ -59,7 +59,7 @@ OsdCpuTable::GetBuffer() const { // ---------------------------------------------------------------------------- OsdCpuHEditTable::OsdCpuHEditTable( - const FarVertexEditTables::VertexEditBatch &batch) + const FarVertexEditTables::VertexEditBatch &batch) : _primvarIndicesTable(new OsdCpuTable(batch.GetVertexIndices())), _editValuesTable(new OsdCpuTable(batch.GetValues())) { @@ -106,30 +106,30 @@ OsdCpuHEditTable::GetPrimvarWidth() const { OsdCpuComputeContext::OsdCpuComputeContext(FarMesh const *farMesh) { - FarSubdivisionTables const * farTables = + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables _tables.resize(farTables->GetNumTables(), 0); - _tables[FarSubdivisionTables::E_IT] = new OsdCpuTable(farTables->Get_E_IT()); - _tables[FarSubdivisionTables::V_IT] = new OsdCpuTable(farTables->Get_V_IT()); - _tables[FarSubdivisionTables::V_ITa] = new OsdCpuTable(farTables->Get_V_ITa()); - _tables[FarSubdivisionTables::E_W] = new OsdCpuTable(farTables->Get_E_W()); - _tables[FarSubdivisionTables::V_W] = new OsdCpuTable(farTables->Get_V_W()); + _tables[FarSubdivisionTables::E_IT] = new OsdCpuTable(farTables->Get_E_IT()); + _tables[FarSubdivisionTables::V_IT] = new OsdCpuTable(farTables->Get_V_IT()); + _tables[FarSubdivisionTables::V_ITa] = new OsdCpuTable(farTables->Get_V_ITa()); + _tables[FarSubdivisionTables::E_W] = new OsdCpuTable(farTables->Get_E_W()); + _tables[FarSubdivisionTables::V_W] = new OsdCpuTable(farTables->Get_V_W()); if (farTables->GetNumTables() > 5) { - _tables[FarSubdivisionTables::F_IT] = new OsdCpuTable(farTables->Get_F_IT()); - _tables[FarSubdivisionTables::F_ITa] = new OsdCpuTable(farTables->Get_F_ITa()); + _tables[FarSubdivisionTables::F_IT] = new OsdCpuTable(farTables->Get_F_IT()); + _tables[FarSubdivisionTables::F_ITa] = new OsdCpuTable(farTables->Get_F_ITa()); } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(new OsdCpuHEditTable(edit)); diff --git a/opensubdiv/osd/cpuComputeContext.h b/opensubdiv/osd/cpuComputeContext.h index dd719dc4..7e87c347 100644 --- a/opensubdiv/osd/cpuComputeContext.h +++ b/opensubdiv/osd/cpuComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/subdivisionTables.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" @@ -59,8 +60,7 @@ private: class OsdCpuHEditTable : OsdNonCopyable { public: - OsdCpuHEditTable(const FarVertexEditTables:: - VertexEditBatch &batch); + OsdCpuHEditTable(const FarVertexEditTables::VertexEditBatch &batch); virtual ~OsdCpuHEditTable(); diff --git a/opensubdiv/osd/cpuComputeController.cpp b/opensubdiv/osd/cpuComputeController.cpp index 4a3ab26d..42859e76 100644 --- a/opensubdiv/osd/cpuComputeController.cpp +++ b/opensubdiv/osd/cpuComputeController.cpp @@ -38,214 +38,188 @@ OsdCpuComputeController::~OsdCpuComputeController() { void OsdCpuComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (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 OsdCpuComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeBilinearEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdCpuComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeBilinearVertex( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdCpuComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (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 OsdCpuComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeVertexB( 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(), + (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 OsdCpuComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeLoopVertexB( 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(), + (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 OsdCpuComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdCpuComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdCpuComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); const OsdCpuHEditTable *edit = context->GetEditTable(batch.GetTableIndex()); diff --git a/opensubdiv/osd/cpuComputeController.h b/opensubdiv/osd/cpuComputeController.h index e7910bc2..3557e046 100644 --- a/opensubdiv/osd/cpuComputeController.h +++ b/opensubdiv/osd/cpuComputeController.h @@ -73,10 +73,9 @@ public: if (batches.empty()) return; context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -101,34 +100,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; }; diff --git a/opensubdiv/osd/cudaComputeContext.cpp b/opensubdiv/osd/cudaComputeContext.cpp index e8d5752e..24a08c14 100644 --- a/opensubdiv/osd/cudaComputeContext.cpp +++ b/opensubdiv/osd/cudaComputeContext.cpp @@ -71,8 +71,7 @@ OsdCudaHEditTable::~OsdCudaHEditTable() { } OsdCudaHEditTable * -OsdCudaHEditTable::Create(const FarVertexEditTables:: - VertexEditBatch &batch) { +OsdCudaHEditTable::Create(const FarVertexEditTables::VertexEditBatch &batch) { OsdCudaHEditTable *result = new OsdCudaHEditTable(); @@ -139,21 +138,20 @@ OsdCudaComputeContext::~OsdCudaComputeContext() { bool OsdCudaComputeContext::initialize(FarMesh const *farMesh) { - FarSubdivisionTables const * farTables = - farMesh->GetSubdivisionTables(); + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables _tables.resize(farTables->GetNumTables(), 0); - _tables[FarSubdivisionTables::E_IT] = OsdCudaTable::Create(farTables->Get_E_IT()); - _tables[FarSubdivisionTables::V_IT] = OsdCudaTable::Create(farTables->Get_V_IT()); - _tables[FarSubdivisionTables::V_ITa] = OsdCudaTable::Create(farTables->Get_V_ITa()); - _tables[FarSubdivisionTables::E_W] = OsdCudaTable::Create(farTables->Get_E_W()); - _tables[FarSubdivisionTables::V_W] = OsdCudaTable::Create(farTables->Get_V_W()); + _tables[FarSubdivisionTables::E_IT] = OsdCudaTable::Create(farTables->Get_E_IT()); + _tables[FarSubdivisionTables::V_IT] = OsdCudaTable::Create(farTables->Get_V_IT()); + _tables[FarSubdivisionTables::V_ITa] = OsdCudaTable::Create(farTables->Get_V_ITa()); + _tables[FarSubdivisionTables::E_W] = OsdCudaTable::Create(farTables->Get_E_W()); + _tables[FarSubdivisionTables::V_W] = OsdCudaTable::Create(farTables->Get_V_W()); if (farTables->GetNumTables() > 5) { - _tables[FarSubdivisionTables::F_IT] = OsdCudaTable::Create(farTables->Get_F_IT()); - _tables[FarSubdivisionTables::F_ITa] = OsdCudaTable::Create(farTables->Get_F_ITa()); + _tables[FarSubdivisionTables::F_IT] = OsdCudaTable::Create(farTables->Get_F_IT()); + _tables[FarSubdivisionTables::F_ITa] = OsdCudaTable::Create(farTables->Get_F_ITa()); } // error check @@ -164,12 +162,12 @@ OsdCudaComputeContext::initialize(FarMesh const *farMesh) { } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(OsdCudaHEditTable::Create(edit)); diff --git a/opensubdiv/osd/cudaComputeContext.h b/opensubdiv/osd/cudaComputeContext.h index ebcc907a..72d317f8 100644 --- a/opensubdiv/osd/cudaComputeContext.h +++ b/opensubdiv/osd/cudaComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" @@ -64,8 +65,7 @@ private: class OsdCudaHEditTable : OsdNonCopyable { public: - static OsdCudaHEditTable * Create(const FarVertexEditTables:: - VertexEditBatch &batch); + static OsdCudaHEditTable * Create(const FarVertexEditTables::VertexEditBatch &batch); virtual ~OsdCudaHEditTable(); diff --git a/opensubdiv/osd/cudaComputeController.cpp b/opensubdiv/osd/cudaComputeController.cpp index 59e349a0..a892d3bb 100644 --- a/opensubdiv/osd/cudaComputeController.cpp +++ b/opensubdiv/osd/cudaComputeController.cpp @@ -82,14 +82,12 @@ OsdCudaComputeController::~OsdCudaComputeController() { void OsdCudaComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * F_IT = context->GetTable(FarSubdivisionTables::F_IT); - const OsdCudaTable * F_ITa = context->GetTable(FarSubdivisionTables::F_ITa); + const OsdCudaTable * F_IT = context->GetTable(FarSubdivisionTables::F_IT); + const OsdCudaTable * F_ITa = context->GetTable(FarSubdivisionTables::F_ITa); assert(F_IT); assert(F_ITa); @@ -105,13 +103,11 @@ OsdCudaComputeController::ApplyBilinearFaceVerticesKernel( void OsdCudaComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); + const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); assert(E_IT); OsdCudaComputeBilinearEdge( @@ -125,13 +121,11 @@ OsdCudaComputeController::ApplyBilinearEdgeVerticesKernel( void OsdCudaComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); assert(V_ITa); OsdCudaComputeBilinearVertex( @@ -145,14 +139,12 @@ OsdCudaComputeController::ApplyBilinearVertexVerticesKernel( void OsdCudaComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * F_IT = context->GetTable(FarSubdivisionTables::F_IT); - const OsdCudaTable * F_ITa = context->GetTable(FarSubdivisionTables::F_ITa); + const OsdCudaTable * F_IT = context->GetTable(FarSubdivisionTables::F_IT); + const OsdCudaTable * F_ITa = context->GetTable(FarSubdivisionTables::F_ITa); assert(F_IT); assert(F_ITa); @@ -168,14 +160,12 @@ OsdCudaComputeController::ApplyCatmarkFaceVerticesKernel( void OsdCudaComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); - const OsdCudaTable * E_W = context->GetTable(FarSubdivisionTables::E_W); + const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); + const OsdCudaTable * E_W = context->GetTable(FarSubdivisionTables::E_W); assert(E_IT); assert(E_W); @@ -191,15 +181,13 @@ OsdCudaComputeController::ApplyCatmarkEdgeVerticesKernel( void OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_IT = context->GetTable(FarSubdivisionTables::V_IT); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_IT = context->GetTable(FarSubdivisionTables::V_IT); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_IT); assert(V_W); @@ -217,14 +205,12 @@ OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelB( void OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_W); @@ -240,14 +226,12 @@ OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelA1( void OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_W); @@ -263,14 +247,12 @@ OsdCudaComputeController::ApplyCatmarkVertexVerticesKernelA2( void OsdCudaComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); - const OsdCudaTable * E_W = context->GetTable(FarSubdivisionTables::E_W); + const OsdCudaTable * E_IT = context->GetTable(FarSubdivisionTables::E_IT); + const OsdCudaTable * E_W = context->GetTable(FarSubdivisionTables::E_W); assert(E_IT); assert(E_W); @@ -286,15 +268,13 @@ OsdCudaComputeController::ApplyLoopEdgeVerticesKernel( void OsdCudaComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_IT = context->GetTable(FarSubdivisionTables::V_IT); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_IT = context->GetTable(FarSubdivisionTables::V_IT); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_IT); assert(V_W); @@ -312,14 +292,12 @@ OsdCudaComputeController::ApplyLoopVertexVerticesKernelB( void OsdCudaComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_W); @@ -335,14 +313,12 @@ OsdCudaComputeController::ApplyLoopVertexVerticesKernelA1( void OsdCudaComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); - const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); - const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); + const OsdCudaTable * V_ITa = context->GetTable(FarSubdivisionTables::V_ITa); + const OsdCudaTable * V_W = context->GetTable(FarSubdivisionTables::V_W); assert(V_ITa); assert(V_W); @@ -358,10 +334,8 @@ OsdCudaComputeController::ApplyLoopVertexVerticesKernelA2( void OsdCudaComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCudaComputeContext *context) const { - OsdCudaComputeContext * context = - static_cast(clientdata); assert(context); const OsdCudaHEditTable *edit = context->GetEditTable(batch.GetTableIndex()); diff --git a/opensubdiv/osd/cudaComputeController.h b/opensubdiv/osd/cudaComputeController.h index 4eee0ff9..b8a59299 100644 --- a/opensubdiv/osd/cudaComputeController.h +++ b/opensubdiv/osd/cudaComputeController.h @@ -73,10 +73,9 @@ public: if (batches.empty()) return; context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -101,34 +100,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; }; } // end namespace OPENSUBDIV_VERSION diff --git a/opensubdiv/osd/d3d11ComputeContext.cpp b/opensubdiv/osd/d3d11ComputeContext.cpp index 41b62645..d4f6a0e0 100644 --- a/opensubdiv/osd/d3d11ComputeContext.cpp +++ b/opensubdiv/osd/d3d11ComputeContext.cpp @@ -97,7 +97,7 @@ OsdD3D11ComputeTable::GetSRV() const { // ---------------------------------------------------------------------------- OsdD3D11ComputeHEditTable::OsdD3D11ComputeHEditTable( - const FarVertexEditTables::VertexEditBatch &batch, ID3D11DeviceContext *deviceContext) + const FarVertexEditTables::VertexEditBatch &batch, ID3D11DeviceContext *deviceContext) : _primvarIndicesTable(new OsdD3D11ComputeTable(batch.GetVertexIndices(), deviceContext, DXGI_FORMAT_R32_UINT)), _editValuesTable(new OsdD3D11ComputeTable(batch.GetValues(), deviceContext, DXGI_FORMAT_R32_FLOAT)) { @@ -149,8 +149,7 @@ OsdD3D11ComputeContext::OsdD3D11ComputeContext( : _deviceContext(deviceContext), _currentVertexBufferUAV(0), _currentVaryingBufferUAV(0) { - FarSubdivisionTables const * farTables = - farMesh->GetSubdivisionTables(); + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables // XXXtakahito: Although _tables size depends on table type, F_IT is set @@ -158,27 +157,27 @@ OsdD3D11ComputeContext::OsdD3D11ComputeContext( // bindShaderStorageBuffer()... _tables.resize(7, 0); - _tables[FarSubdivisionTables::E_IT] = new OsdD3D11ComputeTable(farTables->Get_E_IT(), deviceContext, DXGI_FORMAT_R32_SINT); - _tables[FarSubdivisionTables::V_IT] = new OsdD3D11ComputeTable(farTables->Get_V_IT(), deviceContext, DXGI_FORMAT_R32_UINT); - _tables[FarSubdivisionTables::V_ITa] = new OsdD3D11ComputeTable(farTables->Get_V_ITa(), deviceContext, DXGI_FORMAT_R32_SINT); - _tables[FarSubdivisionTables::E_W] = new OsdD3D11ComputeTable(farTables->Get_E_W(), deviceContext, DXGI_FORMAT_R32_FLOAT); - _tables[FarSubdivisionTables::V_W] = new OsdD3D11ComputeTable(farTables->Get_V_W(), deviceContext, DXGI_FORMAT_R32_FLOAT); + _tables[FarSubdivisionTables::E_IT] = new OsdD3D11ComputeTable(farTables->Get_E_IT(), deviceContext, DXGI_FORMAT_R32_SINT); + _tables[FarSubdivisionTables::V_IT] = new OsdD3D11ComputeTable(farTables->Get_V_IT(), deviceContext, DXGI_FORMAT_R32_UINT); + _tables[FarSubdivisionTables::V_ITa] = new OsdD3D11ComputeTable(farTables->Get_V_ITa(), deviceContext, DXGI_FORMAT_R32_SINT); + _tables[FarSubdivisionTables::E_W] = new OsdD3D11ComputeTable(farTables->Get_E_W(), deviceContext, DXGI_FORMAT_R32_FLOAT); + _tables[FarSubdivisionTables::V_W] = new OsdD3D11ComputeTable(farTables->Get_V_W(), deviceContext, DXGI_FORMAT_R32_FLOAT); if (farTables->GetNumTables() > 5) { - _tables[FarSubdivisionTables::F_IT] = new OsdD3D11ComputeTable(farTables->Get_F_IT(), deviceContext, DXGI_FORMAT_R32_UINT); - _tables[FarSubdivisionTables::F_ITa] = new OsdD3D11ComputeTable(farTables->Get_F_ITa(), deviceContext, DXGI_FORMAT_R32_SINT); + _tables[FarSubdivisionTables::F_IT] = new OsdD3D11ComputeTable(farTables->Get_F_IT(), deviceContext, DXGI_FORMAT_R32_UINT); + _tables[FarSubdivisionTables::F_ITa] = new OsdD3D11ComputeTable(farTables->Get_F_ITa(), deviceContext, DXGI_FORMAT_R32_SINT); } else { - _tables[FarSubdivisionTables::F_IT] = NULL; - _tables[FarSubdivisionTables::F_ITa] = NULL; + _tables[FarSubdivisionTables::F_IT] = NULL; + _tables[FarSubdivisionTables::F_ITa] = NULL; } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(new OsdD3D11ComputeHEditTable(edit, deviceContext)); } @@ -294,20 +293,20 @@ OsdD3D11ComputeContext::bindShaderStorageBuffers() { _deviceContext->CSSetUnorderedAccessViews(1, 1, &_currentVaryingBufferUAV, 0); // u1 // XXX: should be better handling for loop subdivision. - if (_tables[FarSubdivisionTables::F_IT]) { + if (_tables[FarSubdivisionTables::F_IT]) { ID3D11ShaderResourceView *SRViews[] = { - _tables[FarSubdivisionTables::F_IT]->GetSRV(), - _tables[FarSubdivisionTables::F_ITa]->GetSRV(), + _tables[FarSubdivisionTables::F_IT]->GetSRV(), + _tables[FarSubdivisionTables::F_ITa]->GetSRV(), }; _deviceContext->CSSetShaderResources(2, 2, SRViews); // t2-t3 } ID3D11ShaderResourceView *SRViews[] = { - _tables[FarSubdivisionTables::E_IT]->GetSRV(), - _tables[FarSubdivisionTables::V_IT]->GetSRV(), - _tables[FarSubdivisionTables::V_ITa]->GetSRV(), - _tables[FarSubdivisionTables::E_W]->GetSRV(), - _tables[FarSubdivisionTables::V_W]->GetSRV(), + _tables[FarSubdivisionTables::E_IT]->GetSRV(), + _tables[FarSubdivisionTables::V_IT]->GetSRV(), + _tables[FarSubdivisionTables::V_ITa]->GetSRV(), + _tables[FarSubdivisionTables::E_W]->GetSRV(), + _tables[FarSubdivisionTables::V_W]->GetSRV(), }; _deviceContext->CSSetShaderResources(4, 5, SRViews); // t4-t8 } diff --git a/opensubdiv/osd/d3d11ComputeContext.h b/opensubdiv/osd/d3d11ComputeContext.h index f5107ec3..11b48a4b 100644 --- a/opensubdiv/osd/d3d11ComputeContext.h +++ b/opensubdiv/osd/d3d11ComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" @@ -67,8 +68,8 @@ private: class OsdD3D11ComputeHEditTable : OsdNonCopyable { public: - OsdD3D11ComputeHEditTable(const FarVertexEditTables:: - VertexEditBatch &batch, ID3D11DeviceContext *deviceContext); + OsdD3D11ComputeHEditTable(const FarVertexEditTables::VertexEditBatch &batch, + ID3D11DeviceContext *deviceContext); virtual ~OsdD3D11ComputeHEditTable(); diff --git a/opensubdiv/osd/d3d11ComputeController.cpp b/opensubdiv/osd/d3d11ComputeController.cpp index 5973071d..394f8dd1 100644 --- a/opensubdiv/osd/d3d11ComputeController.cpp +++ b/opensubdiv/osd/d3d11ComputeController.cpp @@ -91,10 +91,8 @@ OsdD3D11ComputeController::getKernels(int numVertexElements, void OsdD3D11ComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -105,10 +103,8 @@ OsdD3D11ComputeController::ApplyBilinearFaceVerticesKernel( void OsdD3D11ComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -119,10 +115,8 @@ OsdD3D11ComputeController::ApplyBilinearEdgeVerticesKernel( void OsdD3D11ComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -133,10 +127,8 @@ OsdD3D11ComputeController::ApplyBilinearVertexVerticesKernel( void OsdD3D11ComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -149,10 +141,8 @@ OsdD3D11ComputeController::ApplyCatmarkFaceVerticesKernel( void OsdD3D11ComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -163,10 +153,8 @@ OsdD3D11ComputeController::ApplyCatmarkEdgeVerticesKernel( void OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -177,10 +165,8 @@ OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelB( void OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -191,10 +177,8 @@ OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelA1( void OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -205,10 +189,8 @@ OsdD3D11ComputeController::ApplyCatmarkVertexVerticesKernelA2( void OsdD3D11ComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -219,10 +201,8 @@ OsdD3D11ComputeController::ApplyLoopEdgeVerticesKernel( void OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -233,10 +213,8 @@ OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelB( void OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -247,10 +225,8 @@ OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelA1( void OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -261,10 +237,8 @@ OsdD3D11ComputeController::ApplyLoopVertexVerticesKernelA2( void OsdD3D11ComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdD3D11ComputeContext *context) const { - OsdD3D11ComputeContext * context = - static_cast(clientdata); assert(context); OsdD3D11ComputeKernelBundle * kernelBundle = context->GetKernelBundle(); diff --git a/opensubdiv/osd/d3d11ComputeController.h b/opensubdiv/osd/d3d11ComputeController.h old mode 100644 new mode 100755 index c8024626..7b2a1d7f --- a/opensubdiv/osd/d3d11ComputeController.h +++ b/opensubdiv/osd/d3d11ComputeController.h @@ -89,9 +89,9 @@ public: context->SetKernelBundle(getKernels(numVertexElements, numVaryingElements)); context->Bind(vertexBuffer, varyingBuffer); FarDispatcher::Refine(this, + context, batches, - -1, - context); + -1); context->Unbind(); } @@ -116,34 +116,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; OsdD3D11ComputeKernelBundle * getKernels(int numVertexElements, int numVaryingElements); diff --git a/opensubdiv/osd/drawContext.cpp b/opensubdiv/osd/drawContext.cpp index 49d87740..240e4d1d 100644 --- a/opensubdiv/osd/drawContext.cpp +++ b/opensubdiv/osd/drawContext.cpp @@ -64,7 +64,7 @@ OsdDrawContext::ConvertPatchArrays(FarPatchTables::PatchArrayVector const &farPa #if defined(GL_ES_VERSION_2_0) // XXX: farmesh should have FarDensePatchTable for dense mesh indices. // instead of GetFaceVertices(). - const FarSubdivisionTables *tables = farMesh->GetSubdivisionTables(); + const FarSubdivisionTables *tables = farMesh->GetSubdivisionTables(); int level = tables->GetMaxLevel(); const std::vector &indices = farMesh->GetFaceVertices(level-1); diff --git a/opensubdiv/osd/gcdComputeController.cpp b/opensubdiv/osd/gcdComputeController.cpp index 4e5db0b2..4736e711 100644 --- a/opensubdiv/osd/gcdComputeController.cpp +++ b/opensubdiv/osd/gcdComputeController.cpp @@ -35,227 +35,201 @@ OsdGcdComputeController::OsdGcdComputeController() { } void -OsdGcdComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { +OsdGcdComputeController::ApplyBilinearFaceVerticesxKernel( + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeBilinearEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeBilinearVertex( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeVertexB( 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(), + (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(), _gcd_queue); } void OsdGcdComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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, _gcd_queue); } void OsdGcdComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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, _gcd_queue); } void OsdGcdComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd(), _gcd_queue); } void OsdGcdComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeLoopVertexB( 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(), + (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(), _gcd_queue); } void OsdGcdComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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, _gcd_queue); } void OsdGcdComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdGcdComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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, _gcd_queue); } void OsdGcdComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); const OsdCpuHEditTable *edit = context->GetEditTable(batch.GetTableIndex()); diff --git a/opensubdiv/osd/gcdComputeController.h b/opensubdiv/osd/gcdComputeController.h index cab5da34..cd7255e4 100644 --- a/opensubdiv/osd/gcdComputeController.h +++ b/opensubdiv/osd/gcdComputeController.h @@ -73,10 +73,9 @@ public: if (batches.empty()) return; context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -101,34 +100,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; private: dispatch_queue_t _gcd_queue; diff --git a/opensubdiv/osd/glDrawContext.cpp b/opensubdiv/osd/glDrawContext.cpp index 27a44f3f..92e14b88 100644 --- a/opensubdiv/osd/glDrawContext.cpp +++ b/opensubdiv/osd/glDrawContext.cpp @@ -124,7 +124,7 @@ OsdGLDrawContext::create(FarPatchTables const * patchTables, bool requireFVarDat #if defined(GL_ES_VERSION_2_0) // XXX: farmesh should have FarDensePatchTable for dense mesh indices. // instead of GetFaceVertices(). - const FarSubdivisionTables *tables = farMesh->GetSubdivisionTables(); + const FarSubdivisionTables *tables = farMesh->GetSubdivisionTables(); int level = tables->GetMaxLevel(); const std::vector &indices = farMesh->GetFaceVertices(level-1); diff --git a/opensubdiv/osd/glslComputeContext.cpp b/opensubdiv/osd/glslComputeContext.cpp index 97457a8a..3f865cd4 100644 --- a/opensubdiv/osd/glslComputeContext.cpp +++ b/opensubdiv/osd/glslComputeContext.cpp @@ -62,7 +62,7 @@ OsdGLSLComputeTable::GetBuffer() const { // ---------------------------------------------------------------------------- OsdGLSLComputeHEditTable::OsdGLSLComputeHEditTable( - const FarVertexEditTables::VertexEditBatch &batch) + const FarVertexEditTables::VertexEditBatch &batch) : _primvarIndicesTable(new OsdGLSLComputeTable(batch.GetVertexIndices())), _editValuesTable(new OsdGLSLComputeTable(batch.GetValues())) { @@ -113,7 +113,7 @@ OsdGLSLComputeContext::OsdGLSLComputeContext( FarMesh const *farMesh) : _vertexTexture(0), _varyingTexture(0) { - FarSubdivisionTables const * farTables = + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables @@ -122,29 +122,29 @@ OsdGLSLComputeContext::OsdGLSLComputeContext( // bindShaderStorageBuffer()... _tables.resize(7, 0); - _tables[FarSubdivisionTables::E_IT] = new OsdGLSLComputeTable(farTables->Get_E_IT()); - _tables[FarSubdivisionTables::V_IT] = new OsdGLSLComputeTable(farTables->Get_V_IT()); - _tables[FarSubdivisionTables::V_ITa] = new OsdGLSLComputeTable(farTables->Get_V_ITa()); - _tables[FarSubdivisionTables::E_W] = new OsdGLSLComputeTable(farTables->Get_E_W()); - _tables[FarSubdivisionTables::V_W] = new OsdGLSLComputeTable(farTables->Get_V_W()); + _tables[FarSubdivisionTables::E_IT] = new OsdGLSLComputeTable(farTables->Get_E_IT()); + _tables[FarSubdivisionTables::V_IT] = new OsdGLSLComputeTable(farTables->Get_V_IT()); + _tables[FarSubdivisionTables::V_ITa] = new OsdGLSLComputeTable(farTables->Get_V_ITa()); + _tables[FarSubdivisionTables::E_W] = new OsdGLSLComputeTable(farTables->Get_E_W()); + _tables[FarSubdivisionTables::V_W] = new OsdGLSLComputeTable(farTables->Get_V_W()); if (farTables->GetNumTables() > 5) { // catmark, bilinear - _tables[FarSubdivisionTables::F_IT] = new OsdGLSLComputeTable(farTables->Get_F_IT()); - _tables[FarSubdivisionTables::F_ITa] = new OsdGLSLComputeTable(farTables->Get_F_ITa()); + _tables[FarSubdivisionTables::F_IT] = new OsdGLSLComputeTable(farTables->Get_F_IT()); + _tables[FarSubdivisionTables::F_ITa] = new OsdGLSLComputeTable(farTables->Get_F_ITa()); } else { // loop - _tables[FarSubdivisionTables::F_IT] = NULL; - _tables[FarSubdivisionTables::F_ITa] = NULL; + _tables[FarSubdivisionTables::F_IT] = NULL; + _tables[FarSubdivisionTables::F_ITa] = NULL; } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(new OsdGLSLComputeHEditTable(edit)); } @@ -242,23 +242,23 @@ OsdGLSLComputeContext::bindShaderStorageBuffers() { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, _currentVaryingBuffer); // XXX: should be better handling for loop subdivision. - if (_tables[FarSubdivisionTables::F_IT]) { + if (_tables[FarSubdivisionTables::F_IT]) { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, - _tables[FarSubdivisionTables::F_IT]->GetBuffer()); + _tables[FarSubdivisionTables::F_IT]->GetBuffer()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, - _tables[FarSubdivisionTables::F_ITa]->GetBuffer()); + _tables[FarSubdivisionTables::F_ITa]->GetBuffer()); } glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, - _tables[FarSubdivisionTables::E_IT]->GetBuffer()); + _tables[FarSubdivisionTables::E_IT]->GetBuffer()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, - _tables[FarSubdivisionTables::V_IT]->GetBuffer()); + _tables[FarSubdivisionTables::V_IT]->GetBuffer()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, - _tables[FarSubdivisionTables::V_ITa]->GetBuffer()); + _tables[FarSubdivisionTables::V_ITa]->GetBuffer()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, - _tables[FarSubdivisionTables::E_W]->GetBuffer()); + _tables[FarSubdivisionTables::E_W]->GetBuffer()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, - _tables[FarSubdivisionTables::V_W]->GetBuffer()); + _tables[FarSubdivisionTables::V_W]->GetBuffer()); } void @@ -266,7 +266,7 @@ OsdGLSLComputeContext::unbindShaderStorageBuffers() { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, 0); - if (_tables[FarSubdivisionTables::F_IT]) { + if (_tables[FarSubdivisionTables::F_IT]) { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, 0); } diff --git a/opensubdiv/osd/glslComputeContext.h b/opensubdiv/osd/glslComputeContext.h index 73194201..b9454166 100644 --- a/opensubdiv/osd/glslComputeContext.h +++ b/opensubdiv/osd/glslComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" @@ -62,7 +63,7 @@ private: class OsdGLSLComputeHEditTable : OsdNonCopyable { public: - OsdGLSLComputeHEditTable(const FarVertexEditTables:: + OsdGLSLComputeHEditTable(const FarVertexEditTables:: VertexEditBatch &batch); virtual ~OsdGLSLComputeHEditTable(); diff --git a/opensubdiv/osd/glslComputeController.cpp b/opensubdiv/osd/glslComputeController.cpp index cd86ffba..2e1b2a6c 100644 --- a/opensubdiv/osd/glslComputeController.cpp +++ b/opensubdiv/osd/glslComputeController.cpp @@ -73,10 +73,8 @@ OsdGLSLComputeController::getKernels(int numVertexElements, void OsdGLSLComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -87,10 +85,8 @@ OsdGLSLComputeController::ApplyBilinearFaceVerticesKernel( void OsdGLSLComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -101,10 +97,8 @@ OsdGLSLComputeController::ApplyBilinearEdgeVerticesKernel( void OsdGLSLComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -115,10 +109,8 @@ OsdGLSLComputeController::ApplyBilinearVertexVerticesKernel( void OsdGLSLComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -131,10 +123,8 @@ OsdGLSLComputeController::ApplyCatmarkFaceVerticesKernel( void OsdGLSLComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -145,10 +135,8 @@ OsdGLSLComputeController::ApplyCatmarkEdgeVerticesKernel( void OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -159,10 +147,8 @@ OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelB( void OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -173,10 +159,8 @@ OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA1( void OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -187,10 +171,8 @@ OsdGLSLComputeController::ApplyCatmarkVertexVerticesKernelA2( void OsdGLSLComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -201,10 +183,8 @@ OsdGLSLComputeController::ApplyLoopEdgeVerticesKernel( void OsdGLSLComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -215,10 +195,8 @@ OsdGLSLComputeController::ApplyLoopVertexVerticesKernelB( void OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -229,10 +207,8 @@ OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA1( void OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -243,10 +219,8 @@ OsdGLSLComputeController::ApplyLoopVertexVerticesKernelA2( void OsdGLSLComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLComputeContext *context) const { - OsdGLSLComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLComputeKernelBundle * kernelBundle = context->GetKernelBundle(); diff --git a/opensubdiv/osd/glslComputeController.h b/opensubdiv/osd/glslComputeController.h index cebf691c..1138fa5d 100644 --- a/opensubdiv/osd/glslComputeController.h +++ b/opensubdiv/osd/glslComputeController.h @@ -82,10 +82,9 @@ public: context->SetKernelBundle(getKernels(numVertexElements, numVaryingElements)); context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -110,34 +109,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; OsdGLSLComputeKernelBundle * getKernels(int numVertexElements, int numVaryingElements); diff --git a/opensubdiv/osd/glslKernelBundle.cpp b/opensubdiv/osd/glslKernelBundle.cpp index b0dbb87e..26734704 100644 --- a/opensubdiv/osd/glslKernelBundle.cpp +++ b/opensubdiv/osd/glslKernelBundle.cpp @@ -135,13 +135,13 @@ OsdGLSLComputeKernelBundle::Compile(int numVertexElements, int numVaryingElement _uniformIndexStart = glGetUniformLocation(_program, "indexStart"); _uniformIndexEnd = glGetUniformLocation(_program, "indexEnd"); - _tableUniforms[FarSubdivisionTables::F_IT] = glGetUniformLocation(_program, "_F0_IT"); - _tableUniforms[FarSubdivisionTables::F_ITa] = glGetUniformLocation(_program, "_F0_ITa"); - _tableUniforms[FarSubdivisionTables::E_IT] = glGetUniformLocation(_program, "_E0_IT"); - _tableUniforms[FarSubdivisionTables::V_IT] = glGetUniformLocation(_program, "_V0_IT"); - _tableUniforms[FarSubdivisionTables::V_ITa] = glGetUniformLocation(_program, "_V0_ITa"); - _tableUniforms[FarSubdivisionTables::E_W] = glGetUniformLocation(_program, "_E0_S"); - _tableUniforms[FarSubdivisionTables::V_W] = glGetUniformLocation(_program, "_V0_S"); + _tableUniforms[FarSubdivisionTables::F_IT] = glGetUniformLocation(_program, "_F0_IT"); + _tableUniforms[FarSubdivisionTables::F_ITa] = glGetUniformLocation(_program, "_F0_ITa"); + _tableUniforms[FarSubdivisionTables::E_IT] = glGetUniformLocation(_program, "_E0_IT"); + _tableUniforms[FarSubdivisionTables::V_IT] = glGetUniformLocation(_program, "_V0_IT"); + _tableUniforms[FarSubdivisionTables::V_ITa] = glGetUniformLocation(_program, "_V0_ITa"); + _tableUniforms[FarSubdivisionTables::E_W] = glGetUniformLocation(_program, "_E0_S"); + _tableUniforms[FarSubdivisionTables::V_W] = glGetUniformLocation(_program, "_V0_S"); // set unfiorm locations for edit _subEditAdd = glGetSubroutineIndex(_program, diff --git a/opensubdiv/osd/glslKernelBundle.h b/opensubdiv/osd/glslKernelBundle.h index 4e5102f5..fbd36e91 100644 --- a/opensubdiv/osd/glslKernelBundle.h +++ b/opensubdiv/osd/glslKernelBundle.h @@ -105,7 +105,7 @@ protected: GLuint _program; // uniform locations for compute - GLuint _tableUniforms[FarSubdivisionTables::TABLE_TYPES_COUNT]; + GLuint _tableUniforms[FarSubdivisionTables::TABLE_TYPES_COUNT]; GLuint _uniformVertexPass; GLuint _uniformVertexOffset; GLuint _uniformTableOffset; diff --git a/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp b/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp index d4e64e88..fe6a5024 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp +++ b/opensubdiv/osd/glslTransformFeedbackComputeContext.cpp @@ -69,7 +69,8 @@ OsdGLSLTransformFeedbackTable::GetTexture() const { // ---------------------------------------------------------------------------- -OsdGLSLTransformFeedbackHEditTable::OsdGLSLTransformFeedbackHEditTable(const FarVertexEditTables::VertexEditBatch &batch) +OsdGLSLTransformFeedbackHEditTable::OsdGLSLTransformFeedbackHEditTable( + const FarVertexEditTables::VertexEditBatch &batch) : _primvarIndicesTable(new OsdGLSLTransformFeedbackTable(batch.GetVertexIndices(), GL_R32UI)), _editValuesTable(new OsdGLSLTransformFeedbackTable(batch.GetValues(), GL_R32F)) { @@ -120,35 +121,35 @@ OsdGLSLTransformFeedbackComputeContext::OsdGLSLTransformFeedbackComputeContext( FarMesh const *farMesh) : _vertexTexture(0), _varyingTexture(0) { - FarSubdivisionTables const * farTables = + FarSubdivisionTables const * farTables = farMesh->GetSubdivisionTables(); // allocate 5 or 7 tables _tables.resize(7, 0); - _tables[FarSubdivisionTables::E_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_E_IT(), GL_R32I); - _tables[FarSubdivisionTables::V_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_IT(), GL_R32UI); - _tables[FarSubdivisionTables::V_ITa] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_ITa(), GL_R32I); - _tables[FarSubdivisionTables::E_W] = new OsdGLSLTransformFeedbackTable(farTables->Get_E_W(), GL_R32F); - _tables[FarSubdivisionTables::V_W] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_W(), GL_R32F); + _tables[FarSubdivisionTables::E_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_E_IT(), GL_R32I); + _tables[FarSubdivisionTables::V_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_IT(), GL_R32UI); + _tables[FarSubdivisionTables::V_ITa] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_ITa(), GL_R32I); + _tables[FarSubdivisionTables::E_W] = new OsdGLSLTransformFeedbackTable(farTables->Get_E_W(), GL_R32F); + _tables[FarSubdivisionTables::V_W] = new OsdGLSLTransformFeedbackTable(farTables->Get_V_W(), GL_R32F); if (farTables->GetNumTables() > 5) { // catmark, bilinear - _tables[FarSubdivisionTables::F_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_F_IT(), GL_R32UI); - _tables[FarSubdivisionTables::F_ITa] = new OsdGLSLTransformFeedbackTable(farTables->Get_F_ITa(), GL_R32I); + _tables[FarSubdivisionTables::F_IT] = new OsdGLSLTransformFeedbackTable(farTables->Get_F_IT(), GL_R32UI); + _tables[FarSubdivisionTables::F_ITa] = new OsdGLSLTransformFeedbackTable(farTables->Get_F_ITa(), GL_R32I); } else { // loop - _tables[FarSubdivisionTables::F_IT] = NULL; - _tables[FarSubdivisionTables::F_ITa] = NULL; + _tables[FarSubdivisionTables::F_IT] = NULL; + _tables[FarSubdivisionTables::F_ITa] = NULL; } // create hedit tables - FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); + FarVertexEditTables const *editTables = farMesh->GetVertexEdit(); if (editTables) { int numEditBatches = editTables->GetNumBatches(); _editTables.reserve(numEditBatches); for (int i = 0; i < numEditBatches; ++i) { - const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); + const FarVertexEditTables::VertexEditBatch & edit = editTables->GetBatch(i); _editTables.push_back(new OsdGLSLTransformFeedbackHEditTable(edit)); } } @@ -278,23 +279,23 @@ OsdGLSLTransformFeedbackComputeContext::bind() { bindTexture(_kernelBundle->GetVaryingUniformLocation(), _varyingTexture, 1); // XXX: loop... - if (_tables[FarSubdivisionTables::F_IT]) { - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::F_IT), - _tables[FarSubdivisionTables::F_IT]->GetTexture(), 2); - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::F_ITa), - _tables[FarSubdivisionTables::F_ITa]->GetTexture(), 3); + if (_tables[FarSubdivisionTables::F_IT]) { + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::F_IT), + _tables[FarSubdivisionTables::F_IT]->GetTexture(), 2); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::F_ITa), + _tables[FarSubdivisionTables::F_ITa]->GetTexture(), 3); } - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::E_IT), - _tables[FarSubdivisionTables::E_IT]->GetTexture(), 4); - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_IT), - _tables[FarSubdivisionTables::V_IT]->GetTexture(), 5); - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_ITa), - _tables[FarSubdivisionTables::V_ITa]->GetTexture(), 6); - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::E_W), - _tables[FarSubdivisionTables::E_W]->GetTexture(), 7); - bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_W), - _tables[FarSubdivisionTables::V_W]->GetTexture(), 8); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::E_IT), + _tables[FarSubdivisionTables::E_IT]->GetTexture(), 4); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_IT), + _tables[FarSubdivisionTables::V_IT]->GetTexture(), 5); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_ITa), + _tables[FarSubdivisionTables::V_ITa]->GetTexture(), 6); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::E_W), + _tables[FarSubdivisionTables::E_W]->GetTexture(), 7); + bindTexture(_kernelBundle->GetTableUniformLocation(FarSubdivisionTables::V_W), + _tables[FarSubdivisionTables::V_W]->GetTexture(), 8); // bind texture image (for edit kernel) glUniform1i(_kernelBundle->GetVertexBufferImageUniformLocation(), 0); diff --git a/opensubdiv/osd/glslTransformFeedbackComputeContext.h b/opensubdiv/osd/glslTransformFeedbackComputeContext.h index b87ba5fc..55677d69 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeContext.h +++ b/opensubdiv/osd/glslTransformFeedbackComputeContext.h @@ -27,6 +27,7 @@ #include "../version.h" +#include "../far/mesh.h" #include "../far/vertexEditTables.h" #include "../osd/vertex.h" #include "../osd/vertexDescriptor.h" @@ -61,8 +62,8 @@ private: class OsdGLSLTransformFeedbackHEditTable : OsdNonCopyable { public: - OsdGLSLTransformFeedbackHEditTable(const FarVertexEditTables:: - VertexEditBatch &batch); + OsdGLSLTransformFeedbackHEditTable( + const FarVertexEditTables::VertexEditBatch &batch); virtual ~OsdGLSLTransformFeedbackHEditTable(); diff --git a/opensubdiv/osd/glslTransformFeedbackComputeController.cpp b/opensubdiv/osd/glslTransformFeedbackComputeController.cpp index 5789c8ab..50a87773 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeController.cpp +++ b/opensubdiv/osd/glslTransformFeedbackComputeController.cpp @@ -72,10 +72,8 @@ OsdGLSLTransformFeedbackComputeController::getKernels(int numVertexElements, void OsdGLSLTransformFeedbackComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -90,10 +88,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyBilinearFaceVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -108,10 +104,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyBilinearEdgeVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -126,10 +120,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyBilinearVertexVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -146,10 +138,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyCatmarkFaceVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -164,10 +154,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyCatmarkEdgeVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -182,10 +170,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelB( void OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -200,10 +186,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelA1( void OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -218,10 +202,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyCatmarkVertexVerticesKernelA2( void OsdGLSLTransformFeedbackComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -236,10 +218,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyLoopEdgeVerticesKernel( void OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -254,10 +234,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelB( void OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -272,10 +250,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelA1( void OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); @@ -290,10 +266,8 @@ OsdGLSLTransformFeedbackComputeController::ApplyLoopVertexVerticesKernelA2( void OsdGLSLTransformFeedbackComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdGLSLTransformFeedbackComputeContext *context) const { - OsdGLSLTransformFeedbackComputeContext * context = - static_cast(clientdata); assert(context); OsdGLSLTransformFeedbackKernelBundle * kernelBundle = context->GetKernelBundle(); diff --git a/opensubdiv/osd/glslTransformFeedbackComputeController.h b/opensubdiv/osd/glslTransformFeedbackComputeController.h index ec00f362..f48d90be 100644 --- a/opensubdiv/osd/glslTransformFeedbackComputeController.h +++ b/opensubdiv/osd/glslTransformFeedbackComputeController.h @@ -83,10 +83,9 @@ public: context->SetKernelBundle(getKernels(numVertexElements, numVaryingElements)); context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -111,34 +110,34 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; OsdGLSLTransformFeedbackKernelBundle * getKernels(int numVertexElements, int numVaryingElements); diff --git a/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp b/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp index d89ba83d..e32b4b07 100644 --- a/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp +++ b/opensubdiv/osd/glslTransformFeedbackKernelBundle.cpp @@ -157,13 +157,13 @@ OsdGLSLTransformFeedbackKernelBundle::Compile(int numVertexElements, int numVary _uniformTableOffset = glGetUniformLocation(_program, "tableOffset"); _uniformIndexStart = glGetUniformLocation(_program, "indexStart"); - _uniformTables[FarSubdivisionTables::F_IT] = glGetUniformLocation(_program, "_F0_IT"); - _uniformTables[FarSubdivisionTables::F_ITa] = glGetUniformLocation(_program, "_F0_ITa"); - _uniformTables[FarSubdivisionTables::E_IT] = glGetUniformLocation(_program, "_E0_IT"); - _uniformTables[FarSubdivisionTables::V_IT] = glGetUniformLocation(_program, "_V0_IT"); - _uniformTables[FarSubdivisionTables::V_ITa] = glGetUniformLocation(_program, "_V0_ITa"); - _uniformTables[FarSubdivisionTables::E_W] = glGetUniformLocation(_program, "_E0_S"); - _uniformTables[FarSubdivisionTables::V_W] = glGetUniformLocation(_program, "_V0_S"); + _uniformTables[FarSubdivisionTables::F_IT] = glGetUniformLocation(_program, "_F0_IT"); + _uniformTables[FarSubdivisionTables::F_ITa] = glGetUniformLocation(_program, "_F0_ITa"); + _uniformTables[FarSubdivisionTables::E_IT] = glGetUniformLocation(_program, "_E0_IT"); + _uniformTables[FarSubdivisionTables::V_IT] = glGetUniformLocation(_program, "_V0_IT"); + _uniformTables[FarSubdivisionTables::V_ITa] = glGetUniformLocation(_program, "_V0_ITa"); + _uniformTables[FarSubdivisionTables::E_W] = glGetUniformLocation(_program, "_E0_S"); + _uniformTables[FarSubdivisionTables::V_W] = glGetUniformLocation(_program, "_V0_S"); // set unfiorm locations for edit _subEditAdd = glGetSubroutineIndex(_program, diff --git a/opensubdiv/osd/glslTransformFeedbackKernelBundle.h b/opensubdiv/osd/glslTransformFeedbackKernelBundle.h index 19d43710..af25b522 100644 --- a/opensubdiv/osd/glslTransformFeedbackKernelBundle.h +++ b/opensubdiv/osd/glslTransformFeedbackKernelBundle.h @@ -148,7 +148,7 @@ protected: GLuint _program; // uniform locations - GLint _uniformTables[FarSubdivisionTables::TABLE_TYPES_COUNT]; + GLint _uniformTables[FarSubdivisionTables::TABLE_TYPES_COUNT]; GLint _uniformVertexPass; GLint _uniformVertexOffset; GLint _uniformTableOffset; diff --git a/opensubdiv/osd/ompComputeController.cpp b/opensubdiv/osd/ompComputeController.cpp index f40c2579..ace71a70 100644 --- a/opensubdiv/osd/ompComputeController.cpp +++ b/opensubdiv/osd/ompComputeController.cpp @@ -42,214 +42,188 @@ OsdOmpComputeController::OsdOmpComputeController(int numThreads) { void OsdOmpComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdOmpComputeBilinearEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdOmpComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdOmpComputeBilinearVertex( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdOmpComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); 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(), + (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, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); const OsdCpuHEditTable *edit = context->GetEditTable(batch.GetTableIndex()); diff --git a/opensubdiv/osd/ompComputeController.h b/opensubdiv/osd/ompComputeController.h index 16bcc529..e79538d9 100644 --- a/opensubdiv/osd/ompComputeController.h +++ b/opensubdiv/osd/ompComputeController.h @@ -80,10 +80,9 @@ public: omp_set_num_threads(_numThreads); context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -109,33 +108,33 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; int _numThreads; }; diff --git a/opensubdiv/osd/tbbComputeController.cpp b/opensubdiv/osd/tbbComputeController.cpp index 437ea259..c34fc279 100644 --- a/opensubdiv/osd/tbbComputeController.cpp +++ b/opensubdiv/osd/tbbComputeController.cpp @@ -22,6 +22,8 @@ // language governing permissions and limitations under the Apache License. // +#include + #include "../osd/cpuComputeContext.h" #include "../osd/tbbComputeController.h" #include "../osd/tbbKernel.h" @@ -45,214 +47,188 @@ OsdTbbComputeController::OsdTbbComputeController(int numThreads) { void OsdTbbComputeController::ApplyBilinearFaceVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (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 OsdTbbComputeController::ApplyBilinearEdgeVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeBilinearEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdTbbComputeController::ApplyBilinearVertexVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeBilinearVertex( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), + (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), batch.GetVertexOffset(), batch.GetTableOffset(), batch.GetStart(), batch.GetEnd()); } void OsdTbbComputeController::ApplyCatmarkFaceVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeFace( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_IT)->GetBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::F_ITa)->GetBuffer(), + (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 OsdTbbComputeController::ApplyCatmarkEdgeVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelB( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeVertexB( 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(), + (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 OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelA1( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyCatmarkVertexVerticesKernelA2( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyLoopEdgeVerticesKernel( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeEdge( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::E_IT)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::E_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyLoopVertexVerticesKernelB( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeLoopVertexB( 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(), + (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 OsdTbbComputeController::ApplyLoopVertexVerticesKernelA1( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyLoopVertexVerticesKernelA2( - FarKernelBatch const &batch, void *clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); OsdTbbComputeVertexA( context->GetVertexDescriptor(), context->GetCurrentVertexBuffer(), context->GetCurrentVaryingBuffer(), - (const int*)context->GetTable(FarSubdivisionTables::V_ITa)->GetBuffer(), - (const float*)context->GetTable(FarSubdivisionTables::V_W)->GetBuffer(), + (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 OsdTbbComputeController::ApplyVertexEdits( - FarKernelBatch const &batch, void * clientdata) const { + FarKernelBatch const &batch, OsdCpuComputeContext *context) const { - OsdCpuComputeContext * context = - static_cast(clientdata); assert(context); const OsdCpuHEditTable *edit = context->GetEditTable(batch.GetTableIndex()); diff --git a/opensubdiv/osd/tbbComputeController.h b/opensubdiv/osd/tbbComputeController.h index 6994c861..b67d49a0 100644 --- a/opensubdiv/osd/tbbComputeController.h +++ b/opensubdiv/osd/tbbComputeController.h @@ -72,10 +72,9 @@ public: VARYING_BUFFER * varyingBuffer) { context->Bind(vertexBuffer, varyingBuffer); - FarDispatcher::Refine(this, - batches, - -1, - context); + + FarDispatcher::Refine(this, context, batches, /*maxlevel*/-1); + context->Unbind(); } @@ -101,33 +100,33 @@ public: protected: friend class FarDispatcher; - void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyBilinearVertexVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkFaceVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyCatmarkVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopEdgeVerticesKernel(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelB(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA1(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, void * clientdata) const; + void ApplyLoopVertexVerticesKernelA2(FarKernelBatch const &batch, ComputeContext *context) const; - void ApplyVertexEdits(FarKernelBatch const &batch, void * clientdata) const; + void ApplyVertexEdits(FarKernelBatch const &batch, ComputeContext *context) const; int _numThreads; }; diff --git a/opensubdiv/osdutil/refiner.cpp b/opensubdiv/osdutil/refiner.cpp index b31d60d2..29a7b994 100644 --- a/opensubdiv/osdutil/refiner.cpp +++ b/opensubdiv/osdutil/refiner.cpp @@ -98,8 +98,7 @@ PxOsdUtilRefiner::Initialize( // Subdivision tables describe the addition steps with coefficients // needed to perform subdivision - const FarSubdivisionTables* ftable = - _farMesh->GetSubdivisionTables(); + const FarSubdivisionTables* ftable = _farMesh->GetSubdivisionTables(); // Find quads array at given level const FarPatchTables * ptables = _farMesh->GetPatchTables(); diff --git a/python/osd/subdivider.cpp b/python/osd/subdivider.cpp index d7ba4e8a..73d7e29d 100644 --- a/python/osd/subdivider.cpp +++ b/python/osd/subdivider.cpp @@ -111,11 +111,10 @@ shim::Subdivider::getRefinedQuads(Buffer* refinedQuads) return; } - const OpenSubdiv::FarSubdivisionTables *tables = + const OpenSubdiv::FarSubdivisionTables *tables = self->farMesh->GetSubdivisionTables(); - bool loop = dynamic_cast*>(tables); + bool loop = dynamic_cast(tables); if (loop) { cerr << "loop subdivision not supported" << endl; diff --git a/regression/far_regression/main.cpp b/regression/far_regression/main.cpp index 05ff8a6e..25dab12e 100644 --- a/regression/far_regression/main.cpp +++ b/regression/far_regression/main.cpp @@ -56,13 +56,13 @@ struct xyzVV { ~xyzVV( ) { } - void AddWithWeight(const xyzVV& src, float weight, void * =0 ) { + void AddWithWeight(const xyzVV& src, float weight) { _pos[0]+=weight*src._pos[0]; _pos[1]+=weight*src._pos[1]; _pos[2]+=weight*src._pos[2]; } - void AddVaryingWithWeight(const xyzVV& , float, void * =0 ) { } + void AddVaryingWithWeight(const xyzVV& , float) { } void Clear( void * =0 ) { _pos[0]=_pos[1]=_pos[2]=0.0f; } @@ -124,7 +124,7 @@ typedef OpenSubdiv::HbrVertexOperator xyzVertexOperator; typedef OpenSubdiv::FarMesh fMesh; typedef OpenSubdiv::FarMeshFactory fMeshFactory; -typedef OpenSubdiv::FarSubdivisionTables fSubdivision; +typedef OpenSubdiv::FarSubdivisionTables fSubdivision; typedef OpenSubdiv::FarPatchTables fPatches; static bool g_debugmode = false; @@ -309,7 +309,8 @@ int checkMesh( char const * msg, xyzmesh * hmesh, int levels, Scheme scheme=kCat fMeshFactory fact( hmesh, levels ); fMesh * m = fact.Create( ); - OpenSubdiv::FarComputeController::_DefaultController.Refine(m); + static OpenSubdiv::FarComputeController computeController; + computeController.Refine(m); if (g_debugmode) { for (int i=1; i<=levels; ++i)