startup: decode BC3, BC4, and BC5 BCPack DirectStorage streams #1383
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1390"
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 Holastor on 2026-11-24T10:17:55Z.
Extend DirectStorage BCPack texture decompression in
src/startup_stubs/to support BC4 (12 lanes, single channel), BC5 (12 lanes, dual channel), and BC3 (12 lanes, BC4 alpha + BC1 color).Changes
src/startup_stubs/bcpack_tables_bcn.inl,src/startup_stubs/bcpack_tables.h):RANK_PAIR_BC4[64][2],RANK_PAIR_BC5[64][2],RANK_PAIR_BC3_ALPHA[64][2].RANK_QUAD_BC3_COLOUR[256][4].BC4_DICTIONARY,BC5_DICTIONARY,BC3_DICTIONARY.bcpack-rsrevisionc55c5fad539644b8cf5a705051df214291763fc0(Ahmet Dedeler,SPDX-License-Identifier: MIT OR Apache-2.0) alongside the vendored5bf5cc56files insrc/startup_stubs/bcpack_tables_bcn.inl,src/startup_stubs/bcpack_tables.h,tools/_bcpack_rans/README.md, andtools/_bcpack_rans/THIRD_PARTY_NOTICES.md.src/startup_stubs/bcpack_decoder.h):pack_alphaandpack_colourplusdecode_bc4_blocks,decode_bc5_blocks, anddecode_bc3_blockswith 256-entry history / format-dictionary lookup and residual delta summation.4,5, and3indecode_bcpack.src/startup_stubs/xcrdapi.cpp):4,5, and3in DirectStorage request decompression.tests/bcpack_tables_check.py: validate BC4, BC5, and BC3 table structure/ranges unconditionally (10 tests total) in addition to optionalout/bcpack-rs/datacomparison.tests/bcpack_encoder_check.cpp: extend synthetic roundtrip and window-mutation negative control to 250 streams across formats{1, 7, 4, 5, 3}(1..3000 blocks, testing non-zero deltas, dictionary refs, and 256-entry history wrap).tests/startup_stub_consumer.cpp&tests/startup_stub_check.py: mergeupstream/main(preserving BC6H format-6 zero-fill coverage), encode synthetic 3-block BC4/BC5/BC3 streams with non-zero residual deltas + dictionary/history refs viatests/bcpack_encoder.h, add 260-block wrap vectors (i = 259,r = 200), and add wrong/unaligned destination size negative controls (hr != 0with sentinel preservation) across 17 queued DirectStorage requests.Test Commands and Results
Measured at commit
25948ed9on Windows x64:Refs #1139
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:30:08Z.
Review: COMMENTED
Reviewed
43c036c6(startup: decode BC3, BC4, and BC5 BCPack DirectStorage streams).git diff --checkclean; 100% title-neutral;tools/_bcpack_rans/THIRD_PARTY_NOTICES.mdupdated for the BC3/BC4/BC5 tables and routines adapted fromAhmet-Dedeler/bcpack-rs.src/startup_stubs/bcpack_decoder.h: BC4 (1-channel 8B/block), BC5 (2-channel 16B/block), and BC3 (alpha + RGB565 colour 16B/block) decoders checkoutput_capacityandoutput_size % block_bytes == 0, clamp dictionary lookups (dict_idx < 255) and rank-table indices (& 63/& 255), and reuse the existingdecode_lanesrANS framing/trailing-byte guards.src/startup_stubs/xcrdapi.cpp: enables formats3,4,5alongside1and7.tests/startup_stub_consumer.cpp: adds 1-block BC4, BC5, and BC3 DirectStorage memory requests and byte-exact output checks (negative controls for wrong destination size, truncated stream, and non-zero trailing byte are already covered in the same batch).tests/bcpack_tables_check.py: 7 tests ran, 6 passed, 1 skipped (checksRANK_PAIR_BC4,BC4_DICTIONARY,RANK_PAIR_BC5,BC5_DICTIONARY,RANK_PAIR_BC3_ALPHA,RANK_QUAD_BC3_COLOUR,BC3_DICTIONARYagainstbc4.json/bc5.json/bc3.json).tests/docs_links_check.py: 16 Markdown files, 308 links checked.tests/bidi_controls_check.py: 1158 tracked files checked, no bidirectional controls.43c036c673ad2e02164c2adfecd1654ec6b629a9:--preset dev): 6/6 passed (startup_stubs0.53s,startup_storage_directory_batch0.14s,bcpack_tables0.25s,cpu_archive_sixteen_page_gpu_warp4.28s,cpu_archive_directory_gpu_warp9.83s,startup_heartbeat_commit30.19s)./O2(--preset release): 6/6 passed (startup_stubs0.39s,startup_storage_directory_batch0.16s,bcpack_tables0.23s,cpu_archive_sixteen_page_gpu_warp4.42s,cpu_archive_directory_gpu_warp9.99s,startup_heartbeat_commit30.18s).Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:32:31Z.
Review: CHANGES_REQUESTED
I rebuilt
43c036c6on Windows and all three Release checks passed: startup_stubs, bcpack_rans_symbols and bcpack_tables. The new runtime cases each decode one block, so none can check the newly added history lookup. Please add a small reference-generated multi-block case for each new format that makes a later block depend on an earlier block and exercises distinct lane/index values. Keep the exact expected bytes and the generator/reference revision with the cases. Also check that a malformed or wrong-size request for a newly handled format leaves its destination unchanged and a following valid request still succeeds.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T10:55:26Z.
Addressed review feedback in
cc47855c:tests/startup_stub_consumer.cppwith 2-block streams exercising 256-block history lookup (block 1 references block 0 with delta) and residual delta summation.0x5A) and that subsequent valid requests succeed (tested across 10 DirectStorage requests in the batch).Ahmet-Dedeler/bcpack-rsrevc55c5fad5396) intests/startup_stub_consumer.cpp.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T15:04:28Z.
Tables are structurally sound and the three
bcpack_*cases pass — I checked the shapes independentlyIndependent reviewer, not the author. Reviewed
cc47855c; nothing pushed to the branch.Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, Python from
out/pe-env.Independent structural check of the four new tables
I did not use your
bcpack_tables_check.pyfor this; I parsedbcpack_tables_bcn.inlmyself and asserted the shapes thedeclarations promise:
So each pair table has exactly 64 entries of two values in
0..7, and the quad table 256 entries of four values in0..3,with no ragged row and no value outside the 3-bit or 2-bit space. A single wrong row length or a stray
8would be asilent decoder bug rather than a build error, which is why I checked it separately from the fixture.
What I could not verify from here
The semantics of the rank tables — whether row
nreally is the rank pair or quad that 3-bit/2-bit codenselects inthe console stream. That needs either the format documentation or a reference encoder, and the PR description points at
the former. If the tables were derived from a published source, a one-line link next to each table would let a future
reviewer re-derive one row and trust the rest; that is the kind of check that catches a transposed table, which no
structural test will.
I also did not decode a BC3/BC4/BC5 stream end to end:
startup_stub_consumercovers that path, and it is outside what Ican drive without a fixture container.
Verdict
Reviewed
cc47855c. Builds clean, the threebcpack_*cases pass, and the four new tables satisfy the shapes and valueranges their declarations imply. The remaining question is provenance for the rank tables, which I would like to see
recorded rather than inferred.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:43:39Z.
Review: COMMENTED
Re-review of
cc47855c(one new commit,startup: add multi-block history and wrong-size tests for BC3/BC4/BC5, on top of43c036c6). PR is open and not a draft. Nothing was pushed to the branch.Previous findings
Requests from the earlier review round on
43c036c6(the review I posted earlier had no blocking findings; the open requests were the maintainer's change request):bc4_packed/bc5_packed/bc3_packedare now 2-block streams. I decoded them withtools/bcpack_symbols.py(all bytes consumed: 74/74, 96/96, 95/95) and re-assembled the blocks with an independent script that follows the reference crate's assembly rules (rank tables and dictionaries from the pinned reference data). Output matchesbc4_expected/bc5_expected/bc3_expectedbyte for byte. In all three, block 1 takes both its endpoint and index source from block 0 (history reference 1), and the lane values differ across lanes and blocks.Caveat, see New findings 1: the delta lane is zero in every vector, so the endpoint reference and the index reference are never different.
Expected bytes are present. The comment says "Generated using tools/_bcpack_rans reference encoder (Ahmet-Dedeler/bcpack-rs rev c55c5fad5396)", but
tools/_bcpack_ranshas no encoder, no generator script is committed, and the upstream decoder at that revision rejects all three streams (see New findings 2).Request 6 (8-byte destination, sentinel
0x5A, failing HRESULT) followed by valid requests 7-9 is a valid control. BC5 and BC3 have no request-level negative control. At decoder level I confirmed all three formats reject too-small / non-multiple output sizes, every truncated prefix, and a non-zero trailing byte (details below).With the pinned reference data present,
tests/bcpack_tables_check.pyconfirms all seven new tables equal upstream atc55c5fad(see Verified). The notice file now lists them. See New findings 3 for why CI cannot show this.Verified
Linux only. Python 3.14, g++ 14.2 (UBSan), MinGW g++ 14 (posix), Rust 1.90 for the reference crate. No LLVM tooling was needed (the change has no assembly).
git diff --check ea5884d3 cc47855c: clean.python3 tests/bcpack_tables_check.py: 7 tests, 6 pass, 1 skipped (the reference comparison, becauseout/bcpack-rs/datais absent).data/*.jsonfromc55c5fadcopied toout/bcpack-rs/data: 7/7 pass, soRANK_PAIR_BC4/BC5/BC3_ALPHA,RANK_QUAD_BC3_COLOURand the three dictionaries equal upstream.python3 tests/docs_links_check.py: 16 Markdown files, 308 links OK.python3 tests/bidi_controls_check.py: 1158 files, no bidirectional controls.bcpack_decoder.hincluded directly,-fsanitize=undefined -fno-sanitize-recover -D_GLIBCXX_ASSERTIONS, canary bytes around the output buffer, small shim for the MSVC intrinsic header):produced == output_sizewhenever it returns true.<intrin.h>): vectors OK, truncation checks OK.git restore):r - i - 1->r - i(BC5); history size 256 -> 128 (BC3); BC4erignoring the delta; BC5 / BC3 delta sign negated; BC3ertaken fromxr; dictionary guard< 255->< 254(unreachable in my corpus too, harmless).RANK_PAIR_BC4[0]changed from{7,7}to{7,6}: with reference data presentbcpack_tables_check.pyFAILS; without it the same run passes (1 skipped).get_sourcebounds (r <= ireadshist[(i-r)&255], dictionary index guarded,r == 0zero state),& 63/& 255clamps on rank lookups, alphabet widths per lane (match the referenceBC3/BC4/BC5_ALPHABET_BITS),output_size % block_bytes, and thatdecode_lanesbounds the symbol writes. I found no out-of-range read or write.New findings
[0,0]/[0,0,0,0]in all three streams, soer == xrfor every block. A decoder that ignores or mis-signs the delta passes all new runtime cases (mutations: BC4er = xonly, BC5 and BC3delta = -unzigzag(...), BC3get_source(xr, er_state)). The reference comparison I ran does catch them, so the decoder is correct today; the committed test would not notice a regression. Repro: apply the mutation, decode the committed vector, bytes are unchanged. Suggest one block with a non-zero delta ander != xr.bc4_packed,bc5_packed,bc3_packed. The comments attribute the streams to a reference encoder atc55c5fad, but the upstream decoder at that revision returnsNoProgressfor all three (74, 96, 95 bytes consumed, also with up to three zero bytes appended), while the repository's own decoder andtools/bcpack_symbols.pyaccept them. The lane symbols (0,1,2,..., 10,20,30,40) look hand-built. Please state the real generator and commit it or its parameters, or reword the comment.test_compare_with_reference_data_if_present, which is skipped whenout/bcpack-rs/datais missing..github/workflows/windows.ymlruns the script and nothing populates that directory (/out/is ignored), so a wrong row in the 1250-line.inlis not caught in CI (mutation above). The shape checks the other tables have (row count, value ranges) are not added for the new ones. Suggest structure tests that always run: 64 rows of two values in 0..7 for the three pair tables, 256 rows of four values in 0..3 for the quad table, 255 dictionary entries with the right ep/ix ranges.r > i) and the history wrap (i >= 256) are not exercised by the runtime test (mutations on offset, guard, and 128-entry history survive). The decoder is correct against the reference at 255/256/257/300/700 blocks; a regression test would need one larger stream.decode_length > destination_capacitybranch.bcpack_tables.h;bcpack_tables.hheader comment still lists only the old tables.tools/_bcpack_rans/README.mdstill says revision5bf5cc56for the vendored part while the tables are pinned toc55c5fad(not new, but now more visible).No P1 findings. No bounds, overflow, or undefined-behaviour issue found in the BC3/BC4/BC5 paths.
Not verified
tests/startup_stub_consumer.cppitself (the DirectStorage request path, status polling, 10-request batch) was not built or run: it needs the Windows toolchain and the stub DLL environment. I ran the decoder-level equivalents of requests 6-9 only.ctestpresets and the MSVC Debug/Release results quoted by the author and by the other reviewer were not reproduced.c55c5fadfrom its public repository. The one-line claim that the table semantics match the console stream (as opposed to the upstream crate) cannot be checked without console data.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:35:38Z.
Review: COMMENTED
Re-review of head
25948ed9a70dfa4204ca231e449bb6f6182f50a0(3 commits:43c036c6,cc47855c,25948ed9).Result
No P1, no P2. The BC3/BC4/BC5 decoding looks correct and matches the BC1/BC7 structure. Details below.
Commands executed locally (Linux)
git diff --stat origin/main...HEAD: 10 files, +1882/-59.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: self-test passed, 18 files, 407 links.python3 tests/bidi_controls_check.py: 1488 files, no bidirectional controls.python3 tests/bcpack_tables_check.py: Ran 10 tests, OK (1 skipped).tests/bcpack_encoder_check.cppbuilt with g++ (-std=c++17 -mavx2 -mpopcnt, with a local 10-lineintrin.hshim for_BitScan*):250 streams, 481841 bytes, 729376 symbols, 0 failed.--mutate windowcontrol: 250 failed, as expected.tests/startup_stub_consumer.cpp(lines 1581-1650), ran them throughdecode_bcpack, and compared with the expected bytes: all three equal.Mutations (each reverted with
git checkout -- .)bcpack_decoder.hxr_state->er_statei - r + 1)< 255->< 254Findings
src/startup_stubs/bcpack_decoder.h(get_sourcein the BC4/BC5/BC3 paths): the last dictionary entry (index 254,r - i - 1 == 254) is not hit by the 3-block vectors. Please confirm the 260-block wrap streams reach it, or add one block withr = i + 255.src/startup_stubs/bcpack_tables_bcn.inlheader: no author, URL or SPDX line, unlikebcpack_tables.h.tools/_bcpack_rans/README.md: revision5bf5cc56for the vendored part versus tables pinned atc55c5fad. Not new, but now more visible.Checks
/O2job skipped.Not verified
tests/startup_stub_consumer.cppand thexcrdapi.cpprequest path (dispatch now accepts formats 3, 4, 5) were not built or run here: they need the Windows toolchain. I did not run the Win2025 pipeline.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T05:45:29Z.
Review: APPROVED
Re-reviewed
25948ed9. The new BC3, BC4 and BC5 source-built runtime vectors distinguish endpoints and index history, include nonzero lane deltas, and cover the 256-entry history wrap. The wrong-size request leaves its sentinel in place and later requests still succeed. The existing format-6 zero-fill check remains. Windows Release startup_stubs, BCPack tables and symbols, and encoder round-trip and window mutation all passed (five CTests). The optional external table-data Python subcase skipped because the reference checkout was absent; the pinned source and the in-tree structure/range checks were reviewed.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-25T05:31:00Z.
Merged
upstream/mainand addressed all review findings in commit25948ed9:tests/startup_stub_consumer.cpp,tests/startup_stub_check.py):upstream/maincleanly; PR is nowMERGEABLE.Request 6(BC6H zero-fill check) and updatedtests/startup_stub_check.pyto expectformats=1:2 3:3 4:4 5:3 6:1 7:4; zero-filled formats=6:1.tests/startup_stub_consumer.cpp):er == xr) with 3-block synthetic BC4 (24B), BC5 (48B), and BC3 (48B) streams where every block has non-zero residual deltas, plus both dictionary references (r > i) and history references (r <= i).tests/startup_stub_consumer.cpp,tests/bcpack_encoder_check.cpp):Requests 14-16) for BC4, BC5, and BC3 referencing block200at block259, verifying byte0matches0x8b(256-entry window) rather than0x95(128-entry window).tests/bcpack_encoder_check.cppto test 250 synthetic streams across{1, 7, 4, 5, 3}(1..3000 blocks) and verify all 250 fail under--mutate window.tests/startup_stub_consumer.cpp):tests/bcpack_encoder.h(q=0,narrow=0,trim=false) with independently computed expected block bytes instead of attributing them tobcpack-rs.8B and non-multiple7B), BC5 (16B), and BC3 (16B) (Requests 7-10), checking non-zeroHRESULTand intact guard sentinels.tests/bcpack_tables_check.py,src/startup_stubs/bcpack_tables_bcn.inl,src/startup_stubs/bcpack_tables.h,tools/_bcpack_rans/README.md):test_bc4_tables_structure,test_bc5_tables_structure,test_bc3_tables_structure) that run even whenout/bcpack-rs/datais absent.Ahmet Dedeler,c55c5fad539644b8cf5a705051df214291763fc0,SPDX-License-Identifier: MIT OR Apache-2.0) above all 7 tables inbcpack_tables_bcn.inl, updatedbcpack_tables.h, and documented both5bf5cc56andc55c5fadintools/_bcpack_rans/README.md.Observed Verification at
25948ed9.\out\pe-env\Scripts\python.exe -B tests/bcpack_tables_check.py:Ran 10 tests in 0.242s - OK.\out\pe-env\Scripts\python.exe -B tests/bcpack_symbols_check.py:Ran 10 tests in 1.046s - OK.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py:Checked 18 Markdown files and 407 links(passed).\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py:Checked 1490 tracked source, script and build/CI files: no bidirectional controls(passed)ctest --preset dev --no-tests=error --output-on-failure -R '^(startup_stubs|startup_storage_directory_batch|bcpack_)' -V: 15/15 passed (Total Test time (real) = 22.34 sec), includingbcpack_encoder_roundtrip(250 streams, 0 failed),bcpack_encoder_window_control(250 failed as expected),bcpack_lanes_*,startup_stubs,startup_storage_directory_batch,bcpack_prefix_and_mip_tail,bcpack_rans_symbols, andbcpack_tables.