DirectStorage: bound BCPack record scratch memory #1069
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1078"
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 ivall/xcl. Originally posted by TG0000 on 2026-11-24T11:22:47Z.
BCPack now reconstructs tiles from batches of at most 64 records. The decoder used to keep all intermediate records until the input was consumed. The bounded buffer is 2 KiB on the stack and the existing reconstruction history stays on the heap.
What is in it
crates/xcl/src/hle/bcpack/victory.rskeeps lane read-ahead across batches, handles zero symbols directly, and retains the error precedence for malformed streams. Regression tests check exact bytes for all six widths, batch boundaries, and invalid input.28760f3), same file:batch_boundaries_match_the_previous_decoderand the// shortcut:note, which still applies toRecordStream::fill_batch, back.Tested
cargo test --release --locked --workspace --no-fail-fast -- --test-threads=4 --show-outputreported 741 passed, 3 failed, and 41 ignored. All three new tests passed. Two tests reported GPU skips because the D3D12 debug layer was unavailable.decoded_blocks_match_the_previous_decoder(128 bytes of each format) and the test below.28760f3):cargo test -p xcl --lib hle::bcpack: 10 passed, 0 failed.batch_boundaries_match_the_previous_decodercompares FNV-1a hashes ofbc1-700-2(63, 64, 65, 127, 128 and 129 blocks, and 700 blocks hashed per batch of 64) and ofbc1-8192-3with the output ofmain(47efa2e) for the same fixtures. They are synthetic (tests/data/bcpack/generate.py), no game data. It fails when the first record of each full batch is skipped, when the last one is dropped and when the last one is repeated (three builds); the constant-databatch_boundaries_preserve_lane_read_aheadpasses with the repeat.cargo clippy -p xcl --lib --tests: no warning on the changed lines. Not covered byte for byte past block 64: the formats with two symbols per block, because the only fixture over 64 blocks for them,bc7-700-2, has block errors; their lane stage is checked byfixtures_decode_to_their_lanes. Same machine as above.8cb6ba1) the 45-second RX 6800 smoke comparison showed 954 frames on main and 922 and 1027 on head. The selected runs exited cleanly with zero crashes and device removals.Regression run
On the head
28760f3and on main47efa2e(its merge base): one release build and one run each, from clean trees at those commits, the same title and 45 s. Other builds and tests ran on the PC during both runs, so the frame counts are not a timing comparison. Head: 1034 frames, main: 1027; peak commit 15131 MB against 15264 MB; no device removal and no crash.main:
PR:
Earlier runs, on
8cb6ba1(before the review follow-up), main then PR:Not tested
Gameplay FPS, retail BCPack throughput, NVIDIA GPUs, and Wine.
AI use
Codex with GPT 6.2 Sol implemented the patch, added the tests, ran validation, and drafted this description. Claude Code with Claude Sonnet 5.5 wrote the review follow-up commit (the boundary test and the restored note) and updated this description for it.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T12:32:34Z.
Review: COMMENTED
Review of
8cb6ba1against its merge base47efa2e(the tip ofmainwhen I read it), by reading the code; nothing of the PR was built or run here (one check below used a separate script over the tables onmain). I found no defect in the decoder. What I checked, and three smaller points about the tests and the description:crates/xcl/src/hle/bcpack/victory.rs:293-333,:339-358). A batch ends in the round wheredone == fulladvancespos, and in that rounddonebecomes 0 andmovedmakesidle0, so restartingpos,doneandidleat 0 for the next batch is the state the single loop onmainhad at that point. The lanes (latch,out,stalled,need,x,left) and the source iterator live in theRecordStream, so read-ahead carries over. The record indexrow[j * PER + pos % PER]is the oldrecords[pos / per * stride + j * per + pos % per], at most 31 in a 32-byte row.victory.rs:221-243). With ascending starts,slot < start[1]is the old bucket 0,1 + count(start[2..] <= slot)is the old bucket, and since the offset is below2^(b-1)the oldkequalsb, sostart[b] + offset * fis the old maskedc(it is at mostslot, so neither the mask nor the wrapping multiply did anything). I also compared the old and new(sym, f, c)in a separate script over the tables onmainfor all 128 models and all 65536 slots: no difference.victory.rs:127-132). After a block error the rest of the records are drained, so a stream that runs out anywhere still reports the lane error first, as onmain; a lane error ends the iterator (:350-353).dstcan now be partly written when the lane error comes late; the only caller (crates/xcl/src/hle/bcpack/mod.rs:63-66) drops it.stride; every reader takes fixed indices or bounded ranges (s[8..12],s[6..14],s[20..24],s[4..12],s[8..24],s[o..o + 2]), none depends on the slice length, and the bytes paststrideare never written and stay 0.CONFIRMED (tests, minor): the new byte-exact tests do not cross a batch boundary with varying data.
decoded_blocks_match_the_previous_decoder(victory.rs:1061-1096) decodes 128 bytes per format, 16 or 8 blocks, so it stays inside the first batch of 64.batch_boundaries_preserve_lane_read_ahead(victory.rs:1099-1104) usesbc7-8192-3, whose symbols are all zero (crates/xcl/src/hle/bcpack/tests.rs:18-30): all 4096 records are the same, and the same as a batch row that was never written. A record dropped, repeated or left unwritten at a boundary would pass it. What does cover the boundaries is the test that was already there,fixtures_decode_to_their_lanes(tests.rs:33-55), which now goes throughRecordStream(victory.rs:151-159) and comparesbc1-700-2,bc7-700-2andbc1-8192-3with their independent.lanesfiles, for both the one- and two-symbol paths. So the lane stage is covered; the block stage is not checked byte for byte past block 64 on anything but a constant output. Suggestion: addbc1-700-2(the plain formats have no block errors, so its random symbols decode) at 700 blocks against reference bytes or a hash frommain's decoder, and block counts of 63, 64 and 128.CONFIRMED (description): the byte-identity evidence is mostly outside the PR. "Every output byte matched, as did 3,610 truncated and junk cases" comes from a standalone benchmark that is not in the diff, so nobody else can rerun it; in the tree the claim rests on the tests of point 1. Also for the maintainer: Tested compares a workspace run on the head (741 passed, 3 failed, 41 ignored) with a library-only run on
main(695 passed, 21 ignored), so "the same three fail on main" is not the same command on both sides; the NVIDIA report in this thread has since run the whole suite at this head with 0 failed. TheCIworkflow showsaction_requiredat this head (not yet run), onlyPR checksis green. The regression blocks name47efa2eand the head and meet the frame and commit limits; the text mentions two head runs (922 and 1027 frames) and pastes the higher, both above 80 % of 954.CONFIRMED (scope, minor): two changes in one commit. The batching and the rewrite of the symbol lookup in
Lane::step(victory.rs:221-243) are independent; the second is a speed change to the rANS step that the title does not mention (the commit body does). It is correct as far as I can tell (see above), but it would have been easier to review on its own. The commit also drops the// shortcut:note above the oldlanesfunction (main,victory.rs:263-265) with the measured throughput and the plan for a faster split, which still applies.Overlap: #1047 (open, adds
crates/xcl/tests/dstorage_bcpack.rs) tests BCPack through the queue and does not touch this file; no other open PR changesvictory.rs.Verdict: no defects found; from the code this can be merged once
CIhas run on the head. Points 1 to 3 are improvements, not blockers.Review by Claude Code (written by Claude Fable 5.2, checked and edited with Claude Opus 5.5); each point checked by a person before posting.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T12:16:37Z.
Rerun on the new head
28760f362331607e9103ee5f2f0e35ef24754c8e(same machine, debug; the follow-up addsbatch_boundaries_match_the_previous_decoderonly):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 745 passed, 0 failed, 41 ignoredmain930e8b4(no conflict): 755 passed, 0 failed, 41 ignoredfill_batchstarting each batch atpos = 1(the first record of every batch skipped),batch_boundaries_match_the_previous_decoderfails, and so do three older tests (fixtures_decode_to_their_lanes,decoded_blocks_match_the_previous_decoder,truncated_lane_stream_takes_precedence_over_invalid_block). I did not try the dropped and repeated last record.hle::bcpack+hle::dstoragetests, 10 runs: 10 of 10 passed (24 each)The first run, on
8cb6ba1, follows unchanged.NVIDIA run, since Not tested lists NVIDIA. The change is CPU-side; this machine also has the D3D12 debug layer, so the two GPU tests your run skipped ran here.
Tested
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.178cb6ba1a508a504a5fb23166db037f8d9ee32ed1, which is on currentmain47efa2e(so also the merged result):cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 744 passed, 0 failed, 41 ignoredcargo build --release --workspace, thencargo test --release --workspace --no-fail-fast -- --test-threads=4: 744 passed, 0 failed, 41 ignoredplaced_title_textures_share_vram_and_preserve_pixelsand the two on its lock) pass here, andtest_title_draws_with_a_root_signature_under_the_debug_layeranduploads_start_from_each_subresources_stateranstreaming_tests::decoded_blocks_match_the_previous_decoder,batch_boundaries_preserve_lane_read_ahead,truncated_lane_stream_takes_precedence_over_invalid_blockhle::bcpack+hle::dstoragetests (the BCPack fixtures, junk / truncated streams, and the DirectStorage BCPack paths), 10 runs: 10 of 10 passed (23 tests each)gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwarexcl_testtitle.exe), also hadlist_x::tests::cross_queue_cycle_and_same_queue_fifo_do_not_deadlockfail once withE_OUTOFMEMORYwhile the machine was busy compiling. The clean rerun above passed it, and it doesn't touch BCPack.Not tested
AI use
Imported from ivall/xcl. Originally posted by TG0000 on 2026-11-24T13:58:54Z.
Thank you for the careful review. I checked each point against the code.
Pushed
28760f3on top of8cb6ba1(no force push):batch_boundaries_match_the_previous_decoderhashes the output ofbc1-700-2at 63, 64, 65, 127, 128 and 129 blocks (and at 700 blocks, per batch of 64) and ofbc1-8192-3, against whatmain(47efa2e) decodes from the same fixtures. They are synthetic (made bygenerate.py), no game data. It fails when the first record of a full batch is skipped, when the last one is dropped, and when the last one is repeated; the constant-data test still passes with the repeat. Formats with two symbols per block are not covered byte for byte past block 64, becausebc7-700-2has block errors; the description says so.mainwas the library tests only, not the same command as on the head, and that the byte-identity benchmark is not in the diff.// shortcut:note is back onRecordStream::fill_batch, where it still applies. I left the symbol lookup change in this PR rather than rewrite history.Tested:
cargo test -p xcl --lib hle::bcpack: 10 passed, 0 failed.cargo clippy -p xcl --lib --tests: no warning on the changed lines. Update:xcl-smokeblocks for the new head28760f3and for main47efa2eare now in the description (1034 and 1027 frames, no device removal or crash; other work ran on the PC, so not a timing comparison).AI-assisted: this follow-up was written and tested by Claude Code with Claude Sonnet 5.5.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T14:06:29Z.
Follow-up at
28760f3. I read the diff only; nothing was built or run here.batch_boundaries_match_the_previous_decoder(victory.rs:1122-1156) checksbc1-700-2at 63-65 and 127-129 blocks, each batch of 64 over 700 blocks, andbc1-8192-3, so a record dropped or repeated at a batch end now fails it. I did not recompute the hashes. The 64-block hash and the first per-batch hash of the 700-block decode are the same value, as they should be. The two-symbol formats past block 64 are still not covered byte for byte, and the description now says so.main's run is named as library-only, and the benchmark as outside the diff.// shortcut:note is back abovefill_batch(victory.rs:293-296). The symbol-lookup change stays in the first commit, as you chose.PR checksnow fails at28760f3because the Regression run block names8cb6ba1, and the check wants anxcl-smokeblock made on28760f3.CIshowsaction_requiredat this head, so it has not run yet.Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-24T15:17:47Z.
Linux (Wine + vkd3d-proton) + NVIDIA check: the tests of the current head
28760f3pass under Wine, and in one 100 s run of a retail title with8cb6ba1, the head before it, every BCPack request still unpacked (2,442 requests, 0 failed), as onmainin the run beside it (2,379, 0 failed).Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch. RTX 4070 12 GB (driver 615.71.09), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to
x86_64-pc-windows-gnu(rustc 1.98.0),XCL_NETWORK=0,XCL_PSO_PRELOAD=0. Retail title 1.0.2.1, the first-run screens completed once and no story progress, one A press at 44.8 s throughXCL_PRESS_AT. Each head merged ontomain67a3735+ #684 (e56dbc3) without conflicts; 1 run of the base and 1 of8cb6ba1.28760f3adds a test and a comment to8cb6ba1and no decoder code, so I did not repeat the run.Tested
cargo test --release -p xcl --lib bcpackunder Wine, with28760f3merged: 14 passed, 0 failed,batch_boundaries_match_the_previous_decoderamong them (13 of 13 on8cb6ba1).bcpack_unpackedinreport.json67a3735+ #6848cb6ba1The request counts differ by a few percent between any two runs here, because a run is cut at 100 s while the world is still loading; I did not compare the unpacked bytes of the two builds.
Not tested: the decoder's memory use or speed, which is what this change is for; whether the textures look the same (no run of ours reaches a frame of the world); the rest of the test suite; AMD and Intel.
AI use: Claude Code (Claude Fable 5.2) read the diff, built the tree, ran the tests and the two runs and wrote this note.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T08:51:20Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:40:42Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:46:36Z.
Triage (#1607) – head
28760f3No open or merged PR makes the same change. On main, victory.rs:decode still allocates
blocks * stridebytes of records before reconstructing the blocks; this PR streams them in batches of 64 records.The Lane::step symbol lookup rewrite gives the same symbol and the same
cas before (offset*f + start[b] stays below 2^16 inside a bucket), but it is a separate decoder change from bounding scratch memory. It could be its own commit. The PR conflicts with main (ec5c3e21precomputed BCPack bit packing in the same file).Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.