Normalize SPIR-V file byte order (SPIRV-WORDS-ENDIAN) #2051

Merged
leonida/mandy
alexandersato0830 merged 1 commit from codex/spirv-word-endianness into main 2026-11-29 15:43:40 +00:00

Pull request successfully merged and closed

alexandersato0830 commented 2026-11-25 19:02:28 +00:00

Claimed in the coordination issue as: SPIRV-WORDS-ENDIAN

What and why

The shared shader reader rejected SPIR-V files in the opposite byte order, although the Python reflector accepts either order. Use the SPIR-V magic to detect the file’s byte order and return native-endian words to Vulkan. The existing byte-count and short-read checks still apply. SPIR-V binary format · Vulkan SPIR-V environment

Tested

  • On Windows 11, MSVC 19.51, CMake RelWithDebInfo: the word-by-word reversed synthetic fixture failed on main 9f9a7c5 and the shader_library CTest target passed with the fix. The test checks the entire output, including a word beyond the header.
  • Verified the source-only check and git diff --check.

GPUs tested: n/a (CPU-only reader test).

AI-assisted: yes.

  • Based on current main.
  • One topic.
  • Uses source and synthetic test words only.
Claimed in the coordination issue as: [SPIRV-WORDS-ENDIAN](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171693644) ### What and why The shared shader reader rejected SPIR-V files in the opposite byte order, although the Python reflector accepts either order. Use the SPIR-V magic to detect the file’s byte order and return native-endian words to Vulkan. The existing byte-count and short-read checks still apply. [SPIR-V binary format](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#MagicNumber) · [Vulkan SPIR-V environment](https://docs.vulkan.org/spec/latest/appendices/spirvenv.html) ### Tested - On Windows 11, MSVC 19.51, CMake RelWithDebInfo: the word-by-word reversed synthetic fixture failed on main `9f9a7c5` and the `shader_library` CTest target passed with the fix. The test checks the entire output, including a word beyond the header. - Verified the source-only check and `git diff --check`. GPUs tested: n/a (CPU-only reader test). AI-assisted: yes. - [x] Based on current `main`. - [x] One topic. - [x] Uses source and synthetic test words only.
zmasi commented 2026-11-28 11:51:52 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main 24549bdb1 + 09014c5e6 (claim #2570#issuecomment-7238799031):

  • Line-by-line diff audit: Clean (runtime/src/spirv_words.h, runtime/test/shader_library_test.cpp); accepts byte-swapped SPIR-V magic 0x03022307 alongside native 0x07230203 and byte-swaps the header and payload words into host byte order. check_no_game_data.py clean.
  • Red (24549bdb1 + PR test): shader_library_test.exe fails (rc=1 at line 552: read_spirv_words(input, input.tellg()) == module).
  • Green (24549bdb1 + 09014c5e6 merge): Auto-merges cleanly (rc=0), compiles with 0 warnings in spirv_words.h, and shader_library_test.exe passes (SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK, rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `24549bdb1` + `09014c5e6` (claim `#2570#issuecomment-7238799031`): - **Line-by-line diff audit**: Clean (`runtime/src/spirv_words.h`, `runtime/test/shader_library_test.cpp`); accepts byte-swapped SPIR-V magic `0x03022307` alongside native `0x07230203` and byte-swaps the header and payload words into host byte order. `check_no_game_data.py` clean. - **Red (`24549bdb1` + PR test)**: `shader_library_test.exe` fails (`rc=1` at `line 552: read_spirv_words(input, input.tellg()) == module`). - **Green (`24549bdb1` + `09014c5e6` merge)**: Auto-merges cleanly (`rc=0`), compiles with `0` warnings in `spirv_words.h`, and `shader_library_test.exe` passes (`SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK`, `rc=0`). AI-assisted.
enlight3d commented 2026-11-29 00:45:27 +00:00

Run of #2051 (ctest, red/green), by enlight3d. Nothing pushed.

Heads: PR 09014c5e6 (base 9f9a7c5f3, older than main), main 1bc055e6c. git merge-tree --write-tree main <PR head> is clean (no conflicts).
The PR changes runtime/src/spirv_words.h (existing code, new behaviour: accept a byte-swapped SPIR-V file) and adds one case to runtime/test/shader_library_test.cpp. CPU-only test, no GPU used.

Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo.

Commands (vcvars64 environment, only this target built):

cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build bld --target shader_library_test -j 8
ctest --test-dir bld -R "^shader_library$" --output-on-failure
  • GREEN (PR head): shader_library Passed (1/1, 0.27 s).
  • RED (PR head with spirv_words.h taken from main, test kept): Failed at line 552: read_spirv_words(input, input.tellg()) == module. This is a behavioural red: the header exists on main, the reversed-order input is rejected (empty result) instead of returned in native order.
    Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
Run of #2051 (ctest, red/green), by enlight3d. Nothing pushed. Heads: PR `09014c5e6` (base `9f9a7c5f3`, older than main), main `1bc055e6c`. `git merge-tree --write-tree main <PR head>` is clean (no conflicts). The PR changes `runtime/src/spirv_words.h` (existing code, new behaviour: accept a byte-swapped SPIR-V file) and adds one case to `runtime/test/shader_library_test.cpp`. CPU-only test, no GPU used. Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo. Commands (vcvars64 environment, only this target built): ``` cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build bld --target shader_library_test -j 8 ctest --test-dir bld -R "^shader_library$" --output-on-failure ``` - GREEN (PR head): `shader_library` Passed (1/1, 0.27 s). - RED (PR head with `spirv_words.h` taken from main, test kept): Failed at `line 552: read_spirv_words(input, input.tellg()) == module`. This is a behavioural red: the header exists on main, the reversed-order input is rejected (empty result) instead of returned in native order. Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
MoonEyes commented 2026-11-29 15:43:42 +00:00

Merged. Tested by @enlight3d on head 09014c5e6 (CPU only (test); host RTX 3090, Windows 11): shader_library: red with spirv_words.h from main (line 552, byte-swapped SPIR-V rejected); green with PR. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @alexandersato0830!

AI-assisted: yes

Merged. Tested by @enlight3d on head 09014c5e6 (CPU only (test); host RTX 3090, Windows 11): shader_library: red with spirv_words.h from main (line 552, byte-swapped SPIR-V rejected); green with PR. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @alexandersato0830! AI-assisted: yes
Sign in to join this conversation.
No description provided.