Skip to content

Commit

Permalink
Merge pull request #44662 from reduz/bvh-use-page-allocator
Browse files Browse the repository at this point in the history
Use page allocator for BVH
  • Loading branch information
akien-mga authored Dec 25, 2020
2 parents af22325 + 2e66e5d commit ecffa43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/math/dynamic_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "dynamic_bvh.h"

void DynamicBVH::_delete_node(Node *p_node) {
memdelete(p_node);
node_allocator.free(p_node);
}

void DynamicBVH::_recurse_delete_node(Node *p_node) {
Expand All @@ -46,7 +46,7 @@ void DynamicBVH::_recurse_delete_node(Node *p_node) {
}

DynamicBVH::Node *DynamicBVH::_create_node(Node *p_parent, void *p_data) {
Node *node = memnew(Node);
Node *node = node_allocator.alloc();
node->parent = p_parent;
node->data = p_data;
return (node);
Expand Down
2 changes: 2 additions & 0 deletions core/math/dynamic_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/math/aabb.h"
#include "core/templates/list.h"
#include "core/templates/local_vector.h"
#include "core/templates/paged_allocator.h"
#include "core/typedefs.h"

// Based on bullet Dbvh
Expand Down Expand Up @@ -217,6 +218,7 @@ class DynamicBVH {
}
};

PagedAllocator<Node> node_allocator;
// Fields
Node *bvh_root = nullptr;
int lkhd = -1;
Expand Down
6 changes: 3 additions & 3 deletions core/templates/paged_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ class PagedAllocator {
return page_size > 0;
}

void configure(uint32_t p_page_size, bool p_thread_safe) {
void configure(uint32_t p_page_size) {
ERR_FAIL_COND(page_pool != nullptr); //sanity check
ERR_FAIL_COND(p_page_size == 0);
page_size = nearest_power_of_2_templated(p_page_size);
page_mask = page_size - 1;
page_shift = get_shift_from_power_of_2(page_size);
}

PagedAllocator(uint32_t p_page_size = 4096, bool p_thread_safe = false) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages
configure(p_page_size, false);
PagedAllocator(uint32_t p_page_size = 4096) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages
configure(p_page_size);
}

~PagedAllocator() {
Expand Down

0 comments on commit ecffa43

Please sign in to comment.