22#define NANOVDB_USE_SINGLE_ROOT_KEY
23#define NANOVDB_DATA_ALIGNMENT 32
29template<
typename DstT,
typename SrcT>
43template<u
int32_t LOG2DIM>
struct Mask {
56template<
typename TreeT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
Grid {
78 return *
reinterpret_cast<const ccl_global TreeT *
>(
this + 1);
84template<
typename RootT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
Tree {
95 return *
reinterpret_cast<const ccl_global RootT *
>(
102template<
typename ChildT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
RootNode {
106#ifdef NANOVDB_USE_SINGLE_ROOT_KEY
110 return (
uint64_t(uint32_t(ijk.
z) >> ChildT::TOTAL)) |
111 (
uint64_t(uint32_t(ijk.
y) >> ChildT::TOTAL) << 21) |
112 (
uint64_t(uint32_t(ijk.
x) >> ChildT::TOTAL) << 42);
118 return ijk & ~ChildT
::MASK;
130 struct alignas(NANOVDB_DATA_ALIGNMENT)
Tile {
161template<
typename ChildT, const u
int32_t Log2Dim = ChildT::LOG2DIM + 1>
181 alignas(32) Tile
mTable[1u << (3 * Log2Dim)];
197 return (((ijk.
x &
MASK) >> ChildT::TOTAL) << (2 *
LOG2DIM)) |
198 (((ijk.
y &
MASK) >> ChildT::TOTAL) << (
LOG2DIM)) | ((ijk.
z &
MASK) >> ChildT::TOTAL);
204template<
typename ValueT, const u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData {
227template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafFnBase {
242template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData<
Fp16, LOG2DIM> {
247 alignas(32) uint16_t
mCode[1u << 3 * LOG2DIM];
259template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData<
FpN, LOG2DIM> {
267 const int b =
base.mFlags >> 5;
268 uint32_t code =
reinterpret_cast<const ccl_global uint32_t *
>(
this + 1)[
i >> (5 -
b)];
269 code >>= (
i & ((32 >>
b) - 1)) <<
b;
270 code &= (1 << (1 <<
b)) - 1;
277template<
typename BuildT, const u
int32_t Log2Dim = 3>
299 return data.getValue(offset);
333 if (
tile ==
nullptr) {
334 return mRoot->mBackground;
336 if (
tile->child == 0) {
341 const uint32_t upper_n = upper->CoordToOffset(ijk);
342 if (upper->mChildMask.isOff(upper_n)) {
343 return upper->mTable[upper_n].value;
346 const ccl_global auto *lower = upper->getChild(upper_n);
347 const uint32_t lower_n = lower->CoordToOffset(ijk);
348 if (lower->mChildMask.isOff(lower_n)) {
349 return lower->mTable[lower_n].value;
352 const ccl_global LeafT *leaf = lower->getChild(lower_n);
353 return leaf->getValue(ijk);
364 mutable const ccl_global RootT *mRoot =
nullptr;
365 mutable const ccl_global void *mNode[3] = {
nullptr,
nullptr,
nullptr};
374 return (ijk.
x &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].x &&
375 (ijk.
y &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].
y &&
376 (ijk.
z &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].z;
380 const Coord ijk)
const
383 if (
tile->child != 0) {
390 return node.mBackground;
394 const Coord ijk)
const
396 return node.getValue(ijk);
399 template<
typename NodeT>
401 const Coord ijk)
const
403 const uint32_t n = node.CoordToOffset(ijk);
404 if (node.mChildMask.isOff(n)) {
405 return node.mTable[n].value;
407 const ccl_global auto *child = node.getChild(n);
426 template<
typename NodeT>
429 mKeys[NodeT::LEVEL] = ijk & ~NodeT
::MASK;
430 mNode[NodeT::LEVEL] = node;
void BLI_kdtree_nd_ insert(KDTree *tree, int index, const float co[KD_DIMS]) ATTR_NONNULL(1
unsigned long long int uint64_t
typename RootT::ValueType ValueType
ccl_device_inline_method ValueType getValueAndCache(const ccl_global RootT &node, const Coord ijk) const
ccl_device_inline_method ValueType getValueAndCache(const ccl_global LeafT &node, const Coord ijk) const
ccl_device_inline_method CachedReadAccessor(const ccl_global RootT &root)
ccl_device_inline_method bool isCached(const Coord ijk) const
ccl_device_inline_method void insert(const Coord ijk, const ccl_global NodeT *node) const
ccl_device_inline_method ValueType getValue(const Coord ijk) const
ccl_device_inline_method ValueType getValueAndCache(const ccl_global NodeT &node, const Coord ijk) const
typename RootT::ValueType ValueType
ccl_device_inline_method ValueType getValue(const Coord ijk) const
ccl_device_inline_method ReadAccessor(const ccl_global RootT &root)
#define ccl_static_constexpr
#define ccl_device_inline_method
#define CCL_NAMESPACE_END
const ccl_global KernelWorkTile * tile
const ccl_device ccl_global DstT * PtrAdd(const ccl_global SrcT *p, int64_t offset)
LeafNode< BuildT, 3 > NanoLeaf
InternalNode< NanoLeaf< BuildT >, 4 > NanoLower
InternalNode< NanoLower< BuildT >, 5 > NanoUpper
Grid< NanoTree< BuildT > > NanoGrid
RootNode< NanoUpper< BuildT > > NanoRoot
Tree< NanoRoot< BuildT > > NanoTree
const ccl_device_inline_method ccl_global TreeT & tree() const ccl_global
typename TreeT::BuildType BuildType
ccl_static_constexpr int MaxNameSize
char mGridName[MaxNameSize]
const ccl_device_inline_method ccl_global NanoLeaf< BuildT > * getChild(const uint32_t n) const ccl_global
ccl_static_constexpr uint32_t MASK
Mask< Log2Dim > mValueMask
ccl_static_constexpr uint32_t LEVEL
typename ChildT::ValueType ValueType
ccl_static_constexpr uint32_t SIZE
Mask< Log2Dim > mChildMask
static ccl_device_inline_method uint32_t CoordToOffset(const Coord ijk)
ccl_static_constexpr uint32_t LOG2DIM
Tile mTable[1u<<(3 *Log2Dim)]
ccl_static_constexpr uint32_t TOTAL
typename ChildT::BuildType BuildType
ccl_static_constexpr uint32_t DIM
ccl_device_inline_method float getValue(const uint32_t i) const ccl_global
LeafFnBase< LOG2DIM > base
uint16_t mCode[1u<< 3 *LOG2DIM]
ccl_device_inline_method float getValue(const uint32_t i) const ccl_global
LeafFnBase< LOG2DIM > base
ValueType mValues[1u<< 3 *LOG2DIM]
ccl_device_inline_method ValueType getValue(const uint32_t i) const ccl_global
Mask< LOG2DIM > mValueMask
Mask< LOG2DIM > mValueMask
ccl_static_constexpr uint32_t DIM
ccl_static_constexpr uint32_t LOG2DIM
ccl_static_constexpr uint32_t TOTAL
typename DataType::BuildType BuildType
ccl_static_constexpr uint32_t MASK
LeafData< BuildT, Log2Dim > DataType
ccl_static_constexpr uint32_t SIZE
typename DataType::ValueType ValueType
ccl_static_constexpr uint32_t LEVEL
static ccl_device_inline_method uint32_t CoordToOffset(const Coord ijk)
ccl_device_inline_method ValueType getValue(const Coord ijk) const ccl_global
ccl_device_inline_method ValueType getValue(const uint32_t offset) const ccl_global
ccl_device_inline_method bool isOff(const uint32_t n) const ccl_global
ccl_static_constexpr uint32_t SIZE
ccl_static_constexpr uint32_t WORD_COUNT
uint64_t mWords[WORD_COUNT]
static ccl_device_inline_method uint64_t CoordToKey(const Coord ijk)
typename ChildT::ValueType ValueType
typename ChildT::BuildType BuildType
const ccl_device_inline_method ccl_global NanoUpper< BuildT > * getChild(const ccl_global Tile *tile) const ccl_global
const ccl_device_inline_method ccl_global Tile * probeTile(const Coord ijk) const ccl_global
ccl_static_constexpr uint32_t LEVEL
const ccl_device_inline_method ccl_global RootT & root() const ccl_global
typename RootT::ValueType ValueType
typename RootT::BuildType BuildType