render3d: a command buffer holds at most 512 draws, and that many are drawn at start-up

Metal pools the command storage a command buffer grew to and grows it only when one encodes more than
any before (IOGPU under vkQueueSubmit < fn_gvk_once_end: +2-7 KB a window while a frame's draws
climbed, 192 KB in the trail scene). gvk_draw submits the frame's command buffer after
gvk_cb_cap_of draws (R3D_CB_DRAWS, 0 = none) and r3d_warm_commands draws that many through the
normal path once r3d is ready. steady: a frame drawing 20 to 200 actors grows 0 (was 2.7-7.5 KB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 13:59:00 +03:00
parent 404ee2ee3b
commit 22c104f766
4 changed files with 47 additions and 0 deletions

View file

@ -1248,6 +1248,10 @@ function gvk_set_view(render3d_st: mut Render3dState, cb: pointer) -> void {
# first / count select vertices or indices; count 0 means the mesh's own count. instances >= 1.
function gvk_draw(render3d_st: mut Render3dState, p: int, m: Mesh, st: GvkState, first: int, count: int, instances: int, tx: words, tx_w: int, tx_cap: int, rec: words, rec_o: int) -> void {
if render3d_st.gvk_prog_var == null or p <= 0 or p >= len(render3d_st.gvk_prog_var) or render3d_st.gvk_prog_var[p] == null { return }
let cap = gvk_cb_cap_of(render3d_st)
if cap > 0 and render3d_st.gvk_cb_draws >= cap { gvk_flush(render3d_st) }
if render3d_st.gvk_cb == null { render3d_st.gvk_cb_draws = 0 }
render3d_st.gvk_cb_draws += 1
let prof = gvk_prof(render3d_st)
var t0: long = 0
if prof { t0 = gl_now_us() }
@ -1974,3 +1978,15 @@ function gvk_pipeline_fast(render3d_st: mut Render3dState, p: int, m: Mesh, st:
if p < 4096 { render3d_st.gvk_pc_last[p] = len(render3d_st.gvk_pc_prog) - 1 }
return pipe
}
# Draws a command buffer holds before it is submitted and the frame goes on in the next. Metal pools
# the storage a command buffer grew to and grows it only when one encodes more than any before, so
# with a bound and that many drawn at start-up (r3d_warm_commands) play never grows it. 0: no bound.
const GVK_CB_DRAWS: int = 512
function gvk_cb_cap_of(render3d_st: mut Render3dState) -> int {
if render3d_st.gvk_cb_cap < 0 {
render3d_st.gvk_cb_cap = GVK_CB_DRAWS
if r3d_env_has(render3d_st, "R3D_CB_DRAWS") { render3d_st.gvk_cb_cap = Text.to_int(r3d_env(render3d_st, "R3D_CB_DRAWS")) }
}
return render3d_st.gvk_cb_cap
}