tests: model the console BVH node set #2921
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2921"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-26T20:33:51Z.
What changed
This adds a pure-Python CPU model of the console BVH node test,
image_bvh_intersect_ray/image_bvh64_intersect_ray, and extends the existing gfx1030 fixture with a model-only witness set.The model covers:
0xfffffffffor misses and absent children.{t_num, t_denom, I_num, J_num}in the triangle return mode,+inf/1/0/0on a miss.(pointer >> 3) << 6from the 40-bit descriptor base in 256-byte units, and the 64-bit absolute form.The node formats and box test follow Mesa RADV's public software emulation (MIT); the triangle test is the watertight formulation RADV uses. No game files or raw captures are included.
Tests
Output:
The 315 cases cover 66 FP32 boxes, 46 binary16 boxes, 119 triangles and 84 pointer decodings, including hits, misses, ties, shared edges, negative zero, NaN vertices, zero direction, disabled children, vertex permutations and the ID byte's high bits. The existing five-ray FP32 assertions still pass.
tests/docs_links_check.pypasses (546 links). The native five-ray GPU fixture was not run here: LLVM 15, LLD 15 and the HIP runtime are unavailable on this host. The HIP kernel and assembly are unchanged.Limits
The model is a reference for a translator, not a translation. Native gfx1030 readback remains pending, and the triangle return mode 0 is outside this slice.
Refs #870, #1268.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-26T21:05:17Z.
Added
tests/checks/python-linux/bvh_node_model.txtso the 315-case model-only witness set runs in the Linux Python job, not only by hand.python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux --jobs 2passes all six fragments locally, includingmodel_witness_cases=315 node=231 pointer=84 mismatches=0.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:29:58Z.
Review: COMMENTED
PR #2921 by @lambirou -- tests: model the console BVH node set
What works
Issues
Recommendations
Overall
A well-researched, well-tested implementation. The linear layout extension is cleanly separated from tiled modes. Minor concern about BC format handling in linear mode, but the existing refusal behavior is safe. Ready for merge.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:39:58Z.
Review: APPROVED
Reviewed
c59a56f2453ce73196c3a80a54a7f38e9770ded0. I ranpython -B tests/gfx1030_bvh_box/check.py --model-onlyin the integration tree for current main. All 315 model witnesses matched (231 node and 84 pointer cases), and the reversed-sort and zero-fill controls both produced the expected mismatch. The CPU model and source-linked formulas are clearly scoped. Native gfx1030 execution was outside this check. Required Windows CI passed.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T05:47:23Z.
Independent Linux/Python result on
c59a56f2(= merge2944b050). Post-merge receipt; measurements only.Environment
2026-11-27T05:41:11Zwhile this ran, so this is a post-merge receipt on the merged tree.The three files it depends on are byte-identical (LF-normalised) between the head I measured and the merge
commit —
bvh_model.pyc54fb83a03823cd4,check.py3051cdaa7f08993b,bvh_node_model.txt9f6513856010e87c— and currentorigin/main(6aa59440) still carries the same three blobs.--model-onlyis the only path that can run here.c59a56f2453ce73196c3a80a54a7f38e9770ded0,git status --porcelain --untracked-files=noempty.Commands and raw output
The counts reproduce, and the new fragment does reach CI before merge: the
python-linuxjob has noif:,the workflow's
pull_requesttrigger has nopaths:filter, and that job runs--from-dir tests/checks/python-linux, wherebvh_node_model.txtnow lives.What the 315 cases pin
I injected 23 one-line mutants of
bvh_model.pythroughsys.modules['bvh_model']before importingcheck.py, then ran--model-only; the unmutated module reports 0 failures through the same path before andafter the matrix, and the file on disk is unchanged. Mutant, what it changes, and the first literal failure
(expected/actual):
19 of the 21 non-equivalent mutants fail the run: 18 through a named witness mismatch, and M19 through
struct.errorrather than a wrong value. Two others (below) are provably equivalent Python rewrites and areexcluded from the denominator. So the box test, the sort stability, the absent-child and miss fills, the
descriptor-relative addressing and the triangle barycentric sign are all pinned by these literals.
One branch the set never observes
if direction[kz] < 0.0: kx, ky = ky, kx(bvh_model.py:188) is reached by four witnesses —tri/kind0-behind..tri/kind3-behind, direction(0, 0, -1)— but all four miss, identically with andwithout the swap, because a global sign flip leaves the ahead test invariant.
A triangle that hits with a negative dominant component separates the two. Node: kind 0, byte 60 =
0x01(i = 1, j = 0, first = 2, so a = v2, b = v1, c = v0), vertices
(0,0),(1,0),(0,1)atz = -4;ray origin
(0.2, 0.2, 0), direction(0, 0, -1), inverse(inf, inf, -1),descriptor(0, sort=True):The same triangle at
z = +4with direction(0, 0, +1)returns40800000 3f800001 3e4cccce 3f19999a,exactly the second row, so the two differ by an overall sign of all four words. That is not a hit/miss
difference:
t/detis+4in both (t = -4withdet = -1is ahead, not behind), and every quotient issign-invariant. Only a raw-word expectation can see it — which is what the native comparison is for. Worth
noting that 44 hitting triangles do return
det < 0, so that path is covered; it is the axis swap under anegative dominant component that is not. Adding the mirrored case would pin whichever sign is chosen; if the
sign is meant to follow the console, it has to come from the native readback (or RADV), not from the model.
The other three survivors
first = (3 - i - j) & 3->first = 3 - i - j: a Python no-op.3-i-jlies in[-3, 3]andmappedis afour-tuple, so
mapped[-k]ismapped[4-k], exactly what& 3computes. No input can kill it.TRIANGLE_VERTICES[kind & 3] + (0,)->+ (1,): equivalent. The appended slot is selected wheneverfirst,iorjis 3; in every such id byte another of the three selected indices equals it(
first == 3requiresi + j ≡ 0 mod 4, soiorjis 3, ori == j), two vertices coincide,detisexactly zero, and both versions miss. A sweep of 1024
(kind, id byte)combinations, 192 of them hitting,shows no separation, but the structural argument is the proof.
if math.isnan(lo[0])->math.isnan(low[0]): it survives the set, and it is separable. On the existingbox32/infinite-boundsnode, setinverse[0] = 0.0and keep everything else: the delivered model returns00000304 0000020c 00000105 00000400, the mutant00000105 00000400 ffffffff ffffffff. Box 2 storeslo[0] = -inf, so the computed bound is-inf * 0 = NaN; the mutant reads that as the absent-slot markerand drops the box. The documented rule ties the marker to the stored bound, which supports the delivered
version — but the input is undocumented rather than excluded (the doc only states zero direction ->
infinite inverse, not its converse), so I would not add a case for it.
What this fixture ties to hardware, and what it does not
model_check()(line 78) exercisesreference()(line 59), notbvh_model, so the five-ray assertionsquoted in the body are not evidence about the new model;
witness_check()(line 105) is its only consumer.The native path compares its ten readbacks against the
RAYSliterals (line 1050), not againstbvh_model,so the pending native run will not validate the model either. If the model is meant to predict the console
words, the native path has to push the same cases through it.
Limits
executed.
bvh_model.py. Theindependent oracle it rests on is the RADV derivation cited in the docstring, which is not in the tree.
Green here says "the model still does what the literals say", not "the model matches the console".
wide=True; the 64-bit form is pinned only by sixteenPOINTER_WITNESSEScallingnode_addressdirectly.descriptor(return_barycentrics=False)is never built, so the mode-0ValueErroris unexercised.
AI-assisted.