summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2021-03-19 11:06:56 -0400
committerMarge Bot <eric+marge@anholt.net>2021-03-19 20:16:02 +0000
commita06958278f98e69611e7c58d2a89baa842150c42 (patch)
tree3f6756606a333148debe948d79c26ce649c2436c
parent62335d7bc510721dad2b61404ee6101203bacc7a (diff)
zink: split off a bunch of batch struct members to new batch state struct
this is just a cosmetic patch intended for review, skip this in bisects Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9547>
-rw-r--r--src/gallium/drivers/zink/zink_batch.c220
-rw-r--r--src/gallium/drivers/zink/zink_batch.h26
-rw-r--r--src/gallium/drivers/zink/zink_blit.c4
-rw-r--r--src/gallium/drivers/zink/zink_clear.c6
-rw-r--r--src/gallium/drivers/zink/zink_context.c48
-rw-r--r--src/gallium/drivers/zink/zink_descriptors.c2
-rw-r--r--src/gallium/drivers/zink/zink_draw.c70
-rw-r--r--src/gallium/drivers/zink/zink_fence.c19
-rw-r--r--src/gallium/drivers/zink/zink_fence.h5
-rw-r--r--src/gallium/drivers/zink/zink_query.c50
10 files changed, 248 insertions, 202 deletions
diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c
index 9cec01c4df3..38c64d93673 100644
--- a/src/gallium/drivers/zink/zink_batch.c
+++ b/src/gallium/drivers/zink/zink_batch.c
@@ -17,66 +17,63 @@
#include "wsi_common.h"
void
-zink_batch_clear_resources(struct zink_screen *screen, struct zink_batch *batch)
+zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs)
{
/* unref all used resources */
- set_foreach(batch->resources, entry) {
+ set_foreach(bs->resources, entry) {
struct zink_resource_object *obj = (struct zink_resource_object *)entry->key;
zink_resource_object_reference(screen, &obj, NULL);
- _mesa_set_remove(batch->resources, entry);
+ _mesa_set_remove(bs->resources, entry);
}
}
void
-zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
+zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
{
struct zink_screen *screen = zink_screen(ctx->base.screen);
- batch->descs_used = 0;
-
- // cmdbuf hasn't been submitted before
- if (batch->submitted)
- zink_fence_finish(screen, &ctx->base, batch->fence, PIPE_TIMEOUT_INFINITE);
+ if (bs->fence->submitted)
+ zink_fence_finish(screen, &ctx->base, bs->fence, PIPE_TIMEOUT_INFINITE);
- zink_batch_clear_resources(screen, batch);
+ zink_batch_state_clear_resources(screen, bs);
- set_foreach(batch->active_queries, entry) {
+ set_foreach(bs->active_queries, entry) {
struct zink_query *query = (void*)entry->key;
zink_prune_query(screen, query);
- _mesa_set_remove(batch->active_queries, entry);
+ _mesa_set_remove(bs->active_queries, entry);
}
- set_foreach(batch->surfaces, entry) {
+ set_foreach(bs->surfaces, entry) {
struct zink_surface *surf = (struct zink_surface *)entry->key;
- surf->batch_uses &= ~BITFIELD64_BIT(batch->batch_id);
+ surf->batch_uses &= ~BITFIELD64_BIT(bs->batch_id);
pipe_surface_reference((struct pipe_surface**)&surf, NULL);
- _mesa_set_remove(batch->surfaces, entry);
+ _mesa_set_remove(bs->surfaces, entry);
}
- set_foreach(batch->bufferviews, entry) {
+ set_foreach(bs->bufferviews, entry) {
struct zink_buffer_view *buffer_view = (struct zink_buffer_view *)entry->key;
- buffer_view->batch_uses &= ~BITFIELD64_BIT(batch->batch_id);
+ buffer_view->batch_uses &= ~BITFIELD64_BIT(bs->batch_id);
zink_buffer_view_reference(screen, &buffer_view, NULL);
- _mesa_set_remove(batch->bufferviews, entry);
+ _mesa_set_remove(bs->bufferviews, entry);
}
- util_dynarray_foreach(&batch->zombie_samplers, VkSampler, samp) {
+ util_dynarray_foreach(&bs->zombie_samplers, VkSampler, samp) {
vkDestroySampler(screen->dev, *samp, NULL);
}
- util_dynarray_clear(&batch->zombie_samplers);
- util_dynarray_clear(&batch->persistent_resources);
+ util_dynarray_clear(&bs->zombie_samplers);
+ util_dynarray_clear(&bs->persistent_resources);
- set_foreach(batch->desc_sets, entry) {
+ set_foreach(bs->desc_sets, entry) {
struct zink_descriptor_set *zds = (void*)entry->key;
- zds->batch_uses &= ~BITFIELD_BIT(batch->batch_id);
- /* reset descriptor pools when no batch is using this program to avoid
+ zds->batch_uses &= ~BITFIELD_BIT(bs->batch_id);
+ /* reset descriptor pools when no bs is using this program to avoid
* having some inactive program hogging a billion descriptors
*/
pipe_reference(&zds->reference, NULL);
zink_descriptor_set_recycle(zds);
- _mesa_set_remove(batch->desc_sets, entry);
+ _mesa_set_remove(bs->desc_sets, entry);
}
- set_foreach(batch->programs, entry) {
- if (batch->batch_id == ZINK_COMPUTE_BATCH_ID) {
+ set_foreach(bs->programs, entry) {
+ if (bs->is_compute) {
struct zink_compute_program *comp = (struct zink_compute_program*)entry->key;
bool in_use = comp == ctx->curr_compute;
if (zink_compute_program_reference(screen, &comp, NULL) && in_use)
@@ -87,87 +84,125 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
if (zink_gfx_program_reference(screen, &prog, NULL) && in_use)
ctx->curr_program = NULL;
}
- _mesa_set_remove(batch->programs, entry);
+ _mesa_set_remove(bs->programs, entry);
}
- set_foreach(batch->fbs, entry) {
+ set_foreach(bs->fbs, entry) {
struct zink_framebuffer *fb = (void*)entry->key;
zink_framebuffer_reference(screen, &fb, NULL);
- _mesa_set_remove(batch->fbs, entry);
+ _mesa_set_remove(bs->fbs, entry);
}
- if (vkResetCommandPool(screen->dev, batch->cmdpool, 0) != VK_SUCCESS)
- debug_printf("vkResetCommandPool failed\n");
- batch->submitted = batch->has_work = false;
- batch->resource_size = 0;
+ bs->flush_res = NULL;
+
+ bs->descs_used = 0;
+ bs->fence->submitted = false;
+ bs->resource_size = 0;
}
void
-zink_batch_destroy(struct zink_context* ctx, struct zink_batch *batch)
+zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs)
{
- struct zink_screen *screen = zink_screen(ctx->base.screen);
+ if (!bs)
+ return;
- vkFreeCommandBuffers(screen->dev, batch->cmdpool, 1, &batch->cmdbuf);
- vkDestroyCommandPool(screen->dev, batch->cmdpool, NULL);
- zink_fence_reference(screen, &batch->fence, NULL);
- _mesa_set_destroy(batch->fbs, NULL);
- _mesa_set_destroy(batch->resources, NULL);
- util_dynarray_fini(&batch->zombie_samplers);
- _mesa_set_destroy(batch->surfaces, NULL);
- _mesa_set_destroy(batch->programs, NULL);
- _mesa_set_destroy(batch->active_queries, NULL);
+ if (bs->cmdbuf)
+ vkFreeCommandBuffers(screen->dev, bs->cmdpool, 1, &bs->cmdbuf);
+ if (bs->cmdpool)
+ vkDestroyCommandPool(screen->dev, bs->cmdpool, NULL);
+
+ _mesa_set_destroy(bs->fbs, NULL);
+ _mesa_set_destroy(bs->resources, NULL);
+ util_dynarray_fini(&bs->zombie_samplers);
+ _mesa_set_destroy(bs->surfaces, NULL);
+ _mesa_set_destroy(bs->bufferviews, NULL);
+ _mesa_set_destroy(bs->programs, NULL);
+ _mesa_set_destroy(bs->desc_sets, NULL);
+ _mesa_set_destroy(bs->active_queries, NULL);
+ ralloc_free(bs);
}
-static void
-init_batch(struct zink_context *ctx, struct zink_batch *batch)
+static struct zink_batch_state *
+create_batch_state(struct zink_context *ctx, unsigned idx)
{
struct zink_screen *screen = zink_screen(ctx->base.screen);
+ struct zink_batch_state *bs = rzalloc(NULL, struct zink_batch_state);
VkCommandPoolCreateInfo cpci = {};
cpci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
cpci.queueFamilyIndex = screen->gfx_queue;
cpci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
- if (vkCreateCommandPool(screen->dev, &cpci, NULL, &batch->cmdpool) != VK_SUCCESS)
- return;
+ if (vkCreateCommandPool(screen->dev, &cpci, NULL, &bs->cmdpool) != VK_SUCCESS)
+ goto fail;
VkCommandBufferAllocateInfo cbai = {};
cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
- cbai.commandPool = batch->cmdpool;
+ cbai.commandPool = bs->cmdpool;
cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cbai.commandBufferCount = 1;
- if (vkAllocateCommandBuffers(screen->dev, &cbai, &batch->cmdbuf) != VK_SUCCESS)
- return;
+ if (vkAllocateCommandBuffers(screen->dev, &cbai, &bs->cmdbuf) != VK_SUCCESS)
+ goto fail;
+
+#define SET_CREATE_OR_FAIL(ptr) \
+ ptr = _mesa_pointer_set_create(bs); \
+ if (!ptr) \
+ goto fail
+
+ SET_CREATE_OR_FAIL(bs->fbs);
+ SET_CREATE_OR_FAIL(bs->resources);
+ SET_CREATE_OR_FAIL(bs->surfaces);
+ SET_CREATE_OR_FAIL(bs->bufferviews);
+ SET_CREATE_OR_FAIL(bs->programs);
+ SET_CREATE_OR_FAIL(bs->desc_sets);
+ SET_CREATE_OR_FAIL(bs->active_queries);
+ util_dynarray_init(&bs->zombie_samplers, NULL);
+ util_dynarray_init(&bs->persistent_resources, NULL);
+ bs->batch_id = idx;
+
+ if (!zink_create_fence(screen, bs))
+ /* this destroys the batch state on failure */
+ return NULL;
+
+ bs->is_compute = idx == ZINK_COMPUTE_BATCH_ID;
+
+ return bs;
+fail:
+ zink_batch_state_destroy(screen, bs);
+ return NULL;
+}
+
+static void
+init_batch_state(struct zink_context *ctx, struct zink_batch *batch)
+{
+ struct zink_batch_state *bs = create_batch_state(ctx, batch->batch_id);
+ batch->state = bs;
+}
+
+void
+zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch)
+{
+ struct zink_screen *screen = zink_screen(ctx->base.screen);
+ bool fresh = !batch->state;
-#define SET_CREATE_OR_FAIL(ptr) do { \
- ptr = _mesa_pointer_set_create(NULL); \
- if (!ptr) \
- return; \
- } while (0)
-
- SET_CREATE_OR_FAIL(batch->fbs);
- SET_CREATE_OR_FAIL(batch->resources);
- SET_CREATE_OR_FAIL(batch->surfaces);
- SET_CREATE_OR_FAIL(batch->bufferviews);
- SET_CREATE_OR_FAIL(batch->programs);
- SET_CREATE_OR_FAIL(batch->desc_sets);
- SET_CREATE_OR_FAIL(batch->active_queries);
- util_dynarray_init(&batch->zombie_samplers, NULL);
- util_dynarray_init(&batch->persistent_resources, NULL);
-
- batch->fence = zink_create_fence(ctx->base.screen, batch);
+ init_batch_state(ctx, batch);
+ assert(batch->state);
+
+ if (!fresh) {
+ if (vkResetCommandPool(screen->dev, batch->state->cmdpool, 0) != VK_SUCCESS)
+ debug_printf("vkResetCommandPool failed\n");
+ }
+ batch->has_work = false;
}
void
zink_start_batch(struct zink_context *ctx, struct zink_batch *batch)
{
- if (!batch->fence)
- init_batch(ctx, batch);
zink_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)
+ if (vkBeginCommandBuffer(batch->state->cmdbuf, &cbbi) != VK_SUCCESS)
debug_printf("vkBeginCommandBuffer failed\n");
if (!ctx->queries_disabled)
@@ -180,14 +215,14 @@ 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) {
+ if (vkEndCommandBuffer(batch->state->cmdbuf) != VK_SUCCESS) {
debug_printf("vkEndCommandBuffer failed\n");
return;
}
zink_fence_init(ctx, batch);
- util_dynarray_foreach(&batch->persistent_resources, struct zink_resource*, res) {
+ util_dynarray_foreach(&batch->state->persistent_resources, struct zink_resource*, res) {
struct zink_screen *screen = zink_screen(ctx->base.screen);
assert(!(*res)->obj->offset);
VkMappedMemoryRange range = {
@@ -208,19 +243,19 @@ zink_end_batch(struct zink_context *ctx, struct zink_batch *batch)
si.pSignalSemaphores = NULL;
si.pWaitDstStageMask = NULL;
si.commandBufferCount = 1;
- si.pCommandBuffers = &batch->cmdbuf;
+ si.pCommandBuffers = &batch->state->cmdbuf;
struct wsi_memory_signal_submit_info mem_signal = {
.sType = VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA,
.pNext = si.pNext,
};
- if (batch->flush_res) {
- mem_signal.memory = batch->flush_res->obj->mem;
+ if (batch->state->flush_res) {
+ mem_signal.memory = batch->state->flush_res->obj->mem;
si.pNext = &mem_signal;
}
- if (vkQueueSubmit(ctx->queue, 1, &si, batch->fence->fence) != VK_SUCCESS) {
+ if (vkQueueSubmit(ctx->queue, 1, &si, batch->state->fence->fence) != VK_SUCCESS) {
debug_printf("ZINK: vkQueueSubmit() failed\n");
ctx->is_device_lost = true;
@@ -228,8 +263,7 @@ zink_end_batch(struct zink_context *ctx, struct zink_batch *batch)
ctx->reset.reset(ctx->reset.data, PIPE_GUILTY_CONTEXT_RESET);
}
}
- batch->submitted = true;
- batch->flush_res = NULL;
+ batch->state->fence->submitted = true;
}
/* returns a queue based on whether a resource
@@ -259,21 +293,21 @@ zink_batch_reference_resource_rw(struct zink_batch *batch, struct zink_resource
}
/* if the resource already has usage of any sort set for this batch, we can skip hashing */
- if (!zink_resource_has_usage_for_id(res, batch->batch_id)) {
+ if (!zink_resource_has_usage_for_id(res, batch->state->batch_id)) {
bool found = false;
- _mesa_set_search_and_add(batch->resources, res->obj, &found);
+ _mesa_set_search_and_add(batch->state->resources, res->obj, &found);
if (!found) {
pipe_reference(NULL, &res->obj->reference);
- batch->resource_size += res->obj->size;
+ batch->state->resource_size += res->obj->size;
if (stencil) {
pipe_reference(NULL, &stencil->obj->reference);
- batch->resource_size += stencil->obj->size;
+ batch->state->resource_size += stencil->obj->size;
}
}
}
/* multiple array entries are fine */
if (res->obj->persistent_maps)
- util_dynarray_append(&batch->persistent_resources, struct zink_resource*, res);
+ util_dynarray_append(&batch->state->persistent_resources, struct zink_resource*, res);
/* the batch_uses value for this batch is guaranteed to not be in use now because
* zink_reset_batch() waits on the fence and removes access before resetting
*/
@@ -290,7 +324,7 @@ static bool
ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr, uint32_t *u)
{
bool found = false;
- uint32_t bit = BITFIELD_BIT(batch->batch_id);
+ uint32_t bit = BITFIELD_BIT(batch->state->batch_id);
if ((*u) & bit)
return false;
_mesa_set_search_and_add(s, ptr, &found);
@@ -304,11 +338,11 @@ zink_batch_reference_sampler_view(struct zink_batch *batch,
struct zink_sampler_view *sv)
{
if (sv->base.target == PIPE_BUFFER) {
- if (!ptr_add_usage(batch, batch->bufferviews, sv->buffer_view, &sv->buffer_view->batch_uses))
+ if (!ptr_add_usage(batch, batch->state->bufferviews, sv->buffer_view, &sv->buffer_view->batch_uses))
return;
pipe_reference(NULL, &sv->buffer_view->reference);
} else {
- if (!ptr_add_usage(batch, batch->surfaces, sv->image_view, &sv->image_view->batch_uses))
+ if (!ptr_add_usage(batch, batch->state->surfaces, sv->image_view, &sv->image_view->batch_uses))
return;
pipe_reference(NULL, &sv->image_view->base.reference);
}
@@ -320,7 +354,7 @@ zink_batch_reference_framebuffer(struct zink_batch *batch,
struct zink_framebuffer *fb)
{
bool found;
- _mesa_set_search_or_add(batch->fbs, fb, &found);
+ _mesa_set_search_or_add(batch->state->fbs, fb, &found);
if (!found)
pipe_reference(NULL, &fb->reference);
}
@@ -330,7 +364,7 @@ zink_batch_reference_program(struct zink_batch *batch,
struct zink_program *pg)
{
bool found = false;
- _mesa_set_search_and_add(batch->programs, pg, &found);
+ _mesa_set_search_and_add(batch->state->programs, pg, &found);
if (!found)
pipe_reference(NULL, &pg->reference);
batch->has_work = true;
@@ -339,7 +373,7 @@ zink_batch_reference_program(struct zink_batch *batch,
bool
zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds)
{
- if (!ptr_add_usage(batch, batch->desc_sets, zds, &zds->batch_uses))
+ if (!ptr_add_usage(batch, batch->state->desc_sets, zds, &zds->batch_uses))
return false;
pipe_reference(NULL, &zds->reference);
return true;
@@ -350,11 +384,11 @@ zink_batch_reference_image_view(struct zink_batch *batch,
struct zink_image_view *image_view)
{
if (image_view->base.resource->target == PIPE_BUFFER) {
- if (!ptr_add_usage(batch, batch->bufferviews, image_view->buffer_view, &image_view->buffer_view->batch_uses))
+ if (!ptr_add_usage(batch, batch->state->bufferviews, image_view->buffer_view, &image_view->buffer_view->batch_uses))
return;
pipe_reference(NULL, &image_view->buffer_view->reference);
} else {
- if (!ptr_add_usage(batch, batch->surfaces, image_view->surface, &image_view->surface->batch_uses))
+ if (!ptr_add_usage(batch, batch->state->surfaces, image_view->surface, &image_view->surface->batch_uses))
return;
pipe_reference(NULL, &image_view->surface->base.reference);
}
diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h
index 8b07311ee31..b99fe06348c 100644
--- a/src/gallium/drivers/zink/zink_batch.h
+++ b/src/gallium/drivers/zink/zink_batch.h
@@ -49,7 +49,7 @@ enum zink_queue {
ZINK_QUEUE_ANY,
};
-struct zink_batch {
+struct zink_batch_state {
unsigned batch_id : 3;
VkCommandPool cmdpool;
VkCommandBuffer cmdbuf;
@@ -74,11 +74,28 @@ struct zink_batch {
VkDeviceSize resource_size;
+ bool is_compute;
+};
+
+struct zink_batch {
+ unsigned batch_id : 3;
+ struct zink_batch_state *state;
+ enum zink_queue queue;
+
bool has_work;
- bool submitted;
bool in_rp; //renderpass is currently active
};
+
+void
+zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
+
+void
+zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs);
+
+void
+zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs);
+
void
zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch);
void
@@ -90,9 +107,6 @@ zink_start_batch(struct zink_context *ctx, struct zink_batch *batch);
void
zink_end_batch(struct zink_context *ctx, struct zink_batch *batch);
-void
-zink_batch_destroy(struct zink_context* ctx, struct zink_batch *batch);
-
enum zink_queue
zink_batch_reference_resource_rw(struct zink_batch *batch,
struct zink_resource *res,
@@ -113,6 +127,4 @@ zink_batch_reference_image_view(struct zink_batch *batch,
bool
zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds);
-void
-zink_batch_clear_resources(struct zink_screen *screen, struct zink_batch *batch);
#endif
diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c
index 1ef54b8a946..dae9d08bd9f 100644
--- a/src/gallium/drivers/zink/zink_blit.c
+++ b/src/gallium/drivers/zink/zink_blit.c
@@ -84,7 +84,7 @@ blit_resolve(struct zink_context *ctx, const struct pipe_blit_info *info)
region.extent.width = info->dst.box.width;
region.extent.height = info->dst.box.height;
region.extent.depth = info->dst.box.depth;
- vkCmdResolveImage(batch->cmdbuf, src->obj->image, src->layout,
+ vkCmdResolveImage(batch->state->cmdbuf, src->obj->image, src->layout,
dst->obj->image, dst->layout,
1, &region);
@@ -169,7 +169,7 @@ blit_native(struct zink_context *ctx, const struct pipe_blit_info *info)
region.dstSubresource.layerCount = 1;
}
- vkCmdBlitImage(batch->cmdbuf, src->obj->image, src->layout,
+ vkCmdBlitImage(batch->state->cmdbuf, src->obj->image, src->layout,
dst->obj->image, dst->layout,
1, &region,
zink_filter(info->filter));
diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c
index fee325da610..f8dceb1a578 100644
--- a/src/gallium/drivers/zink/zink_clear.c
+++ b/src/gallium/drivers/zink/zink_clear.c
@@ -115,7 +115,7 @@ clear_in_rp(struct pipe_context *pctx,
cr.baseArrayLayer = 0;
cr.layerCount = util_framebuffer_get_num_layers(fb);
struct zink_batch *batch = zink_batch_rp(ctx);
- vkCmdClearAttachments(batch->cmdbuf, num_attachments, attachments, 1, &cr);
+ vkCmdClearAttachments(batch->state->cmdbuf, num_attachments, attachments, 1, &cr);
}
static void
@@ -139,7 +139,7 @@ clear_color_no_rp(struct zink_context *ctx, struct zink_resource *res, const uni
zink_resource_image_needs_barrier(res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0))
zink_resource_image_barrier(ctx, NULL, res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0);
zink_batch_reference_resource_rw(batch, res, true);
- vkCmdClearColorImage(batch->cmdbuf, res->obj->image, res->layout, &color, 1, &range);
+ vkCmdClearColorImage(batch->state->cmdbuf, res->obj->image, res->layout, &color, 1, &range);
}
static void
@@ -159,7 +159,7 @@ clear_zs_no_rp(struct zink_context *ctx, struct zink_resource *res, VkImageAspec
zink_resource_image_needs_barrier(res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0))
zink_resource_image_barrier(ctx, NULL, res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0);
zink_batch_reference_resource_rw(batch, res, true);
- vkCmdClearDepthStencilImage(batch->cmdbuf, res->obj->image, res->layout, &zs_value, 1, &range);
+ vkCmdClearDepthStencilImage(batch->state->cmdbuf, res->obj->image, res->layout, &zs_value, 1, &range);
}
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index ec785f80f92..233565f20b8 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -293,10 +293,12 @@ zink_context_destroy(struct pipe_context *pctx)
for (unsigned i = 0; i < ARRAY_SIZE(ctx->null_buffers); i++)
pipe_resource_reference(&ctx->null_buffers[i], NULL);
- for (int i = 0; i < ARRAY_SIZE(ctx->batches); ++i)
- zink_batch_destroy(ctx, &ctx->batches[i]);
- if (ctx->compute_batch.cmdpool)
- zink_batch_destroy(ctx, &ctx->compute_batch);
+ for (int i = 0; i < ARRAY_SIZE(ctx->batches); ++i) {
+ zink_reset_batch_state(ctx, ctx->batches[i].state);
+ zink_batch_state_destroy(screen, ctx->batches[i].state);
+ }
+ zink_reset_batch_state(ctx, ctx->compute_batch.state);
+ zink_batch_state_destroy(screen, ctx->compute_batch.state);
hash_table_foreach(ctx->render_pass_cache, he)
zink_destroy_render_pass(screen, he->data);
@@ -495,7 +497,7 @@ zink_delete_sampler_state(struct pipe_context *pctx,
struct zink_sampler_state *sampler = sampler_state;
struct zink_batch *batch = zink_curr_batch(zink_context(pctx));
zink_descriptor_set_refs_clear(&sampler->desc_set_refs, sampler_state);
- util_dynarray_append(&batch->zombie_samplers, VkSampler,
+ util_dynarray_append(&batch->state->zombie_samplers, VkSampler,
sampler->sampler);
if (sampler->custom_border_color)
p_atomic_dec(&zink_screen(pctx->screen)->cur_custom_border_color_samplers);
@@ -1251,7 +1253,7 @@ zink_begin_render_pass(struct zink_context *ctx, struct zink_batch *batch)
zink_batch_reference_resource_rw(batch, zink_resource(ctx->framebuffer->surfaces[i]->texture), true);
}
- vkCmdBeginRenderPass(batch->cmdbuf, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
+ vkCmdBeginRenderPass(batch->state->cmdbuf, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
batch->in_rp = true;
zink_clear_framebuffer(ctx, clear_buffers);
@@ -1261,7 +1263,7 @@ static void
zink_end_render_pass(struct zink_context *ctx, struct zink_batch *batch)
{
if (batch->in_rp)
- vkCmdEndRenderPass(batch->cmdbuf);
+ vkCmdEndRenderPass(batch->state->cmdbuf);
batch->in_rp = false;
}
@@ -1548,7 +1550,7 @@ zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch,
isr
};
vkCmdPipelineBarrier(
- batch->cmdbuf,
+ batch->state->cmdbuf,
res->access_stage ? res->access_stage : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
pipeline,
0,
@@ -1640,7 +1642,7 @@ zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch,
};
vkCmdPipelineBarrier(
- batch->cmdbuf,
+ batch->state->cmdbuf,
res->access_stage ? res->access_stage : pipeline_access_stage(res->access),
pipeline,
0,
@@ -1705,7 +1707,7 @@ zink_flush(struct pipe_context *pctx,
struct zink_batch *batch = zink_curr_batch(ctx);
if (deferred)
- batch->fence->deferred_ctx = pctx;
+ batch->state->fence->deferred_ctx = pctx;
else if (batch->has_work) {
if (flags & PIPE_FLUSH_END_OF_FRAME) {
if (ctx->fb_state.nr_cbufs)
@@ -1715,7 +1717,7 @@ zink_flush(struct pipe_context *pctx,
ctx->fb_state.cbufs[i] ? zink_resource(ctx->fb_state.cbufs[i]->texture) : NULL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, 0, 0);
if (zink_screen(pctx->screen)->needs_mesa_flush_wsi && ctx->fb_state.cbufs[0])
- batch->flush_res = zink_resource(ctx->fb_state.cbufs[0]->texture);
+ batch->state->flush_res = zink_resource(ctx->fb_state.cbufs[0]->texture);
}
flush_batch(ctx);
@@ -1730,15 +1732,14 @@ zink_flush(struct pipe_context *pctx,
}
zink_fence_reference(zink_screen(pctx->screen),
(struct zink_fence **)pfence,
- batch->fence);
-
+ batch->state->fence);
if (flags & PIPE_FLUSH_END_OF_FRAME) {
/* if the first frame has not yet occurred, we need an explicit fence here
* in some cases in order to correctly draw the first frame, though it's
* unknown at this time why this is the case
*/
if (!ctx->first_frame_done)
- zink_fence_finish(zink_screen(pctx->screen), pctx, batch->fence, PIPE_TIMEOUT_INFINITE);
+ zink_fence_finish(zink_screen(pctx->screen), pctx, batch->state->fence, PIPE_TIMEOUT_INFINITE);
ctx->first_frame_done = true;
}
}
@@ -1761,10 +1762,10 @@ zink_wait_on_batch(struct zink_context *ctx, int batch_id)
if (batch_id >= 0) {
struct zink_batch *batch = batch_id == ZINK_COMPUTE_BATCH_ID ? &ctx->compute_batch : &ctx->batches[batch_id];
if (batch != zink_curr_batch(ctx)) {
- if (!batch->submitted) { // this is the compute batch
+ if (!batch->state->fence->submitted) { // this is the compute batch
zink_flush_compute(ctx);
} else
- ctx->base.screen->fence_finish(ctx->base.screen, NULL, (struct pipe_fence_handle*)batch->fence,
+ ctx->base.screen->fence_finish(ctx->base.screen, NULL, (struct pipe_fence_handle*)batch->state->fence,
PIPE_TIMEOUT_INFINITE);
return;
}
@@ -1899,13 +1900,13 @@ zink_memory_barrier(struct pipe_context *pctx, unsigned flags)
zink_end_render_pass(ctx, batch);
/* this should be the only call needed */
- vkCmdPipelineBarrier(batch->cmdbuf, src, dst, 0, 0, &b, 0, NULL, 0, NULL);
+ vkCmdPipelineBarrier(batch->state->cmdbuf, src, dst, 0, 0, &b, 0, NULL, 0, NULL);
flush_batch(ctx);
}
batch = &ctx->compute_batch;
if (batch->has_work) {
/* this should be the only call needed */
- vkCmdPipelineBarrier(batch->cmdbuf, src, dst, 0, 0, &b, 0, NULL, 0, NULL);
+ vkCmdPipelineBarrier(batch->state->cmdbuf, src, dst, 0, 0, &b, 0, NULL, 0, NULL);
zink_end_batch(ctx, batch);
zink_start_batch(ctx, batch);
}
@@ -1934,7 +1935,7 @@ zink_copy_buffer(struct zink_context *ctx, struct zink_batch *batch, struct zink
util_range_add(&dst->base, &dst->valid_buffer_range, dst_offset, dst_offset + size);
zink_resource_buffer_barrier(ctx, batch, src, VK_ACCESS_TRANSFER_READ_BIT, 0);
zink_resource_buffer_barrier(ctx, batch, dst, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
- vkCmdCopyBuffer(batch->cmdbuf, src->obj->buffer, dst->obj->buffer, 1, &region);
+ vkCmdCopyBuffer(batch->state->cmdbuf, src->obj->buffer, dst->obj->buffer, 1, &region);
}
void
@@ -2009,9 +2010,9 @@ zink_copy_image_buffer(struct zink_context *ctx, struct zink_batch *batch, struc
* - vkCmdCopyBufferToImage spec
*/
if (buf2img)
- vkCmdCopyBufferToImage(batch->cmdbuf, buf->obj->buffer, img->obj->image, img->layout, 1, &region);
+ vkCmdCopyBufferToImage(batch->state->cmdbuf, buf->obj->buffer, img->obj->image, img->layout, 1, &region);
else
- vkCmdCopyImageToBuffer(batch->cmdbuf, img->obj->image, img->layout, buf->obj->buffer, 1, &region);
+ vkCmdCopyImageToBuffer(batch->state->cmdbuf, img->obj->image, img->layout, buf->obj->buffer, 1, &region);
}
}
@@ -2078,7 +2079,7 @@ zink_resource_copy_region(struct pipe_context *pctx,
zink_batch_reference_resource_rw(batch, dst, true);
zink_resource_setup_transfer_layouts(ctx, src, dst);
- vkCmdCopyImage(batch->cmdbuf, src->obj->image, src->layout,
+ vkCmdCopyImage(batch->state->cmdbuf, src->obj->image, src->layout,
dst->obj->image, dst->layout,
1, &region);
} else if (dst->base.target == PIPE_BUFFER &&
@@ -2229,9 +2230,10 @@ zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
static bool
init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx)
{
+ batch->queue = idx == ZINK_COMPUTE_BATCH_ID ? ZINK_QUEUE_COMPUTE : ZINK_QUEUE_GFX;
batch->batch_id = idx;
zink_start_batch(ctx, batch);
- return !!batch->fence;
+ return !!batch->state;
}
struct pipe_context *
diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c
index 786291c724a..91023c5f9f8 100644
--- a/src/gallium/drivers/zink/zink_descriptors.c
+++ b/src/gallium/drivers/zink/zink_descriptors.c
@@ -407,7 +407,7 @@ quick_out:
zds->punted = zds->invalid = false;
*need_resource_refs = false;
if (zink_batch_add_desc_set(batch, zds)) {
- batch->descs_used += pool->key.num_descriptors;
+ batch->state->descs_used += pool->key.num_descriptors;
*need_resource_refs = true;
}
pg->last_set[type] = zds;
diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c
index c7637d3b17d..e8541cf188f 100644
--- a/src/gallium/drivers/zink/zink_draw.c
+++ b/src/gallium/drivers/zink/zink_draw.c
@@ -147,7 +147,7 @@ zink_emit_stream_output_targets(struct pipe_context *pctx)
t->base.buffer_offset + t->base.buffer_size);
}
- screen->vk_CmdBindTransformFeedbackBuffersEXT(batch->cmdbuf, 0, ctx->num_so_targets,
+ screen->vk_CmdBindTransformFeedbackBuffersEXT(batch->state->cmdbuf, 0, ctx->num_so_targets,
buffers, buffer_offsets,
buffer_sizes);
ctx->dirty_so_targets = false;
@@ -219,11 +219,11 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
}
if (screen->info.have_EXT_extended_dynamic_state)
- screen->vk_CmdBindVertexBuffers2EXT(batch->cmdbuf, 0,
+ screen->vk_CmdBindVertexBuffers2EXT(batch->state->cmdbuf, 0,
elems->hw_state.num_bindings,
buffers, buffer_offsets, NULL, buffer_strides);
else
- vkCmdBindVertexBuffers(batch->cmdbuf, 0,
+ vkCmdBindVertexBuffers(batch->state->cmdbuf, 0,
elems->hw_state.num_bindings,
buffers, buffer_offsets);
}
@@ -649,7 +649,7 @@ update_sampler_descriptors(struct zink_context *ctx, struct zink_descriptor_set
zink_batch_reference_sampler_view(batch, sampler_view);
if (sampler)
/* this only tracks the most recent usage for now */
- sampler->batch_uses = BITFIELD_BIT(batch->batch_id);
+ sampler->batch_uses = BITFIELD_BIT(batch->state->batch_id);
}
assert(num_wds < num_descriptors);
@@ -788,7 +788,7 @@ update_descriptors(struct zink_context *ctx, struct zink_screen *screen, bool is
for (unsigned h = 0; h < ZINK_DESCRIPTOR_TYPES; h++) {
if (zds[h]) {
- vkCmdBindDescriptorSets(batch->cmdbuf, is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
+ vkCmdBindDescriptorSets(batch->state->cmdbuf, is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
pg->layout, zds[h]->pool->type, 1, &zds[h]->desc_set,
zds[h]->pool->type == ZINK_DESCRIPTOR_TYPE_UBO ? dynamic_offset_idx : 0, dynamic_offsets);
}
@@ -866,7 +866,7 @@ zink_draw_vbo(struct pipe_context *pctx,
/* flush anytime our total batch memory usage is potentially >= 1/10 of total gpu memory
* this should also eventually trigger a stall if the app is going nuts with gpu memory
*/
- if (zink_curr_batch(ctx)->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
+ if (zink_curr_batch(ctx)->state->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
ctx->base.flush(&ctx->base, NULL, 0);
if (dinfo->primitive_restart && !restart_supported(dinfo->mode)) {
@@ -1004,9 +1004,9 @@ zink_draw_vbo(struct pipe_context *pctx,
viewports[i] = viewport;
}
if (screen->info.have_EXT_extended_dynamic_state)
- screen->vk_CmdSetViewportWithCountEXT(batch->cmdbuf, ctx->vp_state.num_viewports, viewports);
+ screen->vk_CmdSetViewportWithCountEXT(batch->state->cmdbuf, ctx->vp_state.num_viewports, viewports);
else
- vkCmdSetViewport(batch->cmdbuf, 0, ctx->vp_state.num_viewports, viewports);
+ vkCmdSetViewport(batch->state->cmdbuf, 0, ctx->vp_state.num_viewports, viewports);
VkRect2D scissors[PIPE_MAX_VIEWPORTS] = {};
if (ctx->rast_state->base.scissor) {
for (unsigned i = 0; i < ctx->vp_state.num_viewports; i++) {
@@ -1022,59 +1022,59 @@ zink_draw_vbo(struct pipe_context *pctx,
}
}
if (screen->info.have_EXT_extended_dynamic_state)
- screen->vk_CmdSetScissorWithCountEXT(batch->cmdbuf, ctx->vp_state.num_viewports, scissors);
+ screen->vk_CmdSetScissorWithCountEXT(batch->state->cmdbuf, ctx->vp_state.num_viewports, scissors);
else
- vkCmdSetScissor(batch->cmdbuf, 0, ctx->vp_state.num_viewports, scissors);
+ vkCmdSetScissor(batch->state->cmdbuf, 0, ctx->vp_state.num_viewports, scissors);
if (line_width_needed(reduced_prim, rast_state->hw_state.polygon_mode)) {
if (screen->info.feats.features.wideLines || ctx->line_width == 1.0f)
- vkCmdSetLineWidth(batch->cmdbuf, ctx->line_width);
+ vkCmdSetLineWidth(batch->state->cmdbuf, ctx->line_width);
else
debug_printf("BUG: wide lines not supported, needs fallback!");
}
if (dsa_state->base.stencil[0].enabled) {
if (dsa_state->base.stencil[1].enabled) {
- vkCmdSetStencilReference(batch->cmdbuf, VK_STENCIL_FACE_FRONT_BIT,
+ vkCmdSetStencilReference(batch->state->cmdbuf, VK_STENCIL_FACE_FRONT_BIT,
ctx->stencil_ref.ref_value[0]);
- vkCmdSetStencilReference(batch->cmdbuf, VK_STENCIL_FACE_BACK_BIT,
+ vkCmdSetStencilReference(batch->state->cmdbuf, VK_STENCIL_FACE_BACK_BIT,
ctx->stencil_ref.ref_value[1]);
} else
- vkCmdSetStencilReference(batch->cmdbuf,
+ vkCmdSetStencilReference(batch->state->cmdbuf,
VK_STENCIL_FACE_FRONT_AND_BACK,
ctx->stencil_ref.ref_value[0]);
}
if (depth_bias)
- vkCmdSetDepthBias(batch->cmdbuf, rast_state->offset_units, rast_state->offset_clamp, rast_state->offset_scale);
+ vkCmdSetDepthBias(batch->state->cmdbuf, rast_state->offset_units, rast_state->offset_clamp, rast_state->offset_scale);
else
- vkCmdSetDepthBias(batch->cmdbuf, 0.0f, 0.0f, 0.0f);
+ vkCmdSetDepthBias(batch->state->cmdbuf, 0.0f, 0.0f, 0.0f);
if (ctx->gfx_pipeline_state.blend_state->need_blend_constants)
- vkCmdSetBlendConstants(batch->cmdbuf, ctx->blend_constants);
+ vkCmdSetBlendConstants(batch->state->cmdbuf, ctx->blend_constants);
VkPipeline pipeline = zink_get_gfx_pipeline(screen, gfx_program,
&ctx->gfx_pipeline_state,
dinfo->mode);
- vkCmdBindPipeline(batch->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+ vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
zink_bind_vertex_buffers(batch, ctx);
if (BITSET_TEST(ctx->gfx_stages[PIPE_SHADER_VERTEX]->nir->info.system_values_read, SYSTEM_VALUE_BASE_VERTEX)) {
unsigned draw_mode_is_indexed = dinfo->index_size > 0;
- vkCmdPushConstants(batch->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
+ vkCmdPushConstants(batch->state->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
offsetof(struct zink_push_constant, draw_mode_is_indexed), sizeof(unsigned),
&draw_mode_is_indexed);
}
if (ctx->drawid_broken) {
unsigned draw_id = dinfo->drawid;
- vkCmdPushConstants(batch->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
+ vkCmdPushConstants(batch->state->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
offsetof(struct zink_push_constant, draw_id), sizeof(unsigned),
&draw_id);
}
if (gfx_program->shaders[PIPE_SHADER_TESS_CTRL] && gfx_program->shaders[PIPE_SHADER_TESS_CTRL]->is_generated)
- vkCmdPushConstants(batch->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
+ vkCmdPushConstants(batch->state->cmdbuf, gfx_program->base.layout, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
offsetof(struct zink_push_constant, default_inner_level), sizeof(float) * 6,
&ctx->tess_levels[0]);
@@ -1093,7 +1093,7 @@ zink_draw_vbo(struct pipe_context *pctx,
}
}
}
- screen->vk_CmdBeginTransformFeedbackEXT(batch->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
+ screen->vk_CmdBeginTransformFeedbackEXT(batch->state->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
}
if (dinfo->index_size > 0) {
@@ -1117,7 +1117,7 @@ zink_draw_vbo(struct pipe_context *pctx,
unreachable("unknown index size!");
}
struct zink_resource *res = zink_resource(index_buffer);
- vkCmdBindIndexBuffer(batch->cmdbuf, res->obj->buffer, index_offset, index_type);
+ vkCmdBindIndexBuffer(batch->state->cmdbuf, res->obj->buffer, index_offset, index_type);
zink_batch_reference_resource_rw(batch, res, false);
if (dindirect && dindirect->buffer) {
struct zink_resource *indirect = zink_resource(dindirect->buffer);
@@ -1125,20 +1125,20 @@ zink_draw_vbo(struct pipe_context *pctx,
if (dindirect->indirect_draw_count) {
struct zink_resource *indirect_draw_count = zink_resource(dindirect->indirect_draw_count);
zink_batch_reference_resource_rw(batch, indirect_draw_count, false);
- screen->vk_CmdDrawIndexedIndirectCount(batch->cmdbuf, indirect->obj->buffer, dindirect->offset,
+ screen->vk_CmdDrawIndexedIndirectCount(batch->state->cmdbuf, indirect->obj->buffer, dindirect->offset,
indirect_draw_count->obj->buffer, dindirect->indirect_draw_count_offset,
dindirect->draw_count, dindirect->stride);
} else
- vkCmdDrawIndexedIndirect(batch->cmdbuf, indirect->obj->buffer, dindirect->offset, dindirect->draw_count, dindirect->stride);
+ vkCmdDrawIndexedIndirect(batch->state->cmdbuf, indirect->obj->buffer, dindirect->offset, dindirect->draw_count, dindirect->stride);
} else
- vkCmdDrawIndexed(batch->cmdbuf,
+ vkCmdDrawIndexed(batch->state->cmdbuf,
draws[0].count, dinfo->instance_count,
need_index_buffer_unref ? 0 : draws[0].start, dinfo->index_bias, dinfo->start_instance);
} else {
if (so_target && screen->info.tf_props.transformFeedbackDraw) {
zink_batch_reference_resource_rw(batch, zink_resource(so_target->base.buffer), false);
zink_batch_reference_resource_rw(batch, zink_resource(so_target->counter_buffer), true);
- screen->vk_CmdDrawIndirectByteCountEXT(batch->cmdbuf, dinfo->instance_count, dinfo->start_instance,
+ screen->vk_CmdDrawIndirectByteCountEXT(batch->state->cmdbuf, dinfo->instance_count, dinfo->start_instance,
zink_resource(so_target->counter_buffer)->obj->buffer, so_target->counter_buffer_offset, 0,
MIN2(so_target->stride, screen->info.tf_props.maxTransformFeedbackBufferDataStride));
} else if (dindirect && dindirect->buffer) {
@@ -1147,13 +1147,13 @@ zink_draw_vbo(struct pipe_context *pctx,
if (dindirect->indirect_draw_count) {
struct zink_resource *indirect_draw_count = zink_resource(dindirect->indirect_draw_count);
zink_batch_reference_resource_rw(batch, indirect_draw_count, false);
- screen->vk_CmdDrawIndirectCount(batch->cmdbuf, indirect->obj->buffer, dindirect->offset,
+ screen->vk_CmdDrawIndirectCount(batch->state->cmdbuf, indirect->obj->buffer, dindirect->offset,
indirect_draw_count->obj->buffer, dindirect->indirect_draw_count_offset,
dindirect->draw_count, dindirect->stride);
} else
- vkCmdDrawIndirect(batch->cmdbuf, indirect->obj->buffer, dindirect->offset, dindirect->draw_count, dindirect->stride);
+ vkCmdDrawIndirect(batch->state->cmdbuf, indirect->obj->buffer, dindirect->offset, dindirect->draw_count, dindirect->stride);
} else
- vkCmdDraw(batch->cmdbuf, draws[0].count, dinfo->instance_count, draws[0].start, dinfo->start_instance);
+ vkCmdDraw(batch->state->cmdbuf, draws[0].count, dinfo->instance_count, draws[0].start, dinfo->start_instance);
}
if (dinfo->index_size > 0 && (dinfo->has_user_indices || need_index_buffer_unref))
@@ -1168,7 +1168,7 @@ zink_draw_vbo(struct pipe_context *pctx,
t->counter_buffer_valid = true;
}
}
- screen->vk_CmdEndTransformFeedbackEXT(batch->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
+ screen->vk_CmdEndTransformFeedbackEXT(batch->state->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
}
batch->has_work = true;
}
@@ -1183,7 +1183,7 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
/* flush anytime our total batch memory usage is potentially >= 1/10 of total gpu memory
* this should also eventually trigger a stall if the app is going nuts with gpu memory
*/
- if (batch->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
+ if (batch->state->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
zink_flush_compute(ctx);
struct zink_compute_program *comp_program = get_compute_program(ctx);
@@ -1198,12 +1198,12 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
update_descriptors(ctx, screen, true);
- vkCmdBindPipeline(batch->cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
+ vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
if (info->indirect) {
- vkCmdDispatchIndirect(batch->cmdbuf, zink_resource(info->indirect)->obj->buffer, info->indirect_offset);
+ vkCmdDispatchIndirect(batch->state->cmdbuf, zink_resource(info->indirect)->obj->buffer, info->indirect_offset);
zink_batch_reference_resource_rw(batch, zink_resource(info->indirect), false);
} else
- vkCmdDispatch(batch->cmdbuf, info->grid[0], info->grid[1], info->grid[2]);
+ vkCmdDispatch(batch->state->cmdbuf, info->grid[0], info->grid[1], info->grid[2]);
batch->has_work = true;
}
diff --git a/src/gallium/drivers/zink/zink_fence.c b/src/gallium/drivers/zink/zink_fence.c
index 7aec89eb2fe..485d6108c8a 100644
--- a/src/gallium/drivers/zink/zink_fence.c
+++ b/src/gallium/drivers/zink/zink_fence.c
@@ -40,40 +40,39 @@ destroy_fence(struct zink_screen *screen, struct zink_fence *fence)
FREE(fence);
}
-struct zink_fence *
-zink_create_fence(struct pipe_screen *pscreen, struct zink_batch *batch)
+bool
+zink_create_fence(struct zink_screen *screen, struct zink_batch_state *bs)
{
- struct zink_screen *screen = zink_screen(pscreen);
-
VkFenceCreateInfo fci = {};
fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
struct zink_fence *ret = CALLOC_STRUCT(zink_fence);
if (!ret) {
debug_printf("CALLOC_STRUCT failed\n");
- return NULL;
+ return false;
}
if (vkCreateFence(screen->dev, &fci, NULL, &ret->fence) != VK_SUCCESS) {
debug_printf("vkCreateFence failed\n");
goto fail;
}
- ret->batch_id = batch->batch_id;
+ ret->batch_id = bs->batch_id;
util_dynarray_init(&ret->resources, NULL);
pipe_reference_init(&ret->reference, 1);
- return ret;
+ bs->fence = ret;
+ return true;
fail:
destroy_fence(screen, ret);
- return NULL;
+ return false;
}
void
zink_fence_init(struct zink_context *ctx, struct zink_batch *batch)
{
- struct zink_fence *fence = batch->fence;
- set_foreach(batch->resources, entry) {
+ struct zink_fence *fence = batch->state->fence;
+ set_foreach(batch->state->resources, entry) {
/* the fence needs its own reference to ensure it can safely access lifetime-dependent
* resource members
*/
diff --git a/src/gallium/drivers/zink/zink_fence.h b/src/gallium/drivers/zink/zink_fence.h
index 4cfca828beb..4c12a231745 100644
--- a/src/gallium/drivers/zink/zink_fence.h
+++ b/src/gallium/drivers/zink/zink_fence.h
@@ -31,6 +31,7 @@
struct pipe_context;
struct pipe_screen;
+struct zink_batch_state;
struct zink_context;
struct zink_screen;
@@ -51,8 +52,8 @@ zink_fence(struct pipe_fence_handle *pfence)
void
zink_fence_init(struct zink_context *ctx, struct zink_batch *batch);
-struct zink_fence *
-zink_create_fence(struct pipe_screen *pscreen, struct zink_batch *batch);
+bool
+zink_create_fence(struct zink_screen *screen, struct zink_batch_state *bs);
void
zink_fence_reference(struct zink_screen *screen,
diff --git a/src/gallium/drivers/zink/zink_query.c b/src/gallium/drivers/zink/zink_query.c
index 6867a540f27..ea912190ca7 100644
--- a/src/gallium/drivers/zink/zink_query.c
+++ b/src/gallium/drivers/zink/zink_query.c
@@ -204,9 +204,9 @@ zink_create_query(struct pipe_context *pctx,
}
struct zink_batch *batch = get_batch_for_query(zink_context(pctx), query, true);
batch->has_work = true;
- vkCmdResetQueryPool(batch->cmdbuf, query->query_pool, 0, query->num_queries);
+ vkCmdResetQueryPool(batch->state->cmdbuf, query->query_pool, 0, query->num_queries);
if (query->type == PIPE_QUERY_PRIMITIVES_GENERATED)
- vkCmdResetQueryPool(batch->cmdbuf, query->xfb_query_pool[0], 0, query->num_queries);
+ vkCmdResetQueryPool(batch->state->cmdbuf, query->xfb_query_pool[0], 0, query->num_queries);
if (query->type == PIPE_QUERY_TIMESTAMP)
query->active = true;
return (struct pipe_query *)query;
@@ -406,7 +406,7 @@ force_cpu_read(struct zink_context *ctx, struct pipe_query *pquery, bool wait, e
unsigned result_size = result_type <= PIPE_QUERY_TYPE_U32 ? sizeof(uint32_t) : sizeof(uint64_t);
struct zink_query *query = (struct zink_query*)pquery;
union pipe_query_result result;
- if (zink_curr_batch(ctx)->batch_id == query->batch_id)
+ if (zink_curr_batch(ctx)->state->batch_id == query->batch_id)
pctx->flush(pctx, NULL, PIPE_FLUSH_HINT_FINISH);
else if (is_cs_query(query))
zink_flush_compute(ctx);
@@ -456,7 +456,7 @@ copy_results_to_buffer(struct zink_context *ctx, struct zink_query *query, struc
zink_batch_reference_resource_rw(batch, res, true);
zink_resource_buffer_barrier(ctx, batch, res, VK_ACCESS_TRANSFER_WRITE_BIT, 0);
util_range_add(&res->base, &res->valid_buffer_range, offset, offset + result_size);
- vkCmdCopyQueryPoolResults(batch->cmdbuf, query->query_pool, query_id, num_results, res->obj->buffer,
+ vkCmdCopyQueryPoolResults(batch->state->cmdbuf, query->query_pool, query_id, num_results, res->obj->buffer,
offset, 0, flags);
/* this is required for compute batch sync and will be removed later */
if (is_cs_query(query))
@@ -477,12 +477,12 @@ reset_pool(struct zink_context *ctx, struct zink_batch *batch, struct zink_query
if (q->type != PIPE_QUERY_TIMESTAMP)
get_query_result(&ctx->base, (struct pipe_query*)q, false, &q->accumulated_result);
- vkCmdResetQueryPool(batch->cmdbuf, q->query_pool, 0, q->num_queries);
+ vkCmdResetQueryPool(batch->state->cmdbuf, q->query_pool, 0, q->num_queries);
if (q->type == PIPE_QUERY_PRIMITIVES_GENERATED)
- vkCmdResetQueryPool(batch->cmdbuf, q->xfb_query_pool[0], 0, q->num_queries);
+ vkCmdResetQueryPool(batch->state->cmdbuf, q->xfb_query_pool[0], 0, q->num_queries);
else if (q->type == PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE) {
for (unsigned i = 0; i < ARRAY_SIZE(q->xfb_query_pool); i++)
- vkCmdResetQueryPool(batch->cmdbuf, q->xfb_query_pool[i], 0, q->num_queries);
+ vkCmdResetQueryPool(batch->state->cmdbuf, q->xfb_query_pool[i], 0, q->num_queries);
}
memset(q->have_gs, 0, sizeof(q->have_gs));
memset(q->have_xfb, 0, sizeof(q->have_xfb));
@@ -501,7 +501,7 @@ begin_query(struct zink_context *ctx, struct zink_batch *batch, struct zink_quer
q->active = true;
batch->has_work = true;
if (q->type == PIPE_QUERY_TIME_ELAPSED)
- vkCmdWriteTimestamp(batch->cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, q->query_pool, q->curr_query++);
+ vkCmdWriteTimestamp(batch->state->cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, q->query_pool, q->curr_query++);
/* ignore the rest of begin_query for timestamps */
if (is_time_query(q))
return;
@@ -510,20 +510,20 @@ begin_query(struct zink_context *ctx, struct zink_batch *batch, struct zink_quer
if (q->type == PIPE_QUERY_PRIMITIVES_EMITTED ||
q->type == PIPE_QUERY_PRIMITIVES_GENERATED ||
q->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE) {
- zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->cmdbuf,
+ zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->state->cmdbuf,
q->xfb_query_pool[0] ? q->xfb_query_pool[0] : q->query_pool,
q->curr_query,
flags,
q->index);
q->xfb_running = true;
} else if (q->type == PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE) {
- zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->cmdbuf,
+ zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->state->cmdbuf,
q->query_pool,
q->curr_query,
flags,
0);
for (unsigned i = 0; i < ARRAY_SIZE(q->xfb_query_pool); i++)
- zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->cmdbuf,
+ zink_screen(ctx->base.screen)->vk_CmdBeginQueryIndexedEXT(batch->state->cmdbuf,
q->xfb_query_pool[i],
q->curr_query,
flags,
@@ -531,12 +531,12 @@ begin_query(struct zink_context *ctx, struct zink_batch *batch, struct zink_quer
q->xfb_running = true;
}
if (q->vkqtype != VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT)
- vkCmdBeginQuery(batch->cmdbuf, q->query_pool, q->curr_query, flags);
+ vkCmdBeginQuery(batch->state->cmdbuf, q->query_pool, q->curr_query, flags);
if (needs_stats_list(q))
list_addtail(&q->stats_list, &ctx->primitives_generated_queries);
p_atomic_inc(&q->fences);
- q->batch_id = batch->batch_id;
- _mesa_set_add(batch->active_queries, q);
+ q->batch_id = batch->state->batch_id;
+ _mesa_set_add(batch->state->active_queries, q);
}
static bool
@@ -563,23 +563,23 @@ end_query(struct zink_context *ctx, struct zink_batch *batch, struct zink_query
batch->has_work = true;
q->active = q->type == PIPE_QUERY_TIMESTAMP;
if (is_time_query(q)) {
- vkCmdWriteTimestamp(batch->cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ vkCmdWriteTimestamp(batch->state->cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
q->query_pool, q->curr_query);
- q->batch_id = batch->batch_id;
+ q->batch_id = batch->state->batch_id;
} else if (q->type == PIPE_QUERY_PRIMITIVES_EMITTED ||
q->type == PIPE_QUERY_PRIMITIVES_GENERATED ||
q->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE)
- screen->vk_CmdEndQueryIndexedEXT(batch->cmdbuf, q->xfb_query_pool[0] ? q->xfb_query_pool[0] :
- q->query_pool,
+ screen->vk_CmdEndQueryIndexedEXT(batch->state->cmdbuf, q->xfb_query_pool[0] ? q->xfb_query_pool[0] :
+ q->query_pool,
q->curr_query, q->index);
else if (q->type == PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE) {
- screen->vk_CmdEndQueryIndexedEXT(batch->cmdbuf, q->query_pool, q->curr_query, 0);
+ screen->vk_CmdEndQueryIndexedEXT(batch->state->cmdbuf, q->query_pool, q->curr_query, 0);
for (unsigned i = 0; i < ARRAY_SIZE(q->xfb_query_pool); i++)
- screen->vk_CmdEndQueryIndexedEXT(batch->cmdbuf, q->xfb_query_pool[i], q->curr_query, i + 1);
+ screen->vk_CmdEndQueryIndexedEXT(batch->state->cmdbuf, q->xfb_query_pool[i], q->curr_query, i + 1);
}
if (q->vkqtype != VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT && !is_time_query(q))
- vkCmdEndQuery(batch->cmdbuf, q->query_pool, q->curr_query);
+ vkCmdEndQuery(batch->state->cmdbuf, q->query_pool, q->curr_query);
if (needs_stats_list(q))
list_delinit(&q->stats_list);
if (++q->curr_query == q->num_queries) {
@@ -630,9 +630,7 @@ zink_get_query_result(struct pipe_context *pctx,
void
zink_suspend_queries(struct zink_context *ctx, struct zink_batch *batch)
{
- if (!batch->active_queries)
- return;
- set_foreach(batch->active_queries, entry) {
+ set_foreach(batch->state->active_queries, entry) {
struct zink_query *query = (void*)entry->key;
/* if a query isn't active here then we don't need to reactivate it on the next batch */
if (query->active) {
@@ -694,7 +692,7 @@ zink_render_condition(struct pipe_context *pctx,
if (query == NULL) {
zink_clear_apply_conditionals(ctx);
- screen->vk_CmdEndConditionalRenderingEXT(batch->cmdbuf);
+ screen->vk_CmdEndConditionalRenderingEXT(batch->state->cmdbuf);
ctx->render_condition_active = false;
return;
}
@@ -738,7 +736,7 @@ zink_render_condition(struct pipe_context *pctx,
begin_info.sType = VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT;
begin_info.buffer = res->obj->buffer;
begin_info.flags = begin_flags;
- screen->vk_CmdBeginConditionalRenderingEXT(batch->cmdbuf, &begin_info);
+ screen->vk_CmdBeginConditionalRenderingEXT(batch->state->cmdbuf, &begin_info);
ctx->render_condition_active = true;
pipe_resource_reference(&pres, NULL);