fix(shader): keep absent BVH children out of sorted box hits #27
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!27
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-27"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@mathcx on GitHub · 2026-11-25 15:48 UTC · original
fix/bvh-absent-child-sort→main· +36 −2 · 3 files · 1 commits · closed without merging1. Problema / Contexto
Nas instruções de interseção de ray tracing do console (
image_bvh_intersect_rayeimage_bvh64_intersect_ray), cada nó interno de caixas delimitadoras (tipos4/box16e5/box32) armazena até 4 ponteiros de filhos (children[0..4]) acompanhados de 4 AABBs. Quando um nó interno possui menos de 4 filhos ativos, os slots ausentes recebem a sentinelaNONE(0xffff_ffff), mas os floats correspondentes da caixa nem sempre são preenchidos comNaNpelo construtor da estrutura — podendo conter zeros ([0.0; 6]) ou limites finitos residuais.Anteriormente, tanto a referência em CPU (
bvh::boxes) quanto a emissão inline em DXIL (Lower::bvh_boxes) descartavam apenas caixas comb[0].is_nan(). Se o raio interceptasse uma caixa finita associada a um slotchildren[n] == NONE, o identificador continuava sendoNONE, masdistances[n]recebia a distância finitaenterem vez de permanecer em+inf(f32::INFINITY). Quando a ordenação por distância estava habilitada (sort = true), a rede de ordenação classificava esseNONEà frente de filhos válidos atingidos a distâncias maiores (enter_ausente < enter_valido), deslocando ponteiros válidos para depois de0xffff_ffff. Como os loops de travessia de BVH nos shaders interrompem o empilhamento ao encontrarNONE(ou consomem os slots assumindo que todos os hits válidos precedemNONE), hits geométricos reais eram descartados prematuramente durante a travessia (relacionado à Issue #4).2. Alterações Técnicas
crates/victory-shader/src/bvh.rs:bvh::boxespara exigirchildren[n] != NONEantes de registrar um hit e atribuirdistances[n] = enter, mantendodistances[n] = f32::INFINITYem qualquer slot de filho ausente independentemente das coordenadas armazenadas na AABB.a_missing_child_with_a_finite_box_does_not_sort_ahead_of_hitscobrindo nósbox32(kind = 5) ebox16(kind = 4), com e sem ordenação (sort = trueesort = false), quando filhosNONEpossuem caixas finitas ([0.0; 6]eUNIT) mais próximas da origem do raio do que filhos válidos.crates/victory-shader/src/emit/intersect.rs:Lower::bvh_boxespara emitiricmp ne(pred::NE) entrechildren[n]enone(0xffff_ffff) e combinar o predicadopresentao bithitviaBin::And, garantindo quedistances[n]selecioneinfinitypara filhos ausentes antes da rede de ordenação em DXIL.crates/victory-shader/src/emit/intersect_tests.rs:box32ebox16com filhosNONEem caixas finitas posicionadas à frente de filhos válidos na cena de validação GPU/WARP (scene), exercitando os caminhos de 32 bits e 64 bits (com e semBOX_SORT) no adaptador de hardware e no WARP contra a referência corrigida.3. Validação e Testes
cargo clippy -p victory-shader --all-targets -- -D warnings: aprovado sem avisos.cargo test -p victory-shader: todos os testes unitários e de integração em GPU/WARP aprovados (228 passed, 0 failed, 3 ignored).cargo xtask policy: aprovado (asset policye limites de tamanho de arquivo respeitados).cargo run --release -p victory -- translate --validate --pipelines:26.599containers processados,25.745 / 25.758shaders DXIL emitidos,25.674validados viadxil.dlle25.346PSOs aceitos na GPU local sem regressões.1. Problem / Context
In the console ray-tracing intersection instructions (
image_bvh_intersect_rayandimage_bvh64_intersect_ray), each internal bounding-box node (pointer kinds4/box16and5/box32) holds up to 4 child pointers (children[0..4]) alongside 4 AABBs. When an internal node has fewer than 4 active children, unused child slots carry theNONEsentinel (0xffff_ffff), while their box coordinates are not guaranteed to be filled withNaN— they may hold zeroed ([0.0; 6]) or leftover finite bounds.Previously, both the CPU reference (
bvh::boxes) and the inline DXIL emitter (Lower::bvh_boxes) only rejected disabled boxes viab[0].is_nan(). Whenever a ray intersected the finite bounds of an absent child slot (children[n] == NONE),ids[n]stayedNONE, butdistances[n]was overwritten withenterinstead of remaining+inf(f32::INFINITY). With distance sorting enabled (sort = true), the 4-element sorting network ordered thatNONEslot ahead of valid child hits at larger entry distances (enter_absent < enter_valid), pushing valid child pointers behind0xffff_ffff. Because shader BVH traversal loops stop pushing children upon encounteringNONE(or assume valid hits precedeNONEslots), valid geometry intersections behind closer unused slots were silently dropped (related to Issue #4).2. Technical Changes
crates/victory-shader/src/bvh.rs:bvh::boxesto requirechildren[n] != NONEbefore recording a slab hit, keepingdistances[n] = f32::INFINITYfor absent child slots regardless of their box coordinates.a_missing_child_with_a_finite_box_does_not_sort_ahead_of_hitscovering bothbox32(kind = 5) andbox16(kind = 4), sorted and unsorted (sort = trueandsort = false), whenNONEslots have closer finite bounds ([0.0; 6]andUNIT) than valid children.crates/victory-shader/src/emit/intersect.rs:Lower::bvh_boxesto emiticmp ne(pred::NE) comparingchildren[n]againstnone(0xffff_ffff) and combinepresentintohitviaBin::And, ensuringdistances[n]selectsinfinityfor absent children prior to the DXIL sorting network.crates/victory-shader/src/emit/intersect_tests.rs:box32andbox16test nodes with closer finite-boxNONEchildren ahead of valid children inscene(), exercising 32-bit and 64-bit pointer modes (both with and withoutBOX_SORT) on the hardware D3D12 adapter and WARP against the fixed reference.3. Verification & Testing
cargo clippy -p victory-shader --all-targets -- -D warnings: passed with zero warnings.cargo test -p victory-shader: all unit and GPU/WARP integration tests passed (228 passed, 0 failed, 3 ignored).cargo xtask policy: passed (asset policyand file size checks clean).cargo run --release -p victory -- translate --validate --pipelines:26,599containers processed,25,745 / 25,758DXIL shaders emitted,25,674validated throughdxil.dll, and25,346host PSOs created with zero regressions.Pull request closed