inflate: copy DEFLATE stored blocks in bulk (RT-INFLATE-STORED-COPY) #1189

Closed
sodove wants to merge 1 commit from upstream-pr/1189 into main
sodove commented 2026-11-24 19:53:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-24T19:53:35Z.


Claimed in the coordination issue as: RT-INFLATE-STORED-COPY (claim).

Depends on: none. Applies independently alongside #1081, which changes match expansion and Adler-32.

What changed

The CPU zlib inflater used by the DirectStorage request handler and shader-library extraction appended each byte of an aligned DEFLATE stored block separately. It now takes the available input as a span and appends that range in one operation. The declared length is still checked against the output limit before copying. A truncated block still contributes its available prefix before reporting a data error.

Measured on the runtime queue

Windows 11 x64, Ryzen 5 9600X, MSVC 19.44 /O2. Synthetic zlib requests each produced 4 MiB. The indicated percentage of output came from stored blocks containing pseudorandom bytes. A compressed tail kept every request within the shim’s source/destination size contract.

Source and share from stored blocks main 6293c1c4f → this PR (ms/request) #1081 09ba0aa85 → both (ms/request)
Memory, 0% (control) 18.08 → 18.24 2.16 → 2.12
Memory, 50% 18.13 → 15.23 4.20 → 2.52
Memory, 95% 18.63 → 12.37 6.53 → 2.78
File, 95%, warm OS cache 20.82 → 13.89 7.73 → 3.57

Each figure is the median of ten paired rounds with alternating run order. Timed the actual queue from enqueue through submission and its completion event, eight requests per sample after a warm-up batch. Every request returned S_OK and its full destination matched outside the timer. The mixed cases improved in all ten pairs. Changes on the 0% control were within 2% in either direction. The retail block mix, game startup time and FPS were not measured.

Tested

  • Built gta6rt.exe in RelWithDebInfo on native Windows. CTest passed shader_library and dstorage (329 checks in the latter). The shader-library suite also passed on Linux x86-64 with GCC 15.2.
  • Extended the existing mixed-block test across all eight alignments to check the exact output prefix and error classification. A control that rejected a short block before appending its prefix failed the new assertion.
  • 710 additional synthetic boundary, output-limit and checksum checks passed on each of the four variants, including empty and 65,535-byte blocks.
  • Full semantic suite passed (6,168 tests, 470 files). The two changed paths passed the game-data check. git merge-tree applies this PR and #1081 cleanly.

GPUs tested: n/a (CPU and DirectStorage queue). Only synthetic input used.

