Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/lib/pan_device.h
4560 views
1
/**************************************************************************
2
*
3
* Copyright 2018-2019 Alyssa Rosenzweig
4
* Copyright 2018-2019 Collabora, Ltd.
5
* Copyright © 2015 Intel Corporation
6
* All Rights Reserved.
7
*
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the
10
* "Software"), to deal in the Software without restriction, including
11
* without limitation the rights to use, copy, modify, merge, publish,
12
* distribute, sub license, and/or sell copies of the Software, and to
13
* permit persons to whom the Software is furnished to do so, subject to
14
* the following conditions:
15
*
16
* The above copyright notice and this permission notice (including the
17
* next paragraph) shall be included in all copies or substantial portions
18
* of the Software.
19
*
20
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
*
28
**************************************************************************/
29
30
#ifndef PAN_DEVICE_H
31
#define PAN_DEVICE_H
32
33
#include <xf86drm.h>
34
#include "renderonly/renderonly.h"
35
#include "util/u_dynarray.h"
36
#include "util/bitset.h"
37
#include "util/list.h"
38
#include "util/sparse_array.h"
39
40
#include "panfrost/util/pan_ir.h"
41
#include "pan_pool.h"
42
#include "pan_util.h"
43
44
#include <midgard_pack.h>
45
46
#if defined(__cplusplus)
47
extern "C" {
48
#endif
49
50
/* Driver limits */
51
#define PAN_MAX_CONST_BUFFERS 16
52
53
/* How many power-of-two levels in the BO cache do we want? 2^12
54
* minimum chosen as it is the page size that all allocations are
55
* rounded to */
56
57
#define MIN_BO_CACHE_BUCKET (12) /* 2^12 = 4KB */
58
#define MAX_BO_CACHE_BUCKET (22) /* 2^22 = 4MB */
59
60
/* Fencepost problem, hence the off-by-one */
61
#define NR_BO_CACHE_BUCKETS (MAX_BO_CACHE_BUCKET - MIN_BO_CACHE_BUCKET + 1)
62
63
struct pan_blitter {
64
struct {
65
struct pan_pool *pool;
66
struct hash_table *blit;
67
struct hash_table *blend;
68
pthread_mutex_t lock;
69
} shaders;
70
struct {
71
struct pan_pool *pool;
72
struct hash_table *rsds;
73
pthread_mutex_t lock;
74
} rsds;
75
};
76
77
struct pan_blend_shaders {
78
struct hash_table *shaders;
79
pthread_mutex_t lock;
80
};
81
82
enum pan_indirect_draw_flags {
83
PAN_INDIRECT_DRAW_NO_INDEX = 0 << 0,
84
PAN_INDIRECT_DRAW_1B_INDEX = 1 << 0,
85
PAN_INDIRECT_DRAW_2B_INDEX = 2 << 0,
86
PAN_INDIRECT_DRAW_4B_INDEX = 3 << 0,
87
PAN_INDIRECT_DRAW_INDEX_SIZE_MASK = 3 << 0,
88
PAN_INDIRECT_DRAW_HAS_PSIZ = 1 << 2,
89
PAN_INDIRECT_DRAW_PRIMITIVE_RESTART = 1 << 3,
90
PAN_INDIRECT_DRAW_UPDATE_PRIM_SIZE = 1 << 4,
91
PAN_INDIRECT_DRAW_LAST_FLAG = PAN_INDIRECT_DRAW_UPDATE_PRIM_SIZE,
92
PAN_INDIRECT_DRAW_FLAGS_MASK = (PAN_INDIRECT_DRAW_LAST_FLAG << 1) - 1,
93
PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_1B_INDEX = PAN_INDIRECT_DRAW_LAST_FLAG << 1,
94
PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_2B_INDEX,
95
PAN_INDIRECT_DRAW_MIN_MAX_SEARCH_4B_INDEX,
96
PAN_INDIRECT_DRAW_NUM_SHADERS,
97
};
98
99
struct pan_indirect_draw_shader {
100
struct panfrost_ubo_push push;
101
mali_ptr rsd;
102
};
103
104
struct pan_indirect_draw_shaders {
105
struct pan_indirect_draw_shader shaders[PAN_INDIRECT_DRAW_NUM_SHADERS];
106
107
/* Take the lock when initializing the draw shaders context or when
108
* allocating from the binary pool.
109
*/
110
pthread_mutex_t lock;
111
112
/* A memory pool for shader binaries. We currently don't allocate a
113
* single BO for all shaders up-front because estimating shader size
114
* is not trivial, and changes to the compiler might influence this
115
* estimation.
116
*/
117
struct pan_pool *bin_pool;
118
119
/* BO containing all renderer states attached to the compute shaders.
120
* Those are built at shader compilation time and re-used every time
121
* panfrost_emit_indirect_draw() is called.
122
*/
123
struct panfrost_bo *states;
124
125
/* Varying memory is allocated dynamically by compute jobs from this
126
* heap.
127
*/
128
struct panfrost_bo *varying_heap;
129
};
130
131
struct pan_indirect_dispatch {
132
struct panfrost_ubo_push push;
133
struct panfrost_bo *bin;
134
struct panfrost_bo *descs;
135
};
136
137
/** Implementation-defined tiler features */
138
struct panfrost_tiler_features {
139
/** Number of bytes per tiler bin */
140
unsigned bin_size;
141
142
/** Maximum number of levels that may be simultaneously enabled.
143
* Invariant: bitcount(hierarchy_mask) <= max_levels */
144
unsigned max_levels;
145
};
146
147
struct panfrost_device {
148
/* For ralloc */
149
void *memctx;
150
151
int fd;
152
153
/* Properties of the GPU in use */
154
unsigned arch;
155
unsigned gpu_id;
156
unsigned core_count;
157
unsigned thread_tls_alloc;
158
struct panfrost_tiler_features tiler_features;
159
unsigned quirks;
160
161
/* Table of formats, indexed by a PIPE format */
162
const struct panfrost_format *formats;
163
164
/* Bitmask of supported compressed texture formats */
165
uint32_t compressed_formats;
166
167
/* debug flags, see pan_util.h how to interpret */
168
unsigned debug;
169
170
drmVersionPtr kernel_version;
171
172
struct renderonly *ro;
173
174
pthread_mutex_t bo_map_lock;
175
struct util_sparse_array bo_map;
176
177
struct {
178
pthread_mutex_t lock;
179
180
/* List containing all cached BOs sorted in LRU (Least
181
* Recently Used) order. This allows us to quickly evict BOs
182
* that are more than 1 second old.
183
*/
184
struct list_head lru;
185
186
/* The BO cache is a set of buckets with power-of-two sizes
187
* ranging from 2^12 (4096, the page size) to
188
* 2^(12 + MAX_BO_CACHE_BUCKETS).
189
* Each bucket is a linked list of free panfrost_bo objects. */
190
191
struct list_head buckets[NR_BO_CACHE_BUCKETS];
192
} bo_cache;
193
194
struct pan_blitter blitter;
195
struct pan_blend_shaders blend_shaders;
196
struct pan_indirect_draw_shaders indirect_draw_shaders;
197
struct pan_indirect_dispatch indirect_dispatch;
198
199
/* Tiler heap shared across all tiler jobs, allocated against the
200
* device since there's only a single tiler. Since this is invisible to
201
* the CPU, it's okay for multiple contexts to reference it
202
* simultaneously; by keeping on the device struct, we eliminate a
203
* costly per-context allocation. */
204
205
struct panfrost_bo *tiler_heap;
206
207
/* The tiler heap is shared by all contexts, and is written by tiler
208
* jobs and read by fragment job. We need to ensure that a
209
* vertex/tiler job chain from one context is not inserted between
210
* the vertex/tiler and fragment job of another context, otherwise
211
* we end up with tiler heap corruption.
212
*/
213
pthread_mutex_t submit_lock;
214
215
/* Sample positions are preloaded into a write-once constant buffer,
216
* such that they can be referenced fore free later. Needed
217
* unconditionally on Bifrost, and useful for sharing with Midgard */
218
219
struct panfrost_bo *sample_positions;
220
};
221
222
void
223
panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);
224
225
void
226
panfrost_close_device(struct panfrost_device *dev);
227
228
bool
229
panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt);
230
231
void
232
panfrost_upload_sample_positions(struct panfrost_device *dev);
233
234
mali_ptr
235
panfrost_sample_positions(const struct panfrost_device *dev,
236
enum mali_sample_pattern pattern);
237
void
238
panfrost_query_sample_position(
239
enum mali_sample_pattern pattern,
240
unsigned sample_idx,
241
float *out);
242
243
static inline struct panfrost_bo *
244
pan_lookup_bo(struct panfrost_device *dev, uint32_t gem_handle)
245
{
246
return (struct panfrost_bo *)util_sparse_array_get(&dev->bo_map, gem_handle);
247
}
248
249
static inline bool
250
pan_is_bifrost(const struct panfrost_device *dev)
251
{
252
return dev->arch >= 6 && dev->arch <= 7;
253
}
254
255
#if defined(__cplusplus)
256
} // extern "C"
257
#endif
258
259
#endif
260
261