Skip to content

Commit

Permalink
fix ImageBlock issues
Browse files Browse the repository at this point in the history
This commit addresses an ImageBlock issue that occurred when ImageBlock
was used with the parameters coalesce=false, normalize=True, and when
the sample footprint reached beyond the boundary.

It also updates Dr.Jit-Core to fix a loop recording issue (size of side
effects not correctly propagated) that I found along the way.
  • Loading branch information
wjakob committed Jan 17, 2023
1 parent 16c8d2a commit df4cbe0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ext/drjit
Submodule drjit updated 1 files
+1 −1 ext/drjit-core
24 changes: 16 additions & 8 deletions src/render/imageblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,25 @@ MI_VARIANT void ImageBlock<Float, Spectrum>::put(const Point2f &pos,

// Evaluate filters weights along the X and Y axes

for (uint32_t i = 0; i < count.x(); ++i) {
new (weights_x + i)
Float(JIT ? m_rfilter->eval(rel_f.x())
: m_rfilter->eval_discretized(rel_f.x()));
for (uint32_t x = 0; x < count.x(); ++x) {
Float wx = JIT ? m_rfilter->eval(rel_f.x())
: m_rfilter->eval_discretized(rel_f.x());

if (unlikely(m_normalize))
dr::masked(wx, x >= count_u.x()) = 0.f;

new (weights_x + x) Float(wx);
rel_f.x() += 1.f;
}

for (uint32_t i = 0; i < count.y(); ++i) {
new (weights_y + i)
Float(JIT ? m_rfilter->eval(rel_f.y())
: m_rfilter->eval_discretized(rel_f.y()));
for (uint32_t y = 0; y < count.y(); ++y) {
Float wy = JIT ? m_rfilter->eval(rel_f.y())
: m_rfilter->eval_discretized(rel_f.y());

if (unlikely(m_normalize))
dr::masked(wy, y >= count_u.y()) = 0.f;

new (weights_y + y) Float(wy);
rel_f.y() += 1.f;
}

Expand Down
18 changes: 18 additions & 0 deletions src/render/tests/test_imageblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,21 @@ def test04_read(variants_all, filter_name, border, offset, normalize, enable_ad)
ref /= dr.sum(weight)

assert dr.allclose(value, ref, atol=1e-5)


@pytest.mark.parametrize("coalesce", [ False, True ])
@pytest.mark.parametrize("normalize", [ False, True ])
def test05_boundary_effects(variants_vec_rgb, coalesce, normalize):
# Check that everything works correctly even when the image block
# is smaller than the filter kernel
rfilter = mi.load_dict({'type':'gaussian'})
ib = mi.ImageBlock(
size=(1, 1),
offset=(0, 0),
channel_count=1,
rfilter=rfilter,
normalize=normalize,
coalesce=coalesce
)
ib.put(pos=(0.5, 0.5), values=(dr.ones(mi.Float, 100),))
assert dr.allclose(ib.tensor().array, 100, rtol=1e-2)

0 comments on commit df4cbe0

Please sign in to comment.