Skip to content
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7188,6 +7188,14 @@ interpolation buffer, one can specify vertex buffers
(`RTC_BUFFER_TYPE_VERTEX`) and vertex attribute buffers
(`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`) as well.

The `bufferType` has to be either `RTC_BUFFER_TYPE_VERTEX` or
`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`, and the `bufferSlot` has to be a
valid slot of the specified buffer type, thus smaller than the number of
time steps for vertex buffers and smaller than the vertex attribute
count set using `rtcSetGeometryVertexAttributeCount` for vertex
attribute buffers. Otherwise an `RTC_ERROR_INVALID_ARGUMENT` error is
raised and no data is interpolated.

The `rtcInterpolate` call stores `valueCount` number of interpolated
floating point values to the memory location pointed to by `P`. One can
avoid storing the interpolated value by setting `P` to `NULL`.
Expand Down
8 changes: 8 additions & 0 deletions doc/src/api/rtcInterpolate.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ interpolation buffer, one can specify vertex buffers
(`RTC_BUFFER_TYPE_VERTEX`) and vertex attribute buffers
(`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`) as well.

The `bufferType` has to be either `RTC_BUFFER_TYPE_VERTEX` or
`RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE`, and the `bufferSlot` has to be a
valid slot of the specified buffer type, thus smaller than the number
of time steps for vertex buffers and smaller than the vertex attribute
count set using `rtcSetGeometryVertexAttributeCount` for vertex
attribute buffers. Otherwise an `RTC_ERROR_INVALID_ARGUMENT` error is
raised and no data is interpolated.

The `rtcInterpolate` call stores `valueCount` number of interpolated
floating point values to the memory location pointed to by `P`. One
can avoid storing the interpolated value by setting `P` to `NULL`.
Expand Down
17 changes: 17 additions & 0 deletions kernels/common/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,23 @@ namespace embree
throw_RTCError(RTC_ERROR_INVALID_OPERATION,"operation not supported for this geometry");
}

/*! validates the buffer type and slot of an interpolation request. The buffer slot
* originates from the public rtcInterpolate/rtcInterpolateN API and is used to index
* fixed size arrays of buffer descriptors, thus it has to be range checked at runtime. */
__forceinline void checkInterpolateBuffer(RTCBufferType bufferType, unsigned int bufferSlot, size_t numVertexAttributes) const
{
if (bufferType == RTC_BUFFER_TYPE_VERTEX) {
if (unlikely(bufferSlot >= numTimeSteps))
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex buffer slot specified for interpolation");
}
else if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
if (unlikely(bufferSlot >= numVertexAttributes))
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid vertex attribute buffer slot specified for interpolation");
}
else
throw_RTCError(RTC_ERROR_INVALID_ARGUMENT,"invalid buffer type specified for interpolation");
}

/*! interpolates user data to the specified u/v locations */
virtual void interpolateN(const RTCInterpolateNArguments* const args);

Expand Down
7 changes: 3 additions & 4 deletions kernels/common/scene_curves.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size()));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

adds additional branching that is anyway present below

const char* src = nullptr;
size_t stride = 0;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
Expand Down Expand Up @@ -708,10 +707,11 @@ namespace embree
float* ddPdudu = args->ddPdudu;
unsigned int valueCount = args->valueCount;

checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());

/* we interpolate vertex attributes linearly for hermite basis */
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE)
{
assert(bufferSlot <= vertexAttribs.size());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should be converted to exception

const char* vsrc = vertexAttribs[bufferSlot].getPtr();
const size_t vstride = vertexAttribs[bufferSlot].getStride();

Expand All @@ -732,7 +732,6 @@ namespace embree
/* interpolation for vertex buffers */
else

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

here enter only on VERTEX_BUFFER type

{
assert(bufferSlot < numTimeSteps);
const char* vsrc = vertices[bufferSlot].getPtr();
const char* tsrc = tangents[bufferSlot].getPtr();
const size_t vstride = vertices[bufferSlot].getStride();
Expand Down
3 changes: 1 addition & 2 deletions kernels/common/scene_grid_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size()));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
Expand Down
3 changes: 1 addition & 2 deletions kernels/common/scene_line_segments.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size()));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
Expand Down
3 changes: 1 addition & 2 deletions kernels/common/scene_quad_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size()));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
Expand Down
10 changes: 2 additions & 8 deletions kernels/common/scene_subdiv_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,21 +854,18 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < RTC_MAX_TIME_STEP_COUNT) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot < RTC_MAX_USER_VERTEX_BUFFERS));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
std::vector<SharedLazyTessellationCache::CacheEntry>* baseEntry = nullptr;
Topology* topo = nullptr;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
assert(bufferSlot < vertexAttribs.size());
src = vertexAttribs[bufferSlot].getPtr();
stride = vertexAttribs[bufferSlot].getStride();
baseEntry = &vertex_attrib_buffer_tags[bufferSlot];
int topologyID = vertexAttribs[bufferSlot].userData;
topo = &topology[topologyID];
} else {
assert(bufferSlot < numTimeSteps);
src = vertices[bufferSlot].getPtr();
stride = vertices[bufferSlot].getStride();
baseEntry = &vertex_buffer_tags[bufferSlot];
Expand Down Expand Up @@ -931,21 +928,18 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < RTC_MAX_TIME_STEP_COUNT) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot < RTC_MAX_USER_VERTEX_BUFFERS));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
std::vector<SharedLazyTessellationCache::CacheEntry>* baseEntry = nullptr;
Topology* topo = nullptr;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
assert(bufferSlot < vertexAttribs.size());
src = vertexAttribs[bufferSlot].getPtr();
stride = vertexAttribs[bufferSlot].getStride();
baseEntry = &vertex_attrib_buffer_tags[bufferSlot];
int topologyID = vertexAttribs[bufferSlot].userData;
topo = &topology[topologyID];
} else {
assert(bufferSlot < numTimeSteps);
src = vertices[bufferSlot].getPtr();
stride = vertices[bufferSlot].getStride();
baseEntry = &vertex_buffer_tags[bufferSlot];
Expand Down
3 changes: 1 addition & 2 deletions kernels/common/scene_triangle_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ namespace embree
unsigned int valueCount = args->valueCount;

/* calculate base pointer and stride */
assert((bufferType == RTC_BUFFER_TYPE_VERTEX && bufferSlot < numTimeSteps) ||
(bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE && bufferSlot <= vertexAttribs.size()));
checkInterpolateBuffer(bufferType,bufferSlot,vertexAttribs.size());
const char* src = nullptr;
size_t stride = 0;
if (bufferType == RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) {
Expand Down
Loading