upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test
diff options
context:
space:
mode:
authorDimitar Pavlov <360593571+azsekazvamdimitar@users.noreply.github.com>2026-11-25 15:39:43 +0200
committerDimitar Pavlov <360593571+azsekazvamdimitar@users.noreply.github.com>2026-11-26 11:18:19 +0200
commit49a0b69fcdb80db1f2a44ce7ca0ab8dfdec1e403 (patch)
treedd53c9909834cbfeec85e7cbd188595c8a2d9931 /runtime/test
parenta73a57e1339be072baf5522351c8ec7f1482b56b (diff)
d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD)
A page xmem maps at two addresses was copied whole at every refresh, since a guard on one view doesn't fault a write through the other: about 1 GB a submission after the story load on a retail boot. ShadowPages now arms the geometry watch's cells of each aliased 64 KiB block at every address it is mapped and copies a block only when a cell's version moved. xmem tells the cells of a mapping change after updating the peers, and of list value writes made through the section. AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090 (NVIDIA 590.48.01).
Diffstat (limited to 'runtime/test')
-rw-r--r--runtime/test/d3d12_existing_heap_test.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/runtime/test/d3d12_existing_heap_test.cpp b/runtime/test/d3d12_existing_heap_test.cpp
index 25fa1f654..7848ac864 100644
--- a/runtime/test/d3d12_existing_heap_test.cpp
+++ b/runtime/test/d3d12_existing_heap_test.cpp
@@ -13,6 +13,7 @@
13#include "host_wine.h" 13#include "host_wine.h"
14#include "../shims/d3d12_com.h" 14#include "../shims/d3d12_com.h"
15#include "../src/title_page_watch.h" 15#include "../src/title_page_watch.h"
16#include "../src/title_geometry_watch.h"
16#include "../src/gfx10_descriptors.h" 17#include "../src/gfx10_descriptors.h"
17#include "../src/deferred_image_binding.h" 18#include "../src/deferred_image_binding.h"
18#include <dxgi1_4.h> 19#include <dxgi1_4.h>
@@ -922,6 +923,84 @@ int check_aliased_write(ID3D12Device* device) {
922 return 0; 923 return 0;
923} 924}
924 925
926// The same page, guarded at both addresses instead of copied at every submission. With the other address known (what
927// xmem answers through leonida::geometry_writes::aliases), the shadow at A arms the geometry watch's cells of the
928// aliased 64 KiB at A and at B: both read-only between submissions, and a submission that follows no write copies
929// nothing of it. The control: a write through a third view nobody reported doesn't fault, so it stays stale until a
930// write through B (which faults) marks the block; then both arrive. Each view commits its pages itself: Wine shows a
931// page of a SEC_RESERVE view as committed only in the view that committed it.
932std::uintptr_t g_alias_a, g_alias_b;
933void aliases_of_test_views(std::uintptr_t va, std::vector<std::uintptr_t>& others) {
934 if (va >= g_alias_a && va < g_alias_a + 4 * 0x10000) others.push_back(va - g_alias_a + g_alias_b);
935 if (va >= g_alias_b && va < g_alias_b + 4 * 0x10000) others.push_back(va - g_alias_b + g_alias_a);
936}
937
938int check_aliased_guard(ID3D12Device* device) {
939 const char* who = "vulkan slot-133 aliased page, guarded";
940 constexpr SIZE_T size = 4 * 0x10000;
941 constexpr UINT64 committed = size / 2, block = 0x10000, at = 0x11000;
942 HANDLE section = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE | SEC_RESERVE, 0, DWORD(size),
943 nullptr);
944 EXPECT(section != nullptr);
945 std::uint8_t* views[3]{};
946 for (auto& view : views) {
947 view = static_cast<std::uint8_t*>(MapViewOfFile(section, FILE_MAP_ALL_ACCESS, 0, 0, size));
948 EXPECT(view != nullptr && VirtualAlloc(view, committed, MEM_COMMIT, PAGE_READWRITE) == view);
949 }
950 std::uint8_t *a = views[0], *b = views[1], *c = views[2];
951 g_alias_a = reinterpret_cast<std::uintptr_t>(a);
952 g_alias_b = reinterpret_cast<std::uintptr_t>(b);
953 leonida::geometry_writes::aliases.store(&aliases_of_test_views, std::memory_order_release);
954 leonida::title_page_aliases::set(g_alias_a + block, true);
955 leonida::title_page_aliases::set(g_alias_b + block, true);
956 long long unreported = -1, faulted = -1;
957 DWORD at_a = 0, at_b = 0, b_written = 0;
958 {
959 Ref<ID3D12Resource> buffer;
960 buffer.p = place_shadow(device, a, size);
961 EXPECT(buffer.p != nullptr);
962 GpuReader reader;
963 if (reader.init(device, size)) return 1;
964 std::vector<std::uint8_t> want(size, 0), got;
965 for (UINT64 i = 0; i < committed; ++i) want[i] = a[i] = pattern_byte(i, 23);
966 EXPECT(reader.read(buffer.p, got) == 0);
967 EXPECT(first_difference(got, want) == -1);
968 at_a = protection_of(a + at);
969 at_b = protection_of(b + at);
970 EXPECT((at_a & 0xff) == PAGE_READONLY);
971 EXPECT((at_b & 0xff) == PAGE_READONLY);
972 // Nothing written: the block is not copied, so a write the cells can't see is not either.
973 for (UINT64 i = at; i < at + 64; ++i) want[i] = c[i] = 0x5a;
974 EXPECT(reader.read(buffer.p, got) == 0);
975 unreported = first_difference(got, want);
976 // Through B: faults, and the block is copied again (the write through C with it).
977 for (UINT64 i = at + 0x800; i < at + 0x1000; ++i) want[i] = b[i] = pattern_byte(i, 151);
978 b_written = protection_of(b + at);
979 EXPECT(reader.read(buffer.p, got) == 0);
980 faulted = first_difference(got, want);
981 EXPECT((protection_of(b + at) & 0xff) == PAGE_READONLY);
982 // Through A, the shadow's own address.
983 for (UINT64 i = at; i < at + 16; ++i) want[i] = a[i] = 0xc3;
984 EXPECT(reader.read(buffer.p, got) == 0);
985 EXPECT(first_difference(got, want) == -1);
986 }
987 // Released: both addresses are writable again.
988 EXPECT((protection_of(a + at) & 0xff) == PAGE_READWRITE);
989 EXPECT((protection_of(b + at) & 0xff) == PAGE_READWRITE);
990 leonida::title_page_aliases::set(g_alias_a + block, false);
991 leonida::title_page_aliases::set(g_alias_b + block, false);
992 leonida::geometry_writes::aliases.store(nullptr, std::memory_order_release);
993 for (auto* view : views) UnmapViewOfFile(view);
994 CloseHandle(section);
995 std::printf("%s: protection between submissions 0x%lx at A, 0x%lx at B (0x%lx after the write through B); an "
996 "unreported view's write: first stale byte at %lld (expected 69632); after a write through B: %s\n",
997 who, at_a, at_b, b_written, unreported, faulted == -1 ? "arrives" : "STILL STALE");
998 EXPECT(unreported == static_cast<long long>(at));
999 EXPECT((b_written & 0xff) == PAGE_READWRITE);
1000 EXPECT(faulted == -1);
1001 return 0;
1002}
1003
925// Kernel writes into a watched page. ReadFile writes from kernel mode, so a page a shadow made read-only fails it 1004// Kernel writes into a watched page. ReadFile writes from kernel mode, so a page a shadow made read-only fails it
926// with ERROR_NOACCESS instead of faulting into the layer: the plain call fails (the control). Through the file shims' 1005// with ERROR_NOACCESS instead of faulting into the layer: the plain call fails (the control). Through the file shims'
927// path (leonida::kernel_writes::read_file, what the title's ReadFile import resolves to), the destination is pinned 1006// path (leonida::kernel_writes::read_file, what the title's ReadFile import resolves to), the destination is pinned
@@ -1960,6 +2039,7 @@ int check_written_pages_all(ID3D12Device* device) {
1960 failures += check_concurrent_writes(device, false); 2039 failures += check_concurrent_writes(device, false);
1961 if (leonida::title_write_watch::enabled()) failures += check_concurrent_writes(device, true); 2040 if (leonida::title_write_watch::enabled()) failures += check_concurrent_writes(device, true);
1962 failures += check_aliased_write(device); 2041 failures += check_aliased_write(device);
2042 failures += check_aliased_guard(device);
1963 failures += check_kernel_write(device); 2043 failures += check_kernel_write(device);
1964 failures += check_shared_pages(device); 2044 failures += check_shared_pages(device);
1965 return failures; 2045 return failures;