2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "../osd/ompKernel.h"
|
2015-05-29 16:21:14 +00:00
|
|
|
#include "../osd/bufferDescriptor.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <cassert>
|
2014-05-09 00:20:54 +00:00
|
|
|
#include <cstdlib>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <omp.h>
|
2014-10-23 19:07:12 +00:00
|
|
|
#include <vector>
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
namespace Osd {
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
template <class T> T *
|
2015-05-29 16:21:14 +00:00
|
|
|
elementAtIndex(T * src, int index, BufferDescriptor const &desc) {
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
return src + index * desc.stride;
|
2014-05-09 00:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2015-05-29 16:21:14 +00:00
|
|
|
clear(float *dst, BufferDescriptor const &desc) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(dst);
|
|
|
|
memset(dst, 0, desc.length*sizeof(float));
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static inline void
|
|
|
|
addWithWeight(float *dst, const float *src, int srcIndex, float weight,
|
2015-05-29 16:21:14 +00:00
|
|
|
BufferDescriptor const &desc) {
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2016-06-25 21:23:55 +00:00
|
|
|
assert(src && dst);
|
2014-09-05 22:07:46 +00:00
|
|
|
src = elementAtIndex(src, srcIndex, desc);
|
|
|
|
for (int k = 0; k < desc.length; ++k) {
|
|
|
|
dst[k] += src[k] * weight;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static inline void
|
|
|
|
copy(float *dst, int dstIndex, const float *src,
|
2015-05-29 16:21:14 +00:00
|
|
|
BufferDescriptor const &desc) {
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2016-06-25 21:23:55 +00:00
|
|
|
assert(src && dst);
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
dst = elementAtIndex(dst, dstIndex, desc);
|
|
|
|
memcpy(dst, src, desc.length*sizeof(float));
|
2014-06-10 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// XXXX manuelk this should be optimized further by using SIMD - considering
|
|
|
|
// OMP is somewhat obsolete - this is probably not worth it.
|
|
|
|
void
|
2015-05-29 16:21:14 +00:00
|
|
|
OmpEvalStencils(float const * src, BufferDescriptor const &srcDesc,
|
|
|
|
float * dst, BufferDescriptor const &dstDesc,
|
2015-05-19 17:16:56 +00:00
|
|
|
int const * sizes,
|
2015-05-09 00:31:26 +00:00
|
|
|
int const * offsets,
|
|
|
|
int const * indices,
|
|
|
|
float const * weights,
|
|
|
|
int start, int end) {
|
2015-07-05 17:22:38 +00:00
|
|
|
start = (start > 0 ? start : 0);
|
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
src += srcDesc.offset;
|
|
|
|
dst += dstDesc.offset;
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
int numThreads = omp_get_max_threads();
|
|
|
|
int n = end - start;
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
float * result = (float*)alloca(srcDesc.length * numThreads * sizeof(float));
|
2014-06-10 23:31:44 +00:00
|
|
|
|
|
|
|
#pragma omp parallel for
|
2015-05-07 23:11:00 +00:00
|
|
|
for (int i = 0; i < n; ++i) {
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2015-07-05 17:22:38 +00:00
|
|
|
int index = i + start; // Stencil index
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// Get thread-local pointers
|
|
|
|
int const * threadIndices = indices + offsets[index];
|
|
|
|
float const * threadWeights = weights + offsets[index];
|
2014-06-10 23:31:44 +00:00
|
|
|
|
|
|
|
int threadId = omp_get_thread_num();
|
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
float * threadResult = result + threadId*srcDesc.length;
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
clear(threadResult, dstDesc);
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int j=0; j<(int)sizes[index]; ++j) {
|
2015-05-07 23:11:00 +00:00
|
|
|
addWithWeight(threadResult, src,
|
|
|
|
threadIndices[j], threadWeights[j], srcDesc);
|
2014-06-10 23:31:44 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
copy(dst, i, threadResult, dstDesc);
|
2012-12-11 01:15:13 +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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-29 16:21:14 +00:00
|
|
|
OmpEvalStencils(float const * src, BufferDescriptor const &srcDesc,
|
|
|
|
float * dst, BufferDescriptor const &dstDesc,
|
|
|
|
float * dstDu, BufferDescriptor const &dstDuDesc,
|
|
|
|
float * dstDv, BufferDescriptor const &dstDvDesc,
|
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 const * sizes,
|
|
|
|
int const * offsets,
|
|
|
|
int const * indices,
|
|
|
|
float const * weights,
|
|
|
|
float const * duWeights,
|
|
|
|
float const * dvWeights,
|
|
|
|
int start, int end) {
|
2015-07-05 17:22:38 +00:00
|
|
|
start = (start > 0 ? start : 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
|
|
|
|
|
|
|
src += srcDesc.offset;
|
|
|
|
dst += dstDesc.offset;
|
|
|
|
dstDu += dstDuDesc.offset;
|
|
|
|
dstDv += dstDvDesc.offset;
|
|
|
|
|
|
|
|
int numThreads = omp_get_max_threads();
|
|
|
|
int n = end - start;
|
|
|
|
|
|
|
|
float * result = (float*)alloca(srcDesc.length * numThreads * sizeof(float));
|
|
|
|
float * resultDu = (float*)alloca(srcDesc.length * numThreads * sizeof(float));
|
|
|
|
float * resultDv = (float*)alloca(srcDesc.length * numThreads * sizeof(float));
|
|
|
|
|
|
|
|
#pragma omp parallel for
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
|
2015-07-05 17:22:38 +00:00
|
|
|
int index = i + start; // Stencil index
|
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
|
|
|
|
|
|
|
// Get thread-local pointers
|
|
|
|
int const * threadIndices = indices + offsets[index];
|
|
|
|
float const * threadWeights = weights + offsets[index];
|
|
|
|
float const * threadWeightsDu = duWeights + offsets[index];
|
|
|
|
float const * threadWeightsDv = dvWeights + offsets[index];
|
|
|
|
|
|
|
|
int threadId = omp_get_thread_num();
|
|
|
|
|
|
|
|
float * threadResult = result + threadId*srcDesc.length;
|
|
|
|
float * threadResultDu = resultDu + threadId*srcDesc.length;
|
|
|
|
float * threadResultDv = resultDv + threadId*srcDesc.length;
|
|
|
|
|
|
|
|
clear(threadResult, dstDesc);
|
|
|
|
clear(threadResultDu, dstDuDesc);
|
|
|
|
clear(threadResultDv, dstDvDesc);
|
|
|
|
|
|
|
|
for (int j=0; j<(int)sizes[index]; ++j) {
|
|
|
|
addWithWeight(threadResult, src,
|
|
|
|
threadIndices[j], threadWeights[j], srcDesc);
|
|
|
|
addWithWeight(threadResultDu, src,
|
|
|
|
threadIndices[j], threadWeightsDu[j], srcDesc);
|
|
|
|
addWithWeight(threadResultDv, src,
|
|
|
|
threadIndices[j], threadWeightsDv[j], srcDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(dst, i, threadResult, dstDesc);
|
|
|
|
copy(dstDu, i, threadResultDu, dstDuDesc);
|
|
|
|
copy(dstDv, i, threadResultDv, dstDvDesc);
|
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2012-12-11 01:15:13 +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
|
|
|
} // end namespace Osd
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|