Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions runtime/shims/xmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,13 @@ bool title_mapped_twin(uintptr_t address, uintptr_t gpu, bool unmap) {
return true;
}

auto find_mapped_source_page(uintptr_t source) {
const auto mapped = g_mapped.find(source);
if (mapped != g_mapped.end()) return mapped;
const uintptr_t cpu_source = leonida::title_gpu_views::to_cpu(source, kPhysicalPageSize);
return cpu_source == source ? mapped : g_mapped.find(cpu_source);
}

bool copy_page_mappings(void* destination, const void* source, uint64_t pages, bool repeat_first) {
const uintptr_t to = reinterpret_cast<uintptr_t>(destination);
const uintptr_t from = reinterpret_cast<uintptr_t>(source);
Expand Down Expand Up @@ -2062,11 +2069,7 @@ bool copy_page_mappings(void* destination, const void* source, uint64_t pages, b
std::vector<uint64_t> found(static_cast<size_t>(pages), 0);
for (uint64_t i = 0; i < pages; ++i) {
const uintptr_t src_va = from + (repeat_first ? 0 : i) * kPhysicalPageSize;
auto it = g_mapped.find(src_va);
if (it == g_mapped.end()) { // a GPU-only source whose pages were mapped at its CPU view
const uintptr_t cpu_src = leonida::title_gpu_views::to_cpu(src_va, kPhysicalPageSize);
if (cpu_src != src_va) it = g_mapped.find(cpu_src);
}
const auto it = find_mapped_source_page(src_va);
if (it != g_mapped.end()) found[static_cast<size_t>(i)] = it->second;
}
const DWORD protect = view_protect(*window);
Expand Down Expand Up @@ -2479,7 +2482,7 @@ bool copy_page_mappings(std::uint32_t count, const PageBatch* batches, std::uint
const auto source = pool + uint64_t(r.start) * kPhysicalPageSize;
for (uint32_t j = 0; j < n; ++j) {
const auto src = source + uint64_t(j) * kPhysicalPageSize;
const auto it = g_mapped.find(src);
const auto it = find_mapped_source_page(src);
if (it == g_mapped.end()) {
// A hole in a valid source window unmaps the destination (CLHelper, RT-QUEUE31).
if (!find_window(src, kPhysicalPageSize))
Expand Down
8 changes: 8 additions & 0 deletions runtime/test/xmem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ void test_copy_page_mappings_cpu_view(const PhysicalApi& api) {
check(readable(other) && page_holds(other, 0x7300u),
"a GPU-only source page unmapped there is looked up at its CPU range");

api.map(other, 1, nullptr);
const rt::xmem::PageRange cpu_source{0, 2, 1};
const rt::xmem::PageBatch batch{reinterpret_cast<uintptr_t>(other), 1, &cpu_source};
check(rt::xmem::copy_page_mappings(1, &batch, reinterpret_cast<uintptr_t>(gpu), kPair, 0),
"a batch copies from a GPU-only range whose source page is mapped at its CPU view");
check(readable(other) && page_holds(other, 0x7300u),
"a batch source at the paired CPU view leaves its destination mapped with the source bytes");

// A CPU page the title mapped itself is the title's: a copy onto its GPU-only page, or an unmap of it, changes the
// GPU-only page alone (the console's CopyPageMappingsBatchX edits only that range's page table).
check(copy(gpu + 2 * kPage64k, pool + kPage64k, 1, false), "a copy onto a GPU-only page whose CPU page is the title's");
Expand Down
Loading