diff options
author | Erik Faye-Lund <[email protected]> | 2019-03-26 19:35:13 +0100 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-28 08:51:44 +0000 |
commit | 21cffebe4f22ea49b0d11fdb2e01da8a0707624a (patch) | |
tree | a60145e4d6eff368e3042c19cd7483feb0fac217 | |
parent | a27b84dd2e75d681a8be3511eb1020ca22ed4d02 (diff) |
zink: reference vertex and index buffers
Acked-by: Jordan Justen <[email protected]>
-rw-r--r-- | src/gallium/drivers/zink/zink_cmdbuf.c | 21 | ||||
-rw-r--r-- | src/gallium/drivers/zink/zink_cmdbuf.h | 7 | ||||
-rw-r--r-- | src/gallium/drivers/zink/zink_context.c | 19 |
3 files changed, 42 insertions, 5 deletions
diff --git a/src/gallium/drivers/zink/zink_cmdbuf.c b/src/gallium/drivers/zink/zink_cmdbuf.c index aab898f84b1..44c4d941b8d 100644 --- a/src/gallium/drivers/zink/zink_cmdbuf.c +++ b/src/gallium/drivers/zink/zink_cmdbuf.c @@ -4,9 +4,11 @@ #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_cmdbuf(struct zink_screen *screen, struct zink_cmdbuf *cmdbuf) @@ -20,6 +22,13 @@ reset_cmdbuf(struct zink_screen *screen, struct zink_cmdbuf *cmdbuf) zink_render_pass_reference(screen, &cmdbuf->rp, NULL); zink_framebuffer_reference(screen, &cmdbuf->fb, NULL); + + /* unref all used resources */ + set_foreach(cmdbuf->resources, entry) { + struct pipe_resource *pres = (struct pipe_resource *)entry->key; + pipe_resource_reference(&pres, NULL); + } + _mesa_set_clear(cmdbuf->resources, NULL); } struct zink_cmdbuf * @@ -79,3 +88,15 @@ zink_end_cmdbuf(struct zink_context *ctx, struct zink_cmdbuf *cmdbuf) if (vkQueueWaitIdle(ctx->queue) != VK_SUCCESS) debug_printf("vkQueueWaitIdle failed\n"); } + +void +zink_cmdbuf_reference_resoure(struct zink_cmdbuf *cmdbuf, + struct zink_resource *res) +{ + struct set_entry *entry = _mesa_set_search(cmdbuf->resources, res); + if (!entry) { + struct pipe_resource *tmp = NULL; + entry = _mesa_set_add(cmdbuf->resources, res); + pipe_resource_reference(&tmp, &res->base); + } +} diff --git a/src/gallium/drivers/zink/zink_cmdbuf.h b/src/gallium/drivers/zink/zink_cmdbuf.h index ff5f4729760..f0159d91120 100644 --- a/src/gallium/drivers/zink/zink_cmdbuf.h +++ b/src/gallium/drivers/zink/zink_cmdbuf.h @@ -30,6 +30,7 @@ struct zink_context; struct zink_fence; struct zink_framebuffer; struct zink_render_pass; +struct zink_resource; struct zink_cmdbuf { VkCommandBuffer cmdbuf; @@ -37,6 +38,8 @@ struct zink_cmdbuf { struct zink_render_pass *rp; struct zink_framebuffer *fb; + + struct set *resources; }; struct zink_cmdbuf * @@ -45,4 +48,8 @@ zink_start_cmdbuf(struct zink_context *ctx); void zink_end_cmdbuf(struct zink_context *ctx, struct zink_cmdbuf *cmdbuf); +void +zink_cmdbuf_reference_resoure(struct zink_cmdbuf *cmdbuf, + struct zink_resource *res); + #endif diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index b364a12b538..f87d66fd4fb 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -743,7 +743,7 @@ zink_primitive_topology(enum pipe_prim_type mode) } static void -zink_bind_vertex_buffers(VkCommandBuffer cmdbuf, struct zink_context *ctx) +zink_bind_vertex_buffers(struct zink_cmdbuf *cmdbuf, struct zink_context *ctx) { VkBuffer buffers[PIPE_MAX_ATTRIBS]; VkDeviceSize buffer_offsets[PIPE_MAX_ATTRIBS]; @@ -754,10 +754,11 @@ zink_bind_vertex_buffers(VkCommandBuffer cmdbuf, struct zink_context *ctx) struct zink_resource *res = zink_resource(vb->buffer.resource); buffers[i] = res->buffer; buffer_offsets[i] = vb->buffer_offset; + zink_cmdbuf_reference_resoure(cmdbuf, res); } if (elems->num_bindings > 0) - vkCmdBindVertexBuffers(cmdbuf, 0, elems->num_bindings, buffers, buffer_offsets); + vkCmdBindVertexBuffers(cmdbuf->cmdbuf, 0, elems->num_bindings, buffers, buffer_offsets); } static void @@ -955,12 +956,14 @@ zink_draw_vbo(struct pipe_context *pctx, vkCmdBindPipeline(cmdbuf->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); vkCmdBindDescriptorSets(cmdbuf->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, gfx_program->layout, 0, 1, &desc_set, 0, NULL); - zink_bind_vertex_buffers(cmdbuf->cmdbuf, ctx); + zink_bind_vertex_buffers(cmdbuf, ctx); if (dinfo->index_size > 0) { assert(dinfo->index_size != 1); VkIndexType index_type = dinfo->index_size == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32; - vkCmdBindIndexBuffer(cmdbuf->cmdbuf, zink_resource(index_buffer)->buffer, index_offset, index_type); + struct zink_resource *res = zink_resource(index_buffer); + vkCmdBindIndexBuffer(cmdbuf->cmdbuf, res->buffer, index_offset, index_type); + zink_cmdbuf_reference_resoure(cmdbuf, res); vkCmdDrawIndexed(cmdbuf->cmdbuf, dinfo->count, dinfo->instance_count, dinfo->start, dinfo->index_bias, dinfo->start_instance); @@ -1247,10 +1250,16 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) cbai.commandPool = ctx->cmdpool; cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; cbai.commandBufferCount = 1; - for (int i = 0; i < ARRAY_SIZE(ctx->cmdbufs); ++i) + for (int i = 0; i < ARRAY_SIZE(ctx->cmdbufs); ++i) { if (vkAllocateCommandBuffers(screen->dev, &cbai, &ctx->cmdbufs[i].cmdbuf) != VK_SUCCESS) goto fail; + ctx->cmdbufs[i].resources = _mesa_set_create(NULL, _mesa_hash_pointer, + _mesa_key_pointer_equal); + if (!ctx->cmdbufs[i].resources) + goto fail; + } + VkDescriptorPoolSize sizes[] = { {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000} }; |