2 * © Copyright 2018 Alyssa Rosenzweig
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 "pan_context.h"
29 #include "pan_swizzle.h"
30 #include "pan_format.h"
32 #include "util/macros.h"
33 #include "util/u_format.h"
34 #include "util/u_inlines.h"
35 #include "util/u_upload_mgr.h"
36 #include "util/u_memory.h"
37 #include "util/half_float.h"
38 #include "indices/u_primconvert.h"
39 #include "tgsi/tgsi_parse.h"
41 #include "pan_screen.h"
42 #include "pan_blending.h"
43 #include "pan_blend_shaders.h"
44 #include "pan_wallpaper.h"
46 #ifdef DUMP_PERFORMANCE_COUNTERS
47 static int performance_counter_number
= 0;
50 /* Do not actually send anything to the GPU; merely generate the cmdstream as fast as possible. Disables framebuffer writes */
53 #define SET_BIT(lval, bit, cond) \
59 /* TODO: Sample size, etc */
62 panfrost_set_framebuffer_msaa(struct panfrost_context
*ctx
, bool enabled
)
64 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_HAS_MSAA
, enabled
);
65 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_NO_MSAA
, !enabled
);
68 SET_BIT(ctx
->fragment_fbd
.format
, MALI_FRAMEBUFFER_MSAA_A
| MALI_FRAMEBUFFER_MSAA_B
, enabled
);
70 SET_BIT(ctx
->fragment_rts
[0].format
, MALI_MFBD_FORMAT_MSAA
, enabled
);
72 SET_BIT(ctx
->fragment_fbd
.unk1
, (1 << 4) | (1 << 1), enabled
);
75 ctx
->fragment_fbd
.rt_count_2
= enabled
? 4 : 1;
79 /* AFBC is enabled on a per-resource basis (AFBC enabling is theoretically
80 * indepdent between color buffers and depth/stencil). To enable, we allocate
81 * the AFBC metadata buffer and mark that it is enabled. We do -not- actually
82 * edit the fragment job here. This routine should be called ONCE per
83 * AFBC-compressed buffer, rather than on every frame. */
86 panfrost_enable_afbc(struct panfrost_context
*ctx
, struct panfrost_resource
*rsrc
, bool ds
)
89 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
90 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
91 /* AFBC metadata is 16 bytes per tile */
92 int tile_w
= (rsrc
->base
.width0
+ (MALI_TILE_LENGTH
- 1)) >> MALI_TILE_SHIFT
;
93 int tile_h
= (rsrc
->base
.height0
+ (MALI_TILE_LENGTH
- 1)) >> MALI_TILE_SHIFT
;
94 int bytes_per_pixel
= util_format_get_blocksize(rsrc
->base
.format
);
95 int stride
= bytes_per_pixel
* rsrc
->base
.width0
; /* TODO: Alignment? */
97 stride
*= 2; /* TODO: Should this be carried over? */
98 int main_size
= stride
* rsrc
->base
.height0
;
99 rsrc
->bo
->afbc_metadata_size
= tile_w
* tile_h
* 16;
101 /* Allocate the AFBC slab itself, large enough to hold the above */
102 screen
->driver
->allocate_slab(screen
, &rsrc
->bo
->afbc_slab
,
103 (rsrc
->bo
->afbc_metadata_size
+ main_size
+ 4095) / 4096,
106 rsrc
->bo
->has_afbc
= true;
108 /* Compressed textured reads use a tagged pointer to the metadata */
110 rsrc
->bo
->gpu
[0] = rsrc
->bo
->afbc_slab
.gpu
| (ds
? 0 : 1);
111 rsrc
->bo
->cpu
[0] = rsrc
->bo
->afbc_slab
.cpu
;
113 printf("AFBC not supported yet on SFBD\n");
119 panfrost_enable_checksum(struct panfrost_context
*ctx
, struct panfrost_resource
*rsrc
)
121 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
122 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
123 int tile_w
= (rsrc
->base
.width0
+ (MALI_TILE_LENGTH
- 1)) >> MALI_TILE_SHIFT
;
124 int tile_h
= (rsrc
->base
.height0
+ (MALI_TILE_LENGTH
- 1)) >> MALI_TILE_SHIFT
;
126 /* 8 byte checksum per tile */
127 rsrc
->bo
->checksum_stride
= tile_w
* 8;
128 int pages
= (((rsrc
->bo
->checksum_stride
* tile_h
) + 4095) / 4096);
129 screen
->driver
->allocate_slab(screen
, &rsrc
->bo
->checksum_slab
, pages
, false, 0, 0, 0);
131 rsrc
->bo
->has_checksum
= true;
134 /* ..by contrast, this routine runs for every FRAGMENT job, but does no
135 * allocation. AFBC is enabled on a per-surface basis */
138 panfrost_set_fragment_afbc(struct panfrost_context
*ctx
)
140 for (int cb
= 0; cb
< ctx
->pipe_framebuffer
.nr_cbufs
; ++cb
) {
141 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) ctx
->pipe_framebuffer
.cbufs
[cb
]->texture
;
143 /* Non-AFBC is the default */
144 if (!rsrc
->bo
->has_afbc
)
147 /* Enable AFBC for the render target */
148 ctx
->fragment_rts
[0].afbc
.metadata
= rsrc
->bo
->afbc_slab
.gpu
;
149 ctx
->fragment_rts
[0].afbc
.stride
= 0;
150 ctx
->fragment_rts
[0].afbc
.unk
= 0x30009;
152 ctx
->fragment_rts
[0].format
|= MALI_MFBD_FORMAT_AFBC
;
154 /* Change colourspace from RGB to BGR? */
156 ctx
->fragment_rts
[0].format
|= 0x800000;
157 ctx
->fragment_rts
[0].format
&= ~0x20000;
160 /* Point rendering to our special framebuffer */
161 ctx
->fragment_rts
[0].framebuffer
= rsrc
->bo
->afbc_slab
.gpu
+ rsrc
->bo
->afbc_metadata_size
;
163 /* WAT? Stride is diff from the scanout case */
164 ctx
->fragment_rts
[0].framebuffer_stride
= ctx
->pipe_framebuffer
.width
* 2 * 4;
167 /* Enable depth/stencil AFBC for the framebuffer (not the render target) */
168 if (ctx
->pipe_framebuffer
.zsbuf
) {
169 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) ctx
->pipe_framebuffer
.zsbuf
->texture
;
171 if (rsrc
->bo
->has_afbc
) {
172 ctx
->fragment_fbd
.unk3
|= MALI_MFBD_EXTRA
;
174 ctx
->fragment_extra
.ds_afbc
.depth_stencil_afbc_metadata
= rsrc
->bo
->afbc_slab
.gpu
;
175 ctx
->fragment_extra
.ds_afbc
.depth_stencil_afbc_stride
= 0;
177 ctx
->fragment_extra
.ds_afbc
.depth_stencil
= rsrc
->bo
->afbc_slab
.gpu
+ rsrc
->bo
->afbc_metadata_size
;
179 ctx
->fragment_extra
.ds_afbc
.zero1
= 0x10009;
180 ctx
->fragment_extra
.ds_afbc
.padding
= 0x1000;
182 ctx
->fragment_extra
.unk
= 0x435; /* General 0x400 in all unks. 0x5 for depth/stencil. 0x10 for AFBC encoded depth stencil. Unclear where the 0x20 is from */
184 ctx
->fragment_fbd
.unk3
|= 0x400;
188 /* For the special case of a depth-only FBO, we need to attach a dummy render target */
190 if (ctx
->pipe_framebuffer
.nr_cbufs
== 0) {
191 ctx
->fragment_rts
[0].format
= 0x80008000;
192 ctx
->fragment_rts
[0].framebuffer
= 0;
193 ctx
->fragment_rts
[0].framebuffer_stride
= 0;
197 /* Framebuffer descriptor */
201 panfrost_set_framebuffer_resolution(struct mali_single_framebuffer
*fb
, int w
, int h
)
203 fb
->width
= MALI_POSITIVE(w
);
204 fb
->height
= MALI_POSITIVE(h
);
206 /* No idea why this is needed, but it's how resolution_check is
207 * calculated. It's not clear to us yet why the hardware wants this.
208 * The formula itself was discovered mostly by manual bruteforce and
209 * aggressive algebraic simplification. */
211 fb
->resolution_check
= ((w
+ h
) / 3) << 4;
215 static PANFROST_FRAMEBUFFER
216 panfrost_emit_fbd(struct panfrost_context
*ctx
)
219 struct mali_single_framebuffer framebuffer
= {
221 .format
= 0x30000000,
222 .clear_flags
= 0x1000,
223 .unknown_address_0
= ctx
->scratchpad
.gpu
,
224 .unknown_address_1
= ctx
->scratchpad
.gpu
+ 0x6000,
225 .unknown_address_2
= ctx
->scratchpad
.gpu
+ 0x6200,
227 .tiler_heap_free
= ctx
->tiler_heap
.gpu
,
228 .tiler_heap_end
= ctx
->tiler_heap
.gpu
+ ctx
->tiler_heap
.size
,
231 panfrost_set_framebuffer_resolution(&framebuffer
, ctx
->pipe_framebuffer
.width
, ctx
->pipe_framebuffer
.height
);
233 struct bifrost_framebuffer framebuffer
= {
234 .tiler_meta
= 0xf00000c600,
236 .width1
= MALI_POSITIVE(ctx
->pipe_framebuffer
.width
),
237 .height1
= MALI_POSITIVE(ctx
->pipe_framebuffer
.height
),
238 .width2
= MALI_POSITIVE(ctx
->pipe_framebuffer
.width
),
239 .height2
= MALI_POSITIVE(ctx
->pipe_framebuffer
.height
),
244 .rt_count_1
= MALI_POSITIVE(1),
249 /* Presumably corresponds to unknown_address_X of SFBD */
250 .scratchpad
= ctx
->scratchpad
.gpu
,
251 .tiler_scratch_start
= ctx
->misc_0
.gpu
,
252 .tiler_scratch_middle
= ctx
->misc_0
.gpu
+ /*ctx->misc_0.size*/40960, /* Size depends on the size of the framebuffer and the number of vertices */
254 .tiler_heap_start
= ctx
->tiler_heap
.gpu
,
255 .tiler_heap_end
= ctx
->tiler_heap
.gpu
+ ctx
->tiler_heap
.size
,
263 /* Are we currently rendering to the screen (rather than an FBO)? */
266 panfrost_is_scanout(struct panfrost_context
*ctx
)
268 /* If there is no color buffer, it's an FBO */
269 if (!ctx
->pipe_framebuffer
.nr_cbufs
)
272 /* If we're too early that no framebuffer was sent, it's scanout */
273 if (!ctx
->pipe_framebuffer
.cbufs
[0])
276 return ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_DISPLAY_TARGET
||
277 ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_SCANOUT
||
278 ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_SHARED
;
281 /* The above function is for generalised fbd emission, used in both fragment as
282 * well as vertex/tiler payloads. This payload is specific to fragment
286 panfrost_new_frag_framebuffer(struct panfrost_context
*ctx
)
288 mali_ptr framebuffer
;
291 if (ctx
->pipe_framebuffer
.nr_cbufs
> 0) {
292 framebuffer
= ((struct panfrost_resource
*) ctx
->pipe_framebuffer
.cbufs
[0]->texture
)->bo
->gpu
[0];
293 stride
= util_format_get_stride(ctx
->pipe_framebuffer
.cbufs
[0]->format
, ctx
->pipe_framebuffer
.width
);
295 /* Depth-only framebuffer -> dummy RT */
300 /* The default is upside down from OpenGL's perspective. */
301 if (panfrost_is_scanout(ctx
)) {
302 framebuffer
+= stride
* (ctx
->pipe_framebuffer
.height
- 1);
307 struct mali_single_framebuffer fb
= panfrost_emit_fbd(ctx
);
309 fb
.framebuffer
= framebuffer
;
312 fb
.format
= 0xb84e0281; /* RGB32, no MSAA */
314 struct bifrost_framebuffer fb
= panfrost_emit_fbd(ctx
);
320 struct bifrost_render_target rt
= {
322 .format
= 0x860a8899, /* RGBA32, no MSAA */
323 .framebuffer
= framebuffer
,
324 .framebuffer_stride
= (stride
/ 16) & 0xfffffff,
327 memcpy(&ctx
->fragment_rts
[0], &rt
, sizeof(rt
));
329 memset(&ctx
->fragment_extra
, 0, sizeof(ctx
->fragment_extra
));
332 memcpy(&ctx
->fragment_fbd
, &fb
, sizeof(fb
));
335 /* Maps float 0.0-1.0 to int 0x00-0xFF */
337 normalised_float_to_u8(float f
)
339 return (uint8_t) (int) (f
* 255.0f
);
344 struct pipe_context
*pipe
,
346 const union pipe_color_union
*color
,
347 double depth
, unsigned stencil
)
349 struct panfrost_context
*ctx
= pan_context(pipe
);
352 printf("Warning: clear color null?\n");
356 /* Save settings for FBO switch */
357 ctx
->last_clear
.buffers
= buffers
;
358 ctx
->last_clear
.color
= color
;
359 ctx
->last_clear
.depth
= depth
;
360 ctx
->last_clear
.depth
= depth
;
362 bool clear_color
= buffers
& PIPE_CLEAR_COLOR
;
363 bool clear_depth
= buffers
& PIPE_CLEAR_DEPTH
;
364 bool clear_stencil
= buffers
& PIPE_CLEAR_STENCIL
;
366 /* Remember that we've done something */
367 ctx
->frame_cleared
= true;
369 /* Alpha clear only meaningful without alpha channel */
370 bool has_alpha
= ctx
->pipe_framebuffer
.nr_cbufs
&& util_format_has_alpha(ctx
->pipe_framebuffer
.cbufs
[0]->format
);
371 float clear_alpha
= has_alpha
? color
->f
[3] : 1.0f
;
373 uint32_t packed_color
=
374 (normalised_float_to_u8(clear_alpha
) << 24) |
375 (normalised_float_to_u8(color
->f
[2]) << 16) |
376 (normalised_float_to_u8(color
->f
[1]) << 8) |
377 (normalised_float_to_u8(color
->f
[0]) << 0);
380 struct bifrost_render_target
*buffer_color
= &ctx
->fragment_rts
[0];
382 struct mali_single_framebuffer
*buffer_color
= &ctx
->fragment_fbd
;
386 struct bifrost_framebuffer
*buffer_ds
= &ctx
->fragment_fbd
;
388 struct mali_single_framebuffer
*buffer_ds
= buffer_color
;
392 /* Fields duplicated 4x for unknown reasons. Same in Utgard,
393 * too, which is doubly weird. */
395 buffer_color
->clear_color_1
= packed_color
;
396 buffer_color
->clear_color_2
= packed_color
;
397 buffer_color
->clear_color_3
= packed_color
;
398 buffer_color
->clear_color_4
= packed_color
;
403 buffer_ds
->clear_depth_1
= depth
;
404 buffer_ds
->clear_depth_2
= depth
;
405 buffer_ds
->clear_depth_3
= depth
;
406 buffer_ds
->clear_depth_4
= depth
;
408 buffer_ds
->clear_depth
= depth
;
413 buffer_ds
->clear_stencil
= stencil
;
416 /* Setup buffers depending on MFBD/SFBD */
420 if (clear_depth
|| clear_stencil
) {
421 /* Setup combined 24/8 depth/stencil */
422 ctx
->fragment_fbd
.unk3
|= MALI_MFBD_EXTRA
;
423 //ctx->fragment_extra.unk = /*0x405*/0x404;
424 ctx
->fragment_extra
.unk
= 0x405;
425 ctx
->fragment_extra
.ds_linear
.depth
= ctx
->depth_stencil_buffer
.gpu
;
426 ctx
->fragment_extra
.ds_linear
.depth_stride
= ctx
->pipe_framebuffer
.width
* 4;
432 buffer_ds
->depth_buffer
= ctx
->depth_stencil_buffer
.gpu
;
433 buffer_ds
->depth_buffer_enable
= MALI_DEPTH_STENCIL_ENABLE
;
437 buffer_ds
->stencil_buffer
= ctx
->depth_stencil_buffer
.gpu
;
438 buffer_ds
->stencil_buffer_enable
= MALI_DEPTH_STENCIL_ENABLE
;
444 /* Set flags based on what has been cleared, for the SFBD case */
445 /* XXX: What do these flags mean? */
446 int clear_flags
= 0x101100;
448 if (clear_color
&& clear_depth
&& clear_stencil
) {
449 /* On a tiler like this, it's fastest to clear all three buffers at once */
451 clear_flags
|= MALI_CLEAR_FAST
;
453 clear_flags
|= MALI_CLEAR_SLOW
;
456 clear_flags
|= MALI_CLEAR_SLOW_STENCIL
;
459 fbd
->clear_flags
= clear_flags
;
464 panfrost_attach_vt_framebuffer(struct panfrost_context
*ctx
)
467 /* MFBD needs a sequential semi-render target upload, but this is, is beyond me for now */
468 struct bifrost_render_target rts_list
[] = {
473 .framebuffer
= ctx
->misc_0
.gpu
,
478 /* Allocate memory for the three components */
479 int size
= 1024 + sizeof(ctx
->vt_framebuffer
) + sizeof(rts_list
);
480 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, size
);
482 /* Opaque 1024-block */
483 rts_list
[0].chunknown
.pointer
= transfer
.gpu
;
485 mali_ptr framebuffer
= (transfer
.gpu
+ 1024) | PANFROST_DEFAULT_FBD
;
486 memcpy(transfer
.cpu
+ 1024, &ctx
->vt_framebuffer
, sizeof(ctx
->vt_framebuffer
));
487 memcpy(transfer
.cpu
+ 1024 + sizeof(ctx
->vt_framebuffer
), rts_list
, sizeof(rts_list
));
489 mali_ptr framebuffer
= panfrost_upload_transient(ctx
, &ctx
->vt_framebuffer
, sizeof(ctx
->vt_framebuffer
)) | PANFROST_DEFAULT_FBD
;
491 ctx
->payload_vertex
.postfix
.framebuffer
= framebuffer
;
492 ctx
->payload_tiler
.postfix
.framebuffer
= framebuffer
;
496 panfrost_viewport(struct panfrost_context
*ctx
,
499 int viewport_x0
, int viewport_y0
,
500 int viewport_x1
, int viewport_y1
)
502 /* Viewport encoding is asymmetric. Purpose of the floats is unknown? */
504 struct mali_viewport ret
= {
514 .depth_range_n
= depth_range_n
,
515 .depth_range_f
= depth_range_f
,
517 .viewport0
= { viewport_x0
, viewport_y0
},
518 .viewport1
= { MALI_POSITIVE(viewport_x1
), MALI_POSITIVE(viewport_y1
) },
521 memcpy(ctx
->viewport
, &ret
, sizeof(ret
));
524 /* Reset per-frame context, called on context initialisation as well as after
525 * flushing a frame */
528 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
530 unsigned transient_count
= ctx
->transient_pools
[ctx
->cmdstream_i
].entry_index
*ctx
->transient_pools
[0].entry_size
+ ctx
->transient_pools
[ctx
->cmdstream_i
].entry_offset
;
531 printf("Uploaded transient %d bytes\n", transient_count
);
533 /* Rotate cmdstream */
534 if ((++ctx
->cmdstream_i
) == (sizeof(ctx
->transient_pools
) / sizeof(ctx
->transient_pools
[0])))
535 ctx
->cmdstream_i
= 0;
537 ctx
->vt_framebuffer
= panfrost_emit_fbd(ctx
);
538 panfrost_new_frag_framebuffer(ctx
);
540 /* Reset varyings allocated */
541 ctx
->varying_height
= 0;
543 /* The transient cmdstream is dirty every frame; the only bits worth preserving
544 * (textures, shaders, etc) are in other buffers anyways */
546 ctx
->transient_pools
[ctx
->cmdstream_i
].entry_index
= 0;
547 ctx
->transient_pools
[ctx
->cmdstream_i
].entry_offset
= 0;
549 /* Regenerate payloads */
550 panfrost_attach_vt_framebuffer(ctx
);
553 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
556 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
| PAN_DIRTY_TEXTURES
;
559 /* In practice, every field of these payloads should be configurable
560 * arbitrarily, which means these functions are basically catch-all's for
561 * as-of-yet unwavering unknowns */
564 panfrost_emit_vertex_payload(struct panfrost_context
*ctx
)
566 struct midgard_payload_vertex_tiler payload
= {
568 .workgroups_z_shift
= 32,
569 .workgroups_x_shift_2
= 0x2,
570 .workgroups_x_shift_3
= 0x5,
575 memcpy(&ctx
->payload_vertex
, &payload
, sizeof(payload
));
579 panfrost_emit_tiler_payload(struct panfrost_context
*ctx
)
581 struct midgard_payload_vertex_tiler payload
= {
583 .workgroups_z_shift
= 32,
584 .workgroups_x_shift_2
= 0x2,
585 .workgroups_x_shift_3
= 0x6,
587 .zero1
= 0xffff, /* Why is this only seen on test-quad-textured? */
591 /* Reserve the viewport */
592 struct panfrost_transfer t
= panfrost_allocate_chunk(ctx
, sizeof(struct mali_viewport
), HEAP_DESCRIPTOR
);
593 ctx
->viewport
= (struct mali_viewport
*) t
.cpu
;
594 payload
.postfix
.viewport
= t
.gpu
;
596 memcpy(&ctx
->payload_tiler
, &payload
, sizeof(payload
));
600 translate_tex_wrap(enum pipe_tex_wrap w
)
603 case PIPE_TEX_WRAP_REPEAT
:
604 return MALI_WRAP_REPEAT
;
606 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
607 return MALI_WRAP_CLAMP_TO_EDGE
;
609 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
610 return MALI_WRAP_CLAMP_TO_BORDER
;
612 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
613 return MALI_WRAP_MIRRORED_REPEAT
;
622 translate_tex_filter(enum pipe_tex_filter f
)
625 case PIPE_TEX_FILTER_NEAREST
:
628 case PIPE_TEX_FILTER_LINEAR
:
638 translate_mip_filter(enum pipe_tex_mipfilter f
)
640 return (f
== PIPE_TEX_MIPFILTER_LINEAR
) ? MALI_MIP_LINEAR
: 0;
644 panfrost_translate_compare_func(enum pipe_compare_func in
)
647 case PIPE_FUNC_NEVER
:
648 return MALI_FUNC_NEVER
;
651 return MALI_FUNC_LESS
;
653 case PIPE_FUNC_EQUAL
:
654 return MALI_FUNC_EQUAL
;
656 case PIPE_FUNC_LEQUAL
:
657 return MALI_FUNC_LEQUAL
;
659 case PIPE_FUNC_GREATER
:
660 return MALI_FUNC_GREATER
;
662 case PIPE_FUNC_NOTEQUAL
:
663 return MALI_FUNC_NOTEQUAL
;
665 case PIPE_FUNC_GEQUAL
:
666 return MALI_FUNC_GEQUAL
;
668 case PIPE_FUNC_ALWAYS
:
669 return MALI_FUNC_ALWAYS
;
673 return 0; /* Unreachable */
677 panfrost_translate_alt_compare_func(enum pipe_compare_func in
)
680 case PIPE_FUNC_NEVER
:
681 return MALI_ALT_FUNC_NEVER
;
684 return MALI_ALT_FUNC_LESS
;
686 case PIPE_FUNC_EQUAL
:
687 return MALI_ALT_FUNC_EQUAL
;
689 case PIPE_FUNC_LEQUAL
:
690 return MALI_ALT_FUNC_LEQUAL
;
692 case PIPE_FUNC_GREATER
:
693 return MALI_ALT_FUNC_GREATER
;
695 case PIPE_FUNC_NOTEQUAL
:
696 return MALI_ALT_FUNC_NOTEQUAL
;
698 case PIPE_FUNC_GEQUAL
:
699 return MALI_ALT_FUNC_GEQUAL
;
701 case PIPE_FUNC_ALWAYS
:
702 return MALI_ALT_FUNC_ALWAYS
;
706 return 0; /* Unreachable */
710 panfrost_translate_stencil_op(enum pipe_stencil_op in
)
713 case PIPE_STENCIL_OP_KEEP
:
714 return MALI_STENCIL_KEEP
;
716 case PIPE_STENCIL_OP_ZERO
:
717 return MALI_STENCIL_ZERO
;
719 case PIPE_STENCIL_OP_REPLACE
:
720 return MALI_STENCIL_REPLACE
;
722 case PIPE_STENCIL_OP_INCR
:
723 return MALI_STENCIL_INCR
;
725 case PIPE_STENCIL_OP_DECR
:
726 return MALI_STENCIL_DECR
;
728 case PIPE_STENCIL_OP_INCR_WRAP
:
729 return MALI_STENCIL_INCR_WRAP
;
731 case PIPE_STENCIL_OP_DECR_WRAP
:
732 return MALI_STENCIL_DECR_WRAP
;
734 case PIPE_STENCIL_OP_INVERT
:
735 return MALI_STENCIL_INVERT
;
739 return 0; /* Unreachable */
743 panfrost_make_stencil_state(const struct pipe_stencil_state
*in
, struct mali_stencil_test
*out
)
745 out
->ref
= 0; /* Gallium gets it from elsewhere */
747 out
->mask
= in
->valuemask
;
748 out
->func
= panfrost_translate_compare_func(in
->func
);
749 out
->sfail
= panfrost_translate_stencil_op(in
->fail_op
);
750 out
->dpfail
= panfrost_translate_stencil_op(in
->zfail_op
);
751 out
->dppass
= panfrost_translate_stencil_op(in
->zpass_op
);
755 panfrost_default_shader_backend(struct panfrost_context
*ctx
)
757 struct mali_shader_meta shader
= {
758 .alpha_coverage
= ~MALI_ALPHA_COVERAGE(0.000000),
760 .unknown2_3
= MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS
) | 0x3010 /*| MALI_CAN_DISCARD*/,
762 .unknown2_4
= MALI_NO_MSAA
| 0x4e0,
764 .unknown2_4
= MALI_NO_MSAA
| 0x4f0,
768 struct pipe_stencil_state default_stencil
= {
770 .func
= PIPE_FUNC_ALWAYS
,
771 .fail_op
= MALI_STENCIL_KEEP
,
772 .zfail_op
= MALI_STENCIL_KEEP
,
773 .zpass_op
= MALI_STENCIL_KEEP
,
778 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_front
);
779 shader
.stencil_mask_front
= default_stencil
.writemask
;
781 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_back
);
782 shader
.stencil_mask_back
= default_stencil
.writemask
;
784 if (default_stencil
.enabled
)
785 shader
.unknown2_4
|= MALI_STENCIL_TEST
;
787 memcpy(&ctx
->fragment_shader_core
, &shader
, sizeof(shader
));
790 /* Generates a vertex/tiler job. This is, in some sense, the heart of the
791 * graphics command stream. It should be called once per draw, accordding to
792 * presentations. Set is_tiler for "tiler" jobs (fragment shader jobs, but in
793 * Mali parlance, "fragment" refers to framebuffer writeout). Clear it for
796 struct panfrost_transfer
797 panfrost_vertex_tiler_job(struct panfrost_context
*ctx
, bool is_tiler
, bool is_elided_tiler
)
799 /* Each draw call corresponds to two jobs, and we want to offset to leave room for the set-value job */
800 int draw_job_index
= 1 + (2 * ctx
->draw_count
);
802 struct mali_job_descriptor_header job
= {
803 .job_type
= is_tiler
? JOB_TYPE_TILER
: JOB_TYPE_VERTEX
,
804 .job_index
= draw_job_index
+ (is_tiler
? 1 : 0),
806 .job_descriptor_size
= 1,
810 /* XXX: What is this? */
814 job
.unknown_flags
= ctx
->draw_count
? 64 : 1;
818 /* Only non-elided tiler jobs have dependencies which are known at this point */
820 if (is_tiler
&& !is_elided_tiler
) {
821 /* Tiler jobs depend on vertex jobs */
823 job
.job_dependency_index_1
= draw_job_index
;
825 /* Tiler jobs also depend on the previous tiler job */
828 job
.job_dependency_index_2
= draw_job_index
- 1;
831 struct midgard_payload_vertex_tiler
*payload
= is_tiler
? &ctx
->payload_tiler
: &ctx
->payload_vertex
;
833 /* There's some padding hacks on 32-bit */
840 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(job
) + sizeof(*payload
));
841 memcpy(transfer
.cpu
, &job
, sizeof(job
));
842 memcpy(transfer
.cpu
+ sizeof(job
) - offset
, payload
, sizeof(*payload
));
846 /* Generates a set value job. It's unclear what exactly this does, why it's
847 * necessary, and when to call it. */
850 panfrost_set_value_job(struct panfrost_context
*ctx
)
852 struct mali_job_descriptor_header job
= {
853 .job_type
= JOB_TYPE_SET_VALUE
,
854 .job_descriptor_size
= 1,
855 .job_index
= 1 + (2 * ctx
->draw_count
),
858 struct mali_payload_set_value payload
= {
859 .out
= ctx
->misc_0
.gpu
,
863 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(job
) + sizeof(payload
));
864 memcpy(transfer
.cpu
, &job
, sizeof(job
));
865 memcpy(transfer
.cpu
+ sizeof(job
), &payload
, sizeof(payload
));
867 ctx
->u_set_value_job
= (struct mali_job_descriptor_header
*) transfer
.cpu
;
868 ctx
->set_value_job
= transfer
.gpu
;
871 /* Generate a fragment job. This should be called once per frame. (According to
872 * presentations, this is supposed to correspond to eglSwapBuffers) */
875 panfrost_fragment_job(struct panfrost_context
*ctx
)
877 /* Update fragment FBD */
878 panfrost_set_fragment_afbc(ctx
);
880 if (ctx
->pipe_framebuffer
.nr_cbufs
== 1) {
881 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) ctx
->pipe_framebuffer
.cbufs
[0]->texture
;
882 int stride
= util_format_get_stride(rsrc
->base
.format
, rsrc
->base
.width0
);
884 if (rsrc
->bo
->has_checksum
) {
885 //ctx->fragment_fbd.unk3 |= 0xa00000;
886 //ctx->fragment_fbd.unk3 = 0xa02100;
887 ctx
->fragment_fbd
.unk3
|= MALI_MFBD_EXTRA
;
888 ctx
->fragment_extra
.unk
|= 0x420;
889 ctx
->fragment_extra
.checksum_stride
= rsrc
->bo
->checksum_stride
;
890 ctx
->fragment_extra
.checksum
= rsrc
->bo
->gpu
[0] + stride
* rsrc
->base
.height0
;
894 /* The frame is complete and therefore the framebuffer descriptor is
895 * ready for linkage and upload */
897 size_t sz
= sizeof(ctx
->fragment_fbd
) + sizeof(struct bifrost_fb_extra
) + sizeof(struct bifrost_render_target
) * 1;
898 struct panfrost_transfer fbd_t
= panfrost_allocate_transient(ctx
, sz
);
901 memcpy(fbd_t
.cpu
, &ctx
->fragment_fbd
, sizeof(ctx
->fragment_fbd
));
902 offset
+= sizeof(ctx
->fragment_fbd
);
904 /* Upload extra framebuffer info if necessary */
905 if (ctx
->fragment_fbd
.unk3
& MALI_MFBD_EXTRA
) {
906 memcpy(fbd_t
.cpu
+ offset
, &ctx
->fragment_extra
, sizeof(struct bifrost_fb_extra
));
907 offset
+= sizeof(struct bifrost_fb_extra
);
910 /* Upload (single) render target */
911 memcpy(fbd_t
.cpu
+ offset
, &ctx
->fragment_rts
[0], sizeof(struct bifrost_render_target
) * 1);
913 /* Generate the fragment (frame) job */
915 struct mali_job_descriptor_header header
= {
916 .job_type
= JOB_TYPE_FRAGMENT
,
919 .job_descriptor_size
= 1
923 struct mali_payload_fragment payload
= {
924 .min_tile_coord
= MALI_COORDINATE_TO_TILE_MIN(0, 0),
925 .max_tile_coord
= MALI_COORDINATE_TO_TILE_MAX(ctx
->pipe_framebuffer
.width
, ctx
->pipe_framebuffer
.height
),
926 .framebuffer
= fbd_t
.gpu
| PANFROST_DEFAULT_FBD
| (ctx
->fragment_fbd
.unk3
& MALI_MFBD_EXTRA
? 2 : 0),
929 /* Normally, there should be no padding. However, fragment jobs are
930 * shared with 64-bit Bifrost systems, and accordingly there is 4-bytes
931 * of zero padding in between. */
933 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(header
) + sizeof(payload
));
934 memcpy(transfer
.cpu
, &header
, sizeof(header
));
935 memcpy(transfer
.cpu
+ sizeof(header
), &payload
, sizeof(payload
));
939 /* Emits attributes and varying descriptors, which should be called every draw,
940 * excepting some obscure circumstances */
943 panfrost_emit_vertex_data(struct panfrost_context
*ctx
)
945 /* TODO: Only update the dirtied buffers */
946 union mali_attr attrs
[PIPE_MAX_ATTRIBS
];
947 union mali_attr varyings
[PIPE_MAX_ATTRIBS
];
949 unsigned invocation_count
= MALI_NEGATIVE(ctx
->payload_tiler
.prefix
.invocation_count
);
951 for (int i
= 0; i
< ctx
->vertex_buffer_count
; ++i
) {
952 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[i
];
953 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (buf
->buffer
.resource
);
955 /* Let's figure out the layout of the attributes in memory so
956 * we can be smart about size computation. The idea is to
957 * figure out the maximum src_offset, which tells us the latest
958 * spot a vertex could start. Meanwhile, we figure out the size
959 * of the attribute memory (assuming interleaved
960 * representation) and tack on the max src_offset for a
961 * reasonably good upper bound on the size.
963 * Proving correctness is left as an exercise to the reader.
966 unsigned max_src_offset
= 0;
968 for (unsigned j
= 0; j
< ctx
->vertex
->num_elements
; ++j
) {
969 if (ctx
->vertex
->pipe
[j
].vertex_buffer_index
!= i
) continue;
970 max_src_offset
= MAX2(max_src_offset
, ctx
->vertex
->pipe
[j
].src_offset
);
973 /* Offset vertex count by draw_start to make sure we upload enough */
974 attrs
[i
].stride
= buf
->stride
;
975 attrs
[i
].size
= buf
->stride
* (ctx
->payload_vertex
.draw_start
+ invocation_count
) + max_src_offset
;
977 /* Vertex elements are -already- GPU-visible, at
978 * rsrc->gpu. However, attribute buffers must be 64 aligned. If
979 * it is not, for now we have to duplicate the buffer. */
981 mali_ptr effective_address
= (rsrc
->bo
->gpu
[0] + buf
->buffer_offset
);
983 if (effective_address
& 0x3F) {
984 attrs
[i
].elements
= panfrost_upload_transient(ctx
, rsrc
->bo
->cpu
[0] + buf
->buffer_offset
, attrs
[i
].size
) | 1;
986 attrs
[i
].elements
= effective_address
| 1;
990 struct panfrost_varyings
*vars
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
].varyings
;
992 for (int i
= 0; i
< vars
->varying_buffer_count
; ++i
) {
993 mali_ptr varying_address
= ctx
->varying_mem
.gpu
+ ctx
->varying_height
;
995 varyings
[i
].elements
= varying_address
| 1;
996 varyings
[i
].stride
= vars
->varyings_stride
[i
];
997 varyings
[i
].size
= vars
->varyings_stride
[i
] * invocation_count
;
999 /* If this varying has to be linked somewhere, do it now. See
1000 * pan_assemble.c for the indices. TODO: Use a more generic
1001 * linking interface */
1005 ctx
->payload_tiler
.postfix
.position_varying
= varying_address
;
1006 } else if (i
== 2) {
1008 ctx
->payload_tiler
.primitive_size
.pointer
= varying_address
;
1011 /* Varyings appear to need 64-byte alignment */
1012 ctx
->varying_height
+= ALIGN(varyings
[i
].size
, 64);
1014 /* Ensure that we fit */
1015 assert(ctx
->varying_height
< ctx
->varying_mem
.size
);
1018 ctx
->payload_vertex
.postfix
.attributes
= panfrost_upload_transient(ctx
, attrs
, ctx
->vertex_buffer_count
* sizeof(union mali_attr
));
1020 mali_ptr varyings_p
= panfrost_upload_transient(ctx
, &varyings
, vars
->varying_buffer_count
* sizeof(union mali_attr
));
1021 ctx
->payload_vertex
.postfix
.varyings
= varyings_p
;
1022 ctx
->payload_tiler
.postfix
.varyings
= varyings_p
;
1025 /* Go through dirty flags and actualise them in the cmdstream. */
1028 panfrost_emit_for_draw(struct panfrost_context
*ctx
, bool with_vertex_data
)
1030 if (with_vertex_data
) {
1031 panfrost_emit_vertex_data(ctx
);
1034 if (ctx
->dirty
& PAN_DIRTY_RASTERIZER
) {
1035 ctx
->payload_tiler
.gl_enables
= ctx
->rasterizer
->tiler_gl_enables
;
1036 panfrost_set_framebuffer_msaa(ctx
, ctx
->rasterizer
->base
.multisample
);
1039 if (ctx
->occlusion_query
) {
1040 ctx
->payload_tiler
.gl_enables
|= MALI_OCCLUSION_BOOLEAN
;
1041 ctx
->payload_tiler
.postfix
.occlusion_counter
= ctx
->occlusion_query
->transfer
.gpu
;
1044 if (ctx
->dirty
& PAN_DIRTY_VS
) {
1047 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
1049 /* Late shader descriptor assignments */
1050 vs
->tripipe
->texture_count
= ctx
->sampler_view_count
[PIPE_SHADER_VERTEX
];
1051 vs
->tripipe
->sampler_count
= ctx
->sampler_count
[PIPE_SHADER_VERTEX
];
1054 vs
->tripipe
->midgard1
.unknown1
= 0x2201;
1056 ctx
->payload_vertex
.postfix
._shader_upper
= vs
->tripipe_gpu
>> 4;
1058 /* Varying descriptor is tied to the vertex shader. Also the
1059 * fragment shader, I suppose, but it's generated with the
1060 * vertex shader so */
1062 struct panfrost_varyings
*varyings
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
].varyings
;
1064 ctx
->payload_vertex
.postfix
.varying_meta
= varyings
->varyings_descriptor
;
1065 ctx
->payload_tiler
.postfix
.varying_meta
= varyings
->varyings_descriptor_fragment
;
1068 if (ctx
->dirty
& (PAN_DIRTY_RASTERIZER
| PAN_DIRTY_VS
)) {
1069 /* Check if we need to link the gl_PointSize varying */
1071 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
1073 bool needs_gl_point_size
= vs
->writes_point_size
&& ctx
->payload_tiler
.prefix
.draw_mode
== MALI_POINTS
;
1075 if (!needs_gl_point_size
) {
1076 /* If the size is constant, write it out. Otherwise,
1077 * don't touch primitive_size (since we would clobber
1078 * the pointer there) */
1080 ctx
->payload_tiler
.primitive_size
.constant
= ctx
->rasterizer
->base
.line_width
;
1083 /* Set the flag for varying (pointer) point size if the shader needs that */
1084 SET_BIT(ctx
->payload_tiler
.prefix
.unknown_draw
, MALI_DRAW_VARYING_SIZE
, needs_gl_point_size
);
1087 /* TODO: Maybe dirty track FS, maybe not. For now, it's transient. */
1089 ctx
->dirty
|= PAN_DIRTY_FS
;
1091 if (ctx
->dirty
& PAN_DIRTY_FS
) {
1093 struct panfrost_shader_state
*variant
= &ctx
->fs
->variants
[ctx
->fs
->active_variant
];
1095 #define COPY(name) ctx->fragment_shader_core.name = variant->tripipe->name
1098 COPY(attribute_count
);
1099 COPY(varying_count
);
1100 COPY(midgard1
.uniform_count
);
1101 COPY(midgard1
.work_count
);
1102 COPY(midgard1
.unknown2
);
1105 /* If there is a blend shader, work registers are shared */
1107 if (ctx
->blend
->has_blend_shader
)
1108 ctx
->fragment_shader_core
.midgard1
.work_count
= /*MAX2(ctx->fragment_shader_core.midgard1.work_count, ctx->blend->blend_work_count)*/16;
1110 /* Set late due to depending on render state */
1111 /* The one at the end seems to mean "1 UBO" */
1112 ctx
->fragment_shader_core
.midgard1
.unknown1
= MALI_NO_ALPHA_TO_COVERAGE
| 0x200 | 0x2201;
1114 /* Assign texture/sample count right before upload */
1115 ctx
->fragment_shader_core
.texture_count
= ctx
->sampler_view_count
[PIPE_SHADER_FRAGMENT
];
1116 ctx
->fragment_shader_core
.sampler_count
= ctx
->sampler_count
[PIPE_SHADER_FRAGMENT
];
1118 /* Assign the stencil refs late */
1119 ctx
->fragment_shader_core
.stencil_front
.ref
= ctx
->stencil_ref
.ref_value
[0];
1120 ctx
->fragment_shader_core
.stencil_back
.ref
= ctx
->stencil_ref
.ref_value
[1];
1122 /* CAN_DISCARD should be set if the fragment shader possibly
1123 * contains a 'discard' instruction, or maybe other
1124 * circumstances. It is likely this is related to optimizations
1125 * related to forward-pixel kill, as per "Mali Performance 3:
1126 * Is EGL_BUFFER_PRESERVED a good thing?" by Peter Harris
1129 if (variant
->can_discard
) {
1130 ctx
->fragment_shader_core
.unknown2_3
|= MALI_CAN_DISCARD
;
1131 ctx
->fragment_shader_core
.midgard1
.unknown1
&= ~MALI_NO_ALPHA_TO_COVERAGE
;
1132 ctx
->fragment_shader_core
.midgard1
.unknown1
|= 0x4000;
1133 ctx
->fragment_shader_core
.midgard1
.unknown1
= 0x4200;
1136 if (ctx
->blend
->has_blend_shader
)
1137 ctx
->fragment_shader_core
.blend_shader
= ctx
->blend
->blend_shader
;
1139 size_t size
= sizeof(struct mali_shader_meta
) + sizeof(struct mali_blend_meta
);
1140 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, size
);
1141 memcpy(transfer
.cpu
, &ctx
->fragment_shader_core
, sizeof(struct mali_shader_meta
));
1143 ctx
->payload_tiler
.postfix
._shader_upper
= (transfer
.gpu
) >> 4;
1146 /* Additional blend descriptor tacked on for newer systems */
1148 unsigned blend_count
= 0;
1150 if (ctx
->blend
->has_blend_shader
) {
1151 /* For a blend shader, the bottom nibble corresponds to
1152 * the number of work registers used, which signals the
1153 * -existence- of a blend shader */
1155 assert(ctx
->blend
->blend_work_count
>= 2);
1156 blend_count
|= MIN2(ctx
->blend
->blend_work_count
, 3);
1158 /* Otherwise, the bottom bit simply specifies if
1159 * blending (anything other than REPLACE) is enabled */
1161 /* XXX: Less ugly way to do this? */
1163 (ctx
->blend
->equation
.rgb_mode
== 0x122) &&
1164 (ctx
->blend
->equation
.alpha_mode
== 0x122) &&
1165 (ctx
->blend
->equation
.color_mask
== 0xf);
1171 /* Second blend equation is always a simple replace */
1173 uint64_t replace_magic
= 0xf0122122;
1174 struct mali_blend_equation replace_mode
;
1175 memcpy(&replace_mode
, &replace_magic
, sizeof(replace_mode
));
1177 struct mali_blend_meta blend_meta
[] = {
1179 .unk1
= 0x200 | blend_count
,
1180 .blend_equation_1
= ctx
->blend
->equation
,
1181 .blend_equation_2
= replace_mode
1185 if (ctx
->blend
->has_blend_shader
)
1186 memcpy(&blend_meta
[0].blend_equation_1
, &ctx
->blend
->blend_shader
, sizeof(ctx
->blend
->blend_shader
));
1188 memcpy(transfer
.cpu
+ sizeof(struct mali_shader_meta
), blend_meta
, sizeof(blend_meta
));
1192 if (ctx
->dirty
& PAN_DIRTY_VERTEX
) {
1193 ctx
->payload_vertex
.postfix
.attribute_meta
= ctx
->vertex
->descriptor_ptr
;
1196 if (ctx
->dirty
& PAN_DIRTY_SAMPLERS
) {
1197 /* Upload samplers back to back, no padding */
1199 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
1200 if (!ctx
->sampler_count
[t
]) continue;
1202 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(struct mali_sampler_descriptor
) * ctx
->sampler_count
[t
]);
1203 struct mali_sampler_descriptor
*desc
= (struct mali_sampler_descriptor
*) transfer
.cpu
;
1205 for (int i
= 0; i
< ctx
->sampler_count
[t
]; ++i
) {
1206 desc
[i
] = ctx
->samplers
[t
][i
]->hw
;
1209 if (t
== PIPE_SHADER_FRAGMENT
)
1210 ctx
->payload_tiler
.postfix
.sampler_descriptor
= transfer
.gpu
;
1211 else if (t
== PIPE_SHADER_VERTEX
)
1212 ctx
->payload_vertex
.postfix
.sampler_descriptor
= transfer
.gpu
;
1218 if (ctx
->dirty
& PAN_DIRTY_TEXTURES
) {
1219 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
1221 if (!ctx
->sampler_view_count
[t
]) continue;
1223 uint64_t trampolines
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
1225 for (int i
= 0; i
< ctx
->sampler_view_count
[t
]; ++i
) {
1226 if (!ctx
->sampler_views
[t
][i
])
1229 struct pipe_resource
*tex_rsrc
= ctx
->sampler_views
[t
][i
]->base
.texture
;
1230 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) tex_rsrc
;
1232 /* Inject the address in. */
1233 for (int l
= 0; l
< (tex_rsrc
->last_level
+ 1); ++l
)
1234 ctx
->sampler_views
[t
][i
]->hw
.swizzled_bitmaps
[l
] = rsrc
->bo
->gpu
[l
];
1236 /* Workaround maybe-errata (?) with non-mipmaps */
1237 int s
= ctx
->sampler_views
[t
][i
]->hw
.nr_mipmap_levels
;
1239 if (!rsrc
->bo
->is_mipmap
) {
1241 /* HW ERRATA, not needed after T6XX */
1242 ctx
->sampler_views
[t
][i
]->hw
.swizzled_bitmaps
[1] = rsrc
->bo
->gpu
[0];
1244 ctx
->sampler_views
[t
][i
]->hw
.unknown3A
= 1;
1246 ctx
->sampler_views
[t
][i
]->hw
.nr_mipmap_levels
= 0;
1249 trampolines
[i
] = panfrost_upload_transient(ctx
, &ctx
->sampler_views
[t
][i
]->hw
, sizeof(struct mali_texture_descriptor
));
1252 ctx
->sampler_views
[t
][i
]->hw
.nr_mipmap_levels
= s
;
1255 ctx
->sampler_views
[t
][i
]->hw
.unknown3A
= 0;
1259 mali_ptr trampoline
= panfrost_upload_transient(ctx
, trampolines
, sizeof(uint64_t) * ctx
->sampler_view_count
[t
]);
1261 if (t
== PIPE_SHADER_FRAGMENT
)
1262 ctx
->payload_tiler
.postfix
.texture_trampoline
= trampoline
;
1263 else if (t
== PIPE_SHADER_VERTEX
)
1264 ctx
->payload_vertex
.postfix
.texture_trampoline
= trampoline
;
1270 /* Generate the viewport vector of the form: <width/2, height/2, centerx, centery> */
1271 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
1273 float viewport_vec4
[] = {
1275 fabsf(vp
->scale
[1]),
1278 /* -1.0 * vp->translate[1] */ fabs(1.0 * vp
->scale
[1]) /* XXX */
1281 for (int i
= 0; i
< PIPE_SHADER_TYPES
; ++i
) {
1282 struct panfrost_constant_buffer
*buf
= &ctx
->constant_buffer
[i
];
1284 if (i
== PIPE_SHADER_VERTEX
|| i
== PIPE_SHADER_FRAGMENT
) {
1285 /* It doesn't matter if we don't use all the memory;
1286 * we'd need a dummy UBO anyway. Compute the max */
1288 size_t size
= sizeof(viewport_vec4
) + buf
->size
;
1289 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, size
);
1291 /* Keep track how much we've uploaded */
1294 if (i
== PIPE_SHADER_VERTEX
) {
1295 /* Upload viewport */
1296 memcpy(transfer
.cpu
+ offset
, viewport_vec4
, sizeof(viewport_vec4
));
1297 offset
+= sizeof(viewport_vec4
);
1300 /* Upload uniforms */
1301 memcpy(transfer
.cpu
+ offset
, buf
->buffer
, buf
->size
);
1303 int uniform_count
= 0;
1305 struct mali_vertex_tiler_postfix
*postfix
;
1308 case PIPE_SHADER_VERTEX
:
1309 uniform_count
= ctx
->vs
->variants
[ctx
->vs
->active_variant
].uniform_count
;
1310 postfix
= &ctx
->payload_vertex
.postfix
;
1313 case PIPE_SHADER_FRAGMENT
:
1314 uniform_count
= ctx
->fs
->variants
[ctx
->fs
->active_variant
].uniform_count
;
1315 postfix
= &ctx
->payload_tiler
.postfix
;
1319 printf("Unknown shader stage %d in uniform upload\n", i
);
1323 /* Also attach the same buffer as a UBO for extended access */
1325 struct mali_uniform_buffer_meta uniform_buffers
[] = {
1327 .size
= MALI_POSITIVE((2 + uniform_count
)),
1328 .ptr
= transfer
.gpu
>> 2,
1332 mali_ptr ubufs
= panfrost_upload_transient(ctx
, uniform_buffers
, sizeof(uniform_buffers
));
1333 postfix
->uniforms
= transfer
.gpu
;
1334 postfix
->uniform_buffers
= ubufs
;
1343 /* Corresponds to exactly one draw, but does not submit anything */
1346 panfrost_queue_draw(struct panfrost_context
*ctx
)
1348 /* TODO: Expand the array? */
1349 if (ctx
->draw_count
>= MAX_DRAW_CALLS
) {
1350 printf("Job buffer overflow, ignoring draw\n");
1354 /* Handle dirty flags now */
1355 panfrost_emit_for_draw(ctx
, true);
1357 struct panfrost_transfer vertex
= panfrost_vertex_tiler_job(ctx
, false, false);
1358 struct panfrost_transfer tiler
= panfrost_vertex_tiler_job(ctx
, true, false);
1360 ctx
->u_vertex_jobs
[ctx
->vertex_job_count
] = (struct mali_job_descriptor_header
*) vertex
.cpu
;
1361 ctx
->vertex_jobs
[ctx
->vertex_job_count
++] = vertex
.gpu
;
1363 ctx
->u_tiler_jobs
[ctx
->tiler_job_count
] = (struct mali_job_descriptor_header
*) tiler
.cpu
;
1364 ctx
->tiler_jobs
[ctx
->tiler_job_count
++] = tiler
.gpu
;
1369 /* At the end of the frame, the vertex and tiler jobs are linked together and
1370 * then the fragment job is plonked at the end. Set value job is first for
1371 * unknown reasons. */
1374 panfrost_link_job_pair(struct mali_job_descriptor_header
*first
, mali_ptr next
)
1376 if (first
->job_descriptor_size
)
1377 first
->next_job_64
= (u64
) (uintptr_t) next
;
1379 first
->next_job_32
= (u32
) (uintptr_t) next
;
1383 panfrost_link_jobs(struct panfrost_context
*ctx
)
1385 if (ctx
->draw_count
) {
1386 /* Generate the set_value_job */
1387 panfrost_set_value_job(ctx
);
1389 /* Have the first vertex job depend on the set value job */
1390 ctx
->u_vertex_jobs
[0]->job_dependency_index_1
= ctx
->u_set_value_job
->job_index
;
1393 panfrost_link_job_pair(ctx
->u_set_value_job
, ctx
->vertex_jobs
[0]);
1396 /* V -> V/T ; T -> T/null */
1397 for (int i
= 0; i
< ctx
->vertex_job_count
; ++i
) {
1398 bool isLast
= (i
+ 1) == ctx
->vertex_job_count
;
1400 panfrost_link_job_pair(ctx
->u_vertex_jobs
[i
], isLast
? ctx
->tiler_jobs
[0]: ctx
->vertex_jobs
[i
+ 1]);
1404 for (int i
= 0; i
< ctx
->tiler_job_count
; ++i
) {
1405 bool isLast
= (i
+ 1) == ctx
->tiler_job_count
;
1406 panfrost_link_job_pair(ctx
->u_tiler_jobs
[i
], isLast
? 0 : ctx
->tiler_jobs
[i
+ 1]);
1410 /* The entire frame is in memory -- send it off to the kernel! */
1413 panfrost_submit_frame(struct panfrost_context
*ctx
, bool flush_immediate
)
1415 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
1416 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
1418 /* Edge case if screen is cleared and nothing else */
1419 bool has_draws
= ctx
->draw_count
> 0;
1421 /* Workaround a bizarre lockup (a hardware errata?) */
1423 flush_immediate
= true;
1425 /* A number of jobs are batched -- this must be linked and cleared */
1426 panfrost_link_jobs(ctx
);
1428 ctx
->draw_count
= 0;
1429 ctx
->vertex_job_count
= 0;
1430 ctx
->tiler_job_count
= 0;
1434 int fragment_id
= screen
->driver
->submit_vs_fs_job(ctx
, has_draws
);
1436 /* If visual, we can stall a frame */
1438 if (panfrost_is_scanout(ctx
) && !flush_immediate
)
1439 screen
->driver
->force_flush_fragment(ctx
);
1441 screen
->last_fragment_id
= fragment_id
;
1442 screen
->last_fragment_flushed
= false;
1444 /* If readback, flush now (hurts the pipelined performance) */
1445 if (panfrost_is_scanout(ctx
) && flush_immediate
)
1446 screen
->driver
->force_flush_fragment(ctx
);
1448 #ifdef DUMP_PERFORMANCE_COUNTERS
1450 snprintf(filename
, sizeof(filename
), "/dev/shm/frame%d.mdgprf", ++performance_counter_number
);
1451 FILE *fp
= fopen(filename
, "wb");
1452 fwrite(screen
->perf_counters
.cpu
, 4096, sizeof(uint32_t), fp
);
1459 bool dont_scanout
= false;
1463 struct pipe_context
*pipe
,
1464 struct pipe_fence_handle
**fence
,
1467 struct panfrost_context
*ctx
= pan_context(pipe
);
1469 /* If there is nothing drawn, skip the frame */
1470 if (!ctx
->draw_count
&& !ctx
->frame_cleared
) return;
1472 if (!ctx
->frame_cleared
) {
1473 /* While there are draws, there was no clear. This is a partial
1474 * update, which needs to be handled via the "wallpaper"
1475 * method. We also need to fake a clear, just to get the
1476 * FRAGMENT job correct. */
1478 panfrost_clear(&ctx
->base
, ctx
->last_clear
.buffers
, ctx
->last_clear
.color
, ctx
->last_clear
.depth
, ctx
->last_clear
.stencil
);
1480 panfrost_draw_wallpaper(pipe
);
1483 /* Frame clear handled, reset */
1484 ctx
->frame_cleared
= false;
1486 /* Whether to stall the pipeline for immediately correct results */
1487 bool flush_immediate
= flags
& PIPE_FLUSH_END_OF_FRAME
;
1489 /* Submit the frame itself */
1490 panfrost_submit_frame(ctx
, flush_immediate
);
1492 /* Prepare for the next frame */
1493 panfrost_invalidate_frame(ctx
);
1496 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
1499 g2m_draw_mode(enum pipe_prim_type mode
)
1502 DEFINE_CASE(POINTS
);
1504 DEFINE_CASE(LINE_LOOP
);
1505 DEFINE_CASE(LINE_STRIP
);
1506 DEFINE_CASE(TRIANGLES
);
1507 DEFINE_CASE(TRIANGLE_STRIP
);
1508 DEFINE_CASE(TRIANGLE_FAN
);
1510 DEFINE_CASE(QUAD_STRIP
);
1511 DEFINE_CASE(POLYGON
);
1514 printf("Illegal draw mode %d\n", mode
);
1516 return MALI_LINE_LOOP
;
1523 panfrost_translate_index_size(unsigned size
)
1527 return MALI_DRAW_INDEXED_UINT8
;
1530 return MALI_DRAW_INDEXED_UINT16
;
1533 return MALI_DRAW_INDEXED_UINT32
;
1536 printf("Unknown index size %d\n", size
);
1542 static const uint8_t *
1543 panfrost_get_index_buffer_raw(const struct pipe_draw_info
*info
)
1545 if (info
->has_user_indices
) {
1546 return (const uint8_t *) info
->index
.user
;
1548 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
1549 return (const uint8_t *) rsrc
->bo
->cpu
[0];
1553 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
1554 * good for the duration of the draw (transient), could last longer */
1557 panfrost_get_index_buffer_mapped(struct panfrost_context
*ctx
, const struct pipe_draw_info
*info
)
1559 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
1561 off_t offset
= info
->start
* info
->index_size
;
1563 if (!info
->has_user_indices
) {
1564 /* Only resources can be directly mapped */
1565 return rsrc
->bo
->gpu
[0] + offset
;
1567 /* Otherwise, we need to upload to transient memory */
1568 const uint8_t *ibuf8
= panfrost_get_index_buffer_raw(info
);
1569 return panfrost_upload_transient(ctx
, ibuf8
+ offset
, info
->count
* info
->index_size
);
1575 struct pipe_context
*pipe
,
1576 const struct pipe_draw_info
*info
);
1578 #define CALCULATE_MIN_MAX_INDEX(T, buffer, start, count) \
1579 for (unsigned _idx = (start); _idx < (start + count); ++_idx) { \
1580 T idx = buffer[_idx]; \
1581 if (idx > max_index) max_index = idx; \
1582 if (idx < min_index) min_index = idx; \
1587 struct pipe_context
*pipe
,
1588 const struct pipe_draw_info
*info
)
1590 struct panfrost_context
*ctx
= pan_context(pipe
);
1592 ctx
->payload_vertex
.draw_start
= info
->start
;
1593 ctx
->payload_tiler
.draw_start
= info
->start
;
1595 int mode
= info
->mode
;
1598 /* Fallback for non-ES draw modes */
1599 /* Primconvert not needed on Midgard anymore due to native
1600 * QUADS/POLYGONS. Bifrost/desktop-GL may need it though so not
1603 if (info
->mode
>= PIPE_PRIM_QUADS
) {
1604 if (info
->mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && ctx
->rasterizer
&& !ctx
->rasterizer
->base
.flatshade
) {
1605 mode
= PIPE_PRIM_TRIANGLE_FAN
;
1607 if (info
->count
< 4) {
1608 /* Degenerate case? */
1612 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
1613 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
1619 ctx
->payload_tiler
.prefix
.draw_mode
= g2m_draw_mode(mode
);
1621 ctx
->vertex_count
= info
->count
;
1623 /* For non-indexed draws, they're the same */
1624 unsigned invocation_count
= ctx
->vertex_count
;
1626 /* For higher amounts of vertices (greater than what fits in a 16-bit
1627 * short), the other value is needed, otherwise there will be bizarre
1628 * rendering artefacts. It's not clear what these values mean yet. */
1630 ctx
->payload_tiler
.prefix
.unknown_draw
&= ~(0x3000 | 0x18000);
1631 ctx
->payload_tiler
.prefix
.unknown_draw
|= (info
->mode
== PIPE_PRIM_POINTS
|| ctx
->vertex_count
> 65535) ? 0x3000 : 0x18000;
1633 if (info
->index_size
) {
1634 /* Calculate the min/max index used so we can figure out how
1635 * many times to invoke the vertex shader */
1637 const uint8_t *ibuf8
= panfrost_get_index_buffer_raw(info
);
1639 int min_index
= INT_MAX
;
1642 if (info
->index_size
== 1) {
1643 CALCULATE_MIN_MAX_INDEX(uint8_t, ibuf8
, info
->start
, info
->count
);
1644 } else if (info
->index_size
== 2) {
1645 const uint16_t *ibuf16
= (const uint16_t *) ibuf8
;
1646 CALCULATE_MIN_MAX_INDEX(uint16_t, ibuf16
, info
->start
, info
->count
);
1647 } else if (info
->index_size
== 4) {
1648 const uint32_t *ibuf32
= (const uint32_t *) ibuf8
;
1649 CALCULATE_MIN_MAX_INDEX(uint32_t, ibuf32
, info
->start
, info
->count
);
1654 /* Make sure we didn't go crazy */
1655 assert(min_index
< INT_MAX
);
1656 assert(max_index
> 0);
1657 assert(max_index
> min_index
);
1659 /* Use the corresponding values */
1660 invocation_count
= max_index
- min_index
+ 1;
1661 ctx
->payload_vertex
.draw_start
= min_index
;
1662 ctx
->payload_tiler
.draw_start
= min_index
;
1664 ctx
->payload_tiler
.prefix
.negative_start
= -min_index
;
1665 ctx
->payload_tiler
.prefix
.index_count
= MALI_POSITIVE(info
->count
);
1667 //assert(!info->restart_index); /* TODO: Research */
1668 assert(!info
->index_bias
);
1669 //assert(!info->min_index); /* TODO: Use value */
1671 ctx
->payload_tiler
.prefix
.unknown_draw
|= panfrost_translate_index_size(info
->index_size
);
1672 ctx
->payload_tiler
.prefix
.indices
= panfrost_get_index_buffer_mapped(ctx
, info
);
1674 /* Index count == vertex count, if no indexing is applied, as
1675 * if it is internally indexed in the expected order */
1677 ctx
->payload_tiler
.prefix
.negative_start
= 0;
1678 ctx
->payload_tiler
.prefix
.index_count
= MALI_POSITIVE(ctx
->vertex_count
);
1680 /* Reverse index state */
1681 ctx
->payload_tiler
.prefix
.unknown_draw
&= ~MALI_DRAW_INDEXED_UINT32
;
1682 ctx
->payload_tiler
.prefix
.indices
= (uintptr_t) NULL
;
1685 ctx
->payload_vertex
.prefix
.invocation_count
= MALI_POSITIVE(invocation_count
);
1686 ctx
->payload_tiler
.prefix
.invocation_count
= MALI_POSITIVE(invocation_count
);
1688 /* Fire off the draw itself */
1689 panfrost_queue_draw(ctx
);
1695 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
1701 panfrost_set_scissor(struct panfrost_context
*ctx
)
1703 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1705 if (ss
&& ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
&& 0) {
1706 ctx
->viewport
->viewport0
[0] = ss
->minx
;
1707 ctx
->viewport
->viewport0
[1] = ss
->miny
;
1708 ctx
->viewport
->viewport1
[0] = MALI_POSITIVE(ss
->maxx
);
1709 ctx
->viewport
->viewport1
[1] = MALI_POSITIVE(ss
->maxy
);
1711 ctx
->viewport
->viewport0
[0] = 0;
1712 ctx
->viewport
->viewport0
[1] = 0;
1713 ctx
->viewport
->viewport1
[0] = MALI_POSITIVE(ctx
->pipe_framebuffer
.width
);
1714 ctx
->viewport
->viewport1
[1] = MALI_POSITIVE(ctx
->pipe_framebuffer
.height
);
1719 panfrost_create_rasterizer_state(
1720 struct pipe_context
*pctx
,
1721 const struct pipe_rasterizer_state
*cso
)
1723 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
1727 /* Bitmask, unknown meaning of the start value */
1729 so
->tiler_gl_enables
= 0x7;
1731 so
->tiler_gl_enables
= 0x105;
1734 so
->tiler_gl_enables
|= MALI_FRONT_FACE(
1735 cso
->front_ccw
? MALI_CCW
: MALI_CW
);
1737 if (cso
->cull_face
& PIPE_FACE_FRONT
)
1738 so
->tiler_gl_enables
|= MALI_CULL_FACE_FRONT
;
1740 if (cso
->cull_face
& PIPE_FACE_BACK
)
1741 so
->tiler_gl_enables
|= MALI_CULL_FACE_BACK
;
1747 panfrost_bind_rasterizer_state(
1748 struct pipe_context
*pctx
,
1751 struct panfrost_context
*ctx
= pan_context(pctx
);
1752 struct pipe_rasterizer_state
*cso
= hwcso
;
1754 /* TODO: Why can't rasterizer be NULL ever? Other drivers are fine.. */
1758 /* If scissor test has changed, we'll need to update that now */
1759 bool update_scissor
= !ctx
->rasterizer
|| ctx
->rasterizer
->base
.scissor
!= cso
->scissor
;
1761 ctx
->rasterizer
= hwcso
;
1763 /* Actualise late changes */
1765 panfrost_set_scissor(ctx
);
1767 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
1771 panfrost_create_vertex_elements_state(
1772 struct pipe_context
*pctx
,
1773 unsigned num_elements
,
1774 const struct pipe_vertex_element
*elements
)
1776 struct panfrost_context
*ctx
= pan_context(pctx
);
1777 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
1779 so
->num_elements
= num_elements
;
1780 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
1782 struct panfrost_transfer transfer
= panfrost_allocate_chunk(ctx
, sizeof(struct mali_attr_meta
) * num_elements
, HEAP_DESCRIPTOR
);
1783 so
->hw
= (struct mali_attr_meta
*) transfer
.cpu
;
1784 so
->descriptor_ptr
= transfer
.gpu
;
1786 /* Allocate memory for the descriptor state */
1788 for (int i
= 0; i
< num_elements
; ++i
) {
1789 so
->hw
[i
].index
= elements
[i
].vertex_buffer_index
;
1791 enum pipe_format fmt
= elements
[i
].src_format
;
1792 const struct util_format_description
*desc
= util_format_description(fmt
);
1793 so
->hw
[i
].unknown1
= 0x2;
1794 so
->hw
[i
].swizzle
= panfrost_get_default_swizzle(desc
->nr_channels
);
1796 so
->hw
[i
].format
= panfrost_find_format(desc
);
1798 /* The field itself should probably be shifted over */
1799 so
->hw
[i
].src_offset
= elements
[i
].src_offset
;
1806 panfrost_bind_vertex_elements_state(
1807 struct pipe_context
*pctx
,
1810 struct panfrost_context
*ctx
= pan_context(pctx
);
1812 ctx
->vertex
= hwcso
;
1813 ctx
->dirty
|= PAN_DIRTY_VERTEX
;
1817 panfrost_delete_vertex_elements_state(struct pipe_context
*pctx
, void *hwcso
)
1819 printf("Vertex elements delete leaks descriptor\n");
1824 panfrost_create_shader_state(
1825 struct pipe_context
*pctx
,
1826 const struct pipe_shader_state
*cso
)
1828 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
1831 /* Token deep copy to prevent memory corruption */
1833 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
1834 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
1840 panfrost_delete_shader_state(
1841 struct pipe_context
*pctx
,
1844 printf("Deleting shader state maybe leaks tokens, per-variant compiled shaders, per-variant descriptors\n");
1849 panfrost_create_sampler_state(
1850 struct pipe_context
*pctx
,
1851 const struct pipe_sampler_state
*cso
)
1853 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
1856 /* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
1858 struct mali_sampler_descriptor sampler_descriptor
= {
1859 .filter_mode
= MALI_TEX_MIN(translate_tex_filter(cso
->min_img_filter
))
1860 | MALI_TEX_MAG(translate_tex_filter(cso
->mag_img_filter
))
1861 | translate_mip_filter(cso
->min_mip_filter
)
1864 .wrap_s
= translate_tex_wrap(cso
->wrap_s
),
1865 .wrap_t
= translate_tex_wrap(cso
->wrap_t
),
1866 .wrap_r
= translate_tex_wrap(cso
->wrap_r
),
1867 .compare_func
= panfrost_translate_alt_compare_func(cso
->compare_func
),
1869 cso
->border_color
.f
[0],
1870 cso
->border_color
.f
[1],
1871 cso
->border_color
.f
[2],
1872 cso
->border_color
.f
[3]
1874 .min_lod
= FIXED_16(0.0),
1875 .max_lod
= FIXED_16(31.0),
1879 so
->hw
= sampler_descriptor
;
1885 panfrost_bind_sampler_states(
1886 struct pipe_context
*pctx
,
1887 enum pipe_shader_type shader
,
1888 unsigned start_slot
, unsigned num_sampler
,
1891 assert(start_slot
== 0);
1893 struct panfrost_context
*ctx
= pan_context(pctx
);
1895 /* XXX: Should upload, not just copy? */
1896 ctx
->sampler_count
[shader
] = num_sampler
;
1897 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
1899 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
;
1903 panfrost_variant_matches(struct panfrost_context
*ctx
, struct panfrost_shader_state
*variant
)
1905 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
1907 if (alpha
->enabled
|| variant
->alpha_state
.enabled
) {
1908 /* Make sure enable state is at least the same */
1909 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
1913 /* Check that the contents of the test are the same */
1914 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
1915 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
1917 if (!(same_func
&& same_ref
)) {
1921 /* Otherwise, we're good to go */
1926 panfrost_bind_fs_state(
1927 struct pipe_context
*pctx
,
1930 struct panfrost_context
*ctx
= pan_context(pctx
);
1935 /* Match the appropriate variant */
1937 signed variant
= -1;
1939 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
1941 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
1942 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
])) {
1948 if (variant
== -1) {
1949 /* No variant matched, so create a new one */
1950 variant
= variants
->variant_count
++;
1951 assert(variants
->variant_count
< MAX_SHADER_VARIANTS
);
1953 variants
->variants
[variant
].base
= hwcso
;
1954 variants
->variants
[variant
].alpha_state
= ctx
->depth_stencil
->alpha
;
1956 /* Allocate the mapped descriptor ahead-of-time. TODO: Use for FS as well as VS */
1957 struct panfrost_context
*ctx
= pan_context(pctx
);
1958 struct panfrost_transfer transfer
= panfrost_allocate_chunk(ctx
, sizeof(struct mali_shader_meta
), HEAP_DESCRIPTOR
);
1960 variants
->variants
[variant
].tripipe
= (struct mali_shader_meta
*) transfer
.cpu
;
1961 variants
->variants
[variant
].tripipe_gpu
= transfer
.gpu
;
1965 /* Select this variant */
1966 variants
->active_variant
= variant
;
1968 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
1969 assert(panfrost_variant_matches(ctx
, shader_state
));
1971 /* Now we have a variant selected, so compile and go */
1973 if (!shader_state
->compiled
) {
1974 panfrost_shader_compile(ctx
, shader_state
->tripipe
, NULL
, JOB_TYPE_TILER
, shader_state
);
1975 shader_state
->compiled
= true;
1979 ctx
->dirty
|= PAN_DIRTY_FS
;
1983 panfrost_bind_vs_state(
1984 struct pipe_context
*pctx
,
1987 struct panfrost_context
*ctx
= pan_context(pctx
);
1992 if (!ctx
->vs
->variants
[0].compiled
) {
1993 ctx
->vs
->variants
[0].base
= hwcso
;
1995 /* TODO DRY from above */
1996 struct panfrost_transfer transfer
= panfrost_allocate_chunk(ctx
, sizeof(struct mali_shader_meta
), HEAP_DESCRIPTOR
);
1997 ctx
->vs
->variants
[0].tripipe
= (struct mali_shader_meta
*) transfer
.cpu
;
1998 ctx
->vs
->variants
[0].tripipe_gpu
= transfer
.gpu
;
2000 panfrost_shader_compile(ctx
, ctx
->vs
->variants
[0].tripipe
, NULL
, JOB_TYPE_VERTEX
, &ctx
->vs
->variants
[0]);
2001 ctx
->vs
->variants
[0].compiled
= true;
2005 ctx
->dirty
|= PAN_DIRTY_VS
;
2009 panfrost_set_vertex_buffers(
2010 struct pipe_context
*pctx
,
2011 unsigned start_slot
,
2012 unsigned num_buffers
,
2013 const struct pipe_vertex_buffer
*buffers
)
2015 struct panfrost_context
*ctx
= pan_context(pctx
);
2016 assert(num_buffers
<= PIPE_MAX_ATTRIBS
);
2018 /* XXX: Dirty tracking? etc */
2020 size_t sz
= sizeof(buffers
[0]) * num_buffers
;
2021 ctx
->vertex_buffers
= malloc(sz
);
2022 ctx
->vertex_buffer_count
= num_buffers
;
2023 memcpy(ctx
->vertex_buffers
, buffers
, sz
);
2025 if (ctx
->vertex_buffers
) {
2026 free(ctx
->vertex_buffers
);
2027 ctx
->vertex_buffers
= NULL
;
2030 ctx
->vertex_buffer_count
= 0;
2035 panfrost_set_constant_buffer(
2036 struct pipe_context
*pctx
,
2037 enum pipe_shader_type shader
, uint index
,
2038 const struct pipe_constant_buffer
*buf
)
2040 struct panfrost_context
*ctx
= pan_context(pctx
);
2041 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
2043 size_t sz
= buf
? buf
->buffer_size
: 0;
2045 /* Free previous buffer */
2052 pbuf
->buffer
= NULL
;
2055 /* If unbinding, we're done */
2060 /* Multiple constant buffers not yet supported */
2065 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (buf
->buffer
);
2068 cpu
= rsrc
->bo
->cpu
[0];
2069 } else if (buf
->user_buffer
) {
2070 cpu
= buf
->user_buffer
;
2072 printf("No constant buffer?\n");
2076 /* Copy the constant buffer into the driver context for later upload */
2078 pbuf
->buffer
= malloc(sz
);
2079 memcpy(pbuf
->buffer
, cpu
+ buf
->buffer_offset
, sz
);
2083 panfrost_set_stencil_ref(
2084 struct pipe_context
*pctx
,
2085 const struct pipe_stencil_ref
*ref
)
2087 struct panfrost_context
*ctx
= pan_context(pctx
);
2088 ctx
->stencil_ref
= *ref
;
2090 /* Shader core dirty */
2091 ctx
->dirty
|= PAN_DIRTY_FS
;
2094 static struct pipe_sampler_view
*
2095 panfrost_create_sampler_view(
2096 struct pipe_context
*pctx
,
2097 struct pipe_resource
*texture
,
2098 const struct pipe_sampler_view
*template)
2100 struct panfrost_sampler_view
*so
= CALLOC_STRUCT(panfrost_sampler_view
);
2101 int bytes_per_pixel
= util_format_get_blocksize(texture
->format
);
2103 pipe_reference(NULL
, &texture
->reference
);
2105 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
2107 so
->base
= *template;
2108 so
->base
.texture
= texture
;
2109 so
->base
.reference
.count
= 1;
2110 so
->base
.context
= pctx
;
2112 /* sampler_views correspond to texture descriptors, minus the texture
2113 * (data) itself. So, we serialise the descriptor here and cache it for
2116 /* TODO: Other types of textures */
2117 assert(template->target
== PIPE_TEXTURE_2D
);
2119 /* Make sure it's something with which we're familiar */
2120 assert(bytes_per_pixel
>= 1 && bytes_per_pixel
<= 4);
2122 /* TODO: Detect from format better */
2123 const struct util_format_description
*desc
= util_format_description(prsrc
->base
.format
);
2125 unsigned char user_swizzle
[4] = {
2126 template->swizzle_r
,
2127 template->swizzle_g
,
2128 template->swizzle_b
,
2132 enum mali_format format
= panfrost_find_format(desc
);
2134 struct mali_texture_descriptor texture_descriptor
= {
2135 .width
= MALI_POSITIVE(texture
->width0
),
2136 .height
= MALI_POSITIVE(texture
->height0
),
2137 .depth
= MALI_POSITIVE(texture
->depth0
),
2141 .swizzle
= panfrost_translate_swizzle_4(desc
->swizzle
),
2145 .is_not_cubemap
= 1,
2147 /* 0x11 - regular texture 2d, uncompressed tiled */
2148 /* 0x12 - regular texture 2d, uncompressed linear */
2149 /* 0x1c - AFBC compressed (internally tiled, probably) texture 2D */
2151 .usage2
= prsrc
->bo
->has_afbc
? 0x1c : (prsrc
->bo
->tiled
? 0x11 : 0x12),
2154 .swizzle
= panfrost_translate_swizzle_4(user_swizzle
)
2157 /* TODO: Other base levels require adjusting dimensions / level numbers / etc */
2158 assert (template->u
.tex
.first_level
== 0);
2160 texture_descriptor
.nr_mipmap_levels
= template->u
.tex
.last_level
- template->u
.tex
.first_level
;
2162 so
->hw
= texture_descriptor
;
2164 return (struct pipe_sampler_view
*) so
;
2168 panfrost_set_sampler_views(
2169 struct pipe_context
*pctx
,
2170 enum pipe_shader_type shader
,
2171 unsigned start_slot
, unsigned num_views
,
2172 struct pipe_sampler_view
**views
)
2174 struct panfrost_context
*ctx
= pan_context(pctx
);
2176 assert(start_slot
== 0);
2178 ctx
->sampler_view_count
[shader
] = num_views
;
2179 memcpy(ctx
->sampler_views
[shader
], views
, num_views
* sizeof (void *));
2181 ctx
->dirty
|= PAN_DIRTY_TEXTURES
;
2185 panfrost_sampler_view_destroy(
2186 struct pipe_context
*pctx
,
2187 struct pipe_sampler_view
*views
)
2189 //struct panfrost_context *ctx = pan_context(pctx);
2197 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
2198 const struct pipe_framebuffer_state
*fb
)
2200 struct panfrost_context
*ctx
= pan_context(pctx
);
2202 /* Flush when switching away from an FBO */
2204 if (!panfrost_is_scanout(ctx
)) {
2205 panfrost_flush(pctx
, NULL
, 0);
2208 ctx
->pipe_framebuffer
.nr_cbufs
= fb
->nr_cbufs
;
2209 ctx
->pipe_framebuffer
.samples
= fb
->samples
;
2210 ctx
->pipe_framebuffer
.layers
= fb
->layers
;
2211 ctx
->pipe_framebuffer
.width
= fb
->width
;
2212 ctx
->pipe_framebuffer
.height
= fb
->height
;
2214 for (int i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
2215 struct pipe_surface
*cb
= i
< fb
->nr_cbufs
? fb
->cbufs
[i
] : NULL
;
2217 /* check if changing cbuf */
2218 if (ctx
->pipe_framebuffer
.cbufs
[i
] == cb
) continue;
2220 if (cb
&& (i
!= 0)) {
2221 printf("XXX: Multiple render targets not supported before t7xx!\n");
2226 pipe_surface_reference(&ctx
->pipe_framebuffer
.cbufs
[i
], cb
);
2231 ctx
->vt_framebuffer
= panfrost_emit_fbd(ctx
);
2232 panfrost_attach_vt_framebuffer(ctx
);
2233 panfrost_new_frag_framebuffer(ctx
);
2234 panfrost_set_scissor(ctx
);
2236 struct panfrost_resource
*tex
= ((struct panfrost_resource
*) ctx
->pipe_framebuffer
.cbufs
[i
]->texture
);
2237 bool is_scanout
= panfrost_is_scanout(ctx
);
2239 if (!is_scanout
&& !tex
->bo
->has_afbc
) {
2240 /* The blob is aggressive about enabling AFBC. As such,
2241 * it's pretty much necessary to use it here, since we
2242 * have no traces of non-compressed FBO. */
2244 panfrost_enable_afbc(ctx
, tex
, false);
2247 if (!is_scanout
&& !tex
->bo
->has_checksum
) {
2248 /* Enable transaction elimination if we can */
2249 panfrost_enable_checksum(ctx
, tex
);
2254 struct pipe_surface
*zb
= fb
->zsbuf
;
2256 if (ctx
->pipe_framebuffer
.zsbuf
!= zb
) {
2257 pipe_surface_reference(&ctx
->pipe_framebuffer
.zsbuf
, zb
);
2262 ctx
->vt_framebuffer
= panfrost_emit_fbd(ctx
);
2263 panfrost_attach_vt_framebuffer(ctx
);
2264 panfrost_new_frag_framebuffer(ctx
);
2265 panfrost_set_scissor(ctx
);
2267 struct panfrost_resource
*tex
= ((struct panfrost_resource
*) ctx
->pipe_framebuffer
.zsbuf
->texture
);
2269 if (!tex
->bo
->has_afbc
&& !panfrost_is_scanout(ctx
))
2270 panfrost_enable_afbc(ctx
, tex
, true);
2275 /* Force a clear XXX wrong? */
2276 if (ctx
->last_clear
.color
)
2277 panfrost_clear(&ctx
->base
, ctx
->last_clear
.buffers
, ctx
->last_clear
.color
, ctx
->last_clear
.depth
, ctx
->last_clear
.stencil
);
2280 /* Don't consider the buffer dirty */
2281 ctx
->dirty
&= ~PAN_DIRTY_CLEAR
;
2286 panfrost_create_blend_state(struct pipe_context
*pipe
,
2287 const struct pipe_blend_state
*blend
)
2289 struct panfrost_context
*ctx
= pan_context(pipe
);
2290 struct panfrost_blend_state
*so
= CALLOC_STRUCT(panfrost_blend_state
);
2293 /* TODO: The following features are not yet implemented */
2294 assert(!blend
->logicop_enable
);
2295 assert(!blend
->alpha_to_coverage
);
2296 assert(!blend
->alpha_to_one
);
2298 /* Compile the blend state, first as fixed-function if we can */
2300 if (panfrost_make_fixed_blend_mode(&blend
->rt
[0], &so
->equation
, blend
->rt
[0].colormask
, &ctx
->blend_color
))
2303 /* If we can't, compile a blend shader instead */
2305 panfrost_make_blend_shader(ctx
, so
, &ctx
->blend_color
);
2311 panfrost_bind_blend_state(struct pipe_context
*pipe
,
2314 struct panfrost_context
*ctx
= pan_context(pipe
);
2315 struct pipe_blend_state
*blend
= (struct pipe_blend_state
*) cso
;
2316 struct panfrost_blend_state
*pblend
= (struct panfrost_blend_state
*) cso
;
2317 ctx
->blend
= pblend
;
2322 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_NO_DITHER
, !blend
->dither
);
2324 /* TODO: Attach color */
2326 /* Shader itself is not dirty, but the shader core is */
2327 ctx
->dirty
|= PAN_DIRTY_FS
;
2331 panfrost_delete_blend_state(struct pipe_context
*pipe
,
2334 printf("Deleting blend state may leak blend shader\n");
2339 panfrost_set_blend_color(struct pipe_context
*pipe
,
2340 const struct pipe_blend_color
*blend_color
)
2342 struct panfrost_context
*ctx
= pan_context(pipe
);
2344 /* If blend_color is we're unbinding, so ctx->blend_color is now undefined -> nothing to do */
2347 ctx
->blend_color
= *blend_color
;
2349 /* The blend mode depends on the blend constant color, due to the
2350 * fixed/programmable split. So, we're forced to regenerate the blend
2353 /* TODO: Attach color */
2358 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
2359 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
2361 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
2365 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
2368 struct panfrost_context
*ctx
= pan_context(pipe
);
2369 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
2370 ctx
->depth_stencil
= depth_stencil
;
2375 /* Alpha does not exist in the hardware (it's not in ES3), so it's
2376 * emulated in the fragment shader */
2378 if (depth_stencil
->alpha
.enabled
) {
2379 /* We need to trigger a new shader (maybe) */
2380 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->fs
);
2384 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_STENCIL_TEST
, depth_stencil
->stencil
[0].enabled
); /* XXX: which one? */
2386 panfrost_make_stencil_state(&depth_stencil
->stencil
[0], &ctx
->fragment_shader_core
.stencil_front
);
2387 ctx
->fragment_shader_core
.stencil_mask_front
= depth_stencil
->stencil
[0].writemask
;
2389 panfrost_make_stencil_state(&depth_stencil
->stencil
[1], &ctx
->fragment_shader_core
.stencil_back
);
2390 ctx
->fragment_shader_core
.stencil_mask_back
= depth_stencil
->stencil
[1].writemask
;
2392 /* Depth state (TODO: Refactor) */
2393 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_DEPTH_TEST
, depth_stencil
->depth
.enabled
);
2395 int func
= depth_stencil
->depth
.enabled
? depth_stencil
->depth
.func
: PIPE_FUNC_ALWAYS
;
2397 ctx
->fragment_shader_core
.unknown2_3
&= ~MALI_DEPTH_FUNC_MASK
;
2398 ctx
->fragment_shader_core
.unknown2_3
|= MALI_DEPTH_FUNC(panfrost_translate_compare_func(func
));
2400 /* Bounds test not implemented */
2401 assert(!depth_stencil
->depth
.bounds_test
);
2403 ctx
->dirty
|= PAN_DIRTY_FS
;
2407 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
2413 panfrost_set_sample_mask(struct pipe_context
*pipe
,
2414 unsigned sample_mask
)
2419 panfrost_set_clip_state(struct pipe_context
*pipe
,
2420 const struct pipe_clip_state
*clip
)
2422 //struct panfrost_context *panfrost = pan_context(pipe);
2426 panfrost_set_viewport_states(struct pipe_context
*pipe
,
2427 unsigned start_slot
,
2428 unsigned num_viewports
,
2429 const struct pipe_viewport_state
*viewports
)
2431 struct panfrost_context
*ctx
= pan_context(pipe
);
2433 assert(start_slot
== 0);
2434 assert(num_viewports
== 1);
2436 ctx
->pipe_viewport
= *viewports
;
2439 /* TODO: What if not centered? */
2440 float w
= abs(viewports
->scale
[0]) * 2.0;
2441 float h
= abs(viewports
->scale
[1]) * 2.0;
2443 ctx
->viewport
.viewport1
[0] = MALI_POSITIVE((int) w
);
2444 ctx
->viewport
.viewport1
[1] = MALI_POSITIVE((int) h
);
2449 panfrost_set_scissor_states(struct pipe_context
*pipe
,
2450 unsigned start_slot
,
2451 unsigned num_scissors
,
2452 const struct pipe_scissor_state
*scissors
)
2454 struct panfrost_context
*ctx
= pan_context(pipe
);
2456 assert(start_slot
== 0);
2457 assert(num_scissors
== 1);
2459 ctx
->scissor
= *scissors
;
2461 panfrost_set_scissor(ctx
);
2465 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
2466 const struct pipe_poly_stipple
*stipple
)
2468 //struct panfrost_context *panfrost = pan_context(pipe);
2472 panfrost_set_active_query_state(struct pipe_context
*pipe
,
2475 //struct panfrost_context *panfrost = pan_context(pipe);
2479 panfrost_destroy(struct pipe_context
*pipe
)
2481 struct panfrost_context
*panfrost
= pan_context(pipe
);
2483 if (panfrost
->blitter
)
2484 util_blitter_destroy(panfrost
->blitter
);
2487 static struct pipe_query
*
2488 panfrost_create_query(struct pipe_context
*pipe
,
2492 struct panfrost_query
*q
= CALLOC_STRUCT(panfrost_query
);
2497 return (struct pipe_query
*) q
;
2501 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2507 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2509 struct panfrost_context
*ctx
= pan_context(pipe
);
2510 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2512 switch (query
->type
) {
2513 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2514 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2516 /* Allocate a word for the query results to be stored */
2517 query
->transfer
= panfrost_allocate_chunk(ctx
, sizeof(unsigned), HEAP_DESCRIPTOR
);
2519 ctx
->occlusion_query
= query
;
2525 fprintf(stderr
, "Skipping query %d\n", query
->type
);
2533 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2535 struct panfrost_context
*ctx
= pan_context(pipe
);
2536 ctx
->occlusion_query
= NULL
;
2541 panfrost_get_query_result(struct pipe_context
*pipe
,
2542 struct pipe_query
*q
,
2544 union pipe_query_result
*vresult
)
2547 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2549 /* We need to flush out the jobs to actually run the counter, TODO
2550 * check wait, TODO wallpaper after if needed */
2552 panfrost_flush(pipe
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2554 switch (query
->type
) {
2555 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2556 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
: {
2557 /* Read back the query results */
2558 unsigned *result
= (unsigned *) query
->transfer
.cpu
;
2559 unsigned passed
= *result
;
2561 vresult
->b
= !!passed
;
2565 fprintf(stderr
, "Skipped query get %d\n", query
->type
);
2573 panfrost_setup_hardware(struct panfrost_context
*ctx
)
2575 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2576 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
2578 for (int i
= 0; i
< ARRAY_SIZE(ctx
->transient_pools
); ++i
) {
2579 /* Allocate the beginning of the transient pool */
2580 int entry_size
= (1 << 22); /* 4MB */
2582 ctx
->transient_pools
[i
].entry_size
= entry_size
;
2583 ctx
->transient_pools
[i
].entry_count
= 1;
2585 ctx
->transient_pools
[i
].entries
[0] = (struct panfrost_memory_entry
*) pb_slab_alloc(&screen
->slabs
, entry_size
, HEAP_TRANSIENT
);
2588 screen
->driver
->allocate_slab(screen
, &ctx
->scratchpad
, 64, false, 0, 0, 0);
2589 screen
->driver
->allocate_slab(screen
, &ctx
->varying_mem
, 16384, false, 0, 0, 0);
2590 screen
->driver
->allocate_slab(screen
, &ctx
->shaders
, 4096, true, PAN_ALLOCATE_EXECUTE
, 0, 0);
2591 screen
->driver
->allocate_slab(screen
, &ctx
->tiler_heap
, 32768, false, PAN_ALLOCATE_GROWABLE
, 1, 128);
2592 screen
->driver
->allocate_slab(screen
, &ctx
->misc_0
, 128, false, PAN_ALLOCATE_GROWABLE
, 1, 128);
2596 /* New context creation, which also does hardware initialisation since I don't
2597 * know the better way to structure this :smirk: */
2599 struct pipe_context
*
2600 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
2602 struct panfrost_context
*ctx
= CALLOC_STRUCT(panfrost_context
);
2603 memset(ctx
, 0, sizeof(*ctx
));
2604 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2606 gallium
->screen
= screen
;
2608 gallium
->destroy
= panfrost_destroy
;
2610 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
2612 gallium
->flush
= panfrost_flush
;
2613 gallium
->clear
= panfrost_clear
;
2614 gallium
->draw_vbo
= panfrost_draw_vbo
;
2616 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
2617 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
2619 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
2621 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
2622 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
2623 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
2625 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
2626 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
2627 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
2629 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
2630 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
2631 gallium
->delete_vertex_elements_state
= panfrost_delete_vertex_elements_state
;
2633 gallium
->create_fs_state
= panfrost_create_shader_state
;
2634 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
2635 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
2637 gallium
->create_vs_state
= panfrost_create_shader_state
;
2638 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
2639 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
2641 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
2642 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
2643 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
2645 gallium
->create_blend_state
= panfrost_create_blend_state
;
2646 gallium
->bind_blend_state
= panfrost_bind_blend_state
;
2647 gallium
->delete_blend_state
= panfrost_delete_blend_state
;
2649 gallium
->set_blend_color
= panfrost_set_blend_color
;
2651 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
2652 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
2653 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
2655 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
2657 gallium
->set_clip_state
= panfrost_set_clip_state
;
2658 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
2659 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
2660 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
2661 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
2663 gallium
->create_query
= panfrost_create_query
;
2664 gallium
->destroy_query
= panfrost_destroy_query
;
2665 gallium
->begin_query
= panfrost_begin_query
;
2666 gallium
->end_query
= panfrost_end_query
;
2667 gallium
->get_query_result
= panfrost_get_query_result
;
2669 panfrost_resource_context_init(gallium
);
2671 panfrost_setup_hardware(ctx
);
2674 gallium
->stream_uploader
= u_upload_create_default(gallium
);
2675 gallium
->const_uploader
= gallium
->stream_uploader
;
2676 assert(gallium
->stream_uploader
);
2678 ctx
->primconvert
= util_primconvert_create(gallium
,
2679 (1 << PIPE_PRIM_QUADS
) - 1);
2680 assert(ctx
->primconvert
);
2682 ctx
->blitter
= util_blitter_create(gallium
);
2683 assert(ctx
->blitter
);
2685 /* Prepare for render! */
2688 ctx
->vt_framebuffer
= panfrost_emit_fbd(ctx
);
2690 panfrost_emit_vertex_payload(ctx
);
2691 panfrost_emit_tiler_payload(ctx
);
2692 panfrost_invalidate_frame(ctx
);
2693 panfrost_viewport(ctx
, 0.0, 1.0, 0, 0, ctx
->pipe_framebuffer
.width
, ctx
->pipe_framebuffer
.height
);
2694 panfrost_default_shader_backend(ctx
);
2695 panfrost_generate_space_filler_indices();