shader_library: read indexes in blocks and reject incomplete reads (RT-SHADER-INDEX-BLOCK-READ) #1218

Merged
sodove merged 1 commit from upstream-pr/1218 into main 2026-11-29 08:10:19 +00:00
sodove commented 2026-11-24 20:29:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-24T20:29:40Z.


Claimed in the coordination issue as: RT-SHADER-INDEX-BLOCK-READ (claim).

Depends on: none. #1108 changes how the JSON parser moves subtrees and applies independently.

What changed

The first pipeline that needs the shader library waits for ShaderLibrary::load. Its main and optional indexes now read in 16 KiB blocks. The reader keeps native Unicode paths and shared reads on Windows, and checks the file error indicator before parsing.

This also fixes a reproducible Windows failure. An index started with a valid JSON object and had a locked byte after 64 KiB of readable input. On main the load succeeded with just the readable prefix. The regression test now requires a read error and an unloaded library.

Measured

Native Windows 11 x64, Ryzen 5 9600X, MSVC 19.44 /O2. Each sample timed the complete public ShaderLibrary::load call with warm filesystem cache, including parsing and building the lookup table. After the timer stopped, the harness looked up every synthetic entry and checked its name, stage key, local size and push-constant size. One warm-up round, then 12 paired rounds with alternating revision order.

Synthetic index Entries Bytes main → this PR main + #1108 → both
Compact 26,503 2,563,635 86.78 → 74.08 ms 56.73 → 45.67 ms
Indented, with bindings and sampler metadata 26,503 13,668,393 345.43 → 295.47 ms 202.24 → 139.22 ms
Small control 64 5,795 0.366 → 0.343 ms 0.293 → 0.270 ms

The larger index improved in all 12 pairs on both baselines. The small control favored the change in only 6/12 pairs on main. Baseline 58be9cdf8, #1108 patch from f6ea7b667. This measures the first shader-library load on synthetic data. Game startup and frame rate were not timed.

Tested

  • Built gta6rt.exe in RelWithDebInfo. Native Windows CTests shader_library and mods passed. The Windows lock test failed at the successful-load assertion on the unmodified reader. The shader-library suite also passed on GCC 15.2, Linux x86-64.
  • d3d12_compute and d3d12_fspx_compute passed on both Windows adapters below. The latter creates compute PSOs from the optional FSPX index, dispatches them and verifies readback.
  • 45 additional path and boundary checks per revision, including Unicode directories, UTF-8 BOMs, exact and partial blocks, trailing invalid bytes, and an unreadable-as-JSON optional index alongside a valid main index.
  • Full semantic suite passed, 6,168 tests in 470 files. Both changed paths passed the game-data check. The merge with #1108 is clean.

GPUs tested: RTX 5070 Ti (NVIDIA 610.74), Ryzen 5 9600X integrated Radeon (AMD 32.0.21045.29003), Windows 11.

