panfrost: Identify coverage_mask
[mesa.git] / src / panfrost / include / panfrost-job.h
1 /*
2 * © Copyright 2017-2018 Alyssa Rosenzweig
3 * © Copyright 2017-2018 Connor Abbott
4 * © Copyright 2017-2018 Lyude Paul
5 * © Copyright2019 Collabora, Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 */
27
28 #ifndef __PANFROST_JOB_H__
29 #define __PANFROST_JOB_H__
30
31 #include <stdint.h>
32 #include <stdbool.h>
33 #include <panfrost-misc.h>
34
35 enum mali_job_type {
36 JOB_NOT_STARTED = 0,
37 JOB_TYPE_NULL = 1,
38 JOB_TYPE_WRITE_VALUE = 2,
39 JOB_TYPE_CACHE_FLUSH = 3,
40 JOB_TYPE_COMPUTE = 4,
41 JOB_TYPE_VERTEX = 5,
42 JOB_TYPE_GEOMETRY = 6,
43 JOB_TYPE_TILER = 7,
44 JOB_TYPE_FUSED = 8,
45 JOB_TYPE_FRAGMENT = 9,
46 };
47
48 enum mali_draw_mode {
49 MALI_DRAW_NONE = 0x0,
50 MALI_POINTS = 0x1,
51 MALI_LINES = 0x2,
52 MALI_LINE_STRIP = 0x4,
53 MALI_LINE_LOOP = 0x6,
54 MALI_TRIANGLES = 0x8,
55 MALI_TRIANGLE_STRIP = 0xA,
56 MALI_TRIANGLE_FAN = 0xC,
57 MALI_POLYGON = 0xD,
58 MALI_QUADS = 0xE,
59 MALI_QUAD_STRIP = 0xF,
60
61 /* All other modes invalid */
62 };
63
64 /* Applies to tiler_gl_enables */
65
66 #define MALI_OCCLUSION_QUERY (1 << 3)
67 #define MALI_OCCLUSION_PRECISE (1 << 4)
68
69 /* Set for a glFrontFace(GL_CCW) in a Y=0=TOP coordinate system (like Gallium).
70 * In OpenGL, this would corresponds to glFrontFace(GL_CW). Mesa and the blob
71 * disagree about how to do viewport flipping, so the blob actually sets this
72 * for GL_CW but then has a negative viewport stride */
73
74 #define MALI_FRONT_CCW_TOP (1 << 5)
75
76 #define MALI_CULL_FACE_FRONT (1 << 6)
77 #define MALI_CULL_FACE_BACK (1 << 7)
78
79 /* Used in stencil and depth tests */
80
81 enum mali_func {
82 MALI_FUNC_NEVER = 0,
83 MALI_FUNC_LESS = 1,
84 MALI_FUNC_EQUAL = 2,
85 MALI_FUNC_LEQUAL = 3,
86 MALI_FUNC_GREATER = 4,
87 MALI_FUNC_NOTEQUAL = 5,
88 MALI_FUNC_GEQUAL = 6,
89 MALI_FUNC_ALWAYS = 7
90 };
91
92 /* Flags apply to unknown2_3? */
93
94 #define MALI_HAS_MSAA (1 << 0)
95 #define MALI_CAN_DISCARD (1 << 5)
96
97 /* Applies on SFBD systems, specifying that programmable blending is in use */
98 #define MALI_HAS_BLEND_SHADER (1 << 6)
99
100 /* func is mali_func */
101 #define MALI_DEPTH_FUNC(func) (func << 8)
102 #define MALI_GET_DEPTH_FUNC(flags) ((flags >> 8) & 0x7)
103 #define MALI_DEPTH_FUNC_MASK MALI_DEPTH_FUNC(0x7)
104
105 #define MALI_DEPTH_WRITEMASK (1 << 11)
106
107 #define MALI_DEPTH_CLIP_NEAR (1 << 12)
108 #define MALI_DEPTH_CLIP_FAR (1 << 13)
109
110 /* Next flags to unknown2_4 */
111 #define MALI_STENCIL_TEST (1 << 0)
112
113 /* What?! */
114 #define MALI_SAMPLE_ALPHA_TO_COVERAGE_NO_BLEND_SHADER (1 << 1)
115
116 #define MALI_NO_DITHER (1 << 9)
117 #define MALI_DEPTH_RANGE_A (1 << 12)
118 #define MALI_DEPTH_RANGE_B (1 << 13)
119 #define MALI_NO_MSAA (1 << 14)
120
121 /* Stencil test state is all encoded in a single u32, just with a lot of
122 * enums... */
123
124 enum mali_stencil_op {
125 MALI_STENCIL_KEEP = 0,
126 MALI_STENCIL_REPLACE = 1,
127 MALI_STENCIL_ZERO = 2,
128 MALI_STENCIL_INVERT = 3,
129 MALI_STENCIL_INCR_WRAP = 4,
130 MALI_STENCIL_DECR_WRAP = 5,
131 MALI_STENCIL_INCR = 6,
132 MALI_STENCIL_DECR = 7
133 };
134
135 struct mali_stencil_test {
136 unsigned ref : 8;
137 unsigned mask : 8;
138 enum mali_func func : 3;
139 enum mali_stencil_op sfail : 3;
140 enum mali_stencil_op dpfail : 3;
141 enum mali_stencil_op dppass : 3;
142 unsigned zero : 4;
143 } __attribute__((packed));
144
145 #define MALI_MASK_R (1 << 0)
146 #define MALI_MASK_G (1 << 1)
147 #define MALI_MASK_B (1 << 2)
148 #define MALI_MASK_A (1 << 3)
149
150 enum mali_nondominant_mode {
151 MALI_BLEND_NON_MIRROR = 0,
152 MALI_BLEND_NON_ZERO = 1
153 };
154
155 enum mali_dominant_blend {
156 MALI_BLEND_DOM_SOURCE = 0,
157 MALI_BLEND_DOM_DESTINATION = 1
158 };
159
160 enum mali_dominant_factor {
161 MALI_DOMINANT_UNK0 = 0,
162 MALI_DOMINANT_ZERO = 1,
163 MALI_DOMINANT_SRC_COLOR = 2,
164 MALI_DOMINANT_DST_COLOR = 3,
165 MALI_DOMINANT_UNK4 = 4,
166 MALI_DOMINANT_SRC_ALPHA = 5,
167 MALI_DOMINANT_DST_ALPHA = 6,
168 MALI_DOMINANT_CONSTANT = 7,
169 };
170
171 enum mali_blend_modifier {
172 MALI_BLEND_MOD_UNK0 = 0,
173 MALI_BLEND_MOD_NORMAL = 1,
174 MALI_BLEND_MOD_SOURCE_ONE = 2,
175 MALI_BLEND_MOD_DEST_ONE = 3,
176 };
177
178 struct mali_blend_mode {
179 enum mali_blend_modifier clip_modifier : 2;
180 unsigned unused_0 : 1;
181 unsigned negate_source : 1;
182
183 enum mali_dominant_blend dominant : 1;
184
185 enum mali_nondominant_mode nondominant_mode : 1;
186
187 unsigned unused_1 : 1;
188
189 unsigned negate_dest : 1;
190
191 enum mali_dominant_factor dominant_factor : 3;
192 unsigned complement_dominant : 1;
193 } __attribute__((packed));
194
195 struct mali_blend_equation {
196 /* Of type mali_blend_mode */
197 unsigned rgb_mode : 12;
198 unsigned alpha_mode : 12;
199
200 unsigned zero1 : 4;
201
202 /* Corresponds to MALI_MASK_* above and glColorMask arguments */
203
204 unsigned color_mask : 4;
205 } __attribute__((packed));
206
207 /* Used with channel swizzling */
208 enum mali_channel {
209 MALI_CHANNEL_RED = 0,
210 MALI_CHANNEL_GREEN = 1,
211 MALI_CHANNEL_BLUE = 2,
212 MALI_CHANNEL_ALPHA = 3,
213 MALI_CHANNEL_ZERO = 4,
214 MALI_CHANNEL_ONE = 5,
215 MALI_CHANNEL_RESERVED_0 = 6,
216 MALI_CHANNEL_RESERVED_1 = 7,
217 };
218
219 struct mali_channel_swizzle {
220 enum mali_channel r : 3;
221 enum mali_channel g : 3;
222 enum mali_channel b : 3;
223 enum mali_channel a : 3;
224 } __attribute__((packed));
225
226 /* Compressed per-pixel formats. Each of these formats expands to one to four
227 * floating-point or integer numbers, as defined by the OpenGL specification.
228 * There are various places in OpenGL where the user can specify a compressed
229 * format in memory, which all use the same 8-bit enum in the various
230 * descriptors, although different hardware units support different formats.
231 */
232
233 /* The top 3 bits specify how the bits of each component are interpreted. */
234
235 /* e.g. ETC2_RGB8 */
236 #define MALI_FORMAT_COMPRESSED (0 << 5)
237
238 /* e.g. R11F_G11F_B10F */
239 #define MALI_FORMAT_SPECIAL (2 << 5)
240
241 /* signed normalized, e.g. RGBA8_SNORM */
242 #define MALI_FORMAT_SNORM (3 << 5)
243
244 /* e.g. RGBA8UI */
245 #define MALI_FORMAT_UINT (4 << 5)
246
247 /* e.g. RGBA8 and RGBA32F */
248 #define MALI_FORMAT_UNORM (5 << 5)
249
250 /* e.g. RGBA8I and RGBA16F */
251 #define MALI_FORMAT_SINT (6 << 5)
252
253 /* These formats seem to largely duplicate the others. They're used at least
254 * for Bifrost framebuffer output.
255 */
256 #define MALI_FORMAT_SPECIAL2 (7 << 5)
257 #define MALI_EXTRACT_TYPE(fmt) ((fmt) & 0xe0)
258
259 /* If the high 3 bits are 3 to 6 these two bits say how many components
260 * there are.
261 */
262 #define MALI_NR_CHANNELS(n) ((n - 1) << 3)
263 #define MALI_EXTRACT_CHANNELS(fmt) ((((fmt) >> 3) & 3) + 1)
264
265 /* If the high 3 bits are 3 to 6, then the low 3 bits say how big each
266 * component is, except the special MALI_CHANNEL_FLOAT which overrides what the
267 * bits mean.
268 */
269
270 #define MALI_CHANNEL_4 2
271
272 #define MALI_CHANNEL_8 3
273
274 #define MALI_CHANNEL_16 4
275
276 #define MALI_CHANNEL_32 5
277
278 /* For MALI_FORMAT_SINT it means a half-float (e.g. RG16F). For
279 * MALI_FORMAT_UNORM, it means a 32-bit float.
280 */
281 #define MALI_CHANNEL_FLOAT 7
282 #define MALI_EXTRACT_BITS(fmt) (fmt & 0x7)
283
284 enum mali_format {
285 MALI_ETC2_RGB8 = MALI_FORMAT_COMPRESSED | 0x1,
286 MALI_ETC2_R11_UNORM = MALI_FORMAT_COMPRESSED | 0x2,
287 MALI_ETC2_RGBA8 = MALI_FORMAT_COMPRESSED | 0x3,
288 MALI_ETC2_RG11_UNORM = MALI_FORMAT_COMPRESSED | 0x4,
289 MALI_ETC2_R11_SNORM = MALI_FORMAT_COMPRESSED | 0x11,
290 MALI_ETC2_RG11_SNORM = MALI_FORMAT_COMPRESSED | 0x12,
291 MALI_ETC2_RGB8A1 = MALI_FORMAT_COMPRESSED | 0x13,
292 MALI_ASTC_SRGB_SUPP = MALI_FORMAT_COMPRESSED | 0x16,
293 MALI_ASTC_HDR_SUPP = MALI_FORMAT_COMPRESSED | 0x17,
294
295 MALI_RGB565 = MALI_FORMAT_SPECIAL | 0x0,
296 MALI_RGB5_X1_UNORM = MALI_FORMAT_SPECIAL | 0x1,
297 MALI_RGB5_A1_UNORM = MALI_FORMAT_SPECIAL | 0x2,
298 MALI_RGB10_A2_UNORM = MALI_FORMAT_SPECIAL | 0x3,
299 MALI_RGB10_A2_SNORM = MALI_FORMAT_SPECIAL | 0x5,
300 MALI_RGB10_A2UI = MALI_FORMAT_SPECIAL | 0x7,
301 MALI_RGB10_A2I = MALI_FORMAT_SPECIAL | 0x9,
302
303 MALI_RGB332_UNORM = MALI_FORMAT_SPECIAL | 0xb,
304 MALI_RGB233_UNORM = MALI_FORMAT_SPECIAL | 0xc,
305
306 MALI_Z24X8_UNORM = MALI_FORMAT_SPECIAL | 0xd,
307 MALI_R32_FIXED = MALI_FORMAT_SPECIAL | 0x11,
308 MALI_RG32_FIXED = MALI_FORMAT_SPECIAL | 0x12,
309 MALI_RGB32_FIXED = MALI_FORMAT_SPECIAL | 0x13,
310 MALI_RGBA32_FIXED = MALI_FORMAT_SPECIAL | 0x14,
311 MALI_R11F_G11F_B10F = MALI_FORMAT_SPECIAL | 0x19,
312 MALI_R9F_G9F_B9F_E5F = MALI_FORMAT_SPECIAL | 0x1b,
313 /* Only used for varyings, to indicate the transformed gl_Position */
314 MALI_VARYING_POS = MALI_FORMAT_SPECIAL | 0x1e,
315 /* Only used for varyings, to indicate that the write should be
316 * discarded.
317 */
318 MALI_VARYING_DISCARD = MALI_FORMAT_SPECIAL | 0x1f,
319
320 MALI_R8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
321 MALI_R16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
322 MALI_R32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
323 MALI_RG8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
324 MALI_RG16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
325 MALI_RG32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
326 MALI_RGB8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
327 MALI_RGB16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
328 MALI_RGB32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
329 MALI_RGBA8_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
330 MALI_RGBA16_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
331 MALI_RGBA32_SNORM = MALI_FORMAT_SNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
332
333 MALI_R8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
334 MALI_R16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
335 MALI_R32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
336 MALI_RG8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
337 MALI_RG16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
338 MALI_RG32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
339 MALI_RGB8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
340 MALI_RGB16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
341 MALI_RGB32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
342 MALI_RGBA8UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
343 MALI_RGBA16UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
344 MALI_RGBA32UI = MALI_FORMAT_UINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
345
346 MALI_R8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
347 MALI_R16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
348 MALI_R32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
349 MALI_R32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(1) | MALI_CHANNEL_FLOAT,
350 MALI_RG8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
351 MALI_RG16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
352 MALI_RG32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
353 MALI_RG32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(2) | MALI_CHANNEL_FLOAT,
354 MALI_RGB8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
355 MALI_RGB16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
356 MALI_RGB32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
357 MALI_RGB32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(3) | MALI_CHANNEL_FLOAT,
358 MALI_RGBA4_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_4,
359 MALI_RGBA8_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
360 MALI_RGBA16_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
361 MALI_RGBA32_UNORM = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
362 MALI_RGBA32F = MALI_FORMAT_UNORM | MALI_NR_CHANNELS(4) | MALI_CHANNEL_FLOAT,
363
364 MALI_R8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_8,
365 MALI_R16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_16,
366 MALI_R32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_32,
367 MALI_R16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(1) | MALI_CHANNEL_FLOAT,
368 MALI_RG8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_8,
369 MALI_RG16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_16,
370 MALI_RG32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_32,
371 MALI_RG16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(2) | MALI_CHANNEL_FLOAT,
372 MALI_RGB8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_8,
373 MALI_RGB16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_16,
374 MALI_RGB32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_32,
375 MALI_RGB16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(3) | MALI_CHANNEL_FLOAT,
376 MALI_RGBA8I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_8,
377 MALI_RGBA16I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_16,
378 MALI_RGBA32I = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_32,
379 MALI_RGBA16F = MALI_FORMAT_SINT | MALI_NR_CHANNELS(4) | MALI_CHANNEL_FLOAT,
380
381 MALI_RGBA4 = MALI_FORMAT_SPECIAL2 | 0x8,
382 MALI_RGBA8_2 = MALI_FORMAT_SPECIAL2 | 0xd,
383 MALI_RGB10_A2_2 = MALI_FORMAT_SPECIAL2 | 0xe,
384 };
385
386
387 /* Applies to midgard1.flags_lo */
388
389 /* Should be set when the fragment shader updates the depth value. */
390 #define MALI_WRITES_Z (1 << 4)
391
392 /* Should the hardware perform early-Z testing? Set if the shader does not use
393 * discard, alpha-to-coverage, shader depth writes, and if the shader has no
394 * side effects (writes to global memory or images) unless early-z testing is
395 * forced in the shader.
396 */
397
398 #define MALI_EARLY_Z (1 << 6)
399
400 /* Should the hardware calculate derivatives (via helper invocations)? Set in a
401 * fragment shader that uses texturing or derivative functions */
402
403 #define MALI_HELPER_INVOCATIONS (1 << 7)
404
405 /* Flags denoting the fragment shader's use of tilebuffer readback. If the
406 * shader might read any part of the tilebuffer, set MALI_READS_TILEBUFFER. If
407 * it might read depth/stencil in particular, also set MALI_READS_ZS */
408
409 #define MALI_READS_ZS (1 << 8)
410
411 /* The shader might write to global memory (via OpenCL, SSBOs, or images).
412 * Reading is okay, as are ordinary writes to the tilebuffer/varyings. Setting
413 * incurs a performance penalty. On a fragment shader, this bit implies there
414 * are side effects, hence it interacts with early-z. */
415 #define MALI_WRITES_GLOBAL (1 << 9)
416
417 #define MALI_READS_TILEBUFFER (1 << 12)
418
419 /* Applies to midgard1.flags_hi */
420
421 /* Should be set when the fragment shader updates the stencil value. */
422 #define MALI_WRITES_S (1 << 2)
423
424 /* Mode to suppress generation of Infinity and NaN values by clamping inf
425 * (-inf) to MAX_FLOAT (-MIN_FLOAT) and flushing NaN to 0.0
426 *
427 * Compare suppress_inf/suppress_nan flags on the Bifrost clause header for the
428 * same functionality.
429 *
430 * This is not conformant on GLES3 or OpenCL, but is optional on GLES2, where
431 * it works around app bugs (e.g. in glmark2-es2 -bterrain with FP16).
432 */
433 #define MALI_SUPPRESS_INF_NAN (1 << 3)
434
435 /* Flags for bifrost1.unk1 */
436
437 /* Shader uses less than 32 registers, partitioned as [R0, R15] U [R48, R63],
438 * allowing for full thread count. If clear, the full [R0, R63] register set is
439 * available at half thread count */
440 #define MALI_BIFROST_FULL_THREAD (1 << 9)
441
442 /* Enable early-z testing (presumably). This flag may not be set if the shader:
443 *
444 * - Uses blending
445 * - Uses discard
446 * - Writes gl_FragDepth
447 *
448 * This differs from Midgard which sets the MALI_EARLY_Z flag even with
449 * blending, although I've begun to suspect that flag does not in fact enable
450 * EARLY_Z alone. */
451 #define MALI_BIFROST_EARLY_Z (1 << 15)
452
453 /* First clause type is ATEST */
454 #define MALI_BIFROST_FIRST_ATEST (1 << 26)
455
456 /* The raw Midgard blend payload can either be an equation or a shader
457 * address, depending on the context */
458
459 union midgard_blend {
460 mali_ptr shader;
461
462 struct {
463 struct mali_blend_equation equation;
464 float constant;
465 };
466 };
467
468 /* We need to load the tilebuffer to blend (i.e. the destination factor is not
469 * ZERO) */
470
471 #define MALI_BLEND_LOAD_TIB (0x1)
472
473 /* A blend shader is used to blend this render target */
474 #define MALI_BLEND_MRT_SHADER (0x2)
475
476 /* On MRT Midgard systems (using an MFBD), each render target gets its own
477 * blend descriptor */
478
479 #define MALI_BLEND_SRGB (0x400)
480
481 /* Dithering is specified here for MFBD, otherwise NO_DITHER for SFBD */
482 #define MALI_BLEND_NO_DITHER (0x800)
483
484 struct midgard_blend_rt {
485 /* Flags base value of 0x200 to enable the render target.
486 * OR with 0x1 for blending (anything other than REPLACE).
487 * OR with 0x2 for programmable blending
488 * OR with MALI_BLEND_SRGB for implicit sRGB
489 */
490
491 u64 flags;
492 union midgard_blend blend;
493 } __attribute__((packed));
494
495 /* On Bifrost systems (all MRT), each render target gets one of these
496 * descriptors */
497
498 enum bifrost_shader_type {
499 BIFROST_BLEND_F16 = 0,
500 BIFROST_BLEND_F32 = 1,
501 BIFROST_BLEND_I32 = 2,
502 BIFROST_BLEND_U32 = 3,
503 BIFROST_BLEND_I16 = 4,
504 BIFROST_BLEND_U16 = 5,
505 };
506
507 #define BIFROST_MAX_RENDER_TARGET_COUNT 8
508
509 struct bifrost_blend_rt {
510 /* This is likely an analogue of the flags on
511 * midgard_blend_rt */
512
513 u16 flags; // = 0x200
514
515 /* Single-channel blend constants are encoded in a sort of
516 * fixed-point. Basically, the float is mapped to a byte, becoming
517 * a high byte, and then the lower-byte is added for precision.
518 * For the original float f:
519 *
520 * f = (constant_hi / 255) + (constant_lo / 65535)
521 *
522 * constant_hi = int(f / 255)
523 * constant_lo = 65535*f - (65535/255) * constant_hi
524 */
525 u16 constant;
526
527 struct mali_blend_equation equation;
528
529 /*
530 * - 0x19 normally
531 * - 0x3 when this slot is unused (everything else is 0 except the index)
532 * - 0x11 when this is the fourth slot (and it's used)
533 * - 0 when there is a blend shader
534 */
535 u16 unk2;
536
537 /* increments from 0 to 3 */
538 u16 index;
539
540 union {
541 struct {
542 /* So far, I've only seen:
543 * - R001 for 1-component formats
544 * - RG01 for 2-component formats
545 * - RGB1 for 3-component formats
546 * - RGBA for 4-component formats
547 */
548 u32 swizzle : 12;
549 enum mali_format format : 8;
550
551 /* Type of the shader output variable. Note, this can
552 * be different from the format.
553 * enum bifrost_shader_type
554 */
555 u32 zero1 : 4;
556 u32 shader_type : 3;
557 u32 zero2 : 5;
558 };
559
560 /* Only the low 32 bits of the blend shader are stored, the
561 * high 32 bits are implicitly the same as the original shader.
562 * According to the kernel driver, the program counter for
563 * shaders is actually only 24 bits, so shaders cannot cross
564 * the 2^24-byte boundary, and neither can the blend shader.
565 * The blob handles this by allocating a 2^24 byte pool for
566 * shaders, and making sure that any blend shaders are stored
567 * in the same pool as the original shader. The kernel will
568 * make sure this allocation is aligned to 2^24 bytes.
569 */
570 u32 shader;
571 };
572 } __attribute__((packed));
573
574 /* Descriptor for the shader. Following this is at least one, up to four blend
575 * descriptors for each active render target */
576
577 struct mali_shader_meta {
578 mali_ptr shader;
579 u16 sampler_count;
580 u16 texture_count;
581 u16 attribute_count;
582 u16 varying_count;
583
584 union {
585 struct {
586 u32 uniform_buffer_count : 4;
587 u32 unk1 : 28; // = 0x800000 for vertex, 0x958020 for tiler
588 } bifrost1;
589 struct {
590 unsigned uniform_buffer_count : 4;
591 unsigned flags_lo : 12;
592
593 /* vec4 units */
594 unsigned work_count : 5;
595 unsigned uniform_count : 5;
596 unsigned flags_hi : 6;
597 } midgard1;
598 };
599
600 /* Same as glPolygoOffset() arguments */
601 float depth_units;
602 float depth_factor;
603
604 u32 unknown2_2;
605
606 /* Generated from SAMPLE_COVERAGE_VALUE and SAMPLE_COVERAGE_INVERT. See
607 * 13.8.3 ("Multisample Fragment Operations") in the OpenGL ES 3.2
608 * specification. Only matters when multisampling is enabled. */
609 u16 coverage_mask;
610
611 u16 unknown2_3;
612
613 u8 stencil_mask_front;
614 u8 stencil_mask_back;
615 u16 unknown2_4;
616
617 struct mali_stencil_test stencil_front;
618 struct mali_stencil_test stencil_back;
619
620 union {
621 struct {
622 u32 unk3 : 7;
623 /* On Bifrost, some system values are preloaded in
624 * registers R55-R62 by the thread dispatcher prior to
625 * the start of shader execution. This is a bitfield
626 * with one entry for each register saying which
627 * registers need to be preloaded. Right now, the known
628 * values are:
629 *
630 * Vertex/compute:
631 * - R55 : gl_LocalInvocationID.xy
632 * - R56 : gl_LocalInvocationID.z + unknown in high 16 bits
633 * - R57 : gl_WorkGroupID.x
634 * - R58 : gl_WorkGroupID.y
635 * - R59 : gl_WorkGroupID.z
636 * - R60 : gl_GlobalInvocationID.x
637 * - R61 : gl_GlobalInvocationID.y/gl_VertexID (without base)
638 * - R62 : gl_GlobalInvocationID.z/gl_InstanceID (without base)
639 *
640 * Fragment:
641 * - R55 : unknown, never seen (but the bit for this is
642 * always set?)
643 * - R56 : unknown (bit always unset)
644 * - R57 : gl_PrimitiveID
645 * - R58 : gl_FrontFacing in low bit, potentially other stuff
646 * - R59 : u16 fragment coordinates (used to compute
647 * gl_FragCoord.xy, together with sample positions)
648 * - R60 : gl_SampleMask (used in epilog, so pretty
649 * much always used, but the bit is always 0 -- is
650 * this just always pushed?)
651 * - R61 : gl_SampleMaskIn and gl_SampleID, used by
652 * varying interpolation.
653 * - R62 : unknown (bit always unset).
654 *
655 * Later GPUs (starting with Mali-G52?) support
656 * preloading float varyings into r0-r7. This is
657 * indicated by setting 0x40. There is no distinction
658 * here between 1 varying and 2.
659 */
660 u32 preload_regs : 8;
661 /* In units of 8 bytes or 64 bits, since the
662 * uniform/const port loads 64 bits at a time.
663 */
664 u32 uniform_count : 7;
665 u32 unk4 : 10; // = 2
666 } bifrost2;
667 struct {
668 u32 unknown2_7;
669 } midgard2;
670 };
671
672 u32 padding;
673
674 /* Blending information for the older non-MRT Midgard HW. Check for
675 * MALI_HAS_BLEND_SHADER to decide how to interpret.
676 */
677
678 union midgard_blend blend;
679 } __attribute__((packed));
680
681 /* This only concerns hardware jobs */
682
683 /* Possible values for job_descriptor_size */
684
685 #define MALI_JOB_32 0
686 #define MALI_JOB_64 1
687
688 struct mali_job_descriptor_header {
689 u32 exception_status;
690 u32 first_incomplete_task;
691 u64 fault_pointer;
692 u8 job_descriptor_size : 1;
693 enum mali_job_type job_type : 7;
694 u8 job_barrier : 1;
695 u8 unknown_flags : 7;
696 u16 job_index;
697 u16 job_dependency_index_1;
698 u16 job_dependency_index_2;
699 u64 next_job;
700 } __attribute__((packed));
701
702 /* These concern exception_status */
703
704 /* Access type causing a fault, paralleling AS_FAULTSTATUS_* entries in the
705 * kernel */
706
707 enum mali_exception_access {
708 /* Atomic in the kernel for MMU, but that doesn't make sense for a job
709 * fault so it's just unused */
710 MALI_EXCEPTION_ACCESS_NONE = 0,
711
712 MALI_EXCEPTION_ACCESS_EXECUTE = 1,
713 MALI_EXCEPTION_ACCESS_READ = 2,
714 MALI_EXCEPTION_ACCESS_WRITE = 3
715 };
716
717 /* Details about write_value from panfrost igt tests which use it as a generic
718 * dword write primitive */
719
720 #define MALI_WRITE_VALUE_ZERO 3
721
722 struct mali_payload_write_value {
723 u64 address;
724 u32 value_descriptor;
725 u32 reserved;
726 u64 immediate;
727 } __attribute__((packed));
728
729 /*
730 * Mali Attributes
731 *
732 * This structure lets the attribute unit compute the address of an attribute
733 * given the vertex and instance ID. Unfortunately, the way this works is
734 * rather complicated when instancing is enabled.
735 *
736 * To explain this, first we need to explain how compute and vertex threads are
737 * dispatched. This is a guess (although a pretty firm guess!) since the
738 * details are mostly hidden from the driver, except for attribute instancing.
739 * When a quad is dispatched, it receives a single, linear index. However, we
740 * need to translate that index into a (vertex id, instance id) pair, or a
741 * (local id x, local id y, local id z) triple for compute shaders (although
742 * vertex shaders and compute shaders are handled almost identically).
743 * Focusing on vertex shaders, one option would be to do:
744 *
745 * vertex_id = linear_id % num_vertices
746 * instance_id = linear_id / num_vertices
747 *
748 * but this involves a costly division and modulus by an arbitrary number.
749 * Instead, we could pad num_vertices. We dispatch padded_num_vertices *
750 * num_instances threads instead of num_vertices * num_instances, which results
751 * in some "extra" threads with vertex_id >= num_vertices, which we have to
752 * discard. The more we pad num_vertices, the more "wasted" threads we
753 * dispatch, but the division is potentially easier.
754 *
755 * One straightforward choice is to pad num_vertices to the next power of two,
756 * which means that the division and modulus are just simple bit shifts and
757 * masking. But the actual algorithm is a bit more complicated. The thread
758 * dispatcher has special support for dividing by 3, 5, 7, and 9, in addition
759 * to dividing by a power of two. This is possibly using the technique
760 * described in patent US20170010862A1. As a result, padded_num_vertices can be
761 * 1, 3, 5, 7, or 9 times a power of two. This results in less wasted threads,
762 * since we need less padding.
763 *
764 * padded_num_vertices is picked by the hardware. The driver just specifies the
765 * actual number of vertices. At least for Mali G71, the first few cases are
766 * given by:
767 *
768 * num_vertices | padded_num_vertices
769 * 3 | 4
770 * 4-7 | 8
771 * 8-11 | 12 (3 * 4)
772 * 12-15 | 16
773 * 16-19 | 20 (5 * 4)
774 *
775 * Note that padded_num_vertices is a multiple of four (presumably because
776 * threads are dispatched in groups of 4). Also, padded_num_vertices is always
777 * at least one more than num_vertices, which seems like a quirk of the
778 * hardware. For larger num_vertices, the hardware uses the following
779 * algorithm: using the binary representation of num_vertices, we look at the
780 * most significant set bit as well as the following 3 bits. Let n be the
781 * number of bits after those 4 bits. Then we set padded_num_vertices according
782 * to the following table:
783 *
784 * high bits | padded_num_vertices
785 * 1000 | 9 * 2^n
786 * 1001 | 5 * 2^(n+1)
787 * 101x | 3 * 2^(n+2)
788 * 110x | 7 * 2^(n+1)
789 * 111x | 2^(n+4)
790 *
791 * For example, if num_vertices = 70 is passed to glDraw(), its binary
792 * representation is 1000110, so n = 3 and the high bits are 1000, and
793 * therefore padded_num_vertices = 9 * 2^3 = 72.
794 *
795 * The attribute unit works in terms of the original linear_id. if
796 * num_instances = 1, then they are the same, and everything is simple.
797 * However, with instancing things get more complicated. There are four
798 * possible modes, two of them we can group together:
799 *
800 * 1. Use the linear_id directly. Only used when there is no instancing.
801 *
802 * 2. Use the linear_id modulo a constant. This is used for per-vertex
803 * attributes with instancing enabled by making the constant equal
804 * padded_num_vertices. Because the modulus is always padded_num_vertices, this
805 * mode only supports a modulus that is a power of 2 times 1, 3, 5, 7, or 9.
806 * The shift field specifies the power of two, while the extra_flags field
807 * specifies the odd number. If shift = n and extra_flags = m, then the modulus
808 * is (2m + 1) * 2^n. As an example, if num_vertices = 70, then as computed
809 * above, padded_num_vertices = 9 * 2^3, so we should set extra_flags = 4 and
810 * shift = 3. Note that we must exactly follow the hardware algorithm used to
811 * get padded_num_vertices in order to correctly implement per-vertex
812 * attributes.
813 *
814 * 3. Divide the linear_id by a constant. In order to correctly implement
815 * instance divisors, we have to divide linear_id by padded_num_vertices times
816 * to user-specified divisor. So first we compute padded_num_vertices, again
817 * following the exact same algorithm that the hardware uses, then multiply it
818 * by the GL-level divisor to get the hardware-level divisor. This case is
819 * further divided into two more cases. If the hardware-level divisor is a
820 * power of two, then we just need to shift. The shift amount is specified by
821 * the shift field, so that the hardware-level divisor is just 2^shift.
822 *
823 * If it isn't a power of two, then we have to divide by an arbitrary integer.
824 * For that, we use the well-known technique of multiplying by an approximation
825 * of the inverse. The driver must compute the magic multiplier and shift
826 * amount, and then the hardware does the multiplication and shift. The
827 * hardware and driver also use the "round-down" optimization as described in
828 * http://ridiculousfish.com/files/faster_unsigned_division_by_constants.pdf.
829 * The hardware further assumes the multiplier is between 2^31 and 2^32, so the
830 * high bit is implicitly set to 1 even though it is set to 0 by the driver --
831 * presumably this simplifies the hardware multiplier a little. The hardware
832 * first multiplies linear_id by the multiplier and takes the high 32 bits,
833 * then applies the round-down correction if extra_flags = 1, then finally
834 * shifts right by the shift field.
835 *
836 * There are some differences between ridiculousfish's algorithm and the Mali
837 * hardware algorithm, which means that the reference code from ridiculousfish
838 * doesn't always produce the right constants. Mali does not use the pre-shift
839 * optimization, since that would make a hardware implementation slower (it
840 * would have to always do the pre-shift, multiply, and post-shift operations).
841 * It also forces the multplier to be at least 2^31, which means that the
842 * exponent is entirely fixed, so there is no trial-and-error. Altogether,
843 * given the divisor d, the algorithm the driver must follow is:
844 *
845 * 1. Set shift = floor(log2(d)).
846 * 2. Compute m = ceil(2^(shift + 32) / d) and e = 2^(shift + 32) % d.
847 * 3. If e <= 2^shift, then we need to use the round-down algorithm. Set
848 * magic_divisor = m - 1 and extra_flags = 1.
849 * 4. Otherwise, set magic_divisor = m and extra_flags = 0.
850 *
851 * Unrelated to instancing/actual attributes, images (the OpenCL kind) are
852 * implemented as special attributes, denoted by MALI_ATTR_IMAGE. For images,
853 * let shift=extra_flags=0. Stride is set to the image format's bytes-per-pixel
854 * (*NOT the row stride*). Size is set to the size of the image itself.
855 *
856 * Special internal attribtues and varyings (gl_VertexID, gl_FrontFacing, etc)
857 * use particular fixed addresses with modified structures.
858 */
859
860 enum mali_attr_mode {
861 MALI_ATTR_UNUSED = 0,
862 MALI_ATTR_LINEAR = 1,
863 MALI_ATTR_POT_DIVIDE = 2,
864 MALI_ATTR_MODULO = 3,
865 MALI_ATTR_NPOT_DIVIDE = 4,
866 MALI_ATTR_IMAGE = 5,
867 };
868
869 /* Pseudo-address for gl_VertexID, gl_FragCoord, gl_FrontFacing */
870
871 #define MALI_ATTR_VERTEXID (0x22)
872 #define MALI_ATTR_INSTANCEID (0x24)
873 #define MALI_VARYING_FRAG_COORD (0x25)
874 #define MALI_VARYING_FRONT_FACING (0x26)
875
876 /* This magic "pseudo-address" is used as `elements` to implement
877 * gl_PointCoord. When read from a fragment shader, it generates a point
878 * coordinate per the OpenGL ES 2.0 specification. Flipped coordinate spaces
879 * require an affine transformation in the shader. */
880
881 #define MALI_VARYING_POINT_COORD (0x61)
882
883 /* Used for comparison to check if an address is special. Mostly a guess, but
884 * it doesn't really matter. */
885
886 #define MALI_RECORD_SPECIAL (0x100)
887
888 union mali_attr {
889 /* This is used for actual attributes. */
890 struct {
891 /* The bottom 3 bits are the mode */
892 mali_ptr elements : 64 - 8;
893 u32 shift : 5;
894 u32 extra_flags : 3;
895 u32 stride;
896 u32 size;
897 };
898 /* The entry after an NPOT_DIVIDE entry has this format. It stores
899 * extra information that wouldn't fit in a normal entry.
900 */
901 struct {
902 u32 unk; /* = 0x20 */
903 u32 magic_divisor;
904 u32 zero;
905 /* This is the original, GL-level divisor. */
906 u32 divisor;
907 };
908 } __attribute__((packed));
909
910 struct mali_attr_meta {
911 /* Vertex buffer index */
912 u8 index;
913
914 unsigned unknown1 : 2;
915 unsigned swizzle : 12;
916 enum mali_format format : 8;
917
918 /* Always observed to be zero at the moment */
919 unsigned unknown3 : 2;
920
921 /* When packing multiple attributes in a buffer, offset addresses by
922 * this value. Obscurely, this is signed. */
923 int32_t src_offset;
924 } __attribute__((packed));
925
926 #define FBD_MASK (~0x3f)
927
928 /* MFBD, rather than SFBD */
929 #define MALI_MFBD (0x1)
930
931 /* ORed into an MFBD address to specify the fbx section is included */
932 #define MALI_MFBD_TAG_EXTRA (0x2)
933
934 /* Uniform buffer objects are 64-bit fields divided as:
935 *
936 * u64 size : 10;
937 * mali_ptr ptr : 64 - 10;
938 *
939 * The size is actually the size minus 1 (MALI_POSITIVE), in units of 16 bytes.
940 * This gives a maximum of 2^14 bytes, which just so happens to be the GL
941 * minimum-maximum for GL_MAX_UNIFORM_BLOCK_SIZE.
942 *
943 * The pointer is missing the bottom 2 bits and top 8 bits. The top 8 bits
944 * should be 0 for userspace pointers, according to
945 * https://lwn.net/Articles/718895/. By reusing these bits, we can make each
946 * entry in the table only 64 bits.
947 */
948
949 #define MALI_MAKE_UBO(elements, ptr) \
950 (MALI_POSITIVE((elements)) | (((ptr) >> 2) << 10))
951
952 /* On Bifrost, these fields are the same between the vertex and tiler payloads.
953 * They also seem to be the same between Bifrost and Midgard. They're shared in
954 * fused payloads.
955 */
956
957 /* Applies to unknown_draw */
958
959 #define MALI_DRAW_INDEXED_UINT8 (0x10)
960 #define MALI_DRAW_INDEXED_UINT16 (0x20)
961 #define MALI_DRAW_INDEXED_UINT32 (0x30)
962 #define MALI_DRAW_INDEXED_SIZE (0x30)
963 #define MALI_DRAW_INDEXED_SHIFT (4)
964
965 #define MALI_DRAW_VARYING_SIZE (0x100)
966
967 /* Set to use first vertex as the provoking vertex for flatshading. Clear to
968 * use the last vertex. This is the default in DX and VK, but not in GL. */
969
970 #define MALI_DRAW_FLATSHADE_FIRST (0x800)
971
972 #define MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX (0x10000)
973
974 struct mali_vertex_tiler_prefix {
975 /* This is a dynamic bitfield containing the following things in this order:
976 *
977 * - gl_WorkGroupSize.x
978 * - gl_WorkGroupSize.y
979 * - gl_WorkGroupSize.z
980 * - gl_NumWorkGroups.x
981 * - gl_NumWorkGroups.y
982 * - gl_NumWorkGroups.z
983 *
984 * The number of bits allocated for each number is based on the *_shift
985 * fields below. For example, workgroups_y_shift gives the bit that
986 * gl_NumWorkGroups.y starts at, and workgroups_z_shift gives the bit
987 * that gl_NumWorkGroups.z starts at (and therefore one after the bit
988 * that gl_NumWorkGroups.y ends at). The actual value for each gl_*
989 * value is one more than the stored value, since if any of the values
990 * are zero, then there would be no invocations (and hence no job). If
991 * there were 0 bits allocated to a given field, then it must be zero,
992 * and hence the real value is one.
993 *
994 * Vertex jobs reuse the same job dispatch mechanism as compute jobs,
995 * effectively doing glDispatchCompute(1, vertex_count, instance_count)
996 * where vertex count is the number of vertices.
997 */
998 u32 invocation_count;
999
1000 /* Bitfield for shifts:
1001 *
1002 * size_y_shift : 5
1003 * size_z_shift : 5
1004 * workgroups_x_shift : 6
1005 * workgroups_y_shift : 6
1006 * workgroups_z_shift : 6
1007 * workgroups_x_shift_2 : 4
1008 */
1009 u32 invocation_shifts;
1010
1011 u32 draw_mode : 4;
1012 u32 unknown_draw : 22;
1013
1014 /* This is the the same as workgroups_x_shift_2 in compute shaders, but
1015 * always 5 for vertex jobs and 6 for tiler jobs. I suspect this has
1016 * something to do with how many quads get put in the same execution
1017 * engine, which is a balance (you don't want to starve the engine, but
1018 * you also want to distribute work evenly).
1019 */
1020 u32 workgroups_x_shift_3 : 6;
1021
1022
1023 /* Negative of min_index. This is used to compute
1024 * the unbiased index in tiler/fragment shader runs.
1025 *
1026 * The hardware adds offset_bias_correction in each run,
1027 * so that absent an index bias, the first vertex processed is
1028 * genuinely the first vertex (0). But with an index bias,
1029 * the first vertex process is numbered the same as the bias.
1030 *
1031 * To represent this more conviniently:
1032 * unbiased_index = lower_bound_index +
1033 * index_bias +
1034 * offset_bias_correction
1035 *
1036 * This is done since the hardware doesn't accept a index_bias
1037 * and this allows it to recover the unbiased index.
1038 */
1039 int32_t offset_bias_correction;
1040 u32 zero1;
1041
1042 /* Like many other strictly nonzero quantities, index_count is
1043 * subtracted by one. For an indexed cube, this is equal to 35 = 6
1044 * faces * 2 triangles/per face * 3 vertices/per triangle - 1. That is,
1045 * for an indexed draw, index_count is the number of actual vertices
1046 * rendered whereas invocation_count is the number of unique vertices
1047 * rendered (the number of times the vertex shader must be invoked).
1048 * For non-indexed draws, this is just equal to invocation_count. */
1049
1050 u32 index_count;
1051
1052 /* No hidden structure; literally just a pointer to an array of uint
1053 * indices (width depends on flags). Thanks, guys, for not making my
1054 * life insane for once! NULL for non-indexed draws. */
1055
1056 u64 indices;
1057 } __attribute__((packed));
1058
1059 /* Point size / line width can either be specified as a 32-bit float (for
1060 * constant size) or as a [machine word size]-bit GPU pointer (for varying size). If a pointer
1061 * is selected, by setting the appropriate MALI_DRAW_VARYING_SIZE bit in the tiler
1062 * payload, the contents of varying_pointer will be intepreted as an array of
1063 * fp16 sizes, one for each vertex. gl_PointSize is therefore implemented by
1064 * creating a special MALI_R16F varying writing to varying_pointer. */
1065
1066 union midgard_primitive_size {
1067 float constant;
1068 u64 pointer;
1069 };
1070
1071 struct bifrost_tiler_heap_meta {
1072 u32 zero;
1073 u32 heap_size;
1074 /* note: these are just guesses! */
1075 mali_ptr tiler_heap_start;
1076 mali_ptr tiler_heap_free;
1077 mali_ptr tiler_heap_end;
1078
1079 /* hierarchy weights? but they're still 0 after the job has run... */
1080 u32 zeros[10];
1081 u32 unk1;
1082 u32 unk7e007e;
1083 } __attribute__((packed));
1084
1085 struct bifrost_tiler_meta {
1086 u32 tiler_heap_next_start; /* To be written by the GPU */
1087 u32 used_hierarchy_mask; /* To be written by the GPU */
1088 u16 hierarchy_mask; /* Five values observed: 0xa, 0x14, 0x28, 0x50, 0xa0 */
1089 u16 flags;
1090 u16 width;
1091 u16 height;
1092 u64 zero0;
1093 mali_ptr tiler_heap_meta;
1094 /* TODO what is this used for? */
1095 u64 zeros[20];
1096 } __attribute__((packed));
1097
1098 struct bifrost_tiler_only {
1099 /* 0x20 */
1100 union midgard_primitive_size primitive_size;
1101
1102 mali_ptr tiler_meta;
1103
1104 u64 zero1, zero2, zero3, zero4, zero5, zero6;
1105 } __attribute__((packed));
1106
1107 struct mali_vertex_tiler_postfix {
1108 u16 gl_enables; // 0x6 on Midgard, 0x2 on Bifrost
1109
1110 /* Both zero for non-instanced draws. For instanced draws, a
1111 * decomposition of padded_num_vertices. See the comments about the
1112 * corresponding fields in mali_attr for context. */
1113
1114 unsigned instance_shift : 5;
1115 unsigned instance_odd : 3;
1116
1117 u8 zero4;
1118
1119 /* Offset for first vertex in buffer */
1120 u32 offset_start;
1121
1122 u64 zero5;
1123
1124 /* Zero for vertex jobs. Pointer to the position (gl_Position) varying
1125 * output from the vertex shader for tiler jobs.
1126 */
1127
1128 u64 position_varying;
1129
1130 /* An array of mali_uniform_buffer_meta's. The size is given by the
1131 * shader_meta.
1132 */
1133 u64 uniform_buffers;
1134
1135 /* On Bifrost, this is a pointer to an array of bifrost_texture_descriptor.
1136 * On Midgard, this is a pointer to an array of pointers to the texture
1137 * descriptors, number of pointers bounded by number of textures. The
1138 * indirection is needed to accomodate varying numbers and sizes of
1139 * texture descriptors */
1140 u64 textures;
1141
1142 /* For OpenGL, from what I've seen, this is intimately connected to
1143 * texture_meta. cwabbott says this is not the case under Vulkan, hence
1144 * why this field is seperate (Midgard is Vulkan capable). Pointer to
1145 * array of sampler descriptors (which are uniform in size) */
1146 u64 sampler_descriptor;
1147
1148 u64 uniforms;
1149 u64 shader;
1150 u64 attributes; /* struct attribute_buffer[] */
1151 u64 attribute_meta; /* attribute_meta[] */
1152 u64 varyings; /* struct attr */
1153 u64 varying_meta; /* pointer */
1154 u64 viewport;
1155 u64 occlusion_counter; /* A single bit as far as I can tell */
1156
1157 /* On Bifrost, this points directly to a mali_shared_memory structure.
1158 * On Midgard, this points to a framebuffer (either SFBD or MFBD as
1159 * tagged), which embeds a mali_shared_memory structure */
1160 mali_ptr shared_memory;
1161 } __attribute__((packed));
1162
1163 struct midgard_payload_vertex_tiler {
1164 struct mali_vertex_tiler_prefix prefix;
1165 struct mali_vertex_tiler_postfix postfix;
1166
1167 union midgard_primitive_size primitive_size;
1168 } __attribute__((packed));
1169
1170 struct bifrost_payload_vertex {
1171 struct mali_vertex_tiler_prefix prefix;
1172 struct mali_vertex_tiler_postfix postfix;
1173 } __attribute__((packed));
1174
1175 struct bifrost_payload_tiler {
1176 struct mali_vertex_tiler_prefix prefix;
1177 struct bifrost_tiler_only tiler;
1178 struct mali_vertex_tiler_postfix postfix;
1179 } __attribute__((packed));
1180
1181 struct bifrost_payload_fused {
1182 struct mali_vertex_tiler_prefix prefix;
1183 struct bifrost_tiler_only tiler;
1184 struct mali_vertex_tiler_postfix tiler_postfix;
1185 u64 padding; /* zero */
1186 struct mali_vertex_tiler_postfix vertex_postfix;
1187 } __attribute__((packed));
1188
1189 /* Purposeful off-by-one in width, height fields. For example, a (64, 64)
1190 * texture is stored as (63, 63) in these fields. This adjusts for that.
1191 * There's an identical pattern in the framebuffer descriptor. Even vertex
1192 * count fields work this way, hence the generic name -- integral fields that
1193 * are strictly positive generally need this adjustment. */
1194
1195 #define MALI_POSITIVE(dim) (dim - 1)
1196
1197 /* Used with wrapping. Unclear what top bit conveys */
1198
1199 enum mali_wrap_mode {
1200 MALI_WRAP_REPEAT = 0x8 | 0x0,
1201 MALI_WRAP_CLAMP_TO_EDGE = 0x8 | 0x1,
1202 MALI_WRAP_CLAMP = 0x8 | 0x2,
1203 MALI_WRAP_CLAMP_TO_BORDER = 0x8 | 0x3,
1204 MALI_WRAP_MIRRORED_REPEAT = 0x8 | 0x4 | 0x0,
1205 MALI_WRAP_MIRRORED_CLAMP_TO_EDGE = 0x8 | 0x4 | 0x1,
1206 MALI_WRAP_MIRRORED_CLAMP = 0x8 | 0x4 | 0x2,
1207 MALI_WRAP_MIRRORED_CLAMP_TO_BORDER = 0x8 | 0x4 | 0x3,
1208 };
1209
1210 /* Shared across both command stream and Midgard, and even with Bifrost */
1211
1212 enum mali_texture_type {
1213 MALI_TEX_CUBE = 0x0,
1214 MALI_TEX_1D = 0x1,
1215 MALI_TEX_2D = 0x2,
1216 MALI_TEX_3D = 0x3
1217 };
1218
1219 /* 8192x8192 */
1220 #define MAX_MIP_LEVELS (13)
1221
1222 /* Cubemap bloats everything up */
1223 #define MAX_CUBE_FACES (6)
1224
1225 /* For each pointer, there is an address and optionally also a stride */
1226 #define MAX_ELEMENTS (2)
1227
1228 /* It's not known why there are 4-bits allocated -- this enum is almost
1229 * certainly incomplete */
1230
1231 enum mali_texture_layout {
1232 /* For a Z/S texture, this is linear */
1233 MALI_TEXTURE_TILED = 0x1,
1234
1235 /* Z/S textures cannot be tiled */
1236 MALI_TEXTURE_LINEAR = 0x2,
1237
1238 /* 16x16 sparse */
1239 MALI_TEXTURE_AFBC = 0xC
1240 };
1241
1242 /* Corresponds to the type passed to glTexImage2D and so forth */
1243
1244 struct mali_texture_format {
1245 unsigned swizzle : 12;
1246 enum mali_format format : 8;
1247
1248 unsigned srgb : 1;
1249 unsigned unknown1 : 1;
1250
1251 enum mali_texture_type type : 2;
1252 enum mali_texture_layout layout : 4;
1253
1254 /* Always set */
1255 unsigned unknown2 : 1;
1256
1257 /* Set to allow packing an explicit stride */
1258 unsigned manual_stride : 1;
1259
1260 unsigned zero : 2;
1261 } __attribute__((packed));
1262
1263 struct mali_texture_descriptor {
1264 uint16_t width;
1265 uint16_t height;
1266 uint16_t depth;
1267 uint16_t array_size;
1268
1269 struct mali_texture_format format;
1270
1271 uint16_t unknown3;
1272
1273 /* One for non-mipmapped, zero for mipmapped */
1274 uint8_t unknown3A;
1275
1276 /* Zero for non-mipmapped, (number of levels - 1) for mipmapped */
1277 uint8_t levels;
1278
1279 /* Swizzling is a single 32-bit word, broken up here for convenience.
1280 * Here, swizzling refers to the ES 3.0 texture parameters for channel
1281 * level swizzling, not the internal pixel-level swizzling which is
1282 * below OpenGL's reach */
1283
1284 unsigned swizzle : 12;
1285 unsigned swizzle_zero : 20;
1286
1287 uint32_t unknown5;
1288 uint32_t unknown6;
1289 uint32_t unknown7;
1290 } __attribute__((packed));
1291
1292 /* While Midgard texture descriptors are variable length, Bifrost descriptors
1293 * are fixed like samplers with more pointers to expand if necessary */
1294
1295 struct bifrost_texture_descriptor {
1296 unsigned format_unk : 4; /* 2 */
1297 enum mali_texture_type type : 2;
1298 unsigned zero : 4;
1299 unsigned format_swizzle : 12;
1300 enum mali_format format : 8;
1301 unsigned srgb : 1;
1302 unsigned format_unk3 : 1; /* 0 */
1303
1304 uint16_t width; /* MALI_POSITIVE */
1305 uint16_t height; /* MALI_POSITIVE */
1306
1307 /* OpenGL swizzle */
1308 unsigned swizzle : 12;
1309 enum mali_texture_layout layout : 4;
1310 uint8_t levels : 8; /* Number of levels-1 if mipmapped, 0 if not */
1311 unsigned unk1 : 8;
1312
1313 unsigned levels_unk : 24; /* 0 */
1314 unsigned level_2 : 8; /* Number of levels, again? */
1315
1316 mali_ptr payload;
1317
1318 uint16_t array_size;
1319 uint16_t unk4;
1320
1321 uint16_t depth;
1322 uint16_t unk5;
1323 } __attribute__((packed));
1324
1325 /* filter_mode */
1326
1327 #define MALI_SAMP_MAG_NEAREST (1 << 0)
1328 #define MALI_SAMP_MIN_NEAREST (1 << 1)
1329
1330 /* TODO: What do these bits mean individually? Only seen set together */
1331
1332 #define MALI_SAMP_MIP_LINEAR_1 (1 << 3)
1333 #define MALI_SAMP_MIP_LINEAR_2 (1 << 4)
1334
1335 /* Flag in filter_mode, corresponding to OpenCL's NORMALIZED_COORDS_TRUE
1336 * sampler_t flag. For typical OpenGL textures, this is always set. */
1337
1338 #define MALI_SAMP_NORM_COORDS (1 << 5)
1339
1340 /* Used for lod encoding. Thanks @urjaman for pointing out these routines can
1341 * be cleaned up a lot. */
1342
1343 #define DECODE_FIXED_16(x) ((float) (x / 256.0))
1344
1345 static inline int16_t
1346 FIXED_16(float x, bool allow_negative)
1347 {
1348 /* Clamp inputs, accounting for float error */
1349 float max_lod = (32.0 - (1.0 / 512.0));
1350 float min_lod = allow_negative ? -max_lod : 0.0;
1351
1352 x = ((x > max_lod) ? max_lod : ((x < min_lod) ? min_lod : x));
1353
1354 return (int) (x * 256.0);
1355 }
1356
1357 struct mali_sampler_descriptor {
1358 uint16_t filter_mode;
1359
1360 /* Fixed point, signed.
1361 * Upper 7 bits before the decimal point, although it caps [0-31].
1362 * Lower 8 bits after the decimal point: int(round(x * 256)) */
1363
1364 int16_t lod_bias;
1365 int16_t min_lod;
1366 int16_t max_lod;
1367
1368 /* All one word in reality, but packed a bit. Comparisons are flipped
1369 * from OpenGL. */
1370
1371 enum mali_wrap_mode wrap_s : 4;
1372 enum mali_wrap_mode wrap_t : 4;
1373 enum mali_wrap_mode wrap_r : 4;
1374 enum mali_func compare_func : 3;
1375
1376 /* No effect on 2D textures. For cubemaps, set for ES3 and clear for
1377 * ES2, controlling seamless cubemapping */
1378 unsigned seamless_cube_map : 1;
1379
1380 unsigned zero : 16;
1381
1382 uint32_t zero2;
1383 float border_color[4];
1384 } __attribute__((packed));
1385
1386 /* Bifrost sampler descriptors look pretty similar */
1387
1388 #define BIFROST_SAMP_MIN_NEAREST (1)
1389 #define BIFROST_SAMP_MAG_LINEAR (1)
1390
1391 struct bifrost_sampler_descriptor {
1392 uint8_t unk1;
1393
1394 enum mali_wrap_mode wrap_r : 4;
1395 enum mali_wrap_mode wrap_t : 4;
1396 enum mali_wrap_mode wrap_s : 4;
1397 uint8_t unk8 : 4;
1398
1399 uint8_t unk2 : 1;
1400 uint8_t norm_coords : 1;
1401 uint8_t unk3 : 1;
1402 uint8_t min_filter : 1;
1403 uint8_t zero1 : 1;
1404 uint8_t mag_filter : 1;
1405 uint8_t mip_filter : 1;
1406
1407 int16_t min_lod;
1408 int16_t max_lod;
1409
1410 uint64_t zero2;
1411 uint64_t zero3;
1412 uint64_t zero4;
1413 } __attribute__((packed));
1414
1415 /* viewport0/viewport1 form the arguments to glViewport. viewport1 is
1416 * modified by MALI_POSITIVE; viewport0 is as-is.
1417 */
1418
1419 struct mali_viewport {
1420 /* XY clipping planes */
1421 float clip_minx;
1422 float clip_miny;
1423 float clip_maxx;
1424 float clip_maxy;
1425
1426 /* Depth clipping planes */
1427 float clip_minz;
1428 float clip_maxz;
1429
1430 u16 viewport0[2];
1431 u16 viewport1[2];
1432 } __attribute__((packed));
1433
1434 /* From presentations, 16x16 tiles externally. Use shift for fast computation
1435 * of tile numbers. */
1436
1437 #define MALI_TILE_SHIFT 4
1438 #define MALI_TILE_LENGTH (1 << MALI_TILE_SHIFT)
1439
1440 /* Tile coordinates are stored as a compact u32, as only 12 bits are needed to
1441 * each component. Notice that this provides a theoretical upper bound of (1 <<
1442 * 12) = 4096 tiles in each direction, addressing a maximum framebuffer of size
1443 * 65536x65536. Multiplying that together, times another four given that Mali
1444 * framebuffers are 32-bit ARGB8888, means that this upper bound would take 16
1445 * gigabytes of RAM just to store the uncompressed framebuffer itself, let
1446 * alone rendering in real-time to such a buffer.
1447 *
1448 * Nice job, guys.*/
1449
1450 /* From mali_kbase_10969_workaround.c */
1451 #define MALI_X_COORD_MASK 0x00000FFF
1452 #define MALI_Y_COORD_MASK 0x0FFF0000
1453
1454 /* Extract parts of a tile coordinate */
1455
1456 #define MALI_TILE_COORD_X(coord) ((coord) & MALI_X_COORD_MASK)
1457 #define MALI_TILE_COORD_Y(coord) (((coord) & MALI_Y_COORD_MASK) >> 16)
1458
1459 /* Helpers to generate tile coordinates based on the boundary coordinates in
1460 * screen space. So, with the bounds (0, 0) to (128, 128) for the screen, these
1461 * functions would convert it to the bounding tiles (0, 0) to (7, 7).
1462 * Intentional "off-by-one"; finding the tile number is a form of fencepost
1463 * problem. */
1464
1465 #define MALI_MAKE_TILE_COORDS(X, Y) ((X) | ((Y) << 16))
1466 #define MALI_BOUND_TO_TILE(B, bias) ((B - bias) >> MALI_TILE_SHIFT)
1467 #define MALI_COORDINATE_TO_TILE(W, H, bias) MALI_MAKE_TILE_COORDS(MALI_BOUND_TO_TILE(W, bias), MALI_BOUND_TO_TILE(H, bias))
1468 #define MALI_COORDINATE_TO_TILE_MIN(W, H) MALI_COORDINATE_TO_TILE(W, H, 0)
1469 #define MALI_COORDINATE_TO_TILE_MAX(W, H) MALI_COORDINATE_TO_TILE(W, H, 1)
1470
1471 struct mali_payload_fragment {
1472 u32 min_tile_coord;
1473 u32 max_tile_coord;
1474 mali_ptr framebuffer;
1475 } __attribute__((packed));
1476
1477 /* Single Framebuffer Descriptor */
1478
1479 /* Flags apply to format. With just MSAA_A and MSAA_B, the framebuffer is
1480 * configured for 4x. With MSAA_8, it is configured for 8x. */
1481
1482 #define MALI_SFBD_FORMAT_MSAA_8 (1 << 3)
1483 #define MALI_SFBD_FORMAT_MSAA_A (1 << 4)
1484 #define MALI_SFBD_FORMAT_MSAA_B (1 << 4)
1485 #define MALI_SFBD_FORMAT_SRGB (1 << 5)
1486
1487 /* Fast/slow based on whether all three buffers are cleared at once */
1488
1489 #define MALI_CLEAR_FAST (1 << 18)
1490 #define MALI_CLEAR_SLOW (1 << 28)
1491 #define MALI_CLEAR_SLOW_STENCIL (1 << 31)
1492
1493 /* Configures hierarchical tiling on Midgard for both SFBD/MFBD (embedded
1494 * within the larget framebuffer descriptor). Analogous to
1495 * bifrost_tiler_heap_meta and bifrost_tiler_meta*/
1496
1497 /* See pan_tiler.c for derivation */
1498 #define MALI_HIERARCHY_MASK ((1 << 9) - 1)
1499
1500 /* Flag disabling the tiler for clear-only jobs, with
1501 hierarchical tiling */
1502 #define MALI_TILER_DISABLED (1 << 12)
1503
1504 /* Flag selecting userspace-generated polygon list, for clear-only jobs without
1505 * hierarhical tiling. */
1506 #define MALI_TILER_USER 0xFFF
1507
1508 /* Absent any geometry, the minimum size of the polygon list header */
1509 #define MALI_TILER_MINIMUM_HEADER_SIZE 0x200
1510
1511 struct midgard_tiler_descriptor {
1512 /* Size of the entire polygon list; see pan_tiler.c for the
1513 * computation. It's based on hierarchical tiling */
1514
1515 u32 polygon_list_size;
1516
1517 /* Name known from the replay workaround in the kernel. What exactly is
1518 * flagged here is less known. We do that (tiler_hierarchy_mask & 0x1ff)
1519 * specifies a mask of hierarchy weights, which explains some of the
1520 * performance mysteries around setting it. We also see the bottom bit
1521 * of tiler_flags set in the kernel, but no comment why.
1522 *
1523 * hierarchy_mask can have the TILER_DISABLED flag */
1524
1525 u16 hierarchy_mask;
1526 u16 flags;
1527
1528 /* See mali_tiler.c for an explanation */
1529 mali_ptr polygon_list;
1530 mali_ptr polygon_list_body;
1531
1532 /* Names based on we see symmetry with replay jobs which name these
1533 * explicitly */
1534
1535 mali_ptr heap_start; /* tiler heap_free_address */
1536 mali_ptr heap_end;
1537
1538 /* Hierarchy weights. We know these are weights based on the kernel,
1539 * but I've never seen them be anything other than zero */
1540 u32 weights[8];
1541 };
1542
1543 enum mali_block_format {
1544 MALI_BLOCK_TILED = 0x0,
1545 MALI_BLOCK_UNKNOWN = 0x1,
1546 MALI_BLOCK_LINEAR = 0x2,
1547 MALI_BLOCK_AFBC = 0x3,
1548 };
1549
1550 struct mali_sfbd_format {
1551 /* 0x1 */
1552 unsigned unk1 : 6;
1553
1554 /* mali_channel_swizzle */
1555 unsigned swizzle : 12;
1556
1557 /* MALI_POSITIVE */
1558 unsigned nr_channels : 2;
1559
1560 /* 0x4 */
1561 unsigned unk2 : 6;
1562
1563 enum mali_block_format block : 2;
1564
1565 /* 0xb */
1566 unsigned unk3 : 4;
1567 };
1568
1569 /* Shared structure at the start of framebuffer descriptors, or used bare for
1570 * compute jobs, configuring stack and shared memory */
1571
1572 struct mali_shared_memory {
1573 u32 stack_shift : 4;
1574 u32 unk0 : 28;
1575
1576 /* Configuration for shared memory for compute shaders.
1577 * shared_workgroup_count is logarithmic and may be computed for a
1578 * compute shader using shared memory as:
1579 *
1580 * shared_workgroup_count = MAX2(ceil(log2(count_x)) + ... + ceil(log2(count_z), 10)
1581 *
1582 * For compute shaders that don't use shared memory, or non-compute
1583 * shaders, this is set to ~0
1584 */
1585
1586 u32 shared_workgroup_count : 5;
1587 u32 shared_unk1 : 3;
1588 u32 shared_shift : 4;
1589 u32 shared_zero : 20;
1590
1591 mali_ptr scratchpad;
1592
1593 /* For compute shaders, the RAM backing of workgroup-shared memory. For
1594 * fragment shaders on Bifrost, apparently multisampling locations */
1595
1596 mali_ptr shared_memory;
1597 mali_ptr unknown1;
1598 } __attribute__((packed));
1599
1600 /* Configures multisampling on Bifrost fragment jobs */
1601
1602 struct bifrost_multisampling {
1603 u64 zero1;
1604 u64 zero2;
1605 mali_ptr sample_locations;
1606 u64 zero4;
1607 } __attribute__((packed));
1608
1609 struct mali_single_framebuffer {
1610 struct mali_shared_memory shared_memory;
1611 struct mali_sfbd_format format;
1612
1613 u32 clear_flags;
1614 u32 zero2;
1615
1616 /* Purposeful off-by-one in these fields should be accounted for by the
1617 * MALI_DIMENSION macro */
1618
1619 u16 width;
1620 u16 height;
1621
1622 u32 zero3[4];
1623 mali_ptr checksum;
1624 u32 checksum_stride;
1625 u32 zero5;
1626
1627 /* By default, the framebuffer is upside down from OpenGL's
1628 * perspective. Set framebuffer to the end and negate the stride to
1629 * flip in the Y direction */
1630
1631 mali_ptr framebuffer;
1632 int32_t stride;
1633
1634 u32 zero4;
1635
1636 /* Depth and stencil buffers are interleaved, it appears, as they are
1637 * set to the same address in captures. Both fields set to zero if the
1638 * buffer is not being cleared. Depending on GL_ENABLE magic, you might
1639 * get a zero enable despite the buffer being present; that still is
1640 * disabled. */
1641
1642 mali_ptr depth_buffer; // not SAME_VA
1643 u32 depth_stride_zero : 4;
1644 u32 depth_stride : 28;
1645 u32 zero7;
1646
1647 mali_ptr stencil_buffer; // not SAME_VA
1648 u32 stencil_stride_zero : 4;
1649 u32 stencil_stride : 28;
1650 u32 zero8;
1651
1652 u32 clear_color_1; // RGBA8888 from glClear, actually used by hardware
1653 u32 clear_color_2; // always equal, but unclear function?
1654 u32 clear_color_3; // always equal, but unclear function?
1655 u32 clear_color_4; // always equal, but unclear function?
1656
1657 /* Set to zero if not cleared */
1658
1659 float clear_depth_1; // float32, ditto
1660 float clear_depth_2; // float32, ditto
1661 float clear_depth_3; // float32, ditto
1662 float clear_depth_4; // float32, ditto
1663
1664 u32 clear_stencil; // Exactly as it appears in OpenGL
1665
1666 u32 zero6[7];
1667
1668 struct midgard_tiler_descriptor tiler;
1669
1670 /* More below this, maybe */
1671 } __attribute__((packed));
1672
1673 /* Format bits for the render target flags. Setting MSAA alone works for on
1674 * chip MSAA. Setting MSAA with the LAYERED flag works for MSAA where each
1675 * sample is its own image (implements the ES3 spec directly but inefficient on
1676 * mobile). */
1677
1678 #define MALI_MFBD_FORMAT_LAYERED (1 << 0)
1679 #define MALI_MFBD_FORMAT_MSAA (1 << 1)
1680 #define MALI_MFBD_FORMAT_SRGB (1 << 2)
1681
1682 struct mali_rt_format {
1683 unsigned unk1 : 32;
1684 unsigned unk2 : 3;
1685
1686 unsigned nr_channels : 2; /* MALI_POSITIVE */
1687
1688 unsigned unk3 : 4;
1689 unsigned unk4 : 1;
1690 enum mali_block_format block : 2;
1691 unsigned flags : 4;
1692
1693 unsigned swizzle : 12;
1694
1695 unsigned zero : 3;
1696
1697 /* Disables MFBD preload. When this bit is set, the render target will
1698 * be cleared every frame. When this bit is clear, the hardware will
1699 * automatically wallpaper the render target back from main memory.
1700 * Unfortunately, MFBD preload is very broken on Midgard, so in
1701 * practice, this is a chicken bit that should always be set.
1702 * Discovered by accident, as all good chicken bits are. */
1703
1704 unsigned no_preload : 1;
1705 } __attribute__((packed));
1706
1707 /* Flags for afbc.flags and ds_afbc.flags */
1708
1709 #define MALI_AFBC_FLAGS 0x10009
1710
1711 /* Lossless RGB and RGBA colorspace transform */
1712 #define MALI_AFBC_YTR (1 << 17)
1713
1714 struct mali_render_target {
1715 struct mali_rt_format format;
1716
1717 u64 zero1;
1718
1719 struct {
1720 /* Stuff related to ARM Framebuffer Compression. When AFBC is enabled,
1721 * there is an extra metadata buffer that contains 16 bytes per tile.
1722 * The framebuffer needs to be the same size as before, since we don't
1723 * know ahead of time how much space it will take up. The
1724 * framebuffer_stride is set to 0, since the data isn't stored linearly
1725 * anymore.
1726 *
1727 * When AFBC is disabled, these fields are zero.
1728 */
1729
1730 mali_ptr metadata;
1731 u32 stride; // stride in units of tiles
1732 u32 flags; // = 0x20000
1733 } afbc;
1734
1735 mali_ptr framebuffer;
1736
1737 u32 zero2 : 4;
1738 u32 framebuffer_stride : 28; // in units of bytes, row to next
1739 u32 layer_stride; /* For multisample rendering */
1740
1741 u32 clear_color_1; // RGBA8888 from glClear, actually used by hardware
1742 u32 clear_color_2; // always equal, but unclear function?
1743 u32 clear_color_3; // always equal, but unclear function?
1744 u32 clear_color_4; // always equal, but unclear function?
1745 } __attribute__((packed));
1746
1747 /* An optional part of mali_framebuffer. It comes between the main structure
1748 * and the array of render targets. It must be included if any of these are
1749 * enabled:
1750 *
1751 * - Transaction Elimination
1752 * - Depth/stencil
1753 * - TODO: Anything else?
1754 */
1755
1756 /* flags_hi */
1757 #define MALI_EXTRA_PRESENT (0x10)
1758
1759 /* flags_lo */
1760 #define MALI_EXTRA_ZS (0x4)
1761
1762 struct mali_framebuffer_extra {
1763 mali_ptr checksum;
1764 /* Each tile has an 8 byte checksum, so the stride is "width in tiles * 8" */
1765 u32 checksum_stride;
1766
1767 unsigned flags_lo : 4;
1768 enum mali_block_format zs_block : 2;
1769 unsigned flags_hi : 26;
1770
1771 union {
1772 /* Note: AFBC is only allowed for 24/8 combined depth/stencil. */
1773 struct {
1774 mali_ptr depth_stencil_afbc_metadata;
1775 u32 depth_stencil_afbc_stride; // in units of tiles
1776 u32 flags;
1777
1778 mali_ptr depth_stencil;
1779
1780 u64 padding;
1781 } ds_afbc;
1782
1783 struct {
1784 /* Depth becomes depth/stencil in case of combined D/S */
1785 mali_ptr depth;
1786 u32 depth_stride_zero : 4;
1787 u32 depth_stride : 28;
1788 u32 zero1;
1789
1790 mali_ptr stencil;
1791 u32 stencil_stride_zero : 4;
1792 u32 stencil_stride : 28;
1793 u32 zero2;
1794 } ds_linear;
1795 };
1796
1797
1798 u32 clear_color_1;
1799 u32 clear_color_2;
1800 u64 zero3;
1801 } __attribute__((packed));
1802
1803 /* Flags for mfbd_flags */
1804
1805 /* Enables writing depth results back to main memory (rather than keeping them
1806 * on-chip in the tile buffer and then discarding) */
1807
1808 #define MALI_MFBD_DEPTH_WRITE (1 << 10)
1809
1810 /* The MFBD contains the extra mali_framebuffer_extra section */
1811
1812 #define MALI_MFBD_EXTRA (1 << 13)
1813
1814 struct mali_framebuffer {
1815 union {
1816 struct mali_shared_memory shared_memory;
1817 struct bifrost_multisampling msaa;
1818 };
1819
1820 /* 0x20 */
1821 u16 width1, height1;
1822 u32 zero3;
1823 u16 width2, height2;
1824 u32 unk1 : 19; // = 0x01000
1825 u32 rt_count_1 : 2; // off-by-one (use MALI_POSITIVE)
1826 u32 unk2 : 3; // = 0
1827 u32 rt_count_2 : 3; // no off-by-one
1828 u32 zero4 : 5;
1829 /* 0x30 */
1830 u32 clear_stencil : 8;
1831 u32 mfbd_flags : 24; // = 0x100
1832 float clear_depth;
1833
1834 union {
1835 struct midgard_tiler_descriptor tiler;
1836 struct {
1837 mali_ptr tiler_meta;
1838 u32 zeros[16];
1839 };
1840 };
1841
1842 /* optional: struct mali_framebuffer_extra extra */
1843 /* struct mali_render_target rts[] */
1844 } __attribute__((packed));
1845
1846 #endif /* __PANFROST_JOB_H__ */