2012-06-09 00:06:35 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-09 00:06:35 +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-06-09 00:06:35 +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-06-09 00:06:35 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-06-09 00:06:35 +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-06-09 00:06:35 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "../osd/cpuKernel.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../osd/vertexDescriptor.h"
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <cassert>
|
2014-05-09 00:20:54 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdlib>
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <vector>
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2012-06-09 00:06:35 +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 *
|
|
|
|
elementAtIndex(T * src, int index, VertexBufferDescriptor 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
|
2014-09-05 22:07:46 +00:00
|
|
|
clear(float *dst, VertexBufferDescriptor const &desc) {
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(dst);
|
|
|
|
memset(dst, 0, desc.length*sizeof(float));
|
2014-05-13 23:06:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static inline void
|
|
|
|
addWithWeight(float *dst, const float *src, int srcIndex, float weight,
|
|
|
|
VertexBufferDescriptor const &desc) {
|
2014-05-13 23:06:58 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(src and dst);
|
|
|
|
src = elementAtIndex(src, srcIndex, desc);
|
|
|
|
for (int k = 0; k < desc.length; ++k) {
|
|
|
|
dst[k] += src[k] * weight;
|
2014-05-13 23:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static inline void
|
|
|
|
copy(float *dst, int dstIndex, const float *src,
|
|
|
|
VertexBufferDescriptor const &desc) {
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(src and dst);
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
dst = elementAtIndex(dst, dstIndex, desc);
|
|
|
|
memcpy(dst, src, desc.length*sizeof(float));
|
2012-06-09 00:06:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void
|
|
|
|
CpuComputeStencils(VertexBufferDescriptor const &vertexDesc,
|
|
|
|
float const * vertexSrc,
|
|
|
|
float * vertexDst,
|
|
|
|
unsigned char const * sizes,
|
|
|
|
int const * offsets,
|
|
|
|
int const * indices,
|
|
|
|
float const * weights,
|
|
|
|
int start, int end) {
|
2014-05-27 22:25:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
assert(start>=0 and start<end);
|
2014-05-27 22:25:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (start>0) {
|
|
|
|
sizes += start;
|
|
|
|
indices += offsets[start];
|
|
|
|
weights += offsets[start];
|
2014-05-27 22:25:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (vertexDesc.length==4 and vertexDesc.stride==4) {
|
2013-08-14 23:41:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// SIMD fast path for aligned primvar data (8 floats)
|
|
|
|
ComputeStencilKernel<4>(vertexSrc, vertexDst,
|
|
|
|
sizes, indices, weights, start, end);
|
2013-08-14 23:41:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} else if(vertexDesc.length==8 and vertexDesc.stride==8) {
|
2012-06-09 00:06:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// SIMD fast path for aligned primvar data (8 floats)
|
|
|
|
ComputeStencilKernel<8>(vertexSrc, vertexDst,
|
|
|
|
sizes, indices, weights, start, end);
|
2014-05-09 00:20:54 +00:00
|
|
|
}
|
2013-08-14 23:41:35 +00:00
|
|
|
else {
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// Slow path for non-aligned data
|
|
|
|
float * result = (float*)alloca(vertexDesc.length * sizeof(float));
|
2013-08-14 23:41:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int nstencils = end-start;
|
|
|
|
for (int i=0; i<nstencils; ++i, ++sizes) {
|
2013-08-14 23:41:35 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
clear(result, vertexDesc);
|
2012-06-09 18:12:34 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int j=0; j<*sizes; ++j) {
|
|
|
|
addWithWeight(result, vertexSrc, *indices++, *weights++, vertexDesc);
|
2013-08-14 23:41:35 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
copy(vertexDst, i, result, vertexDesc);
|
2012-06-09 00:06:35 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
}
|
2012-06-09 00:06:35 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
} // end namespace Osd
|
2012-09-18 01:41:48 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
} // end namespace OpenSubdiv
|