From 888f4ca17a37e9d8e8a5b7328a1341ddd6a9fcbc Mon Sep 17 00:00:00 2001 From: Tobim6 <102646588+Tobim6@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:22:21 +0100 Subject: [PATCH] Mesh emulation: the arena counts mesh workgroups started, past the task-record check and at the output copy. Draws with a task stage drew nothing on an RX 580 although their task records ask for mesh groups (mesh.txt), and the same converted stages produce vertices on lavapipe. Header words 4-7 now count, per submission, the emulated mesh workgroups that started, those whose task record covers them, those that reached the output copy and the primitives those declared; mesh.txt prints them after each draw. Co-Authored-By: Claude Opus 5.5 --- runtime/mesh_emu_spirv.c | 11 +++++++++++ runtime/vk_exec_draw.c | 1 + 2 files changed, 12 insertions(+) diff --git a/runtime/mesh_emu_spirv.c b/runtime/mesh_emu_spirv.c index e4cd78d9..3cc8bed9 100644 --- a/runtime/mesh_emu_spirv.c +++ b/runtime/mesh_emu_spirv.c @@ -245,6 +245,12 @@ static void mesh_epilogue(Em *e, const MeshEmuInfo *info, const OutVar *ov, int barrier(e); uint32_t lid = ld(e, m->t_u32, m->lii), base = words_base(e); uint32_t isz = mul(e, pcount, cu(e, K)), vsz = mul(e, vcount, cu(e, S)); + // header word 6: mesh workgroups that reached the output copy; word 7: the primitives they declared (diagnosis) + { + uint32_t l0 = E2(e, OpIEqual, m->t_bool, lid, cu(e, 0)); + atomic(e, OpAtomicIAdd, base, cu(e, 6), E3(e, OpSelect, m->t_u32, l0, cu(e, 1), cu(e, 0))); + atomic(e, OpAtomicIAdd, base, cu(e, 7), E3(e, OpSelect, m->t_u32, l0, pcount, cu(e, 0))); + } uint32_t mz; if_begin(e, E2(e, OpIEqual, m->t_bool, lid, cu(e, 0)), &mz); { @@ -630,6 +636,11 @@ uint32_t *mesh_emu_compute(const uint32_t *w, size_t n, MeshEmuInfo *info, size_ uint32_t recw = add(&e, cu(&e, MESH_EMU_TOFF / 4), mul(&e, slotc, cu(&e, MESH_EMU_TWORDS))); uint32_t cnt = word_load(&e, base, recw); uint32_t act = E2(&e, OpLogicalAnd, m->t_bool, ok, ult(&e, x, cnt)); + // header words 4 and 5: mesh workgroups started and past this check (diagnosis: vk_dump mesh.txt) + uint32_t l0 = E2(&e, OpIEqual, m->t_bool, lid, cu(&e, 0)); + atomic(&e, OpAtomicIAdd, base, cu(&e, 4), E3(&e, OpSelect, m->t_u32, l0, cu(&e, 1), cu(&e, 0))); + atomic(&e, OpAtomicIAdd, base, cu(&e, 5), + E3(&e, OpSelect, m->t_u32, E2(&e, OpLogicalAnd, m->t_bool, l0, act), cu(&e, 1), cu(&e, 0))); uint32_t cont = nid(m), retl = nid(m); op(&code, OpSelectionMerge, 2, cont, 0u); op(&code, OpBranchConditional, 3, act, cont, retl); diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index c26b27cc..de18ac57 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -5905,6 +5905,7 @@ static void me_barrier(VkCommandBuffer cb, VkPipelineStageFlags2 ss, VkAccessFla ME.resets++; me_barrier(cb, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT); + vkCmdFillBuffer(cb, ME.buf, 0, 32, 0); // the counters, and the diagnosis words 4-7 (mesh_emu_spirv.c) me_barrier(cb, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT | VK_ACCESS_2_TRANSFER_WRITE_BIT); uint32_t rec = ME.rec++ % MESH_EMU_DRECS;