Skip to content

Runtime: load translated shaders from the packaged work directory (RT-287) - #4333

Open
ligmaSec wants to merge 1 commit into
ItsNotRexed:mainfrom
ligmaSec:runtime/packaged-shader-path
Open

ligmaSec wants to merge 1 commit into
ItsNotRexed:mainfrom
ligmaSec:runtime/packaged-shader-path

Conversation

@ligmaSec

@ligmaSec ligmaSec commented Nov 23, 2026 •

Copy link
Copy Markdown

RT-287. Coordination claim

The runtime stage records the absolute <work>/shaders/spirv path in shader_path.txt beside gta6rt.exe. The Vulkan backend reads it on first use. Wine and Proton convert the Unix path through the running prefix, so the launcher needs no fixed drive letter and no external path conversion command. An explicit shader directory supplied by the device or LEONIDA_SHADERS takes precedence. Paths stay wide on Windows when opening the index and modules.

Verification

  • Before the patch, the synthetic mapped draw returned exit 1 with no translated shaders when the override was unset, despite the shaders being present.
  • After packaging with separate output and work directories, Wine 10.0 resolved the work path through a private V: mapping and passed all 4,096 pixel checks on Mesa llvmpipe 25.0.7. Khronos validation reported no errors. UMU-Proton 11.0-2e found the same work directory through an S: mapping and passed the same draw. The work path contained spaces and a non-ASCII character.
  • A Windows-form UTF-8 sidecar passed under Wine. An explicit override pointing to a missing directory returned exit 1 and named that directory, confirming which configuration took precedence.
  • All 64 Python packaging and dry-run checks passed. shader_library passed in the native Linux build and in the Windows cross-build under Wine. An independent Windows 10 run (MSVC 19.40, RTX 4060 driver 32.0.16.1088) matched all 4,096 pixels with Vulkan validation active. It also confirmed the generated Unicode path and explicit override precedence. Native Windows verification

AI-assisted. Synthetic fixtures only. Software Vulkan and Xvfb, no physical GPU.

@molodayamama

Copy link
Copy Markdown

Native Windows verification of a6f6f054c515032fae10986c1388a33602b94b16: Windows 10 22H2 (19045.7058), RTX 4060 (32.0.16.1088), MSVC 19.40/Ninja RelWithDebInfo, Khronos Vulkan validation enabled.

For a local integration fixture I used d3d12_draw_test with its explicit info.shader_dir assignment removed and its synthetic shader library placed under a separate work path containing a space and a Cyrillic letter. I staged the test executable in a separate output directory using this branch's make_game.runtime(..., work=...); the backend and packaging code were unchanged.

  • Without shader_path.txt and with LEONIDA_SHADERS unset: exit 1 with no translated shaders.
  • With the sidecar emitted by the packager: confirmed the UTF-8 bytes, then started from a different working directory. The backend loaded all four synthetic shaders from the Unicode path, the draw test exited 0, and all 4096 pixels matched in the main readback. Vulkan validation was active.
  • With the good sidecar still present and LEONIDA_SHADERS set to a missing path: exit 1 naming the override's index.json, confirming precedence.

shader_library also passed, as did Windows test_make_game_platform.py (40/40) and test_make_game_dry_run.py (24/24). No game data. AI-assisted (Codex).

@akimfomin

Copy link
Copy Markdown

To complement the integrated Win10 draw above, I tested the Windows path-resolution and file-read code at a6f6f054 against 03b09a08 on Windows 11 28000.3501 (ACP 1251). The standalone Clang/MinGW probe used the original ShaderLibrary headers and the production directory-resolution method bodies, with unrelated device code omitted.

  • A UTF-8 shader_path.txt beside the executable pointed to an existing absolute directory containing spaces and characters outside the active code page. The process started from a different directory with a decoy sidecar. Main found no shader library without an override. The PR selected the executable-adjacent sidecar and read both synthetic SPIR-V modules from the primary and FSPX indexes.
  • Setting LEONIDA_SHADERS to a second directory with characters outside ACP 1251 failed on main after narrowing the path. The PR read both modules from the intended override and used it ahead of the sidecar.
  • An explicit device directory took precedence over the environment. Missing explicit/environment overrides reported the selected path. A malformed sidecar and a cwd-only decoy both failed cleanly.

