Repository navigation
rdna2spirv: BVH box test as measured on RDNA2: NaN planes skipped, near/far by direction sign (SHADER-650) - #3567
Conversation
…ar/far by direction sign (SHADER-650) Native image_bvh_intersect_ray on an RX 6900 XT (gfx1030, tools/hw_oracle, 338 cases) picks each axis's near and far plane by the sign of the inverse direction, takes the inverse direction as given (0 x inf is NaN), reduces the three near and the three far t with NaN skipped (all-NaN is a miss), and sorts by max(tnear, 0) through the network (0,2) (1,3) (0,1) (2,3) (1,2). A lone NaN bound leaves its plane open and an empty box misses without a separate check, so ItsNotRexed#3373's empty-box test is folded into this rule. The translator now matches all 338 measured cases (main 43). cs_bvh/cs_bvh32 and vk_compute_test expect the scene's NaN box at t = 0, as native gfx1030 returns. tests/semantic/test_image_bvh_box_hw.py holds 241 of the measured cases. docs/design.md Ray tracing row updated; the descriptor base is measured too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Cross-check on a second RDNA2 chip. @Vonsek posted nine native gfx1036 rows for this case in #3381 (comment) with the same rule this PR implements, found independently. I ran the same nine rows (box32, sorting on, including the
So the box rule now has native results from gfx1030 and gfx1036, and the translator matches both. Thanks @Vonsek. AI-assisted (Claude Code). |
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
kacper-serewis
left a comment
There was a problem hiding this comment.
At dc6068c, the new slab comparison can accept a finite inverted BOX32. With X bounds [1,0], Y and Z [0,67108864], origin (-33554432,0,0), direction (1,1,1), extent 67108864, the X distances round to the same float32. Interpreted SPIR-V from #3373 emitted four misses; #3567 returned four child IDs. The CPU reference misses. Retain ordered inversion detection and add this case, or qualify the contract based on native evidence. Native RDNA2 behavior for this input is unmeasured. Twelve focused tests and 80 other independent comparisons passed. AI-assisted CPU validation.
Native gfx1030 rounds both (plane - origin) and the multiply by the inverse direction toward zero: 811 measured cases (800 randomized slabs far from the origin plus 11 ties), round-to-nearest predicts 769, round-toward-zero all 811. kacper-serewis's inverted box at origin.x = -2^25 is a hit on hardware for this reason. The translator emulates it exactly: TwoSum error for the subtraction, a Dekker split of the scaled mantissas for the product's error sign, one ulp back toward zero when the nearest result went away from zero, finite overflow to +-FLT_MAX. 50 of the rounding cases are added to test_image_bvh_box_hw.py. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @kacper-serewis, good catch on the rounding. I measured your case natively instead of guessing. Your case is a hit on RDNA2. RX 6900 XT (gfx1030, AMD 26.11.2), That raised the real question, how the hardware rounds the slab distances, so I measured that too:
811 = 800 randomized slabs with origins 2^18 to 2^27 away (where the last bit decides hit or miss) plus 11 tie cases, yours among them. So I made the translator exact (35f19f4): the subtraction and the multiply now round toward zero bit for bit in SPIR-V, using the exact error of each op (TwoSum for the subtraction, a Dekker split of the scaled mantissas for the product) and stepping one ulp toward zero when the nearest result went away from zero; finite overflow gives ±FLT_MAX.
AI-assisted (Claude Code). |
|
Independent verification on NVIDIA GeForce RTX 4060 Ti (Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0, Tested head
Both BVH compute tests pass cleanly on 32-wide subgroups under wave64 emulation. AI-assisted. |
SHADER-650 (claim, finding). AI-assisted (Claude Code).
Depends on: #3373 (SHADER-635, empty boxes). This branch is #3373's head plus one commit, which replaces its separate empty-box check: the measured box test below rejects an empty box on its own.
What and why
The box step of
image_bvh_intersect_ray/image_bvh64_intersect_rayfollowed RADV's software path: per-axisFMin/FMaxof the two slab values, the inverse direction clamped to ±FLT_MAX, any NaN inmin.xculling the child, and children sorted by their unclamped entry distance. Native RDNA2 does something else, measured on an AMD Radeon RX 6900 XT (gfx1030) throughtools/hw_oracleraw kernels that write a node into memory and trace one ray:0 × infis NaN. Both the subtraction and the multiply round toward zero (811 measured cases; round-to-nearest predicts 769). So an inverted box whose two planes round to the same t is entered, as @kacper-serewis's case is on hardware.<swap.So a lone NaN bound leaves its plane open (the
cs_bvhscene's "inactive" box{NaN, 0, 0, 1, 1, 1}is entered at t = 0), and a box plane exactly on the origin along a zero-direction axis is open as well.Changes
tools/rdna2spirv.py: the box branch implements the rule above (OpIsNan selects, no FMin/FMax on a NaN, no FClamp of the inverse direction), the slab subtraction and multiply round toward zero exactly (newf32_sub_rtz/f32_mul_rtz: TwoSum error for the subtraction, Dekker split of the mantissas scaled to [1, 2) for the product's error sign, one ulp back toward zero when the nearest result went away from zero, finite overflow to ±FLT_MAX), and the sort network is reordered. Triangle nodes are unchanged.docs/design.md, Ray tracing row: the measured box rule; the descriptor base is measured, not an assumption; thecs_bvhwords.runtime/test/vk_compute_test.cpp,cs_bvh.asm,cs_bvh32.asm: the scene's box result is0x68 0x48 0x40 0xffffffff, what native gfx1030 returns for that exact scene (it was0x48 0x40 miss miss, the emulation's answer).tests/semantic/test_image_bvh_box_hw.py(new): 241 of the measured cases as data, each run through the translator and compared with the hardware's four words, plus 50 measured rounding cases (11 ties including @kacper-serewis's, and the 39 randomized ones round-to-nearest gets wrong).Tested
Hardware, AMD Radeon RX 6900 XT (gfx1030), AMD driver 26.11.2, Windows 11:
cs_bvhscene. The 32-bit form with a non-zero descriptor base and the 64-bit form with base 0 gave the same words in all 71 cases where both ran.mainmatches 43 of the 338, rdna2spirv: an empty BVH box is a miss, not a box that spans everything #3373 alone 66; rdna2spirv: an empty BVH box is a miss, not a box that spans everything #3373's translator gets 745 of the 800 randomized.scripts/run_gpu_tests.py --filter bvh:cs_bvh,cs_bvh32PASS with the new words. Full suite: 184/199 passed, 15 skipped, 0 failed (runtime built from this branch with MSVC Build Tools 2022).CPU:
tests/semantic/test_image_bvh_box_hw.py: 291/291. Negative controls: on rdna2spirv: an empty BVH box is a miss, not a box that spans everything #3373's translator 182 of the 241 fail; on dc6068c (this PR before the rounding fix) 42 of the 50 rounding cases fail.tests/semantic/test_image_bvh_box.py(rdna2spirv: an empty BVH box is a miss, not a box that spans everything #3373's) andtest_image_bvh_tri.py: 11 passed.tests/test_translate.py: 562 passed, 4 skipped (same as rdna2spirv: an empty BVH box is a miss, not a box that spans everything #3373's base).python -m unittest discover -s tests/semantic: 7328 tests OK (1 expected failure, unchanged).tests/test_docs_design_rows.py,tests/test_docs_links.py,tests/test_text_write_line_endings.py: OK.python -m compileall -q make_game.py tools tests: OK.Not measured: the extent boundary itself, and gfx1013 (the console) or RDNA1. An independent RDNA2/RDNA1 run of
test_image_bvh_box_hw.py's nodes throughtools/hw_oraclewould be welcome; @TheMrBeez's gfx1036 measurement of thecs_bvhNaN box agrees.No game data, keys or decryption.
🤖 Generated with Claude Code