Skip to content

image_bvh_census: count the game's image_bvh call sites, descriptor fields and result-word reads - #4639

Open
shelbykb2 wants to merge 3 commits into
ItsNotRexed:mainfrom
shelbykb2:tools/image-bvh-census
Open

shelbykb2 wants to merge 3 commits into
ItsNotRexed:mainfrom
shelbykb2:tools/image-bvh-census

Conversation

@shelbykb2

Copy link
Copy Markdown
Contributor

Claimed in #4421 (comment).

What and why

tools/image_bvh_census.py counts how the game's shaders call image_bvh_intersect_ray / image_bvh64_intersect_ray: sites per form, the descriptor's fields at each site, and how the four result words are read. docs/design.md's Ray tracing row had no corpus counts for any of this. Counts, mnemonics and field values only; standard library only.

Counts (1.0.2.1 disassembly, 26,503 listings)

  • Sites: 716 in 64 CS: 638 32-bit form, 78 64-bit form.
  • Descriptor (PAL sq_bvh_rsrc_t fields), the same at all 716 sites: box_grow 0, box_sort_en 1, size all ones, triangle_return_mode 1, llc_noalloc 0, big_page 1, type 8. Word 0 is a literal at the 78 64-bit sites. The base field is not decoded here (Ray tracing: the first real core_bvh4 BLAS on a GPU (the descriptor base is the 256-byte-unit field) #3794 settles it).
  • Result words, on every path from the call:
    • 397 sites take v_rcp_f32 of word 1 and multiply word 0 by it (v_mul_f32 244, v_mul_legacy_f32 153); 335 of them also words 2 and 3.
    • The same 397 read sext(w1[31:16]) into v_mul_i32_i24; the product is compared with v_cmp_lt_i32 against -1 at 319 and v_cmp_gt_i32 against 0 at 78.
    • All 716 read the words as integers: 397 through the shift/or pack mnemonics, 319 through v_cmp_eq_u32 only.
    • No site reads a word as an undivided float, a memory operand or a select on every path.

So where the analysis can prove a read, the triangle words are only used as ratios over word 1 and by word 1's high half. That bears on #4202 and #3567: normalised and raw-scaled words look the same to such a reader, apart from rounding.

Limits

Tested (f86bab2 on d0835dd9)

  • python -m pytest -q tests/test_image_bvh_census.py tests/test_docs_*.py tests/test_ci_registration.py tests/test_text_write_line_endings.py tests/test_text_encoding.py: 48 passed. The 15 census tests use invented listings only.
  • Two full corpus runs (about 10 minutes each) give byte-identical JSON.
  • No GPU involved. No game data in the diff: fixtures are hand-written, outputs are counts.

AI-assisted (Claude Code; an Opus worker wrote the tool, I reviewed and re-ran it).

🤖 Generated with Claude Code

shelbykb2 and others added 3 commits November 22, 2026 20:39
…-word reads

tools/image_bvh_census.py walks forward from every image_bvh*_intersect_ray
call and classifies each read of the four result words as ratio (divided by
word 1), high_half (sext(w1[31:16]) into v_mul_i32_i24), raw integer, raw
float, raw other or select, on every path or on some paths only. An EXEC lane
rule (narrowing, else-half of a saved mask, restores, join values) hides a
definition only when it can prove the read's lanes ran the overwrite or never
held the definition. The descriptor SGPRs are decoded into PAL sq_bvh_rsrc_t
fields. Counts, mnemonics and field values only; synthetic tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…on 7

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ks on inner back edges

The summary now says, per category, how many sites have a some-paths read
before the next call in program order and how many have them all after a
later call. strip() also drops the saved-mask SGPRs, so a mask saved in one
pass of an inner loop cannot place a read in the next. The docs quote the
split instead of guessing causes, name the integer mnemonics, and no longer
mention word 0 (the base field belongs to ItsNotRexed#3794).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shelbykb2
shelbykb2 force-pushed the tools/image-bvh-census branch from f86bab2 to a049544 Compare November 23, 2026 03:44
@shelbykb2

Copy link
Copy Markdown
Contributor Author

Rebased on 7b7d73f8 after the merge round (the only conflict was in docs). Re-tested on the RX 6800: census, docs and registration tests 58 passed (no GPU involved). AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested a049544 merged with main 2d3369a on WSL2 Ubuntu, Python 3.12.16: pass for what runs without a game copy.

  • python -I tests/test_image_bvh_census.py: 15 tests OK; tests/test_docs_*.py OK.
  • Negative control: the tool is new, so with it absent the test cannot import it (ModuleNotFoundError: image_bvh_census); there is no earlier version to compare against.
  • The corpus counts in docs/bvh.md and docs/design.md need the game files and I did not check them.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at a04954471 on Windows 11: pytest tests/test_image_bvh_census.py -q -> 15 passed; git diff --check clean.

The new tools/image_bvh_census.py counts the game's image_bvh call sites, descriptor fields and result-word reads from disassembly, with the documented synthetic cases covering the counted shapes and the some-paths reads split by position. I cannot re-run it over the corpus here; the tool and tests are self-contained. No blocking issue.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly with current main (merge-tree re-run), compileall clean, tests/test_image_bvh_census.py passes 15/15 under python -I — and also passes cherry-picked straight onto main, so the three commits are not context-dependent. Docs compliance suites green; the census tool is stdlib-only, writes pin LF, and the corpus numbers in bvh.md/design.md are statistics over mnemonics, not game data. FYI the two red suites in the merged tree (test_joaat_agreement, test_rdna2_decode) are regressions on current main, not from these commits — see #4421. CI legs were pending at check time. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only 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.

4 participants