mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 15:49:57 -04:00
Refresh the texture pool from a list of its entries instead of walking every slot, for about 7 % more frames a second where the replay thread is the limit.
Each submission's first sync of the bindless texture pool walked every registered slot, 33,000 in Kokiri Forest, to find the few textures the CPU wrote and the few slots that changed. Three parts of that walk change, each with its own switch (pool_fast, pool_presnap, pool_group; on by default, 0 and ab accepted): - The freshness check goes through a list of the entries the slots resolved to, with a check by 2 MiB region first; slots that resolved to nothing are looked up again when the game's memory map changes and every eighth submission. The use stamps the idle eviction reads are left from a count of the slots that hold each entry. - The check takes the write-watch snapshots of its regions first, so unchanged entries pass the region test. - The GPU-written slots of one address bucket with one descriptor form a group, which the dirty walk leaves alone while its first member is unchanged. Measured on an RTX 5090 at 2560x1440, standing in Kokiri Forest, in-run A/B over five runs with all three switched (three of them with the barrier change switched too): 93.6 to 100.7, 96.4 to 103.1, 95.8 to 102.6, 99.3 to 107.1 and 91.9 to 99.9 frames a second, the replay thread 0.7 to 0.8 ms a frame shorter; a control's blocks differ by 0.4 %. On a walk with NX2NAVI_POOL_GROUP_CHECK=1 no group that was left alone had missed a write, and screenshots across the A and B blocks show the same picture. From pull request #390. Not tried: the texture eviction under memory pressure (a 9 GiB budget was never reached on the walk), AMD and Intel drivers, Linux. One of the nine runs with it on ended by itself with exit code 0 and nothing in its log two seconds after the window lost the focus; three repeats of that run did not. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -683,6 +683,11 @@ static uint64_t image_bytes(void) {
|
||||
static int overlaps(uint64_t a, uint64_t n, uint64_t b, uint64_t m) { return a < b + m && b < a + n; }
|
||||
static int inside(uint64_t a, uint64_t n, RtRange r) { return a >= r.base && n <= r.size && a - r.base <= r.size - n; }
|
||||
|
||||
// Bumped (lock held exclusively) by every change of what is mapped or readable: vk_exec_draw.c's texture pool looks the
|
||||
// slots over unreadable storage up again only then (and now and then).
|
||||
static uint32_t map_gen;
|
||||
uint32_t mem_map_gen(void) { return __atomic_load_n(&map_gen, __ATOMIC_ACQUIRE); }
|
||||
|
||||
// ---- 0x01 SetHeapSize
|
||||
uint32_t mem_set_heap_size(uint64_t size, uint64_t *addr) {
|
||||
plat_mutex_lock(&lock);
|
||||
@@ -693,6 +698,7 @@ uint32_t mem_set_heap_size(uint64_t size, uint64_t *addr) {
|
||||
if (size > heap_size) commit(L.heap.base + heap_size, size - heap_size, "heap");
|
||||
if (size < heap_size) decommit(L.heap.base + size, heap_size - size, "heap");
|
||||
heap_size = size;
|
||||
__atomic_store_n(&map_gen, map_gen + 1, __ATOMIC_RELEASE);
|
||||
plat_mutex_unlock(&lock);
|
||||
if (addr) *addr = L.heap.base;
|
||||
return R_OK;
|
||||
@@ -749,6 +755,7 @@ uint32_t mem_set_permission(uint64_t a, uint64_t n, uint32_t perm) {
|
||||
}
|
||||
memset(t, (int)perm, n / PAGE);
|
||||
protect(a, n, perm == PERM_RW ? PLAT_PROT_RW : perm == PERM_R ? PLAT_PROT_READ : PLAT_PROT_NONE, "module data");
|
||||
__atomic_store_n(&map_gen, map_gen + 1, __ATOMIC_RELEASE);
|
||||
plat_mutex_unlock(&lock);
|
||||
rt_log("%s data permission +%#llx size %#llx perm %u", m->name, (unsigned long long)(a - m->base),
|
||||
(unsigned long long)n, perm);
|
||||
@@ -820,6 +827,7 @@ static uint32_t stack_move(int unmap, uint64_t dst, uint64_t src, uint64_t n) {
|
||||
stack_maps[nstack_maps++] = (StackMap){dst, src, n};
|
||||
}
|
||||
out:
|
||||
__atomic_store_n(&map_gen, map_gen + 1, __ATOMIC_RELEASE);
|
||||
plat_mutex_unlock(&lock);
|
||||
return r;
|
||||
}
|
||||
@@ -872,6 +880,7 @@ static uint32_t alias_map(int unmap, uint64_t a, uint64_t n) {
|
||||
alias_bytes += fresh * PAGE;
|
||||
}
|
||||
out:
|
||||
__atomic_store_n(&map_gen, map_gen + 1, __ATOMIC_RELEASE);
|
||||
plat_mutex_unlock(&lock);
|
||||
if (r) rt_log("%sMapPhysicalMemory %#llx+%#llx failed %#x (alias %#llx used, heap %#llx)", unmap ? "Un" : "",
|
||||
(unsigned long long)a, (unsigned long long)n, r, (unsigned long long)alias_bytes,
|
||||
|
||||
Reference in New Issue
Block a user