Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/util/pan_ir.h
4560 views
1
/*
2
* Copyright (C) 2020 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
* 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
#ifndef __PAN_IR_H
25
#define __PAN_IR_H
26
27
#include <stdint.h>
28
#include "compiler/nir/nir.h"
29
#include "util/u_dynarray.h"
30
#include "util/hash_table.h"
31
32
/* Define the general compiler entry point */
33
34
#define MAX_SYSVAL_COUNT 32
35
36
/* Allow 2D of sysval IDs, while allowing nonparametric sysvals to equal
37
* their class for equal comparison */
38
39
#define PAN_SYSVAL(type, no) (((no) << 16) | PAN_SYSVAL_##type)
40
#define PAN_SYSVAL_TYPE(sysval) ((sysval) & 0xffff)
41
#define PAN_SYSVAL_ID(sysval) ((sysval) >> 16)
42
43
/* Define some common types. We start at one for easy indexing of hash
44
* tables internal to the compiler */
45
46
enum {
47
PAN_SYSVAL_VIEWPORT_SCALE = 1,
48
PAN_SYSVAL_VIEWPORT_OFFSET = 2,
49
PAN_SYSVAL_TEXTURE_SIZE = 3,
50
PAN_SYSVAL_SSBO = 4,
51
PAN_SYSVAL_NUM_WORK_GROUPS = 5,
52
PAN_SYSVAL_SAMPLER = 7,
53
PAN_SYSVAL_LOCAL_GROUP_SIZE = 8,
54
PAN_SYSVAL_WORK_DIM = 9,
55
PAN_SYSVAL_IMAGE_SIZE = 10,
56
PAN_SYSVAL_SAMPLE_POSITIONS = 11,
57
PAN_SYSVAL_MULTISAMPLED = 12,
58
PAN_SYSVAL_RT_CONVERSION = 13,
59
PAN_SYSVAL_VERTEX_INSTANCE_OFFSETS = 14,
60
PAN_SYSVAL_DRAWID = 15,
61
};
62
63
#define PAN_TXS_SYSVAL_ID(texidx, dim, is_array) \
64
((texidx) | ((dim) << 7) | ((is_array) ? (1 << 9) : 0))
65
66
#define PAN_SYSVAL_ID_TO_TXS_TEX_IDX(id) ((id) & 0x7f)
67
#define PAN_SYSVAL_ID_TO_TXS_DIM(id) (((id) >> 7) & 0x3)
68
#define PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(id) !!((id) & (1 << 9))
69
70
/* Special attribute slots for vertex builtins. Sort of arbitrary but let's be
71
* consistent with the blob so we can compare traces easier. */
72
73
enum {
74
PAN_VERTEX_ID = 16,
75
PAN_INSTANCE_ID = 17,
76
PAN_MAX_ATTRIBUTE
77
};
78
79
struct panfrost_sysvals {
80
/* The mapping of sysvals to uniforms, the count, and the off-by-one inverse */
81
unsigned sysvals[MAX_SYSVAL_COUNT];
82
unsigned sysval_count;
83
};
84
85
/* Technically Midgard could go up to 92 in a pathological case but we don't
86
* take advantage of that. Likewise Bifrost's FAU encoding can address 128
87
* words but actual implementations (G72, G76) are capped at 64 */
88
89
#define PAN_MAX_PUSH 64
90
91
/* Architectural invariants (Midgard and Bifrost): UBO must be <= 2^16 bytes so
92
* an offset to a word must be < 2^16. There are less than 2^8 UBOs */
93
94
struct panfrost_ubo_word {
95
uint16_t ubo;
96
uint16_t offset;
97
};
98
99
struct panfrost_ubo_push {
100
unsigned count;
101
struct panfrost_ubo_word words[PAN_MAX_PUSH];
102
};
103
104
/* Helper for searching the above. Note this is O(N) to the number of pushed
105
* constants, do not run in the draw call hot path */
106
107
unsigned
108
pan_lookup_pushed_ubo(struct panfrost_ubo_push *push, unsigned ubo, unsigned offs);
109
110
struct hash_table_u64 *
111
panfrost_init_sysvals(struct panfrost_sysvals *sysvals, void *memctx);
112
113
unsigned
114
pan_lookup_sysval(struct hash_table_u64 *sysval_to_id,
115
struct panfrost_sysvals *sysvals,
116
int sysval);
117
118
int
119
panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest);
120
121
struct panfrost_compile_inputs {
122
unsigned gpu_id;
123
bool is_blend, is_blit;
124
struct {
125
unsigned rt;
126
unsigned nr_samples;
127
uint64_t bifrost_blend_desc;
128
} blend;
129
unsigned sysval_ubo;
130
bool shaderdb;
131
bool no_ubo_to_push;
132
133
enum pipe_format rt_formats[8];
134
unsigned nr_cbufs;
135
};
136
137
struct pan_shader_varying {
138
gl_varying_slot location;
139
enum pipe_format format;
140
};
141
142
struct bifrost_shader_blend_info {
143
nir_alu_type type;
144
uint32_t return_offset;
145
146
/* mali_bifrost_register_file_format corresponding to nir_alu_type */
147
unsigned format;
148
};
149
150
struct bifrost_shader_info {
151
struct bifrost_shader_blend_info blend[8];
152
nir_alu_type blend_src1_type;
153
bool wait_6, wait_7;
154
155
/* Packed, preloaded message descriptors */
156
uint16_t messages[2];
157
};
158
159
struct midgard_shader_info {
160
unsigned first_tag;
161
};
162
163
struct pan_shader_info {
164
gl_shader_stage stage;
165
unsigned work_reg_count;
166
unsigned tls_size;
167
unsigned wls_size;
168
169
union {
170
struct {
171
bool reads_frag_coord;
172
bool reads_point_coord;
173
bool reads_face;
174
bool helper_invocations;
175
bool can_discard;
176
bool writes_depth;
177
bool writes_stencil;
178
bool writes_coverage;
179
bool sidefx;
180
bool reads_sample_id;
181
bool reads_sample_pos;
182
bool reads_sample_mask_in;
183
bool reads_helper_invocation;
184
bool sample_shading;
185
bool early_fragment_tests;
186
bool can_early_z, can_fpk;
187
BITSET_WORD outputs_read;
188
BITSET_WORD outputs_written;
189
} fs;
190
191
struct {
192
bool writes_point_size;
193
} vs;
194
};
195
196
bool separable;
197
bool contains_barrier;
198
bool writes_global;
199
uint64_t outputs_written;
200
201
unsigned sampler_count;
202
unsigned texture_count;
203
unsigned ubo_count;
204
unsigned attribute_count;
205
206
struct {
207
unsigned input_count;
208
struct pan_shader_varying input[MAX_VARYING];
209
unsigned output_count;
210
struct pan_shader_varying output[MAX_VARYING];
211
} varyings;
212
213
struct panfrost_sysvals sysvals;
214
215
/* UBOs to push to Register Mapped Uniforms (Midgard) or Fast Access
216
* Uniforms (Bifrost) */
217
struct panfrost_ubo_push push;
218
219
uint32_t ubo_mask;
220
221
union {
222
struct bifrost_shader_info bifrost;
223
struct midgard_shader_info midgard;
224
};
225
};
226
227
typedef struct pan_block {
228
/* Link to next block. Must be first for mir_get_block */
229
struct list_head link;
230
231
/* List of instructions emitted for the current block */
232
struct list_head instructions;
233
234
/* Index of the block in source order */
235
unsigned name;
236
237
/* Control flow graph */
238
struct pan_block *successors[2];
239
struct set *predecessors;
240
bool unconditional_jumps;
241
242
/* In liveness analysis, these are live masks (per-component) for
243
* indices for the block. Scalar compilers have the luxury of using
244
* simple bit fields, but for us, liveness is a vector idea. */
245
uint16_t *live_in;
246
uint16_t *live_out;
247
} pan_block;
248
249
struct pan_instruction {
250
struct list_head link;
251
};
252
253
#define pan_foreach_instr_in_block_rev(block, v) \
254
list_for_each_entry_rev(struct pan_instruction, v, &block->instructions, link)
255
256
#define pan_foreach_successor(blk, v) \
257
pan_block *v; \
258
pan_block **_v; \
259
for (_v = (pan_block **) &blk->successors[0], \
260
v = *_v; \
261
v != NULL && _v < (pan_block **) &blk->successors[2]; \
262
_v++, v = *_v) \
263
264
#define pan_foreach_predecessor(blk, v) \
265
struct set_entry *_entry_##v; \
266
struct pan_block *v; \
267
for (_entry_##v = _mesa_set_next_entry(blk->predecessors, NULL), \
268
v = (struct pan_block *) (_entry_##v ? _entry_##v->key : NULL); \
269
_entry_##v != NULL; \
270
_entry_##v = _mesa_set_next_entry(blk->predecessors, _entry_##v), \
271
v = (struct pan_block *) (_entry_##v ? _entry_##v->key : NULL))
272
273
static inline pan_block *
274
pan_exit_block(struct list_head *blocks)
275
{
276
pan_block *last = list_last_entry(blocks, pan_block, link);
277
assert(!last->successors[0] && !last->successors[1]);
278
return last;
279
}
280
281
typedef void (*pan_liveness_update)(uint16_t *, void *, unsigned max);
282
283
void pan_liveness_gen(uint16_t *live, unsigned node, unsigned max, uint16_t mask);
284
void pan_liveness_kill(uint16_t *live, unsigned node, unsigned max, uint16_t mask);
285
bool pan_liveness_get(uint16_t *live, unsigned node, uint16_t max);
286
287
void pan_compute_liveness(struct list_head *blocks,
288
unsigned temp_count,
289
pan_liveness_update callback);
290
291
void pan_free_liveness(struct list_head *blocks);
292
293
uint16_t
294
pan_to_bytemask(unsigned bytes, unsigned mask);
295
296
void pan_block_add_successor(pan_block *block, pan_block *successor);
297
298
/* IR indexing */
299
#define PAN_IS_REG (1)
300
301
static inline unsigned
302
pan_ssa_index(nir_ssa_def *ssa)
303
{
304
/* Off-by-one ensures BIR_NO_ARG is skipped */
305
return ((ssa->index + 1) << 1) | 0;
306
}
307
308
static inline unsigned
309
pan_src_index(nir_src *src)
310
{
311
if (src->is_ssa)
312
return pan_ssa_index(src->ssa);
313
else {
314
assert(!src->reg.indirect);
315
return (src->reg.reg->index << 1) | PAN_IS_REG;
316
}
317
}
318
319
static inline unsigned
320
pan_dest_index(nir_dest *dst)
321
{
322
if (dst->is_ssa)
323
return pan_ssa_index(&dst->ssa);
324
else {
325
assert(!dst->reg.indirect);
326
return (dst->reg.reg->index << 1) | PAN_IS_REG;
327
}
328
}
329
330
/* IR printing helpers */
331
void pan_print_alu_type(nir_alu_type t, FILE *fp);
332
333
/* Until it can be upstreamed.. */
334
bool pan_has_source_mod(nir_alu_src *src, nir_op op);
335
bool pan_has_dest_mod(nir_dest **dest, nir_op op);
336
337
/* NIR passes to do some backend-specific lowering */
338
339
#define PAN_WRITEOUT_C 1
340
#define PAN_WRITEOUT_Z 2
341
#define PAN_WRITEOUT_S 4
342
343
bool pan_nir_reorder_writeout(nir_shader *nir);
344
bool pan_nir_lower_zs_store(nir_shader *nir);
345
346
bool pan_nir_lower_64bit_intrin(nir_shader *shader);
347
348
bool pan_lower_helper_invocation(nir_shader *shader);
349
bool pan_lower_sample_pos(nir_shader *shader);
350
351
#endif
352
353