DirectStorage: inflate zlib requests with zlib-rs #1722

Open
github-bot wants to merge 1 commit from github-bot/gh-1722 into main AGit
Owner

@⁠gbuyssens on GitHub · 2026-11-24 19:54 UTC · original
gbuyssens:main → main · +45 −1 · 3 files · 1 commits · draft

DirectStorage's zlib stage decodes with zlib-rs instead of miniz_oxide. Titles stream thousands of 64 KiB zlib blocks at start-up (the retail title I test: ~9 800 file requests in its first load, ~650 MB inflated), and zlib-rs decodes them about twice as fast. The behaviour does not change. Related: #661 speeds up only miniz_oxide's Adler-32 (5.7 %); this replaces the decoder in this path, so #661 would no longer matter for DirectStorage.

What is in it

  • crates/xcl/src/hle/dstorage.rs: inflate_zlib(src, limit) wraps zlib_rs::inflate::uncompress_slice with the same rules as the miniz call it replaces (output limited to the destination or intermediate size, E_ZLIB_DATA on a wrong Adler-32, a cut stream or more output than the limit, a shorter stream returned as is for BCPack's lenient case, bytes after the stream's end ignored), plus a unit test of each rule.
  • crates/xcl/Cargo.toml, Cargo.lock: zlib-rs 0.5.5 (Zlib licence, pure Rust, no dependencies). The other miniz_oxide uses (shader packs, PNG, tests) are left as they are.

Tested

  • RTX 3060 (driver 32.0.16.2101), i5-9600K, 32 GB, Windows 11 Pro 26300, Rust 1.98.0 MSVC; debug for the suite, release for timing and the title.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 859 passed, 0 failed, 42 ignored (main c160d86: 858 / 0 / 42; the one more is the new test). SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

  • Decode speed, release, 64 KiB blocks compressed at level 6, 20 passes × 3 rounds, all outputs checked against the input:

    blocks miniz_oxide (current) zlib-rs
    400 cut from a game executable (52 % ratio) 210–226 MB/s 407–433 MB/s
    127 cut from a release xcl.exe (38 % ratio) 180–274 MB/s 494–514 MB/s

    The same harness checked the edge cases on all decoders: trailing padding, bad Adler-32, a limit one byte short, a limit larger than the stream.

  • Retail title, scripts/smoke.ps1 -Seconds 90, release builds, main c160d86 and this PR alternating, 9 runs after a warm-up: no crash or device removal in any run. On this title the start-up is not bound by inflate: in the runs that started fast, the first 9 000 requests completed at 12.3 / 12.9 s (main) and 13.0 / 11.9 s (PR). The title also has a slow start-up mode in both builds (first PresentX at 15–31 s instead of ~4 s), which makes frames and peak commit follow how far the title got rather than the build.

Regression run

