Repository navigation
Fix SYCL instID[0] corruption when RTC_MAX_INSTANCE_LEVEL_COUNT > 1 - #645
Draft
stefanatwork wants to merge 1 commit into
Draft
stefanatwork wants to merge 1 commit into
stefanatwork wants to merge 1 commit into
Conversation
embree_instanced_geometry_sycl.exe produced wrong (uncolored) output
compared to the CPU reference tutorial whenever
RTC_MAX_INSTANCE_LEVEL_COUNT was built as 2 (it matched when built as 1).
Root cause: instance_id_stack::copy_UU() in kernels/common/instance_stack.h
filled the instID array using two separate loops with a runtime-variable
split point (depth = context->instStackSize):
for (l = 0; l < depth; ++l) tgt[l] = src[l];
for (l = depth; l < MAX; ++l) tgt[l] = RTC_INVALID_GEOMETRY_ID;
On the Intel GPU SYCL/DPC++ toolchain used for the HW raytracing backend,
this two-loop pattern gets miscompiled when depth is a runtime value: the
copied value and the invalidation marker end up swapped between tgt[0] and
tgt[1]. This was confirmed via device-side printf tracing, showing the
valid instance id landing in instID[1] instead of instID[0], so
ray.instID[0] (the field tutorials/apps actually read) was always
RTC_INVALID_GEOMETRY_ID.
This only affects RTC_MAX_INSTANCE_LEVEL_COUNT > 1, because the ==1 case
uses a trivial single assignment (tgt[0] = src[0]) with no loop.
Fix: replace the two loops with a single fused loop using a per-element
ternary, which avoids the problematic codegen pattern:
for (l = 0; l < MAX; ++l) tgt[l] = (l < depth) ? src[l] : RTC_INVALID_GEOMETRY_ID;
Verified on real Intel Arc B580 hardware: embree_instanced_geometry_sycl.exe
built with RTC_MAX_INSTANCE_LEVEL_COUNT=2 now produces pixel-identical
output (0 differing pixels) to embree_instanced_geometry.exe (CPU
reference), matching the already-correct RTC_MAX_INSTANCE_LEVEL_COUNT=1
build.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
svenwoop
approved these changes
Oct 28, 2026
svenwoop
left a comment
Collaborator
There was a problem hiding this comment.
Approved, but shorten that comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
embree_instanced_geometry_sycl.exe produced wrong (uncolored) output compared to the CPU reference tutorial whenever
RTC_MAX_INSTANCE_LEVEL_COUNT was built as 2 (it matched when built as 1).
Root cause: instance_id_stack::copy_UU() in kernels/common/instance_stack.h filled the instID array using two separate loops with a runtime-variable split point (depth = context->instStackSize):
On the Intel GPU SYCL/DPC++ toolchain used for the HW raytracing backend, this two-loop pattern gets miscompiled when depth is a runtime value: the copied value and the invalidation marker end up swapped between tgt[0] and tgt[1]. This was confirmed via device-side printf tracing, showing the valid instance id landing in instID[1] instead of instID[0], so ray.instID[0] (the field tutorials/apps actually read) was always RTC_INVALID_GEOMETRY_ID.
This only affects RTC_MAX_INSTANCE_LEVEL_COUNT > 1, because the ==1 case uses a trivial single assignment (tgt[0] = src[0]) with no loop.
Fix: replace the two loops with a single fused loop using a per-element ternary, which avoids the problematic codegen pattern:
Verified on real Intel Arc B580 hardware: embree_instanced_geometry_sycl.exe built with RTC_MAX_INSTANCE_LEVEL_COUNT=2 now produces pixel-identical output (0 differing pixels) to embree_instanced_geometry.exe (CPU reference), matching the already-correct RTC_MAX_INSTANCE_LEVEL_COUNT=1 build.