DirectStorage: zlib requests inflate with the runtime's native zlib #59

Manually merged
github merged 1 commit from gh-pr/59/head into gh-pr/59/base 2026-11-27 03:16:13 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-26 13:01 UTC · original
Sr-0w:storage/native-zlib → main · +257 −3 · 4 files · 1 commits · merged 2026-11-26 13:42 UTC

What

DirectStorage zlib requests now inflate with the zlib-ng that the .NET runtime ships (System.IO.Compression.Native), not with the managed ZlibInflater. NativeZlibInflater calls the runtime's own exports, the ones ZLibStream calls:

  • one inflate state per queue, reset for each request;
  • the output goes into a reused buffer, so a request allocates nothing;
  • a request must still produce exactly its DestinationSize and end there, with the Adler-32 checked.

The exports are internal to the runtime. If they are missing, or the state fails a known stream when the queue is created, the queue falls back to ZlibInflater.

Why

On a retail game's loading screens (RX 7800 XT, game data on a SATA SSD):

  • the frame rate was about 1 fps;
  • the GPU was busy about 1 ms per frame;
  • the game's threads were blocked more than 95% of the time.

I timed each request on the queue workers over the first 15 minutes of a boot (local instrumentation, not part of this PR):

step time data
zlib inflate 320 s 10.4 GB
BCPack decode 64 s 0.5 GB
waiting for reads 22 s
sink writes 3 s

Inflate speed on 256 KiB chunks, measured on the same machine:

managed ZlibInflater runtime zlib-ng
Debug build 61 MB/s 855 MB/s
Release build 266 MB/s 849 MB/s

Tests

  • NativeZlibInflaterTests checks that both inflaters produce the same bytes (1 B to 256 KiB). It also checks that a longer stream, a shorter one, a truncated one and one with a bad Adler-32 are refused, and that the next request still inflates after a refusal.
  • DirectStorage tests and architecture tests pass.
  • IndirectGatherTests.Gathered_dispatch_records_are_clamped_before_the_list_runs fails on main without this change too.
  • docs/directstorage.md is updated.

In game

A boot with this change is running now; I will add the loading time and fps before and after in a comment.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-26 13:01 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/59) `Sr-0w:storage/native-zlib` → `main` · +257 −3 · 4 files · 1 commits · merged 2026-11-26 13:42 UTC ## What DirectStorage zlib requests now inflate with the zlib-ng that the .NET runtime ships (`System.IO.Compression.Native`), not with the managed `ZlibInflater`. `NativeZlibInflater` calls the runtime's own exports, the ones `ZLibStream` calls: - one inflate state per queue, reset for each request; - the output goes into a reused buffer, so a request allocates nothing; - a request must still produce exactly its `DestinationSize` and end there, with the Adler-32 checked. The exports are internal to the runtime. If they are missing, or the state fails a known stream when the queue is created, the queue falls back to `ZlibInflater`. ## Why On a retail game's loading screens (RX 7800 XT, game data on a SATA SSD): - the frame rate was about 1 fps; - the GPU was busy about 1 ms per frame; - the game's threads were blocked more than 95% of the time. I timed each request on the queue workers over the first 15 minutes of a boot (local instrumentation, not part of this PR): | step | time | data | |---|---|---| | zlib inflate | 320 s | 10.4 GB | | BCPack decode | 64 s | 0.5 GB | | waiting for reads | 22 s | | | sink writes | 3 s | | Inflate speed on 256 KiB chunks, measured on the same machine: | | managed `ZlibInflater` | runtime zlib-ng | |---|---|---| | Debug build | 61 MB/s | 855 MB/s | | Release build | 266 MB/s | 849 MB/s | ## Tests - `NativeZlibInflaterTests` checks that both inflaters produce the same bytes (1 B to 256 KiB). It also checks that a longer stream, a shorter one, a truncated one and one with a bad Adler-32 are refused, and that the next request still inflates after a refusal. - DirectStorage tests and architecture tests pass. - `IndirectGatherTests.Gathered_dispatch_records_are_clamped_before_the_list_runs` fails on main without this change too. - `docs/directstorage.md` is updated. ## In game A boot with this change is running now; I will add the loading time and fps before and after in a comment. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A retail game's loading screens ran at about 1 fps with the GPU busy about 1 ms per frame and the game's threads blocked
over 95% of the time. Timing each request on the queue workers: of a boot's first 15 minutes, 320 s went to inflating
10.4 GB of zlib requests, 64 s to BCPack and 22 s to waiting for reads. The managed ZlibInflater runs at 61 MB/s in a
Debug build and 266 MB/s in Release; the zlib-ng the runtime ships (System.IO.Compression.Native) at about 850 MB/s.

NativeZlibInflater calls the runtime's own exports (what ZLibStream calls): one inflate state per queue, reset per
request, the output written into a reused buffer, so a request allocates nothing. A request must produce exactly its
DestinationSize and end there (Adler-32 checked), as before. The exports are internal to the runtime: when they are
missing or the state fails a known stream at queue creation, the queue keeps the managed inflater.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:16:13 +00:00
github manually merged commit a3a3c9ac5f into gh-pr/59/base 2026-11-27 03:16:13 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-26 13:42 UTC · original

merged, thanks, 3x on inflate is a big one for loading. the fallback check at queue creation is a nice touch

the red CI on this PR was main's fault, the keep-awake test left its thread holding the WARP device and later tests ran out of memory. fixed in d07a8455

on the IndirectGather test failing on your 7800 XT: 6db8e2da makes the gather prelude move its buffers to UAV and back explicitly instead of leaning on implicit promotion, which is the one driver-dependent step we found. if it still fails on main for you, could you post which assertion trips? that tells us whether no prelude ran or which records came back wrong

**@⁠ThatRecompDev** on GitHub · 2026-11-26 13:42 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/59#issuecomment-7193735304) merged, thanks, 3x on inflate is a big one for loading. the fallback check at queue creation is a nice touch the red CI on this PR was main's fault, the keep-awake test left its thread holding the WARP device and later tests ran out of memory. fixed in d07a8455 on the IndirectGather test failing on your 7800 XT: 6db8e2da makes the gather prelude move its buffers to UAV and back explicitly instead of leaning on implicit promotion, which is the one driver-dependent step we found. if it still fails on main for you, could you post which assertion trips? that tells us whether no prelude ran or which records came back wrong
This discussion has been locked. Commenting is limited to contributors.
No description provided.