From 22f61a4eb5f6c8bb336667bf2241511474e1ce22 Mon Sep 17 00:00:00 2001 From: squidbus <1249084-squidbus@users.noreply.gitlab.freedesktop.org> Date: Thu, 21 May 2026 18:25:30 -0700 Subject: [PATCH] kk: Fix pre-compiled compute grid size Vulkan dispatch commands should multiply group count by local size, but pre-compiled dispatches should not. For example, the predicate indirect shader has a local size of 32 and a grid size equal to the max draw count, which was resulting in a dispatch total grid size of (max_draw_count * 32), overrunning the buffer. Reviewed-by: Aitor Camacho Part-of: --- src/kosmickrisp/bridge/mtl_encoder.m | 7 ++----- src/kosmickrisp/vulkan/kk_cmd_dispatch.c | 9 +++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/kosmickrisp/bridge/mtl_encoder.m b/src/kosmickrisp/bridge/mtl_encoder.m index 02a1430df30..1561e7d66c4 100644 --- a/src/kosmickrisp/bridge/mtl_encoder.m +++ b/src/kosmickrisp/bridge/mtl_encoder.m @@ -208,11 +208,8 @@ mtl_dispatch_threads(mtl_compute_encoder *encoder, { @autoreleasepool { id enc = (id)encoder; - MTLSize thread_count = MTLSizeMake(grid_size.x * local_size.x, - grid_size.y * local_size.y, - grid_size.z * local_size.z); - MTLSize threads_per_threadgroup = MTLSizeMake(local_size.x, - local_size.y, + MTLSize thread_count = MTLSizeMake(grid_size.x, grid_size.y, grid_size.z); + MTLSize threads_per_threadgroup = MTLSizeMake(local_size.x, local_size.y, local_size.z); // TODO_KOSMICKRISP can we rely on nonuniform threadgroup size support? diff --git a/src/kosmickrisp/vulkan/kk_cmd_dispatch.c b/src/kosmickrisp/vulkan/kk_cmd_dispatch.c index ef4cb988d84..871f1563e25 100644 --- a/src/kosmickrisp/vulkan/kk_cmd_dispatch.c +++ b/src/kosmickrisp/vulkan/kk_cmd_dispatch.c @@ -70,13 +70,14 @@ kk_CmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, kk_flush_compute_state(cmd); struct kk_shader *cs = cmd->state.shaders[MESA_SHADER_COMPUTE]; + struct mtl_size local_size = cs->info.cs.local_size; struct mtl_size grid_size = { - .x = groupCountX, - .y = groupCountY, - .z = groupCountZ, + .x = groupCountX * local_size.x, + .y = groupCountY * local_size.y, + .z = groupCountZ * local_size.z, }; mtl_compute_encoder *enc = kk_compute_encoder(cmd); - mtl_dispatch_threads(enc, grid_size, cs->info.cs.local_size); + mtl_dispatch_threads(enc, grid_size, local_size); } VKAPI_ATTR void VKAPI_CALL