2 * Copyright 2018 Collabora Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include "zink_batch.h"
25 #include "zink_fence.h"
27 #include "zink_query.h"
28 #include "zink_screen.h"
30 #include "util/u_memory.h"
33 destroy_fence(struct zink_screen
*screen
, struct zink_fence
*fence
)
36 vkDestroyFence(screen
->dev
, fence
->fence
, NULL
);
41 zink_create_fence(struct pipe_screen
*pscreen
, struct zink_batch
*batch
)
43 struct zink_screen
*screen
= zink_screen(pscreen
);
45 VkFenceCreateInfo fci
= {};
46 fci
.sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
;
48 struct zink_fence
*ret
= CALLOC_STRUCT(zink_fence
);
50 debug_printf("CALLOC_STRUCT failed\n");
54 if (vkCreateFence(screen
->dev
, &fci
, NULL
, &ret
->fence
) != VK_SUCCESS
) {
55 debug_printf("vkCreateFence failed\n");
58 ret
->active_queries
= batch
->active_queries
;
59 batch
->active_queries
= NULL
;
61 pipe_reference_init(&ret
->reference
, 1);
65 destroy_fence(screen
, ret
);
70 zink_fence_reference(struct zink_screen
*screen
,
71 struct zink_fence
**ptr
,
72 struct zink_fence
*fence
)
74 if (pipe_reference(&(*ptr
)->reference
, &fence
->reference
))
75 destroy_fence(screen
, *ptr
);
81 fence_reference(struct pipe_screen
*pscreen
,
82 struct pipe_fence_handle
**pptr
,
83 struct pipe_fence_handle
*pfence
)
85 zink_fence_reference(zink_screen(pscreen
), (struct zink_fence
**)pptr
,
90 zink_fence_finish(struct zink_screen
*screen
, struct zink_fence
*fence
,
93 bool success
= vkWaitForFences(screen
->dev
, 1, &fence
->fence
, VK_TRUE
,
94 timeout_ns
) == VK_SUCCESS
;
95 if (success
&& fence
->active_queries
)
96 zink_prune_queries(screen
, fence
);
101 fence_finish(struct pipe_screen
*pscreen
, struct pipe_context
*pctx
,
102 struct pipe_fence_handle
*pfence
, uint64_t timeout_ns
)
104 return zink_fence_finish(zink_screen(pscreen
), zink_fence(pfence
),
109 zink_screen_fence_init(struct pipe_screen
*pscreen
)
111 pscreen
->fence_reference
= fence_reference
;
112 pscreen
->fence_finish
= fence_finish
;