HACK: zink: suspend / resume queries on batch-boundaries
[mesa.git] / src / gallium / drivers / zink / zink_batch.c
index 0db58c6a8810242550e2fe99a1e7fe55e00dd0ce..74700acb3405921201e24c1f65938aa46cce9153 100644 (file)
@@ -3,6 +3,7 @@
 #include "zink_context.h"
 #include "zink_fence.h"
 #include "zink_framebuffer.h"
+#include "zink_query.h"
 #include "zink_render_pass.h"
 #include "zink_resource.h"
 #include "zink_screen.h"
@@ -13,6 +14,8 @@
 static void
 reset_batch(struct zink_screen *screen, struct zink_batch *batch)
 {
+   batch->descs_left = ZINK_BATCH_DESC_SIZE;
+
    // cmdbuf hasn't been submitted before
    if (!batch->fence)
       return;
@@ -30,10 +33,20 @@ reset_batch(struct zink_screen *screen, struct zink_batch *batch)
    }
    _mesa_set_clear(batch->resources, NULL);
 
+   /* unref all used sampler-views */
+   set_foreach(batch->sampler_views, entry) {
+      struct pipe_sampler_view *pres = (struct pipe_sampler_view *)entry->key;
+      pipe_sampler_view_reference(&pres, NULL);
+   }
+   _mesa_set_clear(batch->sampler_views, NULL);
+
    util_dynarray_foreach(&batch->zombie_samplers, VkSampler, samp) {
       vkDestroySampler(screen->dev, *samp, NULL);
    }
    util_dynarray_clear(&batch->zombie_samplers);
+
+   if (vkResetDescriptorPool(screen->dev, batch->descpool, 0) != VK_SUCCESS)
+      fprintf(stderr, "vkResetDescriptorPool failed\n");
 }
 
 void
@@ -46,34 +59,17 @@ zink_start_batch(struct zink_context *ctx, struct zink_batch *batch)
    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;
+   if (!ctx->queries_disabled)
+      zink_resume_queries(ctx, batch);
 }
 
 void
 zink_end_batch(struct zink_context *ctx, struct zink_batch *batch)
 {
+   if (!ctx->queries_disabled)
+      zink_suspend_queries(ctx, batch);
+
    if (vkEndCommandBuffer(batch->cmdbuf) != VK_SUCCESS) {
       debug_printf("vkEndCommandBuffer failed\n");
       return;
@@ -81,9 +77,23 @@ zink_end_batch(struct zink_context *ctx, struct zink_batch *batch)
 
    assert(batch->fence == NULL);
    batch->fence = zink_create_fence(ctx->base.screen);
-   if (!batch->fence ||
-       !submit_cmdbuf(ctx, batch->cmdbuf, batch->fence->fence))
+   if (!batch->fence)
       return;
+
+   VkSubmitInfo si = {};
+   si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+   si.waitSemaphoreCount = 0;
+   si.pWaitSemaphores = NULL;
+   si.signalSemaphoreCount = 0;
+   si.pSignalSemaphores = NULL;
+   si.pWaitDstStageMask = NULL;
+   si.commandBufferCount = 1;
+   si.pCommandBuffers = &batch->cmdbuf;
+
+   if (vkQueueSubmit(ctx->queue, 1, &si, batch->fence->fence) != VK_SUCCESS) {
+      debug_printf("vkQueueSubmit failed\n");
+      abort();
+   }
 }
 
 void
@@ -97,3 +107,15 @@ zink_batch_reference_resoure(struct zink_batch *batch,
       pipe_resource_reference(&tmp, &res->base);
    }
 }
+
+void
+zink_batch_reference_sampler_view(struct zink_batch *batch,
+                                  struct zink_sampler_view *sv)
+{
+   struct set_entry *entry = _mesa_set_search(batch->sampler_views, sv);
+   if (!entry) {
+      struct pipe_sampler_view *tmp = NULL;
+      entry = _mesa_set_add(batch->sampler_views, sv);
+      pipe_sampler_view_reference(&tmp, &sv->base);
+   }
+}