2 * Copyright (C) 2020 Collabora, Ltd.
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:
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
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
28 #include "panfrost-job.h"
29 #include "compiler/nir/nir.h"
30 #include "util/u_dynarray.h"
31 #include "util/hash_table.h"
33 /* Define the general compiler entry point */
35 #define MAX_SYSVAL_COUNT 32
37 /* Allow 2D of sysval IDs, while allowing nonparametric sysvals to equal
38 * their class for equal comparison */
40 #define PAN_SYSVAL(type, no) (((no) << 16) | PAN_SYSVAL_##type)
41 #define PAN_SYSVAL_TYPE(sysval) ((sysval) & 0xffff)
42 #define PAN_SYSVAL_ID(sysval) ((sysval) >> 16)
44 /* Define some common types. We start at one for easy indexing of hash
45 * tables internal to the compiler */
48 PAN_SYSVAL_VIEWPORT_SCALE
= 1,
49 PAN_SYSVAL_VIEWPORT_OFFSET
= 2,
50 PAN_SYSVAL_TEXTURE_SIZE
= 3,
52 PAN_SYSVAL_NUM_WORK_GROUPS
= 5,
53 PAN_SYSVAL_SAMPLER
= 7,
56 #define PAN_TXS_SYSVAL_ID(texidx, dim, is_array) \
57 ((texidx) | ((dim) << 7) | ((is_array) ? (1 << 9) : 0))
59 #define PAN_SYSVAL_ID_TO_TXS_TEX_IDX(id) ((id) & 0x7f)
60 #define PAN_SYSVAL_ID_TO_TXS_DIM(id) (((id) >> 7) & 0x3)
61 #define PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(id) !!((id) & (1 << 9))
63 /* Special attribute slots for vertex builtins. Sort of arbitrary but let's be
64 * consistent with the blob so we can compare traces easier. */
72 struct panfrost_sysvals
{
73 /* The mapping of sysvals to uniforms, the count, and the off-by-one inverse */
74 unsigned sysvals
[MAX_SYSVAL_COUNT
];
75 unsigned sysval_count
;
76 struct hash_table_u64
*sysval_to_id
;
80 panfrost_nir_assign_sysvals(struct panfrost_sysvals
*ctx
, nir_shader
*shader
);
83 panfrost_sysval_for_instr(nir_instr
*instr
, nir_dest
*dest
);
86 int work_register_count
;
90 /* Prepended before uniforms, mapping to SYSVAL_ names for the
93 unsigned sysval_count
;
94 unsigned sysvals
[MAX_SYSVAL_COUNT
];
96 unsigned varyings
[32];
97 enum mali_format varying_type
[32];
99 /* Boolean properties of the program */
100 bool writes_point_size
;
104 struct util_dynarray compiled
;
106 /* For a blend shader using a constant color -- patch point. If
107 * negative, there's no constant. */
109 int blend_patch_offset
;
111 /* The number of bytes to allocate per-thread for Thread Local Storage
112 * (register spilling), or zero if no spilling is used */
115 /* IN: For a fragment shader with a lowered alpha test, the ref value */
119 typedef struct pan_block
{
120 /* Link to next block. Must be first for mir_get_block */
121 struct list_head link
;
123 /* List of instructions emitted for the current block */
124 struct list_head instructions
;
126 /* Index of the block in source order */
129 /* Control flow graph */
130 struct pan_block
*successors
[2];
131 unsigned nr_successors
;
133 struct set
*predecessors
;
135 /* In liveness analysis, these are live masks (per-component) for
136 * indices for the block. Scalar compilers have the luxury of using
137 * simple bit fields, but for us, liveness is a vector idea. */
142 struct pan_instruction
{
143 struct list_head link
;
146 #define pan_foreach_instr_in_block_rev(block, v) \
147 list_for_each_entry_rev(struct pan_instruction, v, &block->instructions, link)
149 #define pan_foreach_successor(blk, v) \
152 for (_v = (pan_block **) &blk->successors[0], \
154 v != NULL && _v < (pan_block **) &blk->successors[2]; \
157 #define pan_foreach_predecessor(blk, v) \
158 struct set_entry *_entry_##v; \
159 struct pan_block *v; \
160 for (_entry_##v = _mesa_set_next_entry(blk->predecessors, NULL), \
161 v = (struct pan_block *) (_entry_##v ? _entry_##v->key : NULL); \
162 _entry_##v != NULL; \
163 _entry_##v = _mesa_set_next_entry(blk->predecessors, _entry_##v), \
164 v = (struct pan_block *) (_entry_##v ? _entry_##v->key : NULL))
167 typedef void (*pan_liveness_update
)(uint16_t *, void *, unsigned max
);
169 void pan_liveness_gen(uint16_t *live
, unsigned node
, unsigned max
, uint16_t mask
);
170 void pan_liveness_kill(uint16_t *live
, unsigned node
, unsigned max
, uint16_t mask
);
171 bool pan_liveness_get(uint16_t *live
, unsigned node
, uint16_t max
);
173 void pan_compute_liveness(struct list_head
*blocks
,
175 pan_liveness_update callback
);
177 void pan_free_liveness(struct list_head
*blocks
);
180 pan_to_bytemask(unsigned bytes
, unsigned mask
);