Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/panfrost/pan_context.h
4570 views
1
/*
2
* © Copyright 2018 Alyssa Rosenzweig
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
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
*/
24
25
#ifndef __BUILDER_H__
26
#define __BUILDER_H__
27
28
#define _LARGEFILE64_SOURCE 1
29
#define CACHE_LINE_SIZE 1024 /* TODO */
30
#include <sys/mman.h>
31
#include <assert.h>
32
#include "pan_resource.h"
33
#include "pan_job.h"
34
#include "pan_blend_cso.h"
35
#include "pan_encoder.h"
36
#include "pan_texture.h"
37
38
#include "pipe/p_compiler.h"
39
#include "pipe/p_config.h"
40
#include "pipe/p_context.h"
41
#include "pipe/p_defines.h"
42
#include "pipe/p_format.h"
43
#include "pipe/p_screen.h"
44
#include "pipe/p_state.h"
45
#include "util/u_blitter.h"
46
#include "util/hash_table.h"
47
48
#include "midgard/midgard_compile.h"
49
#include "compiler/shader_enums.h"
50
51
/* Forward declare to avoid extra header dep */
52
struct prim_convert_context;
53
54
#define SET_BIT(lval, bit, cond) \
55
if (cond) \
56
lval |= (bit); \
57
else \
58
lval &= ~(bit);
59
60
/* Dirty tracking flags. 3D is for general 3D state. Shader flags are
61
* per-stage. Renderer refers to Renderer State Descriptors. Vertex refers to
62
* vertex attributes/elements. */
63
64
enum pan_dirty_3d {
65
PAN_DIRTY_VIEWPORT = BITFIELD_BIT(0),
66
PAN_DIRTY_SCISSOR = BITFIELD_BIT(1),
67
PAN_DIRTY_VERTEX = BITFIELD_BIT(2),
68
PAN_DIRTY_PARAMS = BITFIELD_BIT(3),
69
PAN_DIRTY_DRAWID = BITFIELD_BIT(4),
70
PAN_DIRTY_TLS_SIZE = BITFIELD_BIT(5),
71
};
72
73
enum pan_dirty_shader {
74
PAN_DIRTY_STAGE_RENDERER = BITFIELD_BIT(0),
75
PAN_DIRTY_STAGE_TEXTURE = BITFIELD_BIT(1),
76
PAN_DIRTY_STAGE_SAMPLER = BITFIELD_BIT(2),
77
PAN_DIRTY_STAGE_IMAGE = BITFIELD_BIT(3),
78
PAN_DIRTY_STAGE_CONST = BITFIELD_BIT(4),
79
PAN_DIRTY_STAGE_SSBO = BITFIELD_BIT(5),
80
};
81
82
struct panfrost_constant_buffer {
83
struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
84
uint32_t enabled_mask;
85
};
86
87
struct panfrost_query {
88
/* Passthrough from Gallium */
89
unsigned type;
90
unsigned index;
91
92
/* For computed queries. 64-bit to prevent overflow */
93
struct {
94
uint64_t start;
95
uint64_t end;
96
};
97
98
/* Memory for the GPU to writeback the value of the query */
99
struct pipe_resource *rsrc;
100
101
/* Whether an occlusion query is for a MSAA framebuffer */
102
bool msaa;
103
};
104
105
struct pipe_fence_handle {
106
struct pipe_reference reference;
107
uint32_t syncobj;
108
bool signaled;
109
};
110
111
struct panfrost_streamout_target {
112
struct pipe_stream_output_target base;
113
uint32_t offset;
114
};
115
116
struct panfrost_streamout {
117
struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
118
unsigned num_targets;
119
};
120
121
struct panfrost_context {
122
/* Gallium context */
123
struct pipe_context base;
124
125
/* Dirty global state */
126
enum pan_dirty_3d dirty;
127
128
/* Per shader stage dirty state */
129
enum pan_dirty_shader dirty_shader[PIPE_SHADER_TYPES];
130
131
/* Unowned pools, so manage yourself. */
132
struct panfrost_pool descs, shaders;
133
134
/* Sync obj used to keep track of in-flight jobs. */
135
uint32_t syncobj;
136
137
/* Set of 32 batches. When the set is full, the LRU entry (the batch
138
* with the smallest seqnum) is flushed to free a slot.
139
*/
140
struct {
141
uint64_t seqnum;
142
struct panfrost_batch slots[PAN_MAX_BATCHES];
143
} batches;
144
145
/* Bound job batch */
146
struct panfrost_batch *batch;
147
148
/* Within a launch_grid call.. */
149
const struct pipe_grid_info *compute_grid;
150
151
/* Bit mask for supported PIPE_DRAW for this hardware */
152
unsigned draw_modes;
153
154
struct pipe_framebuffer_state pipe_framebuffer;
155
struct panfrost_streamout streamout;
156
157
bool active_queries;
158
uint64_t prims_generated;
159
uint64_t tf_prims_generated;
160
struct panfrost_query *occlusion_query;
161
162
bool indirect_draw;
163
unsigned drawid;
164
unsigned vertex_count;
165
unsigned instance_count;
166
unsigned offset_start;
167
unsigned base_vertex;
168
unsigned base_instance;
169
mali_ptr first_vertex_sysval_ptr;
170
mali_ptr base_vertex_sysval_ptr;
171
mali_ptr base_instance_sysval_ptr;
172
enum pipe_prim_type active_prim;
173
174
/* If instancing is enabled, vertex count padded for instance; if
175
* it is disabled, just equal to plain vertex count */
176
unsigned padded_count;
177
178
/* TODO: Multiple uniform buffers (index =/= 0), finer updates? */
179
180
struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES];
181
182
struct panfrost_rasterizer *rasterizer;
183
struct panfrost_shader_variants *shader[PIPE_SHADER_TYPES];
184
struct panfrost_vertex_state *vertex;
185
186
struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
187
uint32_t vb_mask;
188
189
struct pipe_shader_buffer ssbo[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
190
uint32_t ssbo_mask[PIPE_SHADER_TYPES];
191
192
struct pipe_image_view images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
193
uint32_t image_mask[PIPE_SHADER_TYPES];
194
195
struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
196
unsigned sampler_count[PIPE_SHADER_TYPES];
197
198
struct panfrost_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
199
unsigned sampler_view_count[PIPE_SHADER_TYPES];
200
201
struct primconvert_context *primconvert;
202
struct blitter_context *blitter;
203
204
struct panfrost_blend_state *blend;
205
206
struct pipe_viewport_state pipe_viewport;
207
struct pipe_scissor_state scissor;
208
struct pipe_blend_color blend_color;
209
struct panfrost_zsa_state *depth_stencil;
210
struct pipe_stencil_ref stencil_ref;
211
uint16_t sample_mask;
212
unsigned min_samples;
213
214
struct panfrost_query *cond_query;
215
bool cond_cond;
216
enum pipe_render_cond_flag cond_mode;
217
218
bool is_noop;
219
220
/* Mask of active render targets */
221
uint8_t fb_rt_mask;
222
};
223
224
/* Corresponds to the CSO */
225
226
struct panfrost_rasterizer {
227
struct pipe_rasterizer_state base;
228
229
/* Partially packed RSD words */
230
struct mali_multisample_misc_packed multisample;
231
struct mali_stencil_mask_misc_packed stencil_misc;
232
};
233
234
/* Linked varyings */
235
struct pan_linkage {
236
/* If the upload is owned by the CSO instead
237
* of the pool, the referenced BO. Else,
238
* NULL. */
239
struct panfrost_bo *bo;
240
241
/* Uploaded attribute descriptors */
242
mali_ptr producer, consumer;
243
244
/* Varyings buffers required */
245
uint32_t present;
246
247
/* Per-vertex stride for general varying buffer */
248
uint32_t stride;
249
};
250
251
/* Variants bundle together to form the backing CSO, bundling multiple
252
* shaders with varying emulated features baked in */
253
254
/* A shader state corresponds to the actual, current variant of the shader */
255
struct panfrost_shader_state {
256
/* Compiled, mapped descriptor, ready for the hardware */
257
bool compiled;
258
259
/* Respectively, shader binary and Renderer State Descriptor */
260
struct panfrost_pool_ref bin, state;
261
262
/* For fragment shaders, a prepared (but not uploaded RSD) */
263
struct mali_renderer_state_packed partial_rsd;
264
265
struct pan_shader_info info;
266
267
/* Linked varyings, for non-separable programs */
268
struct pan_linkage linkage;
269
270
struct pipe_stream_output_info stream_output;
271
uint64_t so_mask;
272
273
/* Variants */
274
enum pipe_format rt_formats[8];
275
unsigned nr_cbufs;
276
277
/* Mask of state that dirties the sysvals */
278
unsigned dirty_3d, dirty_shader;
279
};
280
281
/* A collection of varyings (the CSO) */
282
struct panfrost_shader_variants {
283
/* A panfrost_shader_variants can represent a shader for
284
* either graphics or compute */
285
286
bool is_compute;
287
288
union {
289
struct pipe_shader_state base;
290
struct pipe_compute_state cbase;
291
};
292
293
struct panfrost_shader_state *variants;
294
unsigned variant_space;
295
296
unsigned variant_count;
297
298
/* The current active variant */
299
unsigned active_variant;
300
};
301
302
struct pan_vertex_buffer {
303
unsigned vbi;
304
unsigned divisor;
305
};
306
307
struct panfrost_vertex_state {
308
unsigned num_elements;
309
310
/* buffers corresponds to attribute buffer, element_buffers corresponds
311
* to an index in buffers for each vertex element */
312
struct pan_vertex_buffer buffers[PIPE_MAX_ATTRIBS];
313
unsigned element_buffer[PIPE_MAX_ATTRIBS];
314
unsigned nr_bufs;
315
316
struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
317
unsigned formats[PIPE_MAX_ATTRIBS];
318
};
319
320
struct panfrost_zsa_state {
321
struct pipe_depth_stencil_alpha_state base;
322
323
/* Is any depth, stencil, or alpha testing enabled? */
324
bool enabled;
325
326
/* Mask of PIPE_CLEAR_{DEPTH,STENCIL} written */
327
unsigned draws;
328
329
/* Prepacked words from the RSD */
330
struct mali_multisample_misc_packed rsd_depth;
331
struct mali_stencil_mask_misc_packed rsd_stencil;
332
struct mali_stencil_packed stencil_front, stencil_back;
333
};
334
335
struct panfrost_sampler_state {
336
struct pipe_sampler_state base;
337
struct mali_midgard_sampler_packed hw;
338
};
339
340
/* Misnomer: Sampler view corresponds to textures, not samplers */
341
342
struct panfrost_sampler_view {
343
struct pipe_sampler_view base;
344
struct panfrost_pool_ref state;
345
struct mali_bifrost_texture_packed bifrost_descriptor;
346
mali_ptr texture_bo;
347
uint64_t modifier;
348
};
349
350
static inline struct panfrost_context *
351
pan_context(struct pipe_context *pcontext)
352
{
353
return (struct panfrost_context *) pcontext;
354
}
355
356
static inline struct panfrost_streamout_target *
357
pan_so_target(struct pipe_stream_output_target *target)
358
{
359
return (struct panfrost_streamout_target *)target;
360
}
361
362
static inline struct panfrost_shader_state *
363
panfrost_get_shader_state(struct panfrost_context *ctx,
364
enum pipe_shader_type st)
365
{
366
struct panfrost_shader_variants *all = ctx->shader[st];
367
368
if (!all)
369
return NULL;
370
371
return &all->variants[all->active_variant];
372
}
373
374
struct pipe_context *
375
panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags);
376
377
bool
378
panfrost_writes_point_size(struct panfrost_context *ctx);
379
380
struct panfrost_ptr
381
panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler);
382
383
void
384
panfrost_flush(
385
struct pipe_context *pipe,
386
struct pipe_fence_handle **fence,
387
unsigned flags);
388
389
bool
390
panfrost_render_condition_check(struct panfrost_context *ctx);
391
392
void
393
panfrost_shader_compile(struct pipe_screen *pscreen,
394
struct panfrost_pool *shader_pool,
395
struct panfrost_pool *desc_pool,
396
enum pipe_shader_ir ir_type,
397
const void *ir,
398
gl_shader_stage stage,
399
struct panfrost_shader_state *state);
400
401
void
402
panfrost_analyze_sysvals(struct panfrost_shader_state *ss);
403
404
void
405
panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so,
406
struct pipe_context *pctx,
407
struct pipe_resource *texture);
408
409
/* Instancing */
410
411
mali_ptr
412
panfrost_vertex_buffer_address(struct panfrost_context *ctx, unsigned i);
413
414
/* Compute */
415
416
void
417
panfrost_compute_context_init(struct pipe_context *pctx);
418
419
static inline void
420
panfrost_dirty_state_all(struct panfrost_context *ctx)
421
{
422
ctx->dirty = ~0;
423
424
for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i)
425
ctx->dirty_shader[i] = ~0;
426
}
427
428
static inline void
429
panfrost_clean_state_3d(struct panfrost_context *ctx)
430
{
431
ctx->dirty = 0;
432
433
for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) {
434
if (i != PIPE_SHADER_COMPUTE)
435
ctx->dirty_shader[i] = 0;
436
}
437
}
438
439
void
440
panfrost_cmdstream_context_init(struct pipe_context *pipe);
441
442
#endif
443
444