From 90a3b07762b9a83c828f1953e63d29a144d5b2c1 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 2 Nov 2026 14:59:49 +0300 Subject: [PATCH] Stamp an object the replay defers with the submission it records vk_memory.c defer stamped every deferred image, view and buffer with the last submitted timeline value. An object the replay lets go of while it records a submission can be named by that submission too: vk_texture.c slot_resolve hands a draw a released entry, and entry_of destroys released entries at that address later in the same submission. The completion thread then destroyed the object once the GPU reached the earlier value, before the submission naming it ran, and with the recorder thread behind, before the recorder made the call. The stamp is now the later of the last submitted value and vk_exec_recording_fence, as LAS Recomp and Savage Wind Recomp stamp their deferrals (runtime/nvn/vulkan/textures.c defer). TOTK_DEFER_STAMP=0 brings back the old stamp. Co-Authored-By: Claude Opus 5.5 --- runtime/vk_memory.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index cbcbc165..d8f57e23 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -20,6 +20,7 @@ #include "nvn_api.h" #include "nvn_pool_index.h" #include "vk.h" +#include "vk_exec.h" #include "platform/platform.h" // Timestamps for the tracking cost, in ns; qpc_ms converts. @@ -1937,8 +1938,19 @@ static void defer(int kind, uint64_t handle, VmaAllocation alloc) { plat_once(&cmd_once, cmd_init, NULL); plat_rmutex_lock(&cmd_lock); if (ndead == cap_dead) grow((void **)&dead, &cap_dead, sizeof *dead); - // The open batch may record into the object: it counts as the newest user. - dead[ndead++] = (Dead){kind, handle, alloc, open_active ? open_b.seq : next_seq, tl_noted}; + // The open batch may record into the object: it counts as the newest user. The GPU must also be past every + // submission that names it. tl_noted covers the submitted ones; an object the replay lets go of while it records + // a submission (vk_exec_recording_fence) may be named by that one too, not yet submitted: vk_texture.c + // slot_resolve hands a draw a released entry, and entry_of destroys released entries at that address later in + // the same submission. Stamped with the last submitted value, the object went as soon as the GPU reached it, + // before the submission that names it ran, and with the recorder thread (vk_rec.c) behind, before the recorder + // made the call that names it. LAS Recomp and Savage Wind Recomp stamp every deferral with the submission being + // recorded (runtime/nvn/vulkan/textures.c defer: vk_pending_seq). TOTK_DEFER_STAMP=0 brings back the old stamp. + static int stamp = -1; + if (stamp < 0) stamp = rt_knob("DEFER_STAMP", "1") != 0; + uint64_t tl = tl_noted, rf = stamp ? vk_exec_recording_fence() : 0; + if (rf > tl) tl = rf; + dead[ndead++] = (Dead){kind, handle, alloc, open_active ? open_b.seq : next_seq, tl}; plat_rmutex_unlock(&cmd_lock); }