Call for contributions: unified memory on PCs with separate RAM and VRAM

Đang mở
#715 13 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, linux
Lĩnh vực
backend, performance

Hướng nghiên cứu

Start with docs/dev/ARCHITECTURE.md and the named memory paths: guestMirror.cpp, bufferCache.cpp, guestHostView.cpp, memoryTracker.cpp, pageManager.cpp, hotWriteWatch.cpp, and vma.cpp. Pick one direction, then build a fixed-seed Vulkan benchmark in tools/ and record five before-and-after runs with GPU, driver, OS, and ReBAR details. A design proposal should explain ordering, constraints, and fallbacks; a prototype should report measured results and pass the applicable existing tests.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Why

A PS5 has one unified memory pool shared by CPU and GPU. A PC with a discrete GPU splits system RAM and VRAM across PCIe.

Today AnyKyty bridges the two with a single sparse Vulkan buffer (GuestMirror, 32 MiB DEVICE_LOCAL chunks with host-memory spill, capped at 768 GiB on NVIDIA because its ~896 GiB GPU VA space is shared across all allocations; RADV has 128 TiB). PageManager and MemoryTracker watch guest 4 KiB pages (mprotect+SIGSEGV on Linux, VirtualProtect+VEH on Windows, plus Linux HotWriteWatch using UFFD_FEATURE_WP_ASYNC + PAGEMAP_SCAN). CPU writes reach VRAM through staging/stream buffers and vkCmdCopyBuffer; unknown-reach dispatches can read host RAM via GuestHostView (VK_EXT_external_memory_host / /dev/udmabuf); GPU writes protect guest pages and come back to RAM through readbacks (BufferCache::DownloadMemory).

On a heavy native PS5 title, this bridge is now a primary bottleneck: GPU copies take the largest share of GPU time, and synchronous readback waits stall CPU worker threads while leaving the GPU idle. We want to gather community ideas, designs, and prototypes to rethink how AnyKyty keeps CPU and GPU memory coherent on discrete and unified-memory PCs.

What to pick (directions and tradeoffs)
  • Tighter GPU write-range tracking and copy reduction: when a shader binds a large pool as writable, marking the entire pool GPU-dirty triggers false CPU write faults, unnecessary readbacks, and re-uploads. Narrowing tracked write ranges, batching copies, and skipping unchanged re-uploads helps every GPU and OS (core/kyty/graphics/host_gpu/renderer/cache/bufferCache.cpp, core/kyty/graphics/host_gpu/memoryTracker.cpp).
  • Direct CPU writes into ReBAR-backed mirror chunks: on Resizable BAR GPUs (DEVICE_LOCAL | HOST_VISIBLE, e.g. 16 GiB BAR1), mapping mirror chunks and doing a write-combined memcpy from the CPU could replace staging + vkCmdCopyBuffer (core/kyty/graphics/host_gpu/renderer/cache/guestMirror.cpp).
    • Tradeoff: CPU reads from write-combined VRAM over PCIe are orders of magnitude slower than RAM, so readbacks must stay on cached download buffers.
    • Hard problem: ordering. A direct CPU write is only safe when no in-flight GPU tick can still read the old bytes of that range (queued GPU copies give that ordering for free).
  • Selective hybrid host-mapped memory (VK_EXT_external_memory_host / dma-buf): serving all guest memory from system RAM is a trap—our measurements over PCIe 4.0 x16 show ~26× slower sequential and ~34× slower random GPU reads than VRAM, and assuming snapshot semantics breaks with CPU/GPU races. Keeping read-heavy buffers in VRAM while serving only small, hot CPU↔GPU ping-pong ranges (command rings, sync/label pages, write-once uploads) directly from host memory with strict GPU-ordered sync is much more promising (core/kyty/graphics/host_gpu/renderer/cache/guestHostView.cpp).
  • Direct texture uploads and indirect copies: VK_EXT_host_image_copy (core in Vulkan 1.4) can upload static/streamed textures straight into OPTIMAL images without staging buffers or GPU queue copies (at the cost of CPU swizzle work); VK_KHR_copy_memory_indirect can avoid CPU round-trips for GPU-computed copy ranges.
  • True UMA zero-copy path (APUs / integrated GPUs): on unified-memory PCs (Steam Deck, AMD Strix Halo / Ryzen AI Max, integrated GPUs exposing DEVICE_LOCAL | HOST_VISIBLE | HOST_CACHED, potentially paired with VK_EXT_map_memory_placed), mirror copies and readbacks should be avoidable altogether once CPU/GPU hazard ordering is preserved.
  • OS dirty-page tracking and VRAM residency: exploring Windows GetWriteWatch (MEM_WRITE_WATCH) for hot anonymous write regions, tuning Linux userfaultfd/PAGEMAP_SCAN, and VK_EXT_pageable_device_local_memory + VK_EXT_memory_priority on Windows WDDM (core/kyty/graphics/host_gpu/pageManager.cpp, hotWriteWatch.cpp, vma.cpp).
