From bbaf732b813e61e250c1f344aed71dd4540ae7fd Mon Sep 17 00:00:00 2001 From: chrg6 Date: Thu, 12 Nov 2026 10:04:25 -0500 Subject: [PATCH] Record what an upload read, slot registrations and sampled stand-ins in the flight recorder. Three more texture events for a dump's events.tsv: after each upload a hash of 64 probes of the storage and how many of them were all zero, so a second upload a frame later tells new bytes from the same ones and a first upload of unfilled storage shows; a slot registered with a CPU-written texture, with what the slot named before; and a slot a shader sampled that has no image of its own and follows none, so its stand-in was on screen. They are for telling why a texture shows wrong for one frame while the game streams textures in. Co-Authored-By: Claude Fable 5.2 --- runtime/flight.c | 12 +++++++++++- runtime/flight.h | 6 ++++++ runtime/vk_texture.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/runtime/flight.c b/runtime/flight.c index e316af0a..c55f23dc 100644 --- a/runtime/flight.c +++ b/runtime/flight.c @@ -156,7 +156,8 @@ static void copy_events(DumpJob *j, uint64_t first) { } } -static const char *const tex_kind_names[FLIGHT_TEX_N] = {"new", "up", "reup", "release", "takeback", "drop"}; +static const char *const tex_kind_names[FLIGHT_TEX_N] = {"new", "up", "reup", "release", "takeback", "drop", "bytes", + "reg", "blank"}; // /events.tsv: one line per texture event of the dump's frames (flight_tex). static void write_events(const DumpJob *j) { @@ -185,6 +186,15 @@ static void write_events(const DumpJob *j) { else if (e->kind == FLIGHT_TEX_DROP) snprintf(detail, sizeof detail, "%s", vk_texture_drop_name((int)e->detail)); else if (e->kind == FLIGHT_TEX_UP || e->kind == FLIGHT_TEX_REUP) snprintf(detail, sizeof detail, "%u WriteTexels", e->detail); + else if (e->kind == FLIGHT_TEX_BYTES) + snprintf(detail, sizeof detail, "probe hash %08x, %u of 64 probes all zero", e->detail, e->us); + else if (e->kind == FLIGHT_TEX_REG) { + static const char *const was[4] = {"an unused slot", "the slot named another descriptor at this storage", + "the slot named other storage", "the slot named a finalized texture"}; + snprintf(detail, sizeof detail, "slot %u: %s", e->us, was[e->detail & 3]); + } else if (e->kind == FLIGHT_TEX_BLANK) + snprintf(detail, sizeof detail, "slot %u sampled as its stand-in%s%s", e->us, e->detail & 1 ? ", finalized" : "", + e->detail & 2 ? ", held out" : ""); else detail[0] = 0; fprintf(f, "%llu\t%s\t%#llx\t%#x\t%u\t%u\t%u\t%s\t%s\t%u\n", (unsigned long long)e->frame, e->kind < FLIGHT_TEX_N ? tex_kind_names[e->kind] : "?", (unsigned long long)e->addr, e->format, e->w, diff --git a/runtime/flight.h b/runtime/flight.h index 33eb5c46..5a15dcad 100644 --- a/runtime/flight.h +++ b/runtime/flight.h @@ -20,6 +20,12 @@ void flight_frame(uint64_t frame, uint64_t now_ns, uint64_t interval_ns, const u // carries the frame whose counts in frames.tsv it is part of. Any thread: the ring takes no lock. A no-op until // flight_init turned the recorder on. enum { FLIGHT_TEX_NEW, FLIGHT_TEX_UP, FLIGHT_TEX_REUP, FLIGHT_TEX_RELEASE, FLIGHT_TEX_TAKEBACK, FLIGHT_TEX_DROP, + FLIGHT_TEX_BYTES, // after UP and REUP: what the upload read (detail: a hash of 64 probes of its storage; us: + // how many of the probes were all zero), so a second upload tells new bytes from the same + FLIGHT_TEX_REG, // a slot registered with a CPU-written texture (us: the slot; detail: what it named before: + // 0 nothing, 1 another descriptor at this storage, 2 other storage, 3 a finalized texture) + FLIGHT_TEX_BLANK, // a shader sampled a slot that has no image of its own and follows none: its stand-in was + // on screen (us: the slot; detail: bit 0 the slot is finalized, bit 1 it is held out) FLIGHT_TEX_N }; // The texture's flags: a depth or stencil image, mirrored (the CPU writes its storage), bound into pool memory, an ASTC // texture, written by the GPU (VkTexImage.gpu_owned). diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 582c2b12..ccf82760 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -1734,6 +1734,25 @@ static void flight_ev(const Tex *e, int kind, uint32_t detail, uint32_t us) { static uint64_t frames_now(void) { return __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED); } +// For the flight recorder, after an upload of e: FNV-1a over 64 probes of 64 bytes spread over its storage, and how many +// of them were all zero. Two uploads of one texture with the same hash read the same bytes at the probes; a first one +// with zero probes read storage the game had not filled. +static void flight_bytes(const Tex *e) { + if (!flight_on || !e->pub.mirrored || e->t.L.size < 64 * 64) return; + if (!mem_read_hold(e->pub.addr, e->t.L.size)) return; + const uint8_t *b = (const uint8_t *)(uintptr_t)e->pub.addr; + uint64_t step = (e->t.L.size - 64) / 63; + uint32_t h = 0x811c9dc5u, zero = 0; + for (int i = 0; i < 64; i++) { + const uint8_t *p = b + (uint64_t)i * step; + uint8_t any = 0; + for (int k = 0; k < 64; k++) h = (h ^ p[k]) * 0x01000193u, any |= p[k]; + zero += !any; + } + mem_read_release(); + flight_ev(e, FLIGHT_TEX_BYTES, h, zero); +} + static uint64_t key_hash(const TexKey *k) { // FNV-1a; make_key zeroes the key's padding uint64_t h = 0xcbf29ce484222325ull; const uint8_t *b = (const uint8_t *)k; @@ -2722,6 +2741,10 @@ void vk_pool_marks_read(const uint32_t *marks, uint32_t n) { followed = 1; if (trace) marks_check(p, id, now, 1); } + if (flight_on && !followed) // nothing of its own and nothing followed: its stand-in was on screen + flight_tex(FLIGHT_TEX_BLANK, k.addr, (uint32_t)s->t.d.format, s->t.d.width, s->t.d.height, 0, + tex_mirrored(&s->t) ? FLIGHT_TF_MIRRORED : 0, + (s->finalized ? 1u : 0) | (holds.n && nvn_hm_get(&holds, &k) ? 2u : 0), id); // The slot's own key may be held although an entry at its address took the mark: the slot shows the stand-in // then (slot_resolve follows fewer entries than the loop above credits), and only this drop makes its texture // again. Left to the case where the loop found nothing, such a slot kept the stand-in for good. @@ -3348,6 +3371,7 @@ static void upload(Tex *e) { n_uploads++, perf_count(PERF_CNT_TEX_UP); } flight_ev(e, e->uploaded ? FLIGHT_TEX_REUP : FLIGHT_TEX_UP, e->wt_n, (uint32_t)(dt / 1000)); + flight_bytes(e); e->wt_n = 0; e->uploaded = 1; e->n_up++; @@ -4073,6 +4097,10 @@ void vk_texture_register(int id, const tex_t *t, const view_t *v) { unlock(); return; } + if (flight_on && tex_mirrored(t)) + flight_tex(FLIGHT_TEX_REG, (uint64_t)(uintptr_t)t->mem, (uint32_t)t->d.format, t->d.width, t->d.height, 0, + FLIGHT_TF_MIRRORED, + !s->used ? 0 : s->finalized ? 3 : (uintptr_t)s->t.mem == (uintptr_t)t->mem ? 1 : 2, (uint32_t)id); s->t = *t; if (!s->used && id < VK_POOL_TEX) pool_slots++; s->used = 1;