Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version History
- Ship all release packages with OpenVDB
- Set DEPENDENTLOADFLAG also on the Windows binaries built with Clang/SYCL
- Fix linking applications against the GPU device module on Windows
- Fix VDB recommit and observer registry issues
- Update to latest versions of dependencies (compiling the tests now
needs CMake v3.16 and C++14)

Expand Down
4 changes: 4 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,10 @@ so that the observer may be mapped again.

When an observer is no longer needed, it should be released using `vklRelease`.

Observers are tied to the state of the observed volume at the time the observer
was created. Before committing a volume again, release all observers of that
volume and of its samplers; create new observers after the commit as needed.

The observer API is not thread safe, and these functions should not
be called concurrently on the same object.

Expand Down
2 changes: 1 addition & 1 deletion openvkl/devices/cpu/iterator/UnstructuredIterator.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static box1f evalNodeStacklessV(const varying UnstructuredIterator *uniform
iterator->super.super.context->super.sampler;

while (1) {
uniform bool isInner = (node->nominalLength.x >= 0);
uniform bool isInner = !isLeafNode(node);

if (isInner &&
(elementaryCellIteration ||
Expand Down
4 changes: 2 additions & 2 deletions openvkl/devices/cpu/observer/ObserverRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace openvkl {
}

template <int W>
void ObserverRegistry<W>::add(void *ptr)
void ObserverRegistry<W>::add(void *ptr, size_t numElements)
{
std::lock_guard<std::recursive_mutex> g(mtx);
CALL_ISPC(ObserverRegistry_add, ispcEquivalent, ptr);
CALL_ISPC(ObserverRegistry_add, ispcEquivalent, ptr, numElements);
}

template <int W>
Expand Down
2 changes: 1 addition & 1 deletion openvkl/devices/cpu/observer/ObserverRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace openvkl {
ObserverRegistry(ObserverRegistry &&other) = delete;
ObserverRegistry &operator=(ObserverRegistry &&other) = delete;

void add(void *ptr);
void add(void *ptr, size_t numElements);

void remove(void *ptr);

Expand Down
1 change: 1 addition & 0 deletions openvkl/devices/cpu/observer/ObserverRegistry.ih
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ struct ObserverRegistry
size_t size;
size_t capacity;
void *uniform *uniform data;
size_t *uniform numElements; // per data entry
};
34 changes: 24 additions & 10 deletions openvkl/devices/cpu/observer/ObserverRegistry.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export void *uniform EXPORT_UNIQUE(ObserverRegistry_create)
self->size = 0;
self->capacity = 0;
self->data = NULL;
self->numElements = NULL;
return self;
}

Expand All @@ -21,13 +22,16 @@ export void EXPORT_UNIQUE(ObserverRegistry_destroy, void *uniform _self)
assert(_self);
ObserverRegistry *uniform self = ((ObserverRegistry * uniform) _self);
if (self->data)
delete self->data;
delete[] self->data;
if (self->numElements)
delete[] self->numElements;
delete self;
}

export void EXPORT_UNIQUE(ObserverRegistry_add,
void *uniform _self,
void *uniform ptr)
void *uniform ptr,
uniform size_t numElements)
{
assert(_self);
ObserverRegistry *uniform self = ((ObserverRegistry * uniform) _self);
Expand All @@ -40,23 +44,31 @@ export void EXPORT_UNIQUE(ObserverRegistry_add,
assert(self->size <= self->capacity);
if (self->size >= self->capacity) {
void *uniform *uniform oldData = self->data;
size_t *uniform oldNumElements = self->numElements;
const uniform size_t newCapacity = self->capacity + 1;
// ISPC seems to not be able to parse
// uniform new void *uniform [...]
// directly.
typedef void *uniform VoidPtr;
self->data = uniform new uniform VoidPtr[newCapacity];
self->capacity = newCapacity;
self->data = uniform new uniform VoidPtr[newCapacity];
self->numElements = uniform new uniform size_t[newCapacity];
self->capacity = newCapacity;
if (oldData) {
if (self->size > 0)
if (self->size > 0) {
memcpy(self->data, oldData, sizeof(void *uniform) * self->size);
delete oldData;
memcpy(self->numElements,
oldNumElements,
sizeof(uniform size_t) * self->size);
}
delete[] oldData;
delete[] oldNumElements;
} else
assert(self->capacity == 1);
}

self->data[self->size] = ptr;
self->size = self->size + 1;
self->data[self->size] = ptr;
self->numElements[self->size] = numElements;
self->size = self->size + 1;
}

export void EXPORT_UNIQUE(ObserverRegistry_remove,
Expand All @@ -67,9 +79,11 @@ export void EXPORT_UNIQUE(ObserverRegistry_remove,
ObserverRegistry *uniform self = ((ObserverRegistry * uniform) _self);
for (uniform size_t i = 0; i < self->size; ++i) {
if (self->data[i] == ptr) {
self->data[i] = self->data[self->size];
self->size = self->size - 1;
// Like std::vector, we never decrease capacity.
self->size = self->size - 1;
self->data[i] = self->data[self->size];
self->numElements[i] = self->numElements[self->size];
return;
}
}
}
2 changes: 0 additions & 2 deletions openvkl/devices/cpu/sampler/Sampler.ih
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export void EXPORT_UNIQUE(Sampler_create,
const void *uniform _volume,
void *uniform _sampler);

export void EXPORT_UNIQUE(Sampler_destroy, void *uniform _sampler);

export void EXPORT_UNIQUE(Sampler_setFilters,
void *uniform _sampler,
uniform VKLFilter filter,
Expand Down
7 changes: 0 additions & 7 deletions openvkl/devices/cpu/sampler/Sampler.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ export void EXPORT_UNIQUE(Sampler_setFilters,
Sampler_setFiltersInternal(sampler, filter, gradientFilter);
}

export void EXPORT_UNIQUE(Sampler_destroy,
void *uniform _sampler)
{
SamplerShared *uniform sampler = (SamplerShared *uniform)_sampler;
delete sampler;
}

// these functions do not yet support multi-attribute or time-varying volumes.

export void EXPORT_UNIQUE(Sampler_sample_N_export,
Expand Down
9 changes: 5 additions & 4 deletions openvkl/devices/cpu/volume/UnstructuredBVH.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <algorithm>
#include <cmath>
#include <mutex>
#include <vector>
#include "../../common/BufferShared.h"
Expand Down Expand Up @@ -150,7 +151,7 @@ namespace openvkl {

struct Node
{
vec3f nominalLength; // x set to negative for LeafNode;
vec3f nominalLength; // sign bit of x set => leaf (incl. -0)
range1f valueRange;
int level;
Node *parent;
Expand Down Expand Up @@ -276,14 +277,14 @@ namespace openvkl {

inline bool isLeafNode(const Node *node)
{
return (node->nominalLength.x < 0);
return (std::signbit)(node->nominalLength.x);
}

inline void addLevelToNodes(Node *root, int level)
{
root->level = level;

if (root->nominalLength.x > 0) {
if (!isLeafNode(root)) {
auto inner = (InnerNode *)root;

addLevelToNodes(inner->children[0], level + 1);
Expand All @@ -293,7 +294,7 @@ namespace openvkl {

inline int getMaxNodeLevel(Node *root)
{
if (root->nominalLength.x > 0) {
if (!isLeafNode(root)) {
auto inner = (InnerNode *)root;
return std::max(getMaxNodeLevel(inner->children[0]),
getMaxNodeLevel(inner->children[1]));
Expand Down
22 changes: 22 additions & 0 deletions openvkl/devices/cpu/volume/UnstructuredBVH.ih
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "rkcommon/math/math.ih"
#include "UnstructuredVolumeBaseShared.h"

#ifndef ISPC
namespace ispc {
#endif

// leaf iff sign bit of nominalLength.x set (incl. -0, missed by < 0)
inline VKL_INTEROP_UNIFORM bool isLeafNode(
const VKL_INTEROP_UNIFORM Node *VKL_INTEROP_UNIFORM node)
{
return (intbits(node->nominalLength.x) >> 31) != 0;
Comment thread
johguenther marked this conversation as resolved.
Resolved
}

#ifndef ISPC
} // namespace ispc
#endif
4 changes: 2 additions & 2 deletions openvkl/devices/cpu/volume/UnstructuredVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace openvkl {

static void dumpBVH(Node *root, int indent = 0)
{
if (root->nominalLength.x < 0) {
if (isLeafNode(root)) {
auto leaf = (LeafNodeSingle *)root;
tabIndent(indent);
std::cerr << "id: " << leaf->cellID << " bounds: " << leaf->bounds
Expand Down Expand Up @@ -381,7 +381,7 @@ namespace openvkl {
throw std::runtime_error("bvh build failure");
}

if (rtcRoot->nominalLength.x < 0) {
if (isLeafNode(rtcRoot)) {
auto &val = ((LeafNode *)rtcRoot)->bounds;
bounds = box3f(val.lower, val.upper);
} else {
Expand Down
1 change: 1 addition & 0 deletions openvkl/devices/cpu/volume/UnstructuredVolume.ih
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "../common/Data.ih"
#include "UnstructuredBVH.ih"
#include "UnstructuredVolumeShared.h"

inline uniform Node *uniform sibling(uniform Node *uniform node)
Expand Down
6 changes: 3 additions & 3 deletions openvkl/devices/cpu/volume/UnstructuredVolume.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ inline bool pointInAABBTest(const uniform box3fa &box, const vec3f &point)
uniform int stackPtr = 0; \
\
while (1) { \
uniform bool isLeaf = (node->nominalLength.x < 0); \
uniform bool isLeaf = isLeafNode(node); \
if (isLeaf) { \
uniform LeafNodeSingle *uniform leaf = \
(uniform LeafNodeSingle * uniform) node; \
Expand Down Expand Up @@ -80,7 +80,7 @@ inline bool pointInAABBTest(const uniform box3fa &box, const vec3f &point)
uniform int stackPtr = 0; \
\
while (1) { \
uniform bool isLeaf = (node->nominalLength.x < 0); \
uniform bool isLeaf = isLeafNode(node); \
if (isLeaf) { \
uniform LeafNodeMulti *uniform leaf = \
(uniform LeafNodeMulti * uniform) node; \
Expand Down Expand Up @@ -145,7 +145,7 @@ inline void traverseBVH(uniform Node *uniform root,
uniform uint32 bitstack = 0;

while (1) {
uniform bool isInner = (node->nominalLength.x >= 0);
uniform bool isInner = !isLeafNode(node);

if (isInner) {
uniform InnerNode *uniform inner = (uniform InnerNode * uniform) node;
Expand Down
7 changes: 0 additions & 7 deletions openvkl/devices/cpu/volume/amr/AMRSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace openvkl {
ispc::UnstructuredSamplerShared>
{
AMRSampler(Device *, AMRVolume<W> &volume);
~AMRSampler() override;

void commit() override;

Expand Down Expand Up @@ -73,12 +72,6 @@ namespace openvkl {
CALL_ISPC(AMRSampler_create, volume.getSh(), this->getSh());
}

template <int W>
inline AMRSampler<W>::~AMRSampler()
{
CALL_ISPC(AMRSampler_destroy, this->getSh());
}

template <int W>
inline void AMRSampler<W>::commit()
{
Expand Down
2 changes: 0 additions & 2 deletions openvkl/devices/cpu/volume/amr/AMRVolume.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,3 @@ export void EXPORT_UNIQUE(AMRSampler_create,

sampler->computeGradient_varying = AMRVolume_computeGradient;
}

export void EXPORT_UNIQUE(AMRSampler_destroy, void *uniform _sampler) {}
2 changes: 1 addition & 1 deletion openvkl/devices/cpu/volume/particle/ParticleVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace openvkl {
throw std::runtime_error("bvh build failure");
}

if (rtcRoot->nominalLength.x < 0) {
if (isLeafNode(rtcRoot)) {
auto &val = ((ParticleLeafNode *)rtcRoot)->bounds;
bounds = box3f(val.lower, val.upper);
} else {
Expand Down
2 changes: 1 addition & 1 deletion openvkl/devices/cpu/volume/vdb/VdbLeafAccessObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace openvkl {
{
accessBuffer = allocator.allocate<uint32>(grid.numLeaves);
size = grid.numLeaves;
getRegistry().add(accessBuffer);
getRegistry().add(accessBuffer, size);
}

template <int W>
Expand Down
3 changes: 2 additions & 1 deletion openvkl/devices/cpu/volume/vdb/VdbLeafAccessObserver.ih
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ inline uniform bool VdbLeafAccessObserver_isObservable(
for (uniform size_t i = 0; i < registry->size; ++i) { \
uint32 *uniform accessBuffer = ((uint32 * uniform) registry->data[i]); \
/* NOTE: this is not synchronized between threads! */ \
accessBuffer[leafIndex] = 1; \
if (leafIndex < registry->numElements[i]) \
accessBuffer[leafIndex] = 1; \
} \
}

Expand Down
6 changes: 0 additions & 6 deletions openvkl/devices/cpu/volume/vdb/VdbSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ namespace openvkl {
this->getSh());
}

template <int W>
VdbSampler<W>::~VdbSampler()
{
CALL_ISPC(VdbSampler_destroy, this->getSh());
}

template <int W>
void VdbSampler<W>::commit()
{
Expand Down
1 change: 0 additions & 1 deletion openvkl/devices/cpu/volume/vdb/VdbSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace openvkl {
: public AddStructShared<VdbSamplerBase<W>, ispc::VdbSamplerShared>
{
explicit VdbSampler(Device *, VdbVolume<W> &volume);
~VdbSampler() override;

void commit() override;

Expand Down
Loading
Loading