Repository navigation
Conversation
tools/render_buckets.py streams every rpf9dump models manifest's Items (the levels manifest is several GB), enumerates archives with os.listdir, checks each archive's total against the manifest's Count, and counts RenderBucket & 0x7F, bit 7, values outside 0-6 and distinct shader hashes per bucket, per material and per unique model. docs/models.md gets the whole-export table next to the 3,000-model sample; the RenderBucketMask rule stays sample-only (the field is not in the manifests). Synthetic tests only; counts only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
At On Windows 11, save each line below as a separate file. Run {"Count":2,"Items":[{}]}
{"Items":[{}],"Count":2}The first file reports one item and a declared count of two. The command exits with code 1. The second file prints Please read the top-level count in either position. Keep the incremental read of the items. All 10 tests in AI-assisted. |
…tsNotRexed#4946) iter_items returned at the closing bracket of Items, so a top-level Count after Items was never read. After Items closes it now parses the remaining top-level members one by one (a Count nested in a later value doesn't count), keeping the incremental read of the items. Tests cover Count before and after Items, a nested Count after Items, small read chunks, and the exit code on a mismatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @shdann, confirmed and fixed in
AI-assisted. |
|
Approve, with notes. 10/10 new tests pass ( Notes:
AI-assisted review, no game files. |
kacper-serewis
left a comment
There was a problem hiding this comment.
At b11d450 the streaming reader accepts { "Count":2,"Items":[{}{}] despite the missing separator and unfinished object. On valid JSON, a mismatched Count after Items also passes. Please validate separators and the enclosing object, and check Count in either order (tools/render_buckets.py:36). The archive report at line 149 also overwrites earlier entries with the same archive label while including all their rows in the total. Please retain unambiguous labels or reject collisions. The bucket arithmetic itself matched our independent Windows CPU count across 11 cached manifests (14,631 model rows, 61,759 materials). All ten supplied synthetic tests passed. AI-assisted.
|
I checked the update at Run this from the repository root with from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess, sys
prefix = '{"Items":[{}],"Count":'
with TemporaryDirectory() as tmp:
path = Path(tmp) / "manifest.json"
for spaces in (0, (8 << 20) - len(prefix) - 1):
path.write_bytes((prefix + " " * spaces + "12}").encode())
result = subprocess.run([sys.executable, "-I", "tools/render_buckets.py", str(path)])
print("exit", result.returncode)On Windows, the first file reports one item and a count of 12 (exit 1). The second reports one item and a count of 1 (exit 0). Both files contain the same JSON value. All 12 existing tests pass. In AI-assisted. |
…earer unique counts (review on ItsNotRexed#4946) - A value after Items that reaches the end of the read buffer is read on before it is accepted: the digits of a Count split between reads gave a shorter number (shdann). Test sweeps every chunk size over a four-digit Count. - A material without a shader hash is counted on its own, not as a "none" hash. - Docstring and docs/models.md say exactly what a unique model is (the ordered material list: reordered materials count again, full collisions merge), that per-archive unique figures are first-seen-in-listing-order, and that the sample's "Shaders" column counts rows while the new column counts hashes (tupacfan04). Counts on the export are unchanged; 0 materials lack a hash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ffer The reader copied from render_buckets had the boundary case found in review on ItsNotRexed#4946: the digits of a top-level Count after Items, split between reads, were accepted as a shorter number. Same fix here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Both fixed in @shdann, the number split between reads: confirmed and fixed. @tupacfan04, thanks for the review. On your notes:
AI-assisted. |
|
I verified the split-number fix at I also measured a memory regression in the new trailing-count path. When Reproduce from the repository root with import gc, sys, tempfile, tracemalloc
from pathlib import Path
sys.path.insert(0, str(Path("tools").resolve()))
import render_buckets as rb
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "manifest.json"
failures = ",".join(['{"Offset":1234,"Reason":"synthetic"}'] * 400000)
for last in (False, True):
fields = ['"Items":[{}]', '"ModelDecodeFailures":[' + failures + ']']
fields.insert(2 if last else 0, '"Count":1')
path.write_text("{" + ",".join(fields) + "}", encoding="utf-8")
gc.collect()
tracemalloc.start()
rb.count([("a", str(path))])
print(last, tracemalloc.get_traced_memory()[1])
tracemalloc.stop()Please skip unrelated trailing values incrementally while looking for the top-level count. The probe measures parser allocations after fixture creation. It uses synthetic data only. AI-assisted. |
…eview on ItsNotRexed#4946) The reader now parses the top-level object member by member: Count is the top-level member wherever it stands, and a missing, doubled, leading or trailing comma in Items, an unclosed object or data after it raise ValueError; the CLI reports that and exits 2 (kacper-serewis). A second manifest with an archive label already used gets a numbered label, so per-archive entries no longer overwrite each other while both stay in the totals. Tests cover the malformed cases at several read sizes, top-level-only Count, and the label collision. Counts on the export are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same parser as render_buckets after review on ItsNotRexed#4946: top-level members parsed one by one, separators and the enclosing object checked. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @kacper-serewis. All three points are addressed as of
AI-assisted. |
|
The parser change at
The count-first case now uses 7.8 times the previous peak. The census does not use the failure records. At On Windows, AI-assisted. |
… (review on ItsNotRexed#4946) Members other than Items and Count (e.g. a large ModelDecodeFailures list before a trailing Count) were decoded into Python lists and dicts just to step over them (shdann). They are now skipped structurally: brackets must match and strings end, nothing is built. On shdann's 14.8 MB fixture the peak traced allocation is the same with Count first or last (about 29.6 MB, the read buffer). Tests cover the memory bound and malformed skipped values. Counts on the export are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @shdann, confirmed and fixed in
AI-assisted. |
Same change as render_buckets after review on ItsNotRexed#4946. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The memory fix works on the 400,000-record probe. Peak traced allocations at One validation regression remains. A missing comma between two failure records now lets the command report success. Save this line as {"Count":1,"Items":[{}],"ModelDecodeFailures":[{} {}]}Run In AI-assisted. |
|
@shdann, this one is covered by
The failure array is no longer decoded in either position. Members other than AI-assisted. |
|
Tested c9d14a9 merged with main 3faac55 (the PR head already contains it) on Linux (WSL2 Ubuntu 22.04) / Python 3.12.16,
|
kacper-serewis
left a comment
There was a problem hiding this comment.
The original malformed-root and duplicate-label findings are resolved at bf7ee136. One valid-input failure remains. For a standalone numeric metadata member, pad the JSON so the default 8 MiB read ends after the dot in 1.25, the e in 1e24, or the minus in 1E-2. Each exits 2, before or after Items. _Stream.value accepts the integer prefix before the remaining characters arrive. The same splits inside Items objects and skipped arrays pass. Please defer accepting a numeric prefix until a valid delimiter or EOF confirms the whole number. AI-assisted Windows CPU CLI review with synthetic inputs.
|
Independent check of Environment: Windows 11, CPython 3.15.2.
Caveat: AI-assisted (Devin). |
shdann found on ItsNotRexed#4980 that the shared reader accepted "1" from "1e3" when a read ended at the e. When the number characters run on to the end of the buffer, the reader now reads more before it accepts the number. Test sweeps every chunk size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One more fix at |
…ts uses it (review on ItsNotRexed#4946) tools/manifest_stream.py holds the reader both census tools need, with one rule in one place: a decoded value is accepted only when a terminator (, } ] :, or whitespace) is visible after it or the file has ended; otherwise it is read on and decoded again from its start. That covers every split the reviews found (digits, ".", "e", signs) and split literals and strings (kacper-serewis). Members other than Items and Count are validated without being built: commas, colons, keys and brackets are checked while discarding (shdann's missing comma between skipped records), with memory bounded. tests/test_manifest_stream.py reads 8 valid documents at every read size from 1 to their length and requires json.loads' result, rejects 44 invalid ones at every read size, checks the reviewers' splits at the default 8 MiB read, and bounds memory for a large skipped member. Counts on the export are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested e5fefc3 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass. Ran |
…ffer The reader copied from render_buckets had the boundary case found in review on ItsNotRexed#4946: the digits of a top-level Count after Items, split between reads, were accepted as a shorter number. Same fix here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flyander
left a comment
There was a problem hiding this comment.
Reproduced on head 5d4dc42f with a synthetic manifest:
{"Items":[{"Name":"x","Verts":1,"Tris":1,"Materials":[{"Shader":["bad"],"RenderBucket":0}]}],"Count":1}
Running python -I tools/render_buckets.py <manifest.json> raises an uncaught TypeError: unhashable type: 'list' at the model deduplication key. The code treats a non-string Shader as no_shader, but then appends the raw value to sig and uses it in seen; so a malformed field crashes instead of producing the tool's input error/report. Please sanitize or reject non-scalar shader values before building the signature and add a synthetic regression. No game data or GPU was used.
…d (review on ItsNotRexed#4946) A list or object as Shader, Name, Verts or Tris goes into the unique-model key as canonical JSON instead of crashing the set lookup; a model entry or material that is not an object, or Materials that is not an array, exits 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ffer The reader copied from render_buckets had the boundary case found in review on ItsNotRexed#4946: the digits of a top-level Count after Items, split between reads, were accepted as a shorter number. Same fix here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same parser as render_buckets after review on ItsNotRexed#4946: top-level members parsed one by one, separators and the enclosing object checked. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same change as render_buckets after review on ItsNotRexed#4946. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e loop without candidates The private copy of the streaming reader is gone: texture_dicts imports tools/manifest_stream.py from ItsNotRexed#4946 (one reader, exhaustively tested at every read size), so the two tools cannot drift apart. summarise() only walks the dictionary archives when a reference has a name-hash candidate (shdann's performance note). Numbers on the export are identical. Depends on: ItsNotRexed#4946 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @Flyander, reproduced and fixed in
Regressions: The published render-bucket numbers do not change: the export's |
…r's ItsNotRexed#4946 pattern) Manifest arrays read by the census must hold objects; a top level, model entry, material, texture or dictionary that is not one exits 2 instead of raising AttributeError. A non-string dictionary Name is no longer hashed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Flyander's ItsNotRexed#4946 pattern) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent CPU retest of
One remaining input-shape case: at |
|
Rechecked head |
|
Reviewed 26d3f79 (CPU, Linux, Python 3.13): 1 issue
No game files. |
|
The head |
|
Tested
|
|
Re-check of my earlier comment (tested c9d14a9, nested Count concern; my later pass was on e5fefc3): the head has moved to 26d3f79 and the concern is still resolved. Tested 26d3f79 merged with main 561b65a on Linux (WSL2), Python 3.12.16 (-I): pass. Repro from the concern, Tests: |
…lsy non-array is not "no materials" (review on ItsNotRexed#4946) - A decode error more than 8 characters before the buffer's end (and not an unterminated string), or a value followed by a non-terminator with more than 8 characters read after it, is a syntax error: raised at once instead of reading the rest of a several-GB manifest (tedin7). - Materials {} / "" / 0 / false is an input error; only absent or null means no materials (LILILI2007). - The docstring says the output is keyed by archive folder names (cynbun). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ffer The reader copied from render_buckets had the boundary case found in review on ItsNotRexed#4946: the digits of a top-level Count after Items, split between reads, were accepted as a shorter number. Same fix here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same parser as render_buckets after review on ItsNotRexed#4946: top-level members parsed one by one, separators and the enclosing object checked. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same change as render_buckets after review on ItsNotRexed#4946. Numbers unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e loop without candidates The private copy of the streaming reader is gone: texture_dicts imports tools/manifest_stream.py from ItsNotRexed#4946 (one reader, exhaustively tested at every read size), so the two tools cannot drift apart. summarise() only walks the dictionary archives when a reference has a name-hash candidate (shdann's performance note). Numbers on the export are identical. Depends on: ItsNotRexed#4946 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r's ItsNotRexed#4946 pattern) Manifest arrays read by the census must hold objects; a top level, model entry, material, texture or dictionary that is not one exits 2 instead of raising AttributeError. A non-string dictionary Name is no longer hashed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Flyander's ItsNotRexed#4946 pattern) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @tedin7, @LILILI2007 and @kapitche. Fixed in
Tests: |
|
Tested 5c17447 merged with main e0816d6 on Linux (WSL2), CPython 3.12.16: pass |
…Flyander's ItsNotRexed#4946 pattern) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASSET-396, claimed in the coordination issue: #4816 (comment)
What and why
docs/models.md("Shader render buckets") gives theRenderBucketsplit from a sample of 3,000 models (27,435 shaders). The export rule there (1 = blend, 2 = decal, 3 = alpha test, 6 = water) depends on it. This PR counts it over the whole export:tools/render_buckets.py(stdlib) streams everyrpf9dump modelsmanifest'sItems. The levels manifest is several GB, so it's read item by item. Archives are found withos.listdir, so dot-named folders aren't skipped, and each archive's item total is checked against the manifest'sCount. For each material it countsRenderBucket & 0x7F, bit 7, values outside 0-6, unreadable values and the number of distinct shader hashes per bucket. Counts are given per material row and per unique model (name + vertex and triangle counts + the ordered (shader, bucket) list), so a model repeated across dictionaries or archives counts once. It prints counts only, and--jsonrefuses to overwrite an input.docs/models.md: a whole-export table next to the sample table, without changing it.Result on my own Xbox Series 1.0.2.1 copy
Run on all ten manifests: 382,781 models (every archive matches its
Count; the same total as the decoded-model count elsewhere in the docs), 2,328,563 materials, 363,698 unique models.fc34f08b, as the sample said. Water uses three.Limits
RenderBucketMaskfield, so theRenderBucketMask == 0xFF00 | (1 << bucket)rule isn't re-checked and stays sample-only. The doc says so.Tested
Windows 11, Python 3.13, CPU only:
python -I tests/test_render_buckets.py: 10 tests, OK. They're synthetic manifests and cover streaming across small read chunks, dedupe across archives,Countmismatch, dot-named archives and the--jsonoverwrite guard.tests/test_docs_links.py,tests/test_tool_startup.pyandtests/test_docs_design_rows.py: OK.python -m compileall -q tools testsandgit diff --checkare clean.python -I tools/render_buckets.py <export dir> --json <report>on the export: 0.4 min, exit 0.No game data in the PR: synthetic fixtures only, and counts only in the doc. AI-assisted.
🤖 Generated with Claude Code