Skip to content

runtime: avoid truncating fractional shader index metadata - #8445

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

svds12343 wants to merge 1 commit into
ItsNotRexed: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

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.

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.

3 participants