AI-assisted: yes (OpenAI Codex).

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • Source and synthetic tests only.
  • No translator rule changed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479272011 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1189). Originally posted by [sodove](https://github.com/sodove) on 2026-11-24T19:53:35Z. --- Claimed in the coordination issue as: RT-INFLATE-STORED-COPY ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142471707)). Depends on: none. Applies independently alongside #1081, which changes match expansion and Adler-32. ### What changed The CPU zlib inflater used by the DirectStorage request handler and shader-library extraction appended each byte of an aligned DEFLATE stored block separately. It now takes the available input as a span and appends that range in one operation. The declared length is still checked against the output limit before copying. A truncated block still contributes its available prefix before reporting a data error. ### Measured on the runtime queue Windows 11 x64, Ryzen 5 9600X, MSVC 19.44 `/O2`. Synthetic zlib requests each produced 4 MiB. The indicated percentage of output came from stored blocks containing pseudorandom bytes. A compressed tail kept every request within the shim’s source/destination size contract. | Source and share from stored blocks | main `6293c1c4f` → this PR (ms/request) | #1081 `09ba0aa85` → both (ms/request) | |---|---:|---:| | Memory, 0% (control) | 18.08 → 18.24 | 2.16 → 2.12 | | Memory, 50% | 18.13 → 15.23 | 4.20 → 2.52 | | Memory, 95% | 18.63 → 12.37 | 6.53 → 2.78 | | File, 95%, warm OS cache | 20.82 → 13.89 | 7.73 → 3.57 | Each figure is the median of ten paired rounds with alternating run order. Timed the actual queue from enqueue through submission and its completion event, eight requests per sample after a warm-up batch. Every request returned `S_OK` and its full destination matched outside the timer. The mixed cases improved in all ten pairs. Changes on the 0% control were within 2% in either direction. The retail block mix, game startup time and FPS were not measured. ### Tested - Built `gta6rt.exe` in RelWithDebInfo on native Windows. CTest passed `shader_library` and `dstorage` (329 checks in the latter). The shader-library suite also passed on Linux x86-64 with GCC 15.2. - Extended the existing mixed-block test across all eight alignments to check the exact output prefix and error classification. A control that rejected a short block before appending its prefix failed the new assertion. - 710 additional synthetic boundary, output-limit and checksum checks passed on each of the four variants, including empty and 65,535-byte blocks. - Full semantic suite passed (6,168 tests, 470 files). The two changed paths passed the game-data check. `git merge-tree` applies this PR and #1081 cleanly. GPUs tested: n/a (CPU and DirectStorage queue). Only synthetic input used. AI-assisted: yes (OpenAI Codex). ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] Source and synthetic tests only. - [x] No translator rule changed.
Deedlyy commented 2026-11-24 20:08:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:08:47Z.


Recommendation: [MERGE]

Reasoning: The CPU zlib inflater copies DEFLATE stored blocks with one range append instead of byte by byte, keeping the output-limit check and truncated-block behaviour. Small performance change in the DirectStorage/shader-library path, with a test. It's independent of #1081. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 3/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143105142 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1189#issuecomment-7143105142). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:08:47Z. --- **Recommendation:** [MERGE] **Reasoning:** The CPU zlib inflater copies DEFLATE stored blocks with one range append instead of byte by byte, keeping the output-limit check and truncated-block behaviour. Small performance change in the DirectStorage/shader-library path, with a test. It's independent of #1081. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 3/10
zmasi commented 2026-11-28 21:52:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T21:52:00Z.


Independent Verification Report — 152c64442b + origin/main (a8465211fb)

Environment: Windows 11 (26200), AMD Ryzen 9 5950X, MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8, Debug /Od /MDd & Release /O2 /MD).
Verdict: PASS (Ready to merge) — clean Git merge with origin/main (3c0ba53315c7).

1. Correctness & Throughput Verification on Windows 11 + MSVC 19.44

  • shader_library_test (Debug /Od /MDd & Release /O2 /MD on 152c64442b + origin/main): PASS (SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK), 0 new warnings in shader_library.h or touched test lines, verifying exact truncation prefix preservation (ZlibError::data) and whole-block pre-check behavior (ZlibError::limit).
  • Audited BitReader::take_aligned (shader_library.h:107-111): reader.align() resets count_ = 0 and pos_ <= in_.size() before reading the 4-byte LEN/NLEN header, so in_.subspan(pos_, std::min(length, in_.size() - pos_)) is always in-bounds. (Minor non-blocking note: take_aligned does not set failed_ = true on short reads unlike byte(), which is harmless here since zlib_inflate immediately returns fail(ZlibError::data) when payload.size() != length.)
  • Throughput (200 x 1 MiB stored-block zlib stream = 16 x 65,535 B blocks, MSVC 19.44 /O2 /MD):
    • origin/main (byte-by-byte loop): 437.21 ms (0.48 GB/s)
    • 152c64442b (take_aligned + bulk out.insert): 53.84 ms (3.89 GB/s) — 8.1x faster with identical decompressed output.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246330249 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1189#issuecomment-7246330249). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:52:00Z. --- ### Independent Verification Report — `152c64442b` + `origin/main` (`a8465211fb`) **Environment:** Windows 11 (`26200`), AMD Ryzen 9 5950X, MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8`, Debug `/Od /MDd` & Release `/O2 /MD`). **Verdict:** **PASS (Ready to merge)** — clean Git merge with `origin/main` (`3c0ba53315c7`). #### 1. Correctness & Throughput Verification on Windows 11 + MSVC `19.44` - `shader_library_test` (Debug `/Od /MDd` & Release `/O2 /MD` on `152c64442b` + `origin/main`): **PASS** (`SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK`), `0` new warnings in `shader_library.h` or touched test lines, verifying exact truncation prefix preservation (`ZlibError::data`) and whole-block pre-check behavior (`ZlibError::limit`). - Audited `BitReader::take_aligned` (`shader_library.h:107-111`): `reader.align()` resets `count_ = 0` and `pos_ <= in_.size()` before reading the 4-byte `LEN`/`NLEN` header, so `in_.subspan(pos_, std::min(length, in_.size() - pos_))` is always in-bounds. (Minor non-blocking note: `take_aligned` does not set `failed_ = true` on short reads unlike `byte()`, which is harmless here since `zlib_inflate` immediately returns `fail(ZlibError::data)` when `payload.size() != length`.) - **Throughput (`200 x 1 MiB` stored-block zlib stream = `16 x 65,535 B` blocks, MSVC `19.44` `/O2 /MD`):** - `origin/main` (byte-by-byte loop): `437.21 ms` (`0.48 GB/s`) - `152c64442b` (`take_aligned` + bulk `out.insert`): `53.84 ms` (`3.89 GB/s`) — **8.1x faster** with identical decompressed output. AI-assisted.
