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
|
|
|
#include "vn_ring.h"
|
|
|
|
|
|
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 */
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
|
#define VN_MAX_API_VERSION VK_MAKE_VERSION(1, 1, VK_HEADER_VERSION)
|
|
|
|
|
#else
|
|
|
|
|
#define VN_MAX_API_VERSION VK_MAKE_VERSION(1, 2, VK_HEADER_VERSION)
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
struct vn_renderer *renderer;
|
|
|
|
|
struct vn_renderer_info renderer_info;
|
|
|
|
|
|
2021-08-29 22:02:16 -07:00
|
|
|
/* XXX staged features to be merged to core venus protocol */
|
|
|
|
|
VkVenusExperimentalFeatures100000MESA experimental;
|
|
|
|
|
|
2021-07-30 11:07:55 -07:00
|
|
|
struct {
|
|
|
|
|
mtx_t mutex;
|
|
|
|
|
struct vn_renderer_shmem *shmem;
|
|
|
|
|
struct vn_ring ring;
|
|
|
|
|
uint64_t id;
|
|
|
|
|
|
|
|
|
|
struct vn_cs_encoder upload;
|
|
|
|
|
uint32_t command_dropped;
|
2021-08-29 21:56:15 -07:00
|
|
|
|
|
|
|
|
/* to synchronize renderer/ring */
|
|
|
|
|
mtx_t roundtrip_mutex;
|
|
|
|
|
uint32_t roundtrip_next;
|
2021-07-30 11:07:55 -07:00
|
|
|
} ring;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
struct vn_renderer_shmem *shmem;
|
|
|
|
|
size_t size;
|
|
|
|
|
size_t used;
|
|
|
|
|
void *ptr;
|
|
|
|
|
} reply;
|
|
|
|
|
|
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,
|
|
|
|
|
uint32_t *roundtrip_seqno);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
vn_instance_wait_roundtrip(struct vn_instance *instance,
|
|
|
|
|
uint32_t roundtrip_seqno);
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vn_instance_roundtrip(struct vn_instance *instance)
|
|
|
|
|
{
|
|
|
|
|
uint32_t roundtrip_seqno;
|
|
|
|
|
if (vn_instance_submit_roundtrip(instance, &roundtrip_seqno) == VK_SUCCESS)
|
|
|
|
|
vn_instance_wait_roundtrip(instance, roundtrip_seqno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
vn_instance_ring_submit(struct vn_instance *instance,
|
|
|
|
|
const struct vn_cs_encoder *cs);
|
|
|
|
|
|
|
|
|
|
struct vn_instance_submit_command {
|
|
|
|
|
/* empty command implies errors */
|
|
|
|
|
struct vn_cs_encoder command;
|
|
|
|
|
struct vn_cs_encoder_buffer buffer;
|
|
|
|
|
/* non-zero implies waiting */
|
|
|
|
|
size_t reply_size;
|
|
|
|
|
|
|
|
|
|
/* when reply_size is non-zero, NULL can be returned on errors */
|
|
|
|
|
struct vn_renderer_shmem *reply_shmem;
|
|
|
|
|
struct vn_cs_decoder reply;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline struct vn_cs_encoder *
|
|
|
|
|
vn_instance_submit_command_init(struct vn_instance *instance,
|
|
|
|
|
struct vn_instance_submit_command *submit,
|
|
|
|
|
void *cmd_data,
|
|
|
|
|
size_t cmd_size,
|
|
|
|
|
size_t reply_size)
|
|
|
|
|
{
|
2021-08-30 09:37:08 -07:00
|
|
|
submit->buffer = VN_CS_ENCODER_BUFFER_INITIALIZER(cmd_data);
|
|
|
|
|
submit->command = VN_CS_ENCODER_INITIALIZER(&submit->buffer, cmd_size);
|
2021-07-30 11:07:55 -07:00
|
|
|
|
|
|
|
|
submit->reply_size = reply_size;
|
|
|
|
|
submit->reply_shmem = NULL;
|
|
|
|
|
|
|
|
|
|
return &submit->command;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
vn_instance_submit_command(struct vn_instance *instance,
|
|
|
|
|
struct vn_instance_submit_command *submit);
|
|
|
|
|
|
|
|
|
|
static inline struct vn_cs_decoder *
|
|
|
|
|
vn_instance_get_command_reply(struct vn_instance *instance,
|
|
|
|
|
struct vn_instance_submit_command *submit)
|
|
|
|
|
{
|
|
|
|
|
return submit->reply_shmem ? &submit->reply : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
vn_instance_free_command_reply(struct vn_instance *instance,
|
|
|
|
|
struct vn_instance_submit_command *submit)
|
|
|
|
|
{
|
|
|
|
|
assert(submit->reply_shmem);
|
|
|
|
|
vn_renderer_shmem_unref(instance->renderer, submit->reply_shmem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* VN_INSTANCE_H */
|