diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 047927d5582..236b9fce2e0 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -75,6 +75,14 @@ zink_context_destroy(struct pipe_context *pctx) _mesa_set_destroy(ctx->batches[i].sampler_views, NULL); _mesa_set_destroy(ctx->batches[i].programs, NULL); } + zink_batch_release(screen, &ctx->compute_batch); + util_dynarray_fini(&ctx->compute_batch.zombie_samplers); + vkDestroyDescriptorPool(screen->dev, ctx->compute_batch.descpool, NULL); + vkFreeCommandBuffers(screen->dev, ctx->cmdpool, 1, &ctx->compute_batch.cmdbuf); + + _mesa_set_destroy(ctx->compute_batch.resources, NULL); + _mesa_set_destroy(ctx->compute_batch.sampler_views, NULL); + _mesa_set_destroy(ctx->compute_batch.programs, NULL); vkDestroyCommandPool(screen->dev, ctx->cmdpool, NULL); util_primconvert_destroy(ctx->primconvert); @@ -1274,10 +1282,14 @@ void zink_wait_on_batch(struct zink_context *ctx, int batch_id) { if (batch_id >= 0) { - struct zink_batch *batch = &ctx->batches[batch_id]; + struct zink_batch *batch = batch_id == ZINK_COMPUTE_BATCH_ID ? &ctx->compute_batch : &ctx->batches[batch_id]; if (batch != zink_curr_batch(ctx)) { - ctx->base.screen->fence_finish(ctx->base.screen, NULL, (struct pipe_fence_handle*)batch->fence, - PIPE_TIMEOUT_INFINITE); + if (!batch->fence) { // this is the compute batch + zink_end_batch(ctx, batch); + zink_start_batch(ctx, batch); + } else + ctx->base.screen->fence_finish(ctx->base.screen, NULL, (struct pipe_fence_handle*)batch->fence, + PIPE_TIMEOUT_INFINITE); return; } } @@ -1565,7 +1577,7 @@ init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx) struct zink_screen *screen = zink_screen(ctx->base.screen); VkCommandBufferAllocateInfo cbai = {}; cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - cbai.commandPool = ctx->cmdpool; + cbai.commandPool = idx == ZINK_COMPUTE_BATCH_ID ? ctx->compute_cmdpool : ctx->cmdpool; cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; cbai.commandBufferCount = 1; @@ -1697,12 +1709,20 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) cpci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; if (vkCreateCommandPool(screen->dev, &cpci, NULL, &ctx->cmdpool) != VK_SUCCESS) goto fail; + if (vkCreateCommandPool(screen->dev, &cpci, NULL, &ctx->compute_cmdpool) != VK_SUCCESS) + goto fail; for (int i = 0; i < ARRAY_SIZE(ctx->batches); ++i) { if (!init_batch(ctx, &ctx->batches[i], i)) goto fail; } + if (vkCreateCommandPool(screen->dev, &cpci, NULL, &ctx->compute_cmdpool) != VK_SUCCESS) + goto fail; + if (!init_batch(ctx, &ctx->compute_batch, ZINK_COMPUTE_BATCH_ID)) + goto fail; + zink_start_batch(ctx, &ctx->compute_batch); + vkGetDeviceQueue(screen->dev, screen->gfx_queue, 0, &ctx->queue); ctx->program_cache = _mesa_hash_table_create(NULL, @@ -1731,6 +1751,8 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) fail: if (ctx) { vkDestroyCommandPool(screen->dev, ctx->cmdpool, NULL); + if (ctx->compute_cmdpool) + vkDestroyCommandPool(screen->dev, ctx->compute_cmdpool, NULL); FREE(ctx); } return NULL; diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index ffb55454f7c..644aa01da4c 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -109,6 +109,9 @@ struct zink_context { VkQueue queue; + VkCommandPool compute_cmdpool; + struct zink_batch compute_batch; + struct pipe_constant_buffer ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; struct pipe_shader_buffer ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS]; uint32_t writable_ssbos[PIPE_SHADER_TYPES];