Fix BVH sorted box hits: absent child can sort before a real hit (#173) #414

Closed
AndradeTK wants to merge 1 commit from upstream-pr/414 into main
AndradeTK commented 2026-11-25 00:30:09 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AndradeTK on 2026-11-25T00:30:09Z.


In bvh::boxes and the matching DXIL emitter (emit/intersect.rs), an absent child (NONE) could get a finite sort key when its stored bounds pass the slab test, letting it sort ahead of a valid hit. Give absent children the same infinite distance as misses: in the CPU reference guard the hit on children[n] != NONE, and in the emitter AND an unsigned child < NONE (i.e. present) into the hit mask.

Adds a regression test (sorted_boxes_put_absent_children_after_real_hits) covering the issue's reproducer: ray +Z extent 10, slot 0 absent with intersecting bounds, slot 1 present; sorted result is [8, NONE, NONE, NONE] and unsorted keeps slot order. Synthetic cases only; no game data.

Verified: victory-shader lib tests pass, clippy clean.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594313984 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/414). Originally posted by [AndradeTK](https://github.com/AndradeTK) on 2026-11-25T00:30:09Z. --- In bvh::boxes and the matching DXIL emitter (emit/intersect.rs), an absent child (NONE) could get a finite sort key when its stored bounds pass the slab test, letting it sort ahead of a valid hit. Give absent children the same infinite distance as misses: in the CPU reference guard the hit on children[n] != NONE, and in the emitter AND an unsigned child < NONE (i.e. present) into the hit mask. Adds a regression test (sorted_boxes_put_absent_children_after_real_hits) covering the issue's reproducer: ray +Z extent 10, slot 0 absent with intersecting bounds, slot 1 present; sorted result is [8, NONE, NONE, NONE] and unsorted keeps slot order. Synthetic cases only; no game data. Verified: victory-shader lib tests pass, clippy clean.
copilot-pull-request-reviewer[bot commented 2026-11-25 01:11:45 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T00:31:31Z.

Review: COMMENTED


No active review issues are reported for the BVH hit-sorting change.

No open issues 🎉

What changed in this PR

Fixes BVH hit sorting so absent children cannot sort ahead of valid hits, keeping the CPU reference and DXIL emitter consistent.

Changes:

  • Gives absent children infinite sort distances in both implementations.
  • Adds a regression test covering sorted results and unchanged slot order when sorting is disabled.
File Description
crates/​victory-shader/​src/​emit/​intersect.rs Adds a child-presence check to the emitted hit mask.
crates/​victory-shader/​src/​bvh.rs Excludes absent children from hits and adds regression coverage.

Review effort: Balanced

<!-- greyfinch-sync:fxceless/victory-fork:review:6049687167 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/414#pullrequestreview-6049687167). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-25T00:31:31Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟢 Approval recommended No active review issues are reported for the BVH hit-sorting change. **No open issues** 🎉 <details> <summary><strong>What changed in this PR</strong></summary> Fixes BVH hit sorting so absent children cannot sort ahead of valid hits, keeping the CPU reference and DXIL emitter consistent. **Changes:** - Gives absent children infinite sort distances in both implementations. - Adds a regression test covering sorted results and unchanged slot order when sorting is disabled. | File | Description | | ---- | ----------- | | `crates/​victory-shader/​src/​emit/​intersect.rs` | Adds a child-presence check to the emitted hit mask. | | `crates/​victory-shader/​src/​bvh.rs` | Excludes absent children from hits and adds regression coverage. | </details> <sub>Review effort: Balanced</sub>
upstream-sync closed this pull request 2026-11-25 02:09:32 +00:00
kaayzouee commented 2026-11-25 02:10:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:41:25Z.


Is this a duplicate of #213?

Both fix absent BVH children sorting ahead of valid hits in the CPU reference and DXIL emitter.

This is an automated message. If you believe it is incorrect, please reply with the relevant technical differences.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149841953 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/414#issuecomment-7149841953). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:41:25Z. --- Is this a duplicate of #213? Both fix absent BVH children sorting ahead of valid hits in the CPU reference and DXIL emitter. This is an automated message. If you believe it is incorrect, please reply with the relevant technical differences.
AndradeTK commented 2026-11-25 02:10:12 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AndradeTK on 2026-11-25T01:51:11Z.


Closing as duplicate of #213 ("Ray tracing: a child that is not there is a miss, whatever its box" by Pablo-Barros), which covers the same fix in bvh.rs and emit/intersect.rs with a broader change set (+docs). No need for two PRs addressing the same issue. Thanks for the catch, @kaayzouee.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7150032750 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/414#issuecomment-7150032750). Originally posted by [AndradeTK](https://github.com/AndradeTK) on 2026-11-25T01:51:11Z. --- Closing as duplicate of #213 ("Ray tracing: a child that is not there is a miss, whatever its box" by Pablo-Barros), which covers the same fix in bvh.rs and emit/intersect.rs with a broader change set (+docs). No need for two PRs addressing the same issue. Thanks for the catch, @kaayzouee.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!414
No description provided.