OreoFR commented 2026-11-29 00:14:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T00:14:50Z.


Verified by OreoFR

  • Base: main a8465211f + PR head 152c64442 (merged with --no-ff, no conflict; tested in a package with other PRs that share no file with it)
  • Test: ctest -R ^shader_library$ (red: the PR's test with src/shader_library.h from main)
  • Red on main: passes on main too (the bulk stored-block copy keeps the behaviour the new checks pin)
  • Green with the PR: passes; full ctest on the package: no new failure from this PR (the two other new failures in that package come from #1328)
  • Verdict: NO RED (optimisation; the added checks pass on main as well)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11
  • Note: shares runtime/src/shader_library.h and runtime/test/shader_library_test.cpp with the open #2566; a rebase may be needed if #2566 lands first.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247978829 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1189#issuecomment-7247978829). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T00:14:50Z. --- **Verified by OreoFR** - Base: main `a8465211f` + PR head `152c64442` (merged with --no-ff, no conflict; tested in a package with other PRs that share no file with it) - Test: `ctest -R ^shader_library$` (red: the PR's test with src/shader_library.h from main) - Red on main: passes on main too (the bulk stored-block copy keeps the behaviour the new checks pin) - Green with the PR: passes; full ctest on the package: no new failure from this PR (the two other new failures in that package come from #1328) - Verdict: NO RED (optimisation; the added checks pass on main as well) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 - Note: shares `runtime/src/shader_library.h` and `runtime/test/shader_library_test.cpp` with the open #2566; a rebase may be needed if #2566 lands first. AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-29 14:44:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T14:44:41Z.


Read at 152c64442 against main bd643e46e (diff reading, no build here). This answers the "no test" question.

  • No failing test is possible by design. The change only swaps the byte-by-byte append of a stored block for a range append, and it keeps the output-limit check and the truncated-block prefix.
  • The added shader_library_test.cpp cases pin that behaviour: data error plus the exact prefix for a cut inside the payload, and ZlibError::limit before the payload is consumed. They pass on main too, as reported above, so they guard against regressions but do not show a red.
  • The speed claim is not covered by a test.
  • Merges cleanly with current main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257541976 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1189#issuecomment-7257541976). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T14:44:41Z. --- Read at 152c64442 against main bd643e46e (diff reading, no build here). This answers the "no test" question. - No failing test is possible by design. The change only swaps the byte-by-byte append of a stored block for a range append, and it keeps the output-limit check and the truncated-block prefix. - The added `shader_library_test.cpp` cases pin that behaviour: data error plus the exact prefix for a cut inside the payload, and `ZlibError::limit` before the payload is consumed. They pass on main too, as reported above, so they guard against regressions but do not show a red. - The speed claim is not covered by a test. - Merges cleanly with current main. AI-assisted (Claude Code).
aslan2142 commented 2026-12-01 16:33:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:33:39Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317808660 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1189#issuecomment-7317808660). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:33:39Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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
ProjectLeonida/mandy!1189
No description provided.