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_SEMAPHORE_H
24 #define VK_SEMAPHORE_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_semaphore {
36    struct vk_object_base base;
37 
38    /** VkSemaphoreTypeCreateInfo::semaphoreType */
39    VkSemaphoreType type;
40 
41    /* Temporary semaphore state.
42     *
43     * A semaphore *may* have temporary state.  That state is added to the
44     * semaphore by an import operation and is reset back to NULL when the
45     * semaphore is reset.  A semaphore with temporary state cannot be signaled
46     * because the semaphore must already be signaled before the temporary
47     * state can be exported from the semaphore in the other process and
48     * imported here.
49     */
50    struct vk_sync *temporary;
51 
52    /** Permanent semaphore state.
53     *
54     * Every semaphore has some form of permanent state.
55     *
56     * This field must be last
57     */
58    alignas(8) struct vk_sync permanent;
59 };
60 
61 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_semaphore, base, VkSemaphore,
62                                VK_OBJECT_TYPE_SEMAPHORE);
63 
64 void vk_semaphore_reset_temporary(struct vk_device *device,
65                                   struct vk_semaphore *semaphore);
66 
67 static inline struct vk_sync *
vk_semaphore_get_active_sync(struct vk_semaphore * semaphore)68 vk_semaphore_get_active_sync(struct vk_semaphore *semaphore)
69 {
70    return semaphore->temporary ? semaphore->temporary : &semaphore->permanent;
71 }
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /* VK_SEMAPHORE_H */
78 
79