main (run 1, back to back with the PR's run 1):

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 3060
title: MyDump
seconds: 90
exit: 0x0
frames shown: 2395 (PresentX 2395)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14593 MB

PR:

xcl-smoke v1
commit: e51814e921aec8c89b2c75cac2c38a7111ca8a73
gpu: NVIDIA GeForce RTX 3060
title: MyDump
seconds: 90
exit: 0x0
frames shown: 2424 (PresentX 2425)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 9738 MB

Not tested

  • A start-up speed-up on a title: the one I have is not inflate-bound, so the gain shown is CPU time per request, not load time.
  • AMD / Intel CPUs, and a cold disk cache (the package was in the file cache).
  • Real title blocks in the decode benchmark (blocks were cut from executables and recompressed, not read from DirectStorage requests).

Ruled out: libdeflate decoded the same blocks faster (540–685 MB/s), but its Rust binding (libdeflater) is Apache-2.0 only, which GPL-2.0 does not allow. Decoding with miniz_oxide into an exact-size buffer instead of a growing Vec gave nothing measurable (181–274 MB/s).

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, its test and the decode benchmark, ran the suite and the smoke runs, and drafted this description.

🤖 Generated with Claude Code

**@⁠gbuyssens** on GitHub · 2026-11-24 19:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1722) `gbuyssens:main` → `main` · +45 −1 · 3 files · 1 commits · draft DirectStorage's zlib stage decodes with zlib-rs instead of miniz_oxide. Titles stream thousands of 64 KiB zlib blocks at start-up (the retail title I test: ~9 800 file requests in its first load, ~650 MB inflated), and zlib-rs decodes them about twice as fast. The behaviour does not change. Related: #661 speeds up only miniz_oxide's Adler-32 (5.7 %); this replaces the decoder in this path, so #661 would no longer matter for DirectStorage. **What is in it** - `crates/xcl/src/hle/dstorage.rs`: `inflate_zlib(src, limit)` wraps `zlib_rs::inflate::uncompress_slice` with the same rules as the miniz call it replaces (output limited to the destination or intermediate size, E_ZLIB_DATA on a wrong Adler-32, a cut stream or more output than the limit, a shorter stream returned as is for BCPack's lenient case, bytes after the stream's end ignored), plus a unit test of each rule. - `crates/xcl/Cargo.toml`, `Cargo.lock`: `zlib-rs` 0.5.5 (Zlib licence, pure Rust, no dependencies). The other miniz_oxide uses (shader packs, PNG, tests) are left as they are. **Tested** - RTX 3060 (driver 32.0.16.2101), i5-9600K, 32 GB, Windows 11 Pro 26300, Rust 1.98.0 MSVC; debug for the suite, release for timing and the title. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: **859 passed, 0 failed, 42 ignored** (main `c160d86`: 858 / 0 / 42; the one more is the new test). SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - Decode speed, release, 64 KiB blocks compressed at level 6, 20 passes × 3 rounds, all outputs checked against the input: | blocks | miniz_oxide (current) | zlib-rs | |---|---|---| | 400 cut from a game executable (52 % ratio) | 210–226 MB/s | 407–433 MB/s | | 127 cut from a release `xcl.exe` (38 % ratio) | 180–274 MB/s | 494–514 MB/s | The same harness checked the edge cases on all decoders: trailing padding, bad Adler-32, a limit one byte short, a limit larger than the stream. - Retail title, `scripts/smoke.ps1 -Seconds 90`, release builds, main `c160d86` and this PR alternating, 9 runs after a warm-up: no crash or device removal in any run. On this title the start-up is not bound by inflate: in the runs that started fast, the first 9 000 requests completed at 12.3 / 12.9 s (main) and 13.0 / 11.9 s (PR). The title also has a slow start-up mode in both builds (first PresentX at 15–31 s instead of ~4 s), which makes frames and peak commit follow how far the title got rather than the build. **Regression run** main (run 1, back to back with the PR's run 1): ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 3060 title: MyDump seconds: 90 exit: 0x0 frames shown: 2395 (PresentX 2395) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14593 MB ``` PR: ``` xcl-smoke v1 commit: e51814e921aec8c89b2c75cac2c38a7111ca8a73 gpu: NVIDIA GeForce RTX 3060 title: MyDump seconds: 90 exit: 0x0 frames shown: 2424 (PresentX 2425) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 9738 MB ``` **Not tested** - A start-up speed-up on a title: the one I have is not inflate-bound, so the gain shown is CPU time per request, not load time. - AMD / Intel CPUs, and a cold disk cache (the package was in the file cache). - Real title blocks in the decode benchmark (blocks were cut from executables and recompressed, not read from DirectStorage requests). Ruled out: libdeflate decoded the same blocks faster (540–685 MB/s), but its Rust binding (`libdeflater`) is Apache-2.0 only, which GPL-2.0 does not allow. Decoding with miniz_oxide into an exact-size buffer instead of a growing Vec gave nothing measurable (181–274 MB/s). **AI use** - Claude Code (Claude Opus 5.5) wrote the change, its test and the decode benchmark, ran the suite and the smoke runs, and drafted this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Titles stream thousands of 64 KiB zlib blocks through DirectStorage at
start-up (the retail title tested: ~9 800 requests in its first load).
miniz_oxide decoded them at 210-270 MB/s on an i5-9600K; zlib-rs decodes
the same blocks at 410-515 MB/s (400 blocks cut from a game executable
and a release xcl.exe, compressed at level 6, 20 passes, 3 rounds).

