gcd: files for GCD dispatcher (right now just copy of OMP one), add items to glViewer

This commit is contained in:
Aras Pranckevicius 2013-02-02 22:53:33 +02:00
parent 84d91323ac
commit 54c7329ba4
10 changed files with 1076 additions and 4 deletions

View File

@ -210,12 +210,20 @@ if (WIN32)
find_package(DXSDK)
endif()
if (NOT NO_GCD AND APPLE)
set(GCD_FOUND 1)
endif()
find_package(Maya 201200)
# Warn about missing dependencies that will cause parts of OpenSubdiv to be
# disabled. Also, add preprocessor defines that can be used in the source
# code to determine if a specific dependency is present or not.
if(GCD_FOUND)
add_definitions( -DOPENSUBDIV_HAS_GCD )
endif()
if(OPENMP_FOUND)
add_definitions(
-DOPENSUBDIV_HAS_OPENMP

View File

@ -51,6 +51,7 @@ Optional:
-DGLFW_LOCATION=[path to GLFW]
-DMAYA_LOCATION=[path to Maya]
-DNO_OMP=1 // disable OpenMP
-DNO_GCD=1 // disable GrandCentralDispatch on OSX
````
The paths to Maya, Ptex, GLFW, and GLEW can also be specified through the

View File

@ -89,6 +89,11 @@
#include <osd/ompComputeController.h>
#endif
#ifdef OPENSUBDIV_HAS_GCD
#include <osd/gcdDispatcher.h>
#include <osd/gcdComputeController.h>
#endif
#ifdef OPENSUBDIV_HAS_OPENCL
#include <osd/clDispatcher.h>
#include <osd/clGLVertexBuffer.h>
@ -157,10 +162,11 @@ typedef OpenSubdiv::HbrHalfedge<OpenSubdiv::OsdVertex> OsdHbrHalfedge;
enum KernelType { kCPU = 0,
kOPENMP = 1,
kCUDA = 2,
kCL = 3,
kGLSL = 4,
kGLSLCompute = 5 };
kGCD = 2,
kCUDA = 3,
kCL = 4,
kGLSL = 5,
kGLSLCompute = 6 };
struct SimpleShape {
std::string name;
@ -567,6 +573,8 @@ getKernelName(int kernel) {
return "CPU";
else if (kernel == kOPENMP)
return "OpenMP";
else if (kernel == kGCD)
return "GCD";
else if (kernel == kCUDA)
return "Cuda";
else if (kernel == kGLSL)
@ -634,6 +642,12 @@ createOsdMesh( const char * shape, int level, int kernel, Scheme scheme=kCatmark
OpenSubdiv::OsdOmpComputeController,
OpenSubdiv::OsdGLDrawContext>(hmesh, 6, level, bits);
#endif
#ifdef OPENSUBDIV_HAS_GCD
} else if (kernel == kGCD) {
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
OpenSubdiv::OsdGcdComputeController,
OpenSubdiv::OsdGLDrawContext>(hmesh, 6, level, bits);
#endif
#ifdef OPENSUBDIV_HAS_OPENCL
} else if(kernel == kCL) {
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCLGLVertexBuffer,
@ -1604,6 +1618,9 @@ initHUD()
#ifdef OPENSUBDIV_HAS_OPENMP
g_hud.AddRadioButton(0, "OPENMP", false, 10, 30, callbackKernel, kOPENMP, 'k');
#endif
#ifdef OPENSUBDIV_HAS_GCD
g_hud.AddRadioButton(0, "GCD", false, 10, 30, callbackKernel, kGCD, 'k');
#endif
#ifdef OPENSUBDIV_HAS_CUDA
g_hud.AddRadioButton(0, "CUDA", false, 10, 50, callbackKernel, kCUDA, 'k');
#endif

View File

@ -177,6 +177,25 @@ if( OPENMP_FOUND )
endif()
endif()
#-------------------------------------------------------------------------------
if( GCD_FOUND )
list(APPEND CPU_SOURCE_FILES
gcdDispatcher.cpp
gcdKernel.cpp
gcdComputeController.cpp
)
list(APPEND PUBLIC_HEADER_FILES
gcdDispatcher.h
gcdKernel.h
gcdComputeController.h
)
#if (CMAKE_COMPILER_IS_GNUCXX)
# list(APPEND PLATFORM_LIBRARIES
# gomp
# )
#endif()
endif()
#-------------------------------------------------------------------------------
# GL code & dependencies
if( OPENGL_FOUND OR OPENGLES_FOUND )

View File

@ -0,0 +1,76 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#include "../osd/cpuComputeContext.h"
#include "../osd/gcdComputeController.h"
#include "../osd/gcdDispatcher.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
OsdGcdComputeController::OsdGcdComputeController() {
}
void
OsdGcdComputeController::Synchronize() {
// XXX:
}
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

View File

@ -0,0 +1,112 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#ifndef OSD_GCD_COMPUTE_CONTROLLER_H
#define OSD_GCD_COMPUTE_CONTROLLER_H
#include "../version.h"
#include "../osd/cpuComputeContext.h"
#include "../osd/gcdDispatcher.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
/// \brief Compute controller for launching Grand Central Dispatch subdivision kernels.
/// OsdGcdComputeController is a compute controller class to launch
/// Grand Central Dispatch threaded subdivision kernels. It requires OsdCpuVertexBufferInterface
/// as arguments of Refine function.
class OsdGcdComputeController {
public:
typedef OsdCpuComputeContext ComputeContext;
/// Constructor.
explicit OsdGcdComputeController();
/// Launch subdivision kernels and apply to given vertex buffers.
/// vertexBuffer will be interpolated with vertex interpolation and
/// varyingBuffer will be interpolated with varying interpolation.
/// vertexBuffer and varyingBuffer should implement
/// OsdCpuVertexBufferInterface.
template<class VERTEX_BUFFER, class VARYING_BUFFER>
void Refine(OsdCpuComputeContext *context,
VERTEX_BUFFER *vertexBuffer,
VARYING_BUFFER *varyingBuffer) {
context->Bind(vertexBuffer, varyingBuffer);
OsdGcdKernelDispatcher::GetInstance()->Refine(context->GetFarMesh(),
context);
context->Unbind();
}
template<class VERTEX_BUFFER>
void Refine(OsdCpuComputeContext *context, VERTEX_BUFFER *vertexBuffer) {
Refine(context, vertexBuffer, (VERTEX_BUFFER*)0);
}
/// Waits until all running subdivision kernels finish.
void Synchronize();
private:
int _numThreads;
};
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OSD_GCD_COMPUTE_CONTROLLER_H

View File

@ -0,0 +1,311 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#include "../osd/gcdDispatcher.h"
#include "../osd/gcdKernel.h"
#include "../osd/cpuComputeContext.h"
//#include <stdlib.h>
//#include <string.h>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
OsdGcdKernelDispatcher::OsdGcdKernelDispatcher() {
}
OsdGcdKernelDispatcher::~OsdGcdKernelDispatcher() {
}
void
OsdGcdKernelDispatcher::Refine(FarMesh<OsdVertex> * mesh,
OsdCpuComputeContext *context) const {
FarDispatcher<OsdVertex>::Refine(mesh, /*maxlevel =*/ -1, context);
}
OsdGcdKernelDispatcher *
OsdGcdKernelDispatcher::GetInstance() {
static OsdGcdKernelDispatcher instance;
return &instance;
}
void
OsdGcdKernelDispatcher::ApplyBilinearFaceVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeFace(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::F_IT, level-1),
(const int*)context->GetTablePtr(Table::F_ITa, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyBilinearEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeBilinearEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::E_IT, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyBilinearVertexVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeBilinearVertex(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::V_ITa, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyCatmarkFaceVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeFace(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::F_IT, level-1),
(const int*)context->GetTablePtr(Table::F_ITa, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyCatmarkEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::E_IT, level-1),
(const float*)context->GetTablePtr(Table::E_W, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyCatmarkVertexVerticesKernelB(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeVertexB(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::V_ITa, level-1),
(const int*)context->GetTablePtr(Table::V_IT, level-1),
(const float*)context->GetTablePtr(Table::V_W, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyCatmarkVertexVerticesKernelA(
FarMesh<OsdVertex> * mesh, int offset, bool pass, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::V_ITa, level-1),
(const float*)context->GetTablePtr(Table::V_W, level-1),
offset, start, end, pass);
}
void
OsdGcdKernelDispatcher::ApplyLoopEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeEdge(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::E_IT, level-1),
(const float*)context->GetTablePtr(Table::E_W, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyLoopVertexVerticesKernelB(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeLoopVertexB(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::V_ITa, level-1),
(const int*)context->GetTablePtr(Table::V_IT, level-1),
(const float*)context->GetTablePtr(Table::V_W, level-1),
offset, start, end);
}
void
OsdGcdKernelDispatcher::ApplyLoopVertexVerticesKernelA(
FarMesh<OsdVertex> * mesh, int offset, bool pass, int level,
int start, int end, void * clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
OsdGcdComputeVertexA(
context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
context->GetCurrentVaryingBuffer(),
(const int*)context->GetTablePtr(Table::V_ITa, level-1),
(const float*)context->GetTablePtr(Table::V_W, level-1),
offset, start, end, pass);
}
void
OsdGcdKernelDispatcher::ApplyVertexEdits(
FarMesh<OsdVertex> *mesh, int offset, int level, void *clientdata) const {
OsdCpuComputeContext * context =
static_cast<OsdCpuComputeContext*>(clientdata);
assert(context);
int numEdits = context->GetNumEditTables();
for (int i = 0; i < numEdits; ++i) {
const FarVertexEditTables<OsdVertex>::VertexEditBatch * edit =
context->GetEditTable(i);
assert(edit);
const FarTable<unsigned int> &primvarIndices = edit->GetVertexIndices();
const FarTable<float> &editValues = edit->GetValues();
// XXX: how about edits for varying...?
if (edit->GetOperation() == FarVertexEdit::Add) {
OsdGcdEditVertexAdd(context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
edit->GetPrimvarIndex(),
edit->GetPrimvarWidth(),
primvarIndices.GetNumElements(level-1),
(const int*)primvarIndices[level-1],
(const float*)editValues[level-1]);
} else if (edit->GetOperation() == FarVertexEdit::Set) {
OsdGcdEditVertexSet(context->GetVertexDescriptor(),
context->GetCurrentVertexBuffer(),
edit->GetPrimvarIndex(),
edit->GetPrimvarWidth(),
primvarIndices.GetNumElements(level-1),
(const int*)primvarIndices[level-1],
(const float*)editValues[level-1]);
}
}
}
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

View File

@ -0,0 +1,135 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#ifndef OSD_GCD_DISPATCHER_H
#define OSD_GCD_DISPATCHER_H
#include "../version.h"
#include "../osd/vertex.h"
#include "../far/dispatcher.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
class OsdCpuComputeContext;
class OsdGcdKernelDispatcher : public FarDispatcher<OsdVertex>
{
public:
OsdGcdKernelDispatcher();
virtual ~OsdGcdKernelDispatcher();
void Refine(FarMesh<OsdVertex> * mesh, OsdCpuComputeContext *context) const;
static OsdGcdKernelDispatcher * GetInstance();
protected:
virtual void ApplyBilinearFaceVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyBilinearEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyBilinearVertexVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyCatmarkFaceVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyCatmarkEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyCatmarkVertexVerticesKernelB(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyCatmarkVertexVerticesKernelA(
FarMesh<OsdVertex> * mesh, int offset, bool pass, int level,
int start, int end, void * clientdata) const;
virtual void ApplyLoopEdgeVerticesKernel(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyLoopVertexVerticesKernelB(
FarMesh<OsdVertex> * mesh, int offset, int level,
int start, int end, void * clientdata) const;
virtual void ApplyLoopVertexVerticesKernelA(
FarMesh<OsdVertex> * mesh, int offset, bool pass, int level,
int start, int end, void * clientdata) const;
virtual void ApplyVertexEdits(
FarMesh<OsdVertex> *mesh, int offset, int level,
void * clientdata) const;
};
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OSD_GCD_DISPATCHER_H

View File

@ -0,0 +1,277 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#include "../osd/gcdKernel.h"
#include "../osd/vertexDescriptor.h"
#include <math.h>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
void OsdGcdComputeFace(
const OsdVertexDescriptor *vdesc, float * vertex, float * varying,
const int *F_IT, const int *F_ITa, int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int h = F_ITa[2*i];
int n = F_ITa[2*i+1];
float weight = 1.0f/n;
// XXX: should use local vertex struct variable instead of
// accumulating directly into global memory.
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
for (int j = 0; j < n; ++j) {
int index = F_IT[h+j];
vdesc->AddWithWeight(vertex, dstIndex, index, weight);
vdesc->AddVaryingWithWeight(varying, dstIndex, index, weight);
}
}
}
void OsdGcdComputeEdge(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *E_IT, const float *E_W, int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int eidx0 = E_IT[4*i+0];
int eidx1 = E_IT[4*i+1];
int eidx2 = E_IT[4*i+2];
int eidx3 = E_IT[4*i+3];
float vertWeight = E_W[i*2+0];
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
vdesc->AddWithWeight(vertex, dstIndex, eidx0, vertWeight);
vdesc->AddWithWeight(vertex, dstIndex, eidx1, vertWeight);
if (eidx2 != -1) {
float faceWeight = E_W[i*2+1];
vdesc->AddWithWeight(vertex, dstIndex, eidx2, faceWeight);
vdesc->AddWithWeight(vertex, dstIndex, eidx3, faceWeight);
}
vdesc->AddVaryingWithWeight(varying, dstIndex, eidx0, 0.5f);
vdesc->AddVaryingWithWeight(varying, dstIndex, eidx1, 0.5f);
}
}
void OsdGcdComputeVertexA(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *V_ITa, const float *V_W,
int offset, int start, int end, int pass) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int n = V_ITa[5*i+1];
int p = V_ITa[5*i+2];
int eidx0 = V_ITa[5*i+3];
int eidx1 = V_ITa[5*i+4];
float weight = (pass == 1) ? V_W[i] : 1.0f - V_W[i];
// In the case of fractional weight, the weight must be inverted since
// the value is shared with the k_Smooth kernel (statistically the
// k_Smooth kernel runs much more often than this one)
if (weight > 0.0f && weight < 1.0f && n > 0)
weight = 1.0f - weight;
int dstIndex = offset + i;
if (not pass)
vdesc->Clear(vertex, varying, dstIndex);
if (eidx0 == -1 || (pass == 0 && (n == -1))) {
vdesc->AddWithWeight(vertex, dstIndex, p, weight);
} else {
vdesc->AddWithWeight(vertex, dstIndex, p, weight * 0.75f);
vdesc->AddWithWeight(vertex, dstIndex, eidx0, weight * 0.125f);
vdesc->AddWithWeight(vertex, dstIndex, eidx1, weight * 0.125f);
}
if (not pass)
vdesc->AddVaryingWithWeight(varying, dstIndex, p, 1.0f);
}
}
void OsdGcdComputeVertexB(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *V_ITa, const int *V_IT, const float *V_W,
int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int h = V_ITa[5*i];
int n = V_ITa[5*i+1];
int p = V_ITa[5*i+2];
float weight = V_W[i];
float wp = 1.0f/static_cast<float>(n*n);
float wv = (n-2.0f) * n * wp;
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
vdesc->AddWithWeight(vertex, dstIndex, p, weight * wv);
for (int j = 0; j < n; ++j) {
vdesc->AddWithWeight(vertex, dstIndex, V_IT[h+j*2], weight * wp);
vdesc->AddWithWeight(vertex, dstIndex, V_IT[h+j*2+1], weight * wp);
}
vdesc->AddVaryingWithWeight(varying, dstIndex, p, 1.0f);
}
}
void OsdGcdComputeLoopVertexB(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *V_ITa, const int *V_IT, const float *V_W,
int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int h = V_ITa[5*i];
int n = V_ITa[5*i+1];
int p = V_ITa[5*i+2];
float weight = V_W[i];
float wp = 1.0f/static_cast<float>(n);
float beta = 0.25f * cosf(static_cast<float>(M_PI) * 2.0f * wp) + 0.375f;
beta = beta * beta;
beta = (0.625f - beta) * wp;
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
vdesc->AddWithWeight(vertex, dstIndex, p, weight * (1.0f - (beta * n)));
for (int j = 0; j < n; ++j)
vdesc->AddWithWeight(vertex, dstIndex, V_IT[h+j], weight * beta);
vdesc->AddVaryingWithWeight(varying, dstIndex, p, 1.0f);
}
}
void OsdGcdComputeBilinearEdge(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *E_IT, int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int eidx0 = E_IT[2*i+0];
int eidx1 = E_IT[2*i+1];
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
vdesc->AddWithWeight(vertex, dstIndex, eidx0, 0.5f);
vdesc->AddWithWeight(vertex, dstIndex, eidx1, 0.5f);
vdesc->AddVaryingWithWeight(varying, dstIndex, eidx0, 0.5f);
vdesc->AddVaryingWithWeight(varying, dstIndex, eidx1, 0.5f);
}
}
void OsdGcdComputeBilinearVertex(
const OsdVertexDescriptor *vdesc, float *vertex, float *varying,
const int *V_ITa, int offset, int start, int end) {
#pragma omp parallel for
for (int i = start; i < end; i++) {
int p = V_ITa[i];
int dstIndex = offset + i;
vdesc->Clear(vertex, varying, dstIndex);
vdesc->AddWithWeight(vertex, dstIndex, p, 1.0f);
vdesc->AddVaryingWithWeight(varying, dstIndex, p, 1.0f);
}
}
void OsdGcdEditVertexAdd(
const OsdVertexDescriptor *vdesc, float *vertex,
int primVarOffset, int primVarWidth, int vertexCount,
const int *editIndices, const float *editValues) {
#pragma omp parallel for
for (int i = 0; i < vertexCount; i++) {
vdesc->ApplyVertexEditAdd(vertex, primVarOffset, primVarWidth,
editIndices[i], &editValues[i*primVarWidth]);
}
}
void OsdGcdEditVertexSet(
const OsdVertexDescriptor *vdesc, float *vertex,
int primVarOffset, int primVarWidth, int vertexCount,
const int *editIndices, const float *editValues) {
#pragma omp parallel for
for (int i = 0; i < vertexCount; i++) {
vdesc->ApplyVertexEditSet(vertex, primVarOffset, primVarWidth,
editIndices[i], &editValues[i*primVarWidth]);
}
}
} // end namespace OPENSUBDIV_VERSION
} // end namespace OpenSubdiv

