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_fence.h"
26 #include "zink_screen.h"
28 #include "util/u_memory.h"
31 destroy_fence(struct zink_screen
*screen
, struct zink_fence
*fence
)
34 vkDestroyFence(screen
->dev
, fence
->fence
, NULL
);
39 zink_create_fence(struct pipe_screen
*pscreen
)
41 struct zink_screen
*screen
= zink_screen(pscreen
);
43 VkFenceCreateInfo fci
= {};
44 fci
.sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
;
46 struct zink_fence
*ret
= CALLOC_STRUCT(zink_fence
);
48 debug_printf("CALLOC_STRUCT failed\n");
52 if (vkCreateFence(screen
->dev
, &fci
, NULL
, &ret
->fence
) != VK_SUCCESS
) {
53 debug_printf("vkCreateFence failed\n");
57 pipe_reference_init(&ret
->reference
, 1);
61 destroy_fence(screen
, ret
);
66 zink_fence_reference(struct zink_screen
*screen
,
67 struct zink_fence
**ptr
,
68 struct zink_fence
*fence
)
70 if (pipe_reference(&(*ptr
)->reference
, &fence
->reference
))
71 destroy_fence(screen
, *ptr
);
77 fence_reference(struct pipe_screen
*pscreen
,
78 struct pipe_fence_handle
**pptr
,
79 struct pipe_fence_handle
*pfence
)
81 zink_fence_reference(zink_screen(pscreen
), (struct zink_fence
**)pptr
,
86 zink_fence_finish(struct zink_screen
*screen
, struct zink_fence
*fence
,
89 return vkWaitForFences(screen
->dev
, 1, &fence
->fence
, VK_TRUE
,
90 timeout_ns
) == VK_SUCCESS
;
94 fence_finish(struct pipe_screen
*pscreen
, struct pipe_context
*pctx
,
95 struct pipe_fence_handle
*pfence
, uint64_t timeout_ns
)
97 return zink_fence_finish(zink_screen(pscreen
), zink_fence(pfence
),
102 zink_screen_fence_init(struct pipe_screen
*pscreen
)
104 pscreen
->fence_reference
= fence_reference
;
105 pscreen
->fence_finish
= fence_finish
;