mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
c/main: Refactor fence to be more independent
This commit is contained in:
parent
293d617dd5
commit
c6031a26e8
|
@ -124,6 +124,16 @@ compositor_swapchain_import(struct xrt_compositor *xc,
|
|||
return comp_swapchain_import(&c->vk, &c->cscgc, info, native_images, num_images, out_xsc);
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
compositor_import_fence(struct xrt_compositor *xc,
|
||||
xrt_graphics_sync_handle_t handle,
|
||||
struct xrt_compositor_fence **out_xcf)
|
||||
{
|
||||
struct comp_compositor *c = comp_compositor(xc);
|
||||
|
||||
return comp_fence_import(&c->vk, handle, out_xcf);
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type type)
|
||||
{
|
||||
|
@ -1425,7 +1435,7 @@ xrt_gfx_provider_create_system(struct xrt_device *xdev, struct xrt_system_compos
|
|||
|
||||
c->base.base.create_swapchain = compositor_swapchain_create;
|
||||
c->base.base.import_swapchain = compositor_swapchain_import;
|
||||
c->base.base.import_fence = comp_compositor_import_fence;
|
||||
c->base.base.import_fence = compositor_import_fence;
|
||||
c->base.base.begin_session = compositor_begin_session;
|
||||
c->base.base.end_session = compositor_end_session;
|
||||
c->base.base.predict_frame = compositor_predict_frame;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "vk/vk_image_allocator.h"
|
||||
|
||||
#include "main/comp_sync.h"
|
||||
#include "main/comp_settings.h"
|
||||
#include "main/comp_swapchain.h"
|
||||
#include "main/comp_window.h"
|
||||
|
@ -210,14 +211,6 @@ comp_compositor(struct xrt_compositor *xc)
|
|||
return (struct comp_compositor *)xc;
|
||||
}
|
||||
|
||||
/*!
|
||||
* For importing fences, defined in comp_sync.c .
|
||||
*/
|
||||
xrt_result_t
|
||||
comp_compositor_import_fence(struct xrt_compositor *xc,
|
||||
xrt_graphics_sync_handle_t handle,
|
||||
struct xrt_compositor_fence **out_xcf);
|
||||
|
||||
/*!
|
||||
* Spew level logging.
|
||||
*
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Sync code for the main compositor.
|
||||
* @brief Independent @ref xrt_compositor_fence implementation.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @ingroup comp_main
|
||||
*/
|
||||
|
||||
#include "xrt/xrt_config_os.h"
|
||||
|
||||
#include "main/comp_sync.h"
|
||||
|
||||
#include "util/u_misc.h"
|
||||
#include "util/u_handles.h"
|
||||
|
||||
#include "main/comp_compositor.h"
|
||||
|
||||
#include <xrt/xrt_handles.h>
|
||||
#include <xrt/xrt_config_os.h>
|
||||
#include "util/u_trace_marker.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -23,22 +23,23 @@
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
struct fence
|
||||
{
|
||||
struct xrt_compositor_fence base;
|
||||
struct comp_compositor *c;
|
||||
|
||||
VkFence fence;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Helper functions.
|
||||
* Structs.
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* A very simple implementation of a fence primitive.
|
||||
*/
|
||||
struct fence
|
||||
{
|
||||
struct xrt_compositor_fence base;
|
||||
|
||||
struct vk_bundle *vk;
|
||||
|
||||
VkFence fence;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
@ -53,7 +54,7 @@ fence_wait(struct xrt_compositor_fence *xcf, uint64_t timeout)
|
|||
COMP_TRACE_MARKER();
|
||||
|
||||
struct fence *f = (struct fence *)xcf;
|
||||
struct vk_bundle *vk = &f->c->vk;
|
||||
struct vk_bundle *vk = f->vk;
|
||||
|
||||
// Count no handle as signled fence.
|
||||
if (f->fence == VK_NULL_HANDLE) {
|
||||
|
@ -65,7 +66,7 @@ fence_wait(struct xrt_compositor_fence *xcf, uint64_t timeout)
|
|||
return XRT_SUCCESS;
|
||||
}
|
||||
if (ret != VK_SUCCESS) {
|
||||
COMP_ERROR(f->c, "vkWaitForFences: %s", vk_result_string(ret));
|
||||
VK_ERROR(vk, "vkWaitForFences: %s", vk_result_string(ret));
|
||||
return XRT_ERROR_VULKAN;
|
||||
}
|
||||
|
||||
|
@ -78,7 +79,7 @@ fence_destroy(struct xrt_compositor_fence *xcf)
|
|||
COMP_TRACE_MARKER();
|
||||
|
||||
struct fence *f = (struct fence *)xcf;
|
||||
struct vk_bundle *vk = &f->c->vk;
|
||||
struct vk_bundle *vk = f->vk;
|
||||
|
||||
if (f->fence != VK_NULL_HANDLE) {
|
||||
vk->vkDestroyFence(vk->device, f->fence, NULL);
|
||||
|
@ -91,20 +92,15 @@ fence_destroy(struct xrt_compositor_fence *xcf)
|
|||
|
||||
/*
|
||||
*
|
||||
* Compositor function.
|
||||
* 'Exported' function.
|
||||
*
|
||||
*/
|
||||
|
||||
xrt_result_t
|
||||
comp_compositor_import_fence(struct xrt_compositor *xc,
|
||||
xrt_graphics_sync_handle_t handle,
|
||||
struct xrt_compositor_fence **out_xcf)
|
||||
comp_fence_import(struct vk_bundle *vk, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
|
||||
struct comp_compositor *c = comp_compositor(xc);
|
||||
struct vk_bundle *vk = &c->vk;
|
||||
|
||||
VkFence fence = VK_NULL_HANDLE;
|
||||
|
||||
VkResult ret = vk_create_fence_sync_from_native(vk, handle, &fence);
|
||||
|
@ -116,7 +112,7 @@ comp_compositor_import_fence(struct xrt_compositor *xc,
|
|||
f->base.wait = fence_wait;
|
||||
f->base.destroy = fence_destroy;
|
||||
f->fence = fence;
|
||||
f->c = c;
|
||||
f->vk = vk;
|
||||
|
||||
*out_xcf = &f->base;
|
||||
|
||||
|
|
35
src/xrt/compositor/main/comp_sync.h
Normal file
35
src/xrt/compositor/main/comp_sync.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2019-2021, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Independent @ref xrt_compositor_fence implementation.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @ingroup comp_main
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xrt/xrt_handles.h"
|
||||
#include "xrt/xrt_compositor.h"
|
||||
#include "vk/vk_helpers.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
* For importing @ref xrt_graphics_sync_handle_t and turn them into a @ref xrt_compositor_fence.
|
||||
*
|
||||
* The vk_bundle is owned by the compositor, its the state trackers job to make
|
||||
* sure that compositor lives for as long as the fence does and that all fences
|
||||
* are destroyed before the compositor is destroyed.
|
||||
*/
|
||||
xrt_result_t
|
||||
comp_fence_import(struct vk_bundle *vk, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue