Geometry Nodes: add simulation support #104924
|
@ -4,7 +4,7 @@
|
|||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_node_tree_zones.hh"
|
||||
|
||||
#include "BLI_bit_array_vector.hh"
|
||||
#include "BLI_bit_group_vector.hh"
|
||||
#include "BLI_bit_span_ops.hh"
|
||||
#include "BLI_task.hh"
|
||||
#include "BLI_timeit.hh"
|
||||
|
@ -55,7 +55,7 @@ struct ZoneRelation {
|
|||
|
||||
static Vector<ZoneRelation> get_direct_zone_relations(
|
||||
const Span<std::unique_ptr<TreeZone>> all_zones,
|
||||
const BitArrayVector<> &depend_on_input_flag_array)
|
||||
const BitGroupVector<> &depend_on_input_flag_array)
|
||||
{
|
||||
Vector<ZoneRelation> zone_relations;
|
||||
|
||||
|
@ -106,7 +106,7 @@ static Vector<ZoneRelation> get_direct_zone_relations(
|
|||
|
||||
static void update_parent_zone_per_node(const Span<const bNode *> all_nodes,
|
||||
const Span<std::unique_ptr<TreeZone>> all_zones,
|
||||
const BitArrayVector<> &depend_on_input_flag_array,
|
||||
const BitGroupVector<> &depend_on_input_flag_array,
|
||||
Map<int, int> &r_parent_zone_by_node_id)
|
||||
{
|
||||
for (const int node_i : all_nodes.index_range()) {
|
||||
|
@ -143,9 +143,9 @@ static std::unique_ptr<TreeZones> discover_tree_zones(const bNodeTree &tree)
|
|||
const int zones_num = tree_zones->zones.size();
|
||||
const int nodes_num = all_nodes.size();
|
||||
/* A bit for every node-zone-combination. The bit is set when the node is in the zone. */
|
||||
BitArrayVector<> depend_on_input_flag_array(nodes_num, zones_num, false);
|
||||
BitGroupVector<> depend_on_input_flag_array(nodes_num, zones_num, false);
|
||||
/* The bit is set when the node depends on the output of the zone. */
|
||||
BitArrayVector<> depend_on_output_flag_array(nodes_num, zones_num, false);
|
||||
BitGroupVector<> depend_on_output_flag_array(nodes_num, zones_num, false);
|
||||
|
||||
const Span<const bNode *> sorted_nodes = tree.toposort_left_to_right();
|
||||
for (const bNode *node : sorted_nodes) {
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_bit_vector.hh"
|
||||
|
||||
namespace blender::bits {
|
||||
|
||||
/**
|
||||
* A #BitArrayVector is a compact data structure that allows storing an arbitrary but fixed number
|
||||
* of bits per element. For example, it could be used to compactly store 5 bits per vertex in a
|
||||
* mesh. The data structure stores the bits in a way so that the #BitSpan for every element is
|
||||
* bounded according to #is_bounded_span. The makes sure that operations on entire groups can be
|
||||
* implemented efficiently. For example, one can easy `or` one group into another.
|
||||
*/
|
||||
template<int64_t InlineBufferCapacity = 64, typename Allocator = GuardedAllocator>
|
||||
class BitArrayVector {
|
||||
private:
|
||||
int64_t group_size_ = 0;
|
||||
int64_t aligned_group_size_ = 0;
|
||||
BitVector<InlineBufferCapacity, Allocator> data_;
|
||||
|
||||
static int64_t align_group_size(const int64_t group_size)
|
||||
{
|
||||
if (group_size < 64) {
|
||||
/* Align to next power of two so that a single group never spans across two ints. */
|
||||
return int64_t(power_of_2_max_u(uint32_t(group_size)));
|
||||
}
|
||||
/* Align to multiple of BitsPerInt. */
|
||||
return (group_size + BitsPerInt - 1) & ~(BitsPerInt - 1);
|
||||
}
|
||||
|
||||
public:
|
||||
BitArrayVector() = default;
|
||||
|
||||
BitArrayVector(const int64_t size_in_groups,
|
||||
const int64_t group_size,
|
||||
const bool value = false,
|
||||
Allocator allocator = {})
|
||||
: group_size_(group_size),
|
||||
aligned_group_size_(align_group_size(group_size)),
|
||||
data_(size_in_groups * aligned_group_size_, value, allocator)
|
||||
{
|
||||
BLI_assert(group_size >= 0);
|
||||
BLI_assert(size_in_groups >= 0);
|
||||
}
|
||||
|
||||
/** Get all the bits at an index. */
|
||||
BoundedBitSpan operator[](const int64_t i) const
|
||||
{
|
||||
const int64_t offset = aligned_group_size_ * i;
|
||||
return {data_.data() + (offset >> BitToIntIndexShift),
|
||||
IndexRange(offset & BitIndexMask, group_size_)};
|
||||
}
|
||||
|
||||
/** Get all the bits at an index. */
|
||||
MutableBoundedBitSpan operator[](const int64_t i)
|
||||
{
|
||||
const int64_t offset = aligned_group_size_ * i;
|
||||
return {data_.data() + (offset >> BitToIntIndexShift),
|
||||
IndexRange(offset & BitIndexMask, group_size_)};
|
||||
}
|
||||
|
||||
int64_t size() const
|
||||
{
|
||||
return aligned_group_size_ == 0 ? 0 : data_.size() / aligned_group_size_;
|
||||
}
|
||||
|
||||
int64_t group_size() const
|
||||
{
|
||||
return group_size_;
|
||||
}
|
||||
|
||||
IndexRange index_range() const
|
||||
{
|
||||
return IndexRange{this->size()};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blender::bits
|
||||
|
||||
namespace blender {
|
||||
using bits::BitArrayVector;
|
||||
}
|
|
@ -186,7 +186,6 @@ set(SRC
|
|||
BLI_bit_ref.hh
|
||||
BLI_bit_span.hh
|
||||
BLI_bit_span_ops.hh
|
||||
BLI_bit_array_vector.hh
|
||||
BLI_bit_vector.hh
|
||||
BLI_bitmap.h
|
||||
BLI_bitmap_draw_2d.h
|
||||
|
@ -483,7 +482,6 @@ if(WITH_GTESTS)
|
|||
tests/BLI_bit_group_vector_test.cc
|
||||
tests/BLI_bit_ref_test.cc
|
||||
tests/BLI_bit_span_test.cc
|
||||
tests/BLI_bit_array_vector_test.cc
|
||||
tests/BLI_bit_vector_test.cc
|
||||
tests/BLI_bitmap_test.cc
|
||||
tests/BLI_bounds_test.cc
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
#include "BLI_bit_array_vector.hh"
|
||||
#include "BLI_strict_flags.h"
|
||||
|
||||
#include "testing/testing.h"
|
||||
|
||||
namespace blender::bits::tests {
|
||||
|
||||
TEST(bit_array_vector, DefaultConstruct)
|
||||
{
|
||||
BitArrayVector<> groups;
|
||||
EXPECT_EQ(groups.size(), 0);
|
||||
}
|
||||
|
||||
TEST(bit_array_vector, Construct)
|
||||
{
|
||||
BitArrayVector<> groups(12, 5);
|
||||
|
||||
EXPECT_EQ(groups.size(), 12);
|
||||
EXPECT_EQ(groups[0].size(), 5);
|
||||
EXPECT_EQ(groups[4].size(), 5);
|
||||
}
|
||||
|
||||
} // namespace blender::bits::tests
|
Loading…
Reference in New Issue