mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 15:59:59 -04:00
Remove the read-back refresh of the VRAM mirror, which brought back the tree columns.
Copying the invalidated ranges from guest memory into the mirror at every submission put the guest's copy of those pages over GPU results that live only in the mirror. In adult Hyrule Field that wiped tree records, and the trees stretched into columns reaching the sky again. With NX2NAVI_READBACK_SYNC=0 the columns did not appear at the same spot. The memory check (NX2NAVI_MEMORY=verify) still finds mirror pages newer than guest memory there with or without the refresh, about 3 per 60 frames, which is left for later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,7 @@ static const char *const known[] = {
|
||||
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE",
|
||||
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
|
||||
"MV_SURVEY",
|
||||
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME", "READBACK_SYNC",
|
||||
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_RES_FIXED", "PATCH_SCENE", "PATCH_WIDE_ASPECT", "PATCH_WIDE_HUD", "PATCH_WIDE_MOVIE", "PATCH_WIDE_OUT", "PATCH_WIDE_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POWER_FULL", "TEX_SAME",
|
||||
"PREWARM_FULL", "PREWARM_WAIT_MS", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
|
||||
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_END", "REEXEC",
|
||||
"RENDER_SCALE", "REPLAY_ASYNC", "RTSS",
|
||||
|
||||
@@ -114,9 +114,6 @@ const char *nvn_op_name(uint32_t op); // "DRAW_IDX", ...; "
|
||||
// MemoryPoolInvalidateMappedRange: the CPU is about to read pool storage the GPU wrote. Weak no-op in nvn_ext.c; a back
|
||||
// end that renders into host-side copies defines it and writes them back.
|
||||
void nvn_pool_invalidate(const pool_t *p, uint64_t off, uint64_t size);
|
||||
// The range nvn_pool_invalidate is about to read back. Weak no-op in nvn_ext.c; a back end that keeps device-side copies
|
||||
// of pool memory (vk_memory.c, "read-back ranges") defines it and refreshes the range from guest memory at every use.
|
||||
void nvn_pool_invalidated(const pool_t *p, uint64_t off, uint64_t size);
|
||||
// MemoryPoolFlushMappedRange: the CPU wrote [mem + off, mem + off + size). Weak no-op in nvn_ext.c; a back end that keeps
|
||||
// device-side copies of pool memory (vk_memory.c's VRAM mirror) defines it and copies the range again.
|
||||
void nvn_pool_flushed(const pool_t *p, uint64_t off, uint64_t size);
|
||||
|
||||
@@ -16,13 +16,9 @@
|
||||
void nvn_pool_invalidate(const pool_t *p, uint64_t off, uint64_t size) {
|
||||
if (!p->mem || nvn_gpu_only((uintptr_t)p->mem) || off >= p->size || !size) return;
|
||||
if (size > p->size - off) size = p->size - off;
|
||||
nvn_pool_invalidated(p, off, size);
|
||||
gfx_backend()->guest_read((uintptr_t)p->mem + off, size);
|
||||
}
|
||||
|
||||
__attribute__((weak)) void nvn_pool_invalidated(const pool_t *p, uint64_t off, uint64_t size) {
|
||||
(void)p, (void)off, (void)size;
|
||||
}
|
||||
__attribute__((weak)) void nvn_pool_flushed(const pool_t *p, uint64_t off, uint64_t size) { (void)p, (void)off, (void)size; }
|
||||
|
||||
// ---------- debug labels, markers, groups, checkpoints: meaningful only to NVN debugging tools
|
||||
|
||||
@@ -36,11 +36,6 @@ typedef struct { struct PoolRec *phys; uint64_t off; } VPage; // virtual page
|
||||
|
||||
#define FLUSH_RANGES 32 // flush ranges a mirrored pool keeps between two syncs (flush_add)
|
||||
typedef struct { uint64_t lo, hi; } FlushRange;
|
||||
// Read-back ranges: small results the CPU invalidates, reads and often writes again (the exposure meter: the GPU adds
|
||||
// a frame's light into it, the CPU reads the sum and stores 0). mirror_sync copies them from guest memory into the
|
||||
// mirror at every submission that uses the pool, whether or not a write was seen: see "read-back ranges" below.
|
||||
#define READBACK_RANGES 4
|
||||
#define READBACK_MAX (16u << 10)
|
||||
|
||||
typedef struct PoolRec {
|
||||
const pool_t *key;
|
||||
@@ -73,8 +68,6 @@ typedef struct PoolRec {
|
||||
FlushRange fl[FLUSH_RANGES + 1]; // flush_lock: nvnMemoryPoolFlushMappedRange pages not copied yet (flush_add)
|
||||
int fl_n; // flush_lock: ranges in fl; read without the lock to skip an empty list
|
||||
uint64_t fl_calls, fl_sum; // flush_lock: the calls and bytes behind fl, for mirror_sync's statistics
|
||||
FlushRange rb[READBACK_RANGES + 1]; // flush_lock: read-back ranges (nvn_pool_invalidated), guest addresses
|
||||
int rb_n; // flush_lock: ranges in rb; read without the lock to skip an empty list
|
||||
// Shadow storage (POOL_IMPORT in shadow mode, "shadow storage" below): buf is a host-visible copy of the guest pages.
|
||||
VmaAllocation salloc;
|
||||
uint8_t *smap; // its mapping; offsets as in buf (from import_lo)
|
||||
@@ -1243,7 +1236,6 @@ typedef struct {
|
||||
uint64_t presnap_queries, sync_queries, presnap_t, sync_t, prologues, presnap_bytes;
|
||||
uint64_t snap_bytes, merge_bytes, merge_dispatches, snap_allocs; // write-back merge
|
||||
uint64_t page_bytes, flush_n, flush_bytes, flush_calls, flush_sum; // what mirror_sync queues, by source
|
||||
uint64_t rb_n, rb_bytes; // read-back ranges mirror_sync queued
|
||||
} MirrorAcc;
|
||||
static MirrorAcc mrep; // replay: this submission
|
||||
static MirrorAcc macc; // mirror_stat_lock: since the last summary
|
||||
@@ -1501,19 +1493,6 @@ static void mirror_sync(PoolRec *r) {
|
||||
(hi - lo) / 1048576.0, n, (unsigned long long)calls, sum / 1048576.0);
|
||||
}
|
||||
}
|
||||
if (__atomic_load_n(&r->rb_n, __ATOMIC_ACQUIRE)) {
|
||||
FlushRange rb[READBACK_RANGES];
|
||||
plat_mutex_lock(&flush_lock);
|
||||
int n = r->rb_n;
|
||||
memcpy(rb, r->rb, (size_t)n * sizeof *rb);
|
||||
plat_mutex_unlock(&flush_lock);
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint64_t a = rb[i].lo > lo ? rb[i].lo : lo, b = rb[i].hi < hi ? rb[i].hi : hi;
|
||||
if (a >= b) continue;
|
||||
range_add(&pend, &npend, &cpend, r, a - lo, b - a);
|
||||
mrep.rb_n++, mrep.rb_bytes += b - a;
|
||||
}
|
||||
}
|
||||
mrep.syncs++;
|
||||
mrep.sync_t += qpc() - t0;
|
||||
}
|
||||
@@ -1855,36 +1834,6 @@ void nvn_pool_flushed(const pool_t *p, uint64_t off, uint64_t size) {
|
||||
plat_mutex_unlock_shared(&pool_lock);
|
||||
}
|
||||
|
||||
// ---- read-back ranges
|
||||
// mirror_sync decides at record time which guest pages to copy into the mirror; the copy itself runs when the GPU
|
||||
// reaches the submission. A CPU write in between (the game's threads overlap the replay) is in guest memory when the
|
||||
// copy runs but was not seen at record time, so the GPU works on the mirror's older bytes and the write-back puts
|
||||
// them over the CPU's: the exposure meter added a frame onto the sum the CPU had already read, it read twice the
|
||||
// light one frame and none the next, and the picture flared or dimmed for a frame. A range the CPU invalidates is a
|
||||
// result it reads and may reset, so every submission that uses its pool copies it unconditionally, last of the
|
||||
// uploads, and the GPU adds to what the CPU left there. Small ranges only, READBACK_RANGES per pool (the nearest two
|
||||
// merge beyond that). NX2NAVI_READBACK_SYNC=0 turns it off.
|
||||
static int readback_on = -1;
|
||||
static volatile int64_t m_rb_calls;
|
||||
void nvn_pool_invalidated(const pool_t *p, uint64_t off, uint64_t size) {
|
||||
if (!vk_mirror_on || !size || size > READBACK_MAX || !p->mem) return;
|
||||
if (readback_on < 0) { const char *v = cfg_get("NX2NAVI_READBACK_SYNC"); readback_on = !(v && !strcmp(v, "0")); }
|
||||
if (!readback_on) return;
|
||||
plat_inc64(&m_rb_calls);
|
||||
plat_mutex_lock_shared(&pool_lock);
|
||||
const pidx_ent *e = pidx_find(&pool_index, (uintptr_t)p->mem, 0);
|
||||
PoolRec *r = e && e->key == p ? e->buf : NULL;
|
||||
if (r && r->kind == POOL_IMPORT) {
|
||||
uint64_t a = ((uintptr_t)p->mem + off) & ~0xfffull, b = ((uintptr_t)p->mem + off + size + 0xfff) & ~0xfffull;
|
||||
plat_mutex_lock(&flush_lock);
|
||||
int known = 0;
|
||||
for (int i = 0; i < r->rb_n && !known; i++) known = r->rb[i].lo <= a && b <= r->rb[i].hi;
|
||||
if (!known) __atomic_store_n(&r->rb_n, flush_add(r->rb, r->rb_n, a, b, READBACK_RANGES), __ATOMIC_RELEASE);
|
||||
plat_mutex_unlock(&flush_lock);
|
||||
}
|
||||
plat_mutex_unlock_shared(&pool_lock);
|
||||
}
|
||||
|
||||
// gen_lock exclusive: freezes up to FREEZE_PER_SUB candidate regions still idle. The query after the
|
||||
// protection collects the writes made before it took effect.
|
||||
static void freeze_pass(void) {
|
||||
@@ -2134,11 +2083,9 @@ static void mirror_log(uint64_t frame) {
|
||||
a.merge_dispatches / f, a.snap_bytes / f / M, a.snap_allocs / f, fc / f, fb / f / M,
|
||||
a.presnap_queries / f, a.presnap_bytes / f / M, a.sync_queries / f, a.prologues / f, qpc_ms(a.presnap_t + a.sync_t) / f,
|
||||
qpc_ms(a.presnap_t) / f, qpc_ms(a.sync_t) / f, ver);
|
||||
uint64_t rc = (uint64_t)plat_xchg64(&m_rb_calls, 0);
|
||||
rt_log("mem: mirror frame %llu: upload sources per frame, overlaps counted twice: written pages %.3f MiB; flush ranges "
|
||||
"%.2f, %.3f MiB, from %.1f flushes of %.3f MiB; read-back ranges %.2f, %.4f MiB, from %.2f invalidates",
|
||||
(unsigned long long)frame, a.page_bytes / f / M, a.flush_n / f, a.flush_bytes / f / M, a.flush_calls / f,
|
||||
a.flush_sum / f / M, a.rb_n / f, a.rb_bytes / f / M, rc / f);
|
||||
"%.2f, %.3f MiB, from %.1f flushes of %.3f MiB", (unsigned long long)frame, a.page_bytes / f / M, a.flush_n / f,
|
||||
a.flush_bytes / f / M, a.flush_calls / f, a.flush_sum / f / M);
|
||||
}
|
||||
|
||||
// With NX2NAVI_TRACE=perf every 600 frames: what holds device-local memory, to see what grows over a long session.
|
||||
|
||||
Reference in New Issue
Block a user