1 #include "zink_batch.h"
3 #include "zink_context.h"
4 #include "zink_fence.h"
5 #include "zink_framebuffer.h"
6 #include "zink_query.h"
7 #include "zink_render_pass.h"
8 #include "zink_resource.h"
9 #include "zink_screen.h"
11 #include "util/u_debug.h"
15 reset_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
17 struct zink_screen
*screen
= zink_screen(ctx
->base
.screen
);
18 batch
->descs_left
= ZINK_BATCH_DESC_SIZE
;
20 // cmdbuf hasn't been submitted before
24 zink_fence_finish(screen
, batch
->fence
, PIPE_TIMEOUT_INFINITE
);
25 zink_fence_reference(screen
, &batch
->fence
, NULL
);
27 zink_render_pass_reference(screen
, &batch
->rp
, NULL
);
28 zink_framebuffer_reference(screen
, &batch
->fb
, NULL
);
30 /* unref all used resources */
31 set_foreach(batch
->resources
, entry
) {
32 struct pipe_resource
*pres
= (struct pipe_resource
*)entry
->key
;
33 pipe_resource_reference(&pres
, NULL
);
35 _mesa_set_clear(batch
->resources
, NULL
);
37 /* unref all used sampler-views */
38 set_foreach(batch
->sampler_views
, entry
) {
39 struct pipe_sampler_view
*pres
= (struct pipe_sampler_view
*)entry
->key
;
40 pipe_sampler_view_reference(&pres
, NULL
);
42 _mesa_set_clear(batch
->sampler_views
, NULL
);
44 util_dynarray_foreach(&batch
->zombie_samplers
, VkSampler
, samp
) {
45 vkDestroySampler(screen
->dev
, *samp
, NULL
);
47 util_dynarray_clear(&batch
->zombie_samplers
);
49 if (vkResetDescriptorPool(screen
->dev
, batch
->descpool
, 0) != VK_SUCCESS
)
50 fprintf(stderr
, "vkResetDescriptorPool failed\n");
54 zink_start_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
56 reset_batch(ctx
, batch
);
58 VkCommandBufferBeginInfo cbbi
= {};
59 cbbi
.sType
= VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
;
60 cbbi
.flags
= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
;
61 if (vkBeginCommandBuffer(batch
->cmdbuf
, &cbbi
) != VK_SUCCESS
)
62 debug_printf("vkBeginCommandBuffer failed\n");
64 if (!ctx
->queries_disabled
)
65 zink_resume_queries(ctx
, batch
);
69 zink_end_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
71 if (!ctx
->queries_disabled
)
72 zink_suspend_queries(ctx
, batch
);
74 if (vkEndCommandBuffer(batch
->cmdbuf
) != VK_SUCCESS
) {
75 debug_printf("vkEndCommandBuffer failed\n");
79 assert(batch
->fence
== NULL
);
80 batch
->fence
= zink_create_fence(ctx
->base
.screen
, batch
);
85 si
.sType
= VK_STRUCTURE_TYPE_SUBMIT_INFO
;
86 si
.waitSemaphoreCount
= 0;
87 si
.pWaitSemaphores
= NULL
;
88 si
.signalSemaphoreCount
= 0;
89 si
.pSignalSemaphores
= NULL
;
90 si
.pWaitDstStageMask
= NULL
;
91 si
.commandBufferCount
= 1;
92 si
.pCommandBuffers
= &batch
->cmdbuf
;
94 if (vkQueueSubmit(ctx
->queue
, 1, &si
, batch
->fence
->fence
) != VK_SUCCESS
) {
95 debug_printf("vkQueueSubmit failed\n");
101 zink_batch_reference_resoure(struct zink_batch
*batch
,
102 struct zink_resource
*res
)
104 struct set_entry
*entry
= _mesa_set_search(batch
->resources
, res
);
106 entry
= _mesa_set_add(batch
->resources
, res
);
107 pipe_reference(NULL
, &res
->base
.reference
);
112 zink_batch_reference_sampler_view(struct zink_batch
*batch
,
113 struct zink_sampler_view
*sv
)
115 struct set_entry
*entry
= _mesa_set_search(batch
->sampler_views
, sv
);
117 entry
= _mesa_set_add(batch
->sampler_views
, sv
);
118 pipe_reference(NULL
, &sv
->base
.reference
);