Pass bounds-callback specific payload to the callback - #618
Conversation
Prior to this change the rtcSetGeometryBoundsFunction() accepted an user payload (userPtr argument) which was not passed to the callback since the UserGeometry::setBoundsFunction() simply ignored the argument. This change makes it so the bounds callback function has an access to this payload via RTCBoundsFunctionArguments::boundsUserPtr. The change allows to use geometry-specific payload (geometryUserPtr) for efficient intersection and filtering, while being able to access data needed for the purpose of bounding box calculation.
|
Developed on macOS, tested via integrating the patched version into Blender (also on macOS). Not sure what is the easiest way to run the full embree test suit, and also how to test oneAPI. |
There was a problem hiding this comment.
Pull request overview
This PR fixes the user-geometry bounds callback payload plumbing so the userPtr passed to rtcSetGeometryBoundsFunction() becomes accessible inside the bounds callback via RTCBoundsFunctionArguments::boundsUserPtr, while keeping geometryUserPtr available for geometry-wide data.
Changes:
- Store the bounds-callback
userPtrinUserGeometry/AccelSetand forward it when invoking the bounds callback. - Extend
RTCBoundsFunctionArguments(C and ISPC headers) with a newboundsUserPtrfield. - Initialize the new
boundsUserPtrmember inAccelSet’s constructor.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| kernels/common/scene_user_geometry.cpp | Persist the bounds-callback payload when setting the bounds function. |
| kernels/common/accelset.h | Pass the new payload through RTCBoundsFunctionArguments and add storage in AccelSet. |
| kernels/common/accelset.cpp | Initialize boundsUserPtr to nullptr in AccelSet constructor. |
| include/embree4/rtcore_geometry.isph | Add boundsUserPtr to the public ISPC bounds callback args struct. |
| include/embree4/rtcore_geometry.h | Add boundsUserPtr to the public C bounds callback args struct. |
Suppressed comments (2)
include/embree4/rtcore_geometry.h:80
RTCBoundsFunctionArgumentsis part of the public callback ABI; insertingboundsUserPtrbetweengeometryUserPtrandprimIDshifts the offsets ofprimID,timeStep, andbounds_o. Applications compiled against older headers will interpret these fields incorrectly at runtime when used with the updated library. To preserve binary compatibility, append the new member at the end of the struct (or introduce a versioned args struct/size field) and update all corresponding call sites + ISPC header accordingly.
struct RTCBoundsFunctionArguments
{
void* geometryUserPtr;
void* boundsUserPtr;
unsigned int primID;
unsigned int timeStep;
struct RTCBounds* bounds_o;
};
include/embree4/rtcore_geometry.isph:79
- The ISPC
RTCBoundsFunctionArgumentslayout must match the C API layout and should remain ABI-stable across releases. InsertingboundsUserPtrbeforeprimIDchanges field offsets for any existing ISPC user code compiled against older headers. Consider appending the new field at the end (and mirroring that order in the C header + all internal call sites).
struct RTCBoundsFunctionArguments
{
void* uniform geometryUserPtr;
void* uniform boundsUserPtr;
uniform unsigned int primID;
uniform unsigned int timeStep;
uniform RTCBounds* uniform bounds_o;
};
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Add boundsUserPtr field to RTCBoundsFunctionArguments struct across all headers (C and ISPC) - Update documentation to reflect the new field and its purpose - Update CHANGELOG with release notes for version 4.5
Prior to this change the rtcSetGeometryBoundsFunction() accepted an user payload (userPtr argument) which was not passed to the callback since the UserGeometry::setBoundsFunction() simply ignored the argument.
This change makes it so the bounds callback function has an access to this payload via RTCBoundsFunctionArguments::boundsUserPtr.
The change allows to use geometry-specific payload (geometryUserPtr) for efficient intersection and filtering, while being able to access data needed for the purpose of bounding box calculation.