Loading...
Searching...
No Matches
pnanovdb_validate_strides.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
/*!
\file pnanovdb_validate_strides.h
\author Andrew Reidmeyer
\brief This header implements validation tests for the strides used
in PNanaoVDB.h (instead of pointers). It can be used both for
unit-testing (hence its location), but also to update PNanoVDB.h
if the ABI changes in NanoVDB.h.
*/
#ifndef NANOVDB_PNANOVDB_VALIDATE_STRIDES_H_HAS_BEEN_INCLUDED
#define NANOVDB_PNANOVDB_VALIDATE_STRIDES_H_HAS_BEEN_INCLUDED
#include <nanovdb/PNanoVDB.h>
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t* poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
{
if (alignment > 0u)
{
(*poffset) = alignment * (((*poffset) + (alignment - 1)) / alignment);
}
pnanovdb_uint32_t ret = (*poffset);
(*poffset) += size;
return ret;
}
static void compute_root_strides(
pnanovdb_uint32_t grid_type,
pnanovdb_uint32_t* background_off,
pnanovdb_uint32_t* min_off, pnanovdb_uint32_t* max_off,
pnanovdb_uint32_t* ave_off, pnanovdb_uint32_t* stddev_off,
pnanovdb_uint32_t* total_size)
{
pnanovdb_uint32_t offset = 0u;
allocate(&offset, PNANOVDB_ROOT_BASE_SIZE, 32u);
pnanovdb_uint32_t minmaxStride = pnanovdb_grid_type_minmax_strides_bits[grid_type] / 8u;
pnanovdb_uint32_t minmaxAlign = pnanovdb_grid_type_minmax_aligns_bits[grid_type] / 8u;
pnanovdb_uint32_t statStride = pnanovdb_grid_type_stat_strides_bits[grid_type] / 8u;
*background_off = allocate(&offset, minmaxStride, minmaxAlign);
*min_off = allocate(&offset, minmaxStride, minmaxAlign);
*max_off = allocate(&offset, minmaxStride, minmaxAlign);
*ave_off = allocate(&offset, statStride, statStride);
*stddev_off = allocate(&offset, statStride, statStride);
*total_size = allocate(&offset, 0u, 32u);
}
static void compute_tile_strides(pnanovdb_uint32_t grid_type, pnanovdb_uint32_t* value_off, pnanovdb_uint32_t* total_size)
{
pnanovdb_uint32_t offset = 0u;
allocate(&offset, PNANOVDB_ROOT_TILE_BASE_SIZE, 32u);
pnanovdb_uint32_t valueStride = pnanovdb_grid_type_minmax_strides_bits[grid_type] / 8u;
pnanovdb_uint32_t valueAlign = pnanovdb_grid_type_minmax_aligns_bits[grid_type] / 8u;
*value_off = allocate(&offset, valueStride, valueAlign);
*total_size = allocate(&offset, 0u, 32u);
}
static void compute_node_strides(
pnanovdb_uint32_t grid_type,
pnanovdb_uint32_t nodeLevel,
pnanovdb_uint32_t* min_off, pnanovdb_uint32_t* max_off,
pnanovdb_uint32_t* ave_off, pnanovdb_uint32_t* stddev_off,
pnanovdb_uint32_t* table_off,
pnanovdb_uint32_t* total_size)
{
static const pnanovdb_uint32_t node_size[3] = { PNANOVDB_LEAF_BASE_SIZE, PNANOVDB_LOWER_BASE_SIZE, PNANOVDB_UPPER_BASE_SIZE };
static const pnanovdb_uint32_t node_elements[3] = { PNANOVDB_LEAF_TABLE_COUNT, PNANOVDB_LOWER_TABLE_COUNT, PNANOVDB_UPPER_TABLE_COUNT };
pnanovdb_uint32_t offset = 0u;
allocate(&offset, node_size[nodeLevel], 32u);
pnanovdb_uint32_t valueStrideBits = pnanovdb_grid_type_value_strides_bits[grid_type];
pnanovdb_uint32_t tableStrideBits = nodeLevel == 0u ? valueStrideBits : pnanovdb_grid_type_table_strides_bits[grid_type];
pnanovdb_uint32_t tableAlign = 32u;
pnanovdb_uint32_t tableFullStride = (tableStrideBits * node_elements[nodeLevel]) / 8u;
pnanovdb_uint32_t minmaxStride = pnanovdb_grid_type_minmax_strides_bits[grid_type] / 8u;
pnanovdb_uint32_t minmaxAlign = pnanovdb_grid_type_minmax_aligns_bits[grid_type] / 8u;
pnanovdb_uint32_t statStride = pnanovdb_grid_type_stat_strides_bits[grid_type] / 8u;
pnanovdb_uint32_t indexMaskStride = 0u;
if (nodeLevel == 0u)
{
if (pnanovdb_grid_type_leaf_type[grid_type] == PNANOVDB_LEAF_TYPE_LITE)
{
minmaxStride = 0u;
minmaxAlign = 0u;
statStride = 0u;
}
else if (pnanovdb_grid_type_leaf_type[grid_type] == PNANOVDB_LEAF_TYPE_FP)
{
minmaxStride = 2u;
minmaxAlign = 2u;
statStride = 2u;
// allocate minimum and quantum
allocate(&offset, 4u, 4u);
allocate(&offset, 4u, 4u);
}
else if (pnanovdb_grid_type_leaf_type[grid_type] == PNANOVDB_LEAF_TYPE_INDEX)
{
minmaxStride = 0u;
minmaxAlign = 0u;
statStride = 0u;
tableAlign = 8u;
tableFullStride = 8u;
}
else if (pnanovdb_grid_type_leaf_type[grid_type] == PNANOVDB_LEAF_TYPE_INDEXMASK)
{
minmaxStride = 0u;
minmaxAlign = 0u;
statStride = 0u;
tableAlign = 8u;
tableFullStride = 8u;
indexMaskStride = 64u;
}
else if (pnanovdb_grid_type_leaf_type[grid_type] == PNANOVDB_LEAF_TYPE_POINTINDEX)
{
minmaxStride = 8u;
minmaxAlign = 8u;
statStride = 0u;
tableAlign = 2u;
tableFullStride = (16u * node_elements[nodeLevel]) / 8u;
}
}
*min_off = allocate(&offset, minmaxStride, minmaxAlign);
*max_off = allocate(&offset, minmaxStride, minmaxAlign);
*ave_off = allocate(&offset, statStride, statStride);
*stddev_off = allocate(&offset, statStride, statStride);
*table_off = allocate(&offset, tableFullStride, tableAlign);
allocate(&offset, indexMaskStride, tableAlign);
*total_size = allocate(&offset, 0u, 32u);
}
static bool validate_strides(int(*local_printf)(const char* format, ...))
{
pnanovdb_grid_type_constants_t constants[PNANOVDB_GRID_TYPE_END];
for (pnanovdb_uint32_t idx = 0u; idx < PNANOVDB_GRID_TYPE_END; idx++)
{
pnanovdb_uint32_t root_background, root_min, root_max, root_ave, root_stddev, root_size;
compute_root_strides(idx, &root_background, &root_min, &root_max, &root_ave, &root_stddev, &root_size);
pnanovdb_uint32_t tile_value, tile_size;
compute_tile_strides(idx, &tile_value, &tile_size);
pnanovdb_uint32_t upper_min, upper_max, upper_ave, upper_stddev, upper_table, upper_size;
compute_node_strides(idx, 2, &upper_min, &upper_max, &upper_ave, &upper_stddev, &upper_table, &upper_size);
pnanovdb_uint32_t lower_min, lower_max, lower_ave, lower_stddev, lower_table, lower_size;
compute_node_strides(idx, 1, &lower_min, &lower_max, &lower_ave, &lower_stddev, &lower_table, &lower_size);
pnanovdb_uint32_t leaf_min, leaf_max, leaf_ave, leaf_stddev, leaf_table, leaf_size;
compute_node_strides(idx, 0, &leaf_min, &leaf_max, &leaf_ave, &leaf_stddev, &leaf_table, &leaf_size);
pnanovdb_uint32_t valueStrideBits = pnanovdb_grid_type_value_strides_bits[idx];
pnanovdb_uint32_t tableStrideBits = pnanovdb_grid_type_table_strides_bits[idx];
pnanovdb_uint32_t tableStride = tableStrideBits / 8u;
// For FP, always return the base of the table
if (pnanovdb_grid_type_leaf_type[idx] == PNANOVDB_LEAF_TYPE_FP)
{
valueStrideBits = 0u;
}
pnanovdb_grid_type_constants_t local_constants = {
root_background, root_min, root_max, root_ave, root_stddev, root_size,
valueStrideBits, tableStride, tile_value, tile_size,
upper_min, upper_max, upper_ave, upper_stddev, upper_table, upper_size,
lower_min, lower_max, lower_ave, lower_stddev, lower_table, lower_size,
leaf_min, leaf_max, leaf_ave, leaf_stddev, leaf_table, leaf_size
};
constants[idx] = local_constants;
}
bool mismatch = false;
for (pnanovdb_uint32_t idx = 0u; idx < PNANOVDB_GRID_TYPE_END; idx++)
{
pnanovdb_grid_type_constants_t c = constants[idx];
pnanovdb_grid_type_constants_t t = pnanovdb_grid_type_constants[idx];
if (memcmp(&c, &t, sizeof(pnanovdb_grid_type_constants_t)) != 0)
{
mismatch = true;
}
}
if (mismatch)
{
local_printf("Error: Mismatch between constant tables.\n");
for (pnanovdb_uint32_t pass = 0u; pass < 2u; pass++)
{
if (pass == 0u)
{
local_printf("Printing expected values:\n");
}
else
{
local_printf("Printing current header values:\n");
}
for (pnanovdb_uint32_t idx = 0u; idx < PNANOVDB_GRID_TYPE_END; idx++)
{
pnanovdb_grid_type_constants_t c = (pass == 0u) ? constants[idx] : pnanovdb_grid_type_constants[idx];
local_printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d},\n",
c.root_off_background, c.root_off_min, c.root_off_max, c.root_off_ave, c.root_off_stddev, c.root_size,
c.value_stride_bits, c.table_stride, c.root_tile_off_value, c.root_tile_size,
c.upper_off_min, c.upper_off_max, c.upper_off_ave, c.upper_off_stddev, c.upper_off_table, c.upper_size,
c.lower_off_min, c.lower_off_max, c.lower_off_ave, c.lower_off_stddev, c.lower_off_table, c.lower_size,
c.leaf_off_min, c.leaf_off_max, c.leaf_off_ave, c.leaf_off_stddev, c.leaf_off_table, c.leaf_size
);
}
}
}
return !mismatch;
}
#endif// end of NANOVDB_PNANOVDB_VALIDATE_STRIDES_H_HAS_BEEN_INCLUDED
PNanoVDB.h
This file is a portable (e.g. pointer-less) C99/GLSL/HLSL port of NanoVDB.h, which is compatible with...
PNANOVDB_LEAF_TYPE_LITE
#define PNANOVDB_LEAF_TYPE_LITE
Definition PNanoVDB.h:984
pnanovdb_grid_type_leaf_type
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_leaf_type[26]
Definition PNanoVDB.h:1002
pnanovdb_grid_type_constants
PNANOVDB_STATIC_CONST pnanovdb_grid_type_constants_t pnanovdb_grid_type_constants[26]
Definition PNanoVDB.h:1637
PNANOVDB_LEAF_TYPE_INDEXMASK
#define PNANOVDB_LEAF_TYPE_INDEXMASK
Definition PNanoVDB.h:987
pnanovdb_grid_type_minmax_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_strides_bits[26]
Definition PNanoVDB.h:996
pnanovdb_grid_type_value_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_value_strides_bits[26]
Definition PNanoVDB.h:992
PNANOVDB_ROOT_BASE_SIZE
#define PNANOVDB_ROOT_BASE_SIZE
Definition PNanoVDB.h:1388
pnanovdb_grid_type_minmax_aligns_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_minmax_aligns_bits[26]
Definition PNanoVDB.h:998
PNANOVDB_LEAF_TYPE_FP
#define PNANOVDB_LEAF_TYPE_FP
Definition PNanoVDB.h:985
PNANOVDB_UPPER_BASE_SIZE
#define PNANOVDB_UPPER_BASE_SIZE
Definition PNanoVDB.h:1467
PNANOVDB_LOWER_BASE_SIZE
#define PNANOVDB_LOWER_BASE_SIZE
Definition PNanoVDB.h:1522
PNANOVDB_GRID_TYPE_END
#define PNANOVDB_GRID_TYPE_END
Definition PNanoVDB.h:961
PNANOVDB_LEAF_TYPE_INDEX
#define PNANOVDB_LEAF_TYPE_INDEX
Definition PNanoVDB.h:986
pnanovdb_grid_type_stat_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_stat_strides_bits[26]
Definition PNanoVDB.h:1000
PNANOVDB_ROOT_TILE_BASE_SIZE
#define PNANOVDB_ROOT_TILE_BASE_SIZE
Definition PNanoVDB.h:1426
pnanovdb_grid_type_table_strides_bits
PNANOVDB_STATIC_CONST pnanovdb_uint32_t pnanovdb_grid_type_table_strides_bits[26]
Definition PNanoVDB.h:994
PNANOVDB_LOWER_TABLE_COUNT
#define PNANOVDB_LOWER_TABLE_COUNT
Definition PNanoVDB.h:1521
PNANOVDB_LEAF_TABLE_COUNT
#define PNANOVDB_LEAF_TABLE_COUNT
Definition PNanoVDB.h:1574
PNANOVDB_UPPER_TABLE_COUNT
#define PNANOVDB_UPPER_TABLE_COUNT
Definition PNanoVDB.h:1466
PNANOVDB_LEAF_BASE_SIZE
#define PNANOVDB_LEAF_BASE_SIZE
Definition PNanoVDB.h:1575
PNANOVDB_LEAF_TYPE_POINTINDEX
#define PNANOVDB_LEAF_TYPE_POINTINDEX
Definition PNanoVDB.h:988
compute_root_strides
static void compute_root_strides(pnanovdb_uint32_t grid_type, pnanovdb_uint32_t *background_off, pnanovdb_uint32_t *min_off, pnanovdb_uint32_t *max_off, pnanovdb_uint32_t *ave_off, pnanovdb_uint32_t *stddev_off, pnanovdb_uint32_t *total_size)
Definition pnanovdb_validate_strides.h:31
compute_node_strides
static void compute_node_strides(pnanovdb_uint32_t grid_type, pnanovdb_uint32_t nodeLevel, pnanovdb_uint32_t *min_off, pnanovdb_uint32_t *max_off, pnanovdb_uint32_t *ave_off, pnanovdb_uint32_t *stddev_off, pnanovdb_uint32_t *table_off, pnanovdb_uint32_t *total_size)
Definition pnanovdb_validate_strides.h:65
allocate
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition pnanovdb_validate_strides.h:20
compute_tile_strides
static void compute_tile_strides(pnanovdb_uint32_t grid_type, pnanovdb_uint32_t *value_off, pnanovdb_uint32_t *total_size)
Definition pnanovdb_validate_strides.h:53
validate_strides
static bool validate_strides(int(*local_printf)(const char *format,...))
Definition pnanovdb_validate_strides.h:139
pnanovdb_grid_type_constants_t
Definition PNanoVDB.h:1604
pnanovdb_grid_type_constants_t::leaf_off_stddev
pnanovdb_uint32_t leaf_off_stddev
Definition PNanoVDB.h:1630
pnanovdb_grid_type_constants_t::leaf_off_ave
pnanovdb_uint32_t leaf_off_ave
Definition PNanoVDB.h:1629
pnanovdb_grid_type_constants_t::upper_off_min
pnanovdb_uint32_t upper_off_min
Definition PNanoVDB.h:1615
pnanovdb_grid_type_constants_t::leaf_size
pnanovdb_uint32_t leaf_size
Definition PNanoVDB.h:1632
pnanovdb_grid_type_constants_t::root_size
pnanovdb_uint32_t root_size
Definition PNanoVDB.h:1610
pnanovdb_grid_type_constants_t::leaf_off_table
pnanovdb_uint32_t leaf_off_table
Definition PNanoVDB.h:1631
pnanovdb_grid_type_constants_t::upper_off_max
pnanovdb_uint32_t upper_off_max
Definition PNanoVDB.h:1616
pnanovdb_grid_type_constants_t::upper_off_ave
pnanovdb_uint32_t upper_off_ave
Definition PNanoVDB.h:1617
pnanovdb_grid_type_constants_t::table_stride
pnanovdb_uint32_t table_stride
Definition PNanoVDB.h:1612
pnanovdb_grid_type_constants_t::upper_off_table
pnanovdb_uint32_t upper_off_table
Definition PNanoVDB.h:1619
pnanovdb_grid_type_constants_t::root_tile_size
pnanovdb_uint32_t root_tile_size
Definition PNanoVDB.h:1614
pnanovdb_grid_type_constants_t::leaf_off_min
pnanovdb_uint32_t leaf_off_min
Definition PNanoVDB.h:1627
pnanovdb_grid_type_constants_t::lower_size
pnanovdb_uint32_t lower_size
Definition PNanoVDB.h:1626
pnanovdb_grid_type_constants_t::lower_off_min
pnanovdb_uint32_t lower_off_min
Definition PNanoVDB.h:1621
pnanovdb_grid_type_constants_t::upper_size
pnanovdb_uint32_t upper_size
Definition PNanoVDB.h:1620
pnanovdb_grid_type_constants_t::value_stride_bits
pnanovdb_uint32_t value_stride_bits
Definition PNanoVDB.h:1611
pnanovdb_grid_type_constants_t::root_off_min
pnanovdb_uint32_t root_off_min
Definition PNanoVDB.h:1606
pnanovdb_grid_type_constants_t::root_tile_off_value
pnanovdb_uint32_t root_tile_off_value
Definition PNanoVDB.h:1613
pnanovdb_grid_type_constants_t::root_off_ave
pnanovdb_uint32_t root_off_ave
Definition PNanoVDB.h:1608
pnanovdb_grid_type_constants_t::lower_off_stddev
pnanovdb_uint32_t lower_off_stddev
Definition PNanoVDB.h:1624
pnanovdb_grid_type_constants_t::root_off_stddev
pnanovdb_uint32_t root_off_stddev
Definition PNanoVDB.h:1609
pnanovdb_grid_type_constants_t::root_off_background
pnanovdb_uint32_t root_off_background
Definition PNanoVDB.h:1605
pnanovdb_grid_type_constants_t::root_off_max
pnanovdb_uint32_t root_off_max
Definition PNanoVDB.h:1607
pnanovdb_grid_type_constants_t::lower_off_table
pnanovdb_uint32_t lower_off_table
Definition PNanoVDB.h:1625
pnanovdb_grid_type_constants_t::lower_off_max
pnanovdb_uint32_t lower_off_max
Definition PNanoVDB.h:1622
pnanovdb_grid_type_constants_t::leaf_off_max
pnanovdb_uint32_t leaf_off_max
Definition PNanoVDB.h:1628
pnanovdb_grid_type_constants_t::upper_off_stddev
pnanovdb_uint32_t upper_off_stddev
Definition PNanoVDB.h:1618
pnanovdb_grid_type_constants_t::lower_off_ave
pnanovdb_uint32_t lower_off_ave
Definition PNanoVDB.h:1623