startup: decode BCPack DirectStorage requests into destination memory (Refs #1139) #1329
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1336"
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-24T08:28:12Z.
Refs #1139
Connect the multi-lane rANS decoder and BC7/BC1 block reconstruction to the DirectStorage stand-in (
xcrdapi.cpp).Changes
x2w_bcpack::decode_bcpackinsrc/startup_stubs/bcpack_decoder.hbacked by model and codebook tables insrc/startup_stubs/bcpack_tables.h(adapted from bcpack-rs by Ahmet Dedeler under MIT/Apache-2.0, with rANS intervals from Microsoft silicon-rans).src/startup_stubs/xcrdapi.cpp:bcpackformat 7 (BC7) or 1 (BC1) is requested, decode into destination memory.BCPack not decoded: zero-filledshortcut log line, setoutcome = "bcpack decoded", and incrementrequests_compressedinstead ofrequests_bcpack_blank.E_FAILwithout modifying destination memory.tests/startup_stub_consumer.cppverifying exact BC7 mode 6 block reconstruction and negative controls rejecting truncated streams.docs/startup-runtime.mdlimitation note.Reproduction and Verification
All tests pass 100% on Windows x64 (MSVC 19.51, CMake/Ninja).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:41:13Z.
Review: COMMENTED
Reviewed at commit
3795037eef8b8a85e7897be9429d58827c59c93b.Linux Checks
git diff --check origin/main...HEAD: passed (no whitespace/conflict-marker issues)./root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Checked 16 Markdown files and 286 links.)./root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Checked 1084 tracked source, script and build/CI files: no bidirectional controls.)./root/.local/share/x2w-rev-venv/bin/python -B tests/bcpack_check.py: passed (Ran 9 tests ... OK)./root/.local/share/x2w-rev-venv/bin/python -B tests/bcpack_symbols_check.py: passed (Ran 10 tests ... OK)./root/.local/share/x2w-rev-venv/bin/python -B tests/bc7_blocks_check.py: 8 passed, 2 skipped (Ran 10 tests ... OK (skipped=2)).Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)
--preset dev):startup_stub_consumer,startup_stub_acphal,startup_stub_chad,startup_stub_xapu,startup_stub_xcrdapi,startup_stub_xg_xs,startup_stub_gameinput):24.06s(configure1.44s)ctest --preset dev -R '^startup_stubs$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.40s)/O2(--preset release):36.46s(configure1.55s)ctest --preset release -R '^startup_stubs$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.47s)Code Review Notes
src/startup_stubs/xcrdapi.cpp: cleanly wiresx2w_bcpack::decode_bcpackfor formats 7 (BC7) and 1 (BC1), leaves unsupported formats on the zero-fill fallback (requests_bcpack_blank), incrementsrequests_compressedon decoded BCPack requests, and returnsE_FAILwithout modifying destination memory whendecode_bcpackfails.tests/startup_stub_consumer.cpp: exercises a 2-block BC7 Mode 6 decode (bcpack == 7) and a truncated-stream negative control (E_FAIL, destination0xCCuntouched). Gap:bcpack == 1(BC1),zlib + bcpackcombined requests, and unsupported-format fallback are not exercised instartup_stub_consumer.cpp.src/startup_stubs/bcpack_decoder.h:1i32 << prec) uses an MSVC-specifici32literal suffix instead of standard C++17 (std::int32_t{1} << prec).static_cast<uint32_t>(target_symbols_per_lane)) does not guard againsttarget_symbols_per_lane > UINT32_MAX.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:50:42Z.
Review: CHANGES_REQUESTED
The production path adds BC1 as well as BC7, but the new DirectStorage success case exercises only two mode-6 BC7 blocks. Please add a source-built BC1 success case and either bound BC7 to the demonstrated subset or add independent block/readback cases for the other accepted reconstruction paths. Also check a wrong destination size and a subsequent valid request after rejection, with output sentinels intact. For the translated decoder and generated tables, please pin the exact bcpack-rs and silicon-rans source revisions, identify any generated inputs, and retain the applicable upstream copyright and license notices in the tree. The header links and SPDX tags alone do not contain those notices.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T08:59:09Z.
Updated in commit
90e845613afd5c3cb3e17271a7a68d599e8f7800addressing the review findings:1. Flushed Fragment Home State Check
src/startup_stubs/bcpack_decoder.h: added check inphase1DRAIN-to-HDR0 transition: A flushed fragment must reach the rANS home state (0x1000000) before advancing to the next header; otherwise damaged/short fragments were silently accepted.run_bcpack_py_diff.py): 401/401 streams now agree (398 agree reject, 2 agree accept, 0 differ).2. DirectStorage Continuation Cache Scoping
src/startup_stubs/xcrdapi.cpp: added&& !bcpackto the chunk continuation caching check. BCPack requests represent single atomic multi-lane rANS texture payloads rather than chunk-split linear streams. Documented indocs/startup-runtime.md.3. Pinned Revisions, Notices & Table Verification
src/startup_stubs/bcpack_tables.h: pinnedbcpack-rsrevisionc55c5fad539644b8cf5a705051df214291763fc0(Ahmet Dedeler) and rANS revision5bf5cc56(silicon-rans).tools/_bcpack_rans/THIRD_PARTY_NOTICES.md: added MIT license text and file coverage forsrc/startup_stubs/bcpack_tables.handbcpack_decoder.h.tests/bcpack_tables_check.py: pure-Python test verifying C++ arrays againsttools/_bcpack_rans/bcpack_tables.py, table dimensions, 285 valid BC7 control codes, 255 BC7 dictionary entries, BC1 window/quad tables, and canonical SHA-256 (346464df83c8be00905672091f2c64ac2eb0bb02efa9074a78b7620956f362d7). Registered inCMakeLists.txt,.github/workflows/windows.yml, andAGENTS.md.4. Test Coverage (BC1 & Negative Controls)
tests/startup_stub_consumer.cpp:tools/_bcpack_rans/vectors/synthetic_11.json(64 blocks, 515 packed bytes, 512 destination bytes), verifying exact byte matching across all 512 bytes against the reference output.0x01): verifies that trailing junk fails decode (HResult != 0) and the destination sentinel (0xDD) remains untouched.5. C++ Cleanup & Diagnostics
src/startup_stubs/bcpack_decoder.h: replaced non-standard MSVC suffix1i32withint32_t{1}; removed unusedphase1parameter.src/startup_stubs/xcrdapi.cpp: documented thatrequests_compressedis logged underinflated=%ldfor compatibility withtools/startup/live_view.py.Evidence & Test Results
ctest --preset dev --no-tests=error -R '^startup_stubs$' -V: PASS (dstorage control: exit=0 ok,0.55s)ctest --preset dev --no-tests=error -R '^bcpack_' -V: PASS (3/3:bcpack_prefix_and_mip_tail,bcpack_rans_symbols,bcpack_tables)ctest --preset release --no-tests=error -R '^startup_stubs$' -V: PASS (0.33s)ctest --preset release --no-tests=error -R '^bcpack_' -V: PASS (3/3,1.57s)python -B tests/bcpack_tables_check.py: Ran 7 tests in 0.102s — OKpython -B tests/docs_links_check.py: Checked 16 Markdown files and 286 links — OKrun_bcpack_diff.py: 60/60 positive random streams match Rust reference bit-for-bit.run_bcpack_py_diff.py: 401/401 mutated streams match vendored Python behavior.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:48:48Z.
Review: APPROVED
The new mode 1 fixture and the per-mode differential results address the BC7 coverage request. I rebuilt
1fd5cfbaon Windows x64 and ranctest --preset release --no-tests=error -R "^(startup_stubs|bcpack_tables|bcpack_rans_symbols)$". All three passed. The startup fixture checks exact BC7 bytes, the unchanged destination when its size is wrong, and the subsequent valid request. The workflow change only registers the Python table check. This verifies the source-built decoder path in #1139. The actual startup failures remain tracked separately.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:06:40Z.
The Release storage and table checks passed locally at
90e84561. The BC1 fixture and generated-table notices address those parts of the review. Could you put the BC7 coverage of the 60-stream differential in the PR, with per-mode counts and whether the dictionary and residual paths were exercised, and add a small source-built BC7 case outside mode 6 to the checked-in tests? Also add the requested wrong-destination-size case, keeping the destination unchanged and a valid request after it. The table comparisons establish table contents separately from block reconstruction.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T09:17:02Z.
Added in commit
1fd5cfba3ceb3149ba5fc7fe840507a27eb2d85b:1. BC7 Coverage Analysis of the Differential Test Suite (60 Streams / 30 BC7 Streams)
Across the 30 BC7 streams (708 blocks) in the differential suite against the
bcpack-rsRust reference (run_bcpack_diff.py):unzigzag(d_byte)): 319 of 708 blocks have a non-zero endpoint residual delta (delta != 0), exercising the delta reconstruction equation.BC7_DICTIONARY): 712 endpoint references access dictionary entries across 217 distinct dictionary indices (out of 255 total); 470 references read prior block history (0 < r <= i), and 234 references read zero (r == 0).2. In-Repo Source-Built BC7 Case Outside Mode 6 (
tests/startup_stub_consumer.cpp)delta = -47), and dictionary lookups (er = 213,xr = 4).c2 5b 48 7a ea 84 a4 4b fd f7 15 87 90 c4 49 ac).3. Wrong Destination Size & Subsequent Valid Request
destination_size: enqueues the 2-block BC7 stream (32-byte payload) requestingdestination_size = 16.decode_bcpackrejects unconsumed stream bytes, the request fails withE_FAIL(hr1 != 0), and the destination buffer sentinel (0xBB) remains completely untouched.hr2 == 0) with destination memory populated correctly.Test Execution
ctest --preset dev -R '^startup_stubs$' -V: PASS (dstorage control: exit=0 ok,0.68s)ctest --preset release -R '^startup_stubs$' -V: PASS (0.35s)ctest --preset dev -R '^bcpack_' -V: PASS (3/3)ctest --preset release -R '^bcpack_' -V: PASS (3/3)