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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Version History
---------------

### Open VKL 2.0.3

- Fix artifacts when sampling AMR volume

### Open VKL 2.0.2

- Fix used element size in copyDeviceBufferToHost
Expand Down
4 changes: 1 addition & 3 deletions openvkl/devices/cpu/volume/amr/AMRData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ namespace openvkl {
this->cellWidth = info.cellWidth;
this->value = *ispc(data);
this->dims = this->box.size() + vec3i(1);
// make it an ULP smaller such that floor(relBrickPos*f_dims) yields
// correct index even for relBrickPos=1.0f
this->f_dims = nextafter(this->dims, -1);
this->f_dims = vec3f(this->dims);

this->worldBounds =
box3f(vec3f(this->box.lower) * this->cellWidth,
Expand Down
8 changes: 6 additions & 2 deletions openvkl/devices/cpu/volume/amr/CellRef.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ extern CellRef findCell(const AMR *uniform self,
for (uniform int i=0;any(true);i++) {
const AMRBrick *uniform brick = leaf->brickList[i];
if (brick->cellWidth >= minWidth) {
const vec3f relBrickPos
vec3f relBrickPosUnclamped
= (worldSpacePos - brick->bounds.lower) * brick->bounds_scale;
// clamp to 1ULP-less-1 for f_bc stay in valid index range
const vec3f relBrickPos = min(relBrickPosUnclamped, make_vec3f(0x1.fffffep-1f));
// brick coords: integer cell coordinates inside brick
// OPT: the same calculations as below, just in
// floats. this works as long as all values we calculate
Expand Down Expand Up @@ -75,8 +77,10 @@ extern CellRef findLeafCell(const AMR *uniform self,
if (isLeaf(node)) {
const AMRLeaf *uniform leaf = &self->leaf[getOfs(node)];
const AMRBrick *uniform brick = leaf->brickList[0];
const vec3f relBrickPos
const vec3f relBrickPosUnclamped
= (worldSpacePos - brick->bounds.lower) * brick->bounds_scale;
// clamp to 1ULP-less-1 for f_bc stay in valid index range
const vec3f relBrickPos = min(relBrickPosUnclamped, make_vec3f(0x1.fffffep-1f));
// brick coords: integer cell coordinates inside brick
// OPT: the same calculations as below, just in
// floats. this works as long as all values we calculate
Expand Down
48 changes: 11 additions & 37 deletions openvkl/devices/cpu/volume/amr/DualCell.ih
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ inline vec3f dualCellLerpWeightsForLevel(const vec3f &P, const float cellWidth)
return (xfmed - f_idx);
}

inline void initDualCell(DualCell &D,
const vec3f &P,
const uniform AMRLevel &level)
{
const float cellWidth = level.cellWidth;
const float halfCellWidth = 0.5f*cellWidth;
const float rcpCellWidth = rcp(cellWidth);
const vec3f xfmed = (P-halfCellWidth)*rcpCellWidth;
const vec3f f_idx = floor(xfmed);
D.cellID.pos = f_idx * cellWidth + halfCellWidth;
D.cellID.width = cellWidth;
D.weights = xfmed - f_idx;
}

inline void initDualCell(DualCell &D, const vec3f &P, const float cellWidth)
{
const float halfCellWidth = cellWidth * 0.5f;
Expand All @@ -65,6 +51,13 @@ inline void initDualCell(DualCell &D, const vec3f &P, const float cellWidth)
D.weights = xfmed - f_idx;
}

inline void initDualCell(DualCell &D,
const vec3f &P,
const uniform AMRLevel &level)
{
initDualCell(D, P, level.cellWidth);
}

inline bool allCornersAreLeaves(const DualCell &D)
{
return
Expand All @@ -91,9 +84,8 @@ inline bool allCornersArePresent(const DualCell &D)
(D.actualWidth[7] == D.cellID.width);
}

inline float lerp(const DualCell &D)
inline float lerpWithExplicitWeights(const DualCell &D, const vec3f &w)
{
const vec3f &w = D.weights;
const float f000 = D.value[C000];
const float f001 = D.value[C001];
const float f010 = D.value[C010];
Expand All @@ -115,27 +107,9 @@ inline float lerp(const DualCell &D)
return f;
}

inline float lerpWithExplicitWeights(const DualCell &D, const vec3f &w)
inline float lerp(const DualCell &D)
{
const float f000 = D.value[C000];
const float f001 = D.value[C001];
const float f010 = D.value[C010];
const float f011 = D.value[C011];
const float f100 = D.value[C100];
const float f101 = D.value[C101];
const float f110 = D.value[C110];
const float f111 = D.value[C111];

const float f00 = (1.f-w.x)*f000 + w.x*f001;
const float f01 = (1.f-w.x)*f010 + w.x*f011;
const float f10 = (1.f-w.x)*f100 + w.x*f101;
const float f11 = (1.f-w.x)*f110 + w.x*f111;

const float f0 = (1.f-w.y)*f00+w.y*f01;
const float f1 = (1.f-w.y)*f10+w.y*f11;

const float f = (1.f-w.z)*f0+w.z*f1;
return f;
return lerpWithExplicitWeights(D, D.weights);
}

inline float lerpAlpha(const DualCell &D)
Expand Down Expand Up @@ -174,4 +148,4 @@ extern void findDualCell(const AMR *uniform self,
corner */
extern void findMirroredDualCell(const AMR *uniform self,
const vec3i &loID,
DualCell &dual);
DualCell &dual);
5 changes: 4 additions & 1 deletion openvkl/devices/gpu/compute/amr/CellRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ namespace ispc {
if (isLeaf(node)) {
const AMRLeaf *leaf = &self->leaf[getOfs(node)];
const AMRBrick *brick = leaf->brickList[0];
const vec3f relBrickPos =
const vec3f relBrickPosUnclamped =
(worldSpacePos - brick->bounds.lower) * brick->bounds_scale;
// clamp to 1ULP-less-1 for f_bc stay in valid index range
const vec3f relBrickPos =
min(relBrickPosUnclamped, vec3f(0x1.fffffep-1f));
Comment on lines +61 to +62
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clamp uses a hard-to-read hex float literal (0x1.fffffep-1f) to represent the largest float < 1.0. Consider defining this as a named constant (or computing it via nextafter(1.f, 0.f)) to make the intent clearer and avoid duplicating the literal elsewhere.

Copilot uses AI. Check for mistakes.
// brick coords: integer cell coordinates inside brick
// OPT: the same calculations as below, just in
// floats. this works as long as all values we calculate
Expand Down
42 changes: 8 additions & 34 deletions openvkl/devices/gpu/compute/amr/DualCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ispc {

struct DualCellID
{
// position of LOWER-LEFT COORDINATE (ie, CENTER of lower-left cell
// position of LOWER-LEFT COORDINATE (ie, CENTER of lower-left cell)
vec3f pos;
// width of dual cell, also doubles as level indicator
float width;
Expand Down Expand Up @@ -38,10 +38,9 @@ namespace ispc {
return (xfmed - f_idx);
}

inline void initDualCell(DualCell &D, const vec3f &P, const AMRLevel &level)
inline void initDualCell(DualCell &D, const vec3f &P, const float cellWidth)
{
const float cellWidth = level.cellWidth;
const float halfCellWidth = 0.5f * cellWidth;
const float halfCellWidth = cellWidth * 0.5f;
const float rcpCellWidth = rcp(cellWidth);
const vec3f xfmed = (P - halfCellWidth) * rcpCellWidth;
const vec3f f_idx = floor(xfmed);
Expand All @@ -50,15 +49,9 @@ namespace ispc {
D.weights = xfmed - f_idx;
}

inline void initDualCell(DualCell &D, const vec3f &P, const float cellWidth)
inline void initDualCell(DualCell &D, const vec3f &P, const AMRLevel &level)
{
const float halfCellWidth = cellWidth * 0.5f;
const float rcpCellWidth = rcp(cellWidth);
const vec3f xfmed = (P - halfCellWidth) * rcpCellWidth;
const vec3f f_idx = floor(xfmed);
D.cellID.pos = f_idx * cellWidth + halfCellWidth;
D.cellID.width = cellWidth;
D.weights = xfmed - f_idx;
initDualCell(D, P, level.cellWidth);
}

inline bool allCornersAreLeaves(const DualCell &D)
Expand All @@ -79,9 +72,8 @@ namespace ispc {
(D.actualWidth[7] == D.cellID.width);
}

inline float lerp(const DualCell &D)
inline float lerpWithExplicitWeights(const DualCell &D, const vec3f &w)
{
const vec3f &w = D.weights;
const float f000 = D.value[C000];
const float f001 = D.value[C001];
const float f010 = D.value[C010];
Expand All @@ -103,27 +95,9 @@ namespace ispc {
return f;
}

inline float lerpWithExplicitWeights(const DualCell &D, const vec3f &w)
inline float lerp(const DualCell &D)
{
const float f000 = D.value[C000];
const float f001 = D.value[C001];
const float f010 = D.value[C010];
const float f011 = D.value[C011];
const float f100 = D.value[C100];
const float f101 = D.value[C101];
const float f110 = D.value[C110];
const float f111 = D.value[C111];

const float f00 = (1.f - w.x) * f000 + w.x * f001;
const float f01 = (1.f - w.x) * f010 + w.x * f011;
const float f10 = (1.f - w.x) * f100 + w.x * f101;
const float f11 = (1.f - w.x) * f110 + w.x * f111;

const float f0 = (1.f - w.y) * f00 + w.y * f01;
const float f1 = (1.f - w.y) * f10 + w.y * f11;

const float f = (1.f - w.z) * f0 + w.z * f1;
return f;
return lerpWithExplicitWeights(D, D.weights);
}

inline float lerpAlpha(const DualCell &D)
Expand Down
Loading