AI-assisted: yes (OpenAI Codex).

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • Only runtime source and a synthetic regression test.
  • No translator rule changed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479812173 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1218). Originally posted by [sodove](https://github.com/sodove) on 2026-11-24T20:29:40Z. --- Claimed in the coordination issue as: RT-SHADER-INDEX-BLOCK-READ ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143420677)). Depends on: none. #1108 changes how the JSON parser moves subtrees and applies independently. ### What changed The first pipeline that needs the shader library waits for `ShaderLibrary::load`. Its main and optional indexes now read in 16 KiB blocks. The reader keeps native Unicode paths and shared reads on Windows, and checks the file error indicator before parsing. This also fixes a reproducible Windows failure. An index started with a valid JSON object and had a locked byte after 64 KiB of readable input. On `main` the load succeeded with just the readable prefix. The regression test now requires a read error and an unloaded library. ### Measured Native Windows 11 x64, Ryzen 5 9600X, MSVC 19.44 `/O2`. Each sample timed the complete public `ShaderLibrary::load` call with warm filesystem cache, including parsing and building the lookup table. After the timer stopped, the harness looked up every synthetic entry and checked its name, stage key, local size and push-constant size. One warm-up round, then 12 paired rounds with alternating revision order. | Synthetic index | Entries | Bytes | main → this PR | main + #1108 → both | |---|---:|---:|---:|---:| | Compact | 26,503 | 2,563,635 | 86.78 → 74.08 ms | 56.73 → 45.67 ms | | Indented, with bindings and sampler metadata | 26,503 | 13,668,393 | 345.43 → 295.47 ms | 202.24 → 139.22 ms | | Small control | 64 | 5,795 | 0.366 → 0.343 ms | 0.293 → 0.270 ms | The larger index improved in all 12 pairs on both baselines. The small control favored the change in only 6/12 pairs on `main`. Baseline `58be9cdf8`, #1108 patch from `f6ea7b667`. This measures the first shader-library load on synthetic data. Game startup and frame rate were not timed. ### Tested - Built `gta6rt.exe` in RelWithDebInfo. Native Windows CTests `shader_library` and `mods` passed. The Windows lock test failed at the successful-load assertion on the unmodified reader. The shader-library suite also passed on GCC 15.2, Linux x86-64. - `d3d12_compute` and `d3d12_fspx_compute` passed on both Windows adapters below. The latter creates compute PSOs from the optional FSPX index, dispatches them and verifies readback. - 45 additional path and boundary checks per revision, including Unicode directories, UTF-8 BOMs, exact and partial blocks, trailing invalid bytes, and an unreadable-as-JSON optional index alongside a valid main index. - Full semantic suite passed, 6,168 tests in 470 files. Both changed paths passed the game-data check. The merge with #1108 is clean. GPUs tested: RTX 5070 Ti (NVIDIA 610.74), Ryzen 5 9600X integrated Radeon (AMD 32.0.21045.29003), Windows 11. AI-assisted: yes (OpenAI Codex). ### Checklist - [x] Based on current main and merges cleanly. - [x] One topic. - [x] Only runtime source and a synthetic regression test. - [x] No translator rule changed.
Snooozs commented 2026-11-24 20:58:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-24T20:58:04Z.


Read the whole diff and tested 2b67760c4 merged on main 66d4f5aa3 (clean), Windows 10 Pro 19045, VS 2022 RelWithDebInfo, CPU only:

  • the new test with main's shader_library.h: 2 of 2 runs fail at line 666 (!loaded), so the silently shortened index reproduces on Windows 10 too
  • with the PR: 5 of 5 runs of shader_library_test pass

I did not measure load times. Nothing to change from my side.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144296675 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1218#issuecomment-7144296675). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-24T20:58:04Z. --- Read the whole diff and tested `2b67760c4` merged on main `66d4f5aa3` (clean), Windows 10 Pro 19045, VS 2022 RelWithDebInfo, CPU only: - the new test with main's `shader_library.h`: 2 of 2 runs fail at line 666 (`!loaded`), so the silently shortened index reproduces on Windows 10 too - with the PR: 5 of 5 runs of `shader_library_test` pass I did not measure load times. Nothing to change from my side. AI-assisted (Claude Code, Claude Opus 5.5).
zmasi commented 2026-11-28 22:01:52 +00:00 (Migrated from github.com)

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


#1218 | head 2b67760c45 (merged cleanly with main a8465211fb) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(shader_library|d3d12_compute|d3d12_fspx_compute)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: shader_library fails at line 666: !loaded (LockFileEx byte lock at +64 KiB is silently ignored by std::istreambuf_iterator, accepting the truncated {} prefix) | green on PR+main: 3/3 CTests pass (shader_library rejecting the locked-tail index with index.json could not be read, plus d3d12_compute and d3d12_fspx_compute on RTX 3090 with 0 Khronos validation errors); check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246446160 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1218#issuecomment-7246446160). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:01:52Z. --- #1218 | head 2b67760c450fa4d5b15d427bd81122a8fcfd5d2f (merged cleanly with main a8465211fb882e8c38cc0a39760bb8014d927289) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(shader_library|d3d12_compute|d3d12_fspx_compute)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: `shader_library` fails at `line 666: !loaded` (`LockFileEx` byte lock at `+64 KiB` is silently ignored by `std::istreambuf_iterator`, accepting the truncated `{}` prefix) | green on PR+main: 3/3 CTests pass (`shader_library` rejecting the locked-tail index with `index.json could not be read`, plus `d3d12_compute` and `d3d12_fspx_compute` on RTX 3090 with `0` Khronos validation errors); `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-28 22:12:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:12:21Z.


Verified by OreoFR

  • Base: main a8465211f + PR head 2b67760c4 (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: fails at the new locked-tail case: main loads an index.json whose tail cannot be read (CHECK(!loaded))
  • Green with the PR: passes; full ctest on the package: no new failure
  • Verdict: READY
  • 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:7246570186 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1218#issuecomment-7246570186). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:12:21Z. --- **Verified by OreoFR** - Base: main `a8465211f` + PR head `2b67760c4` (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: fails at the new locked-tail case: main loads an index.json whose tail cannot be read (`CHECK(!loaded)`) - Green with the PR: passes; full ctest on the package: no new failure - Verdict: READY - 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).
OreoFR commented 2026-11-29 02:09:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T02:09:42Z.


Verified by OreoFR: link check

  • main 59e65849b + this PR (head 2b67760c4, the head verified earlier) merged with --no-ff, built without the XMA decoder (LEONIDA_CARGO=OFF, no LEONIDA_XMA2_DECODER_LIB: configure reports the XMA2 and Opus decoders not built), RelWithDebInfo, Ninja, MSVC 19.44.35230 (VS 2022 BuildTools), LEONIDA_REQUIRE_VULKAN=ON
  • gta6rt.exe links; imports unchanged vs main built the same way (dumpbin /imports: 25 DLLs, 655 functions, no WS2_32)
  • gta6rt was not launched.

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249248417 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1218#issuecomment-7249248417). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T02:09:42Z. --- **Verified by OreoFR**: link check - main `59e65849b` + this PR (head `2b67760c4`, the head verified earlier) merged with --no-ff, built without the XMA decoder (`LEONIDA_CARGO=OFF`, no `LEONIDA_XMA2_DECODER_LIB`: configure reports the XMA2 and Opus decoders not built), RelWithDebInfo, Ninja, MSVC 19.44.35230 (VS 2022 BuildTools), `LEONIDA_REQUIRE_VULKAN=ON` - `gta6rt.exe` links; imports unchanged vs main built the same way (`dumpbin /imports`: 25 DLLs, 655 functions, no WS2_32) - gta6rt was not launched. AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
MoonEyes commented 2026-11-29 08:10:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T08:10:21Z.


Merged after OreoFR's red/green check (check: green with this PR merged onto main, red without it; gta6rt.exe still links with unchanged imports when the PR touches the runtime) and a re-check here: no conflict with main 02c3ef96d, same head as checked, not frozen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7252931862 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1218#issuecomment-7252931862). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T08:10:21Z. --- Merged after **OreoFR**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1218#issuecomment-7249248417): green with this PR merged onto `main`, red without it; `gta6rt.exe` still links with unchanged imports when the PR touches the runtime) and a re-check here: no conflict with `main` 02c3ef96d, same head as checked, not frozen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan). _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!1218
No description provided.