zink: set primitive restart cap
[mesa.git] / src / gallium / drivers / zink / zink_batch.c
index 45466af5699f2617d5200faf04c1c8c405f0f294..2403524abb509e17cf3e2682678477e947949a90 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"
 #include "util/set.h"
 
 static void
-reset_batch(struct zink_screen *screen, struct zink_batch *batch)
+reset_batch(struct zink_context *ctx, struct zink_batch *batch)
 {
+   struct zink_screen *screen = zink_screen(ctx->base.screen);
+   batch->descs_left = ZINK_BATCH_DESC_SIZE;
+
    // cmdbuf hasn't been submitted before
    if (!batch->fence)
       return;
@@ -41,24 +45,41 @@ reset_batch(struct zink_screen *screen, struct zink_batch *batch)
       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
 zink_start_batch(struct zink_context *ctx, struct zink_batch *batch)
 {
-   reset_batch(zink_screen(ctx->base.screen), batch);
+   reset_batch(ctx, 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");
+
+   if (!ctx->queries_disabled)
+      zink_resume_queries(ctx, batch);
 }
 
-static bool
-submit_cmdbuf(struct zink_context *ctx, VkCommandBuffer cmdbuf, VkFence fence)
+void
+zink_end_batch(struct zink_context *ctx, struct zink_batch *batch)
 {
-   VkPipelineStageFlags wait = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+   if (!ctx->queries_disabled)
+      zink_suspend_queries(ctx, 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, batch);
+   if (!batch->fence)
+      return;
 
    VkSubmitInfo si = {};
    si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -66,31 +87,14 @@ submit_cmdbuf(struct zink_context *ctx, VkCommandBuffer cmdbuf, VkFence fence)
    si.pWaitSemaphores = NULL;
    si.signalSemaphoreCount = 0;
    si.pSignalSemaphores = NULL;
-   si.pWaitDstStageMask = &wait;
+   si.pWaitDstStageMask = NULL;
    si.commandBufferCount = 1;
-   si.pCommandBuffers = &cmdbuf;
+   si.pCommandBuffers = &batch->cmdbuf;
 
-   if (vkQueueSubmit(ctx->queue, 1, &si, fence) != VK_SUCCESS) {
+   if (vkQueueSubmit(ctx->queue, 1, &si, batch->fence->fence) != VK_SUCCESS) {
       debug_printf("vkQueueSubmit failed\n");
-      return false;
+      abort();
    }
-
-   return true;
-}
-
-void
-zink_end_batch(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
@@ -99,9 +103,8 @@ zink_batch_reference_resoure(struct zink_batch *batch,
 {
    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);
+      pipe_reference(NULL, &res->base.reference);
    }
 }
 
@@ -111,8 +114,7 @@ zink_batch_reference_sampler_view(struct zink_batch *batch,
 {
    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);
+      pipe_reference(NULL, &sv->base.reference);
    }
 }