Skip to content

Commit a103e23

Browse files
committed
spatialorder: Rename spatialSortPoints to spatialClusterPoints
This underscores the fact that we don't sort individual points within each cluster (currently) and that the output is aligned to cluster boundaries. Also fix overallocated order[] buffer after a previous refactoring.
1 parent 41061f4 commit a103e23

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/meshoptimizer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,14 @@ MESHOPTIMIZER_API void meshopt_spatialSortRemap(unsigned int* destination, const
715715
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortTriangles(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
716716

717717
/**
718-
* Experimental: Spatial sorter
719-
* Reorders points for spatial locality, and generates a new index buffer.
720-
* Ensures the output can be split into block_size chunks where each chunk has good positional locality.
718+
* Experimental: Spatial clusterizer
719+
* Reorders points into clusters optimized for spatial locality, and generates a new index buffer.
720+
* Ensures the output can be split into cluster_size chunks where each chunk has good positional locality. Only the last chunk will be smaller than cluster_size.
721721
*
722722
* destination must contain enough space for the resulting index buffer (vertex_count elements)
723723
* vertex_positions should have float3 position in the first 12 bytes of each vertex
724-
* chunk_size ??
725724
*/
726-
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t chunk_size);
725+
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialClusterPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t cluster_size);
727726

728727
/**
729728
* Quantize a float into half-precision (as defined by IEEE-754 fp16) floating point value

src/spatialorder.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ static void partitionPoints(unsigned int* target, const unsigned int* order, con
155155
assert(l == split && r == count);
156156
}
157157

158-
static void splitPoints(unsigned int* destination, unsigned int* orderx, unsigned int* ordery, unsigned int* orderz, const unsigned long long* keys, size_t count, void* scratch, size_t chunk_size)
158+
static void splitPoints(unsigned int* destination, unsigned int* orderx, unsigned int* ordery, unsigned int* orderz, const unsigned long long* keys, size_t count, void* scratch, size_t cluster_size)
159159
{
160-
if (count <= chunk_size)
160+
if (count <= cluster_size)
161161
{
162162
memcpy(destination, orderx, count * sizeof(unsigned int));
163163
return;
@@ -182,8 +182,8 @@ static void splitPoints(unsigned int* destination, unsigned int* orderx, unsigne
182182

183183
assert(bestk >= 0);
184184

185-
// split roughly in half, with the left split always being aligned to chunk size
186-
size_t split = ((count / 2) + chunk_size - 1) / chunk_size * chunk_size;
185+
// split roughly in half, with the left split always being aligned to cluster size
186+
size_t split = ((count / 2) + cluster_size - 1) / cluster_size * cluster_size;
187187
assert(split > 0 && split < count);
188188

189189
// mark sides of split for partitioning
@@ -208,8 +208,8 @@ static void splitPoints(unsigned int* destination, unsigned int* orderx, unsigne
208208
partitionPoints(axis, temp, sides, split, count);
209209
}
210210

211-
splitPoints(destination, orderx, ordery, orderz, keys, split, scratch, chunk_size);
212-
splitPoints(destination + split, orderx + split, ordery + split, orderz + split, keys, count - split, scratch, chunk_size);
211+
splitPoints(destination, orderx, ordery, orderz, keys, split, scratch, cluster_size);
212+
splitPoints(destination + split, orderx + split, ordery + split, orderz + split, keys, count - split, scratch, cluster_size);
213213
}
214214

215215
} // namespace meshopt
@@ -303,20 +303,20 @@ void meshopt_spatialSortTriangles(unsigned int* destination, const unsigned int*
303303
}
304304
}
305305

306-
void meshopt_spatialSortPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t chunk_size)
306+
void meshopt_spatialClusterPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t cluster_size)
307307
{
308308
using namespace meshopt;
309309

310310
assert(vertex_positions_stride >= 12 && vertex_positions_stride <= 256);
311311
assert(vertex_positions_stride % sizeof(float) == 0);
312-
assert(chunk_size > 0);
312+
assert(cluster_size > 0);
313313

314314
meshopt_Allocator allocator;
315315

316316
unsigned long long* keys = allocator.allocate<unsigned long long>(vertex_count);
317317
computeOrder(keys, vertex_positions, vertex_count, vertex_positions_stride, /* morton= */ false);
318318

319-
unsigned int* order = allocator.allocate<unsigned int>(vertex_count * 5);
319+
unsigned int* order = allocator.allocate<unsigned int>(vertex_count * 3);
320320
unsigned int* scratch = allocator.allocate<unsigned int>(vertex_count * 2); // 4b for order + 1b for side or 2b for keys
321321
unsigned short* keyk = reinterpret_cast<unsigned short*>(scratch + vertex_count);
322322

@@ -336,5 +336,5 @@ void meshopt_spatialSortPoints(unsigned int* destination, const float* vertex_po
336336
radixPass(order + k * vertex_count, scratch, keyk, vertex_count, hist, 1);
337337
}
338338

339-
splitPoints(destination, order, order + vertex_count, order + 2 * vertex_count, keys, vertex_count, scratch, chunk_size);
339+
splitPoints(destination, order, order + vertex_count, order + 2 * vertex_count, keys, vertex_count, scratch, cluster_size);
340340
}

0 commit comments

Comments
 (0)