Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/virtio/vulkan/vn_device.h
4560 views
1
/*
2
* Copyright 2019 Google LLC
3
* SPDX-License-Identifier: MIT
4
*
5
* based in part on anv and radv which are:
6
* Copyright © 2015 Intel Corporation
7
* Copyright © 2016 Red Hat.
8
* Copyright © 2016 Bas Nieuwenhuizen
9
*/
10
11
#ifndef VN_DEVICE_H
12
#define VN_DEVICE_H
13
14
#include "vn_common.h"
15
16
#include "venus-protocol/vn_protocol_driver_defines.h"
17
18
#include "vn_cs.h"
19
#include "vn_device_memory.h"
20
#include "vn_renderer.h"
21
#include "vn_ring.h"
22
#include "vn_wsi.h"
23
24
struct vn_instance {
25
struct vn_instance_base base;
26
27
struct driOptionCache dri_options;
28
struct driOptionCache available_dri_options;
29
30
struct vn_renderer *renderer;
31
struct vn_renderer_info renderer_info;
32
33
/* Between the driver and the app, VN_MAX_API_VERSION is what we advertise
34
* and base.base.app_info.api_version is what the app requests.
35
*
36
* Between the driver and the renderer, renderer_api_version is the api
37
* version we request internally, which can be higher than
38
* base.base.app_info.api_version. renderer_version is the instance
39
* version we can use internally.
40
*/
41
uint32_t renderer_api_version;
42
uint32_t renderer_version;
43
44
/* to synchronize renderer/ring */
45
mtx_t roundtrip_mutex;
46
uint32_t roundtrip_next;
47
48
struct {
49
mtx_t mutex;
50
struct vn_renderer_shmem *shmem;
51
struct vn_ring ring;
52
uint64_t id;
53
54
struct vn_cs_encoder upload;
55
uint32_t command_dropped;
56
} ring;
57
58
struct {
59
struct vn_renderer_shmem *shmem;
60
size_t size;
61
size_t used;
62
void *ptr;
63
} reply;
64
65
mtx_t physical_device_mutex;
66
struct vn_physical_device *physical_devices;
67
uint32_t physical_device_count;
68
69
/* XXX staged features to be merged to core venus protocol */
70
VkVenusExperimentalFeatures100000MESA experimental;
71
};
72
VK_DEFINE_HANDLE_CASTS(vn_instance,
73
base.base.base,
74
VkInstance,
75
VK_OBJECT_TYPE_INSTANCE)
76
77
struct vn_physical_device {
78
struct vn_physical_device_base base;
79
80
struct vn_instance *instance;
81
82
/* Between the driver and the app, properties.properties.apiVersion is what
83
* we advertise and is capped by VN_MAX_API_VERSION and others.
84
*
85
* Between the driver and the renderer, renderer_version is the device
86
* version we can use internally.
87
*/
88
uint32_t renderer_version;
89
90
/* Between the driver and the app, base.base.supported_extensions is what
91
* we advertise.
92
*
93
* Between the driver and the renderer, renderer_extensions is what we can
94
* use internally (after enabling).
95
*/
96
struct vk_device_extension_table renderer_extensions;
97
uint32_t *extension_spec_versions;
98
99
VkPhysicalDeviceFeatures2 features;
100
VkPhysicalDeviceVulkan11Features vulkan_1_1_features;
101
VkPhysicalDeviceVulkan12Features vulkan_1_2_features;
102
VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback_features;
103
104
VkPhysicalDeviceProperties2 properties;
105
VkPhysicalDeviceVulkan11Properties vulkan_1_1_properties;
106
VkPhysicalDeviceVulkan12Properties vulkan_1_2_properties;
107
VkPhysicalDeviceTransformFeedbackPropertiesEXT
108
transform_feedback_properties;
109
110
VkQueueFamilyProperties2 *queue_family_properties;
111
uint32_t queue_family_count;
112
113
VkPhysicalDeviceMemoryProperties2 memory_properties;
114
115
struct {
116
VkExternalMemoryHandleTypeFlagBits renderer_handle_type;
117
VkExternalMemoryHandleTypeFlags supported_handle_types;
118
} external_memory;
119
120
VkExternalFenceHandleTypeFlags external_fence_handles;
121
VkExternalSemaphoreHandleTypeFlags external_binary_semaphore_handles;
122
VkExternalSemaphoreHandleTypeFlags external_timeline_semaphore_handles;
123
124
struct wsi_device wsi_device;
125
};
126
VK_DEFINE_HANDLE_CASTS(vn_physical_device,
127
base.base.base,
128
VkPhysicalDevice,
129
VK_OBJECT_TYPE_PHYSICAL_DEVICE)
130
131
struct vn_device {
132
struct vn_device_base base;
133
134
struct vn_instance *instance;
135
struct vn_physical_device *physical_device;
136
struct vn_renderer *renderer;
137
138
struct vn_queue *queues;
139
uint32_t queue_count;
140
141
struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES];
142
143
/* cache memory type requirement for AHB backed VkBuffer */
144
uint32_t ahb_buffer_memory_type_bits;
145
};
146
VK_DEFINE_HANDLE_CASTS(vn_device,
147
base.base.base,
148
VkDevice,
149
VK_OBJECT_TYPE_DEVICE)
150
151
VkResult
152
vn_instance_submit_roundtrip(struct vn_instance *instance,
153
uint32_t *roundtrip_seqno);
154
155
void
156
vn_instance_wait_roundtrip(struct vn_instance *instance,
157
uint32_t roundtrip_seqno);
158
159
static inline void
160
vn_instance_roundtrip(struct vn_instance *instance)
161
{
162
uint32_t roundtrip_seqno;
163
if (vn_instance_submit_roundtrip(instance, &roundtrip_seqno) == VK_SUCCESS)
164
vn_instance_wait_roundtrip(instance, roundtrip_seqno);
165
}
166
167
VkResult
168
vn_instance_ring_submit(struct vn_instance *instance,
169
const struct vn_cs_encoder *cs);
170
171
struct vn_instance_submit_command {
172
/* empty command implies errors */
173
struct vn_cs_encoder command;
174
struct vn_cs_encoder_buffer buffer;
175
/* non-zero implies waiting */
176
size_t reply_size;
177
178
/* when reply_size is non-zero, NULL can be returned on errors */
179
struct vn_renderer_shmem *reply_shmem;
180
struct vn_cs_decoder reply;
181
};
182
183
static inline struct vn_cs_encoder *
184
vn_instance_submit_command_init(struct vn_instance *instance,
185
struct vn_instance_submit_command *submit,
186
void *cmd_data,
187
size_t cmd_size,
188
size_t reply_size)
189
{
190
submit->command = VN_CS_ENCODER_INITIALIZER_LOCAL(cmd_data, cmd_size);
191
/* fix submit->command.buffers to not point to a local variable */
192
submit->buffer = submit->command.buffers[0];
193
submit->command.buffers = &submit->buffer;
194
195
submit->reply_size = reply_size;
196
submit->reply_shmem = NULL;
197
198
return &submit->command;
199
}
200
201
void
202
vn_instance_submit_command(struct vn_instance *instance,
203
struct vn_instance_submit_command *submit);
204
205
static inline struct vn_cs_decoder *
206
vn_instance_get_command_reply(struct vn_instance *instance,
207
struct vn_instance_submit_command *submit)
208
{
209
return submit->reply_shmem ? &submit->reply : NULL;
210
}
211
212
static inline void
213
vn_instance_free_command_reply(struct vn_instance *instance,
214
struct vn_instance_submit_command *submit)
215
{
216
assert(submit->reply_shmem);
217
vn_renderer_shmem_unref(instance->renderer, submit->reply_shmem);
218
}
219
220
#endif /* VN_DEVICE_H */
221
222