diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 19:38:04 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 19:38:04 -0500 |
| commit | 39879ce0fdcaea23ce3919c1e845dd360b17b0f8 (patch) | |
| tree | 894ddf50be120cdfbd80b28e895876c518cc2199 /runtime/shims/file_system.cpp | |
| parent | 273b3bdf9d6e736442ad584ad464df6e86ee928b (diff) | |
| parent | 1154976d49acca28ad436b90861e9f9aea28eba9 (diff) | |
Merge main into RT-PROTON-STORY-LOAD (#984)
Merges main at 1154976d4 into the integration branch at 273b3bdf9 (merge base ece4ba5b3). 42 files conflicted;
this commit is the resolution only. Build and test repairs follow in their own commits.
Rule of resolution: where both sides added different things, both stay; where both made the same change in two
forms, main's reviewed form stays and whatever #984's form did in addition is carried into it; where the two
changed the same code for different purposes, both purposes are kept.
Xbox proxy code (runtime/shims/d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_xs.cpp, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, registry.cpp):
- d3d12_xs_device.cpp is #984's file with main's differing pieces ported in: env_slot and the configurable device
routes, XboxQueueSlotRoutes, PresentationHandler / set_presentation_handler, the console caller rule for device
slots 61 and 74 (#383, #385), route_xbox_device_slot, slot 81 as GetFrameStatisticsX, create_host_device, the
console-form rule for slots 25 and 56, the console list IID of #359, and the forms of queue slot 18 (#403) and
list slot 139 (#396).
- Kept from #984: the list proxy with handle translation, queue slots 16/17 as Signal/Wait, the fence's
completed-value mirror, the shared FrameTokenSource, PresentX through queue_present_x when no handler is
attached (slot 30, or 32 on a queue detected as the newer layout), slots 27/53/55/57/70/71/133, the wider
pc_resource_desc, S_OK for queue slots past the PC table.
- Dropped: #984's GetFrameEventsX and LEONIDA_XS_FRAME_EVENTS_SLOT, its second-word rule for slot 61, its
undetected-layout rule for queue slot 18, its list IID mapping to GraphicsCommandList6; main's copy of the base
list proxy, its null-view slot 70 and its refusing slot 133.
Proxy tests (runtime/test/xs_proxy_mock_test.cpp, device_proxy_test.cpp, queue_proxy_test.cpp):
- Checks of both sides, each run once; main's forms of the render-target size and layout checks with #984's extra
cases added; main's --env-slots-74 and #984's --env-slots-70.
- Adapted to the merged code: the queue tail answers S_OK, slot 73 answers an unknown IID with the list proxy,
the queue slot 18 case installs a console caller. Dropped: #984's slot 81 GetFrameEventsX cases.
D3D12/Vulkan layer (runtime/shims/d3d12_com.cpp, d3d12_vulkan_device.cpp, runtime/src/command_list.h,
frame_pacer.h, shader_library.h, vulkan_backend.h, vulkan_replay.h, runtime/test/command_list_test.cpp,
d3d12_close_parity_test.cpp, d3d12_execute_indirect_validation_test.cpp, replay_texture_barrier_test.cpp,
vk_pipeline_check.cpp, vk_test_device.h):
- Resource::create_texture: #984's title images (deferred placed, pending streamed, title pool) and main's
ordinary textures (#1413 shared blocks, #1364 staging fallback) are exclusive branches chosen by the texture's
origin, so both pools run on disjoint sets of textures.
- frame_pacer.h is main's pacer (#402) with #984's FrameTokenSource as the token counter.
- main's forms kept for ExecuteIndirect (#1066, #377), the barrier into LAYOUT_UNDEFINED (#1055), the B4G4R4A4
stand-in, per-face stencil masks, the unaligned tile staging (#528) and the device-lost flag (#980).
- shader_library.h: main's block inflate; #984's `bulk` parameter now defaults to true so main's callers keep it.
- Dropped: #984's B8G8R8A8 stand-in for B4G4R4A4 targets, its refusal of separate stencil masks, its zero-count
refusal in ExecuteIndirect, its wider UNDEFINED -> UNDEFINED release and the test case for it.
Other shims (runtime/shims/dstorage.cpp, file_system.cpp, gameinput.cpp, xgameruntime_offline.cpp,
runtime/test/xgameruntime_offline_test.cpp, xmem_test.cpp):
- ReadFile and DirectStorage reads: #984's pinned kernel_writes read, then main's touch_pages retry on
ERROR_NOACCESS. main's rt::fs::read_file is folded into #984's read_file.
- gameinput: main's strict LEONIDA_INPUT_SCRIPT parser with #984's rsup/rsdown entries.
- Speech synthesis: main's one silent voice and handle checks; #984's accept-anything form dropped.
Build, tools, docs (runtime/CMakeLists.txt, runtime/cmake/translator_deps.cmake, scripts/build_runtime.ps1,
make_game.py, tools/rdna2spirv.py, shader_disasm.py, shader_ir.py, shader_library.py,
runtime/test/shaders/cs_imgload_tfe.asm, cs_imgload_d16_tfe.asm, docs/README.md, boot.md, d3d12_vulkan.md,
runtime/README.md):
- Unions of the test, target and source lists; spirv_loop_guard.py added to translator_deps.cmake.
- rdna2spirv.py: main's DPP compare rule (#957), SMEM vcc base (#647) and widen_wave64_masks (#1021); #984's
restore_skipped_instructions and restore_dot4_inline_sel. #984's duplicate widen_wave64_valu_masks dropped.
- shader_disasm.py and shader_ir.py: main's structure with #984's one-line-per-dword llvm-mc input and wave flags.
- shader_library.py: main's structure with #984's --compute-hashes and per-state compute variants.
One file that did not conflict is changed here: tools/rdna2_decode.py. Git kept both sides' decoders for a VOPC
compare with a DPP operand, and #984's narrower one shadowed main's; it is main's file again.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 0b08c7bb4..dad6f37a8 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -356,6 +356,10 @@ std::vector<std::wstring> parent_of(const std::vector<std::wstring>& parts) { | |||
| 356 | return parts.empty() ? parts : std::vector<std::wstring>(parts.begin(), parts.end() - 1); | 356 | return parts.empty() ? parts : std::vector<std::wstring>(parts.begin(), parts.end() - 1); |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | DWORD missing_error(const Roots& r, const std::vector<std::wstring>& parts) { | ||
| 360 | return is_folder(r, parent_of(parts)) ? ERROR_FILE_NOT_FOUND : ERROR_PATH_NOT_FOUND; | ||
| 361 | } | ||
| 362 | |||
| 359 | // Whether a folder has nothing in the title's view: no overlay entry and no package entry that is not deleted. | 363 | // Whether a folder has nothing in the title's view: no overlay entry and no package entry that is not deleted. |
| 360 | bool empty_in_view(const Roots& r, const std::vector<std::wstring>& parts) { | 364 | bool empty_in_view(const Roots& r, const std::vector<std::wstring>& parts) { |
| 361 | std::error_code ec; | 365 | std::error_code ec; |
| @@ -720,6 +724,26 @@ void note_open(const char* api, LPCWSTR name, DWORD access, const void* caller) | |||
| 720 | rt::startup_trace::quote(rt::startup_trace::where(reinterpret_cast<uint64_t>(caller)))); | 724 | rt::startup_trace::quote(rt::startup_trace::where(reinterpret_cast<uint64_t>(caller)))); |
| 721 | } | 725 | } |
| 722 | 726 | ||
| 727 | // Reads one byte of every 4 KiB page of [buffer, buffer + size) from user mode, so that pages committed on first | ||
| 728 | // touch (xmem's physical-page views: a reserve-only section committed by its vectored handler) are committed before | ||
| 729 | // the kernel writes into them. A page that is not valid at all is left for the caller's ReadFile to refuse. No C++ | ||
| 730 | // objects here: the function has __try. | ||
| 731 | bool touch_pages(void* buffer, DWORD size) { | ||
| 732 | auto* p = static_cast<volatile const unsigned char*>(buffer); | ||
| 733 | const uintptr_t first = reinterpret_cast<uintptr_t>(buffer) & ~uintptr_t{0xfff}; | ||
| 734 | const uintptr_t end = reinterpret_cast<uintptr_t>(buffer) + size; | ||
| 735 | bool all = true; | ||
| 736 | for (uintptr_t page = first; page < end; page += 0x1000) { | ||
| 737 | const uintptr_t at = page < reinterpret_cast<uintptr_t>(p) ? reinterpret_cast<uintptr_t>(p) : page; | ||
| 738 | __try { | ||
| 739 | (void)*reinterpret_cast<volatile const unsigned char*>(at); | ||
| 740 | } __except (EXCEPTION_EXECUTE_HANDLER) { | ||
| 741 | all = false; | ||
| 742 | } | ||
| 743 | } | ||
| 744 | return all; | ||
| 745 | } | ||
| 746 | |||
| 723 | HANDLE WINAPI create_file_w(LPCWSTR name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES attributes, | 747 | HANDLE WINAPI create_file_w(LPCWSTR name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES attributes, |
| 724 | DWORD disposition, DWORD flags, HANDLE template_file) { | 748 | DWORD disposition, DWORD flags, HANDLE template_file) { |
| 725 | if (!name) { | 749 | if (!name) { |
| @@ -1012,10 +1036,7 @@ BOOL WINAPI delete_file_w(LPCWSTR name) { | |||
| 1012 | removed = true; | 1036 | removed = true; |
| 1013 | } | 1037 | } |
| 1014 | } | 1038 | } |
| 1015 | if (!removed) { | 1039 | if (!removed) return fail_bool(missing_error(r, parts)); |
| 1016 | SetLastError(ERROR_FILE_NOT_FOUND); | ||
| 1017 | return FALSE; | ||
| 1018 | } | ||
| 1019 | return TRUE; | 1040 | return TRUE; |
| 1020 | } | 1041 | } |
| 1021 | 1042 | ||
| @@ -1104,7 +1125,7 @@ BOOL WINAPI remove_directory_w(LPCWSTR name) { | |||
| 1104 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); | 1125 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 1105 | if (drive_root(name, parts)) return fail_bool(ERROR_ACCESS_DENIED); // "GAME:" and "T:" themselves stay | 1126 | if (drive_root(name, parts)) return fail_bool(ERROR_ACCESS_DENIED); // "GAME:" and "T:" themselves stay |
| 1106 | const View v = view(r, parts); | 1127 | const View v = view(r, parts); |
| 1107 | if (v.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 1128 | if (v.kind == Kind::None) return fail_bool(missing_error(r, parts)); |
| 1108 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); | 1129 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); |
| 1109 | if (!empty_in_view(r, parts)) return fail_bool(ERROR_DIR_NOT_EMPTY); | 1130 | if (!empty_in_view(r, parts)) return fail_bool(ERROR_DIR_NOT_EMPTY); |
| 1110 | 1131 | ||
| @@ -1141,7 +1162,7 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 1141 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); | 1162 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 1142 | if (drive_root(from, src) || drive_root(to, dst)) return fail_bool(ERROR_ACCESS_DENIED); | 1163 | if (drive_root(from, src) || drive_root(to, dst)) return fail_bool(ERROR_ACCESS_DENIED); |
| 1143 | const View from_view = view(r, src); | 1164 | const View from_view = view(r, src); |
| 1144 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 1165 | if (from_view.kind == Kind::None) return fail_bool(missing_error(r, src)); |
| 1145 | const std::filesystem::path overlay_from = disk_path(r.overlay, src), overlay_to = disk_path(r.overlay, dst); | 1166 | const std::filesystem::path overlay_from = disk_path(r.overlay, src), overlay_to = disk_path(r.overlay, dst); |
| 1146 | if (same_entry(src, dst)) { | 1167 | if (same_entry(src, dst)) { |
| 1147 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same | 1168 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same |
| @@ -1392,7 +1413,7 @@ BOOL WINAPI set_file_attributes_w(LPCWSTR name, DWORD attributes) { | |||
| 1392 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); | 1413 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 1393 | if (parts.empty()) return fail_bool(ERROR_ACCESS_DENIED); | 1414 | if (parts.empty()) return fail_bool(ERROR_ACCESS_DENIED); |
| 1394 | const View v = view(r, parts); | 1415 | const View v = view(r, parts); |
| 1395 | if (v.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 1416 | if (v.kind == Kind::None) return fail_bool(missing_error(r, parts)); |
| 1396 | 1417 | ||
| 1397 | // The attributes belong to the overlay copy: a package file is copied up and a package folder mirrored first, | 1418 | // The attributes belong to the overlay copy: a package file is copied up and a package folder mirrored first, |
| 1398 | // so the package keeps its own attributes and reads, which prefer the overlay, see the new ones. | 1419 | // so the package keeps its own attributes and reads, which prefer the overlay, see the new ones. |
| @@ -1424,7 +1445,19 @@ using namespace rt::fs; | |||
| 1424 | // Reads into title memory. The D3D12 layer keeps some of the title's pages read-only between submissions to see | 1445 | // Reads into title memory. The D3D12 layer keeps some of the title's pages read-only between submissions to see |
| 1425 | // which ones the title writes (slot-133 shadow buffers); the kernel fails a read into such a page with | 1446 | // which ones the title writes (slot-133 shadow buffers); the kernel fails a read into such a page with |
| 1426 | // ERROR_NOACCESS instead of faulting, so the destination is pinned and opened first (title_page_watch.h). | 1447 | // ERROR_NOACCESS instead of faulting, so the destination is pinned and opened first (title_page_watch.h). |
| 1448 | // | ||
| 1449 | // One more retry for a destination the kernel still cannot write. The retail title reads into title memory that | ||
| 1450 | // xmem maps from physical pages committed on first touch; the kernel's write raises no user-mode fault, so ReadFile | ||
| 1451 | // fails with ERROR_NOACCESS (998), and the title's read loop sleeps 1 ms and retries forever (measured on 1.0.2.1, | ||
| 1452 | // native Windows). Touching the pages from user mode commits them; the read is then retried once. | ||
| 1427 | BOOL WINAPI read_file(HANDLE file, LPVOID buffer, DWORD bytes, LPDWORD read, LPOVERLAPPED overlapped) { | 1453 | BOOL WINAPI read_file(HANDLE file, LPVOID buffer, DWORD bytes, LPDWORD read, LPOVERLAPPED overlapped) { |
| 1454 | if (leonida::kernel_writes::read_file(file, buffer, bytes, read, overlapped)) return TRUE; | ||
| 1455 | if (GetLastError() != ERROR_NOACCESS || !buffer || !bytes) return FALSE; | ||
| 1456 | static std::atomic<bool> logged{false}; | ||
| 1457 | if (!logged.exchange(true)) | ||
| 1458 | std::fprintf(stderr, "[rt] fs: ReadFile into uncommitted title memory (ERROR_NOACCESS): committing the " | ||
| 1459 | "destination pages and retrying (logged once)\n"); | ||
| 1460 | touch_pages(buffer, bytes); | ||
| 1428 | return leonida::kernel_writes::read_file(file, buffer, bytes, read, overlapped); | 1461 | return leonida::kernel_writes::read_file(file, buffer, bytes, read, overlapped); |
| 1429 | } | 1462 | } |
| 1430 | BOOL WINAPI read_file_ex(HANDLE file, LPVOID buffer, DWORD bytes, LPOVERLAPPED overlapped, | 1463 | BOOL WINAPI read_file_ex(HANDLE file, LPVOID buffer, DWORD bytes, LPOVERLAPPED overlapped, |