Free what the upscalers and SMAA hold once they are switched off.

DLSS's sizes (their images and features), the HUD-less picture for frame generation, FSR 1's two window-size
images and SMAA's three work images stayed for the rest of the run after their setting was turned off. They now go
after ten seconds without use (SMAA's after a minute, since its passes only run where the game's own SMAA does): the
DLSS sizes on the replaying thread with no wait for the GPU, FSR's once every present slot that read them has been
waited for, SMAA's through the deferred destruction. Switching a feature on again makes them again, as its first
frame in a run does. At 5120x2142 that is about 0.9 GiB with DLSS off, 168 MiB of FSR and 109 MiB of SMAA.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 23:17:23 -05:00
parent 2820781fb7
commit d77572c69c
4 changed files with 76 additions and 3 deletions

View File

@@ -75,10 +75,13 @@ static struct {
int none_told;
} A = {.frame_read = ~0ull, .composed = 1};
static void work_idle(uint64_t frame);
int vk_aa_mode(void) {
uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
if (f == A.frame_read) return A.mode;
A.frame_read = f;
work_idle(f);
const char *v = cfg_value("NX2NAVI_AA");
int want = VK_AA_GAME;
for (int i = 1; i < 4; i++)
@@ -134,8 +137,24 @@ static struct {
Img area, search;
Img luma, edges, weights; // at the scene's size (w, h)
uint32_t w, h;
uint64_t smaa_frame; // the last frame that recorded SMAA's passes
} P;
static void img_free(Img *m);
// SMAA's work images stayed for the rest of the run once aa left smaa: three pictures of the scene's size, 109 MiB at
// 5120x2142. They go WORK_IDLE presents after the last frame that used them, through the deferred destruction (no
// submission still names them then); smaa again makes them as a change of the scene's size does (work_images), in the
// command buffer of its first frame. A minute, not less: the passes run only where the game runs its own SMAA, so a
// long pause or loading screen with smaa set also counts as unused, and the images are made again after it.
#define WORK_IDLE 3600
static void work_idle(uint64_t frame) {
if (!P.luma.img || frame - P.smaa_frame < WORK_IDLE) return;
rt_log("aa: SMAA's work images unused for %d frames: freed (%ux%u)", WORK_IDLE, P.w, P.h);
img_free(&P.luma), img_free(&P.edges), img_free(&P.weights);
P.w = P.h = 0;
}
static int pipes_init(void) {
if (P.tried) return P.ok;
P.tried = 1;
@@ -319,6 +338,7 @@ int vk_aa_record(VkCommandBuffer cb, int mode, VkImageView src, VkImageView dst,
pass(cb, P_POST, v, s, &pc, sizeof pc, w, h);
return 1;
}
P.smaa_frame = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
const float metrics[4] = {1.0f / (float)w, 1.0f / (float)h, (float)w, (float)h};
const VkSampler lin[4] = {P.linear, P.linear, P.linear, P.linear};
pass(cb, P_LUMA, (const VkImageView[]){src, P.luma.view}, lin, metrics, sizeof metrics, w, h);