Eight scenarios per revision. Scope was native Win32 path resolution and module file I/O. Synthetic inputs. AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

The path precedence is correct in static review - device > LEONIDA_SHADERS > sidecar (d3d12_vulkan_device.cpp:607-623), with filesystem_error caught, the Wine export guarded and wide paths used (shader_library.h:654,728-731,756-767). 40 platform tests pass, compileall/--help clean, merge clean, and the encoding test covers non-ASCII and spaces.

Four fixes before merge:

  • An empty-but-set LEONIDA_SHADERS returns an empty path and suppresses the sidecar (:395-400); treat empty as unset.
  • The sidecar is not trimmed, so a trailing newline defeats the lookup (:411-413).
  • CDECL vs Wine's WINAPI is wrong on x86 (harmless on x64) at :417.
  • No C++ test was added for the fallback chain.

AI-assisted review, no game files, no GPU.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a6f6f05 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). ctest -R "shader_library|d3d12_translated_draw|d3d12_draw": 4 tests per GPU, 3 pass, 1 skipped (shader_library_corpus, no translated corpus), 0 failed. pytest tests/test_make_game_platform.py: 40 passed. Not run: a packaged work directory with shader_path.txt (needs a translated shader set). No game files.

AI-assisted.

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown

Tested a6f6f05 on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: pass, no regression against main 03b09a0.

  • ctest: 154/154 passed, same 9 skips as main 03b09a0
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 164/210 native, 195/210 with LEONIDA_W64_EMULATE=1, 0 failed; identical to main 03b09a0
    AI-assisted (Claude Code, Claude Fable 5.1).

@2-CD

2-CD commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check (full native ctest suite, complementing the Win10/RTX 4060 integrated-draw and the Windows path-resolution checks above): NVIDIA GeForce RTX 5080 (driver 621.01) + AMD Radeon 610M iGPU (driver 32.0.13018.6), Windows 11, MSVC (VS BuildTools 18) + Ninja, RelWithDebInfo, Vulkan SDK headers fetched. Tested head a6f6f054 (base 03b09a08).

Build: clean, 168 targets.

Targeted (the shader-from-work-dir path), --repeat until-fail:3:

  • d3d12_vulkan_device, shader_library, run_tiny_game*: 11 tests pass x3 (shader_library_corpus skips - no corpus on this PC).
  • tests/test_make_game_platform.py: 40 tests OK.

Full suite (ctest -C RelWithDebInfo -j 6, excluding the 4 window-showing tests dxgi_swapchain|d3d12_present|vk_presenter_sync|xbox_present):

  • NVIDIA RTX 5080: 150/150 passed, 0 failed.
  • AMD Radeon 610M iGPU (LEONIDA_VK_DEVICE=Radeon): 150/150 passed, 0 failed.

The PR's unstable CI state did not reproduce locally.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Tested a6f6f054 (main 03b09a08 is an ancestor, no rebase needed) on Linux, no game files.

GPU suite (RTX 3080, driver 615.71.09, Vulkan 1.4.351) — identical to main on this machine:

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc
    → 195/210 passed, 15 skipped, 0 failed
  • without the variable → 164/210 passed, 46 skipped, 0 failed
  • main 03b09a08, same commands: 195/210 and 164/210, 0 failed. Your d3d12_vulkan_device.cpp and
    shader_library.h changes build with GCC and move nothing.

