inflate: expand repeated matches in blocks and batch Adler reductions #1081

Manually merged
github merged 1 commit from gh-pr/1081/head into gh-pr/1081/base 2026-11-26 09:37:01 +00:00
Owner

@⁠Kadamitas on GitHub · 2026-11-24 18:03 UTC · original
Kadamitas:perf/inflate-output → main · +41 −5 · 2 files · 1 commits · merged 2026-11-25 00:02 UTC

Claimed in the coordination issue as: RT-INFLATE-MATCH-COPY.

Depends on: none

What and why

Shader loading and DirectStorage use the same CPU inflater. This change grows the output buffer once for each length/distance match. A one-byte pattern uses a fill. Longer patterns start with the available prefix and copy completed, non-overlapping spans until the match is complete. Adler-32 reduces its two accumulators every 5,552 bytes, the maximum safe interval for 32-bit sums.

Tested

The Windows x64 MSVC shader-library suite passed, including a new case that expands overlapping one- and three-byte patterns across multiple checksum boundaries.

An independent CPU benchmark compared the parent and proposed code on 114 synthetic stored, fixed and dynamic streams. Both produced the expected decoded bytes and the same digest across 2,136 checks covering success, partial output and errors. Each batch expanded 4,493,676 bytes. In two runs per version the median fell from 12.580–12.596 ms to 3.068–3.076 ms, about 4.1× faster for this CPU workload.

The semantic suite ran 6,165 tests across 470 files. Two files failed because the SPIR-V assembler and validator were missing from the test environment. On the rebased branch, rerunning those files with both tools on PATH passed all 12 tests in test_sopc_validation and all 7 in test_unary_f16_validation.

GPUs tested: n/a (CPU-only change)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • Only source and synthetic fixtures included.
  • No shader translator rule changed.
**@⁠Kadamitas** on GitHub · 2026-11-24 18:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1081) `Kadamitas:perf/inflate-output` → `main` · +41 −5 · 2 files · 1 commits · merged 2026-11-25 00:02 UTC Claimed in the coordination issue as: [RT-INFLATE-MATCH-COPY](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14). Depends on: none ### What and why Shader loading and DirectStorage use the same CPU inflater. This change grows the output buffer once for each length/distance match. A one-byte pattern uses a fill. Longer patterns start with the available prefix and copy completed, non-overlapping spans until the match is complete. Adler-32 reduces its two accumulators every 5,552 bytes, the maximum safe interval for 32-bit sums. ### Tested The Windows x64 MSVC shader-library suite passed, including a new case that expands overlapping one- and three-byte patterns across multiple checksum boundaries. An independent CPU benchmark compared the parent and proposed code on 114 synthetic stored, fixed and dynamic streams. Both produced the expected decoded bytes and the same digest across 2,136 checks covering success, partial output and errors. Each batch expanded 4,493,676 bytes. In two runs per version the median fell from 12.580–12.596 ms to 3.068–3.076 ms, about 4.1× faster for this CPU workload. The semantic suite ran 6,165 tests across 470 files. Two files failed because the SPIR-V assembler and validator were missing from the test environment. On the rebased branch, rerunning those files with both tools on `PATH` passed all 12 tests in `test_sopc_validation` and all 7 in `test_unary_f16_validation`. GPUs tested: n/a (CPU-only change) AI-assisted: yes ### Checklist - [x] Based on current main and merges cleanly. - [x] One topic. - [x] Only source and synthetic fixtures included. - [x] No shader translator rule changed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:37:00 +00:00
github manually merged commit f7d18627bd into gh-pr/1081/base 2026-11-26 09:37:01 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:50 UTC · original · approved these changes

Reviewed and verified. Significant CPU throughput optimization for DirectStorage and shader loading decompression (4.1x faster). Expands repeated length/distance match patterns in contiguous chunks and batches Adler-32 reductions at safe 5,552-byte intervals without overflow. Verified across 2,136 synthetic test cases. 100% clean-room.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1081#pullrequestreview-6045341093) · **approved these changes** Reviewed and verified. Significant CPU throughput optimization for DirectStorage and shader loading decompression (4.1x faster). Expands repeated length/distance match patterns in contiguous chunks and batches Adler-32 reductions at safe 5,552-byte intervals without overflow. Verified across 2,136 synthetic test cases. 100% clean-room.
Author
Owner

@⁠sodove on GitHub · 2026-11-24 19:08 UTC · original

Measured 3aa975421 (parent) against 09ba0aa85 on a Ryzen 5 9600X, Windows 11 x64, MSVC 19.44 /O2. Median wall time per 1 MiB of decoded output:

Synthetic zlib stream Parent (ms) PR (ms) Speedup
Single repeated byte 3.767 0.271 13.92×
Three-byte repeating pattern, fixed Huffman 3.220 0.372 8.66×
Records with 96 repeated and 32 random bytes per 128 3.705 0.988 3.75×
Huffman-only, 16-symbol alphabet 4.721 2.495 1.89×
Stored blocks, incompressible bytes 3.329 0.791 4.21×

The PR was faster in all 10 paired rounds for each stream, including both streams without length/distance matches. Each sample averaged eight in-memory zlib_inflate calls after two warm-ups on the same pinned logical processor. The parent and PR alternated first place in the run order. The timer included checksum verification. Each decoded buffer was checked byte for byte outside the timer.

Both versions passed shader_library_test and 19 additional output lengths from 0 to 65,537 bytes, including one byte on either side of the first two 5,552-byte Adler reduction boundaries. These timings cover CPU decompression only. No game data used.

AI-assisted: yes (OpenAI Codex).

