1 /*
2 * Copyright © 2021 Intel Corporation
3 *
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
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
13 * Software.
14 *
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #ifndef VK_FENCE_H
24 #define VK_FENCE_H
25
26 #include "vk_object.h"
27 #include "vk_sync.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 struct vk_sync;
34
35 struct vk_fence {
36 struct vk_object_base base;
37
38 /* Temporary fence state.
39 *
40 * A fence *may* have temporary state. That state is added to the fence by
41 * an import operation and is reset back to NULL when the fence is reset.
42 * A fence with temporary state cannot be signaled because the fence must
43 * already be signaled before the temporary state can be exported from the
44 * fence in the other process and imported here.
45 */
46 struct vk_sync *temporary;
47
48 /** Permanent fence state.
49 *
50 * Every fence has some form of permanent state.
51 *
52 * This field must be last
53 */
54 alignas(8) struct vk_sync permanent;
55 };
56
57 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_fence, base, VkFence,
58 VK_OBJECT_TYPE_FENCE);
59
60 VkResult vk_fence_create(struct vk_device *device,
61 const VkFenceCreateInfo *pCreateInfo,
62 const VkAllocationCallbacks *pAllocator,
63 struct vk_fence **fence_out);
64
65 void vk_fence_destroy(struct vk_device *device,
66 struct vk_fence *fence,
67 const VkAllocationCallbacks *pAllocator);
68
69 void vk_fence_reset_temporary(struct vk_device *device,
70 struct vk_fence *fence);
71
72 static inline struct vk_sync *
vk_fence_get_active_sync(struct vk_fence * fence)73 vk_fence_get_active_sync(struct vk_fence *fence)
74 {
75 return fence->temporary ? fence->temporary : &fence->permanent;
76 }
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif /* VK_FENCE_H */
83