From bbcc50ae479ff3043d383649672933fc63873203 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sun, 25 Oct 2026 19:21:14 +0300 Subject: [PATCH 1/2] Count texture re-uploads and the share that follows WriteTexels in the perf lines Co-Authored-By: Claude Opus 5.5 --- runtime/vk_texture.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 752e75ef..ec0e012d 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -53,6 +53,7 @@ typedef struct Tex { uint64_t gpu_seq; // order of that GPU write among all of them (gpu_writes) uint64_t gpu_fence; // fence of the submission that made that write (0: not recorded in one) uint8_t listed; // in owned[] + uint32_t wt_n; // WriteTexels into the storage since the last upload } Tex; // A slot keeps what vk_texture_by_id resolved for it, so a draw binding skips the key lookup and the address chain: the @@ -80,6 +81,8 @@ static int nsslots; static nvn_hmap samplers = {.klen = sizeof(samp_par)}; static int nreleased; static uint64_t n_uploads, n_reuploads; +// Re-uploads since the last perf line (tex_lock): all, and those of textures a WriteTexels wrote since their last upload. +static uint64_t ru_n, ru_bytes, ru_ns, ru_wt_n, ru_wt_bytes, ru_wt_ns; // TOTK_TEX_ALIAS (default on; =0: a new image over live storage starts empty): a new descriptor over the storage of a // live image that the GPU wrote gets that image's content (alias_copy). Counts since the last log line. static int tex_alias = -1; @@ -514,7 +517,7 @@ static void upload(Tex *e) { const nvn_texdesc *d = &t->d; int bw, bh, bpb = nvn_fmt_bpb(d->format, &bw, &bh); if (!bpb || !t->mem) return; - uint64_t p0 = perf_begin(); + uint64_t p0 = perf_begin(), u0 = kern_now_ns(); int linear = nvn_tex_is_linear(d), is3d = d->target == NVN_TEXTURE_TARGET_3D, one_d = e->pub.type == VK_IMAGE_TYPE_1D; uint32_t levels = linear ? 1 : e->pub.levels, layers = linear ? 1 : e->pub.layers; int astc = e->f.astc_bw != 0, rgb = e->f.expand_rgb; @@ -594,8 +597,21 @@ static void upload(Tex *e) { free(raw_copy); free(ar); free(rg); - if (e->uploaded) n_reuploads++, perf_count(PERF_CNT_TEX_REUP); - else n_uploads++, perf_count(PERF_CNT_TEX_UP); + uint64_t dt = kern_now_ns() - u0; + if (e->uploaded) { + n_reuploads++, perf_count(PERF_CNT_TEX_REUP); + ru_n++, ru_bytes += t->L.size, ru_ns += dt; + if (e->wt_n) { + ru_wt_n++, ru_wt_bytes += t->L.size, ru_wt_ns += dt; + if (rt_trace & RT_TRACE_PERF) + rt_log("perf: frame %llu: re-upload after %u WriteTexels: texture %#llx fmt %#x %ux%u, %.1f KiB, %.3f ms", + (unsigned long long)__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), e->wt_n, + (unsigned long long)e->pub.addr, d->format, d->width, d->height, t->L.size / 1024.0, dt / 1e6); + } + } else { + n_uploads++, perf_count(PERF_CNT_TEX_UP); + } + e->wt_n = 0; e->uploaded = 1; e->n_up++; perf_end(PERF_TEX, p0); @@ -972,6 +988,10 @@ void vk_texture_new_submit(void) { (unsigned long long)f * 60, (unsigned long long)n_alias_copied, (unsigned long long)n_alias_upload, (unsigned long long)n_alias_uninit); n_alias_copied = n_alias_upload = n_alias_uninit = 0; + rt_log("perf: frame %llu: texture re-uploads %llu (%.1f MiB, %.2f ms), after WriteTexels %llu (%.1f MiB, %.2f ms)", + (unsigned long long)f * 60, (unsigned long long)ru_n, ru_bytes / 1048576.0, ru_ns / 1e6, + (unsigned long long)ru_wt_n, ru_wt_bytes / 1048576.0, ru_wt_ns / 1e6); + ru_n = ru_bytes = ru_ns = ru_wt_n = ru_wt_bytes = ru_wt_ns = 0; uint64_t ck, calls, untr; vk_mem_snap_stats(&ck, &calls, &untr); rt_log("perf: frame %llu: binding storage checks %llu (texture %llu), write-watch snapshot queries %llu, untracked %llu", @@ -1176,6 +1196,7 @@ void vk_write_texels(const tex_t *t, const view_t *v, const NVNcopyRegion *r, co log_limited(&n_bad, "WriteTexels: region outside level %u of texture %#llx", g.level, (unsigned long long)e->pub.addr); vk_guest_written((uintptr_t)t->mem, t->L.size); if (e->pub.gpu_owned) image_texels(e, &g, r, (uint8_t *)src, 1); + else if (e->uploaded) e->wt_n++; } else if (e) { image_texels(e, &g, r, (uint8_t *)src, 1); } From a220b894597dc1a776db8fbf178e446b509a2d7d Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 26 Oct 2026 08:16:10 +0300 Subject: [PATCH 2/2] Collect the open work in one list in docs/backlog.md, read the shared shader list's "*" texture kind as 2D, and record measurements from the other test machines The backlog gets one "Open work" section: freezes, bugs (the Yunobo fade with its repro), machine items and paused branches. prepare_shaders.py no longer stops on the "*" and "*_depth" texture kinds of the newer list revisions. The playbook records the GTX 1050 Ti, RTX 3090 Ti and 8th-gen i7 numbers and how to get a perf log from those machines; port-lessons gains the MacNativeGames virtual-core preemption row; totk.ini.example lists mouse_sens. Co-Authored-By: Claude Opus 5.5 --- docs/agent-playbook.md | 24 ++++- docs/backlog.md | 194 ++++++++++++++++++++++++++-------- docs/research/port-lessons.md | 1 + tools/prepare_shaders.py | 3 +- totk.ini.example | 2 + 5 files changed, 174 insertions(+), 50 deletions(-) diff --git a/docs/agent-playbook.md b/docs/agent-playbook.md index 9fdc6481..f20cee66 100644 --- a/docs/agent-playbook.md +++ b/docs/agent-playbook.md @@ -34,7 +34,8 @@ other `totk.exe` or `ninja.exe` runs. The log's first and last lines record the frame 600. `mem: class` (once at start) says whether the GPU counts as uma or discrete and lists its heaps and types. - With `perf`, `mem: dirty` every 60 frames: what a VRAM mirror of the buffer-bound pools would upload (pages the CPU wrote per frame and per submit, eager and lazy, by pool class), FlushMappedRange calls and bytes, and the mirror - size. The census costs about 1.1 ms of CPU per frame on the submitting thread; `perf_summary.py` summarises it. + size. The dirty count costs about 1.1 ms of CPU per frame on the submitting thread here (3 ms on an 8th-gen i7); + `perf_summary.py` summarises it. - `TOTK_PROFILE= TOTK_PROFILE_FRAMES=lo-hi`: sampling profiler (`runtime/prof_win.c`), read with `tools/prof_report.py `. With `TOTK_PROFILE_RENDER=1` it samples the render thread only and keeps call chains: the report adds inclusive time per function and the exe callers of the driver and system DLLs. @@ -66,11 +67,26 @@ RenderDoc cannot capture: the driver hides `VK_EXT_external_memory_host`. ## Other GPUs -The RX 9070 is the only GPU here; the build also has to run on NVIDIA and older AMD (Vega, wave64 only). New Vulkan code -queries the feature, extension, format or limit it uses and keeps a working path or a logged fallback when it is -missing (`vk_pipeline.c` provoking vertex and subgroup size pinning are examples). Never hard-code what this GPU +The RX 9070 is the only GPU agents can run; the build also has to run on NVIDIA and older AMD (Vega, wave64 only). New +Vulkan code queries the feature, extension, format or limit it uses and keeps a working path or a logged fallback when +it is missing (`vk_pipeline.c` provoking vertex and subgroup size pinning are examples). Never hard-code what this GPU reports: alignments, subgroup size, depth formats, `maxPushDescriptors`. +Numbers from this machine do not carry over. Measured on the user's other machines (2026-10-24/25, logs and analysis +in `build/mem-plan.md`): + +- GTX 1050 Ti (4 GiB, 214 MiB BAR, no ReBAR; i7 8th-10th gen) and RTX 3090 Ti: GPU time 110-120 ms per frame in the + world against 4.3 ms here, because the GPU reads imported host pools over PCIe. The VRAM mirror (cd6f490) brings + the 1050 Ti to 10-11 ms; that machine is now CPU-bound at 25-45 fps (replay 25-30 ms per frame, backlog 0b). +- The same write-watch scan costs about 3x the CPU time it costs here. +- NVIDIA has no ASTC: first texture uploads decode on the CPU, 0.4-0.7 s load frames (backlog 5a.2). +- `cannot alias its pool memory` fills its 16-line log limit on NVIDIA and on the RX 9070 alike (1920x1080, 1600x900, + 800x450 render targets); a suspect for the black patches of backlog 0a (`build/alias-plan.md`). + +A run on another machine goes through the user: copy `build/release/TotK-perf-log.vbs` next to the `totk.exe` you +hand over. It starts the game with `TOTK_TRACE=perf` and writes `logs\perf--