Path: blob/21.2-virgl/src/virtio/vulkan/vn_device.h
4560 views
/*1* Copyright 2019 Google LLC2* SPDX-License-Identifier: MIT3*4* based in part on anv and radv which are:5* Copyright © 2015 Intel Corporation6* Copyright © 2016 Red Hat.7* Copyright © 2016 Bas Nieuwenhuizen8*/910#ifndef VN_DEVICE_H11#define VN_DEVICE_H1213#include "vn_common.h"1415#include "venus-protocol/vn_protocol_driver_defines.h"1617#include "vn_cs.h"18#include "vn_device_memory.h"19#include "vn_renderer.h"20#include "vn_ring.h"21#include "vn_wsi.h"2223struct vn_instance {24struct vn_instance_base base;2526struct driOptionCache dri_options;27struct driOptionCache available_dri_options;2829struct vn_renderer *renderer;30struct vn_renderer_info renderer_info;3132/* Between the driver and the app, VN_MAX_API_VERSION is what we advertise33* and base.base.app_info.api_version is what the app requests.34*35* Between the driver and the renderer, renderer_api_version is the api36* version we request internally, which can be higher than37* base.base.app_info.api_version. renderer_version is the instance38* version we can use internally.39*/40uint32_t renderer_api_version;41uint32_t renderer_version;4243/* to synchronize renderer/ring */44mtx_t roundtrip_mutex;45uint32_t roundtrip_next;4647struct {48mtx_t mutex;49struct vn_renderer_shmem *shmem;50struct vn_ring ring;51uint64_t id;5253struct vn_cs_encoder upload;54uint32_t command_dropped;55} ring;5657struct {58struct vn_renderer_shmem *shmem;59size_t size;60size_t used;61void *ptr;62} reply;6364mtx_t physical_device_mutex;65struct vn_physical_device *physical_devices;66uint32_t physical_device_count;6768/* XXX staged features to be merged to core venus protocol */69VkVenusExperimentalFeatures100000MESA experimental;70};71VK_DEFINE_HANDLE_CASTS(vn_instance,72base.base.base,73VkInstance,74VK_OBJECT_TYPE_INSTANCE)7576struct vn_physical_device {77struct vn_physical_device_base base;7879struct vn_instance *instance;8081/* Between the driver and the app, properties.properties.apiVersion is what82* we advertise and is capped by VN_MAX_API_VERSION and others.83*84* Between the driver and the renderer, renderer_version is the device85* version we can use internally.86*/87uint32_t renderer_version;8889/* Between the driver and the app, base.base.supported_extensions is what90* we advertise.91*92* Between the driver and the renderer, renderer_extensions is what we can93* use internally (after enabling).94*/95struct vk_device_extension_table renderer_extensions;96uint32_t *extension_spec_versions;9798VkPhysicalDeviceFeatures2 features;99VkPhysicalDeviceVulkan11Features vulkan_1_1_features;100VkPhysicalDeviceVulkan12Features vulkan_1_2_features;101VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback_features;102103VkPhysicalDeviceProperties2 properties;104VkPhysicalDeviceVulkan11Properties vulkan_1_1_properties;105VkPhysicalDeviceVulkan12Properties vulkan_1_2_properties;106VkPhysicalDeviceTransformFeedbackPropertiesEXT107transform_feedback_properties;108109VkQueueFamilyProperties2 *queue_family_properties;110uint32_t queue_family_count;111112VkPhysicalDeviceMemoryProperties2 memory_properties;113114struct {115VkExternalMemoryHandleTypeFlagBits renderer_handle_type;116VkExternalMemoryHandleTypeFlags supported_handle_types;117} external_memory;118119VkExternalFenceHandleTypeFlags external_fence_handles;120VkExternalSemaphoreHandleTypeFlags external_binary_semaphore_handles;121VkExternalSemaphoreHandleTypeFlags external_timeline_semaphore_handles;122123struct wsi_device wsi_device;124};125VK_DEFINE_HANDLE_CASTS(vn_physical_device,126base.base.base,127VkPhysicalDevice,128VK_OBJECT_TYPE_PHYSICAL_DEVICE)129130struct vn_device {131struct vn_device_base base;132133struct vn_instance *instance;134struct vn_physical_device *physical_device;135struct vn_renderer *renderer;136137struct vn_queue *queues;138uint32_t queue_count;139140struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES];141142/* cache memory type requirement for AHB backed VkBuffer */143uint32_t ahb_buffer_memory_type_bits;144};145VK_DEFINE_HANDLE_CASTS(vn_device,146base.base.base,147VkDevice,148VK_OBJECT_TYPE_DEVICE)149150VkResult151vn_instance_submit_roundtrip(struct vn_instance *instance,152uint32_t *roundtrip_seqno);153154void155vn_instance_wait_roundtrip(struct vn_instance *instance,156uint32_t roundtrip_seqno);157158static inline void159vn_instance_roundtrip(struct vn_instance *instance)160{161uint32_t roundtrip_seqno;162if (vn_instance_submit_roundtrip(instance, &roundtrip_seqno) == VK_SUCCESS)163vn_instance_wait_roundtrip(instance, roundtrip_seqno);164}165166VkResult167vn_instance_ring_submit(struct vn_instance *instance,168const struct vn_cs_encoder *cs);169170struct vn_instance_submit_command {171/* empty command implies errors */172struct vn_cs_encoder command;173struct vn_cs_encoder_buffer buffer;174/* non-zero implies waiting */175size_t reply_size;176177/* when reply_size is non-zero, NULL can be returned on errors */178struct vn_renderer_shmem *reply_shmem;179struct vn_cs_decoder reply;180};181182static inline struct vn_cs_encoder *183vn_instance_submit_command_init(struct vn_instance *instance,184struct vn_instance_submit_command *submit,185void *cmd_data,186size_t cmd_size,187size_t reply_size)188{189submit->command = VN_CS_ENCODER_INITIALIZER_LOCAL(cmd_data, cmd_size);190/* fix submit->command.buffers to not point to a local variable */191submit->buffer = submit->command.buffers[0];192submit->command.buffers = &submit->buffer;193194submit->reply_size = reply_size;195submit->reply_shmem = NULL;196197return &submit->command;198}199200void201vn_instance_submit_command(struct vn_instance *instance,202struct vn_instance_submit_command *submit);203204static inline struct vn_cs_decoder *205vn_instance_get_command_reply(struct vn_instance *instance,206struct vn_instance_submit_command *submit)207{208return submit->reply_shmem ? &submit->reply : NULL;209}210211static inline void212vn_instance_free_command_reply(struct vn_instance *instance,213struct vn_instance_submit_command *submit)214{215assert(submit->reply_shmem);216vn_renderer_shmem_unref(instance->renderer, submit->reply_shmem);217}218219#endif /* VN_DEVICE_H */220221222