2015-05-09 00:31:26 +00:00
|
|
|
//
|
|
|
|
// Copyright 2015 Pixar
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
|
|
//
|
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
|
|
//
|
|
|
|
// You may obtain a copy of the Apache License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "../osd/glXFBEvaluator.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include "../far/error.h"
|
2015-05-22 18:50:01 +00:00
|
|
|
#include "../far/stencilTable.h"
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
#if _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Osd {
|
|
|
|
|
|
|
|
static const char *shaderSource =
|
|
|
|
#include "../osd/glslXFBKernel.gen.h"
|
|
|
|
;
|
|
|
|
|
|
|
|
template <class T> GLuint
|
|
|
|
createGLTextureBuffer(std::vector<T> const & src, GLenum type) {
|
|
|
|
GLint size = static_cast<int>(src.size()*sizeof(T));
|
|
|
|
void const * ptr = &src.at(0);
|
|
|
|
|
|
|
|
GLuint buffer;
|
|
|
|
glGenBuffers(1, &buffer);
|
|
|
|
|
|
|
|
GLuint devicePtr;
|
|
|
|
glGenTextures(1, &devicePtr);
|
|
|
|
|
|
|
|
#if defined(GL_EXT_direct_state_access)
|
|
|
|
if (glNamedBufferDataEXT && glTextureBufferEXT) {
|
|
|
|
glNamedBufferDataEXT(buffer, size, ptr, GL_STATIC_DRAW);
|
|
|
|
glTextureBufferEXT(devicePtr, GL_TEXTURE_BUFFER, type, buffer);
|
|
|
|
} else {
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
GLint prev = 0;
|
|
|
|
|
|
|
|
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &prev);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, ptr, GL_STATIC_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, prev);
|
|
|
|
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &prev);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, devicePtr);
|
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, type, buffer);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDeleteBuffers(1, &buffer);
|
|
|
|
|
|
|
|
return devicePtr;
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
GLStencilTableTBO::GLStencilTableTBO(
|
|
|
|
Far::StencilTable const *stencilTable) {
|
2015-05-09 00:31:26 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
_numStencils = stencilTable->GetNumStencils();
|
2015-05-09 00:31:26 +00:00
|
|
|
if (_numStencils > 0) {
|
2015-05-22 18:50:01 +00:00
|
|
|
_sizes = createGLTextureBuffer(stencilTable->GetSizes(), GL_R32UI);
|
2015-05-09 00:31:26 +00:00
|
|
|
_offsets = createGLTextureBuffer(
|
2015-05-22 18:50:01 +00:00
|
|
|
stencilTable->GetOffsets(), GL_R32I);
|
2015-05-09 00:31:26 +00:00
|
|
|
_indices = createGLTextureBuffer(
|
2015-05-22 18:50:01 +00:00
|
|
|
stencilTable->GetControlIndices(), GL_R32I);
|
|
|
|
_weights = createGLTextureBuffer(stencilTable->GetWeights(), GL_R32F);
|
2015-05-28 00:23:36 +00:00
|
|
|
_duWeights = _dvWeights = 0;
|
2015-05-09 00:31:26 +00:00
|
|
|
} else {
|
|
|
|
_sizes = _offsets = _indices = _weights = 0;
|
2015-05-28 00:23:36 +00:00
|
|
|
_duWeights = _dvWeights = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLStencilTableTBO::GLStencilTableTBO(
|
|
|
|
Far::LimitStencilTable const *limitStencilTable) {
|
|
|
|
|
|
|
|
_numStencils = limitStencilTable->GetNumStencils();
|
|
|
|
if (_numStencils > 0) {
|
|
|
|
_sizes = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetSizes(), GL_R32UI);
|
|
|
|
_offsets = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetOffsets(), GL_R32I);
|
|
|
|
_indices = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetControlIndices(), GL_R32I);
|
|
|
|
_weights = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetWeights(), GL_R32F);
|
|
|
|
_duWeights = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetDuWeights(), GL_R32F);
|
|
|
|
_dvWeights = createGLTextureBuffer(
|
|
|
|
limitStencilTable->GetDvWeights(), GL_R32F);
|
|
|
|
} else {
|
|
|
|
_sizes = _offsets = _indices = _weights = 0;
|
|
|
|
_duWeights = _dvWeights = 0;
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
GLStencilTableTBO::~GLStencilTableTBO() {
|
2015-05-09 00:31:26 +00:00
|
|
|
if (_sizes) glDeleteTextures(1, &_sizes);
|
|
|
|
if (_offsets) glDeleteTextures(1, &_offsets);
|
|
|
|
if (_indices) glDeleteTextures(1, &_indices);
|
2015-05-28 00:23:36 +00:00
|
|
|
if (_weights) glDeleteTextures(1, &_weights);
|
|
|
|
if (_duWeights) glDeleteTextures(1, &_duWeights);
|
|
|
|
if (_dvWeights) glDeleteTextures(1, &_dvWeights);
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
GLXFBEvaluator::GLXFBEvaluator() : _srcBufferTexture(0) {
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLXFBEvaluator::~GLXFBEvaluator() {
|
|
|
|
if (_srcBufferTexture) {
|
|
|
|
glDeleteTextures(1, &_srcBufferTexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
static GLuint
|
2015-05-29 16:21:14 +00:00
|
|
|
compileKernel(BufferDescriptor const &srcDesc,
|
|
|
|
BufferDescriptor const &dstDesc,
|
|
|
|
BufferDescriptor const &duDesc,
|
|
|
|
BufferDescriptor const &dvDesc,
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
const char *kernelDefine) {
|
|
|
|
|
|
|
|
GLuint program = glCreateProgram();
|
2015-05-09 00:31:26 +00:00
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
std::ostringstream defines;
|
|
|
|
defines << "#define LENGTH " << srcDesc.length << "\n"
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
<< "#define SRC_STRIDE " << srcDesc.stride << "\n"
|
2015-05-28 00:23:36 +00:00
|
|
|
<< "#define VERTEX_SHADER\n"
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
<< kernelDefine << "\n";
|
2015-05-09 00:31:26 +00:00
|
|
|
std::string defineStr = defines.str();
|
|
|
|
|
|
|
|
const char *shaderSources[3] = {"#version 410\n", NULL, NULL};
|
|
|
|
|
|
|
|
shaderSources[1] = defineStr.c_str();
|
|
|
|
shaderSources[2] = shaderSource;
|
2015-05-28 00:23:36 +00:00
|
|
|
glShaderSource(vertexShader, 3, shaderSources, NULL);
|
|
|
|
glCompileShader(vertexShader);
|
|
|
|
glAttachShader(program, vertexShader);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
std::vector<std::string> outputs;
|
2015-05-28 00:23:36 +00:00
|
|
|
char attrName[32];
|
2015-05-09 00:31:26 +00:00
|
|
|
{
|
|
|
|
// vertex data (may include custom vertex data) and varying data
|
|
|
|
// are stored into the same buffer, interleaved.
|
|
|
|
//
|
|
|
|
// (gl_SkipComponents1)
|
|
|
|
// outVertexData[0]
|
|
|
|
// outVertexData[1]
|
|
|
|
// outVertexData[2]
|
|
|
|
// (gl_SkipComponents1)
|
|
|
|
//
|
|
|
|
// note that "primvarOffset" in shader is still needed to read
|
|
|
|
// interleaved components even if gl_SkipComponents is used.
|
|
|
|
//
|
|
|
|
int primvarOffset = (dstDesc.offset % dstDesc.stride);
|
|
|
|
for (int i = 0; i < primvarOffset; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
|
|
|
for (int i = 0; i < dstDesc.length; ++i) {
|
|
|
|
snprintf(attrName, sizeof(attrName), "outVertexBuffer[%d]", i);
|
|
|
|
outputs.push_back(attrName);
|
|
|
|
}
|
|
|
|
for (int i = primvarOffset + dstDesc.length; i < dstDesc.stride; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
2015-05-28 00:23:36 +00:00
|
|
|
}
|
|
|
|
if (duDesc.length) {
|
|
|
|
//
|
|
|
|
// For derivatives, we use another buffer bindings so gl_NextBuffer
|
|
|
|
// is inserted here to switch the destination of transform feedback.
|
|
|
|
//
|
|
|
|
// Note that the destination buffers may or may not be shared between
|
|
|
|
// vertex and each derivatives. gl_NextBuffer seems still works well
|
|
|
|
// in either case.
|
|
|
|
//
|
|
|
|
outputs.push_back("gl_NextBuffer");
|
|
|
|
int primvarOffset = (duDesc.offset % duDesc.stride);
|
|
|
|
for (int i = 0; i < primvarOffset; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
|
|
|
for (int i = 0; i < duDesc.length; ++i) {
|
|
|
|
snprintf(attrName, sizeof(attrName), "outDuBuffer[%d]", i);
|
|
|
|
outputs.push_back(attrName);
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
2015-05-28 00:23:36 +00:00
|
|
|
for (int i = primvarOffset + duDesc.length; i < duDesc.stride; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dvDesc.length) {
|
|
|
|
outputs.push_back("gl_NextBuffer");
|
|
|
|
int primvarOffset = (dvDesc.offset % dvDesc.stride);
|
|
|
|
for (int i = 0; i < primvarOffset; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
|
|
|
for (int i = 0; i < dvDesc.length; ++i) {
|
|
|
|
snprintf(attrName, sizeof(attrName), "outDvBuffer[%d]", i);
|
|
|
|
outputs.push_back(attrName);
|
|
|
|
}
|
|
|
|
for (int i = primvarOffset + dvDesc.length; i < dvDesc.stride; ++i) {
|
|
|
|
outputs.push_back("gl_SkipComponents1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// convert to char* array
|
|
|
|
std::vector<const char *> pOutputs;
|
|
|
|
for (size_t i = 0; i < outputs.size(); ++i) {
|
|
|
|
pOutputs.push_back(&outputs[i][0]);
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glTransformFeedbackVaryings(program, (GLsizei)outputs.size(),
|
2015-05-09 00:31:26 +00:00
|
|
|
&pOutputs[0], GL_INTERLEAVED_ATTRIBS);
|
|
|
|
|
|
|
|
GLint linked = 0;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glLinkProgram(program);
|
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
if (linked == GL_FALSE) {
|
|
|
|
char buffer[1024];
|
2015-05-28 00:23:36 +00:00
|
|
|
glGetShaderInfoLog(vertexShader, 1024, NULL, buffer);
|
2015-05-09 00:31:26 +00:00
|
|
|
Far::Error(Far::FAR_RUNTIME_ERROR, buffer);
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glGetProgramInfoLog(program, 1024, NULL, buffer);
|
2015-05-09 00:31:26 +00:00
|
|
|
Far::Error(Far::FAR_RUNTIME_ERROR, buffer);
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glDeleteProgram(program);
|
|
|
|
program = 0;
|
2015-05-09 00:31:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
glDeleteShader(vertexShader);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
return program;
|
|
|
|
}
|
2015-05-09 00:31:26 +00:00
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
bool
|
2015-05-29 16:21:14 +00:00
|
|
|
GLXFBEvaluator::Compile(BufferDescriptor const &srcDesc,
|
|
|
|
BufferDescriptor const &dstDesc,
|
|
|
|
BufferDescriptor const &duDesc,
|
|
|
|
BufferDescriptor const &dvDesc) {
|
2015-05-09 00:31:26 +00:00
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
// create a stencil kernel
|
|
|
|
_stencilKernel.Compile(srcDesc, dstDesc, duDesc, dvDesc);
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
// create a patch kernel
|
|
|
|
_patchKernel.Compile(srcDesc, dstDesc, duDesc, dvDesc);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
// create a texture for input buffer
|
|
|
|
if (!_srcBufferTexture) {
|
|
|
|
glGenTextures(1, &_srcBufferTexture);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
GLXFBEvaluator::Synchronize(void * /*kernel*/) {
|
|
|
|
// XXX: this is currently just for the test purpose.
|
|
|
|
// need to be reimplemented by fence and sync.
|
|
|
|
glFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bindTexture(GLint sampler, GLuint texture, int unit) {
|
|
|
|
if (sampler == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
glUniform1i(sampler, unit);
|
|
|
|
glActiveTexture(GL_TEXTURE0 + unit);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, texture);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-28 00:23:36 +00:00
|
|
|
GLXFBEvaluator::EvalStencils(
|
2015-05-29 16:21:14 +00:00
|
|
|
GLuint srcBuffer, BufferDescriptor const &srcDesc,
|
|
|
|
GLuint dstBuffer, BufferDescriptor const &dstDesc,
|
|
|
|
GLuint duBuffer, BufferDescriptor const &duDesc,
|
|
|
|
GLuint dvBuffer, BufferDescriptor const &dvDesc,
|
2015-05-28 00:23:36 +00:00
|
|
|
GLuint sizesTexture,
|
|
|
|
GLuint offsetsTexture,
|
|
|
|
GLuint indicesTexture,
|
|
|
|
GLuint weightsTexture,
|
|
|
|
GLuint duWeightsTexture,
|
|
|
|
GLuint dvWeightsTexture,
|
|
|
|
int start, int end) const {
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
if (!_stencilKernel.program) return false;
|
2015-05-09 00:31:26 +00:00
|
|
|
int count = end - start;
|
|
|
|
if (count <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bind vertex array
|
|
|
|
// always create new one, to be safe with multiple contexts (slow though)
|
|
|
|
GLuint vao = 0;
|
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
|
|
|
|
glEnable(GL_RASTERIZER_DISCARD);
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glUseProgram(_stencilKernel.program);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
// Set input VBO as a texture buffer.
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, _srcBufferTexture);
|
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, srcBuffer);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
bindTexture(_stencilKernel.uniformSrcBufferTexture, _srcBufferTexture, 0);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
2015-05-22 18:50:01 +00:00
|
|
|
// bind stencil table textures.
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
bindTexture(_stencilKernel.uniformSizesTexture, sizesTexture, 1);
|
|
|
|
bindTexture(_stencilKernel.uniformOffsetsTexture, offsetsTexture, 2);
|
|
|
|
bindTexture(_stencilKernel.uniformIndicesTexture, indicesTexture, 3);
|
|
|
|
bindTexture(_stencilKernel.uniformWeightsTexture, weightsTexture, 4);
|
2015-05-28 00:23:36 +00:00
|
|
|
if (_stencilKernel.uniformDuWeightsTexture >= 0 && duWeightsTexture)
|
|
|
|
bindTexture(_stencilKernel.uniformDuWeightsTexture, duWeightsTexture, 5);
|
|
|
|
if (_stencilKernel.uniformDvWeightsTexture >= 0 && dvWeightsTexture)
|
|
|
|
bindTexture(_stencilKernel.uniformDvWeightsTexture, dvWeightsTexture, 6);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
// set batch range
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glUniform1i(_stencilKernel.uniformStart, start);
|
|
|
|
glUniform1i(_stencilKernel.uniformEnd, end);
|
|
|
|
glUniform1i(_stencilKernel.uniformSrcOffset, srcDesc.offset);
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
// The destination buffer is bound at vertex boundary.
|
|
|
|
//
|
|
|
|
// Example: When we have a batched and interleaved vertex buffer
|
|
|
|
//
|
|
|
|
// Obj X | Obj Y |
|
|
|
|
// -----------+-------------------------------------------+-------
|
|
|
|
// | vtx 0 | vtx 1 | |
|
|
|
|
// -----------+---------------+---------------+-----------+-------
|
|
|
|
// | x y z r g b a | x y z r g b a | .... |
|
|
|
|
// -----------+---------------+---------------+-----------+-------
|
|
|
|
// ^
|
|
|
|
// srcDesc.offset for Obj Y color
|
|
|
|
//
|
|
|
|
// ^-------------------------------------------^
|
|
|
|
// XFB destination buffer range
|
|
|
|
// S S S * * * *
|
|
|
|
// k k k
|
|
|
|
// i i i
|
|
|
|
// p p p
|
|
|
|
//
|
|
|
|
// We use gl_SkipComponents to skip the first 3 XYZ so the
|
|
|
|
// buffer itself needs to be bound for entire section of ObjY.
|
|
|
|
//
|
|
|
|
// Note that for the source buffer (texture) we bind the whole
|
|
|
|
// buffer (all VBO range) and use srcOffset=srcDesc.offset for
|
|
|
|
// indexing.
|
|
|
|
//
|
2015-05-28 00:23:36 +00:00
|
|
|
int dstBufferBindOffset = dstDesc.stride ?
|
|
|
|
(dstDesc.offset - (dstDesc.offset % dstDesc.stride)) : 0;
|
|
|
|
int duBufferBindOffset = duDesc.stride ?
|
|
|
|
(duDesc.offset - (duDesc.offset % duDesc.stride)) : 0;
|
|
|
|
int dvBufferBindOffset = dvDesc.stride ?
|
|
|
|
(dvDesc.offset - (dvDesc.offset % dvDesc.stride)) : 0;
|
2015-05-09 00:31:26 +00:00
|
|
|
|
|
|
|
// bind destination buffer
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
0, dstBuffer,
|
|
|
|
dstBufferBindOffset * sizeof(float),
|
|
|
|
count * dstDesc.stride * sizeof(float));
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
if (duDesc.length > 0) {
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
1, duBuffer,
|
|
|
|
duBufferBindOffset * sizeof(float),
|
|
|
|
count * duDesc.stride * sizeof(float));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvDesc.length > 0) {
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
2, dvBuffer,
|
|
|
|
dvBufferBindOffset * sizeof(float),
|
|
|
|
count * dvDesc.stride * sizeof(float));
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:31:26 +00:00
|
|
|
glBeginTransformFeedback(GL_POINTS);
|
|
|
|
glDrawArrays(GL_POINTS, 0, count);
|
|
|
|
glEndTransformFeedback();
|
|
|
|
|
|
|
|
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
glActiveTexture(GL_TEXTURE0 + i);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_RASTERIZER_DISCARD);
|
|
|
|
glUseProgram(0);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
|
|
// revert vao
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glDeleteVertexArrays(1, &vao);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
bool
|
|
|
|
GLXFBEvaluator::EvalPatches(
|
2015-05-29 16:21:14 +00:00
|
|
|
GLuint srcBuffer, BufferDescriptor const &srcDesc,
|
|
|
|
GLuint dstBuffer, BufferDescriptor const &dstDesc,
|
|
|
|
GLuint duBuffer, BufferDescriptor const &duDesc,
|
|
|
|
GLuint dvBuffer, BufferDescriptor const &dvDesc,
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
int numPatchCoords,
|
|
|
|
GLuint patchCoordsBuffer,
|
|
|
|
const PatchArrayVector &patchArrays,
|
|
|
|
GLuint patchIndexTexture,
|
|
|
|
GLuint patchParamTexture) const {
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
bool derivatives = (duDesc.length > 0 || dvDesc.length > 0);
|
|
|
|
|
|
|
|
if (!_patchKernel.program) return false;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
|
|
|
// bind vertex array
|
|
|
|
// always create new one, to be safe with multiple contexts (slow though)
|
|
|
|
GLuint vao = 0;
|
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
|
|
|
|
glEnable(GL_RASTERIZER_DISCARD);
|
|
|
|
glUseProgram(_patchKernel.program);
|
|
|
|
|
|
|
|
// Set input VBO as a texture buffer.
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, _srcBufferTexture);
|
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, srcBuffer);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
|
|
|
|
|
|
|
bindTexture(_patchKernel.uniformSrcBufferTexture, _srcBufferTexture, 0);
|
|
|
|
|
|
|
|
// bind patch index and patch param textures.
|
|
|
|
bindTexture(_patchKernel.uniformPatchParamTexture, patchParamTexture, 1);
|
|
|
|
bindTexture(_patchKernel.uniformPatchIndexTexture, patchIndexTexture, 2);
|
|
|
|
|
|
|
|
// set other uniforms
|
|
|
|
glUniform4iv(_patchKernel.uniformPatchArray, (int)patchArrays.size(),
|
|
|
|
(const GLint*)&patchArrays[0]);
|
|
|
|
glUniform1i(_patchKernel.uniformSrcOffset, srcDesc.offset);
|
|
|
|
|
|
|
|
// input patchcoords
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
int stride = sizeof(int) * 5; // patchcoord = int*5 struct
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, patchCoordsBuffer);
|
|
|
|
glVertexAttribIPointer(0, 3, GL_UNSIGNED_INT, stride, (void*)0);
|
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(int)*3));
|
|
|
|
|
|
|
|
int dstBufferBindOffset =
|
|
|
|
dstDesc.offset - (dstDesc.offset % dstDesc.stride);
|
2015-05-28 00:23:36 +00:00
|
|
|
int duBufferBindOffset = duDesc.stride
|
|
|
|
? (duDesc.offset - (duDesc.offset % duDesc.stride))
|
|
|
|
: 0;
|
|
|
|
int dvBufferBindOffset = dvDesc.stride
|
|
|
|
? (dvDesc.offset - (dvDesc.offset % dvDesc.stride))
|
|
|
|
: 0;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
|
|
|
// bind destination buffer
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
0, dstBuffer,
|
|
|
|
dstBufferBindOffset * sizeof(float),
|
|
|
|
numPatchCoords * dstDesc.stride * sizeof(float));
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
if (derivatives) {
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
1, duBuffer,
|
|
|
|
duBufferBindOffset * sizeof(float),
|
|
|
|
numPatchCoords * duDesc.stride * sizeof(float));
|
|
|
|
|
|
|
|
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
2, dvBuffer,
|
|
|
|
dvBufferBindOffset * sizeof(float),
|
|
|
|
numPatchCoords * dvDesc.stride * sizeof(float));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
glBeginTransformFeedback(GL_POINTS);
|
|
|
|
glDrawArrays(GL_POINTS, 0, numPatchCoords);
|
|
|
|
glEndTransformFeedback();
|
|
|
|
|
|
|
|
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
|
|
|
|
|
|
|
|
// unbind textures
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
glActiveTexture(GL_TEXTURE0 + i);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_RASTERIZER_DISCARD);
|
|
|
|
glUseProgram(0);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
|
|
|
glDisableVertexAttribArray(0);
|
|
|
|
glDisableVertexAttribArray(1);
|
|
|
|
|
|
|
|
// revert vao
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glDeleteVertexArrays(1, &vao);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GLXFBEvaluator::_StencilKernel::_StencilKernel() : program(0) {
|
|
|
|
}
|
|
|
|
GLXFBEvaluator::_StencilKernel::~_StencilKernel() {
|
|
|
|
if (program) {
|
|
|
|
glDeleteProgram(program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-29 16:21:14 +00:00
|
|
|
GLXFBEvaluator::_StencilKernel::Compile(BufferDescriptor const &srcDesc,
|
|
|
|
BufferDescriptor const &dstDesc,
|
|
|
|
BufferDescriptor const &duDesc,
|
|
|
|
BufferDescriptor const &dvDesc) {
|
2015-05-28 00:23:36 +00:00
|
|
|
// create stencil kernel
|
|
|
|
if (program) {
|
|
|
|
glDeleteProgram(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool derivatives = (duDesc.length > 0 || dvDesc.length > 0);
|
|
|
|
const char *kernelDef = derivatives
|
|
|
|
? "#define OPENSUBDIV_GLSL_XFB_KERNEL_EVAL_STENCILS\n"
|
|
|
|
"#define OPENSUBDIV_GLSL_XFB_USE_DERIVATIVES\n"
|
|
|
|
: "#define OPENSUBDIV_GLSL_XFB_KERNEL_EVAL_STENCILS\n";
|
|
|
|
|
|
|
|
program = compileKernel(srcDesc, dstDesc, duDesc, dvDesc, kernelDef);
|
|
|
|
if (program == 0) return false;
|
|
|
|
|
|
|
|
// cache uniform locations (TODO: use uniform block)
|
|
|
|
uniformSrcBufferTexture = glGetUniformLocation(program, "vertexBuffer");
|
|
|
|
uniformSrcOffset = glGetUniformLocation(program, "srcOffset");
|
|
|
|
uniformSizesTexture = glGetUniformLocation(program, "sizes");
|
|
|
|
uniformOffsetsTexture = glGetUniformLocation(program, "offsets");
|
|
|
|
uniformIndicesTexture = glGetUniformLocation(program, "indices");
|
|
|
|
uniformWeightsTexture = glGetUniformLocation(program, "weights");
|
|
|
|
uniformDuWeightsTexture = glGetUniformLocation(program, "duWeights");
|
|
|
|
uniformDvWeightsTexture = glGetUniformLocation(program, "dvWeights");
|
|
|
|
uniformStart = glGetUniformLocation(program, "batchStart");
|
|
|
|
uniformEnd = glGetUniformLocation(program, "batchEnd");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
GLXFBEvaluator::_PatchKernel::_PatchKernel() : program(0) {
|
|
|
|
}
|
|
|
|
GLXFBEvaluator::_PatchKernel::~_PatchKernel() {
|
|
|
|
if (program) {
|
|
|
|
glDeleteProgram(program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-29 16:21:14 +00:00
|
|
|
GLXFBEvaluator::_PatchKernel::Compile(BufferDescriptor const &srcDesc,
|
|
|
|
BufferDescriptor const &dstDesc,
|
|
|
|
BufferDescriptor const &duDesc,
|
|
|
|
BufferDescriptor const &dvDesc) {
|
2015-05-28 00:23:36 +00:00
|
|
|
// create stencil kernel
|
|
|
|
if (program) {
|
|
|
|
glDeleteProgram(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool derivatives = (duDesc.length > 0 || dvDesc.length > 0);
|
|
|
|
const char *kernelDef = derivatives
|
|
|
|
? "#define OPENSUBDIV_GLSL_XFB_KERNEL_EVAL_PATCHES\n"
|
|
|
|
"#define OPENSUBDIV_GLSL_XFB_USE_DERIVATIVES\n"
|
|
|
|
: "#define OPENSUBDIV_GLSL_XFB_KERNEL_EVAL_PATCHES\n";
|
|
|
|
|
|
|
|
program = compileKernel(srcDesc, dstDesc, duDesc, dvDesc, kernelDef);
|
|
|
|
if (program == 0) return false;
|
|
|
|
|
|
|
|
// cache uniform locations
|
|
|
|
uniformSrcBufferTexture = glGetUniformLocation(program, "vertexBuffer");
|
|
|
|
uniformSrcOffset = glGetUniformLocation(program, "srcOffset");
|
|
|
|
uniformPatchArray = glGetUniformLocation(program, "patchArray");
|
|
|
|
uniformPatchParamTexture = glGetUniformLocation(program, "patchParamBuffer");
|
|
|
|
uniformPatchIndexTexture = glGetUniformLocation(program, "patchIndexBuffer");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
2015-05-09 00:31:26 +00:00
|
|
|
} // end namespace Osd
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|