DirectStorage: inflate zlib requests with zlib-rs #1712

Open
gbuyssens wants to merge 1 commit from upstream-pr/1722 into main
gbuyssens commented 2026-11-24 19:54:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gbuyssens on 2026-11-24T19:54:40Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:5479287767 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1722). Originally posted by [gbuyssens](https://github.com/gbuyssens) on 2026-11-24T19:54:40Z. --- 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)
DavidM1911 commented 2026-11-24 23:08:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T22:28:51Z.


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

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

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7146280121 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1722#issuecomment-7146280121). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T22:28:51Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
humsterbumster commented 2026-11-25 02:08:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by humsterbumster on 2026-11-25T01:32:19Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7149660958 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1722#issuecomment-7149660958). Originally posted by [humsterbumster](https://github.com/humsterbumster) on 2026-11-25T01:32:19Z. --- 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.
Foniass commented 2026-12-01 06:35:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:35:31Z.


Triage (#1607) – head e51814e

No open or merged PR swaps the zlib inflater. #3325 parallelizes zlib requests and #661 (merged) sped up the checksums; neither changes the inflater.
zlib-rs is Zlib-licensed, which is compatible with GPL-3.0. The new dependency needs the reason given in the PR description (the speedup claimed in the doc comment is not measured in the diff).
inflate_zlib zero-fills a limit-sized buffer for every request, even when the stream is shorter. miniz_oxide's _with_limit grows its buffer as needed instead.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303048313 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1722#issuecomment-7303048313). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:35:31Z. --- **Triage (#1607)** – head e51814e No open or merged PR swaps the zlib inflater. #3325 parallelizes zlib requests and #661 (merged) sped up the checksums; neither changes the inflater. `zlib-rs` is Zlib-licensed, which is compatible with GPL-3.0. The new dependency needs the reason given in the PR description (the speedup claimed in the doc comment is not measured in the diff). `inflate_zlib` zero-fills a `limit`-sized buffer for every request, even when the stream is shorter. `miniz_oxide`'s `_with_limit` grows its buffer as needed instead. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1722:upstream-pr/1722'
git switch 'upstream-pr/1722'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1722'
git switch 'upstream-pr/1722'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1722'
git switch 'upstream-pr/1722'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1722'
git switch 'main'
git merge --squash 'upstream-pr/1722'
git switch 'main'
git merge --ff-only 'upstream-pr/1722'
git switch 'main'
git merge 'upstream-pr/1722'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1712
No description provided.