Open questions we would love input on
  1. Ordering for direct ReBAR writes: what lightweight tracking (per-range last-reader tick, ring-buffered shadow slots, or copy-on-write fallback) best proves a dirty range has no in-flight GPU reader without adding per-draw CPU overhead?
  2. Narrowing GPU write ranges: how can we detect which subranges of a bound storage buffer a dispatch actually writes, without heavy readbacks or shader instrumentation stalls?
  3. Hybrid classification: what simple online heuristic cleanly separates "keep in VRAM" from "serve directly from host RAM over PCIe" across titles?
  4. Cross-vendor reality: what driver quirks have you hit with VK_EXT_map_memory_placed, VK_EXT_host_image_copy, ReBAR WC writes (vkd3d-proton's no_upload_hvv lessons), or NVIDIA's 896 GiB GPU VA limit across NVIDIA, AMD (RADV/Windows), and Intel?
Expected result

Either:

  • A concrete design proposal in this issue (citing data, driver/spec constraints, and how it handles CPU/GPU ordering and cross-vendor fallbacks), or
  • A focused prototype or pull request with measured before/after numbers on a synthetic benchmark and all existing tests passing.
How to test without our games

Write a small synthetic Vulkan benchmark or test in tools/ (1 to 30 s, fixed seed, printing throughput or latency): e.g., dirty-page write + staging-vs-ReBAR upload throughput, PCIe host-import vs VRAM shader bandwidth, readback round-trip latency under concurrent draws, or vkCopyMemoryToImage vs vkCmdCopyBufferToImage. Give before and after numbers on the same machine in the same session (five runs each), state GPU/driver/OS/ReBAR status, and verify existing tests (ctest -R '^kyty_shim_' when a GPU is available, or the CPU-only library/tracker tests). Do not claim a frame-rate gain you cannot measure without a title; claim the micro-benchmark and what bottleneck it models.

Difficulty

Medium to hard. Design discussions and small benchmark prototypes are welcome before any large refactor.

Who to ask

Comment in this issue; the maintainers read every comment, can share constraints from docs/dev/ARCHITECTURE.md and core/kyty/graphics/host_gpu/, and will benchmark promising designs on real titles.

Rules that apply to every call
  • Comment on the issue before you start coding, so two people do not duplicate work. One topic per pull request, against AnyKyty.
  • Conventional Commits (fix(kyty): ..., feat(kyty): ..., perf(kyty): ..., test(...), docs: ...). No comments in code. Nothing specific to one title: no game names, no title IDs, no data taken from a game, no per-title branches.
  • Say where a behaviour comes from: public specs, driver documentation, published write-ups, or your own measurements. Do not post or attach firmware files, system modules, or game files.
  • Each CI test finishes in 30 s. python3 tools/check_conventions.py --base origin/AnyKyty must pass before you push.
  • Build and test: docs/dev/START_HERE.md and docs/dev/BUILD.md.
Links
Ngôn ngữ chính
C++
Star
214
Fork
7
Merge trung bình
7 giờ 53 phút
Pull request đã merge (30 ngày)
280

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của simnJS/AnyPS5

Tất cả issue của simnJS/AnyPS5

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.