Your Python side: python -I tests/test_make_game_platform.py → 40 tests OK. The 28 pytest-marked files
run the way CI's translator-tests job does: 1592 passed, 1 failed on your branch and the same
1592 passed, 1 failed on main — the one failure is test_u16_high_half::test_d16_buffer_store_no_redundant_extract_after_shr16
(a spirv-val "previous definition" problem coming from aa2988cc, which #3902 fixes), unrelated to your change.
python -m compileall -q make_game.py tools tests: clean.

What we cannot cover here: the packaged-directory lookup you are adding runs through the shim's path handling on
Wine/Windows; on Linux nothing in the 210 programs goes down that route, so this is a build + suite + unit-test
confirmation, not a check of the Wine/Windows path itself. The RTX 5080 was not run in this pass (186 MiB free on
that card, another job holds it); it ran on the previous pass and matched the 3080 exactly.

Machine: Linux Mint 22 (Ubuntu 24.04 base), llvm-mc 20.1.2, SPIRV-Tools 2025.1~rc1 (Ubuntu packages), GCC 13.3,
Python 3.12.3 with pytest 9.2.0 and numpy 2.5.5, built with cmake -S runtime -B runtime/build/linux -DLEONIDA_VULKAN_HEADERS_FETCH=ON. AI-assisted testing, counts read through by hand.

@traeb0n

traeb0n commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a6f6f05 on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11 Pro 26300, MSVC 14.44 RelWithDebInfo (scripts/build_runtime.ps1), Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1 for ctest: the tests pass, but a non-UTF-8 shader_path.txt crashes the runtime (0xC0000409).

  • Full ctest -E loader -j 4: 150/150, 0 compiler warnings. shader_library, d3d12_draw, d3d12_translated_draw and d3d12_compute pass when run alone with -V.
  • The sidecar path, natively. As in @molodayamama's run, I built d3d12_draw_test with info.shader_dir left empty, unset LEONIDA_SHADERS, put shader_path.txt beside the exe, and started it from %TEMP%:
shader_path.txt result
none exit 1: no translated shaders: set LEONIDA_SHADERS to <work>/shaders/spirv (as intended)
UTF-8 path to the test's library exit 0: 4 translated shaders from C:\Users\…\Temp\leonida_draw_test, all pixel checks pass
same path + _ + byte 0xFC (a cp1252 ü, not valid UTF-8) exit 0xC0000409 (fail-fast after std::terminate), no [rt] line

Why it crashes: std::filesystem::path(std::u8string(...)) in configured_shader_directory() converts with MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS). On invalid UTF-8, MSVC's STL throws std::system_error, the base class, not std::filesystem::filesystem_error. The catch (const std::filesystem::filesystem_error&) in library() doesn't catch it, so the exception escapes. A user who edits the file in an ANSI editor, or a path written by something else in the console code page, would hit this. make_game.py itself always writes UTF-8.

A fix could be any of:

  • catch (const std::exception& e) around the call (the message already says "invalid translated shader path");
  • converting with MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, …) in configured_shader_directory() and returning {} with a message on failure.

One more from code reading only (not run): the reader keeps every byte, so a sidecar an editor saves with a trailing newline (or CRLF, or a UTF-8 BOM) becomes part of the path. Trimming trailing \r\n and a leading EF BB BF would make hand edits forgiving.

Baseline on main 03b09a0, same machine and settings: 150/150 ctest.

No game files. AI-assisted (Claude Code).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a6f6f05 on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101), Windows 11, MSVC 14.51: pass. This is a regression check only.

I built the branch with CMake and Ninja, RelWithDebInfo. The build has no Vulkan SDK, thus no validation layers. LEONIDA_SHADERS was not set.

ctest --output-on-failure -j 4 gives 134 tests: 132 pass and 2 fail. The 2 failures are d3d12_present and xbox_present. Main 03b09a08 gives the same result on this computer. These two tests fail here because of the window size. The 9 skipped tests and the 1 disabled test are the same. shader_library passes.

python -I tests/test_make_game_platform.py gives 40 tests, OK. With make_game.py from main 03b09a08, test_runtime_records_shader_work_directory gives an error.

I did not test the lookup of shader_path.txt in the runtime. No test in the suite uses it.

No game files. An AI tool helped me to run the tests.

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.

10 participants