Skip to content

Fix packet scatter to raw pointers - #518

Open
jeongseok-meta wants to merge 9 commits into
mitsuba-renderer:masterfrom
jeongseok-meta:fix-raw-pointer-packet-scatter
Open

jeongseok-meta wants to merge 9 commits into
mitsuba-renderer:masterfrom
jeongseok-meta:fix-raw-pointer-packet-scatter

Conversation

@jeongseok-meta

@jeongseok-meta jeongseok-meta commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Motivation

dr::scatter() accepts raw-pointer targets, but packet values currently try to call scatter_packet_ on the pointer type. Pointer expressions such as .data() also cannot bind to the existing lvalue target parameter. This prevents Momentum's rasterizer from building.

conda-forge currently carries a patch for this behavior. It can be removed after this fix is included in a Dr.Jit release.

Changes

  • Preserve the existing lvalue overload and add a constrained overload for pointer expressions.
  • Dispatch raw-pointer packet scatters through the outer static array, selecting the generic element-wise fallback; JIT/AD specializations require an array target.
  • Normalize scalar and SIMD indices to unsigned 32-bit values without changing their nesting depth, so each recursive packet layer contributes its flattening stride.
  • Require a static native outer packet with one clear compile-time diagnostic, without instantiating pointer-incompatible overloads, while preserving native nested DynamicArray recursion.
  • Cover padded, nested, and deeply nested packet layouts, native nested DynamicArray values, signed indices, and explicit-template lvalue calls.

Testing

  • Fresh GCC 15/CMake build: the extension compiled and the four focused raw-pointer packet tests passed, covering scalar, nested, deeply nested, and native nested DynamicArray values.
  • Standalone scalar, masked, nested, and signed-index packet scatter probes passed.
  • A depth-three packet value with a depth-one SIMD index produces [1, ..., 16], confirming recursive flattening without collisions.
  • Native nested DynamicArray packet scatter produces [1, 2, 3, 4, 5, 6]; dynamically sized outer values and JIT/AD packet values fail with only the intended unsupported-value diagnostic.
  • The previous vendored broadcast fallback also supports native nested DynamicArray values but fails to compile for static arrays containing JIT/AD elements; Momentum's raw-pointer callers use native fixed-size packets.
  • tests/test_call_ext.py: 128 passed
  • Unpatched Dr.Jit reproduces Momentum rasterizer failures at both pointer-expression and packet-dispatch call sites.
  • With this change, Momentum's rasterizer and pymomentum renderer build, and pymomentum/test/test_renderer.py passes all 8 tests.
  • python -m py_compile tests/test_memop_ext.py
  • git diff --check

jeongseok-meta added a commit to jeongseok-meta/drjit that referenced this pull request Jul 21, 2026
@jeongseok-meta
jeongseok-meta force-pushed the fix-raw-pointer-packet-scatter branch from 086a67e to e25a39c Compare July 21, 2026 10:17
@wjakob
wjakob force-pushed the master branch 3 times, most recently from c0798bb to 93575f9 Compare August 18, 2026 14:29
@wjakob
wjakob force-pushed the master branch 2 times, most recently from 405372d to 43b0a48 Compare August 21, 2026 11:19
Preserve index nesting during recursive packet flattening, support native nested DynamicArray values, and reject unsupported dynamic/JIT/AD outer values with one diagnostic. Add focused regression coverage for both nested cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant