render3d: recycle texture and buffer ids, free a released model whole, actor_release

A freed texture or buffer id goes on a spare list the next one takes; tex_note_size keeps sizes by id.
model_release frees prims, meshes, material names, the skin and leaves gltf_cached. actor_release
takes an actor off the stage and actor_new reuses its record (ECS's Things come and go all day).
steady.ludic: an actor round at 0 bytes over 2000.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 12:00:53 +03:00
parent 2fe4018d28
commit 9b482d609a
14 changed files with 208 additions and 39 deletions

View file

@ -43,6 +43,18 @@ program Steady {
return Vk.heap_bytes() - before
}
# bytes gained over n actors placed and released (actor_release): the records come round again
function actor_rounds(render3d_st: mut Render3dState, m: Model, n: int) -> long {
let before = Vk.heap_bytes()
for i in 0 .. n {
let a = actor_new(render3d_st, m)
actor_place(a, float(i % 7), 0.0, 0.0, 0.0)
actor_hide_part(a, "none", true)
actor_release(render3d_st, a)
}
return Vk.heap_bytes() - before
}
# bytes gained over n parses of a glTF document, each freed whole (Json.free_all): strings too
function parse_rounds(text: string, n: int) -> long {
let before = Vk.heap_bytes()
@ -71,10 +83,13 @@ program Steady {
let grew_f = frame_rounds(render3d_st, 600)
model_rounds(render3d_st, 20)
let grew_m = model_rounds(render3d_st, 200)
let am = gltf_load(render3d_st, "packages/ludic.lab/plate", "plate.gltf", "plate")
actor_rounds(render3d_st, am, 20)
let grew_a = actor_rounds(render3d_st, am, 2000)
let text = Fs.read_text("packages/ludic.lab/plate/plate.gltf")
parse_rounds(text, 20)
let grew_p = parse_rounds(text, 200)
print(`steady: the buffer path gained {grew_b} bytes over 5000 rounds, the frame {grew_f} over 600, a glTF parsed and freed {grew_p} over 200, a model loaded and let go {grew_m} over 200`)
print(`steady: the buffer path gained {grew_b} bytes over 5000 rounds, the frame {grew_f} over 600, a glTF parsed and freed {grew_p} over 200, a model loaded and let go {grew_m} over 200, an actor placed and released {grew_a} over 2000`)
# a few KB of slack for what the system's own libraries keep (Metal's caches, the allocator)
var ok = grew_b < 16384
if not ok { print("steady: FAILED - releasing and making a buffer again leaves memory behind") }
@ -92,6 +107,10 @@ program Steady {
ok = false
print("steady: FAILED - a model loaded and let go leaves memory behind")
}
if grew_a >= 4096 {
ok = false
print("steady: FAILED - an actor placed and released leaves memory behind")
}
if ok { print("STEADY OK") } else { print("STEADY FAILED") }
quit()
}