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_program.h"
8 #include "zink_render_pass.h"
9 #include "zink_resource.h"
10 #include "zink_screen.h"
12 #include "util/u_debug.h"
16 reset_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
18 struct zink_screen
*screen
= zink_screen(ctx
->base
.screen
);
19 batch
->descs_left
= ZINK_BATCH_DESC_SIZE
;
21 // cmdbuf hasn't been submitted before
25 zink_fence_finish(screen
, batch
->fence
, PIPE_TIMEOUT_INFINITE
);
26 zink_fence_reference(screen
, &batch
->fence
, NULL
);
28 zink_render_pass_reference(screen
, &batch
->rp
, NULL
);
29 zink_framebuffer_reference(screen
, &batch
->fb
, NULL
);
30 set_foreach(batch
->programs
, entry
) {
31 struct zink_gfx_program
*prog
= (struct zink_gfx_program
*)entry
->key
;
32 zink_gfx_program_reference(screen
, &prog
, NULL
);
34 _mesa_set_clear(batch
->programs
, NULL
);
36 /* unref all used resources */
37 set_foreach(batch
->resources
, entry
) {
38 struct pipe_resource
*pres
= (struct pipe_resource
*)entry
->key
;
39 pipe_resource_reference(&pres
, NULL
);
41 _mesa_set_clear(batch
->resources
, NULL
);
43 /* unref all used sampler-views */
44 set_foreach(batch
->sampler_views
, entry
) {
45 struct pipe_sampler_view
*pres
= (struct pipe_sampler_view
*)entry
->key
;
46 pipe_sampler_view_reference(&pres
, NULL
);
48 _mesa_set_clear(batch
->sampler_views
, NULL
);
50 util_dynarray_foreach(&batch
->zombie_samplers
, VkSampler
, samp
) {
51 vkDestroySampler(screen
->dev
, *samp
, NULL
);
53 util_dynarray_clear(&batch
->zombie_samplers
);
55 if (vkResetDescriptorPool(screen
->dev
, batch
->descpool
, 0) != VK_SUCCESS
)
56 fprintf(stderr
, "vkResetDescriptorPool failed\n");
60 zink_start_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
62 reset_batch(ctx
, batch
);
64 VkCommandBufferBeginInfo cbbi
= {};
65 cbbi
.sType
= VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
;
66 cbbi
.flags
= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
;
67 if (vkBeginCommandBuffer(batch
->cmdbuf
, &cbbi
) != VK_SUCCESS
)
68 debug_printf("vkBeginCommandBuffer failed\n");
70 if (!ctx
->queries_disabled
)
71 zink_resume_queries(ctx
, batch
);
75 zink_end_batch(struct zink_context
*ctx
, struct zink_batch
*batch
)
77 if (!ctx
->queries_disabled
)
78 zink_suspend_queries(ctx
, batch
);
80 if (vkEndCommandBuffer(batch
->cmdbuf
) != VK_SUCCESS
) {
81 debug_printf("vkEndCommandBuffer failed\n");
85 assert(batch
->fence
== NULL
);
86 batch
->fence
= zink_create_fence(ctx
->base
.screen
, batch
);
91 si
.sType
= VK_STRUCTURE_TYPE_SUBMIT_INFO
;
92 si
.waitSemaphoreCount
= 0;
93 si
.pWaitSemaphores
= NULL
;
94 si
.signalSemaphoreCount
= 0;
95 si
.pSignalSemaphores
= NULL
;
96 si
.pWaitDstStageMask
= NULL
;
97 si
.commandBufferCount
= 1;
98 si
.pCommandBuffers
= &batch
->cmdbuf
;
100 if (vkQueueSubmit(ctx
->queue
, 1, &si
, batch
->fence
->fence
) != VK_SUCCESS
) {
101 debug_printf("vkQueueSubmit failed\n");
107 zink_batch_reference_resoure(struct zink_batch
*batch
,
108 struct zink_resource
*res
)
110 struct set_entry
*entry
= _mesa_set_search(batch
->resources
, res
);
112 entry
= _mesa_set_add(batch
->resources
, res
);
113 pipe_reference(NULL
, &res
->base
.reference
);
115 /* u_transfer_helper unrefs the stencil buffer when the depth buffer is unrefed,
116 * so we add an extra ref here to the stencil buffer to compensate
118 struct zink_resource
*stencil
;
120 zink_get_depth_stencil_resources((struct pipe_resource
*)res
, NULL
, &stencil
);
122 pipe_reference(NULL
, &stencil
->base
.reference
);
127 zink_batch_reference_sampler_view(struct zink_batch
*batch
,
128 struct zink_sampler_view
*sv
)
130 struct set_entry
*entry
= _mesa_set_search(batch
->sampler_views
, sv
);
132 entry
= _mesa_set_add(batch
->sampler_views
, sv
);
133 pipe_reference(NULL
, &sv
->base
.reference
);
138 zink_batch_reference_program(struct zink_batch
*batch
,
139 struct zink_gfx_program
*prog
)
141 struct set_entry
*entry
= _mesa_set_search(batch
->programs
, prog
);
143 entry
= _mesa_set_add(batch
->programs
, prog
);
144 pipe_reference(NULL
, &prog
->reference
);