20#define NANOVDB_USE_SINGLE_ROOT_KEY
21#define NANOVDB_DATA_ALIGNMENT 32
27template<
typename DstT,
typename SrcT>
50template<u
int32_t LOG2DIM>
struct Mask {
63template<
typename TreeT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
Grid {
85 return *
reinterpret_cast<const ccl_global TreeT *
>(
this + 1);
91template<
typename RootT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
Tree {
102 return *
reinterpret_cast<const ccl_global RootT *
>(
109template<
typename ChildT>
struct alignas(NANOVDB_DATA_ALIGNMENT)
RootNode {
113#ifdef NANOVDB_USE_SINGLE_ROOT_KEY
117 return (
uint64_t(uint32_t(ijk.
z) >> ChildT::TOTAL)) |
118 (
uint64_t(uint32_t(ijk.
y) >> ChildT::TOTAL) << 21) |
119 (
uint64_t(uint32_t(ijk.
x) >> ChildT::TOTAL) << 42);
125 return ijk & ~ChildT
::MASK;
137 struct alignas(NANOVDB_DATA_ALIGNMENT)
Tile {
168template<
typename ChildT, const u
int32_t Log2Dim = ChildT::LOG2DIM + 1>
188 alignas(32) Tile
mTable[1u << (3 * Log2Dim)];
204 return (((ijk.
x &
MASK) >> ChildT::TOTAL) << (2 *
LOG2DIM)) |
205 (((ijk.
y &
MASK) >> ChildT::TOTAL) << (
LOG2DIM)) | ((ijk.
z &
MASK) >> ChildT::TOTAL);
211template<
typename ValueT, const u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData {
234template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafFnBase {
249template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData<
Fp16, LOG2DIM> {
254 alignas(32) uint16_t
mCode[1u << 3 * LOG2DIM];
266template<u
int32_t LOG2DIM>
struct alignas(NANOVDB_DATA_ALIGNMENT)
LeafData<
FpN, LOG2DIM> {
274 const int b =
base.mFlags >> 5;
275 uint32_t code =
reinterpret_cast<const ccl_global uint32_t *
>(
this + 1)[
i >> (5 -
b)];
276 code >>= (
i & ((32 >>
b) - 1)) <<
b;
277 code &= (1 << (1 <<
b)) - 1;
278 return float(code) *
base.mQuantum +
base.mMinimum;
284template<
typename BuildT, const u
int32_t Log2Dim = 3>
306 return data.getValue(offset);
340 if (
tile ==
nullptr) {
341 return mRoot->mBackground;
343 if (
tile->child == 0) {
348 const uint32_t upper_n = upper->CoordToOffset(ijk);
349 if (upper->mChildMask.isOff(upper_n)) {
350 return upper->mTable[upper_n].value;
353 const ccl_global auto *lower = upper->getChild(upper_n);
354 const uint32_t lower_n = lower->CoordToOffset(ijk);
355 if (lower->mChildMask.isOff(lower_n)) {
356 return lower->mTable[lower_n].value;
359 const ccl_global LeafT *leaf = lower->getChild(lower_n);
360 return leaf->getValue(ijk);
371 mutable const ccl_global RootT *mRoot =
nullptr;
372 mutable const ccl_global void *mNode[3] = {
nullptr,
nullptr,
nullptr};
381 return (ijk.
x &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].x &&
382 (ijk.
y &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].
y &&
383 (ijk.
z &
int32_t(~NodeT::MASK)) == mKeys[NodeT::LEVEL].z;
387 const Coord ijk)
const
390 if (
tile->child != 0) {
397 return node.mBackground;
401 const Coord ijk)
const
403 return node.getValue(ijk);
406 template<
typename NodeT>
408 const Coord ijk)
const
410 const uint32_t n = node.CoordToOffset(ijk);
411 if (node.mChildMask.isOff(n)) {
412 return node.mTable[n].value;
414 const ccl_global auto *child = node.getChild(n);
433 template<
typename NodeT>
436 mKeys[NodeT::LEVEL] = ijk & ~NodeT
::MASK;
437 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
ccl_device_inline_method Coord operator&(int32_t n) const
ccl_device_inline_method Coord(int32_t x, int32_t y, int32_t z)
ccl_device_inline_method Coord(int32_t n)
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