116
opensubdiv/osd/gcdKernel.h Normal file
View File

@ -0,0 +1,116 @@
//
// Copyright (C) Pixar. All rights reserved.
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
//
#ifndef OSD_GCD_KERNEL_H
#define OSD_GCD_KERNEL_H
#include "../version.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
struct OsdVertexDescriptor;
void OsdGcdComputeFace(const OsdVertexDescriptor *vdesc,
float * vertex, float * varying,
const int *F_IT, const int *F_ITa,
int offset, int start, int end);
void OsdGcdComputeEdge(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *E_IT, const float *E_ITa,
int offset, int start, int end);
void OsdGcdComputeVertexA(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *V_ITa, const float *V_IT,
int offset, int start, int end, int pass);
void OsdGcdComputeVertexB(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *V_ITa, const int *V_IT, const float *V_W,
int offset, int start, int end);
void OsdGcdComputeLoopVertexB(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *V_ITa, const int *V_IT,
const float *V_W,
int offset, int start, int end);
void OsdGcdComputeBilinearEdge(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *E_IT,
int offset, int start, int end);
void OsdGcdComputeBilinearVertex(const OsdVertexDescriptor *vdesc,
float *vertex, float * varying,
const int *V_ITa,
int offset, int start, int end);
void OsdGcdEditVertexAdd(const OsdVertexDescriptor *vdesc, float *vertex,
int primVarOffset, int primVarWidth, int count,
const int *editIndices, const float *editValues);
void OsdGcdEditVertexSet(const OsdVertexDescriptor *vdesc, float *vertex,
int primVarOffset, int primVarWidth, int count,
const int *editIndices, const float *editValues);
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif // OSD_GCD_KERNEL_H