Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_screen.h
4570 views
1
/*
2
* Copyright 2018 Collabora Ltd.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* on the rights to use, copy, modify, merge, publish, distribute, sub
8
* license, and/or sell copies of the Software, and to permit persons to whom
9
* the Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
* USE OR OTHER DEALINGS IN THE SOFTWARE.
22
*/
23
24
#ifndef ZINK_SCREEN_H
25
#define ZINK_SCREEN_H
26
27
#include "zink_device_info.h"
28
#include "zink_instance.h"
29
#include "vk_dispatch_table.h"
30
31
#include "util/u_idalloc.h"
32
#include "pipe/p_screen.h"
33
#include "util/slab.h"
34
#include "compiler/nir/nir.h"
35
#include "util/disk_cache.h"
36
#include "util/log.h"
37
#include "util/simple_mtx.h"
38
#include "util/u_queue.h"
39
#include "util/u_live_shader_cache.h"
40
41
#include <vulkan/vulkan.h>
42
43
extern uint32_t zink_debug;
44
struct hash_table;
45
46
struct zink_batch_state;
47
struct zink_context;
48
struct zink_descriptor_layout_key;
49
struct zink_program;
50
struct zink_shader;
51
enum zink_descriptor_type;
52
53
#define ZINK_DEBUG_NIR 0x1
54
#define ZINK_DEBUG_SPIRV 0x2
55
#define ZINK_DEBUG_TGSI 0x4
56
#define ZINK_DEBUG_VALIDATION 0x8
57
58
enum zink_descriptor_mode {
59
ZINK_DESCRIPTOR_MODE_AUTO,
60
ZINK_DESCRIPTOR_MODE_LAZY,
61
ZINK_DESCRIPTOR_MODE_NOTEMPLATES,
62
};
63
64
struct zink_modifier_prop {
65
uint32_t drmFormatModifierCount;
66
VkDrmFormatModifierPropertiesEXT* pDrmFormatModifierProperties;
67
};
68
69
struct zink_screen {
70
struct pipe_screen base;
71
bool threaded;
72
uint32_t curr_batch; //the current batch id
73
uint32_t last_finished; //this is racy but ultimately doesn't matter
74
VkSemaphore sem;
75
VkSemaphore prev_sem;
76
struct util_queue flush_queue;
77
78
bool device_lost;
79
struct sw_winsys *winsys;
80
81
struct hash_table framebuffer_cache;
82
simple_mtx_t framebuffer_mtx;
83
struct hash_table surface_cache;
84
simple_mtx_t surface_mtx;
85
struct hash_table bufferview_cache;
86
simple_mtx_t bufferview_mtx;
87
88
struct slab_parent_pool transfer_pool;
89
struct disk_cache *disk_cache;
90
struct util_queue cache_put_thread;
91
struct util_queue cache_get_thread;
92
93
struct util_live_shader_cache shaders;
94
95
simple_mtx_t mem_cache_mtx;
96
struct hash_table *resource_mem_cache;
97
uint64_t mem_cache_size;
98
unsigned mem_cache_count;
99
100
uint64_t total_video_mem;
101
uint64_t total_mem;
102
103
VkInstance instance;
104
struct zink_instance_info instance_info;
105
106
VkPhysicalDevice pdev;
107
uint32_t vk_version, spirv_version;
108
struct util_idalloc_mt buffer_ids;
109
110
struct zink_device_info info;
111
struct nir_shader_compiler_options nir_options;
112
113
bool have_X8_D24_UNORM_PACK32;
114
bool have_D24_UNORM_S8_UINT;
115
bool have_triangle_fans;
116
117
uint32_t gfx_queue;
118
uint32_t max_queues;
119
uint32_t timestamp_valid_bits;
120
VkDevice dev;
121
VkQueue queue; //gfx+compute
122
VkQueue thread_queue; //gfx+compute
123
VkDebugUtilsMessengerEXT debugUtilsCallbackHandle;
124
125
uint32_t cur_custom_border_color_samplers;
126
127
bool needs_mesa_wsi;
128
bool needs_mesa_flush_wsi;
129
130
struct vk_dispatch_table vk;
131
132
bool (*descriptor_program_init)(struct zink_context *ctx, struct zink_program *pg);
133
void (*descriptor_program_deinit)(struct zink_screen *screen, struct zink_program *pg);
134
void (*descriptors_update)(struct zink_context *ctx, bool is_compute);
135
void (*context_update_descriptor_states)(struct zink_context *ctx, bool is_compute);
136
void (*context_invalidate_descriptor_state)(struct zink_context *ctx, enum pipe_shader_type shader,
137
enum zink_descriptor_type type,
138
unsigned start, unsigned count);
139
bool (*batch_descriptor_init)(struct zink_screen *screen, struct zink_batch_state *bs);
140
void (*batch_descriptor_reset)(struct zink_screen *screen, struct zink_batch_state *bs);
141
void (*batch_descriptor_deinit)(struct zink_screen *screen, struct zink_batch_state *bs);
142
bool (*descriptors_init)(struct zink_context *ctx);
143
void (*descriptors_deinit)(struct zink_context *ctx);
144
enum zink_descriptor_mode descriptor_mode;
145
146
struct {
147
bool dual_color_blend_by_location;
148
bool inline_uniforms;
149
} driconf;
150
151
VkFormatProperties format_props[PIPE_FORMAT_COUNT];
152
struct zink_modifier_prop modifier_props[PIPE_FORMAT_COUNT];
153
struct {
154
uint32_t image_view;
155
uint32_t buffer_view;
156
} null_descriptor_hashes;
157
158
VkExtent2D maxSampleLocationGridSize[5];
159
};
160
161
162
/* update last_finished to account for batch_id wrapping */
163
static inline void
164
zink_screen_update_last_finished(struct zink_screen *screen, uint32_t batch_id)
165
{
166
/* last_finished may have wrapped */
167
if (screen->last_finished < UINT_MAX / 2) {
168
/* last_finished has wrapped, batch_id has not */
169
if (batch_id > UINT_MAX / 2)
170
return;
171
} else if (batch_id < UINT_MAX / 2) {
172
/* batch_id has wrapped, last_finished has not */
173
screen->last_finished = batch_id;
174
return;
175
}
176
/* neither have wrapped */
177
screen->last_finished = MAX2(batch_id, screen->last_finished);
178
}
179
180
/* check a batch_id against last_finished while accounting for wrapping */
181
static inline bool
182
zink_screen_check_last_finished(struct zink_screen *screen, uint32_t batch_id)
183
{
184
/* last_finished may have wrapped */
185
if (screen->last_finished < UINT_MAX / 2) {
186
/* last_finished has wrapped, batch_id has not */
187
if (batch_id > UINT_MAX / 2)
188
return true;
189
} else if (batch_id < UINT_MAX / 2) {
190
/* batch_id has wrapped, last_finished has not */
191
return false;
192
}
193
return screen->last_finished >= batch_id;
194
}
195
196
bool
197
zink_screen_init_semaphore(struct zink_screen *screen);
198
199
static inline bool
200
zink_screen_handle_vkresult(struct zink_screen *screen, VkResult ret)
201
{
202
bool success = false;
203
switch (ret) {
204
case VK_SUCCESS:
205
success = true;
206
break;
207
case VK_ERROR_DEVICE_LOST:
208
screen->device_lost = true;
209
FALLTHROUGH;
210
default:
211
success = false;
212
break;
213
}
214
return success;
215
}
216
217
static inline struct zink_screen *
218
zink_screen(struct pipe_screen *pipe)
219
{
220
return (struct zink_screen *)pipe;
221
}
222
223
224
struct mem_cache_entry {
225
VkDeviceMemory mem;
226
void *map;
227
};
228
229
VkFormat
230
zink_get_format(struct zink_screen *screen, enum pipe_format format);
231
232
bool
233
zink_screen_batch_id_wait(struct zink_screen *screen, uint32_t batch_id, uint64_t timeout);
234
235
bool
236
zink_screen_timeline_wait(struct zink_screen *screen, uint32_t batch_id, uint64_t timeout);
237
238
bool
239
zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format);
240
241
#define GET_PROC_ADDR_INSTANCE_LOCAL(instance, x) PFN_vk##x vk_##x = (PFN_vk##x)vkGetInstanceProcAddr(instance, "vk"#x)
242
243
void
244
zink_screen_update_pipeline_cache(struct zink_screen *screen, struct zink_program *pg);
245
246
void
247
zink_screen_get_pipeline_cache(struct zink_screen *screen, struct zink_program *pg);
248
249
void
250
zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback);
251
252
void
253
zink_stub_function_not_loaded(void);
254
#endif
255
256