mesa/src/vulkan/runtime/vk_semaphore.h
Jason Ekstrand 673b5e97ec vulkan: Add a common implementation of VkSemaphore
This is built on the new vk_sync primitives.  In the vk_physical_device,
the driver provides a null-terminated array of vk_sync_type pointers in
priority order.  The semaphore implementation then selects the first
type that meets the necessary criterion.  In particular, semaphores may
or may not be timelines depending on the VkSemaphoreType.  It also
auto-selects the semaphore type based on the external handle types
provided and can down-grade as needed to support a particular external
handle.

The implementation itself is mostly copy+pasted from ANV.  The primary
difference is the fact that anv_semaphore_impl has been replaced with
vk_sync.  The permanent vk_sync is still embedded (like ANV) but the
temporary one is a pointer.  This makes stealing the temporary state as
part of VkQueueSubmit a bit easier.

All of the interesting stuff around waits, signals, etc. is implemented
by the vk_sync interface.  All this code does is wrap it all in the
annoyingly detailed VkFence rules so we can provide the correct Vulkan
entrypoint behavior.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13427>
2021-11-16 10:54:27 -06:00

78 lines
2.5 KiB
C

/*
* Copyright © 2021 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef VK_SEMAPHORE_H
#define VK_SEMAPHORE_H
#include "vk_object.h"
#include "vk_sync.h"
#ifdef __cplusplus
extern "C" {
#endif
struct vk_sync;
struct vk_semaphore {
struct vk_object_base base;
/** VkSemaphoreTypeCreateInfo::semaphoreType */
VkSemaphoreType type;
/* Temporary semaphore state.
*
* A semaphore *may* have temporary state. That state is added to the
* semaphore by an import operation and is reset back to NULL when the
* semaphore is reset. A semaphore with temporary state cannot be signaled
* because the semaphore must already be signaled before the temporary
* state can be exported from the semaphore in the other process and
* imported here.
*/
struct vk_sync *temporary;
/** Permanent semaphore state.
*
* Every semaphore has some form of permanent state.
*
* This field must be last
*/
_Alignas(8) struct vk_sync permanent;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(vk_semaphore, base, VkSemaphore,
VK_OBJECT_TYPE_SEMAPHORE);
void vk_semaphore_reset_temporary(struct vk_device *device,
struct vk_semaphore *semaphore);
static inline struct vk_sync *
vk_semaphore_get_active_sync(struct vk_semaphore *semaphore)
{
return semaphore->temporary ? semaphore->temporary : &semaphore->permanent;
}
#ifdef __cplusplus
}
#endif
#endif /* VK_SEMAPHORE_H */