zink: setup compute batch and add handling

this is separate to the gfx batch array,
so we need separate struct members in zink_context for it

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8781>
This commit is contained in:
Mike Blumenkrantz 2020-08-12 16:55:36 -04:00 committed by Marge Bot
parent fa555772b9
commit e3633ed12b
2 changed files with 29 additions and 4 deletions

View file

@ -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;

View file

@ -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];