Skip to content

runtime: avoid truncating fractional shader index metadata - #8445

Closed
svds12343 wants to merge 1 commit into
ProjectLeonida:mainfrom
svds12343:fix/shader-metadata-integers
Closed

svds12343 wants to merge 1 commit into
ProjectLeonida:mainfrom
svds12343:fix/shader-metadata-integers

Conversation

@svds12343

Copy link
Copy Markdown

The shader index reader silently truncated fractional metadata: local_size: [64.5, 1, 1] became [64, 1, 1], lds_bytes: 1024.75 became 1024, and fractional signature locations and sampler words became integers. The shared ShaderLibrary::u32 helper now returns its existing invalid-field fallback, zero, for non-integral values. It checks the range before casting, then checks that conversion preserved the value. This does not reject the whole index or change the handling of valid whole numbers.

Claim: #8344 (comment) (new RT item, no assigned numbered ID). AI-assisted (Codex).

Validation at 6253d2b, based on main 6dda063:

No PR dependencies. #7364 owns f16_halves string-key parsing; this change only handles numeric values. The pending JSON grammar, underflow, locale and UTF-8 work is separate. Linux/macOS, full runtime/GPU tests and game execution were not run. No translator rule changed.

Checklist

  • No game data, keys or decryption, including in logs and reports.
  • Translator contract/fixture requirement: not applicable; no translator rule changed.

@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent build + test: PASS (one design note)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo. GPU (not used): NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124.

Head 6253d2b39, merged locally with current main 867d922f0 (clean merge).

Test PR (merged) runtime/src/shader_library.h reverted to main
shader_library_test.exe exit 0, ... JSON, FSSM extraction, FSPX programs and index lookup OK exit 1: line 62: entry->push_constant_bytes == expected && entry->lds_bytes == expected (the fractional cases were truncated, e.g. 1.5 became 1)

Design note: a fractional or invalid value now reads as 0, the same as a missing field. For push_constant_bytes, lds_bytes, local_size[0] or subgroup_size, 0 means "absent/none", so a corrupt index entry quietly produces a pipeline with no push constants or no LDS instead of being refused. That's better than truncation (144.5 → 144 looks valid), but a log line or a skipped entry for a fractional integer field would make a broken index visible. No issues otherwise.

FYI: #8254, #8256 and #8270 also change shader_library.h.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6253d2b3 on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 867d922f: pass

  • Built only the shader_library test target(s) from the merged tree and ran them through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1.
    • line 62: entry->push_constant_bytes == expected && entry->lds_bytes == expected
    • line 305: test_integer_metadata() == 0

So the new test depends on the change. The agent also built the test under ASan/UBSan and reports it clean; I did not repeat the sanitizer build.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

@RAINighty

Copy link
Copy Markdown

Tested 6253d2b39 merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, MSVC 19.44.35228, RelWithDebInfo (Ninja), CPU-only tests: pass.

  • shader_library passes with this PR; shader_library_corpus is skipped (no corpus here).
  • Negative control: this PR's shader_library_test.cpp with main's runtime/src/shader_library.h: shader_library fails, so the new test does catch the change.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@Pierrot1398

Copy link
Copy Markdown

Tested 6253d2b on NVIDIA GeForce RTX 5060 Ti, driver 621.24, Windows 11 Pro build 26300, VS 18 Build Tools (MSVC), Ninja, RelWithDebInfo: pass.

  • shader_library: passed 3/3 with ctest --repeat until-fail:3, including test_integer_metadata.

Built the PR head, not merged onto main. Synthetic only, no game files. AI-assisted (Claude Code).

@egexon

egexon commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6253d2b (merged onto main 867d922) on RTX 5070, NVIDIA 621.24, Windows 11 (build 26200), Vulkan validation layer on (LEONIDA_VK_VALIDATION=1, VK_VALIDATION_VALIDATE_SYNC=1): pass.

  • shader_library: passes with this PR, and passes on main.

Ran the tests that belong to the test files this PR changes (ctest entries, or the test program directly when it is not registered), with no game files (LEONIDA_GAME_DIR unset). AI-assisted (Claude Code).

@kristofbarany

Copy link
Copy Markdown

Tested 6253d2b merged onto main 867d922 (clean merge) on NVIDIA GeForce RTX 4070, driver 621.24, native Windows 11 Pro 26300, MSVC 14.44.35207, Ninja RelWithDebInfo: pass.

  • shader_library_test: passes; no compiler warnings in the build.
  • shader_library_corpus_test on my own translated 1.0.2.1 corpus (LEONIDA_SHADERS): 26503 reached … 0 not translated; 0 failures, the same counts as unchanged main, so the real index metadata still loads.

No game data used. AI-assisted (Claude Code).

@karearl

karearl commented Nov 23, 2026

Copy link
Copy Markdown

On main here d3d12_vulkan_device (tiles == 1, fixed by #8496/#7125) and d3d12_depth_resolve fail without the PR too; one-off failures in a full -j 8 run were rerun alone 3 times and passed.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants