Skip to content

bvh_gpu_smoke: check InitHeaders and GetBVHCompactedSize byte for byte (TEST-594) - #5130

Open
Dom-in wants to merge 2 commits into
ItsNotRexed:mainfrom
Dom-in:bvh-check-headers
Open

Dom-in wants to merge 2 commits into
ItsNotRexed:mainfrom
Dom-in:bvh-check-headers

Conversation

@Dom-in

@Dom-in Dom-in commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Depends on: #5085 (this branch adds one commit on top of it). TEST-594, the BVH builder's programs checked on a GPU.

What

Five more --checked cases in tools/bvh_gpu_smoke.py, for two programs whose effect reads straight off their code:

  • InitHeaders: for each 40-byte record (table+0x0, count at +0x10), it fills the 64-byte BVH header at the record's first address. That's three of the record's fields, the empty bounds (+-FLT_MAX), a fourth field, -1, the last two fields and 0x7f7f7f. Where the record has a second address, it writes an empty box there. The case has three records, one without a bounds address, plus a fourth record past the count, which must stay untouched, as must the bytes past each header.
  • GetBVHCompactedSize in its three modes (mode at table+0x20, header address at +0x18):
    • mode 1: (n + 1) << 6 as a u64;
    • mode 2: adds (8 * K + 0x137) & ~0xff and writes K. Two cases: K is the header's word 3 when word 0 isn't negative, and 0 when it is;
    • mode 3: writes (n + 1) << 2 and n + 1 to two other outputs.

Since one program now has several inputs, CHECKED keys can be Program:case. The temporary files replace the :, which on NTFS would name a stream, not a file.

Tested

AMD Radeon RX 9070, Windows 11:

docs/embedded_shaders.md §5/§6 updated. Counts and statuses only; nothing from the package is included.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — pass (CPU only, no game files).

Environment: Windows 11, CPython 3.15.2.

  • The PR's test: 12/12; parent bvh_gpu_smoke.py errors 1 (InitHeaders/GetBVHCompactedSize uncovered)

AI-assisted (Devin).

@kotekompotek

Copy link
Copy Markdown

Independent Windows CPU verification on 361a3ba4:

  • python -m pytest tests/test_bvh_gpu_smoke.py --basetemp D:\temp\pytest_tmp -q: 12 passed in 1.69s

Dom-in and others added 2 commits November 23, 2026 12:21
…fix sums

The runner now sets VKC_SUBGROUP_SIZE from index.json's wave64 flag, as
check.py does: a wave64 program left to the device's default may run 32 wide.
PrefixSum64..PrefixSum4096 are checked against their exclusive scan and total.
On main the five wave64 ones fail at element 128 or 256 (a VOP3 lane mask
printed as s6 for s[6:7], fixed by ItsNotRexed#3910); with ItsNotRexed#3910 all twelve checked
programs match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InitHeaders fills a 64-byte BVH header per 40-byte record and an empty box where
a record has a bounds address; GetBVHCompactedSize computes a compacted size in
three modes. Five new --checked cases ("Program:case" for several inputs to
one program) compare every byte they write and the bytes they must leave alone.
All five match on an RX 9070; with global_store_dwordx4 or s_addk_i32 skipped in
the translator the dependent cases fail. Temporary files no longer carry the
case's ':' (an NTFS stream name on Windows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 0da85f6f merged onto main 561b65a8 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I tests/test_bvh_gpu_smoke.py: 12 tests OK.
  • Negative control (tools/bvh_gpu_smoke.py from main, the PR's tests kept): tests/test_bvh_gpu_smoke.py 12 tests FAILED (errors=1).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0da85f6 merged with main 28f8653 on Linux/Python 3.12.16: pass. The merge is clean and tests/test_bvh_gpu_smoke.py passes (its demo run reports 1 of 1 pass). Negative control: with tools/bvh_gpu_smoke.py and the test file reverted to main, the run errors out; restored afterwards.

@jebaczydow

Copy link
Copy Markdown

Read the diff (not run). Two small points on the new GetBVHCompactedSize cases:

  1. In _compacted_case (H4, H12 = 37, 9) the mode-2 sum is ((H4 + 1) << 6) + ((8 * K + 0x137) & 0xFFFFFF00). For K = 9 that is 89 + 0x137 = 0x17F -> 0x100, and for the negative case (K = 0) it is 0x137 -> 0x100. So the summed value at OUT is identical in both cases and the 8 * K term has no effect on it; only the separate K store at OUT + 8 differs. A translator that got the 8 * K multiply wrong in the sum but stored K correctly would still pass. The term first changes the masked value at K = 26 (826 + 0x137 = 0x207 -> 0x200), so an H12 of 26 or more (e.g. 40) would exercise it.

  2. PREFIX_DATA = 0x10000 plus the 16 KiB PrefixSum4096 input means --checked needs a heap of roughly 0x14000 bytes or more, but main() still only requires heap_bytes >= TABLE_QWORDS * 8. The unit test used heap_bytes=1 << 16 before this PR and now uses 1 << 18, so 64 KiB used to fit. With an explicit small --heap-bytes, struct.pack_into at PREFIX_DATA would raise struct.error instead of a clean ap.error. The default is 1 MiB, so only explicit small values hit it; I have not run it.

AI-assisted (Claude); code read only, nothing run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants