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_format.h"
31 #include "util/macros.h"
32 #include "util/u_format.h"
33 #include "util/u_inlines.h"
34 #include "util/u_upload_mgr.h"
35 #include "util/u_memory.h"
36 #include "util/u_vbuf.h"
37 #include "util/half_float.h"
38 #include "util/u_helpers.h"
39 #include "util/u_format.h"
40 #include "util/u_prim_restart.h"
41 #include "indices/u_primconvert.h"
42 #include "tgsi/tgsi_parse.h"
43 #include "util/u_math.h"
45 #include "pan_screen.h"
46 #include "pan_blending.h"
47 #include "pan_blend_shaders.h"
49 #include "pan_tiler.h"
51 /* Do not actually send anything to the GPU; merely generate the cmdstream as fast as possible. Disables framebuffer writes */
54 static enum mali_job_type
55 panfrost_job_type_for_pipe(enum pipe_shader_type type
) {
58 case PIPE_SHADER_VERTEX
:
59 return JOB_TYPE_VERTEX
;
61 case PIPE_SHADER_FRAGMENT
:
62 /* Note: JOB_TYPE_FRAGMENT is different.
63 * JOB_TYPE_FRAGMENT actually executes the
64 * fragment shader, but JOB_TYPE_TILER is how you
66 return JOB_TYPE_TILER
;
68 case PIPE_SHADER_GEOMETRY
:
69 return JOB_TYPE_GEOMETRY
;
71 case PIPE_SHADER_COMPUTE
:
72 return JOB_TYPE_COMPUTE
;
75 unreachable("Unsupported shader stage");
79 /* Framebuffer descriptor */
81 static struct midgard_tiler_descriptor
82 panfrost_emit_midg_tiler(
83 struct panfrost_context
*ctx
,
86 unsigned vertex_count
)
88 struct midgard_tiler_descriptor t
= {};
91 panfrost_choose_hierarchy_mask(width
, height
, vertex_count
);
93 /* Compute the polygon header size and use that to offset the body */
95 unsigned header_size
= panfrost_tiler_header_size(
96 width
, height
, t
.hierarchy_mask
);
98 unsigned body_size
= panfrost_tiler_body_size(
99 width
, height
, t
.hierarchy_mask
);
103 unsigned total_size
= header_size
+ body_size
;
105 if (t
.hierarchy_mask
) {
106 assert(ctx
->tiler_polygon_list
.bo
->size
>= total_size
);
108 /* Specify allocated tiler structures */
109 t
.polygon_list
= ctx
->tiler_polygon_list
.bo
->gpu
;
111 /* Allow the entire tiler heap */
112 t
.heap_start
= ctx
->tiler_heap
.bo
->gpu
;
114 ctx
->tiler_heap
.bo
->gpu
+ ctx
->tiler_heap
.bo
->size
;
116 /* The tiler is disabled, so don't allow the tiler heap */
117 t
.heap_start
= ctx
->tiler_heap
.bo
->gpu
;
118 t
.heap_end
= t
.heap_start
;
120 /* Use a dummy polygon list */
121 t
.polygon_list
= ctx
->tiler_dummy
.bo
->gpu
;
123 /* Also, set a "tiler disabled?" flag? */
124 t
.hierarchy_mask
|= 0x1000;
127 t
.polygon_list_body
=
128 t
.polygon_list
+ header_size
;
130 t
.polygon_list_size
=
131 header_size
+ body_size
;
136 struct mali_single_framebuffer
137 panfrost_emit_sfbd(struct panfrost_context
*ctx
, unsigned vertex_count
)
139 unsigned width
= ctx
->pipe_framebuffer
.width
;
140 unsigned height
= ctx
->pipe_framebuffer
.height
;
142 struct mali_single_framebuffer framebuffer
= {
143 .width
= MALI_POSITIVE(width
),
144 .height
= MALI_POSITIVE(width
),
146 .format
= 0x30000000,
147 .clear_flags
= 0x1000,
148 .unknown_address_0
= ctx
->scratchpad
.bo
->gpu
,
149 .tiler
= panfrost_emit_midg_tiler(ctx
,
150 width
, height
, vertex_count
),
156 struct bifrost_framebuffer
157 panfrost_emit_mfbd(struct panfrost_context
*ctx
, unsigned vertex_count
)
159 unsigned width
= ctx
->pipe_framebuffer
.width
;
160 unsigned height
= ctx
->pipe_framebuffer
.height
;
162 struct bifrost_framebuffer framebuffer
= {
163 .width1
= MALI_POSITIVE(width
),
164 .height1
= MALI_POSITIVE(height
),
165 .width2
= MALI_POSITIVE(width
),
166 .height2
= MALI_POSITIVE(height
),
171 .rt_count_1
= MALI_POSITIVE(1),
176 .scratchpad
= ctx
->scratchpad
.bo
->gpu
,
177 .tiler
= panfrost_emit_midg_tiler(ctx
,
178 width
, height
, vertex_count
)
184 /* Are we currently rendering to the screen (rather than an FBO)? */
187 panfrost_is_scanout(struct panfrost_context
*ctx
)
189 /* If there is no color buffer, it's an FBO */
190 if (ctx
->pipe_framebuffer
.nr_cbufs
!= 1)
193 /* If we're too early that no framebuffer was sent, it's scanout */
194 if (!ctx
->pipe_framebuffer
.cbufs
[0])
197 return ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_DISPLAY_TARGET
||
198 ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_SCANOUT
||
199 ctx
->pipe_framebuffer
.cbufs
[0]->texture
->bind
& PIPE_BIND_SHARED
;
204 struct pipe_context
*pipe
,
206 const union pipe_color_union
*color
,
207 double depth
, unsigned stencil
)
209 struct panfrost_context
*ctx
= pan_context(pipe
);
210 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
212 panfrost_job_clear(ctx
, job
, buffers
, color
, depth
, stencil
);
216 panfrost_attach_vt_mfbd(struct panfrost_context
*ctx
)
218 return panfrost_upload_transient(ctx
, &ctx
->vt_framebuffer_mfbd
, sizeof(ctx
->vt_framebuffer_mfbd
)) | MALI_MFBD
;
222 panfrost_attach_vt_sfbd(struct panfrost_context
*ctx
)
224 return panfrost_upload_transient(ctx
, &ctx
->vt_framebuffer_sfbd
, sizeof(ctx
->vt_framebuffer_sfbd
)) | MALI_SFBD
;
228 panfrost_attach_vt_framebuffer(struct panfrost_context
*ctx
)
230 mali_ptr framebuffer
= ctx
->require_sfbd
?
231 panfrost_attach_vt_sfbd(ctx
) :
232 panfrost_attach_vt_mfbd(ctx
);
234 ctx
->payload_vertex
.postfix
.framebuffer
= framebuffer
;
235 ctx
->payload_tiler
.postfix
.framebuffer
= framebuffer
;
238 /* Reset per-frame context, called on context initialisation as well as after
239 * flushing a frame */
242 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
244 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
;
245 DBG("Uploaded transient %d bytes\n", transient_count
);
247 /* Rotate cmdstream */
248 if ((++ctx
->cmdstream_i
) == (sizeof(ctx
->transient_pools
) / sizeof(ctx
->transient_pools
[0])))
249 ctx
->cmdstream_i
= 0;
251 if (ctx
->require_sfbd
)
252 ctx
->vt_framebuffer_sfbd
= panfrost_emit_sfbd(ctx
, ~0);
254 ctx
->vt_framebuffer_mfbd
= panfrost_emit_mfbd(ctx
, ~0);
256 /* Reset varyings allocated */
257 ctx
->varying_height
= 0;
259 /* The transient cmdstream is dirty every frame; the only bits worth preserving
260 * (textures, shaders, etc) are in other buffers anyways */
262 ctx
->transient_pools
[ctx
->cmdstream_i
].entry_index
= 0;
263 ctx
->transient_pools
[ctx
->cmdstream_i
].entry_offset
= 0;
265 /* Regenerate payloads */
266 panfrost_attach_vt_framebuffer(ctx
);
269 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
272 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
| PAN_DIRTY_TEXTURES
;
275 /* In practice, every field of these payloads should be configurable
276 * arbitrarily, which means these functions are basically catch-all's for
277 * as-of-yet unwavering unknowns */
280 panfrost_emit_vertex_payload(struct panfrost_context
*ctx
)
282 struct midgard_payload_vertex_tiler payload
= {
283 .gl_enables
= 0x4 | (ctx
->is_t6xx
? 0 : 0x2),
286 memcpy(&ctx
->payload_vertex
, &payload
, sizeof(payload
));
290 panfrost_emit_tiler_payload(struct panfrost_context
*ctx
)
292 struct midgard_payload_vertex_tiler payload
= {
294 .zero1
= 0xffff, /* Why is this only seen on test-quad-textured? */
298 memcpy(&ctx
->payload_tiler
, &payload
, sizeof(payload
));
302 translate_tex_wrap(enum pipe_tex_wrap w
)
305 case PIPE_TEX_WRAP_REPEAT
:
306 return MALI_WRAP_REPEAT
;
308 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
309 return MALI_WRAP_CLAMP_TO_EDGE
;
311 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
312 return MALI_WRAP_CLAMP_TO_BORDER
;
314 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
315 return MALI_WRAP_MIRRORED_REPEAT
;
318 unreachable("Invalid wrap");
323 translate_tex_filter(enum pipe_tex_filter f
)
326 case PIPE_TEX_FILTER_NEAREST
:
329 case PIPE_TEX_FILTER_LINEAR
:
333 unreachable("Invalid filter");
338 translate_mip_filter(enum pipe_tex_mipfilter f
)
340 return (f
== PIPE_TEX_MIPFILTER_LINEAR
) ? MALI_MIP_LINEAR
: 0;
344 panfrost_translate_compare_func(enum pipe_compare_func in
)
347 case PIPE_FUNC_NEVER
:
348 return MALI_FUNC_NEVER
;
351 return MALI_FUNC_LESS
;
353 case PIPE_FUNC_EQUAL
:
354 return MALI_FUNC_EQUAL
;
356 case PIPE_FUNC_LEQUAL
:
357 return MALI_FUNC_LEQUAL
;
359 case PIPE_FUNC_GREATER
:
360 return MALI_FUNC_GREATER
;
362 case PIPE_FUNC_NOTEQUAL
:
363 return MALI_FUNC_NOTEQUAL
;
365 case PIPE_FUNC_GEQUAL
:
366 return MALI_FUNC_GEQUAL
;
368 case PIPE_FUNC_ALWAYS
:
369 return MALI_FUNC_ALWAYS
;
372 unreachable("Invalid func");
377 panfrost_translate_alt_compare_func(enum pipe_compare_func in
)
380 case PIPE_FUNC_NEVER
:
381 return MALI_ALT_FUNC_NEVER
;
384 return MALI_ALT_FUNC_LESS
;
386 case PIPE_FUNC_EQUAL
:
387 return MALI_ALT_FUNC_EQUAL
;
389 case PIPE_FUNC_LEQUAL
:
390 return MALI_ALT_FUNC_LEQUAL
;
392 case PIPE_FUNC_GREATER
:
393 return MALI_ALT_FUNC_GREATER
;
395 case PIPE_FUNC_NOTEQUAL
:
396 return MALI_ALT_FUNC_NOTEQUAL
;
398 case PIPE_FUNC_GEQUAL
:
399 return MALI_ALT_FUNC_GEQUAL
;
401 case PIPE_FUNC_ALWAYS
:
402 return MALI_ALT_FUNC_ALWAYS
;
405 unreachable("Invalid alt func");
410 panfrost_translate_stencil_op(enum pipe_stencil_op in
)
413 case PIPE_STENCIL_OP_KEEP
:
414 return MALI_STENCIL_KEEP
;
416 case PIPE_STENCIL_OP_ZERO
:
417 return MALI_STENCIL_ZERO
;
419 case PIPE_STENCIL_OP_REPLACE
:
420 return MALI_STENCIL_REPLACE
;
422 case PIPE_STENCIL_OP_INCR
:
423 return MALI_STENCIL_INCR
;
425 case PIPE_STENCIL_OP_DECR
:
426 return MALI_STENCIL_DECR
;
428 case PIPE_STENCIL_OP_INCR_WRAP
:
429 return MALI_STENCIL_INCR_WRAP
;
431 case PIPE_STENCIL_OP_DECR_WRAP
:
432 return MALI_STENCIL_DECR_WRAP
;
434 case PIPE_STENCIL_OP_INVERT
:
435 return MALI_STENCIL_INVERT
;
438 unreachable("Invalid stencil op");
443 panfrost_make_stencil_state(const struct pipe_stencil_state
*in
, struct mali_stencil_test
*out
)
445 out
->ref
= 0; /* Gallium gets it from elsewhere */
447 out
->mask
= in
->valuemask
;
448 out
->func
= panfrost_translate_compare_func(in
->func
);
449 out
->sfail
= panfrost_translate_stencil_op(in
->fail_op
);
450 out
->dpfail
= panfrost_translate_stencil_op(in
->zfail_op
);
451 out
->dppass
= panfrost_translate_stencil_op(in
->zpass_op
);
455 panfrost_default_shader_backend(struct panfrost_context
*ctx
)
457 struct mali_shader_meta shader
= {
458 .alpha_coverage
= ~MALI_ALPHA_COVERAGE(0.000000),
460 .unknown2_3
= MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS
) | 0x3010,
461 .unknown2_4
= MALI_NO_MSAA
| 0x4e0,
465 shader
.unknown2_4
|= 0x10;
468 struct pipe_stencil_state default_stencil
= {
470 .func
= PIPE_FUNC_ALWAYS
,
471 .fail_op
= MALI_STENCIL_KEEP
,
472 .zfail_op
= MALI_STENCIL_KEEP
,
473 .zpass_op
= MALI_STENCIL_KEEP
,
478 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_front
);
479 shader
.stencil_mask_front
= default_stencil
.writemask
;
481 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_back
);
482 shader
.stencil_mask_back
= default_stencil
.writemask
;
484 if (default_stencil
.enabled
)
485 shader
.unknown2_4
|= MALI_STENCIL_TEST
;
487 memcpy(&ctx
->fragment_shader_core
, &shader
, sizeof(shader
));
490 /* Generates a vertex/tiler job. This is, in some sense, the heart of the
491 * graphics command stream. It should be called once per draw, accordding to
492 * presentations. Set is_tiler for "tiler" jobs (fragment shader jobs, but in
493 * Mali parlance, "fragment" refers to framebuffer writeout). Clear it for
496 struct panfrost_transfer
497 panfrost_vertex_tiler_job(struct panfrost_context
*ctx
, bool is_tiler
)
499 struct mali_job_descriptor_header job
= {
500 .job_type
= is_tiler
? JOB_TYPE_TILER
: JOB_TYPE_VERTEX
,
502 .job_descriptor_size
= 1,
506 struct midgard_payload_vertex_tiler
*payload
= is_tiler
? &ctx
->payload_tiler
: &ctx
->payload_vertex
;
508 /* There's some padding hacks on 32-bit */
515 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(job
) + sizeof(*payload
));
517 memcpy(transfer
.cpu
, &job
, sizeof(job
));
518 memcpy(transfer
.cpu
+ sizeof(job
) - offset
, payload
, sizeof(*payload
));
523 panfrost_emit_varyings(
524 struct panfrost_context
*ctx
,
525 union mali_attr
*slot
,
529 mali_ptr varying_address
= ctx
->varying_mem
.bo
->gpu
+ ctx
->varying_height
;
531 /* Fill out the descriptor */
532 slot
->elements
= varying_address
| MALI_ATTR_LINEAR
;
533 slot
->stride
= stride
;
534 slot
->size
= stride
* count
;
536 ctx
->varying_height
+= ALIGN_POT(slot
->size
, 64);
537 assert(ctx
->varying_height
< ctx
->varying_mem
.bo
->size
);
539 return varying_address
;
543 panfrost_emit_point_coord(union mali_attr
*slot
)
545 slot
->elements
= MALI_VARYING_POINT_COORD
| MALI_ATTR_LINEAR
;
546 slot
->stride
= slot
->size
= 0;
550 panfrost_emit_varying_descriptor(
551 struct panfrost_context
*ctx
,
552 unsigned vertex_count
)
554 /* Load the shaders */
556 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
557 struct panfrost_shader_state
*fs
= &ctx
->fs
->variants
[ctx
->fs
->active_variant
];
558 unsigned int num_gen_varyings
= 0;
560 /* Allocate the varying descriptor */
562 size_t vs_size
= sizeof(struct mali_attr_meta
) * vs
->tripipe
->varying_count
;
563 size_t fs_size
= sizeof(struct mali_attr_meta
) * fs
->tripipe
->varying_count
;
565 struct panfrost_transfer trans
= panfrost_allocate_transient(ctx
,
569 * Assign ->src_offset now that we know about all the general purpose
570 * varyings that will be used by the fragment and vertex shaders.
572 for (unsigned i
= 0; i
< vs
->tripipe
->varying_count
; i
++) {
574 * General purpose varyings have ->index set to 0, skip other
577 if (vs
->varyings
[i
].index
)
580 vs
->varyings
[i
].src_offset
= 16 * (num_gen_varyings
++);
583 for (unsigned i
= 0; i
< fs
->tripipe
->varying_count
; i
++) {
586 /* If we have a point sprite replacement, handle that here. We
587 * have to translate location first. TODO: Flip y in shader.
588 * We're already keying ... just time crunch .. */
590 unsigned loc
= fs
->varyings_loc
[i
];
592 (loc
>= VARYING_SLOT_VAR0
) ? (loc
- VARYING_SLOT_VAR0
) :
593 (loc
== VARYING_SLOT_PNTC
) ? 8 :
596 if (~pnt_loc
&& fs
->point_sprite_mask
& (1 << pnt_loc
)) {
597 /* gl_PointCoord index by convention */
598 fs
->varyings
[i
].index
= 3;
599 fs
->reads_point_coord
= true;
601 /* Swizzle out the z/w to 0/1 */
602 fs
->varyings
[i
].format
= MALI_RG16F
;
603 fs
->varyings
[i
].swizzle
=
604 panfrost_get_default_swizzle(2);
609 if (fs
->varyings
[i
].index
)
613 * Re-use the VS general purpose varying pos if it exists,
614 * create a new one otherwise.
616 for (j
= 0; j
< vs
->tripipe
->varying_count
; j
++) {
617 if (fs
->varyings_loc
[i
] == vs
->varyings_loc
[j
])
621 if (j
< vs
->tripipe
->varying_count
)
622 fs
->varyings
[i
].src_offset
= vs
->varyings
[j
].src_offset
;
624 fs
->varyings
[i
].src_offset
= 16 * (num_gen_varyings
++);
627 memcpy(trans
.cpu
, vs
->varyings
, vs_size
);
628 memcpy(trans
.cpu
+ vs_size
, fs
->varyings
, fs_size
);
630 ctx
->payload_vertex
.postfix
.varying_meta
= trans
.gpu
;
631 ctx
->payload_tiler
.postfix
.varying_meta
= trans
.gpu
+ vs_size
;
633 /* Buffer indices must be in this order per our convention */
634 union mali_attr varyings
[PIPE_MAX_ATTRIBS
];
637 panfrost_emit_varyings(ctx
, &varyings
[idx
++], num_gen_varyings
* 16,
640 /* fp32 vec4 gl_Position */
641 ctx
->payload_tiler
.postfix
.position_varying
=
642 panfrost_emit_varyings(ctx
, &varyings
[idx
++],
643 sizeof(float) * 4, vertex_count
);
646 if (vs
->writes_point_size
|| fs
->reads_point_coord
) {
647 /* fp16 vec1 gl_PointSize */
648 ctx
->payload_tiler
.primitive_size
.pointer
=
649 panfrost_emit_varyings(ctx
, &varyings
[idx
++],
653 if (fs
->reads_point_coord
) {
654 /* Special descriptor */
655 panfrost_emit_point_coord(&varyings
[idx
++]);
658 mali_ptr varyings_p
= panfrost_upload_transient(ctx
, &varyings
, idx
* sizeof(union mali_attr
));
659 ctx
->payload_vertex
.postfix
.varyings
= varyings_p
;
660 ctx
->payload_tiler
.postfix
.varyings
= varyings_p
;
664 panfrost_vertex_buffer_address(struct panfrost_context
*ctx
, unsigned i
)
666 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[i
];
667 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (buf
->buffer
.resource
);
669 return rsrc
->bo
->gpu
+ buf
->buffer_offset
;
673 panfrost_writes_point_size(struct panfrost_context
*ctx
)
676 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
678 return vs
->writes_point_size
&& ctx
->payload_tiler
.prefix
.draw_mode
== MALI_POINTS
;
681 /* Stage the attribute descriptors so we can adjust src_offset
682 * to let BOs align nicely */
685 panfrost_stage_attributes(struct panfrost_context
*ctx
)
687 struct panfrost_vertex_state
*so
= ctx
->vertex
;
689 size_t sz
= sizeof(struct mali_attr_meta
) * so
->num_elements
;
690 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sz
);
691 struct mali_attr_meta
*target
= (struct mali_attr_meta
*) transfer
.cpu
;
693 /* Copy as-is for the first pass */
694 memcpy(target
, so
->hw
, sz
);
696 /* Fixup offsets for the second pass. Recall that the hardware
697 * calculates attribute addresses as:
699 * addr = base + (stride * vtx) + src_offset;
701 * However, on Mali, base must be aligned to 64-bytes, so we
704 * base' = base & ~63 = base - (base & 63)
706 * To compensate when using base' (see emit_vertex_data), we have
707 * to adjust src_offset by the masked off piece:
709 * addr' = base' + (stride * vtx) + (src_offset + (base & 63))
710 * = base - (base & 63) + (stride * vtx) + src_offset + (base & 63)
711 * = base + (stride * vtx) + src_offset
717 unsigned start
= ctx
->payload_vertex
.draw_start
;
719 for (unsigned i
= 0; i
< so
->num_elements
; ++i
) {
720 unsigned vbi
= so
->pipe
[i
].vertex_buffer_index
;
721 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[vbi
];
722 mali_ptr addr
= panfrost_vertex_buffer_address(ctx
, vbi
);
724 /* Adjust by the masked off bits of the offset */
725 target
[i
].src_offset
+= (addr
& 63);
727 /* Also, somewhat obscurely per-instance data needs to be
728 * offset in response to a delayed start in an indexed draw */
730 if (so
->pipe
[i
].instance_divisor
&& ctx
->instance_count
> 1 && start
) {
731 target
[i
].src_offset
-= buf
->stride
* start
;
737 ctx
->payload_vertex
.postfix
.attribute_meta
= transfer
.gpu
;
741 panfrost_upload_sampler_descriptors(struct panfrost_context
*ctx
)
743 size_t desc_size
= sizeof(struct mali_sampler_descriptor
);
745 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
748 if (ctx
->sampler_count
[t
] && ctx
->sampler_view_count
[t
]) {
749 size_t transfer_size
= desc_size
* ctx
->sampler_count
[t
];
751 struct panfrost_transfer transfer
=
752 panfrost_allocate_transient(ctx
, transfer_size
);
754 struct mali_sampler_descriptor
*desc
=
755 (struct mali_sampler_descriptor
*) transfer
.cpu
;
757 for (int i
= 0; i
< ctx
->sampler_count
[t
]; ++i
)
758 desc
[i
] = ctx
->samplers
[t
][i
]->hw
;
760 upload
= transfer
.gpu
;
763 if (t
== PIPE_SHADER_FRAGMENT
)
764 ctx
->payload_tiler
.postfix
.sampler_descriptor
= upload
;
765 else if (t
== PIPE_SHADER_VERTEX
)
766 ctx
->payload_vertex
.postfix
.sampler_descriptor
= upload
;
774 struct panfrost_context
*ctx
,
775 struct panfrost_sampler_view
*view
)
778 return (mali_ptr
) NULL
;
780 struct pipe_sampler_view
*pview
= &view
->base
;
781 struct panfrost_resource
*rsrc
= pan_resource(pview
->texture
);
783 /* Do we interleave an explicit stride with every element? */
785 bool has_manual_stride
=
786 view
->hw
.format
.usage2
& MALI_TEX_MANUAL_STRIDE
;
788 /* For easy access */
790 assert(pview
->target
!= PIPE_BUFFER
);
791 unsigned first_level
= pview
->u
.tex
.first_level
;
792 unsigned last_level
= pview
->u
.tex
.last_level
;
793 unsigned first_layer
= pview
->u
.tex
.first_layer
;
794 unsigned last_layer
= pview
->u
.tex
.last_layer
;
796 /* Lower-bit is set when sampling from colour AFBC */
797 bool is_afbc
= rsrc
->layout
== PAN_AFBC
;
798 bool is_zs
= rsrc
->base
.bind
& PIPE_BIND_DEPTH_STENCIL
;
799 unsigned afbc_bit
= (is_afbc
&& !is_zs
) ? 1 : 0;
801 /* Add the BO to the job so it's retained until the job is done. */
802 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
803 panfrost_job_add_bo(job
, rsrc
->bo
);
805 /* Inject the addresses in, interleaving mip levels, cube faces, and
806 * strides in that order */
810 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
811 for (unsigned f
= first_layer
; f
<= last_layer
; ++f
) {
813 view
->hw
.payload
[idx
++] =
814 panfrost_get_texture_address(rsrc
, l
, f
) + afbc_bit
;
816 if (has_manual_stride
) {
817 view
->hw
.payload
[idx
++] =
818 rsrc
->slices
[l
].stride
;
823 return panfrost_upload_transient(ctx
, &view
->hw
,
824 sizeof(struct mali_texture_descriptor
));
828 panfrost_upload_texture_descriptors(struct panfrost_context
*ctx
)
830 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
831 mali_ptr trampoline
= 0;
833 if (ctx
->sampler_view_count
[t
]) {
834 uint64_t trampolines
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
836 for (int i
= 0; i
< ctx
->sampler_view_count
[t
]; ++i
)
838 panfrost_upload_tex(ctx
, ctx
->sampler_views
[t
][i
]);
840 trampoline
= panfrost_upload_transient(ctx
, trampolines
, sizeof(uint64_t) * ctx
->sampler_view_count
[t
]);
843 if (t
== PIPE_SHADER_FRAGMENT
)
844 ctx
->payload_tiler
.postfix
.texture_trampoline
= trampoline
;
845 else if (t
== PIPE_SHADER_VERTEX
)
846 ctx
->payload_vertex
.postfix
.texture_trampoline
= trampoline
;
852 struct sysval_uniform
{
860 static void panfrost_upload_viewport_scale_sysval(struct panfrost_context
*ctx
,
861 struct sysval_uniform
*uniform
)
863 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
865 uniform
->f
[0] = vp
->scale
[0];
866 uniform
->f
[1] = vp
->scale
[1];
867 uniform
->f
[2] = vp
->scale
[2];
870 static void panfrost_upload_viewport_offset_sysval(struct panfrost_context
*ctx
,
871 struct sysval_uniform
*uniform
)
873 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
875 uniform
->f
[0] = vp
->translate
[0];
876 uniform
->f
[1] = vp
->translate
[1];
877 uniform
->f
[2] = vp
->translate
[2];
880 static void panfrost_upload_txs_sysval(struct panfrost_context
*ctx
,
881 enum pipe_shader_type st
,
882 unsigned int sysvalid
,
883 struct sysval_uniform
*uniform
)
885 unsigned texidx
= PAN_SYSVAL_ID_TO_TXS_TEX_IDX(sysvalid
);
886 unsigned dim
= PAN_SYSVAL_ID_TO_TXS_DIM(sysvalid
);
887 bool is_array
= PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(sysvalid
);
888 struct pipe_sampler_view
*tex
= &ctx
->sampler_views
[st
][texidx
]->base
;
891 uniform
->i
[0] = u_minify(tex
->texture
->width0
, tex
->u
.tex
.first_level
);
894 uniform
->i
[1] = u_minify(tex
->texture
->height0
,
895 tex
->u
.tex
.first_level
);
898 uniform
->i
[2] = u_minify(tex
->texture
->depth0
,
899 tex
->u
.tex
.first_level
);
902 uniform
->i
[dim
] = tex
->texture
->array_size
;
905 static void panfrost_upload_sysvals(struct panfrost_context
*ctx
, void *buf
,
906 struct panfrost_shader_state
*ss
,
907 enum pipe_shader_type st
)
909 struct sysval_uniform
*uniforms
= (void *)buf
;
911 for (unsigned i
= 0; i
< ss
->sysval_count
; ++i
) {
912 int sysval
= ss
->sysval
[i
];
914 switch (PAN_SYSVAL_TYPE(sysval
)) {
915 case PAN_SYSVAL_VIEWPORT_SCALE
:
916 panfrost_upload_viewport_scale_sysval(ctx
, &uniforms
[i
]);
918 case PAN_SYSVAL_VIEWPORT_OFFSET
:
919 panfrost_upload_viewport_offset_sysval(ctx
, &uniforms
[i
]);
921 case PAN_SYSVAL_TEXTURE_SIZE
:
922 panfrost_upload_txs_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
932 panfrost_map_constant_buffer_cpu(struct panfrost_constant_buffer
*buf
, unsigned index
)
934 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
935 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
938 return rsrc
->bo
->cpu
;
939 else if (cb
->user_buffer
)
940 return cb
->user_buffer
;
942 unreachable("No constant buffer");
946 panfrost_map_constant_buffer_gpu(
947 struct panfrost_context
*ctx
,
948 struct panfrost_constant_buffer
*buf
,
951 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
952 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
955 return rsrc
->bo
->gpu
;
956 else if (cb
->user_buffer
)
957 return panfrost_upload_transient(ctx
, cb
->user_buffer
, cb
->buffer_size
);
959 unreachable("No constant buffer");
962 /* Compute number of UBOs active (more specifically, compute the highest UBO
963 * number addressable -- if there are gaps, include them in the count anyway).
964 * We always include UBO #0 in the count, since we *need* uniforms enabled for
968 panfrost_ubo_count(struct panfrost_context
*ctx
, enum pipe_shader_type stage
)
970 unsigned mask
= ctx
->constant_buffer
[stage
].enabled_mask
| 1;
971 return 32 - __builtin_clz(mask
);
974 /* Fixes up a shader state with current state, returning a GPU address to the
978 panfrost_patch_shader_state(
979 struct panfrost_context
*ctx
,
980 struct panfrost_shader_state
*ss
,
981 enum pipe_shader_type stage
)
983 ss
->tripipe
->texture_count
= ctx
->sampler_view_count
[stage
];
984 ss
->tripipe
->sampler_count
= ctx
->sampler_count
[stage
];
986 ss
->tripipe
->midgard1
.flags
= 0x220;
988 unsigned ubo_count
= panfrost_ubo_count(ctx
, stage
);
989 ss
->tripipe
->midgard1
.uniform_buffer_count
= ubo_count
;
991 return ss
->tripipe_gpu
;
994 /* Go through dirty flags and actualise them in the cmdstream. */
997 panfrost_emit_for_draw(struct panfrost_context
*ctx
, bool with_vertex_data
)
999 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
1001 if (with_vertex_data
) {
1002 panfrost_emit_vertex_data(job
);
1004 /* Varyings emitted for -all- geometry */
1005 unsigned total_count
= ctx
->padded_count
* ctx
->instance_count
;
1006 panfrost_emit_varying_descriptor(ctx
, total_count
);
1009 bool msaa
= ctx
->rasterizer
->base
.multisample
;
1011 if (ctx
->dirty
& PAN_DIRTY_RASTERIZER
) {
1012 ctx
->payload_tiler
.gl_enables
= ctx
->rasterizer
->tiler_gl_enables
;
1014 /* TODO: Sample size */
1015 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_HAS_MSAA
, msaa
);
1016 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_NO_MSAA
, !msaa
);
1019 panfrost_job_set_requirements(ctx
, job
);
1021 if (ctx
->occlusion_query
) {
1022 ctx
->payload_tiler
.gl_enables
|= MALI_OCCLUSION_QUERY
| MALI_OCCLUSION_PRECISE
;
1023 ctx
->payload_tiler
.postfix
.occlusion_counter
= ctx
->occlusion_query
->transfer
.gpu
;
1026 if (ctx
->dirty
& PAN_DIRTY_VS
) {
1029 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
1031 ctx
->payload_vertex
.postfix
._shader_upper
=
1032 panfrost_patch_shader_state(ctx
, vs
, PIPE_SHADER_VERTEX
) >> 4;
1035 if (ctx
->dirty
& (PAN_DIRTY_RASTERIZER
| PAN_DIRTY_VS
)) {
1036 /* Check if we need to link the gl_PointSize varying */
1037 if (!panfrost_writes_point_size(ctx
)) {
1038 /* If the size is constant, write it out. Otherwise,
1039 * don't touch primitive_size (since we would clobber
1040 * the pointer there) */
1042 ctx
->payload_tiler
.primitive_size
.constant
= ctx
->rasterizer
->base
.line_width
;
1046 /* TODO: Maybe dirty track FS, maybe not. For now, it's transient. */
1048 ctx
->dirty
|= PAN_DIRTY_FS
;
1050 if (ctx
->dirty
& PAN_DIRTY_FS
) {
1052 struct panfrost_shader_state
*variant
= &ctx
->fs
->variants
[ctx
->fs
->active_variant
];
1054 panfrost_patch_shader_state(ctx
, variant
, PIPE_SHADER_FRAGMENT
);
1056 #define COPY(name) ctx->fragment_shader_core.name = variant->tripipe->name
1059 COPY(attribute_count
);
1060 COPY(varying_count
);
1061 COPY(texture_count
);
1062 COPY(sampler_count
);
1063 COPY(sampler_count
);
1064 COPY(midgard1
.uniform_count
);
1065 COPY(midgard1
.uniform_buffer_count
);
1066 COPY(midgard1
.work_count
);
1067 COPY(midgard1
.flags
);
1068 COPY(midgard1
.unknown2
);
1072 /* Get blending setup */
1073 struct panfrost_blend_final blend
=
1074 panfrost_get_blend_for_context(ctx
, 0);
1076 /* If there is a blend shader, work registers are shared */
1078 if (blend
.is_shader
)
1079 ctx
->fragment_shader_core
.midgard1
.work_count
= /*MAX2(ctx->fragment_shader_core.midgard1.work_count, ctx->blend->blend_work_count)*/16;
1081 /* Set late due to depending on render state */
1082 unsigned flags
= ctx
->fragment_shader_core
.midgard1
.flags
;
1084 /* Depending on whether it's legal to in the given shader, we
1085 * try to enable early-z testing (or forward-pixel kill?) */
1087 if (!variant
->can_discard
)
1088 flags
|= MALI_EARLY_Z
;
1090 /* Any time texturing is used, derivatives are implicitly
1091 * calculated, so we need to enable helper invocations */
1093 if (ctx
->sampler_view_count
[PIPE_SHADER_FRAGMENT
])
1094 flags
|= MALI_HELPER_INVOCATIONS
;
1096 ctx
->fragment_shader_core
.midgard1
.flags
= flags
;
1098 /* Assign the stencil refs late */
1099 ctx
->fragment_shader_core
.stencil_front
.ref
= ctx
->stencil_ref
.ref_value
[0];
1100 ctx
->fragment_shader_core
.stencil_back
.ref
= ctx
->stencil_ref
.ref_value
[1];
1102 /* CAN_DISCARD should be set if the fragment shader possibly
1103 * contains a 'discard' instruction. It is likely this is
1104 * related to optimizations related to forward-pixel kill, as
1105 * per "Mali Performance 3: Is EGL_BUFFER_PRESERVED a good
1106 * thing?" by Peter Harris
1109 if (variant
->can_discard
) {
1110 ctx
->fragment_shader_core
.unknown2_3
|= MALI_CAN_DISCARD
;
1111 ctx
->fragment_shader_core
.midgard1
.flags
|= 0x400;
1114 /* Check if we're using the default blend descriptor (fast path) */
1118 (blend
.equation
.equation
->rgb_mode
== 0x122) &&
1119 (blend
.equation
.equation
->alpha_mode
== 0x122) &&
1120 (blend
.equation
.equation
->color_mask
== 0xf);
1122 /* Even on MFBD, the shader descriptor gets blend shaders. It's
1123 * *also* copied to the blend_meta appended (by convention),
1124 * but this is the field actually read by the hardware. (Or
1125 * maybe both are read...?) */
1127 if (blend
.is_shader
) {
1128 ctx
->fragment_shader_core
.blend
.shader
=
1131 ctx
->fragment_shader_core
.blend
.shader
= 0;
1134 if (ctx
->require_sfbd
) {
1135 /* When only a single render target platform is used, the blend
1136 * information is inside the shader meta itself. We
1137 * additionally need to signal CAN_DISCARD for nontrivial blend
1138 * modes (so we're able to read back the destination buffer) */
1140 if (!blend
.is_shader
) {
1141 ctx
->fragment_shader_core
.blend
.equation
=
1142 *blend
.equation
.equation
;
1143 ctx
->fragment_shader_core
.blend
.constant
=
1144 blend
.equation
.constant
;
1148 ctx
->fragment_shader_core
.unknown2_3
|= MALI_CAN_DISCARD
;
1152 size_t size
= sizeof(struct mali_shader_meta
) + sizeof(struct midgard_blend_rt
);
1153 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, size
);
1154 memcpy(transfer
.cpu
, &ctx
->fragment_shader_core
, sizeof(struct mali_shader_meta
));
1156 ctx
->payload_tiler
.postfix
._shader_upper
= (transfer
.gpu
) >> 4;
1158 if (!ctx
->require_sfbd
) {
1159 /* Additional blend descriptor tacked on for jobs using MFBD */
1161 unsigned blend_count
= 0x200;
1163 if (blend
.is_shader
) {
1164 /* For a blend shader, the bottom nibble corresponds to
1165 * the number of work registers used, which signals the
1166 * -existence- of a blend shader */
1168 assert(blend
.shader
.work_count
>= 2);
1169 blend_count
|= MIN2(blend
.shader
.work_count
, 3);
1171 /* Otherwise, the bottom bit simply specifies if
1172 * blending (anything other than REPLACE) is enabled */
1179 struct midgard_blend_rt rts
[4];
1183 for (unsigned i
= 0; i
< 1; ++i
) {
1185 (ctx
->pipe_framebuffer
.nr_cbufs
> i
) &&
1186 util_format_is_srgb(ctx
->pipe_framebuffer
.cbufs
[i
]->format
);
1188 rts
[i
].flags
= blend_count
;
1191 rts
[i
].flags
|= MALI_BLEND_SRGB
;
1193 /* TODO: sRGB in blend shaders is currently
1194 * unimplemented. Contact me (Alyssa) if you're
1195 * interested in working on this. We have
1196 * native Midgard ops for helping here, but
1197 * they're not well-understood yet. */
1199 assert(!(is_srgb
&& blend
.is_shader
));
1201 if (blend
.is_shader
) {
1202 rts
[i
].blend
.shader
= blend
.shader
.gpu
;
1204 rts
[i
].blend
.equation
= *blend
.equation
.equation
;
1205 rts
[i
].blend
.constant
= blend
.equation
.constant
;
1209 memcpy(transfer
.cpu
+ sizeof(struct mali_shader_meta
), rts
, sizeof(rts
[0]) * 1);
1213 /* We stage to transient, so always dirty.. */
1214 panfrost_stage_attributes(ctx
);
1216 if (ctx
->dirty
& PAN_DIRTY_SAMPLERS
)
1217 panfrost_upload_sampler_descriptors(ctx
);
1219 if (ctx
->dirty
& PAN_DIRTY_TEXTURES
)
1220 panfrost_upload_texture_descriptors(ctx
);
1222 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
1224 for (int i
= 0; i
<= PIPE_SHADER_FRAGMENT
; ++i
) {
1225 struct panfrost_constant_buffer
*buf
= &ctx
->constant_buffer
[i
];
1227 struct panfrost_shader_state
*vs
= &ctx
->vs
->variants
[ctx
->vs
->active_variant
];
1228 struct panfrost_shader_state
*fs
= &ctx
->fs
->variants
[ctx
->fs
->active_variant
];
1229 struct panfrost_shader_state
*ss
= (i
== PIPE_SHADER_FRAGMENT
) ? fs
: vs
;
1231 /* Uniforms are implicitly UBO #0 */
1232 bool has_uniforms
= buf
->enabled_mask
& (1 << 0);
1234 /* Allocate room for the sysval and the uniforms */
1235 size_t sys_size
= sizeof(float) * 4 * ss
->sysval_count
;
1236 size_t uniform_size
= has_uniforms
? (buf
->cb
[0].buffer_size
) : 0;
1237 size_t size
= sys_size
+ uniform_size
;
1238 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, size
);
1240 /* Upload sysvals requested by the shader */
1241 panfrost_upload_sysvals(ctx
, transfer
.cpu
, ss
, i
);
1243 /* Upload uniforms */
1245 const void *cpu
= panfrost_map_constant_buffer_cpu(buf
, 0);
1246 memcpy(transfer
.cpu
+ sys_size
, cpu
, uniform_size
);
1249 int uniform_count
= 0;
1251 struct mali_vertex_tiler_postfix
*postfix
;
1254 case PIPE_SHADER_VERTEX
:
1255 uniform_count
= ctx
->vs
->variants
[ctx
->vs
->active_variant
].uniform_count
;
1256 postfix
= &ctx
->payload_vertex
.postfix
;
1259 case PIPE_SHADER_FRAGMENT
:
1260 uniform_count
= ctx
->fs
->variants
[ctx
->fs
->active_variant
].uniform_count
;
1261 postfix
= &ctx
->payload_tiler
.postfix
;
1265 unreachable("Invalid shader stage\n");
1268 /* Next up, attach UBOs. UBO #0 is the uniforms we just
1271 unsigned ubo_count
= panfrost_ubo_count(ctx
, i
);
1272 assert(ubo_count
>= 1);
1274 size_t sz
= sizeof(struct mali_uniform_buffer_meta
) * ubo_count
;
1275 struct mali_uniform_buffer_meta
*ubos
= calloc(sz
, 1);
1277 /* Upload uniforms as a UBO */
1278 ubos
[0].size
= MALI_POSITIVE((2 + uniform_count
));
1279 ubos
[0].ptr
= transfer
.gpu
>> 2;
1281 /* The rest are honest-to-goodness UBOs */
1283 for (unsigned ubo
= 1; ubo
< ubo_count
; ++ubo
) {
1284 size_t sz
= buf
->cb
[ubo
].buffer_size
;
1286 bool enabled
= buf
->enabled_mask
& (1 << ubo
);
1287 bool empty
= sz
== 0;
1289 if (!enabled
|| empty
) {
1290 /* Stub out disabled UBOs to catch accesses */
1293 ubos
[ubo
].ptr
= 0xDEAD0000;
1297 mali_ptr gpu
= panfrost_map_constant_buffer_gpu(ctx
, buf
, ubo
);
1299 unsigned bytes_per_field
= 16;
1300 unsigned aligned
= ALIGN_POT(sz
, bytes_per_field
);
1301 unsigned fields
= aligned
/ bytes_per_field
;
1303 ubos
[ubo
].size
= MALI_POSITIVE(fields
);
1304 ubos
[ubo
].ptr
= gpu
>> 2;
1307 mali_ptr ubufs
= panfrost_upload_transient(ctx
, ubos
, sz
);
1308 postfix
->uniforms
= transfer
.gpu
;
1309 postfix
->uniform_buffers
= ubufs
;
1311 buf
->dirty_mask
= 0;
1314 /* TODO: Upload the viewport somewhere more appropriate */
1316 /* Clip bounds are encoded as floats. The viewport itself is encoded as
1317 * (somewhat) asymmetric ints. */
1318 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1320 struct mali_viewport view
= {
1321 /* By default, do no viewport clipping, i.e. clip to (-inf,
1322 * inf) in each direction. Clipping to the viewport in theory
1323 * should work, but in practice causes issues when we're not
1324 * explicitly trying to scissor */
1326 .clip_minx
= -INFINITY
,
1327 .clip_miny
= -INFINITY
,
1328 .clip_maxx
= INFINITY
,
1329 .clip_maxy
= INFINITY
,
1335 /* Always scissor to the viewport by default. */
1336 int minx
= (int) (vp
->translate
[0] - vp
->scale
[0]);
1337 int maxx
= (int) (vp
->translate
[0] + vp
->scale
[0]);
1339 int miny
= (int) (vp
->translate
[1] - vp
->scale
[1]);
1340 int maxy
= (int) (vp
->translate
[1] + vp
->scale
[1]);
1342 /* Apply the scissor test */
1344 if (ss
&& ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
) {
1351 /* Hardware needs the min/max to be strictly ordered, so flip if we
1352 * need to. The viewport transformation in the vertex shader will
1353 * handle the negatives if we don't */
1367 /* Clamp everything positive, just in case */
1369 maxx
= MAX2(0, maxx
);
1370 maxy
= MAX2(0, maxy
);
1371 minx
= MAX2(0, minx
);
1372 miny
= MAX2(0, miny
);
1374 /* Clamp to the framebuffer size as a last check */
1376 minx
= MIN2(ctx
->pipe_framebuffer
.width
, minx
);
1377 maxx
= MIN2(ctx
->pipe_framebuffer
.width
, maxx
);
1379 miny
= MIN2(ctx
->pipe_framebuffer
.height
, miny
);
1380 maxy
= MIN2(ctx
->pipe_framebuffer
.height
, maxy
);
1382 /* Update the job, unless we're doing wallpapering (whose lack of
1383 * scissor we can ignore, since if we "miss" a tile of wallpaper, it'll
1384 * just... be faster :) */
1386 if (!ctx
->wallpaper_batch
)
1387 panfrost_job_union_scissor(job
, minx
, miny
, maxx
, maxy
);
1391 view
.viewport0
[0] = minx
;
1392 view
.viewport1
[0] = MALI_POSITIVE(maxx
);
1394 view
.viewport0
[1] = miny
;
1395 view
.viewport1
[1] = MALI_POSITIVE(maxy
);
1397 ctx
->payload_tiler
.postfix
.viewport
=
1398 panfrost_upload_transient(ctx
,
1400 sizeof(struct mali_viewport
));
1405 /* Corresponds to exactly one draw, but does not submit anything */
1408 panfrost_queue_draw(struct panfrost_context
*ctx
)
1410 /* Handle dirty flags now */
1411 panfrost_emit_for_draw(ctx
, true);
1413 /* If rasterizer discard is enable, only submit the vertex */
1415 bool rasterizer_discard
= ctx
->rasterizer
1416 && ctx
->rasterizer
->base
.rasterizer_discard
;
1418 struct panfrost_transfer vertex
= panfrost_vertex_tiler_job(ctx
, false);
1419 struct panfrost_transfer tiler
;
1421 if (!rasterizer_discard
)
1422 tiler
= panfrost_vertex_tiler_job(ctx
, true);
1424 struct panfrost_job
*batch
= panfrost_get_job_for_fbo(ctx
);
1426 if (rasterizer_discard
)
1427 panfrost_scoreboard_queue_vertex_job(batch
, vertex
, FALSE
);
1428 else if (ctx
->wallpaper_batch
)
1429 panfrost_scoreboard_queue_fused_job_prepend(batch
, vertex
, tiler
);
1431 panfrost_scoreboard_queue_fused_job(batch
, vertex
, tiler
);
1434 /* The entire frame is in memory -- send it off to the kernel! */
1437 panfrost_submit_frame(struct panfrost_context
*ctx
, bool flush_immediate
,
1438 struct pipe_fence_handle
**fence
,
1439 struct panfrost_job
*job
)
1441 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
1442 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
1446 panfrost_job_submit(ctx
, job
);
1448 /* If visual, we can stall a frame */
1450 if (!flush_immediate
)
1451 panfrost_drm_force_flush_fragment(ctx
, fence
);
1453 screen
->last_fragment_flushed
= false;
1454 screen
->last_job
= job
;
1456 /* If readback, flush now (hurts the pipelined performance) */
1457 if (flush_immediate
)
1458 panfrost_drm_force_flush_fragment(ctx
, fence
);
1463 panfrost_draw_wallpaper(struct pipe_context
*pipe
)
1465 struct panfrost_context
*ctx
= pan_context(pipe
);
1467 /* Nothing to reload? TODO: MRT wallpapers */
1468 if (ctx
->pipe_framebuffer
.cbufs
[0] == NULL
)
1471 /* Check if the buffer has any content on it worth preserving */
1473 struct pipe_surface
*surf
= ctx
->pipe_framebuffer
.cbufs
[0];
1474 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
1475 unsigned level
= surf
->u
.tex
.level
;
1477 if (!rsrc
->slices
[level
].initialized
)
1480 /* Save the batch */
1481 struct panfrost_job
*batch
= panfrost_get_job_for_fbo(ctx
);
1483 ctx
->wallpaper_batch
= batch
;
1484 panfrost_blit_wallpaper(ctx
);
1485 ctx
->wallpaper_batch
= NULL
;
1490 struct pipe_context
*pipe
,
1491 struct pipe_fence_handle
**fence
,
1494 struct panfrost_context
*ctx
= pan_context(pipe
);
1495 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
1497 /* Nothing to do! */
1498 if (!job
->last_job
.gpu
&& !job
->clear
) return;
1501 panfrost_draw_wallpaper(&ctx
->base
);
1503 /* Whether to stall the pipeline for immediately correct results. Since
1504 * pipelined rendering is quite broken right now (to be fixed by the
1505 * panfrost_job refactor, just take the perf hit for correctness) */
1506 bool flush_immediate
= /*flags & PIPE_FLUSH_END_OF_FRAME*/true;
1508 /* Submit the frame itself */
1509 panfrost_submit_frame(ctx
, flush_immediate
, fence
, job
);
1511 /* Prepare for the next frame */
1512 panfrost_invalidate_frame(ctx
);
1515 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
1518 g2m_draw_mode(enum pipe_prim_type mode
)
1521 DEFINE_CASE(POINTS
);
1523 DEFINE_CASE(LINE_LOOP
);
1524 DEFINE_CASE(LINE_STRIP
);
1525 DEFINE_CASE(TRIANGLES
);
1526 DEFINE_CASE(TRIANGLE_STRIP
);
1527 DEFINE_CASE(TRIANGLE_FAN
);
1529 DEFINE_CASE(QUAD_STRIP
);
1530 DEFINE_CASE(POLYGON
);
1533 unreachable("Invalid draw mode");
1540 panfrost_translate_index_size(unsigned size
)
1544 return MALI_DRAW_INDEXED_UINT8
;
1547 return MALI_DRAW_INDEXED_UINT16
;
1550 return MALI_DRAW_INDEXED_UINT32
;
1553 unreachable("Invalid index size");
1557 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
1558 * good for the duration of the draw (transient), could last longer */
1561 panfrost_get_index_buffer_mapped(struct panfrost_context
*ctx
, const struct pipe_draw_info
*info
)
1563 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
1565 off_t offset
= info
->start
* info
->index_size
;
1566 struct panfrost_job
*batch
= panfrost_get_job_for_fbo(ctx
);
1568 if (!info
->has_user_indices
) {
1569 /* Only resources can be directly mapped */
1570 panfrost_job_add_bo(batch
, rsrc
->bo
);
1571 return rsrc
->bo
->gpu
+ offset
;
1573 /* Otherwise, we need to upload to transient memory */
1574 const uint8_t *ibuf8
= (const uint8_t *) info
->index
.user
;
1575 return panfrost_upload_transient(ctx
, ibuf8
+ offset
, info
->count
* info
->index_size
);
1580 panfrost_scissor_culls_everything(struct panfrost_context
*ctx
)
1582 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1584 /* Check if we're scissoring at all */
1586 if (!(ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
))
1589 return (ss
->minx
== ss
->maxx
) || (ss
->miny
== ss
->maxy
);
1594 struct pipe_context
*pipe
,
1595 const struct pipe_draw_info
*info
)
1597 struct panfrost_context
*ctx
= pan_context(pipe
);
1599 /* First of all, check the scissor to see if anything is drawn at all.
1600 * If it's not, we drop the draw (mostly a conformance issue;
1601 * well-behaved apps shouldn't hit this) */
1603 if (panfrost_scissor_culls_everything(ctx
))
1606 ctx
->payload_vertex
.draw_start
= info
->start
;
1607 ctx
->payload_tiler
.draw_start
= info
->start
;
1609 int mode
= info
->mode
;
1611 /* Fallback unsupported restart index */
1612 unsigned primitive_index
= (1 << (info
->index_size
* 8)) - 1;
1614 if (info
->primitive_restart
&& info
->index_size
1615 && info
->restart_index
!= primitive_index
) {
1616 util_draw_vbo_without_prim_restart(pipe
, info
);
1620 /* Fallback for unsupported modes */
1622 if (!(ctx
->draw_modes
& (1 << mode
))) {
1623 if (mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && ctx
->rasterizer
&& !ctx
->rasterizer
->base
.flatshade
) {
1624 mode
= PIPE_PRIM_TRIANGLE_FAN
;
1626 if (info
->count
< 4) {
1627 /* Degenerate case? */
1631 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
1632 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
1637 /* Now that we have a guaranteed terminating path, find the job.
1638 * Assignment commented out to prevent unused warning */
1640 /* struct panfrost_job *job = */ panfrost_get_job_for_fbo(ctx
);
1642 ctx
->payload_tiler
.prefix
.draw_mode
= g2m_draw_mode(mode
);
1644 ctx
->vertex_count
= info
->count
;
1645 ctx
->instance_count
= info
->instance_count
;
1647 /* For non-indexed draws, they're the same */
1648 unsigned vertex_count
= ctx
->vertex_count
;
1650 unsigned draw_flags
= 0;
1652 /* The draw flags interpret how primitive size is interpreted */
1654 if (panfrost_writes_point_size(ctx
))
1655 draw_flags
|= MALI_DRAW_VARYING_SIZE
;
1657 if (info
->primitive_restart
)
1658 draw_flags
|= MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX
;
1660 /* For higher amounts of vertices (greater than what fits in a 16-bit
1661 * short), the other value is needed, otherwise there will be bizarre
1662 * rendering artefacts. It's not clear what these values mean yet. This
1663 * change is also needed for instancing and sometimes points (perhaps
1664 * related to dynamically setting gl_PointSize) */
1666 bool is_points
= mode
== PIPE_PRIM_POINTS
;
1667 bool many_verts
= ctx
->vertex_count
> 0xFFFF;
1668 bool instanced
= ctx
->instance_count
> 1;
1670 draw_flags
|= (is_points
|| many_verts
|| instanced
) ? 0x3000 : 0x18000;
1672 /* This doesn't make much sense */
1673 if (mode
== PIPE_PRIM_LINE_STRIP
) {
1674 draw_flags
|= 0x800;
1677 if (info
->index_size
) {
1678 /* Calculate the min/max index used so we can figure out how
1679 * many times to invoke the vertex shader */
1681 /* Fetch / calculate index bounds */
1682 unsigned min_index
= 0, max_index
= 0;
1684 if (info
->max_index
== ~0u) {
1685 u_vbuf_get_minmax_index(pipe
, info
, &min_index
, &max_index
);
1687 min_index
= info
->min_index
;
1688 max_index
= info
->max_index
;
1691 /* Use the corresponding values */
1692 vertex_count
= max_index
- min_index
+ 1;
1693 ctx
->payload_vertex
.draw_start
= min_index
;
1694 ctx
->payload_tiler
.draw_start
= min_index
;
1696 ctx
->payload_tiler
.prefix
.negative_start
= -min_index
;
1697 ctx
->payload_tiler
.prefix
.index_count
= MALI_POSITIVE(info
->count
);
1699 //assert(!info->restart_index); /* TODO: Research */
1700 assert(!info
->index_bias
);
1702 draw_flags
|= panfrost_translate_index_size(info
->index_size
);
1703 ctx
->payload_tiler
.prefix
.indices
= panfrost_get_index_buffer_mapped(ctx
, info
);
1705 /* Index count == vertex count, if no indexing is applied, as
1706 * if it is internally indexed in the expected order */
1708 ctx
->payload_tiler
.prefix
.negative_start
= 0;
1709 ctx
->payload_tiler
.prefix
.index_count
= MALI_POSITIVE(ctx
->vertex_count
);
1711 /* Reverse index state */
1712 ctx
->payload_tiler
.prefix
.indices
= (uintptr_t) NULL
;
1715 /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
1716 * vertex_count, 1) */
1718 panfrost_pack_work_groups_fused(
1719 &ctx
->payload_vertex
.prefix
,
1720 &ctx
->payload_tiler
.prefix
,
1721 1, vertex_count
, info
->instance_count
,
1724 ctx
->payload_tiler
.prefix
.unknown_draw
= draw_flags
;
1726 /* Encode the padded vertex count */
1728 if (info
->instance_count
> 1) {
1729 /* Triangles have non-even vertex counts so they change how
1730 * padding works internally */
1733 mode
== PIPE_PRIM_TRIANGLES
||
1734 mode
== PIPE_PRIM_TRIANGLE_STRIP
||
1735 mode
== PIPE_PRIM_TRIANGLE_FAN
;
1737 struct pan_shift_odd so
=
1738 panfrost_padded_vertex_count(vertex_count
, !is_triangle
);
1740 ctx
->payload_vertex
.instance_shift
= so
.shift
;
1741 ctx
->payload_tiler
.instance_shift
= so
.shift
;
1743 ctx
->payload_vertex
.instance_odd
= so
.odd
;
1744 ctx
->payload_tiler
.instance_odd
= so
.odd
;
1746 ctx
->padded_count
= pan_expand_shift_odd(so
);
1748 ctx
->padded_count
= ctx
->vertex_count
;
1750 /* Reset instancing state */
1751 ctx
->payload_vertex
.instance_shift
= 0;
1752 ctx
->payload_vertex
.instance_odd
= 0;
1753 ctx
->payload_tiler
.instance_shift
= 0;
1754 ctx
->payload_tiler
.instance_odd
= 0;
1757 /* Fire off the draw itself */
1758 panfrost_queue_draw(ctx
);
1764 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
1770 panfrost_create_rasterizer_state(
1771 struct pipe_context
*pctx
,
1772 const struct pipe_rasterizer_state
*cso
)
1774 struct panfrost_context
*ctx
= pan_context(pctx
);
1775 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
1779 /* Bitmask, unknown meaning of the start value */
1780 so
->tiler_gl_enables
= ctx
->is_t6xx
? 0x105 : 0x7;
1783 so
->tiler_gl_enables
|= MALI_FRONT_CCW_TOP
;
1785 if (cso
->cull_face
& PIPE_FACE_FRONT
)
1786 so
->tiler_gl_enables
|= MALI_CULL_FACE_FRONT
;
1788 if (cso
->cull_face
& PIPE_FACE_BACK
)
1789 so
->tiler_gl_enables
|= MALI_CULL_FACE_BACK
;
1795 panfrost_bind_rasterizer_state(
1796 struct pipe_context
*pctx
,
1799 struct panfrost_context
*ctx
= pan_context(pctx
);
1801 /* TODO: Why can't rasterizer be NULL ever? Other drivers are fine.. */
1805 ctx
->rasterizer
= hwcso
;
1806 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
1808 /* Point sprites are emulated */
1810 struct panfrost_shader_state
*variant
=
1811 ctx
->fs
? &ctx
->fs
->variants
[ctx
->fs
->active_variant
] : NULL
;
1813 if (ctx
->rasterizer
->base
.sprite_coord_enable
|| (variant
&& variant
->point_sprite_mask
))
1814 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->fs
);
1818 panfrost_create_vertex_elements_state(
1819 struct pipe_context
*pctx
,
1820 unsigned num_elements
,
1821 const struct pipe_vertex_element
*elements
)
1823 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
1825 so
->num_elements
= num_elements
;
1826 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
1828 /* XXX: What the cornball? This is totally, 100%, unapologetically
1829 * nonsense. And yet it somehow fixes a regression in -bshadow
1830 * (previously, we allocated the descriptor here... a newer commit
1831 * removed that allocation, and then memory corruption led to
1832 * shader_meta getting overwritten in bad ways and then the whole test
1833 * case falling apart . TODO: LOOK INTO PLEASE XXX XXX BAD XXX XXX XXX
1835 panfrost_allocate_chunk(pan_context(pctx
), 0, HEAP_DESCRIPTOR
);
1837 for (int i
= 0; i
< num_elements
; ++i
) {
1838 so
->hw
[i
].index
= i
;
1840 enum pipe_format fmt
= elements
[i
].src_format
;
1841 const struct util_format_description
*desc
= util_format_description(fmt
);
1842 so
->hw
[i
].unknown1
= 0x2;
1843 so
->hw
[i
].swizzle
= panfrost_get_default_swizzle(desc
->nr_channels
);
1845 so
->hw
[i
].format
= panfrost_find_format(desc
);
1847 /* The field itself should probably be shifted over */
1848 so
->hw
[i
].src_offset
= elements
[i
].src_offset
;
1855 panfrost_bind_vertex_elements_state(
1856 struct pipe_context
*pctx
,
1859 struct panfrost_context
*ctx
= pan_context(pctx
);
1861 ctx
->vertex
= hwcso
;
1862 ctx
->dirty
|= PAN_DIRTY_VERTEX
;
1866 panfrost_create_shader_state(
1867 struct pipe_context
*pctx
,
1868 const struct pipe_shader_state
*cso
)
1870 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
1873 /* Token deep copy to prevent memory corruption */
1875 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
1876 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
1882 panfrost_delete_shader_state(
1883 struct pipe_context
*pctx
,
1886 struct panfrost_shader_variants
*cso
= (struct panfrost_shader_variants
*) so
;
1888 if (cso
->base
.type
== PIPE_SHADER_IR_TGSI
) {
1889 DBG("Deleting TGSI shader leaks duplicated tokens\n");
1896 panfrost_create_sampler_state(
1897 struct pipe_context
*pctx
,
1898 const struct pipe_sampler_state
*cso
)
1900 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
1903 /* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
1905 struct mali_sampler_descriptor sampler_descriptor
= {
1906 .filter_mode
= MALI_TEX_MIN(translate_tex_filter(cso
->min_img_filter
))
1907 | MALI_TEX_MAG(translate_tex_filter(cso
->mag_img_filter
))
1908 | translate_mip_filter(cso
->min_mip_filter
)
1911 .wrap_s
= translate_tex_wrap(cso
->wrap_s
),
1912 .wrap_t
= translate_tex_wrap(cso
->wrap_t
),
1913 .wrap_r
= translate_tex_wrap(cso
->wrap_r
),
1914 .compare_func
= panfrost_translate_alt_compare_func(cso
->compare_func
),
1916 cso
->border_color
.f
[0],
1917 cso
->border_color
.f
[1],
1918 cso
->border_color
.f
[2],
1919 cso
->border_color
.f
[3]
1921 .min_lod
= FIXED_16(cso
->min_lod
),
1922 .max_lod
= FIXED_16(cso
->max_lod
),
1923 .seamless_cube_map
= cso
->seamless_cube_map
,
1926 /* If necessary, we disable mipmapping in the sampler descriptor by
1927 * clamping the LOD as tight as possible (from 0 to epsilon,
1928 * essentially -- remember these are fixed point numbers, so
1931 if (cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
)
1932 sampler_descriptor
.max_lod
= sampler_descriptor
.min_lod
;
1934 /* Enforce that there is something in the middle by adding epsilon*/
1936 if (sampler_descriptor
.min_lod
== sampler_descriptor
.max_lod
)
1937 sampler_descriptor
.max_lod
++;
1940 assert(sampler_descriptor
.max_lod
> sampler_descriptor
.min_lod
);
1942 so
->hw
= sampler_descriptor
;
1948 panfrost_bind_sampler_states(
1949 struct pipe_context
*pctx
,
1950 enum pipe_shader_type shader
,
1951 unsigned start_slot
, unsigned num_sampler
,
1954 assert(start_slot
== 0);
1956 struct panfrost_context
*ctx
= pan_context(pctx
);
1958 /* XXX: Should upload, not just copy? */
1959 ctx
->sampler_count
[shader
] = num_sampler
;
1960 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
1962 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
;
1966 panfrost_variant_matches(
1967 struct panfrost_context
*ctx
,
1968 struct panfrost_shader_state
*variant
,
1969 enum pipe_shader_type type
)
1971 struct pipe_rasterizer_state
*rasterizer
= &ctx
->rasterizer
->base
;
1972 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
1974 bool is_fragment
= (type
== PIPE_SHADER_FRAGMENT
);
1976 if (is_fragment
&& (alpha
->enabled
|| variant
->alpha_state
.enabled
)) {
1977 /* Make sure enable state is at least the same */
1978 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
1982 /* Check that the contents of the test are the same */
1983 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
1984 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
1986 if (!(same_func
&& same_ref
)) {
1991 if (is_fragment
&& rasterizer
&& (rasterizer
->sprite_coord_enable
|
1992 variant
->point_sprite_mask
)) {
1993 /* Ensure the same varyings are turned to point sprites */
1994 if (rasterizer
->sprite_coord_enable
!= variant
->point_sprite_mask
)
1997 /* Ensure the orientation is correct */
1999 rasterizer
->sprite_coord_mode
==
2000 PIPE_SPRITE_COORD_UPPER_LEFT
;
2002 if (variant
->point_sprite_upper_left
!= upper_left
)
2006 /* Otherwise, we're good to go */
2011 panfrost_bind_shader_state(
2012 struct pipe_context
*pctx
,
2014 enum pipe_shader_type type
)
2016 struct panfrost_context
*ctx
= pan_context(pctx
);
2018 if (type
== PIPE_SHADER_FRAGMENT
) {
2020 ctx
->dirty
|= PAN_DIRTY_FS
;
2022 assert(type
== PIPE_SHADER_VERTEX
);
2024 ctx
->dirty
|= PAN_DIRTY_VS
;
2029 /* Match the appropriate variant */
2031 signed variant
= -1;
2032 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
2034 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
2035 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
], type
)) {
2041 if (variant
== -1) {
2042 /* No variant matched, so create a new one */
2043 variant
= variants
->variant_count
++;
2044 assert(variants
->variant_count
< MAX_SHADER_VARIANTS
);
2046 struct panfrost_shader_state
*v
=
2047 &variants
->variants
[variant
];
2051 if (type
== PIPE_SHADER_FRAGMENT
) {
2052 v
->alpha_state
= ctx
->depth_stencil
->alpha
;
2054 if (ctx
->rasterizer
) {
2055 v
->point_sprite_mask
= ctx
->rasterizer
->base
.sprite_coord_enable
;
2056 v
->point_sprite_upper_left
=
2057 ctx
->rasterizer
->base
.sprite_coord_mode
==
2058 PIPE_SPRITE_COORD_UPPER_LEFT
;
2062 /* Allocate the mapped descriptor ahead-of-time. */
2063 struct panfrost_context
*ctx
= pan_context(pctx
);
2064 struct panfrost_transfer transfer
= panfrost_allocate_chunk(ctx
, sizeof(struct mali_shader_meta
), HEAP_DESCRIPTOR
);
2066 variants
->variants
[variant
].tripipe
= (struct mali_shader_meta
*) transfer
.cpu
;
2067 variants
->variants
[variant
].tripipe_gpu
= transfer
.gpu
;
2071 /* Select this variant */
2072 variants
->active_variant
= variant
;
2074 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
2075 assert(panfrost_variant_matches(ctx
, shader_state
, type
));
2077 /* We finally have a variant, so compile it */
2079 if (!shader_state
->compiled
) {
2080 panfrost_shader_compile(ctx
, shader_state
->tripipe
, NULL
,
2081 panfrost_job_type_for_pipe(type
), shader_state
);
2083 shader_state
->compiled
= true;
2088 panfrost_bind_vs_state(struct pipe_context
*pctx
, void *hwcso
)
2090 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
2094 panfrost_bind_fs_state(struct pipe_context
*pctx
, void *hwcso
)
2096 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
2100 panfrost_set_vertex_buffers(
2101 struct pipe_context
*pctx
,
2102 unsigned start_slot
,
2103 unsigned num_buffers
,
2104 const struct pipe_vertex_buffer
*buffers
)
2106 struct panfrost_context
*ctx
= pan_context(pctx
);
2108 util_set_vertex_buffers_mask(ctx
->vertex_buffers
, &ctx
->vb_mask
, buffers
, start_slot
, num_buffers
);
2112 panfrost_set_constant_buffer(
2113 struct pipe_context
*pctx
,
2114 enum pipe_shader_type shader
, uint index
,
2115 const struct pipe_constant_buffer
*buf
)
2117 struct panfrost_context
*ctx
= pan_context(pctx
);
2118 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
2120 util_copy_constant_buffer(&pbuf
->cb
[index
], buf
);
2122 unsigned mask
= (1 << index
);
2124 if (unlikely(!buf
)) {
2125 pbuf
->enabled_mask
&= ~mask
;
2126 pbuf
->dirty_mask
&= ~mask
;
2130 pbuf
->enabled_mask
|= mask
;
2131 pbuf
->dirty_mask
|= mask
;
2135 panfrost_set_stencil_ref(
2136 struct pipe_context
*pctx
,
2137 const struct pipe_stencil_ref
*ref
)
2139 struct panfrost_context
*ctx
= pan_context(pctx
);
2140 ctx
->stencil_ref
= *ref
;
2142 /* Shader core dirty */
2143 ctx
->dirty
|= PAN_DIRTY_FS
;
2146 static enum mali_texture_type
2147 panfrost_translate_texture_type(enum pipe_texture_target t
) {
2151 case PIPE_TEXTURE_1D
:
2152 case PIPE_TEXTURE_1D_ARRAY
:
2155 case PIPE_TEXTURE_2D
:
2156 case PIPE_TEXTURE_2D_ARRAY
:
2157 case PIPE_TEXTURE_RECT
:
2160 case PIPE_TEXTURE_3D
:
2163 case PIPE_TEXTURE_CUBE
:
2164 case PIPE_TEXTURE_CUBE_ARRAY
:
2165 return MALI_TEX_CUBE
;
2168 unreachable("Unknown target");
2172 static struct pipe_sampler_view
*
2173 panfrost_create_sampler_view(
2174 struct pipe_context
*pctx
,
2175 struct pipe_resource
*texture
,
2176 const struct pipe_sampler_view
*template)
2178 struct panfrost_sampler_view
*so
= rzalloc(pctx
, struct panfrost_sampler_view
);
2179 int bytes_per_pixel
= util_format_get_blocksize(texture
->format
);
2181 pipe_reference(NULL
, &texture
->reference
);
2183 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
2186 so
->base
= *template;
2187 so
->base
.texture
= texture
;
2188 so
->base
.reference
.count
= 1;
2189 so
->base
.context
= pctx
;
2191 /* sampler_views correspond to texture descriptors, minus the texture
2192 * (data) itself. So, we serialise the descriptor here and cache it for
2195 /* TODO: Detect from format better */
2196 const struct util_format_description
*desc
= util_format_description(prsrc
->base
.format
);
2198 unsigned char user_swizzle
[4] = {
2199 template->swizzle_r
,
2200 template->swizzle_g
,
2201 template->swizzle_b
,
2205 enum mali_format format
= panfrost_find_format(desc
);
2207 bool is_depth
= desc
->format
== PIPE_FORMAT_Z32_UNORM
;
2209 unsigned usage2_layout
= 0x10;
2211 switch (prsrc
->layout
) {
2213 usage2_layout
|= 0x8 | 0x4;
2216 usage2_layout
|= 0x1;
2219 usage2_layout
|= is_depth
? 0x1 : 0x2;
2226 /* Check if we need to set a custom stride by computing the "expected"
2227 * stride and comparing it to what the BO actually wants. Only applies
2228 * to linear textures, since tiled/compressed textures have strict
2229 * alignment requirements for their strides as it is */
2231 unsigned first_level
= template->u
.tex
.first_level
;
2232 unsigned last_level
= template->u
.tex
.last_level
;
2234 if (prsrc
->layout
== PAN_LINEAR
) {
2235 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
2236 unsigned actual_stride
= prsrc
->slices
[l
].stride
;
2237 unsigned width
= u_minify(texture
->width0
, l
);
2238 unsigned comp_stride
= width
* bytes_per_pixel
;
2240 if (comp_stride
!= actual_stride
) {
2241 usage2_layout
|= MALI_TEX_MANUAL_STRIDE
;
2247 /* In the hardware, array_size refers specifically to array textures,
2248 * whereas in Gallium, it also covers cubemaps */
2250 unsigned array_size
= texture
->array_size
;
2252 if (template->target
== PIPE_TEXTURE_CUBE
) {
2253 /* TODO: Cubemap arrays */
2254 assert(array_size
== 6);
2258 struct mali_texture_descriptor texture_descriptor
= {
2259 .width
= MALI_POSITIVE(u_minify(texture
->width0
, first_level
)),
2260 .height
= MALI_POSITIVE(u_minify(texture
->height0
, first_level
)),
2261 .depth
= MALI_POSITIVE(u_minify(texture
->depth0
, first_level
)),
2262 .array_size
= MALI_POSITIVE(array_size
),
2266 .swizzle
= panfrost_translate_swizzle_4(desc
->swizzle
),
2269 .srgb
= desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
,
2270 .type
= panfrost_translate_texture_type(template->target
),
2272 .usage2
= usage2_layout
2275 .swizzle
= panfrost_translate_swizzle_4(user_swizzle
)
2278 texture_descriptor
.nr_mipmap_levels
= last_level
- first_level
;
2280 so
->hw
= texture_descriptor
;
2282 return (struct pipe_sampler_view
*) so
;
2286 panfrost_set_sampler_views(
2287 struct pipe_context
*pctx
,
2288 enum pipe_shader_type shader
,
2289 unsigned start_slot
, unsigned num_views
,
2290 struct pipe_sampler_view
**views
)
2292 struct panfrost_context
*ctx
= pan_context(pctx
);
2294 assert(start_slot
== 0);
2296 unsigned new_nr
= 0;
2297 for (unsigned i
= 0; i
< num_views
; ++i
) {
2302 ctx
->sampler_view_count
[shader
] = new_nr
;
2303 memcpy(ctx
->sampler_views
[shader
], views
, num_views
* sizeof (void *));
2305 ctx
->dirty
|= PAN_DIRTY_TEXTURES
;
2309 panfrost_sampler_view_destroy(
2310 struct pipe_context
*pctx
,
2311 struct pipe_sampler_view
*view
)
2313 pipe_resource_reference(&view
->texture
, NULL
);
2318 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
2319 const struct pipe_framebuffer_state
*fb
)
2321 struct panfrost_context
*ctx
= pan_context(pctx
);
2323 /* Flush when switching framebuffers, but not if the framebuffer
2324 * state is being restored by u_blitter
2327 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
2328 bool is_scanout
= panfrost_is_scanout(ctx
);
2329 bool has_draws
= job
->last_job
.gpu
;
2331 if (!ctx
->wallpaper_batch
&& (!is_scanout
|| has_draws
)) {
2332 panfrost_flush(pctx
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2335 ctx
->pipe_framebuffer
.nr_cbufs
= fb
->nr_cbufs
;
2336 ctx
->pipe_framebuffer
.samples
= fb
->samples
;
2337 ctx
->pipe_framebuffer
.layers
= fb
->layers
;
2338 ctx
->pipe_framebuffer
.width
= fb
->width
;
2339 ctx
->pipe_framebuffer
.height
= fb
->height
;
2341 struct pipe_surface
*zb
= fb
->zsbuf
;
2342 bool needs_reattach
= false;
2344 for (int i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
2345 struct pipe_surface
*cb
= i
< fb
->nr_cbufs
? fb
->cbufs
[i
] : NULL
;
2347 /* check if changing cbuf */
2348 if (ctx
->pipe_framebuffer
.cbufs
[i
] == cb
) continue;
2351 pipe_surface_reference(&ctx
->pipe_framebuffer
.cbufs
[i
], cb
);
2353 needs_reattach
|= (cb
!= NULL
);
2356 if (ctx
->pipe_framebuffer
.zsbuf
!= zb
) {
2357 pipe_surface_reference(&ctx
->pipe_framebuffer
.zsbuf
, zb
);
2358 needs_reattach
|= (zb
!= NULL
);
2361 if (needs_reattach
) {
2362 if (ctx
->require_sfbd
)
2363 ctx
->vt_framebuffer_sfbd
= panfrost_emit_sfbd(ctx
, ~0);
2365 ctx
->vt_framebuffer_mfbd
= panfrost_emit_mfbd(ctx
, ~0);
2367 panfrost_attach_vt_framebuffer(ctx
);
2372 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
2373 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
2375 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
2379 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
2382 struct panfrost_context
*ctx
= pan_context(pipe
);
2383 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
2384 ctx
->depth_stencil
= depth_stencil
;
2389 /* Alpha does not exist in the hardware (it's not in ES3), so it's
2390 * emulated in the fragment shader */
2392 if (depth_stencil
->alpha
.enabled
) {
2393 /* We need to trigger a new shader (maybe) */
2394 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->fs
);
2398 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_STENCIL_TEST
, depth_stencil
->stencil
[0].enabled
); /* XXX: which one? */
2400 panfrost_make_stencil_state(&depth_stencil
->stencil
[0], &ctx
->fragment_shader_core
.stencil_front
);
2401 ctx
->fragment_shader_core
.stencil_mask_front
= depth_stencil
->stencil
[0].writemask
;
2403 panfrost_make_stencil_state(&depth_stencil
->stencil
[1], &ctx
->fragment_shader_core
.stencil_back
);
2404 ctx
->fragment_shader_core
.stencil_mask_back
= depth_stencil
->stencil
[1].writemask
;
2406 /* Depth state (TODO: Refactor) */
2407 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_DEPTH_TEST
, depth_stencil
->depth
.enabled
);
2409 int func
= depth_stencil
->depth
.enabled
? depth_stencil
->depth
.func
: PIPE_FUNC_ALWAYS
;
2411 ctx
->fragment_shader_core
.unknown2_3
&= ~MALI_DEPTH_FUNC_MASK
;
2412 ctx
->fragment_shader_core
.unknown2_3
|= MALI_DEPTH_FUNC(panfrost_translate_compare_func(func
));
2414 /* Bounds test not implemented */
2415 assert(!depth_stencil
->depth
.bounds_test
);
2417 ctx
->dirty
|= PAN_DIRTY_FS
;
2421 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
2427 panfrost_set_sample_mask(struct pipe_context
*pipe
,
2428 unsigned sample_mask
)
2433 panfrost_set_clip_state(struct pipe_context
*pipe
,
2434 const struct pipe_clip_state
*clip
)
2436 //struct panfrost_context *panfrost = pan_context(pipe);
2440 panfrost_set_viewport_states(struct pipe_context
*pipe
,
2441 unsigned start_slot
,
2442 unsigned num_viewports
,
2443 const struct pipe_viewport_state
*viewports
)
2445 struct panfrost_context
*ctx
= pan_context(pipe
);
2447 assert(start_slot
== 0);
2448 assert(num_viewports
== 1);
2450 ctx
->pipe_viewport
= *viewports
;
2454 panfrost_set_scissor_states(struct pipe_context
*pipe
,
2455 unsigned start_slot
,
2456 unsigned num_scissors
,
2457 const struct pipe_scissor_state
*scissors
)
2459 struct panfrost_context
*ctx
= pan_context(pipe
);
2461 assert(start_slot
== 0);
2462 assert(num_scissors
== 1);
2464 ctx
->scissor
= *scissors
;
2468 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
2469 const struct pipe_poly_stipple
*stipple
)
2471 //struct panfrost_context *panfrost = pan_context(pipe);
2475 panfrost_set_active_query_state(struct pipe_context
*pipe
,
2478 //struct panfrost_context *panfrost = pan_context(pipe);
2482 panfrost_destroy(struct pipe_context
*pipe
)
2484 struct panfrost_context
*panfrost
= pan_context(pipe
);
2485 struct panfrost_screen
*screen
= pan_screen(pipe
->screen
);
2487 if (panfrost
->blitter
)
2488 util_blitter_destroy(panfrost
->blitter
);
2490 if (panfrost
->blitter_wallpaper
)
2491 util_blitter_destroy(panfrost
->blitter_wallpaper
);
2493 panfrost_drm_free_slab(screen
, &panfrost
->scratchpad
);
2494 panfrost_drm_free_slab(screen
, &panfrost
->varying_mem
);
2495 panfrost_drm_free_slab(screen
, &panfrost
->shaders
);
2496 panfrost_drm_free_slab(screen
, &panfrost
->tiler_heap
);
2497 panfrost_drm_free_slab(screen
, &panfrost
->tiler_polygon_list
);
2498 panfrost_drm_free_slab(screen
, &panfrost
->tiler_dummy
);
2500 for (int i
= 0; i
< ARRAY_SIZE(panfrost
->transient_pools
); ++i
) {
2501 struct panfrost_memory_entry
*entry
;
2502 entry
= panfrost
->transient_pools
[i
].entries
[0];
2503 pb_slab_free(&screen
->slabs
, (struct pb_slab_entry
*)entry
);
2509 static struct pipe_query
*
2510 panfrost_create_query(struct pipe_context
*pipe
,
2514 struct panfrost_query
*q
= rzalloc(pipe
, struct panfrost_query
);
2519 return (struct pipe_query
*) q
;
2523 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2529 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2531 struct panfrost_context
*ctx
= pan_context(pipe
);
2532 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2534 switch (query
->type
) {
2535 case PIPE_QUERY_OCCLUSION_COUNTER
:
2536 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2537 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
: {
2538 /* Allocate a word for the query results to be stored */
2539 query
->transfer
= panfrost_allocate_chunk(ctx
, sizeof(unsigned), HEAP_DESCRIPTOR
);
2541 ctx
->occlusion_query
= query
;
2547 DBG("Skipping query %d\n", query
->type
);
2555 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2557 struct panfrost_context
*ctx
= pan_context(pipe
);
2558 ctx
->occlusion_query
= NULL
;
2563 panfrost_get_query_result(struct pipe_context
*pipe
,
2564 struct pipe_query
*q
,
2566 union pipe_query_result
*vresult
)
2569 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2571 /* We need to flush out the jobs to actually run the counter, TODO
2572 * check wait, TODO wallpaper after if needed */
2574 panfrost_flush(pipe
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2576 switch (query
->type
) {
2577 case PIPE_QUERY_OCCLUSION_COUNTER
:
2578 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2579 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
: {
2580 /* Read back the query results */
2581 unsigned *result
= (unsigned *) query
->transfer
.cpu
;
2582 unsigned passed
= *result
;
2584 if (query
->type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
2585 vresult
->u64
= passed
;
2587 vresult
->b
= !!passed
;
2593 DBG("Skipped query get %d\n", query
->type
);
2600 static struct pipe_stream_output_target
*
2601 panfrost_create_stream_output_target(struct pipe_context
*pctx
,
2602 struct pipe_resource
*prsc
,
2603 unsigned buffer_offset
,
2604 unsigned buffer_size
)
2606 struct pipe_stream_output_target
*target
;
2608 target
= rzalloc(pctx
, struct pipe_stream_output_target
);
2613 pipe_reference_init(&target
->reference
, 1);
2614 pipe_resource_reference(&target
->buffer
, prsc
);
2616 target
->context
= pctx
;
2617 target
->buffer_offset
= buffer_offset
;
2618 target
->buffer_size
= buffer_size
;
2624 panfrost_stream_output_target_destroy(struct pipe_context
*pctx
,
2625 struct pipe_stream_output_target
*target
)
2627 pipe_resource_reference(&target
->buffer
, NULL
);
2628 ralloc_free(target
);
2632 panfrost_set_stream_output_targets(struct pipe_context
*pctx
,
2633 unsigned num_targets
,
2634 struct pipe_stream_output_target
**targets
,
2635 const unsigned *offsets
)
2641 panfrost_setup_hardware(struct panfrost_context
*ctx
)
2643 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2644 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
2646 for (int i
= 0; i
< ARRAY_SIZE(ctx
->transient_pools
); ++i
) {
2647 /* Allocate the beginning of the transient pool */
2648 int entry_size
= (1 << 22); /* 4MB */
2650 ctx
->transient_pools
[i
].entry_size
= entry_size
;
2651 ctx
->transient_pools
[i
].entry_count
= 1;
2653 ctx
->transient_pools
[i
].entries
[0] = (struct panfrost_memory_entry
*) pb_slab_alloc(&screen
->slabs
, entry_size
, HEAP_TRANSIENT
);
2656 panfrost_drm_allocate_slab(screen
, &ctx
->scratchpad
, 64, false, 0, 0, 0);
2657 panfrost_drm_allocate_slab(screen
, &ctx
->varying_mem
, 16384, false, PAN_ALLOCATE_INVISIBLE
| PAN_ALLOCATE_COHERENT_LOCAL
, 0, 0);
2658 panfrost_drm_allocate_slab(screen
, &ctx
->shaders
, 4096, true, PAN_ALLOCATE_EXECUTE
, 0, 0);
2659 panfrost_drm_allocate_slab(screen
, &ctx
->tiler_heap
, 32768, false, PAN_ALLOCATE_INVISIBLE
| PAN_ALLOCATE_GROWABLE
, 1, 128);
2660 panfrost_drm_allocate_slab(screen
, &ctx
->tiler_polygon_list
, 128*128, false, PAN_ALLOCATE_INVISIBLE
| PAN_ALLOCATE_GROWABLE
, 1, 128);
2661 panfrost_drm_allocate_slab(screen
, &ctx
->tiler_dummy
, 1, false, PAN_ALLOCATE_INVISIBLE
, 0, 0);
2664 /* New context creation, which also does hardware initialisation since I don't
2665 * know the better way to structure this :smirk: */
2667 struct pipe_context
*
2668 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
2670 struct panfrost_context
*ctx
= rzalloc(screen
, struct panfrost_context
);
2671 struct panfrost_screen
*pscreen
= pan_screen(screen
);
2672 memset(ctx
, 0, sizeof(*ctx
));
2673 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2675 ctx
->is_t6xx
= pscreen
->gpu_id
<= 0x0750; /* For now, this flag means T760 or less */
2676 ctx
->require_sfbd
= pscreen
->gpu_id
< 0x0750; /* T760 is the first to support MFBD */
2678 gallium
->screen
= screen
;
2680 gallium
->destroy
= panfrost_destroy
;
2682 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
2684 gallium
->flush
= panfrost_flush
;
2685 gallium
->clear
= panfrost_clear
;
2686 gallium
->draw_vbo
= panfrost_draw_vbo
;
2688 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
2689 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
2691 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
2693 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
2694 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
2695 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
2697 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
2698 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
2699 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
2701 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
2702 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
2703 gallium
->delete_vertex_elements_state
= panfrost_generic_cso_delete
;
2705 gallium
->create_fs_state
= panfrost_create_shader_state
;
2706 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
2707 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
2709 gallium
->create_vs_state
= panfrost_create_shader_state
;
2710 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
2711 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
2713 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
2714 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
2715 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
2717 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
2718 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
2719 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
2721 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
2723 gallium
->set_clip_state
= panfrost_set_clip_state
;
2724 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
2725 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
2726 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
2727 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
2729 gallium
->create_query
= panfrost_create_query
;
2730 gallium
->destroy_query
= panfrost_destroy_query
;
2731 gallium
->begin_query
= panfrost_begin_query
;
2732 gallium
->end_query
= panfrost_end_query
;
2733 gallium
->get_query_result
= panfrost_get_query_result
;
2735 gallium
->create_stream_output_target
= panfrost_create_stream_output_target
;
2736 gallium
->stream_output_target_destroy
= panfrost_stream_output_target_destroy
;
2737 gallium
->set_stream_output_targets
= panfrost_set_stream_output_targets
;
2739 panfrost_resource_context_init(gallium
);
2740 panfrost_blend_context_init(gallium
);
2742 panfrost_drm_init_context(ctx
);
2744 panfrost_setup_hardware(ctx
);
2747 gallium
->stream_uploader
= u_upload_create_default(gallium
);
2748 gallium
->const_uploader
= gallium
->stream_uploader
;
2749 assert(gallium
->stream_uploader
);
2751 /* Midgard supports ES modes, plus QUADS/QUAD_STRIPS/POLYGON */
2752 ctx
->draw_modes
= (1 << (PIPE_PRIM_POLYGON
+ 1)) - 1;
2754 ctx
->primconvert
= util_primconvert_create(gallium
, ctx
->draw_modes
);
2756 ctx
->blitter
= util_blitter_create(gallium
);
2757 ctx
->blitter_wallpaper
= util_blitter_create(gallium
);
2759 assert(ctx
->blitter
);
2760 assert(ctx
->blitter_wallpaper
);
2762 /* Prepare for render! */
2764 panfrost_job_init(ctx
);
2765 panfrost_emit_vertex_payload(ctx
);
2766 panfrost_emit_tiler_payload(ctx
);
2767 panfrost_invalidate_frame(ctx
);
2768 panfrost_default_shader_backend(ctx
);