Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/lib/pan_encoder.h
4560 views
1
/*
2
* Copyright (C) 2019 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
* Authors (Collabora):
24
* Alyssa Rosenzweig <[email protected]>
25
*/
26
27
#ifndef __PAN_ENCODER_H
28
#define __PAN_ENCODER_H
29
30
#include <stdbool.h>
31
#include "util/format/u_format.h"
32
#include "pan_bo.h"
33
#include "midgard_pack.h"
34
35
/* Indices for named (non-XFB) varyings that are present. These are packed
36
* tightly so they correspond to a bitfield present (P) indexed by (1 <<
37
* PAN_VARY_*). This has the nice property that you can lookup the buffer index
38
* of a given special field given a shift S by:
39
*
40
* idx = popcount(P & ((1 << S) - 1))
41
*
42
* That is... look at all of the varyings that come earlier and count them, the
43
* count is the new index since plus one. Likewise, the total number of special
44
* buffers required is simply popcount(P)
45
*/
46
47
enum pan_special_varying {
48
PAN_VARY_GENERAL = 0,
49
PAN_VARY_POSITION = 1,
50
PAN_VARY_PSIZ = 2,
51
PAN_VARY_PNTCOORD = 3,
52
PAN_VARY_FACE = 4,
53
PAN_VARY_FRAGCOORD = 5,
54
55
/* Keep last */
56
PAN_VARY_MAX,
57
};
58
59
/* Tiler structure size computation */
60
61
struct panfrost_device;
62
63
unsigned
64
panfrost_tiler_get_polygon_list_size(const struct panfrost_device *dev,
65
unsigned fb_width, unsigned fb_height,
66
bool has_draws);
67
68
unsigned
69
panfrost_tiler_header_size(unsigned width, unsigned height, unsigned mask, bool hierarchy);
70
71
unsigned
72
panfrost_tiler_full_size(unsigned width, unsigned height, unsigned mask, bool hierarchy);
73
74
unsigned
75
panfrost_choose_hierarchy_mask(
76
unsigned width, unsigned height,
77
unsigned vertex_count, bool hierarchy);
78
79
/* Stack sizes */
80
81
unsigned
82
panfrost_get_stack_shift(unsigned stack_size);
83
84
unsigned
85
panfrost_get_total_stack_size(
86
unsigned thread_size,
87
unsigned threads_per_core,
88
unsigned core_count);
89
90
const char * panfrost_model_name(unsigned gpu_id);
91
92
/* Attributes / instancing */
93
94
unsigned
95
panfrost_padded_vertex_count(unsigned vertex_count);
96
97
unsigned
98
panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned *extra_flags);
99
100
/* Records for gl_VertexID and gl_InstanceID use special encodings on Midgard */
101
102
static inline void
103
panfrost_vertex_id(unsigned padded_count,
104
struct mali_attribute_buffer_packed *attr,
105
bool instanced)
106
{
107
pan_pack(attr, ATTRIBUTE_VERTEX_ID, cfg) {
108
if (instanced) {
109
cfg.divisor_r = __builtin_ctz(padded_count);
110
cfg.divisor_p = padded_count >> (cfg.divisor_r + 1);
111
} else {
112
/* Large values so the modulo is a no-op */
113
cfg.divisor_r = 0x1F;
114
cfg.divisor_p = 0x4;
115
}
116
}
117
}
118
119
static inline void
120
panfrost_instance_id(unsigned padded_count,
121
struct mali_attribute_buffer_packed *attr,
122
bool instanced)
123
{
124
pan_pack(attr, ATTRIBUTE_INSTANCE_ID, cfg) {
125
if (!instanced || padded_count <= 1) {
126
/* Divide by large number to force to 0 */
127
cfg.divisor_p = ((1u << 31) - 1);
128
cfg.divisor_r = 0x1F;
129
cfg.divisor_e = 0x1;
130
} else if(util_is_power_of_two_or_zero(padded_count)) {
131
/* Can't underflow since padded_count >= 2 */
132
cfg.divisor_r = __builtin_ctz(padded_count) - 1;
133
} else {
134
cfg.divisor_p =
135
panfrost_compute_magic_divisor(padded_count,
136
&cfg.divisor_r, &cfg.divisor_e);
137
}
138
}
139
}
140
141
/* Sampler comparison functions are flipped in OpenGL from the hardware, so we
142
* need to be able to flip accordingly */
143
144
static inline enum mali_func
145
panfrost_flip_compare_func(enum mali_func f)
146
{
147
switch (f) {
148
case MALI_FUNC_LESS: return MALI_FUNC_GREATER;
149
case MALI_FUNC_GREATER: return MALI_FUNC_LESS;
150
case MALI_FUNC_LEQUAL: return MALI_FUNC_GEQUAL;
151
case MALI_FUNC_GEQUAL: return MALI_FUNC_LEQUAL;
152
default: return f;
153
}
154
155
}
156
157
/* Compute shaders are invoked with a gl_NumWorkGroups X/Y/Z triplet. Vertex
158
* shaders are invoked as (1, vertex_count, instance_count). Compute shaders
159
* also have a gl_WorkGroupSize X/Y/Z triplet. These 6 values are packed
160
* together in a dynamic bitfield, packed by this routine. */
161
162
static inline void
163
panfrost_pack_work_groups_compute(
164
struct mali_invocation_packed *out,
165
unsigned num_x, unsigned num_y, unsigned num_z,
166
unsigned size_x, unsigned size_y, unsigned size_z,
167
bool quirk_graphics, bool indirect_dispatch)
168
{
169
/* The values needing packing, in order, and the corresponding shifts.
170
* Indicies into shift are off-by-one to make the logic easier */
171
172
unsigned values[6] = { size_x, size_y, size_z, num_x, num_y, num_z };
173
unsigned shifts[7] = { 0 };
174
uint32_t packed = 0;
175
176
for (unsigned i = 0; i < 6; ++i) {
177
/* Must be positive, otherwise we underflow */
178
assert(values[i] >= 1);
179
180
/* OR it in, shifting as required */
181
packed |= ((values[i] - 1) << shifts[i]);
182
183
/* How many bits did we use? */
184
unsigned bit_count = util_logbase2_ceil(values[i]);
185
186
/* Set the next shift accordingly */
187
shifts[i + 1] = shifts[i] + bit_count;
188
}
189
190
pan_pack(out, INVOCATION, cfg) {
191
cfg.invocations = packed;
192
cfg.size_y_shift = shifts[1];
193
cfg.size_z_shift = shifts[2];
194
cfg.workgroups_x_shift = shifts[3];
195
196
if (!indirect_dispatch) {
197
/* Leave zero for the dispatch shader */
198
cfg.workgroups_y_shift = shifts[4];
199
cfg.workgroups_z_shift = shifts[5];
200
}
201
202
/* Quirk: for non-instanced graphics, the blob sets
203
* workgroups_z_shift = 32. This doesn't appear to matter to
204
* the hardware, but it's good to be bit-identical. */
205
206
if (quirk_graphics && (num_z <= 1))
207
cfg.workgroups_z_shift = 32;
208
209
/* For graphics, set to the minimum efficient value. For
210
* compute, must equal the workgroup X shift for barriers to
211
* function correctly */
212
213
cfg.thread_group_split = quirk_graphics ?
214
MALI_SPLIT_MIN_EFFICIENT : cfg.workgroups_x_shift;
215
}
216
}
217
218
/* Format conversion */
219
static inline enum mali_z_internal_format
220
panfrost_get_z_internal_format(enum pipe_format fmt)
221
{
222
switch (fmt) {
223
case PIPE_FORMAT_Z16_UNORM:
224
case PIPE_FORMAT_Z16_UNORM_S8_UINT:
225
return MALI_Z_INTERNAL_FORMAT_D16;
226
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
227
case PIPE_FORMAT_Z24X8_UNORM:
228
return MALI_Z_INTERNAL_FORMAT_D24;
229
case PIPE_FORMAT_Z32_FLOAT:
230
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
231
return MALI_Z_INTERNAL_FORMAT_D32;
232
default:
233
unreachable("Unsupported depth/stencil format.");
234
}
235
}
236
237
#endif
238
239