diff options
author | Erik Faye-Lund <[email protected]> | 2019-06-13 11:08:13 +0200 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-28 08:51:45 +0000 |
commit | 9cac63cae9c50d5623de0f0cf998c012c404f813 (patch) | |
tree | bdd8890ea29260b04a8a8b647a27ba07862f4401 /src/gallium/drivers/zink/zink_batch.c | |
parent | 56b1048bb064890fb0bc8fdb5e3bcbc6d51fbd2d (diff) |
zink: implement batching
This reduces stalling quite a bit.
Acked-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/gallium/drivers/zink/zink_batch.c')
-rw-r--r-- | src/gallium/drivers/zink/zink_batch.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c new file mode 100644 index 00000000000..7f73d26569a --- /dev/null +++ b/src/gallium/drivers/zink/zink_batch.c @@ -0,0 +1,99 @@ +#include "zink_batch.h" + +#include "zink_context.h" +#include "zink_fence.h" +#include "zink_framebuffer.h" +#include "zink_render_pass.h" +#include "zink_resource.h" +#include "zink_screen.h" + +#include "util/u_debug.h" +#include "util/set.h" + +static void +reset_batch(struct zink_screen *screen, struct zink_batch *batch) +{ + // cmdbuf hasn't been submitted before + if (!batch->fence) + return; + + zink_fence_finish(screen, batch->fence, PIPE_TIMEOUT_INFINITE); + zink_fence_reference(screen, &batch->fence, NULL); + + zink_render_pass_reference(screen, &batch->rp, NULL); + zink_framebuffer_reference(screen, &batch->fb, NULL); + + /* unref all used resources */ + set_foreach(batch->resources, entry) { + struct pipe_resource *pres = (struct pipe_resource *)entry->key; + pipe_resource_reference(&pres, NULL); + } + _mesa_set_clear(batch->resources, NULL); + + util_dynarray_foreach(&batch->zombie_samplers, VkSampler, samp) { + vkDestroySampler(screen->dev, *samp, NULL); + } + util_dynarray_clear(&batch->zombie_samplers); +} + +void +zink_start_cmdbuf(struct zink_context *ctx, struct zink_batch *batch) +{ + reset_batch(zink_screen(ctx->base.screen), batch); + + VkCommandBufferBeginInfo cbbi = {}; + cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + if (vkBeginCommandBuffer(batch->cmdbuf, &cbbi) != VK_SUCCESS) + debug_printf("vkBeginCommandBuffer failed\n"); +} + +static bool +submit_cmdbuf(struct zink_context *ctx, VkCommandBuffer cmdbuf, VkFence fence) +{ + VkPipelineStageFlags wait = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; + + VkSubmitInfo si = {}; + si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + si.waitSemaphoreCount = 0; + si.pWaitSemaphores = NULL; + si.signalSemaphoreCount = 0; + si.pSignalSemaphores = NULL; + si.pWaitDstStageMask = &wait; + si.commandBufferCount = 1; + si.pCommandBuffers = &cmdbuf; + + if (vkQueueSubmit(ctx->queue, 1, &si, fence) != VK_SUCCESS) { + debug_printf("vkQueueSubmit failed\n"); + return false; + } + + return true; +} + +void +zink_end_cmdbuf(struct zink_context *ctx, struct zink_batch *batch) +{ + if (vkEndCommandBuffer(batch->cmdbuf) != VK_SUCCESS) { + debug_printf("vkEndCommandBuffer failed\n"); + return; + } + + assert(batch->fence == NULL); + batch->fence = zink_create_fence(ctx->base.screen); + if (!batch->fence || + !submit_cmdbuf(ctx, batch->cmdbuf, batch->fence->fence)) + return; +} + +void +zink_batch_reference_resoure(struct zink_batch *batch, + struct zink_resource *res) +{ + struct set_entry *entry = _mesa_set_search(batch->resources, res); + if (!entry) { + struct pipe_resource *tmp = NULL; + entry = _mesa_set_add(batch->resources, res); + pipe_resource_reference(&tmp, &res->base); + } +} |