mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 04:59:57 -04:00
Say in the log what keeps the half-full blocks of video memory from going back to the driver.
A play session at 5120x2160 held 3 to 5 GiB free inside 140 to 180 of the allocator's 64 MiB blocks, 48 to 85 of them at most half full, and the "mem: holes" line said only that 1 to 18 of those could be emptied by moving textures. A second line now counts the other half-full blocks by what stays in them: a VRAM mirror, a texture whose content only the GPU made, a texture a shader sampled lately, or a texture that cannot move for another reason, each with the blocks that kind alone keeps. Those figures say which change would give the memory back: mirrors placed apart from textures, or a wider rule for what a compaction may move. The line is written with the holes line, every 3,600 frames, from the table that line already builds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -858,11 +858,17 @@ typedef struct { uint64_t mem, block_size, bytes; uint32_t type; } VkBlockRow;
|
||||
// their sizes and the textures and rows in them; the textures that could move to another block or be dropped (marks 0:
|
||||
// the texture pool's marks do not tell which textures are sampled, and none counts as movable); the blocks at most half
|
||||
// full by what is listed, and those of them that hold nothing but such textures, which are what a compaction could
|
||||
// give back to the driver.
|
||||
// give back to the driver. kept: the other half-full blocks in which something listed stays, by what stays there
|
||||
// (VK_HOLES_KINDS kinds, in order: a VRAM mirror, a texture whose content only the GPU made, a texture sampled lately,
|
||||
// a texture that cannot move for another reason): kept_with counts the blocks with that kind in them, kept_only those
|
||||
// where nothing else stays.
|
||||
#define VK_HOLES_KINDS 4
|
||||
typedef struct {
|
||||
uint32_t type, marks, blocks, sparse, emptiable;
|
||||
uint64_t block_bytes, tex_bytes, other_bytes, move_bytes, drop_bytes;
|
||||
uint64_t sparse_bytes, sparse_listed, emptiable_bytes, emptiable_move, emptiable_drop;
|
||||
uint32_t kept, kept_with[VK_HOLES_KINDS], kept_only[VK_HOLES_KINDS];
|
||||
uint64_t kept_bytes, kept_only_bytes[VK_HOLES_KINDS];
|
||||
} VkTexHoles;
|
||||
void vk_texture_holes(const VkBlockRow *other, int nother, VkTexHoles *h);
|
||||
// Texture compaction (NX2NAVI_TEX_COMPACT; vk_texture.c "the pass"): idle textures move out of sparsely used blocks
|
||||
|
||||
@@ -4976,6 +4976,15 @@ static void holes_log(uint64_t frame) {
|
||||
"as unsampled", h.other_bytes / M, h.block_bytes > listed ? (h.block_bytes - listed) / M : 0.0, h.sparse,
|
||||
h.sparse_bytes / M, h.sparse_listed / M, h.emptiable, h.emptiable_bytes / M, h.emptiable_move / M,
|
||||
h.emptiable_drop / M);
|
||||
// What keeps the other half-full blocks: a session of 2026-11-14 at 5120x2160 held 3 to 5 GiB free inside 140 to
|
||||
// 180 blocks, 48 to 85 of them at most half full, and the line said only that 1 to 18 of those could be emptied.
|
||||
if (h.kept)
|
||||
rt_log("mem: holes frame %llu: %u more of the half-full blocks, %.0f MiB, keep something that cannot move: a VRAM "
|
||||
"mirror in %u (alone in %u, %.0f MiB), a texture only the GPU made in %u (alone in %u, %.0f MiB), a "
|
||||
"texture sampled lately in %u (alone in %u, %.0f MiB), another texture that cannot move in %u (alone in "
|
||||
"%u, %.0f MiB)", (unsigned long long)frame, h.kept, h.kept_bytes / M, h.kept_with[0], h.kept_only[0],
|
||||
h.kept_only_bytes[0] / M, h.kept_with[1], h.kept_only[1], h.kept_only_bytes[1] / M, h.kept_with[2],
|
||||
h.kept_only[2], h.kept_only_bytes[2] / M, h.kept_with[3], h.kept_only[3], h.kept_only_bytes[3] / M);
|
||||
}
|
||||
|
||||
// With NX2NAVI_TRACE=perf every 60 frames: a line when the device-local memory VMA did not allocate (vram_use_log's
|
||||
|
||||
@@ -6220,6 +6220,21 @@ static int compact_what(const Tex *e, uint64_t now, int marks, uint64_t most) {
|
||||
return now - e->samp_frame >= COMPACT_IDLE ? TCP_MOVE : TCP_STAY;
|
||||
}
|
||||
|
||||
// What keeps an allocation compact_what leaves where it is, for the holes line (vk_texture_holes): a VRAM mirror (a row
|
||||
// of the caller's, no entry), a texture whose content only the GPU made, one a shader sampled within COMPACT_IDLE
|
||||
// presents, or one that cannot move for another reason (compact_what's list). A sparse block that one kind alone
|
||||
// keeps is what a change to that kind's placement or rule would give back.
|
||||
enum { KEEP_MIRROR = 1, KEEP_GPU = 2, KEEP_USED = 4, KEEP_OTHER = 8 };
|
||||
static int stay_why(const Tex *e, int marks, uint64_t most) {
|
||||
if (!e) return KEEP_MIRROR;
|
||||
if (!e->pub.image || e->pub.gone || e->retiring) return KEEP_OTHER;
|
||||
if (!comes_back_intact(e)) return KEEP_GPU;
|
||||
if (!marks || !e->uploaded || e->up_retry || e->wr_fence || e->clobbered || e->pub.samples > 1 || e->f.depth ||
|
||||
e->f.stencil || e->bytes > most)
|
||||
return KEEP_OTHER;
|
||||
return KEEP_USED;
|
||||
}
|
||||
|
||||
static void table_add(CompTable *t, uint64_t mem, uint64_t size, uint64_t bytes, int what, Tex *e) {
|
||||
void *v = nvn_hm_get(&t->by_mem, &mem);
|
||||
uint32_t bi = v ? (uint32_t)((uintptr_t)v - 1) : (uint32_t)t->nb;
|
||||
@@ -6707,6 +6722,22 @@ void vk_texture_holes(const VkBlockRow *other, int nother, VkTexHoles *h) {
|
||||
.move_bytes = s.move_bytes, .drop_bytes = s.drop_bytes, .sparse_bytes = s.sparse_bytes,
|
||||
.sparse_listed = s.sparse_listed, .emptiable_bytes = s.emptiable_bytes,
|
||||
.emptiable_move = s.emptiable_move, .emptiable_drop = s.emptiable_drop};
|
||||
// the sparse blocks a plan could not choose, by what stays in them
|
||||
uint8_t *why = t.nb ? calloc((size_t)t.nb, 1) : NULL;
|
||||
for (int i = 0; why && i < t.na; i++)
|
||||
if (t.a[i].what == TCP_STAY && t.a[i].block < (uint32_t)t.nb)
|
||||
why[t.a[i].block] |= (uint8_t)stay_why(t.ae[i], t.marks, CP.frame_bytes);
|
||||
for (int i = 0; why && i < t.nb; i++) {
|
||||
const TcpBlock *k = &t.b[i];
|
||||
if (!tcp_sparse(k, COMPACT_SPARSE_PCT) || tcp_emptiable(k, COMPACT_SPARSE_PCT) || !why[i]) continue;
|
||||
h->kept++, h->kept_bytes += k->size;
|
||||
for (int j = 0; j < VK_HOLES_KINDS; j++) {
|
||||
if (!(why[i] >> j & 1)) continue;
|
||||
h->kept_with[j]++;
|
||||
if (why[i] == 1u << j) h->kept_only[j]++, h->kept_only_bytes[j] += k->size;
|
||||
}
|
||||
}
|
||||
free(why);
|
||||
table_free(&t);
|
||||
unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user