The behaviour is unchanged: the output is limited to the destination or
intermediate size, a wrong Adler-32, a cut stream or more output than
the limit fail with E_ZLIB_DATA, a shorter stream is returned as it is
(BCPack's lenient case), and bytes after the stream's end are ignored.

Ruled out: libdeflate was faster still (540-685 MB/s), but its Rust
binding is Apache-2.0 only, which GPL-2.0 does not allow. Decoding with
miniz_oxide into an exact-size buffer instead of a growing Vec gave
nothing measurable. zlib-rs is pure Rust, Zlib licence, no dependencies.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:42 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 22:28 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 22:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1722#issuecomment-7146280121) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
Author
Owner

@⁠humsterbumster on GitHub · 2026-11-25 01:32 UTC · original

Independent test report from a Linux/NVIDIA machine (this is a test report, not a code PR).

Tested (patch applied with git cherry-pick -n e51814e onto main aa9ab8a: no conflicts; zlib-rs 0.5.5 resolved from crates.io):

  • Cross build cargo build --workspace --release --target x86_64-pc-windows-gnu (Rust 1.100.0): OK, xcl.exe built.
  • cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run, then the lib test binary under Proton 11 Wine (RTX 5090, NVIDIA 620.73.04): 125 tests printed ok, 0 FAILED, then the binary exits 3 mid-run in gpu::dxil::ops_tests — the same exit this machine's main builds show (batch logs: 19 binaries, 15x rc=0, 3x rc=101, 1x rc=3), so no new failure.
  • Retail title 1.0.2.1 (Xbox GDK build) start-up: same as main — menus at 60 presents per 2 s (30 fps), same log lines, no new warnings from the zlib path.

Not tested: Windows-native run, BCPack/BC7 paths (unchanged by this PR), and a long streaming soak.

A caveat on the retail numbers: this machine's copy of the title's shaders.rpf currently fails the torrent's own SHA-1 on two pieces, so 49 DirectStorage zlib requests fail with 0x89240032 (E_ZLIB_DATA) at the same file offsets with miniz_oxide and with zlib-rs. That is corrupt local data, not this PR: the block at one of those offsets inflates to 62,588 B and then reports a truncated/Adler-invalid stream. I will re-run a clean retail streaming pass once the package verifies.

AI use: omp (DeepSeek V4.1 Flash 1017) ran the build, the test binary and the retail run and wrote this report.

**@⁠humsterbumster** on GitHub · 2026-11-25 01:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1722#issuecomment-7149660958) Independent test report from a Linux/NVIDIA machine (this is a test report, not a code PR). **Tested** (patch applied with `git cherry-pick -n e51814e` onto `main` aa9ab8a: no conflicts; `zlib-rs 0.5.5` resolved from crates.io): - Cross build `cargo build --workspace --release --target x86_64-pc-windows-gnu` (Rust 1.100.0): OK, `xcl.exe` built. - `cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run`, then the lib test binary under Proton 11 Wine (RTX 5090, NVIDIA 620.73.04): 125 tests printed `ok`, 0 `FAILED`, then the binary exits 3 mid-run in `gpu::dxil::ops_tests` — the same exit this machine's main builds show (batch logs: 19 binaries, 15x rc=0, 3x rc=101, 1x rc=3), so no new failure. - Retail title 1.0.2.1 (Xbox GDK build) start-up: same as `main` — menus at 60 presents per 2 s (30 fps), same log lines, no new warnings from the zlib path. **Not tested**: Windows-native run, BCPack/BC7 paths (unchanged by this PR), and a long streaming soak. **A caveat on the retail numbers**: this machine's copy of the title's `shaders.rpf` currently fails the torrent's own SHA-1 on two pieces, so 49 DirectStorage zlib requests fail with `0x89240032` (E_ZLIB_DATA) at the same file offsets with `miniz_oxide` and with `zlib-rs`. That is corrupt local data, not this PR: the block at one of those offsets inflates to 62,588 B and then reports a truncated/Adler-invalid stream. I will re-run a clean retail streaming pass once the package verifies. **AI use**: omp (DeepSeek V4.1 Flash 1017) ran the build, the test binary and the retail run and wrote this report.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1722/head:github-bot/gh-1722'
git switch 'github-bot/gh-1722'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1722'
git switch 'github-bot/gh-1722'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1722'
git switch 'github-bot/gh-1722'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1722'
git switch 'main'
git merge --squash 'github-bot/gh-1722'
git switch 'main'
git merge --ff-only 'github-bot/gh-1722'
git switch 'main'
git merge 'github-bot/gh-1722'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.