From dc69797746ee330d4478e53d6b80f19daf641baa Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 27 Oct 2026 10:17:14 +0300 Subject: [PATCH] Index recording copies by 64 KiB block instead of 4 KiB page: AddControlMemory walked about 500 pages per call under the exclusive copy lock (53 calls a frame, 2 MiB ranges on the 1.4.3 field), and the main thread and job workers recording command buffers waited on it; field walk 72-77 fps to 78-80 Co-Authored-By: Claude Opus 5.5 --- runtime/nvn_api_cmd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/nvn_api_cmd.c b/runtime/nvn_api_cmd.c index 054f3794..b05b1da2 100644 --- a/runtime/nvn_api_cmd.c +++ b/runtime/nvn_api_cmd.c @@ -29,7 +29,7 @@ #define MIN_COMMAND_SIZE 512 // NVN_DEVICE_INFO_COMMAND_BUFFER_MIN_COMMAND_SIZE (nvn_api_core.c devinfo) #define MIN_CONTROL_SIZE 256 // NVN_DEVICE_INFO_COMMAND_BUFFER_MIN_CONTROL_SIZE #define CTL_PER_RECORDING 64 // control memory one recording is reported to use -#define COPY_PAGE_SHIFT 12 +#define COPY_PAGE_SHIFT 16 // recording copy index granularity (release_copies) static cmd_t *cmd_of(const Cpu *c) { return arg_p(c, 0); } @@ -158,8 +158,10 @@ static const tex_t *tex_pin(const NVNtexture *nt) { } // ---------- recording copies -// A handle points just past a copy_prefix. Copies are indexed by the 4 KiB page of their control-memory position, so -// adding control memory again releases the copies recorded there without walking every live copy. +// A handle points just past a copy_prefix. Copies are indexed by the 64 KiB block of their control-memory position, so +// adding control memory again releases the copies recorded there without walking every live copy. 4 KiB pages cost +// about 500 lookups per AddControlMemory under the exclusive lock (1.4.3 field: 53 calls a frame, 2 MiB ranges, 3.7 +// copies per page), and the recording threads waited on it. typedef struct { uint64_t magic, bytes, made_at, used_at, deferred; } copy_prefix; // deferred: 0 unknown, 1 none, 2 some _Static_assert(sizeof(copy_prefix) % 8 == 0, "records stay 8-byte aligned"); typedef struct { uintptr_t lo, hi; uint8_t *copy; } cmd_copy;