Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_batch.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_BATCH_H
25
#define ZINK_BATCH_H
26
27
#include <vulkan/vulkan.h>
28
29
#include "util/list.h"
30
#include "util/set.h"
31
#include "util/u_dynarray.h"
32
33
#include "zink_fence.h"
34
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
39
struct pipe_reference;
40
41
struct zink_buffer_view;
42
struct zink_context;
43
struct zink_descriptor_set;
44
struct zink_framebuffer;
45
struct zink_image_view;
46
struct zink_program;
47
struct zink_render_pass;
48
struct zink_resource;
49
struct zink_sampler_view;
50
struct zink_surface;
51
52
struct zink_batch_usage {
53
uint32_t usage;
54
cnd_t flush;
55
mtx_t mtx;
56
bool unflushed;
57
};
58
59
/* not real api don't use */
60
bool
61
batch_ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr);
62
63
struct zink_batch_state {
64
struct zink_fence fence;
65
struct pipe_reference reference;
66
unsigned draw_count;
67
68
struct zink_batch_usage usage;
69
struct zink_context *ctx;
70
VkCommandPool cmdpool;
71
VkCommandBuffer cmdbuf;
72
VkCommandBuffer barrier_cmdbuf;
73
74
VkQueue queue; //duplicated from batch for threading
75
VkSemaphore sem;
76
77
struct util_queue_fence flush_completed;
78
unsigned compute_count;
79
80
struct pipe_resource *flush_res;
81
82
struct set *fbs;
83
struct set *programs;
84
85
struct set *resources;
86
struct set *surfaces;
87
struct set *bufferviews;
88
89
struct util_dynarray persistent_resources;
90
struct util_dynarray zombie_samplers;
91
92
struct set *active_queries; /* zink_query objects which were active at some point in this batch */
93
94
struct zink_batch_descriptor_data *dd;
95
96
VkDeviceSize resource_size;
97
98
/* this is a monotonic int used to disambiguate internal fences from their tc fence references */
99
unsigned submit_count;
100
101
bool is_device_lost;
102
bool have_timelines;
103
bool has_barriers;
104
bool scanout_flush;
105
};
106
107
struct zink_batch {
108
struct zink_batch_state *state;
109
110
struct zink_batch_usage *last_batch_usage;
111
112
bool has_work;
113
bool in_rp; //renderpass is currently active
114
};
115
116
117
static inline struct zink_batch_state *
118
zink_batch_state(struct zink_fence *fence)
119
{
120
return (struct zink_batch_state *)fence;
121
}
122
123
void
124
zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
125
126
void
127
zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
128
129
void
130
zink_batch_reset_all(struct zink_context *ctx);
131
132
void
133
zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs);
134
135
void
136
zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs);
137
138
void
139
zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch);
140
void
141
zink_batch_reference_framebuffer(struct zink_batch *batch,
142
struct zink_framebuffer *fb);
143
void
144
zink_start_batch(struct zink_context *ctx, struct zink_batch *batch);
145
146
void
147
zink_end_batch(struct zink_context *ctx, struct zink_batch *batch);
148
149
void
150
zink_batch_resource_usage_set(struct zink_batch *batch, struct zink_resource *res, bool write);
151
152
void
153
zink_batch_reference_resource_rw(struct zink_batch *batch,
154
struct zink_resource *res,
155
bool write);
156
void
157
zink_batch_reference_resource(struct zink_batch *batch, struct zink_resource *res);
158
159
void
160
zink_batch_reference_resource_move(struct zink_batch *batch, struct zink_resource *res);
161
162
void
163
zink_batch_reference_sampler_view(struct zink_batch *batch,
164
struct zink_sampler_view *sv);
165
166
void
167
zink_batch_reference_program(struct zink_batch *batch,
168
struct zink_program *pg);
169
170
void
171
zink_batch_reference_image_view(struct zink_batch *batch,
172
struct zink_image_view *image_view);
173
174
void
175
zink_batch_reference_bufferview(struct zink_batch *batch, struct zink_buffer_view *buffer_view);
176
void
177
zink_batch_reference_surface(struct zink_batch *batch, struct zink_surface *surface);
178
179
void
180
debug_describe_zink_batch_state(char *buf, const struct zink_batch_state *ptr);
181
182
static inline void
183
zink_batch_state_reference(struct zink_screen *screen,
184
struct zink_batch_state **dst,
185
struct zink_batch_state *src)
186
{
187
struct zink_batch_state *old_dst = dst ? *dst : NULL;
188
189
if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, src ? &src->reference : NULL,
190
(debug_reference_descriptor)debug_describe_zink_batch_state))
191
zink_batch_state_destroy(screen, old_dst);
192
if (dst) *dst = src;
193
}
194
195
static inline bool
196
zink_batch_usage_is_unflushed(const struct zink_batch_usage *u)
197
{
198
return u && u->unflushed;
199
}
200
201
static inline void
202
zink_batch_usage_unset(struct zink_batch_usage **u, struct zink_batch_state *bs)
203
{
204
(void)p_atomic_cmpxchg((uintptr_t *)u, (uintptr_t)&bs->usage, (uintptr_t)NULL);
205
}
206
207
static inline void
208
zink_batch_usage_set(struct zink_batch_usage **u, struct zink_batch_state *bs)
209
{
210
*u = &bs->usage;
211
}
212
213
static inline bool
214
zink_batch_usage_matches(const struct zink_batch_usage *u, const struct zink_batch_state *bs)
215
{
216
return u == &bs->usage;
217
}
218
219
static inline bool
220
zink_batch_usage_exists(const struct zink_batch_usage *u)
221
{
222
return u && (u->usage || u->unflushed);
223
}
224
225
bool
226
zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);
227
228
void
229
zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u);
230
231
#ifdef __cplusplus
232
}
233
#endif
234
235
#endif
236
237