Change stencils sizes from unsigned char to int.

This commit is contained in:
jcowles 2015-05-19 10:16:56 -07:00
parent d28a5c01c9
commit 7b4aa33a1f
23 changed files with 71 additions and 76 deletions

View File

@ -389,7 +389,7 @@ GregoryBasis::CreateStencilTables(PointsVector const &stencils) {
stencilTables->_numControlVertices = 0;
stencilTables->resize(nStencils, nElements);
unsigned char * sizes = &stencilTables->_sizes[0];
int * sizes = &stencilTables->_sizes[0];
Index * indices = &stencilTables->_indices[0];
float * weights = &stencilTables->_weights[0];
@ -399,7 +399,7 @@ GregoryBasis::CreateStencilTables(PointsVector const &stencils) {
int size = src.GetSize();
memcpy(indices, src.GetIndices(), size*sizeof(Index));
memcpy(weights, src.GetWeights(), size*sizeof(float));
*sizes = (int)size;
*sizes = size;
indices += size;
weights += size;

View File

@ -91,7 +91,7 @@ public:
// in the stencil
void PushBackVertex(Index protoStencil, Index vert, float weight) {
assert(weight!=0.0f);
unsigned char & size = _sizes[protoStencil];
int & size = _sizes[protoStencil];
Index idx = protoStencil*_maxsize;
if (size < (_maxsize-1)) {
idx += size;
@ -134,7 +134,7 @@ public:
}
// Returns the size of a given proto-stencil
unsigned char GetSize(Index protoStencil) const {
int GetSize(Index protoStencil) const {
assert(protoStencil<(int)_sizes.size());
return _sizes[protoStencil];
}
@ -177,9 +177,9 @@ public:
}
// Copy the proto-stencil out of the pool
unsigned char CopyStencil(Index protoStencil,
int CopyStencil(Index protoStencil,
Index * indices, float * weights) {
unsigned char size = GetSize(protoStencil);
int size = GetSize(protoStencil);
memcpy(indices, this->GetIndices(protoStencil), size*sizeof(Index));
memcpy(weights, this->GetWeights(protoStencil), size*sizeof(float));
return size;
@ -202,7 +202,7 @@ protected:
bool _interpolateVarying; // true for varying interpolation
std::vector<unsigned char> _sizes; // 'fast' memory pool
std::vector<int> _sizes; // 'fast' memory pool
std::vector<int> _indices;
std::vector<float> _weights;
@ -233,7 +233,7 @@ public:
void PushBackVertex(Index protoStencil,
Index vert, float weight, float tan1Weight, float tan2Weight) {
assert(weight!=0.0f or tan1Weight!=0.0f or tan2Weight!=0.0f);
unsigned char & size = this->_sizes[protoStencil];
int & size = this->_sizes[protoStencil];
Index idx = protoStencil*this->_maxsize;
if (size < (this->_maxsize-1)) {
idx += size;
@ -290,10 +290,9 @@ public:
memset(GetTan2Weights(protoStencil), 0, this->_sizes[protoStencil]*sizeof(float));
}
unsigned char CopyLimitStencil(Index protoStencil,
int CopyLimitStencil(Index protoStencil,
Index * indices, float * weights, float * tan1Weights, float * tan2Weights) {
unsigned char size =
Allocator<PROTOSTENCIL, BIG_PROTOSTENCIL>::CopyStencil(
int size = Allocator<PROTOSTENCIL, BIG_PROTOSTENCIL>::CopyStencil(
protoStencil, indices, weights);
memcpy(tan1Weights, this->GetTan1Weights(protoStencil), size*sizeof(Index));
memcpy(tan2Weights, this->GetTan2Weights(protoStencil), size*sizeof(float));
@ -313,7 +312,7 @@ private:
//
struct BigStencil {
BigStencil(unsigned char size, Index const * indices,
BigStencil(int size, Index const * indices,
float const * weights) {
_indices.reserve(size+5); _indices.resize(size);
memcpy(&_indices.at(0), indices, size*sizeof(int));
@ -326,8 +325,7 @@ struct BigStencil {
};
struct BigLimitStencil : public BigStencil {
BigLimitStencil(unsigned char size,
Index const * indices, float const * weights,
BigLimitStencil(int size, Index const * indices, float const * weights,
float const * tan1Weights, float const * tan2Weights) :
BigStencil(size, indices, weights) {
@ -369,7 +367,7 @@ public:
if (src._alloc) {
// Stencil contribution
unsigned char srcSize = src._alloc->GetSize(src._id);
int srcSize = src._alloc->GetSize(src._id);
Index const * srcIndices = src._alloc->GetIndices(src._id);
float const * srcWeights = src._alloc->GetWeights(src._id);
@ -395,7 +393,7 @@ public:
return;
}
unsigned char srcSize = table.GetSizes()[idx];
int srcSize = table.GetSizes()[idx];
Index offset = table.GetOffsets()[idx];
Index const * srcIndices = &table.GetControlIndices()[offset];
float const * srcWeights = &table.GetWeights()[offset];
@ -413,10 +411,10 @@ protected:
friend class ProtoLimitStencil;
void addWithWeight(float weight, unsigned char srcSize,
void addWithWeight(float weight, int srcSize,
Index const * srcIndices, float const * srcWeights) {
for (unsigned char i=0; i<srcSize; ++i) {
for (int i=0; i<srcSize; ++i) {
assert(srcWeights[i]!=0.0f);
@ -466,11 +464,11 @@ public:
return;
}
unsigned char srcSize = *src.GetSizePtr();
int srcSize = *src.GetSizePtr();
Index const * srcIndices = src.GetVertexIndices();
float const * srcWeights = src.GetWeights();
for (unsigned char i=0; i<srcSize; ++i) {
for (int i=0; i<srcSize; ++i) {
float w = srcWeights[i];
if (w==0.0f) {

View File

@ -56,7 +56,7 @@ public:
///
/// @param weights Table pointer to the vertex weights of the stencil
///
Stencil(unsigned char * size,
Stencil(int * size,
Index * indices,
float * weights)
: _size(size),
@ -77,7 +77,7 @@ public:
}
/// \brief Returns the size of the stencil as a pointer
unsigned char * GetSizePtr() const {
int * GetSizePtr() const {
return _size;
}
@ -103,7 +103,7 @@ protected:
friend class StencilTablesFactory;
friend class LimitStencilTablesFactory;
unsigned char * _size;
int * _size;
Index * _indices;
float * _weights;
};
@ -138,7 +138,7 @@ public:
Stencil GetStencil(Index i) const;
/// \brief Returns the number of control vertices of each stencil in the table
std::vector<unsigned char> const & GetSizes() const {
std::vector<int> const & GetSizes() const {
return _sizes;
}
@ -210,7 +210,7 @@ protected:
int _numControlVertices; // number of control vertices
std::vector<unsigned char> _sizes; // number of coeffiecient for each stencil
std::vector<int> _sizes; // number of coeffiecient for each stencil
std::vector<Index> _offsets, // offset to the start of each stencil
_indices; // indices of contributing coarse vertices
std::vector<float> _weights; // stencil weight coefficients
@ -235,7 +235,7 @@ public:
///
/// @param dvWeights Table pointer to the 'v' derivative weights
///
LimitStencil( unsigned char * size,
LimitStencil( int* size,
Index * indices,
float * weights,
float * duWeights,
@ -340,7 +340,7 @@ template <class T> void
StencilTables::update(T const *controlValues, T *values,
std::vector<float> const &valueWeights, Index start, Index end) const {
unsigned char const * sizes = &_sizes.at(0);
int const * sizes = &_sizes.at(0);
Index const * indices = &_indices.at(0);
float const * weights = &valueWeights.at(0);
@ -396,7 +396,7 @@ StencilTables::GetStencil(Index i) const {
Index ofs = _offsets[i];
return Stencil( const_cast<unsigned char *>(&_sizes[i]),
return Stencil( const_cast<int*>(&_sizes[i]),
const_cast<Index *>(&_indices[ofs]),
const_cast<float *>(&_weights[ofs]) );
}

View File

@ -230,7 +230,7 @@ StencilTablesFactory::Create(int numTables, StencilTables const ** tables) {
StencilTables * result = new StencilTables;
result->resize(nstencils, nelems);
unsigned char * sizes = &result->_sizes[0];
int * sizes = &result->_sizes[0];
Index * indices = &result->_indices[0];
float * weights = &result->_weights[0];
for (int i=0; i<numTables; ++i) {
@ -239,7 +239,7 @@ StencilTablesFactory::Create(int numTables, StencilTables const ** tables) {
int st_nstencils = st->GetNumStencils(),
st_nelems = (int)st->_indices.size();
memcpy(sizes, &st->_sizes[0], st_nstencils*sizeof(unsigned char));
memcpy(sizes, &st->_sizes[0], st_nstencils*sizeof(int));
memcpy(indices, &st->_indices[0], st_nelems*sizeof(Index));
memcpy(weights, &st->_weights[0], st_nelems*sizeof(float));
@ -366,13 +366,13 @@ StencilTablesFactory::AppendEndCapStencilTables(
result->resize(nBaseStencils + nEndCapStencils,
nBaseStencilsElements + nEndCapStencilsElements);
unsigned char * sizes = &result->_sizes[0];
int* sizes = &result->_sizes[0];
Index * indices = &result->_indices[0];
float * weights = &result->_weights[0];
// put base stencils first
memcpy(sizes, &baseStencilTables->_sizes[0],
nBaseStencils*sizeof(unsigned char));
nBaseStencils*sizeof(int));
memcpy(indices, &baseStencilTables->_indices[0],
nBaseStencilsElements*sizeof(Index));
memcpy(weights, &baseStencilTables->_weights[0],

View File

@ -57,7 +57,7 @@ __kernel void computeStencils(__global float * src,
int srcOffset,
__global float * dst,
int dstOffset,
__global unsigned char * sizes,
__global int * sizes,
__global int * offsets,
__global int * indices,
__global float * weights,
@ -73,7 +73,7 @@ __kernel void computeStencils(__global float * src,
struct Vertex v;
clear(&v);
int size = (int)sizes[current],
int size = sizes[current],
offset = offsets[current];
src += srcOffset;

View File

@ -38,7 +38,7 @@ CpuEvaluator::EvalStencils(const float *src,
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,
@ -63,7 +63,7 @@ CpuEvaluator::EvalStencils(const float *src,
VertexBufferDescriptor const &dstDuDesc,
float *dstDv,
VertexBufferDescriptor const &dstDvDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -113,7 +113,7 @@ public:
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,
@ -161,7 +161,7 @@ public:
VertexBufferDescriptor const &dstDuDesc,
float *dstDv,
VertexBufferDescriptor const &dstDvDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -74,7 +74,7 @@ CpuEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,
@ -94,7 +94,7 @@ CpuEvalStencils(float const * src,
if (srcDesc.length == 4 and dstDesc.length == 4 and
srcDesc.stride == 4 and dstDesc.stride == 4) {
// SIMD fast path for aligned primvar data (8 floats)
// SIMD fast path for aligned primvar data (4 floats)
ComputeStencilKernel<4>(src, dst,
sizes, indices, weights, start, end);
@ -133,7 +133,7 @@ CpuEvalStencils(float const * src,
VertexBufferDescriptor const &dstDuDesc,
float * dstDv,
VertexBufferDescriptor const &dstDvDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,

View File

@ -40,7 +40,7 @@ CpuEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,
@ -55,7 +55,7 @@ CpuEvalStencils(float const * src,
VertexBufferDescriptor const &dstDuDesc,
float * dstDv,
VertexBufferDescriptor const &dstDvDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,
@ -77,7 +77,7 @@ CpuEvalStencils(float const * src,
template <int numElems> void
ComputeStencilKernel(float const * vertexSrc,
float * vertexDst,
unsigned char const * sizes,
int const * sizes,
int const * indices,
float const * weights,
int start,

View File

@ -35,7 +35,7 @@ extern "C" {
int length,
int srcStride,
int dstStride,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,
@ -96,7 +96,7 @@ CudaEvaluator::EvalStencils(const float *src,
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -114,7 +114,7 @@ public:
srcDesc,
dstVertexBuffer->BindCudaBuffer(),
dstDesc,
(unsigned char const *)stencilTable->GetSizesBuffer(),
(int const *)stencilTable->GetSizesBuffer(),
(int const *)stencilTable->GetOffsetsBuffer(),
(int const *)stencilTable->GetIndicesBuffer(),
(float const *)stencilTable->GetWeightsBuffer(),
@ -126,7 +126,7 @@ public:
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -67,7 +67,7 @@ __device__ void addWithWeight(float *dst, float const *src, float weight, int co
template <int NUM_ELEMENTS> __global__ void
computeStencils(float const * cvs, float * vbuffer,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,
@ -101,7 +101,7 @@ computeStencils(float const * cvs, float * dst,
int length,
int srcStride,
int dstStride,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,
@ -134,7 +134,7 @@ computeStencils(float const * cvs, float * dst,
template< int NUM_ELEMENTS, int NUM_THREADS_PER_BLOCK >
__global__ void computeStencilsNv(float const *__restrict cvs,
float * vbuffer,
unsigned char const *__restrict sizes,
int const *__restrict sizes,
int const *__restrict offsets,
int const *__restrict indices,
float const *__restrict weights,
@ -205,7 +205,7 @@ __global__ void computeStencilsNv(float const *__restrict cvs,
template< int NUM_THREADS_PER_BLOCK >
__global__ void computeStencilsNv_v4(float const *__restrict cvs,
float * vbuffer,
unsigned char const *__restrict sizes,
int const *__restrict sizes,
int const *__restrict offsets,
int const *__restrict indices,
float const *__restrict weights,
@ -262,7 +262,7 @@ void CudaEvalStencils(const float *src,
int length,
int srcStride,
int dstStride,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -121,10 +121,7 @@ D3D11StencilTables::D3D11StencilTables(Far::StencilTables const *stencilTables,
_numStencils = stencilTables->GetNumStencils();
if (_numStencils > 0) {
// convert unsigned char sizes buffer to ints
// (HLSL does not have uint8 type)
std::vector<int> const sizes(stencilTables->GetSizes().begin(),
stencilTables->GetSizes().end());
std::vector<int> const &sizes = stencilTables->GetSizes();
_sizesBuffer = createBuffer(sizes, device);
_offsetsBuffer = createBuffer(stencilTables->GetOffsets(), device);

View File

@ -87,7 +87,7 @@ GLStencilTablesTBO::GLStencilTablesTBO(
_numStencils = stencilTables->GetNumStencils();
if (_numStencils > 0) {
_sizes = createGLTextureBuffer(stencilTables->GetSizes(), GL_R8UI);
_sizes = createGLTextureBuffer(stencilTables->GetSizes(), GL_R32UI);
_offsets = createGLTextureBuffer(
stencilTables->GetOffsets(), GL_R32I);
_indices = createGLTextureBuffer(

View File

@ -29,12 +29,12 @@ uniform int batchEnd = 0;
uniform int srcOffset = 0;
uniform int dstOffset = 0;
layout(binding=0) buffer src_buffer { float srcVertexBuffer[]; };
layout(binding=1) buffer dst_buffer { float dstVertexBuffer[]; };
layout(binding=2) buffer stencilSizes { unsigned char _sizes[]; };
layout(binding=3) buffer stencilOffsets { int _offsets[]; };
layout(binding=4) buffer stencilIndices { int _indices[]; };
layout(binding=5) buffer stencilWeights { float _weights[]; };
layout(binding=0) buffer src_buffer { float srcVertexBuffer[]; };
layout(binding=1) buffer dst_buffer { float dstVertexBuffer[]; };
layout(binding=2) buffer stencilSizes { int _sizes[]; };
layout(binding=3) buffer stencilOffsets { int _offsets[]; };
layout(binding=4) buffer stencilIndices { int _indices[]; };
layout(binding=5) buffer stencilWeights { float _weights[]; };
layout(local_size_x=WORK_GROUP_SIZE, local_size_y=1, local_size_z=1) in;
@ -85,7 +85,7 @@ void main() {
clear(dst);
int offset = _offsets[current],
size = int(_sizes[current]);
size = _sizes[current];
for (int i=0; i<size; ++i) {
addWithWeight(dst, readVertex( _indices[offset+i] ), _weights[offset+i]);

View File

@ -37,7 +37,7 @@ OmpEvaluator::EvalStencils(const float *src,
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -90,7 +90,7 @@ public:
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -77,7 +77,7 @@ OmpEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,

View File

@ -39,7 +39,7 @@ OmpEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,

View File

@ -38,7 +38,7 @@ TbbEvaluator::EvalStencils(const float *src,
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char * sizes,
const int * sizes,
const int * offsets,
const int * indices,
const float * weights,

View File

@ -88,7 +88,7 @@ public:
VertexBufferDescriptor const &srcDesc,
float *dst,
VertexBufferDescriptor const &dstDesc,
const unsigned char *sizes,
const int *sizes,
const int *offsets,
const int *indices,
const float *weights,

View File

@ -79,7 +79,7 @@ class TBBStencilKernel {
float const * _vertexSrc;
float * _vertexDst;
unsigned char const * _sizes;
int const * _sizes;
int const * _offsets,
* _indices;
float const * _weights;
@ -90,7 +90,7 @@ public:
VertexBufferDescriptor srcDesc,
float *dst,
VertexBufferDescriptor dstDesc,
unsigned char const * sizes, int const * offsets,
int const * sizes, int const * offsets,
int const * indices, float const * weights) :
_srcDesc(srcDesc),
_dstDesc(dstDesc),
@ -133,7 +133,7 @@ public:
#else
{
#endif
unsigned char const * sizes = _sizes;
int const * sizes = _sizes;
int const * indices = _indices;
float const * weights = _weights;
@ -165,7 +165,7 @@ TbbEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,

View File

@ -39,7 +39,7 @@ TbbEvalStencils(float const * src,
VertexBufferDescriptor const &srcDesc,
float * dst,
VertexBufferDescriptor const &dstDesc,
unsigned char const * sizes,
int const * sizes,
int const * offsets,
int const * indices,
float const * weights,