**@⁠sodove** on GitHub · 2026-11-24 19:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1081#issuecomment-7141659236) Measured `3aa975421` (parent) against `09ba0aa85` on a Ryzen 5 9600X, Windows 11 x64, MSVC 19.44 `/O2`. Median wall time per 1 MiB of decoded output: | Synthetic zlib stream | Parent (ms) | PR (ms) | Speedup | |---|---:|---:|---:| | Single repeated byte | 3.767 | 0.271 | 13.92× | | Three-byte repeating pattern, fixed Huffman | 3.220 | 0.372 | 8.66× | | Records with 96 repeated and 32 random bytes per 128 | 3.705 | 0.988 | 3.75× | | Huffman-only, 16-symbol alphabet | 4.721 | 2.495 | 1.89× | | Stored blocks, incompressible bytes | 3.329 | 0.791 | 4.21× | The PR was faster in all 10 paired rounds for each stream, including both streams without length/distance matches. Each sample averaged eight in-memory `zlib_inflate` calls after two warm-ups on the same pinned logical processor. The parent and PR alternated first place in the run order. The timer included checksum verification. Each decoded buffer was checked byte for byte outside the timer. Both versions passed `shader_library_test` and 19 additional output lengths from 0 to 65,537 bytes, including one byte on either side of the first two 5,552-byte Adler reduction boundaries. These timings cover CPU decompression only. No game data used. AI-assisted: yes (OpenAI Codex).
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 21:20 UTC · original

GPU verification (AI-assisted, independent worker on the shared test box) — head f7d18627b.

Environment: Windows, runtime/build RelWithDebInfo (Ninja), TEMP/TMP set to a user-writable dir (agent shells otherwise default to C:\Windows and host tests fail with 0xc0000409 — environmental, not the PR).

Host tests (ctest -R 'shader_library|startup_trace|bindless|run_startup'): 7/7 passed, shader_library_corpus skipped (no corpus dir). Includes the new inflate/match-copy coverage in shader_library_test.

GPU suite py -3.14 -I scripts/run_gpu_tests.py --build runtime/build (261 shaders translated, 261 pass spirv-val; LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc, spirv-as/spirv-val from Vulkan SDK 1.4.363):

  • AMD Radeon iGPU (gfx1035, driver 24.10.24, Vulkan 1.3.280): VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1 → 230/252 passed, 20 skipped, 2 failed: ms_clip and ms_wave_info_s3 — identical to origin/main (58be9cdf8) baseline on the same build config; known AMD LLPC issue (#802/#808). No validation errors.
  • NVIDIA RTX 4070 SUPER: VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~ → 203/252 passed, 49 skipped, 0 failed — identical to the origin/main baseline. No validation errors.

Verdict: PASS — no regressions vs main on either GPU; the change is host-side inflate/Adler only and the GPU suite is byte-identical in outcome to baseline.

**@⁠whoalin1** on GitHub · 2026-11-24 21:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1081#issuecomment-7144808220) GPU verification (AI-assisted, independent worker on the shared test box) — head `f7d18627b`. Environment: Windows, `runtime/build` RelWithDebInfo (Ninja), `TEMP`/`TMP` set to a user-writable dir (agent shells otherwise default to `C:\Windows` and host tests fail with 0xc0000409 — environmental, not the PR). Host tests (`ctest -R 'shader_library|startup_trace|bindless|run_startup'`): 7/7 passed, `shader_library_corpus` skipped (no corpus dir). Includes the new inflate/match-copy coverage in `shader_library_test`. GPU suite `py -3.14 -I scripts/run_gpu_tests.py --build runtime/build` (261 shaders translated, 261 pass spirv-val; `LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc`, spirv-as/spirv-val from Vulkan SDK 1.4.363): - AMD Radeon iGPU (gfx1035, driver 24.10.24, Vulkan 1.3.280): `VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1` → **230/252 passed, 20 skipped, 2 failed**: `ms_clip` and `ms_wave_info_s3` — identical to `origin/main` (`58be9cdf8`) baseline on the same build config; known AMD LLPC issue (#802/#808). No validation errors. - NVIDIA RTX 4070 SUPER: `VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~` → **203/252 passed, 49 skipped, 0 failed** — identical to the `origin/main` baseline. No validation errors. Verdict: PASS — no regressions vs main on either GPU; the change is host-side inflate/Adler only and the GPU suite is byte-identical in outcome to baseline.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-25 00:02 UTC · original

Merging.

Why merged: RT-INFLATE-MATCH-COPY: the inflater copies repeated matches in blocks (doubling memcpy that only reads finished output; distance at least 1 and bounds-checked) and reduces Adler-32 every 5552 bytes (the standard NMAX). sodove measured it 8-14x faster, and whoalin1's host tests pass.

Why it's good: shader_library, startup_trace, dstorage and d3d12_pipeline_library* pass both plain and under validation; shader_library_corpus is skipped, the same as on main.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 0f98d193c, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main 507029d1e: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main 9c5e70661: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

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

**@⁠QemmHD** on GitHub · 2026-11-25 00:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1081#issuecomment-7148069842) Merging. **Why merged:** RT-INFLATE-MATCH-COPY: the inflater copies repeated matches in blocks (doubling memcpy that only reads finished output; distance at least 1 and bounds-checked) and reduces Adler-32 every 5552 bytes (the standard NMAX). sodove measured it 8-14x faster, and whoalin1's host tests pass. **Why it's good:** shader_library, startup_trace, dstorage and d3d12_pipeline_library* pass both plain and under validation; shader_library_corpus is skipped, the same as on main. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 0f98d193c, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main 507029d1e: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main 9c5e70661: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.