From 76c040d35b320213bf3614fee4a66088f03bf21b Mon Sep 17 00:00:00 2001 From: chrg6 Date: Thu, 12 Nov 2026 10:12:23 -0500 Subject: [PATCH] Record a pool slot losing its picture in the flight recorder. When the pool's entry of a slot goes from a texture's view to the stand-in, events.tsv gets a line with the slot and what its own texture was at that moment: finalized, released, superseded, overwritten, uploaded, its storage readable, held out. The set is written with update-after-bind, so every draw of the submission that samples the slot reads the stand-in from then on; the check at the marks' read-back comes a frame later and finds the slot resolved again. Co-Authored-By: Claude Fable 5.2 --- runtime/flight.c | 8 +++++++- runtime/flight.h | 2 ++ runtime/vk.h | 4 ++++ runtime/vk_exec_draw.c | 29 +++++++++++++++++++++++++++-- runtime/vk_texture.c | 15 +++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/runtime/flight.c b/runtime/flight.c index c55f23dc..89827e7a 100644 --- a/runtime/flight.c +++ b/runtime/flight.c @@ -157,7 +157,7 @@ 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", "bytes", - "reg", "blank"}; + "reg", "blank", "toblank"}; // /events.tsv: one line per texture event of the dump's frames (flight_tex). static void write_events(const DumpJob *j) { @@ -192,6 +192,12 @@ static void write_events(const DumpJob *j) { 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_TOBLANK) { + static const char *const bit[] = {"finalized", "own entry", "released", "superseded", "overwritten", "uploaded", + "storage readable", "held out", "CPU-written", "GPU-owned", "retiring"}; + int o = snprintf(detail, sizeof detail, "slot %u lost its picture:", e->us); + for (int b = 0; b < 11 && o < (int)sizeof detail - 20; b++) + if (e->detail & 1u << b) o += snprintf(detail + o, sizeof detail - (size_t)o, " %s;", bit[b]); } 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" : ""); diff --git a/runtime/flight.h b/runtime/flight.h index 5a15dcad..d29c982d 100644 --- a/runtime/flight.h +++ b/runtime/flight.h @@ -26,6 +26,8 @@ enum { FLIGHT_TEX_NEW, FLIGHT_TEX_UP, FLIGHT_TEX_REUP, FLIGHT_TEX_RELEASE, FLIGH // 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_TOBLANK, // the pool's entry of a slot went from a texture's view to the stand-in (us: the slot; + // detail: vk_texture_slot_why_locked's bits, what the slot's own texture was then) 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.h b/runtime/vk.h index 76c1fc75..763ac012 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -585,6 +585,10 @@ const VkTexImage *vk_texture_exact_by_id_locked(int id, view_t *view, int *has_v uint32_t vk_texture_slots_gen(void); int vk_texture_slot_count_locked(void); void vk_texture_create_budget_locked(int n); // slot lookups create at most n entries (mapped storage only); -1 any +// For the flight recorder: what slot id's own texture is now, as bits (1 the slot is finalized, 2 an entry of its own +// descriptor exists, 4 that entry is released, 8 superseded, 16 overwritten, 32 uploaded, 64 the storage is readable, +// 128 held out by disuse, 256 CPU-written, 512 GPU-owned, 1024 retiring), with the slot's storage and size. +uint32_t vk_texture_slot_why_locked(int id, uint64_t *addr, uint32_t *format, uint32_t *w, uint32_t *h); uint64_t vk_texture_pool_make_ns_take(void); // ns the pool's lookups spent making and first uploading entries since the last call int vk_texture_create_deferred_locked(void); // a lookup since the last call left a creation to the budget // one past the highest texture slot registered so far (or more) int vk_sampler_slot_count_locked(void); diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index e382fce3..f28c02bd 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -19,6 +19,7 @@ #include #include "cfg.h" +#include "flight.h" #include "host.h" #include "nvn_api.h" #include "nvn_hmap.h" @@ -2446,7 +2447,25 @@ static void pool_unres(uint32_t id, int got) { PL.unres[PL.nunres++] = (int)id; } +// For the flight recorder: v is one of the stand-in views. +static int pool_view_blank(VkImageView v) { + for (int i = 0; i < DV_COUNT; i++) + if (v == Z.img[i].view || v == Z.img[i].sview) return 1; + return 0; +} + +// Slot id's entry of a kind went from the view was to now: noted when a texture's view gives way to the stand-in, which +// every draw of the submission that samples the slot then reads (the set is written with update-after-bind). +static void pool_note_blank(uint32_t id, VkImageView was, VkImageView now, int *noted) { + if (!flight_on || *noted || !was || pool_view_blank(was) || !pool_view_blank(now)) return; + uint64_t addr; + uint32_t fmt, w, h, why = vk_texture_slot_why_locked((int)id, &addr, &fmt, &w, &h); + flight_tex(FLIGHT_TEX_TOBLANK, addr, fmt, w, h, 0, 0, why, id); + *noted = 1; +} + static int pool_fill(VkExec *ex, uint32_t id, uint32_t mask, uint64_t tok) { + int noted = 0; vk_texture_create_deferred_locked(); PoolSlot *ps = &PL.ps[id]; uint64_t kh = 0; @@ -2468,7 +2487,10 @@ static int pool_fill(VkExec *ex, uint32_t id, uint32_t mask, uint64_t tok) { for (int k = 0; k < VK_POOL_KINDS; k++) { if (!(mask >> k & 1)) continue; VkImageView *e = &PL.view[(size_t)k * VK_POOL_TEX + id]; - if (*e != m->view[k]) *e = m->view[k], pool_write((uint32_t)k, id, m->view[k], VK_NULL_HANDLE); + if (*e != m->view[k]) { + pool_note_blank(id, *e, m->view[k], ¬ed); + *e = m->view[k], pool_write((uint32_t)k, id, m->view[k], VK_NULL_HANDLE); + } } ps->fmask = ps->stamp == m->stamp ? ps->fmask | mask : mask; ps->stamp = m->stamp; @@ -2482,7 +2504,10 @@ static int pool_fill(VkExec *ex, uint32_t id, uint32_t mask, uint64_t tok) { VkImage img; tex_info_full(ex, &r, tok ? id | 1ull << 63 : 0, 0, 1, &ii, &img); VkImageView *e = &PL.view[(size_t)k * VK_POOL_TEX + id]; - if (*e != ii.imageView) *e = ii.imageView, pool_write((uint32_t)k, id, ii.imageView, VK_NULL_HANDLE); + if (*e != ii.imageView) { + pool_note_blank(id, *e, ii.imageView, ¬ed); + *e = ii.imageView, pool_write((uint32_t)k, id, ii.imageView, VK_NULL_HANDLE); + } } int ok = !vk_texture_create_deferred_locked(); uint32_t ent = 0; diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index ccf82760..adeb458a 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -4256,6 +4256,21 @@ static Tex *slot_resolve(TexSlot *s, view_t *view, int *has_view) { return e; } +uint32_t vk_texture_slot_why_locked(int id, uint64_t *addr, uint32_t *format, uint32_t *w, uint32_t *h) { + *addr = 0, *format = *w = *h = 0; + if (id < 0 || id >= ntslots || !tslots[id].used) return 0; + const TexSlot *s = &tslots[id]; + TexKey k; + make_key(&s->t, &k); + const Tex *own = nvn_hm_get(&by_key, &k); + *addr = k.addr, *format = (uint32_t)s->t.d.format, *w = s->t.d.width, *h = s->t.d.height; + return (s->finalized ? 1u : 0) | (own ? 2u : 0) | (own && own->released ? 4u : 0) | (own && own->superseded ? 8u : 0) | + (own && own->overwritten ? 16u : 0) | (own && own->uploaded ? 32u : 0) | + (s->t.mem && mem_readable((uint64_t)(uintptr_t)s->t.mem, s->t.L.size) ? 64u : 0) | + (holds.n && nvn_hm_get(&holds, &k) ? 128u : 0) | (tex_mirrored(&s->t) ? 256u : 0) | + (own && own->pub.gpu_owned ? 512u : 0) | (own && own->retiring ? 1024u : 0); +} + void vk_texture_lock(void) { lock(); } void vk_texture_unlock(void) { unlock(); } uint32_t vk_texture_slots_gen(void) { return slots_gen; }