From 29bdfc9f75dd24cf6cefb21e057ced8b5bad973d Mon Sep 17 00:00:00 2001 From: MD5Visual <134655923+MD5Visual@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:43:55 +0300 Subject: [PATCH 1/2] fix(oot): indirect mesh first word and task/mesh c0 SSBO tables --- games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m index 6dd9ee970..59573af88 100644 --- a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m +++ b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m @@ -6188,6 +6188,10 @@ static int drv_fillable(int stage, int bank, unsigned off) { case 0: return (off >= 0x110 && off < 0x210) || off == 0x610; #endif case 1: return off >= 0x510 && off < 0x610; +#ifdef GAME_NS2 + case 3: return off >= 0x670 && off < 0x770; /* task storage-buffer table */ + case 4: return off >= 0x770 && off < 0x870; /* mesh storage-buffer table */ +#endif #ifdef GAME_NS2 case 5: return off < 0x10 || (off >= 0x200 && off < 0x410); /* NVN2: the workgroup counts at c0 + 4 */ #else @@ -15196,11 +15200,12 @@ static void mesh_tasks_draw(const p_mesh_tasks *mesh) { rp_end(); cg_flush(); defer_fallback(); rp_flush(); upd_flush(); g_mesh_pre_n = 0; for (int r = 0; r < nrun; r++) { void *source; uint64_t so; - if (!mtl_addr(run[r]->ind, 8, &source, &so)) { if (!r) { RED_ONCE(163, "DrawMeshTasksIndirect record at %#llx is in no memory pool: draw skipped", (unsigned long long)run[r]->ind); return; } continue; } + if (!mtl_addr(run[r]->ind, 16, &source, &so)) { if (!r) { RED_ONCE(163, "DrawMeshTasksIndirect record at %#llx is in no memory pool: draw skipped", (unsigned long long)run[r]->ind); return; } continue; } __strong id ab; size_t ao = arena_alloc(32, &ab); uint32_t *w = (uint32_t *)((uint8_t *)ab.contents + ao); memset(w, 0, 32); w[1] = w[2] = 1; id src = (__bridge id)source; id ce = blit_buffer(src, so, ab, ao, 4); - enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + 4, ab, ao + 16, 4); + static int first_old = -1; if (first_old < 0) { const char *e = getenv("TOTK_MESH_FIRST_OLD"); first_old = e && *e && strcmp(e, "0"); } + enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + (first_old ? 4 : 12), ab, ao + 16, 4); if (!r) { g_mesh_ind_args = ab.gpuAddress + ao; g_mesh_ind_first = ab.gpuAddress + ao + 16; } else { g_mesh_pre[g_mesh_pre_n].op = run[r]; g_mesh_pre[g_mesh_pre_n].sub = g_sub_serial; g_mesh_pre[g_mesh_pre_n].args = ab.gpuAddress + ao; g_mesh_pre[g_mesh_pre_n].first = ab.gpuAddress + ao + 16; g_mesh_pre_n++; } } enc_b_end(g_blit); g_blit = nil; } } From a5f74ca4fd2011353658243dad81916674a29810 Mon Sep 17 00:00:00 2001 From: MD5Visual <134655923+MD5Visual@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:10:15 +0300 Subject: [PATCH 2/2] fix(oot): keep word 1 as the indirect mesh first index The 16-byte record map is still required, but OoT's meshes read the useful first index from word 1: word 3 removed the grass and made distant vertices tear. Default to word 1 and make NVN2's {count,0,0,first} layout opt-in with TOTK_MESH_FIRST_NEW=1. --- games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m index 59573af88..c66c27572 100644 --- a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m +++ b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m @@ -15204,8 +15204,11 @@ static void mesh_tasks_draw(const p_mesh_tasks *mesh) { __strong id ab; size_t ao = arena_alloc(32, &ab); uint32_t *w = (uint32_t *)((uint8_t *)ab.contents + ao); memset(w, 0, 32); w[1] = w[2] = 1; id src = (__bridge id)source; id ce = blit_buffer(src, so, ab, ao, 4); - static int first_old = -1; if (first_old < 0) { const char *e = getenv("TOTK_MESH_FIRST_OLD"); first_old = e && *e && strcmp(e, "0"); } - enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + (first_old ? 4 : 12), ab, ao + 16, 4); + /* NVN2's record is {count, 0, 0, first}; OoT's terrain/grass meshes read the useful word from 1. Keep + word 1 by default (word 3 removed the grass and made vertices tear), and allow the NVN2 layout with + TOTK_MESH_FIRST_NEW=1. The 16-byte map is needed either way for the c0 mesh tables. */ + static int first_new = -1; if (first_new < 0) { const char *e = getenv("TOTK_MESH_FIRST_NEW"); first_new = e && *e && strcmp(e, "0"); } + enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + (first_new ? 12 : 4), ab, ao + 16, 4); if (!r) { g_mesh_ind_args = ab.gpuAddress + ao; g_mesh_ind_first = ab.gpuAddress + ao + 16; } else { g_mesh_pre[g_mesh_pre_n].op = run[r]; g_mesh_pre[g_mesh_pre_n].sub = g_sub_serial; g_mesh_pre[g_mesh_pre_n].args = ab.gpuAddress + ao; g_mesh_pre[g_mesh_pre_n].first = ab.gpuAddress + ao + 16; g_mesh_pre_n++; } } enc_b_end(g_blit); g_blit = nil; } }