Lines Matching refs:bs
30 zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
34 VkResult result = VKSCR(ResetCommandPool)(screen->dev, bs->cmdpool, 0);
39 set_foreach_remove(bs->resources, entry) {
41 if (!zink_resource_object_usage_unset(obj, bs)) {
46 util_dynarray_append(&bs->unref_resources, struct zink_resource_object*, obj);
50 while (util_dynarray_contains(&bs->bindless_releases[i], uint32_t)) {
51 uint32_t handle = util_dynarray_pop(&bs->bindless_releases[i], uint32_t);
58 set_foreach_remove(bs->active_queries, entry) {
60 zink_prune_query(screen, bs, query);
63 set_foreach_remove(bs->surfaces, entry) {
65 zink_batch_usage_unset(&surf->batch_uses, bs);
68 set_foreach_remove(bs->bufferviews, entry) {
70 zink_batch_usage_unset(&buffer_view->batch_uses, bs);
74 util_dynarray_foreach(&bs->dead_framebuffers, struct zink_framebuffer*, fb) {
77 util_dynarray_clear(&bs->dead_framebuffers);
78 util_dynarray_foreach(&bs->zombie_samplers, VkSampler, samp) {
81 util_dynarray_clear(&bs->zombie_samplers);
82 util_dynarray_clear(&bs->persistent_resources);
84 screen->batch_descriptor_reset(screen, bs);
86 set_foreach_remove(bs->programs, entry) {
88 zink_batch_usage_unset(&pg->batch_uses, bs);
92 bs->resource_size = 0;
93 bs->signal_semaphore = VK_NULL_HANDLE;
94 while (util_dynarray_contains(&bs->wait_semaphores, VkSemaphore))
95 VKSCR(DestroySemaphore)(screen->dev, util_dynarray_pop(&bs->wait_semaphores, VkSemaphore), NULL);
96 util_dynarray_clear(&bs->wait_semaphore_stages);
98 bs->present = VK_NULL_HANDLE;
99 while (util_dynarray_contains(&bs->acquires, VkSemaphore))
100 VKSCR(DestroySemaphore)(screen->dev, util_dynarray_pop(&bs->acquires, VkSemaphore), NULL);
101 bs->swapchain = NULL;
103 while (util_dynarray_contains(&bs->dead_swapchains, VkImageView))
104 VKSCR(DestroyImageView)(screen->dev, util_dynarray_pop(&bs->dead_swapchains, VkImageView), NULL);
109 bs->fence.submitted = false;
110 bs->has_barriers = false;
111 if (bs->fence.batch_id)
112 zink_screen_update_last_finished(screen, bs->fence.batch_id);
113 bs->submit_count++;
114 bs->fence.batch_id = 0;
115 bs->usage.usage = 0;
116 bs->next = NULL;
120 unref_resources(struct zink_screen *screen, struct zink_batch_state *bs)
122 while (util_dynarray_contains(&bs->unref_resources, struct zink_resource_object*)) {
123 struct zink_resource_object *obj = util_dynarray_pop(&bs->unref_resources, struct zink_resource_object*);
129 zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs)
131 bs->fence.completed = true;
132 zink_reset_batch_state(ctx, bs);
133 unref_resources(zink_screen(ctx->base.screen), bs);
139 const struct zink_batch_state *bs = ctx->batch_states;
140 ctx->batch_states = bs->next;
142 if (ctx->last_fence == &bs->fence)
150 struct zink_batch_state *bs = ctx->batch_states;
151 bs->fence.completed = true;
153 zink_reset_batch_state(ctx, bs);
154 util_dynarray_append(&ctx->free_batch_states, struct zink_batch_state *, bs);
159 zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs)
161 if (!bs)
164 util_queue_fence_destroy(&bs->flush_completed);
166 cnd_destroy(&bs->usage.flush);
167 mtx_destroy(&bs->usage.mtx);
169 if (bs->cmdbuf)
170 VKSCR(FreeCommandBuffers)(screen->dev, bs->cmdpool, 1, &bs->cmdbuf);
171 if (bs->barrier_cmdbuf)
172 VKSCR(FreeCommandBuffers)(screen->dev, bs->cmdpool, 1, &bs->barrier_cmdbuf);
173 if (bs->cmdpool)
174 VKSCR(DestroyCommandPool)(screen->dev, bs->cmdpool, NULL);
176 util_dynarray_fini(&bs->zombie_samplers);
177 util_dynarray_fini(&bs->dead_framebuffers);
178 util_dynarray_fini(&bs->unref_resources);
179 util_dynarray_fini(&bs->bindless_releases[0]);
180 util_dynarray_fini(&bs->bindless_releases[1]);
181 util_dynarray_fini(&bs->acquires);
182 util_dynarray_fini(&bs->acquire_flags);
183 util_dynarray_fini(&bs->dead_swapchains);
184 _mesa_set_destroy(bs->surfaces, NULL);
185 _mesa_set_destroy(bs->bufferviews, NULL);
186 _mesa_set_destroy(bs->programs, NULL);
187 _mesa_set_destroy(bs->active_queries, NULL);
188 screen->batch_descriptor_deinit(screen, bs);
189 ralloc_free(bs);
196 struct zink_batch_state *bs = rzalloc(NULL, struct zink_batch_state);
200 VkResult result = VKSCR(CreateCommandPool)(screen->dev, &cpci, NULL, &bs->cmdpool);
208 cbai.commandPool = bs->cmdpool;
212 result = VKSCR(AllocateCommandBuffers)(screen->dev, &cbai, &bs->cmdbuf);
218 result = VKSCR(AllocateCommandBuffers)(screen->dev, &cbai, &bs->barrier_cmdbuf);
225 ptr = _mesa_pointer_set_create(bs); \
229 bs->ctx = ctx;
231 SET_CREATE_OR_FAIL(bs->resources);
232 SET_CREATE_OR_FAIL(bs->surfaces);
233 SET_CREATE_OR_FAIL(bs->bufferviews);
234 SET_CREATE_OR_FAIL(bs->programs);
235 SET_CREATE_OR_FAIL(bs->active_queries);
236 util_dynarray_init(&bs->wait_semaphores, NULL);
237 util_dynarray_init(&bs->wait_semaphore_stages, NULL);
238 util_dynarray_init(&bs->zombie_samplers, NULL);
239 util_dynarray_init(&bs->dead_framebuffers, NULL);
240 util_dynarray_init(&bs->persistent_resources, NULL);
241 util_dynarray_init(&bs->unref_resources, NULL);
242 util_dynarray_init(&bs->acquires, NULL);
243 util_dynarray_init(&bs->acquire_flags, NULL);
244 util_dynarray_init(&bs->dead_swapchains, NULL);
245 util_dynarray_init(&bs->bindless_releases[0], NULL);
246 util_dynarray_init(&bs->bindless_releases[1], NULL);
248 cnd_init(&bs->usage.flush);
249 mtx_init(&bs->usage.mtx, mtx_plain);
251 if (!screen->batch_descriptor_init(screen, bs))
254 util_queue_fence_init(&bs->flush_completed);
256 return bs;
258 zink_batch_state_destroy(screen, bs);
263 find_unused_state(struct zink_batch_state *bs)
265 struct zink_fence *fence = &bs->fence;
276 struct zink_batch_state *bs = NULL;
279 bs = util_dynarray_pop(&ctx->free_batch_states, struct zink_batch_state*);
280 if (!bs && ctx->batch_states) {
284 bs = ctx->batch_states;
288 if (bs) {
289 zink_reset_batch_state(ctx, bs);
298 bs = create_batch_state(ctx);
300 return bs;
344 struct zink_batch_state *bs = data;
345 struct zink_screen *screen = zink_screen(bs->ctx->base.screen);
347 if (bs->is_device_lost) {
348 if (bs->ctx->reset.reset)
349 bs->ctx->reset.reset(bs->ctx->reset.data, PIPE_GUILTY_CONTEXT_RESET);
354 } else if (bs->ctx->batch_states_count > 5000) {
355 zink_screen_timeline_wait(screen, bs->fence.batch_id - 2500, PIPE_TIMEOUT_INFINITE);
362 struct zink_batch_state *bs = data;
363 struct zink_context *ctx = bs->ctx;
367 while (!bs->fence.batch_id)
368 bs->fence.batch_id = (uint32_t)p_atomic_inc_return(&screen->curr_batch);
369 bs->usage.usage = bs->fence.batch_id;
370 bs->usage.unflushed = false;
372 uint64_t batch_id = bs->fence.batch_id;
375 si[0].waitSemaphoreCount = util_dynarray_num_elements(&bs->acquires, VkSemaphore);
376 si[0].pWaitSemaphores = bs->acquires.data;
377 while (util_dynarray_num_elements(&bs->acquire_flags, VkPipelineStageFlags) < si[0].waitSemaphoreCount) {
379 util_dynarray_append(&bs->acquire_flags, VkPipelineStageFlags, mask);
381 assert(util_dynarray_num_elements(&bs->acquires, VkSemaphore) <= util_dynarray_num_elements(&bs->acquire_flags, VkPipelineStageFlags));
382 si[0].pWaitDstStageMask = bs->acquire_flags.data;
388 si[1].waitSemaphoreCount = util_dynarray_num_elements(&bs->wait_semaphores, VkSemaphore);
389 si[1].pWaitSemaphores = bs->wait_semaphores.data;
390 si[1].pWaitDstStageMask = bs->wait_semaphore_stages.data;
391 si[1].commandBufferCount = bs->has_barriers ? 2 : 1;
393 bs->barrier_cmdbuf,
394 bs->cmdbuf,
396 si[1].pCommandBuffers = bs->has_barriers ? cmdbufs : &cmdbufs[1];
399 si[1].signalSemaphoreCount = !!bs->signal_semaphore;
400 signals[0] = bs->signal_semaphore;
411 if (bs->present)
412 signals[si[1].signalSemaphoreCount++] = bs->present;
415 VkResult result = VKSCR(EndCommandBuffer)(bs->cmdbuf);
418 bs->is_device_lost = true;
421 if (bs->has_barriers) {
422 result = VKSCR(EndCommandBuffer)(bs->barrier_cmdbuf);
425 bs->is_device_lost = true;
430 while (util_dynarray_contains(&bs->persistent_resources, struct zink_resource_object*)) {
431 struct zink_resource_object *obj = util_dynarray_pop(&bs->persistent_resources, struct zink_resource_object*);
444 bs->is_device_lost = true;
447 bs->submit_count++;
449 cnd_broadcast(&bs->usage.flush);
451 p_atomic_set(&bs->fence.submitted, true);
452 unref_resources(screen, bs);
464 struct zink_batch_state *bs;
469 bs = ctx->batch_states;
470 struct zink_fence *fence = &bs->fence;
476 zink_reset_batch_state(ctx, bs);
477 util_dynarray_append(&ctx->free_batch_states, struct zink_batch_state *, bs);
483 bs = batch->state;
485 zink_batch_state(ctx->last_fence)->next = bs;
488 ctx->batch_states = bs;
490 ctx->last_fence = &bs->fence;
506 util_queue_add_job(&screen->flush_queue, bs, &bs->flush_completed,
509 submit_queue(bs, NULL, 0);
510 post_submit(bs, NULL, 0);