2021-07-30 11:07:55 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
* based in part on anv and radv which are:
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
* Copyright © 2016 Red Hat.
|
|
|
|
|
* Copyright © 2016 Bas Nieuwenhuizen
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef VN_INSTANCE_H
|
|
|
|
|
#define VN_INSTANCE_H
|
|
|
|
|
|
|
|
|
|
#include "vn_common.h"
|
|
|
|
|
|
|
|
|
|
#include "venus-protocol/vn_protocol_driver_defines.h"
|
|
|
|
|
|
|
|
|
|
#include "vn_cs.h"
|
|
|
|
|
#include "vn_renderer.h"
|
2021-12-09 14:12:01 -08:00
|
|
|
#include "vn_renderer_util.h"
|
2021-07-30 11:07:55 -07:00
|
|
|
|
2021-07-30 11:17:56 -07:00
|
|
|
/* require and request at least Vulkan 1.1 at both instance and device levels
|
|
|
|
|
*/
|
|
|
|
|
#define VN_MIN_RENDERER_VERSION VK_API_VERSION_1_1
|
|
|
|
|
|
|
|
|
|
/* max advertised version at both instance and device levels */
|
2023-09-07 19:08:17 +01:00
|
|
|
#if defined(ANDROID_STRICT) && ANDROID_API_LEVEL < 33
|
2021-07-30 11:17:56 -07:00
|
|
|
#define VN_MAX_API_VERSION VK_MAKE_VERSION(1, 1, VK_HEADER_VERSION)
|
|
|
|
|
#else
|
2022-10-11 21:09:19 -07:00
|
|
|
#define VN_MAX_API_VERSION VK_MAKE_VERSION(1, 3, VK_HEADER_VERSION)
|
2021-07-30 11:17:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
2021-07-30 11:07:55 -07:00
|
|
|
struct vn_instance {
|
|
|
|
|
struct vn_instance_base base;
|
|
|
|
|
|
|
|
|
|
struct driOptionCache dri_options;
|
|
|
|
|
struct driOptionCache available_dri_options;
|
2023-11-08 11:27:09 -08:00
|
|
|
bool enable_wsi_multi_plane_modifiers;
|
2021-07-30 11:07:55 -07:00
|
|
|
|
|
|
|
|
struct vn_renderer *renderer;
|
|
|
|
|
|
2023-11-05 18:10:07 -08:00
|
|
|
/* for VN_CS_ENCODER_STORAGE_SHMEM_POOL */
|
2023-11-07 20:05:36 -08:00
|
|
|
struct vn_renderer_shmem_pool cs_shmem_pool;
|
2023-11-05 18:10:07 -08:00
|
|
|
|
2021-12-09 17:08:15 -08:00
|
|
|
struct vn_renderer_shmem_pool reply_shmem_pool;
|
|
|
|
|
|
2022-11-09 14:37:10 -08:00
|
|
|
mtx_t ring_idx_mutex;
|
|
|
|
|
uint64_t ring_idx_used_mask;
|
|
|
|
|
|
2021-07-30 11:07:55 -07:00
|
|
|
struct {
|
2023-11-06 12:33:22 -08:00
|
|
|
struct vn_ring *ring;
|
2023-12-27 16:57:25 -08:00
|
|
|
struct list_head tls_rings;
|
2021-08-29 21:56:15 -07:00
|
|
|
|
|
|
|
|
/* to synchronize renderer/ring */
|
|
|
|
|
mtx_t roundtrip_mutex;
|
2023-03-12 20:24:55 -07:00
|
|
|
uint64_t roundtrip_next;
|
2023-11-05 19:16:04 -08:00
|
|
|
|
2023-11-06 11:24:40 -08:00
|
|
|
struct vn_watchdog watchdog;
|
2021-07-30 11:07:55 -07:00
|
|
|
} ring;
|
|
|
|
|
|
2021-08-29 21:58:57 -07:00
|
|
|
/* Between the driver and the app, VN_MAX_API_VERSION is what we advertise
|
|
|
|
|
* and base.base.app_info.api_version is what the app requests.
|
|
|
|
|
*
|
|
|
|
|
* Between the driver and the renderer, renderer_api_version is the api
|
|
|
|
|
* version we request internally, which can be higher than
|
|
|
|
|
* base.base.app_info.api_version. renderer_version is the instance
|
|
|
|
|
* version we can use internally.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t renderer_api_version;
|
|
|
|
|
uint32_t renderer_version;
|
|
|
|
|
|
2021-08-31 12:16:16 -07:00
|
|
|
struct {
|
|
|
|
|
mtx_t mutex;
|
2021-08-31 12:28:20 -07:00
|
|
|
bool initialized;
|
2021-08-31 12:16:16 -07:00
|
|
|
|
|
|
|
|
struct vn_physical_device *devices;
|
|
|
|
|
uint32_t device_count;
|
|
|
|
|
VkPhysicalDeviceGroupProperties *groups;
|
|
|
|
|
uint32_t group_count;
|
|
|
|
|
} physical_device;
|
2021-07-30 11:07:55 -07:00
|
|
|
};
|
|
|
|
|
VK_DEFINE_HANDLE_CASTS(vn_instance,
|
|
|
|
|
base.base.base,
|
|
|
|
|
VkInstance,
|
|
|
|
|
VK_OBJECT_TYPE_INSTANCE)
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
vn_instance_submit_roundtrip(struct vn_instance *instance,
|
2023-03-12 20:24:55 -07:00
|
|
|
uint64_t *roundtrip_seqno);
|
2021-07-30 11:07:55 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
vn_instance_wait_roundtrip(struct vn_instance *instance,
|
2023-03-12 20:24:55 -07:00
|
|
|
uint64_t roundtrip_seqno);
|
2021-07-30 11:07:55 -07:00
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vn_instance_roundtrip(struct vn_instance *instance)
|
|
|
|
|
{
|
2023-03-12 20:24:55 -07:00
|
|
|
uint64_t roundtrip_seqno;
|
2021-07-30 11:07:55 -07:00
|
|
|
if (vn_instance_submit_roundtrip(instance, &roundtrip_seqno) == VK_SUCCESS)
|
|
|
|
|
vn_instance_wait_roundtrip(instance, roundtrip_seqno);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 15:55:12 -08:00
|
|
|
static inline struct vn_renderer_shmem *
|
|
|
|
|
vn_instance_cs_shmem_alloc(struct vn_instance *instance,
|
|
|
|
|
size_t size,
|
|
|
|
|
size_t *out_offset)
|
|
|
|
|
{
|
2023-11-07 20:05:36 -08:00
|
|
|
return vn_renderer_shmem_pool_alloc(
|
|
|
|
|
instance->renderer, &instance->cs_shmem_pool, size, out_offset);
|
2021-12-08 15:55:12 -08:00
|
|
|
}
|
|
|
|
|
|
2023-11-08 22:48:24 -08:00
|
|
|
static inline struct vn_renderer_shmem *
|
|
|
|
|
vn_instance_reply_shmem_alloc(struct vn_instance *instance,
|
|
|
|
|
size_t size,
|
|
|
|
|
size_t *out_offset)
|
|
|
|
|
{
|
|
|
|
|
return vn_renderer_shmem_pool_alloc(
|
|
|
|
|
instance->renderer, &instance->reply_shmem_pool, size, out_offset);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-09 14:37:10 -08:00
|
|
|
static inline int
|
|
|
|
|
vn_instance_acquire_ring_idx(struct vn_instance *instance)
|
|
|
|
|
{
|
|
|
|
|
mtx_lock(&instance->ring_idx_mutex);
|
|
|
|
|
int ring_idx = ffsll(~instance->ring_idx_used_mask) - 1;
|
2022-12-14 13:34:47 -08:00
|
|
|
if (ring_idx >= instance->renderer->info.max_timeline_count)
|
2022-11-09 14:37:10 -08:00
|
|
|
ring_idx = -1;
|
|
|
|
|
if (ring_idx > 0)
|
|
|
|
|
instance->ring_idx_used_mask |= (1ULL << (uint32_t)ring_idx);
|
|
|
|
|
mtx_unlock(&instance->ring_idx_mutex);
|
|
|
|
|
|
|
|
|
|
assert(ring_idx); /* never acquire the dedicated CPU ring */
|
|
|
|
|
|
|
|
|
|
/* returns -1 when no vacant rings */
|
|
|
|
|
return ring_idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vn_instance_release_ring_idx(struct vn_instance *instance, uint32_t ring_idx)
|
|
|
|
|
{
|
|
|
|
|
assert(ring_idx > 0);
|
|
|
|
|
|
|
|
|
|
mtx_lock(&instance->ring_idx_mutex);
|
|
|
|
|
assert(instance->ring_idx_used_mask & (1ULL << ring_idx));
|
|
|
|
|
instance->ring_idx_used_mask &= ~(1ULL << ring_idx);
|
|
|
|
|
mtx_unlock(&instance->ring_idx_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-30 11:07:55 -07:00
|
|
|
#endif /* VN_INSTANCE_H */
|