Skip to content

runtime: ignore a UTF-8 BOM and trailing CR/LF in shader_path.txt (RT-852) - #8863

Open
ddaikodaiko wants to merge 2 commits into
ItsNotRexed:mainfrom
ddaikodaiko:fix/rt-852-shader-path-text
Open

ddaikodaiko wants to merge 2 commits into
ItsNotRexed:mainfrom
ddaikodaiko:fix/rt-852-shader-path-text

Conversation

@ddaikodaiko

Copy link
Copy Markdown

Claim: #8683 comment (RT-852).

What and why

configured_shader_directory() (runtime/shims/d3d12_vulkan_device.cpp) reads shader_path.txt next to gta6rt.exe and hands the bytes to std::filesystem::path unchanged. A file saved by a Windows editor carries a UTF-8 BOM and/or CRLF, and either becomes part of the directory name: the shader library is not found and every pipeline fails. Notepad's "UTF-8" is exactly that shape, so the default way to edit the file is the broken one.

The change moves the normalization into a small pure helper, runtime/src/shader_path_text.h (leonida::normalize_shader_path_text), and calls it in the reader before the existing empty/NUL checks:

  • drop a leading UTF-8 BOM (EF BB BF), and
  • drop trailing CR, LF, space and tab. No Windows path component can end in one of those, so this cannot merge two different paths.

A path without those bytes is unchanged byte for byte, including inner spaces and UTF-8 names. The Wine branch (text.front() == '/') and the LEONIDA_SHADERS override are untouched.

Testing

Synthetic test runtime/test/shader_path_text_test.cpp (new shader_path_text ctest, pure stdlib, no Vulkan, no GPU, no file): plain path, CRLF, LF, trailing spaces/tabs, BOM alone, BOM+CRLF, a lone BOM, an inner space and a UTF-8 name.

Windows 10 19045, MSVC 19.44.35229, Windows SDK 10.0.26100, RelWithDebInfo, RTX 3060 Ti (driver 32.0.16.1088):

$ ctest -C RelWithDebInfo -R "^shader_path_text$" --output-on-failure
1/1 Test #11: shader_path_text .................   Passed    0.05 sec

The seven tests that actually load translated shaders still pass with the change (d3d12_translated_draw, d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame, d3d12_m4_compute, d3d12_buffer_uav, d3d12_subgroup), and gta6rt rebuilds.

Related but separate: #8162 stages shader_path with file_mode and retries the write; this is the reading side only.

No game files. AI-assisted.

…-852)

A shader_path.txt saved by a Windows editor carries a UTF-8 BOM and CRLF, and the reader took both literally: the shader library was not found and every pipeline failed. Normalize the text in a small pure helper (BOM plus trailing CR/LF/space/tab; no Windows path can end in one) and cover it with a synthetic test.
@matheusfermiano-source

Copy link
Copy Markdown

Linux Debug CTest shader_path_text passes at 8dc7a74c. A Wine 11.22 integration probe confirmed the BOM/CRLF improvement for a synthetic catalog whose Unix path contained non-ASCII UTF-8. It also found a backward-compatibility issue with the trailing ASCII-space trim.

I made two directories with different marker files, catalog/index.json and catalog<space>/index.json. The probe read synthetic shader_path.txt bytes, applied the exact PR helper or the parent's byte handling, converted the selected directory to UTF-16, appended \index.json, and opened it through Wine's CreateFileW. For Unix-style inputs it used the runtime's wine_get_dos_file_name conversion. This is a path/read probe rather than a full runtime or shader test.

File value Parent path handling PR path handling
Z:\…\catalog<space> Opened the marker in catalog<space> Opened the marker in catalog
\\?\Z:\…\catalog<space> Opened the marker in catalog<space> Opened the marker in catalog
BOM + /…/catálogo + CRLF Open failed Opened the marker in catálogo

<space> is one literal final U+0020. The first two rows show a silent switch between two valid catalogs when the hand-edited config contains a DOS path. The default writer ends in the fixed leaf spirv, so the regression is on hand-configured paths. Microsoft also documents that the underlying filesystem can support names ending in spaces even when Windows shell conventions exclude them. Microsoft path rules

Stripping the BOM and line terminators alone would preserve the demonstrated RT-852 fix and these existing paths. If forgiving mis-typed spaces is desired too, checking the exact path first would avoid silently switching catalogs in this case.

AI-assisted (Codex). Synthetic files only.

@lohant27-netizen

Copy link
Copy Markdown

Tested 8dc7a74ca on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8871, #8869, #8825, #8863 and #8885 (no conflicts): pass.

A name ending in a space is legal on the filesystem (catalog vs 'catalog '), so trimming it could silently select a different directory. Only the UTF-8 BOM and the line terminator are dropped now, which is what RT-852 reports; the tests assert that a trailing space or tab survives.
@ddaikodaiko

Copy link
Copy Markdown
Author

Good catch, and you are right: trimming the trailing space could switch between two valid catalogs (catalog and catalog ), which is worse than not finding the typed directory. Fixed in 0198ca1e.

The helper now drops only the UTF-8 BOM and the trailing line terminators (CR/LF), exactly what RT-852 reports. No space or tab is touched. The test asserts the opposite of the old behaviour:

a trailing space is kept              -> "…\\spirv " stays "…\\spirv "
a trailing tab is kept                -> "…\\spirv\t" stays
a space before the line ending is kept -> "…\\spirv \r\n" -> "…\\spirv "
a file of only a line ending normalizes to empty

Windows 10 19045, MSVC 19.44, RelWithDebInfo:

1/1 Test #11: shader_path_text .................   Passed    0.04 sec
100% tests passed, 0 tests failed out of 1

and the seven tests that load translated shaders still pass with gta6rt rebuilt (d3d12_translated_draw, m2_textured, m2_formats, m3_frame, m4_compute, buffer_uav, subgroup).

Your probe case 1 and 2 (Z:\…\catalog and \\?\Z:\…\catalog ) now resolve to the same directory as before the change; the BOM+CRLF row keeps working. Thanks for running it on Wine and with a non-ASCII path.

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.

4 participants