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

Abierto
#715 13 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp, linux

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
C++
Estrellas
214
Forks
7
Merge medio
7 h 53 min
PR fusionados (30 d)
280

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de simnJS/AnyPS5

Todos los issues de simnJS/AnyPS5

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.