Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
81 lines
2.6 KiB
C++
81 lines
2.6 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_array_utils.hh"
|
|
#include "BLI_offset_indices.hh"
|
|
#include "BLI_task.hh"
|
|
|
|
namespace blender::offset_indices {
|
|
|
|
OffsetIndices<int> accumulate_counts_to_offsets(MutableSpan<int> counts_to_offsets,
|
|
const int start_offset)
|
|
{
|
|
int offset = start_offset;
|
|
for (const int i : counts_to_offsets.index_range().drop_back(1)) {
|
|
const int count = counts_to_offsets[i];
|
|
BLI_assert(count >= 0);
|
|
counts_to_offsets[i] = offset;
|
|
offset += count;
|
|
}
|
|
counts_to_offsets.last() = offset;
|
|
return OffsetIndices<int>(counts_to_offsets);
|
|
}
|
|
|
|
void fill_constant_group_size(const int size, const int start_offset, MutableSpan<int> offsets)
|
|
{
|
|
threading::parallel_for(offsets.index_range(), 1024, [&](const IndexRange range) {
|
|
for (const int64_t i : range) {
|
|
offsets[i] = size * i + start_offset;
|
|
}
|
|
});
|
|
}
|
|
|
|
void copy_group_sizes(const OffsetIndices<int> offsets,
|
|
const IndexMask &mask,
|
|
MutableSpan<int> sizes)
|
|
{
|
|
mask.foreach_index_optimized<int64_t>(GrainSize(4096),
|
|
[&](const int64_t i) { sizes[i] = offsets[i].size(); });
|
|
}
|
|
|
|
void gather_group_sizes(const OffsetIndices<int> offsets,
|
|
const IndexMask &mask,
|
|
MutableSpan<int> sizes)
|
|
{
|
|
mask.foreach_index_optimized<int64_t>(GrainSize(4096), [&](const int64_t i, const int64_t pos) {
|
|
sizes[pos] = offsets[i].size();
|
|
});
|
|
}
|
|
|
|
OffsetIndices<int> gather_selected_offsets(const OffsetIndices<int> src_offsets,
|
|
const IndexMask &selection,
|
|
MutableSpan<int> dst_offsets)
|
|
{
|
|
if (selection.is_empty()) {
|
|
return {};
|
|
}
|
|
BLI_assert(selection.size() == (dst_offsets.size() - 1));
|
|
gather_group_sizes(src_offsets, selection, dst_offsets);
|
|
accumulate_counts_to_offsets(dst_offsets);
|
|
return OffsetIndices<int>(dst_offsets);
|
|
}
|
|
|
|
void build_reverse_map(OffsetIndices<int> offsets, MutableSpan<int> r_map)
|
|
{
|
|
threading::parallel_for(offsets.index_range(), 1024, [&](const IndexRange range) {
|
|
for (const int64_t i : range) {
|
|
r_map.slice(offsets[i]).fill(i);
|
|
}
|
|
});
|
|
}
|
|
|
|
void build_reverse_offsets(const Span<int> indices, MutableSpan<int> offsets)
|
|
{
|
|
BLI_assert(std::all_of(offsets.begin(), offsets.end(), [](int value) { return value == 0; }));
|
|
array_utils::count_indices(indices, offsets);
|
|
offset_indices::accumulate_counts_to_offsets(offsets);
|
|
}
|
|
|
|
} // namespace blender::offset_indices
|