2 * © Copyright 2018 Alyssa Rosenzweig
3 * Copyright © 2014-2017 Broadcom
4 * Copyright (C) 2017 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include "pan_context.h"
31 #include "pan_format.h"
33 #include "util/macros.h"
34 #include "util/u_format.h"
35 #include "util/u_inlines.h"
36 #include "util/u_upload_mgr.h"
37 #include "util/u_memory.h"
38 #include "util/u_vbuf.h"
39 #include "util/half_float.h"
40 #include "util/u_helpers.h"
41 #include "util/u_format.h"
42 #include "util/u_prim.h"
43 #include "util/u_prim_restart.h"
44 #include "indices/u_primconvert.h"
45 #include "tgsi/tgsi_parse.h"
46 #include "tgsi/tgsi_from_mesa.h"
47 #include "util/u_math.h"
49 #include "pan_screen.h"
50 #include "pan_blending.h"
51 #include "pan_blend_shaders.h"
54 /* Framebuffer descriptor */
56 static struct midgard_tiler_descriptor
57 panfrost_emit_midg_tiler(struct panfrost_batch
*batch
, unsigned vertex_count
)
59 struct panfrost_context
*ctx
= batch
->ctx
;
60 struct midgard_tiler_descriptor t
= {};
61 unsigned height
= batch
->key
.height
;
62 unsigned width
= batch
->key
.width
;
65 panfrost_choose_hierarchy_mask(width
, height
, vertex_count
);
67 /* Compute the polygon header size and use that to offset the body */
69 unsigned header_size
= panfrost_tiler_header_size(
70 width
, height
, t
.hierarchy_mask
);
72 t
.polygon_list_size
= panfrost_tiler_full_size(
73 width
, height
, t
.hierarchy_mask
);
77 if (t
.hierarchy_mask
) {
78 t
.polygon_list
= panfrost_batch_get_polygon_list(batch
,
83 /* Allow the entire tiler heap */
84 t
.heap_start
= ctx
->tiler_heap
->gpu
;
85 t
.heap_end
= ctx
->tiler_heap
->gpu
+ ctx
->tiler_heap
->size
;
87 /* The tiler is disabled, so don't allow the tiler heap */
88 t
.heap_start
= ctx
->tiler_heap
->gpu
;
89 t
.heap_end
= t
.heap_start
;
91 /* Use a dummy polygon list */
92 t
.polygon_list
= ctx
->tiler_dummy
->gpu
;
94 /* Disable the tiler */
95 t
.hierarchy_mask
|= MALI_TILER_DISABLED
;
99 t
.polygon_list
+ header_size
;
104 struct mali_single_framebuffer
105 panfrost_emit_sfbd(struct panfrost_batch
*batch
, unsigned vertex_count
)
107 struct panfrost_context
*ctx
= batch
->ctx
;
108 unsigned width
= batch
->key
.width
;
109 unsigned height
= batch
->key
.height
;
111 struct mali_single_framebuffer framebuffer
= {
112 .width
= MALI_POSITIVE(width
),
113 .height
= MALI_POSITIVE(height
),
115 .format
= 0x30000000,
116 .clear_flags
= 0x1000,
117 .unknown_address_0
= ctx
->scratchpad
->gpu
,
118 .tiler
= panfrost_emit_midg_tiler(batch
, vertex_count
),
124 struct bifrost_framebuffer
125 panfrost_emit_mfbd(struct panfrost_batch
*batch
, unsigned vertex_count
)
127 struct panfrost_context
*ctx
= batch
->ctx
;
128 unsigned width
= batch
->key
.width
;
129 unsigned height
= batch
->key
.height
;
131 struct bifrost_framebuffer framebuffer
= {
132 .unk0
= 0x1e5, /* 1e4 if no spill */
133 .width1
= MALI_POSITIVE(width
),
134 .height1
= MALI_POSITIVE(height
),
135 .width2
= MALI_POSITIVE(width
),
136 .height2
= MALI_POSITIVE(height
),
140 .rt_count_1
= MALI_POSITIVE(batch
->key
.nr_cbufs
),
145 .scratchpad
= ctx
->scratchpad
->gpu
,
146 .tiler
= panfrost_emit_midg_tiler(batch
, vertex_count
)
154 struct pipe_context
*pipe
,
156 const union pipe_color_union
*color
,
157 double depth
, unsigned stencil
)
159 struct panfrost_context
*ctx
= pan_context(pipe
);
160 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
162 panfrost_batch_clear(batch
, buffers
, color
, depth
, stencil
);
166 panfrost_attach_vt_mfbd(struct panfrost_batch
*batch
)
168 struct bifrost_framebuffer mfbd
= panfrost_emit_mfbd(batch
, ~0);
170 return panfrost_upload_transient(batch
, &mfbd
, sizeof(mfbd
)) | MALI_MFBD
;
174 panfrost_attach_vt_sfbd(struct panfrost_batch
*batch
)
176 struct mali_single_framebuffer sfbd
= panfrost_emit_sfbd(batch
, ~0);
178 return panfrost_upload_transient(batch
, &sfbd
, sizeof(sfbd
)) | MALI_SFBD
;
182 panfrost_attach_vt_framebuffer(struct panfrost_context
*ctx
)
184 /* Skip the attach if we can */
186 if (ctx
->payloads
[PIPE_SHADER_VERTEX
].postfix
.framebuffer
) {
187 assert(ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.framebuffer
);
191 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
192 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
194 if (!batch
->framebuffer
)
195 batch
->framebuffer
= screen
->require_sfbd
?
196 panfrost_attach_vt_sfbd(batch
) :
197 panfrost_attach_vt_mfbd(batch
);
199 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
200 ctx
->payloads
[i
].postfix
.framebuffer
= batch
->framebuffer
;
203 /* Reset per-frame context, called on context initialisation as well as after
204 * flushing a frame */
207 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
209 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
210 ctx
->payloads
[i
].postfix
.framebuffer
= 0;
213 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
216 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
| PAN_DIRTY_TEXTURES
;
218 /* TODO: When does this need to be handled? */
219 ctx
->active_queries
= true;
222 /* In practice, every field of these payloads should be configurable
223 * arbitrarily, which means these functions are basically catch-all's for
224 * as-of-yet unwavering unknowns */
227 panfrost_emit_vertex_payload(struct panfrost_context
*ctx
)
229 /* 0x2 bit clear on 32-bit T6XX */
231 struct midgard_payload_vertex_tiler payload
= {
232 .gl_enables
= 0x4 | 0x2,
235 /* Vertex and compute are closely coupled, so share a payload */
237 memcpy(&ctx
->payloads
[PIPE_SHADER_VERTEX
], &payload
, sizeof(payload
));
238 memcpy(&ctx
->payloads
[PIPE_SHADER_COMPUTE
], &payload
, sizeof(payload
));
242 panfrost_emit_tiler_payload(struct panfrost_context
*ctx
)
244 struct midgard_payload_vertex_tiler payload
= {
246 .zero1
= 0xffff, /* Why is this only seen on test-quad-textured? */
250 memcpy(&ctx
->payloads
[PIPE_SHADER_FRAGMENT
], &payload
, sizeof(payload
));
254 translate_tex_wrap(enum pipe_tex_wrap w
)
257 case PIPE_TEX_WRAP_REPEAT
:
258 return MALI_WRAP_REPEAT
;
260 /* TODO: lower GL_CLAMP? */
261 case PIPE_TEX_WRAP_CLAMP
:
262 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
263 return MALI_WRAP_CLAMP_TO_EDGE
;
265 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
266 return MALI_WRAP_CLAMP_TO_BORDER
;
268 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
269 return MALI_WRAP_MIRRORED_REPEAT
;
272 unreachable("Invalid wrap");
277 panfrost_translate_compare_func(enum pipe_compare_func in
)
280 case PIPE_FUNC_NEVER
:
281 return MALI_FUNC_NEVER
;
284 return MALI_FUNC_LESS
;
286 case PIPE_FUNC_EQUAL
:
287 return MALI_FUNC_EQUAL
;
289 case PIPE_FUNC_LEQUAL
:
290 return MALI_FUNC_LEQUAL
;
292 case PIPE_FUNC_GREATER
:
293 return MALI_FUNC_GREATER
;
295 case PIPE_FUNC_NOTEQUAL
:
296 return MALI_FUNC_NOTEQUAL
;
298 case PIPE_FUNC_GEQUAL
:
299 return MALI_FUNC_GEQUAL
;
301 case PIPE_FUNC_ALWAYS
:
302 return MALI_FUNC_ALWAYS
;
305 unreachable("Invalid func");
310 panfrost_translate_alt_compare_func(enum pipe_compare_func in
)
313 case PIPE_FUNC_NEVER
:
314 return MALI_ALT_FUNC_NEVER
;
317 return MALI_ALT_FUNC_LESS
;
319 case PIPE_FUNC_EQUAL
:
320 return MALI_ALT_FUNC_EQUAL
;
322 case PIPE_FUNC_LEQUAL
:
323 return MALI_ALT_FUNC_LEQUAL
;
325 case PIPE_FUNC_GREATER
:
326 return MALI_ALT_FUNC_GREATER
;
328 case PIPE_FUNC_NOTEQUAL
:
329 return MALI_ALT_FUNC_NOTEQUAL
;
331 case PIPE_FUNC_GEQUAL
:
332 return MALI_ALT_FUNC_GEQUAL
;
334 case PIPE_FUNC_ALWAYS
:
335 return MALI_ALT_FUNC_ALWAYS
;
338 unreachable("Invalid alt func");
343 panfrost_translate_stencil_op(enum pipe_stencil_op in
)
346 case PIPE_STENCIL_OP_KEEP
:
347 return MALI_STENCIL_KEEP
;
349 case PIPE_STENCIL_OP_ZERO
:
350 return MALI_STENCIL_ZERO
;
352 case PIPE_STENCIL_OP_REPLACE
:
353 return MALI_STENCIL_REPLACE
;
355 case PIPE_STENCIL_OP_INCR
:
356 return MALI_STENCIL_INCR
;
358 case PIPE_STENCIL_OP_DECR
:
359 return MALI_STENCIL_DECR
;
361 case PIPE_STENCIL_OP_INCR_WRAP
:
362 return MALI_STENCIL_INCR_WRAP
;
364 case PIPE_STENCIL_OP_DECR_WRAP
:
365 return MALI_STENCIL_DECR_WRAP
;
367 case PIPE_STENCIL_OP_INVERT
:
368 return MALI_STENCIL_INVERT
;
371 unreachable("Invalid stencil op");
376 panfrost_make_stencil_state(const struct pipe_stencil_state
*in
, struct mali_stencil_test
*out
)
378 out
->ref
= 0; /* Gallium gets it from elsewhere */
380 out
->mask
= in
->valuemask
;
381 out
->func
= panfrost_translate_compare_func(in
->func
);
382 out
->sfail
= panfrost_translate_stencil_op(in
->fail_op
);
383 out
->dpfail
= panfrost_translate_stencil_op(in
->zfail_op
);
384 out
->dppass
= panfrost_translate_stencil_op(in
->zpass_op
);
388 panfrost_default_shader_backend(struct panfrost_context
*ctx
)
390 struct mali_shader_meta shader
= {
391 .alpha_coverage
= ~MALI_ALPHA_COVERAGE(0.000000),
393 .unknown2_3
= MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS
) | 0x3010,
394 .unknown2_4
= MALI_NO_MSAA
| 0x4e0,
397 /* unknown2_4 has 0x10 bit set on T6XX. We don't know why this is
398 * required (independent of 32-bit/64-bit descriptors), or why it's not
399 * used on later GPU revisions. Otherwise, all shader jobs fault on
400 * these earlier chips (perhaps this is a chicken bit of some kind).
401 * More investigation is needed. */
404 shader
.unknown2_4
|= 0x10;
407 struct pipe_stencil_state default_stencil
= {
409 .func
= PIPE_FUNC_ALWAYS
,
410 .fail_op
= MALI_STENCIL_KEEP
,
411 .zfail_op
= MALI_STENCIL_KEEP
,
412 .zpass_op
= MALI_STENCIL_KEEP
,
417 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_front
);
418 shader
.stencil_mask_front
= default_stencil
.writemask
;
420 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_back
);
421 shader
.stencil_mask_back
= default_stencil
.writemask
;
423 if (default_stencil
.enabled
)
424 shader
.unknown2_4
|= MALI_STENCIL_TEST
;
426 memcpy(&ctx
->fragment_shader_core
, &shader
, sizeof(shader
));
429 /* Generates a vertex/tiler job. This is, in some sense, the heart of the
430 * graphics command stream. It should be called once per draw, accordding to
431 * presentations. Set is_tiler for "tiler" jobs (fragment shader jobs, but in
432 * Mali parlance, "fragment" refers to framebuffer writeout). Clear it for
435 struct panfrost_transfer
436 panfrost_vertex_tiler_job(struct panfrost_context
*ctx
, bool is_tiler
)
438 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
439 struct mali_job_descriptor_header job
= {
440 .job_type
= is_tiler
? JOB_TYPE_TILER
: JOB_TYPE_VERTEX
,
441 .job_descriptor_size
= 1,
444 struct midgard_payload_vertex_tiler
*payload
= is_tiler
? &ctx
->payloads
[PIPE_SHADER_FRAGMENT
] : &ctx
->payloads
[PIPE_SHADER_VERTEX
];
446 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, sizeof(job
) + sizeof(*payload
));
447 memcpy(transfer
.cpu
, &job
, sizeof(job
));
448 memcpy(transfer
.cpu
+ sizeof(job
), payload
, sizeof(*payload
));
453 panfrost_vertex_buffer_address(struct panfrost_context
*ctx
, unsigned i
)
455 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[i
];
456 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (buf
->buffer
.resource
);
458 return rsrc
->bo
->gpu
+ buf
->buffer_offset
;
462 panfrost_writes_point_size(struct panfrost_context
*ctx
)
464 assert(ctx
->shader
[PIPE_SHADER_VERTEX
]);
465 struct panfrost_shader_state
*vs
= &ctx
->shader
[PIPE_SHADER_VERTEX
]->variants
[ctx
->shader
[PIPE_SHADER_VERTEX
]->active_variant
];
467 return vs
->writes_point_size
&& ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
== MALI_POINTS
;
470 /* Stage the attribute descriptors so we can adjust src_offset
471 * to let BOs align nicely */
474 panfrost_stage_attributes(struct panfrost_context
*ctx
)
476 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
477 struct panfrost_vertex_state
*so
= ctx
->vertex
;
479 size_t sz
= sizeof(struct mali_attr_meta
) * so
->num_elements
;
480 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, sz
);
481 struct mali_attr_meta
*target
= (struct mali_attr_meta
*) transfer
.cpu
;
483 /* Copy as-is for the first pass */
484 memcpy(target
, so
->hw
, sz
);
486 /* Fixup offsets for the second pass. Recall that the hardware
487 * calculates attribute addresses as:
489 * addr = base + (stride * vtx) + src_offset;
491 * However, on Mali, base must be aligned to 64-bytes, so we
494 * base' = base & ~63 = base - (base & 63)
496 * To compensate when using base' (see emit_vertex_data), we have
497 * to adjust src_offset by the masked off piece:
499 * addr' = base' + (stride * vtx) + (src_offset + (base & 63))
500 * = base - (base & 63) + (stride * vtx) + src_offset + (base & 63)
501 * = base + (stride * vtx) + src_offset
507 unsigned start
= ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
;
509 for (unsigned i
= 0; i
< so
->num_elements
; ++i
) {
510 unsigned vbi
= so
->pipe
[i
].vertex_buffer_index
;
511 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[vbi
];
512 mali_ptr addr
= panfrost_vertex_buffer_address(ctx
, vbi
);
514 /* Adjust by the masked off bits of the offset */
515 target
[i
].src_offset
+= (addr
& 63);
517 /* Also, somewhat obscurely per-instance data needs to be
518 * offset in response to a delayed start in an indexed draw */
520 if (so
->pipe
[i
].instance_divisor
&& ctx
->instance_count
> 1 && start
) {
521 target
[i
].src_offset
-= buf
->stride
* start
;
527 ctx
->payloads
[PIPE_SHADER_VERTEX
].postfix
.attribute_meta
= transfer
.gpu
;
531 panfrost_upload_sampler_descriptors(struct panfrost_context
*ctx
)
533 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
534 size_t desc_size
= sizeof(struct mali_sampler_descriptor
);
536 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
539 if (ctx
->sampler_count
[t
] && ctx
->sampler_view_count
[t
]) {
540 size_t transfer_size
= desc_size
* ctx
->sampler_count
[t
];
542 struct panfrost_transfer transfer
=
543 panfrost_allocate_transient(batch
, transfer_size
);
545 struct mali_sampler_descriptor
*desc
=
546 (struct mali_sampler_descriptor
*) transfer
.cpu
;
548 for (int i
= 0; i
< ctx
->sampler_count
[t
]; ++i
)
549 desc
[i
] = ctx
->samplers
[t
][i
]->hw
;
551 upload
= transfer
.gpu
;
554 ctx
->payloads
[t
].postfix
.sampler_descriptor
= upload
;
558 static enum mali_texture_layout
559 panfrost_layout_for_texture(struct panfrost_resource
*rsrc
)
561 /* TODO: other linear depth textures */
562 bool is_depth
= rsrc
->base
.format
== PIPE_FORMAT_Z32_UNORM
;
564 switch (rsrc
->layout
) {
566 return MALI_TEXTURE_AFBC
;
569 return MALI_TEXTURE_TILED
;
571 return is_depth
? MALI_TEXTURE_TILED
: MALI_TEXTURE_LINEAR
;
573 unreachable("Invalid texture layout");
579 struct panfrost_context
*ctx
,
580 struct panfrost_sampler_view
*view
)
585 struct pipe_sampler_view
*pview
= &view
->base
;
586 struct panfrost_resource
*rsrc
= pan_resource(pview
->texture
);
588 /* Do we interleave an explicit stride with every element? */
590 bool has_manual_stride
= view
->manual_stride
;
592 /* For easy access */
594 bool is_buffer
= pview
->target
== PIPE_BUFFER
;
595 unsigned first_level
= is_buffer
? 0 : pview
->u
.tex
.first_level
;
596 unsigned last_level
= is_buffer
? 0 : pview
->u
.tex
.last_level
;
597 unsigned first_layer
= is_buffer
? 0 : pview
->u
.tex
.first_layer
;
598 unsigned last_layer
= is_buffer
? 0 : pview
->u
.tex
.last_layer
;
600 /* Lower-bit is set when sampling from colour AFBC */
601 bool is_afbc
= rsrc
->layout
== PAN_AFBC
;
602 bool is_zs
= rsrc
->base
.bind
& PIPE_BIND_DEPTH_STENCIL
;
603 unsigned afbc_bit
= (is_afbc
&& !is_zs
) ? 1 : 0;
605 /* Add the BO to the job so it's retained until the job is done. */
606 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
607 panfrost_batch_add_bo(batch
, rsrc
->bo
);
609 /* Add the usage flags in, since they can change across the CSO
610 * lifetime due to layout switches */
612 view
->hw
.format
.layout
= panfrost_layout_for_texture(rsrc
);
613 view
->hw
.format
.manual_stride
= has_manual_stride
;
615 /* Inject the addresses in, interleaving mip levels, cube faces, and
616 * strides in that order */
620 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
621 for (unsigned f
= first_layer
; f
<= last_layer
; ++f
) {
623 view
->hw
.payload
[idx
++] =
624 panfrost_get_texture_address(rsrc
, l
, f
) + afbc_bit
;
626 if (has_manual_stride
) {
627 view
->hw
.payload
[idx
++] =
628 rsrc
->slices
[l
].stride
;
633 return panfrost_upload_transient(batch
, &view
->hw
,
634 sizeof(struct mali_texture_descriptor
));
638 panfrost_upload_texture_descriptors(struct panfrost_context
*ctx
)
640 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
642 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
643 mali_ptr trampoline
= 0;
645 if (ctx
->sampler_view_count
[t
]) {
646 uint64_t trampolines
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
648 for (int i
= 0; i
< ctx
->sampler_view_count
[t
]; ++i
)
650 panfrost_upload_tex(ctx
, ctx
->sampler_views
[t
][i
]);
652 trampoline
= panfrost_upload_transient(batch
, trampolines
, sizeof(uint64_t) * ctx
->sampler_view_count
[t
]);
655 ctx
->payloads
[t
].postfix
.texture_trampoline
= trampoline
;
659 struct sysval_uniform
{
668 static void panfrost_upload_viewport_scale_sysval(struct panfrost_context
*ctx
,
669 struct sysval_uniform
*uniform
)
671 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
673 uniform
->f
[0] = vp
->scale
[0];
674 uniform
->f
[1] = vp
->scale
[1];
675 uniform
->f
[2] = vp
->scale
[2];
678 static void panfrost_upload_viewport_offset_sysval(struct panfrost_context
*ctx
,
679 struct sysval_uniform
*uniform
)
681 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
683 uniform
->f
[0] = vp
->translate
[0];
684 uniform
->f
[1] = vp
->translate
[1];
685 uniform
->f
[2] = vp
->translate
[2];
688 static void panfrost_upload_txs_sysval(struct panfrost_context
*ctx
,
689 enum pipe_shader_type st
,
690 unsigned int sysvalid
,
691 struct sysval_uniform
*uniform
)
693 unsigned texidx
= PAN_SYSVAL_ID_TO_TXS_TEX_IDX(sysvalid
);
694 unsigned dim
= PAN_SYSVAL_ID_TO_TXS_DIM(sysvalid
);
695 bool is_array
= PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(sysvalid
);
696 struct pipe_sampler_view
*tex
= &ctx
->sampler_views
[st
][texidx
]->base
;
699 uniform
->i
[0] = u_minify(tex
->texture
->width0
, tex
->u
.tex
.first_level
);
702 uniform
->i
[1] = u_minify(tex
->texture
->height0
,
703 tex
->u
.tex
.first_level
);
706 uniform
->i
[2] = u_minify(tex
->texture
->depth0
,
707 tex
->u
.tex
.first_level
);
710 uniform
->i
[dim
] = tex
->texture
->array_size
;
713 static void panfrost_upload_ssbo_sysval(
714 struct panfrost_context
*ctx
,
715 enum pipe_shader_type st
,
717 struct sysval_uniform
*uniform
)
719 assert(ctx
->ssbo_mask
[st
] & (1 << ssbo_id
));
720 struct pipe_shader_buffer sb
= ctx
->ssbo
[st
][ssbo_id
];
722 /* Compute address */
723 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
724 struct panfrost_bo
*bo
= pan_resource(sb
.buffer
)->bo
;
726 panfrost_batch_add_bo(batch
, bo
);
728 /* Upload address and size as sysval */
729 uniform
->du
[0] = bo
->gpu
+ sb
.buffer_offset
;
730 uniform
->u
[2] = sb
.buffer_size
;
733 static void panfrost_upload_num_work_groups_sysval(struct panfrost_context
*ctx
,
734 struct sysval_uniform
*uniform
)
736 uniform
->u
[0] = ctx
->compute_grid
->grid
[0];
737 uniform
->u
[1] = ctx
->compute_grid
->grid
[1];
738 uniform
->u
[2] = ctx
->compute_grid
->grid
[2];
741 static void panfrost_upload_sysvals(struct panfrost_context
*ctx
, void *buf
,
742 struct panfrost_shader_state
*ss
,
743 enum pipe_shader_type st
)
745 struct sysval_uniform
*uniforms
= (void *)buf
;
747 for (unsigned i
= 0; i
< ss
->sysval_count
; ++i
) {
748 int sysval
= ss
->sysval
[i
];
750 switch (PAN_SYSVAL_TYPE(sysval
)) {
751 case PAN_SYSVAL_VIEWPORT_SCALE
:
752 panfrost_upload_viewport_scale_sysval(ctx
, &uniforms
[i
]);
754 case PAN_SYSVAL_VIEWPORT_OFFSET
:
755 panfrost_upload_viewport_offset_sysval(ctx
, &uniforms
[i
]);
757 case PAN_SYSVAL_TEXTURE_SIZE
:
758 panfrost_upload_txs_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
761 case PAN_SYSVAL_SSBO
:
762 panfrost_upload_ssbo_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
765 case PAN_SYSVAL_NUM_WORK_GROUPS
:
766 panfrost_upload_num_work_groups_sysval(ctx
, &uniforms
[i
]);
776 panfrost_map_constant_buffer_cpu(struct panfrost_constant_buffer
*buf
, unsigned index
)
778 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
779 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
782 return rsrc
->bo
->cpu
;
783 else if (cb
->user_buffer
)
784 return cb
->user_buffer
;
786 unreachable("No constant buffer");
790 panfrost_map_constant_buffer_gpu(
791 struct panfrost_context
*ctx
,
792 struct panfrost_constant_buffer
*buf
,
795 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
796 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
797 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
800 panfrost_batch_add_bo(batch
, rsrc
->bo
);
801 return rsrc
->bo
->gpu
;
802 } else if (cb
->user_buffer
) {
803 return panfrost_upload_transient(batch
, cb
->user_buffer
, cb
->buffer_size
);
805 unreachable("No constant buffer");
809 /* Compute number of UBOs active (more specifically, compute the highest UBO
810 * number addressable -- if there are gaps, include them in the count anyway).
811 * We always include UBO #0 in the count, since we *need* uniforms enabled for
815 panfrost_ubo_count(struct panfrost_context
*ctx
, enum pipe_shader_type stage
)
817 unsigned mask
= ctx
->constant_buffer
[stage
].enabled_mask
| 1;
818 return 32 - __builtin_clz(mask
);
821 /* Fixes up a shader state with current state, returning a GPU address to the
825 panfrost_patch_shader_state(
826 struct panfrost_context
*ctx
,
827 struct panfrost_shader_state
*ss
,
828 enum pipe_shader_type stage
,
831 ss
->tripipe
->texture_count
= ctx
->sampler_view_count
[stage
];
832 ss
->tripipe
->sampler_count
= ctx
->sampler_count
[stage
];
834 ss
->tripipe
->midgard1
.flags
= 0x220;
836 unsigned ubo_count
= panfrost_ubo_count(ctx
, stage
);
837 ss
->tripipe
->midgard1
.uniform_buffer_count
= ubo_count
;
839 /* We can't reuse over frames; that's not safe. The descriptor must be
840 * transient uploaded */
843 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
845 return panfrost_upload_transient(batch
, ss
->tripipe
,
846 sizeof(struct mali_shader_meta
));
849 /* If we don't need an upload, don't bother */
855 panfrost_patch_shader_state_compute(
856 struct panfrost_context
*ctx
,
857 enum pipe_shader_type stage
,
860 struct panfrost_shader_variants
*all
= ctx
->shader
[stage
];
863 ctx
->payloads
[stage
].postfix
._shader_upper
= 0;
867 struct panfrost_shader_state
*s
= &all
->variants
[all
->active_variant
];
869 ctx
->payloads
[stage
].postfix
._shader_upper
=
870 panfrost_patch_shader_state(ctx
, s
, stage
, should_upload
) >> 4;
873 /* Go through dirty flags and actualise them in the cmdstream. */
876 panfrost_emit_for_draw(struct panfrost_context
*ctx
, bool with_vertex_data
)
878 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
879 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
881 panfrost_attach_vt_framebuffer(ctx
);
883 if (with_vertex_data
) {
884 panfrost_emit_vertex_data(batch
);
886 /* Varyings emitted for -all- geometry */
887 unsigned total_count
= ctx
->padded_count
* ctx
->instance_count
;
888 panfrost_emit_varying_descriptor(ctx
, total_count
);
891 bool msaa
= ctx
->rasterizer
->base
.multisample
;
893 if (ctx
->dirty
& PAN_DIRTY_RASTERIZER
) {
894 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].gl_enables
= ctx
->rasterizer
->tiler_gl_enables
;
896 /* TODO: Sample size */
897 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_HAS_MSAA
, msaa
);
898 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_NO_MSAA
, !msaa
);
901 panfrost_batch_set_requirements(batch
);
903 if (ctx
->occlusion_query
) {
904 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].gl_enables
|= MALI_OCCLUSION_QUERY
| MALI_OCCLUSION_PRECISE
;
905 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.occlusion_counter
= ctx
->occlusion_query
->transfer
.gpu
;
908 panfrost_patch_shader_state_compute(ctx
, PIPE_SHADER_VERTEX
, true);
909 panfrost_patch_shader_state_compute(ctx
, PIPE_SHADER_COMPUTE
, true);
911 if (ctx
->dirty
& (PAN_DIRTY_RASTERIZER
| PAN_DIRTY_VS
)) {
912 /* Check if we need to link the gl_PointSize varying */
913 if (!panfrost_writes_point_size(ctx
)) {
914 /* If the size is constant, write it out. Otherwise,
915 * don't touch primitive_size (since we would clobber
916 * the pointer there) */
918 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].primitive_size
.constant
= ctx
->rasterizer
->base
.line_width
;
922 /* TODO: Maybe dirty track FS, maybe not. For now, it's transient. */
923 if (ctx
->shader
[PIPE_SHADER_FRAGMENT
])
924 ctx
->dirty
|= PAN_DIRTY_FS
;
926 if (ctx
->dirty
& PAN_DIRTY_FS
) {
927 assert(ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
928 struct panfrost_shader_state
*variant
= &ctx
->shader
[PIPE_SHADER_FRAGMENT
]->variants
[ctx
->shader
[PIPE_SHADER_FRAGMENT
]->active_variant
];
930 panfrost_patch_shader_state(ctx
, variant
, PIPE_SHADER_FRAGMENT
, false);
932 panfrost_batch_add_bo(batch
, variant
->bo
);
934 #define COPY(name) ctx->fragment_shader_core.name = variant->tripipe->name
937 COPY(attribute_count
);
941 COPY(midgard1
.uniform_count
);
942 COPY(midgard1
.uniform_buffer_count
);
943 COPY(midgard1
.work_count
);
944 COPY(midgard1
.flags
);
945 COPY(midgard1
.unknown2
);
949 /* Get blending setup */
950 unsigned rt_count
= MAX2(ctx
->pipe_framebuffer
.nr_cbufs
, 1);
952 struct panfrost_blend_final blend
[PIPE_MAX_COLOR_BUFS
];
954 for (unsigned c
= 0; c
< rt_count
; ++c
)
955 blend
[c
] = panfrost_get_blend_for_context(ctx
, c
);
957 /* If there is a blend shader, work registers are shared. XXX: opt */
959 for (unsigned c
= 0; c
< rt_count
; ++c
) {
960 if (blend
[c
].is_shader
)
961 ctx
->fragment_shader_core
.midgard1
.work_count
= 16;
964 /* Set late due to depending on render state */
965 unsigned flags
= ctx
->fragment_shader_core
.midgard1
.flags
;
967 /* Depending on whether it's legal to in the given shader, we
968 * try to enable early-z testing (or forward-pixel kill?) */
970 if (!variant
->can_discard
)
971 flags
|= MALI_EARLY_Z
;
973 /* Any time texturing is used, derivatives are implicitly
974 * calculated, so we need to enable helper invocations */
976 if (variant
->helper_invocations
)
977 flags
|= MALI_HELPER_INVOCATIONS
;
979 ctx
->fragment_shader_core
.midgard1
.flags
= flags
;
981 /* Assign the stencil refs late */
983 unsigned front_ref
= ctx
->stencil_ref
.ref_value
[0];
984 unsigned back_ref
= ctx
->stencil_ref
.ref_value
[1];
985 bool back_enab
= ctx
->depth_stencil
->stencil
[1].enabled
;
987 ctx
->fragment_shader_core
.stencil_front
.ref
= front_ref
;
988 ctx
->fragment_shader_core
.stencil_back
.ref
= back_enab
? back_ref
: front_ref
;
990 /* CAN_DISCARD should be set if the fragment shader possibly
991 * contains a 'discard' instruction. It is likely this is
992 * related to optimizations related to forward-pixel kill, as
993 * per "Mali Performance 3: Is EGL_BUFFER_PRESERVED a good
994 * thing?" by Peter Harris
997 if (variant
->can_discard
) {
998 ctx
->fragment_shader_core
.unknown2_3
|= MALI_CAN_DISCARD
;
999 ctx
->fragment_shader_core
.midgard1
.flags
|= 0x400;
1002 /* Even on MFBD, the shader descriptor gets blend shaders. It's
1003 * *also* copied to the blend_meta appended (by convention),
1004 * but this is the field actually read by the hardware. (Or
1005 * maybe both are read...?) */
1007 if (blend
[0].is_shader
) {
1008 ctx
->fragment_shader_core
.blend
.shader
=
1009 blend
[0].shader
.bo
->gpu
| blend
[0].shader
.first_tag
;
1011 ctx
->fragment_shader_core
.blend
.shader
= 0;
1014 if (screen
->require_sfbd
) {
1015 /* When only a single render target platform is used, the blend
1016 * information is inside the shader meta itself. We
1017 * additionally need to signal CAN_DISCARD for nontrivial blend
1018 * modes (so we're able to read back the destination buffer) */
1020 if (!blend
[0].is_shader
) {
1021 ctx
->fragment_shader_core
.blend
.equation
=
1022 *blend
[0].equation
.equation
;
1023 ctx
->fragment_shader_core
.blend
.constant
=
1024 blend
[0].equation
.constant
;
1027 if (!blend
[0].no_blending
) {
1028 ctx
->fragment_shader_core
.unknown2_3
|= MALI_CAN_DISCARD
;
1032 size_t size
= sizeof(struct mali_shader_meta
) + (sizeof(struct midgard_blend_rt
) * rt_count
);
1033 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, size
);
1034 memcpy(transfer
.cpu
, &ctx
->fragment_shader_core
, sizeof(struct mali_shader_meta
));
1036 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
._shader_upper
= (transfer
.gpu
) >> 4;
1038 if (!screen
->require_sfbd
) {
1039 /* Additional blend descriptor tacked on for jobs using MFBD */
1041 struct midgard_blend_rt rts
[4];
1043 for (unsigned i
= 0; i
< rt_count
; ++i
) {
1044 unsigned blend_count
= 0x200;
1046 if (blend
[i
].is_shader
) {
1047 /* For a blend shader, the bottom nibble corresponds to
1048 * the number of work registers used, which signals the
1049 * -existence- of a blend shader */
1051 assert(blend
[i
].shader
.work_count
>= 2);
1052 blend_count
|= MIN2(blend
[i
].shader
.work_count
, 3);
1054 /* Otherwise, the bottom bit simply specifies if
1055 * blending (anything other than REPLACE) is enabled */
1057 if (!blend
[i
].no_blending
)
1063 (ctx
->pipe_framebuffer
.nr_cbufs
> i
) &&
1064 (ctx
->pipe_framebuffer
.cbufs
[i
]) &&
1065 util_format_is_srgb(ctx
->pipe_framebuffer
.cbufs
[i
]->format
);
1067 rts
[i
].flags
= blend_count
;
1070 rts
[i
].flags
|= MALI_BLEND_SRGB
;
1072 if (!ctx
->blend
->base
.dither
)
1073 rts
[i
].flags
|= MALI_BLEND_NO_DITHER
;
1075 /* TODO: sRGB in blend shaders is currently
1076 * unimplemented. Contact me (Alyssa) if you're
1077 * interested in working on this. We have
1078 * native Midgard ops for helping here, but
1079 * they're not well-understood yet. */
1081 assert(!(is_srgb
&& blend
[i
].is_shader
));
1083 if (blend
[i
].is_shader
) {
1084 rts
[i
].blend
.shader
= blend
[i
].shader
.bo
->gpu
| blend
[i
].shader
.first_tag
;
1086 rts
[i
].blend
.equation
= *blend
[i
].equation
.equation
;
1087 rts
[i
].blend
.constant
= blend
[i
].equation
.constant
;
1091 memcpy(transfer
.cpu
+ sizeof(struct mali_shader_meta
), rts
, sizeof(rts
[0]) * rt_count
);
1095 /* We stage to transient, so always dirty.. */
1097 panfrost_stage_attributes(ctx
);
1099 if (ctx
->dirty
& PAN_DIRTY_SAMPLERS
)
1100 panfrost_upload_sampler_descriptors(ctx
);
1102 if (ctx
->dirty
& PAN_DIRTY_TEXTURES
)
1103 panfrost_upload_texture_descriptors(ctx
);
1105 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
1107 for (int i
= 0; i
< PIPE_SHADER_TYPES
; ++i
) {
1108 struct panfrost_shader_variants
*all
= ctx
->shader
[i
];
1113 struct panfrost_constant_buffer
*buf
= &ctx
->constant_buffer
[i
];
1115 struct panfrost_shader_state
*ss
= &all
->variants
[all
->active_variant
];
1117 panfrost_batch_add_bo(batch
, ss
->bo
);
1119 /* Uniforms are implicitly UBO #0 */
1120 bool has_uniforms
= buf
->enabled_mask
& (1 << 0);
1122 /* Allocate room for the sysval and the uniforms */
1123 size_t sys_size
= sizeof(float) * 4 * ss
->sysval_count
;
1124 size_t uniform_size
= has_uniforms
? (buf
->cb
[0].buffer_size
) : 0;
1125 size_t size
= sys_size
+ uniform_size
;
1126 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, size
);
1128 /* Upload sysvals requested by the shader */
1129 panfrost_upload_sysvals(ctx
, transfer
.cpu
, ss
, i
);
1131 /* Upload uniforms */
1133 const void *cpu
= panfrost_map_constant_buffer_cpu(buf
, 0);
1134 memcpy(transfer
.cpu
+ sys_size
, cpu
, uniform_size
);
1138 ctx
->shader
[i
]->variants
[ctx
->shader
[i
]->active_variant
].uniform_count
;
1140 struct mali_vertex_tiler_postfix
*postfix
=
1141 &ctx
->payloads
[i
].postfix
;
1143 /* Next up, attach UBOs. UBO #0 is the uniforms we just
1146 unsigned ubo_count
= panfrost_ubo_count(ctx
, i
);
1147 assert(ubo_count
>= 1);
1149 size_t sz
= sizeof(struct mali_uniform_buffer_meta
) * ubo_count
;
1150 struct mali_uniform_buffer_meta ubos
[PAN_MAX_CONST_BUFFERS
];
1152 /* Upload uniforms as a UBO */
1153 ubos
[0].size
= MALI_POSITIVE((2 + uniform_count
));
1154 ubos
[0].ptr
= transfer
.gpu
>> 2;
1156 /* The rest are honest-to-goodness UBOs */
1158 for (unsigned ubo
= 1; ubo
< ubo_count
; ++ubo
) {
1159 size_t usz
= buf
->cb
[ubo
].buffer_size
;
1161 bool enabled
= buf
->enabled_mask
& (1 << ubo
);
1162 bool empty
= usz
== 0;
1164 if (!enabled
|| empty
) {
1165 /* Stub out disabled UBOs to catch accesses */
1168 ubos
[ubo
].ptr
= 0xDEAD0000;
1172 mali_ptr gpu
= panfrost_map_constant_buffer_gpu(ctx
, buf
, ubo
);
1174 unsigned bytes_per_field
= 16;
1175 unsigned aligned
= ALIGN_POT(usz
, bytes_per_field
);
1176 unsigned fields
= aligned
/ bytes_per_field
;
1178 ubos
[ubo
].size
= MALI_POSITIVE(fields
);
1179 ubos
[ubo
].ptr
= gpu
>> 2;
1182 mali_ptr ubufs
= panfrost_upload_transient(batch
, ubos
, sz
);
1183 postfix
->uniforms
= transfer
.gpu
;
1184 postfix
->uniform_buffers
= ubufs
;
1186 buf
->dirty_mask
= 0;
1189 /* TODO: Upload the viewport somewhere more appropriate */
1191 /* Clip bounds are encoded as floats. The viewport itself is encoded as
1192 * (somewhat) asymmetric ints. */
1193 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1195 struct mali_viewport view
= {
1196 /* By default, do no viewport clipping, i.e. clip to (-inf,
1197 * inf) in each direction. Clipping to the viewport in theory
1198 * should work, but in practice causes issues when we're not
1199 * explicitly trying to scissor */
1201 .clip_minx
= -INFINITY
,
1202 .clip_miny
= -INFINITY
,
1203 .clip_maxx
= INFINITY
,
1204 .clip_maxy
= INFINITY
,
1207 /* Always scissor to the viewport by default. */
1208 float vp_minx
= (int) (vp
->translate
[0] - fabsf(vp
->scale
[0]));
1209 float vp_maxx
= (int) (vp
->translate
[0] + fabsf(vp
->scale
[0]));
1211 float vp_miny
= (int) (vp
->translate
[1] - fabsf(vp
->scale
[1]));
1212 float vp_maxy
= (int) (vp
->translate
[1] + fabsf(vp
->scale
[1]));
1214 float minz
= (vp
->translate
[2] - fabsf(vp
->scale
[2]));
1215 float maxz
= (vp
->translate
[2] + fabsf(vp
->scale
[2]));
1217 /* Apply the scissor test */
1219 unsigned minx
, miny
, maxx
, maxy
;
1221 if (ss
&& ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
) {
1222 minx
= MAX2(ss
->minx
, vp_minx
);
1223 miny
= MAX2(ss
->miny
, vp_miny
);
1224 maxx
= MIN2(ss
->maxx
, vp_maxx
);
1225 maxy
= MIN2(ss
->maxy
, vp_maxy
);
1233 /* Hardware needs the min/max to be strictly ordered, so flip if we
1234 * need to. The viewport transformation in the vertex shader will
1235 * handle the negatives if we don't */
1238 unsigned temp
= miny
;
1244 unsigned temp
= minx
;
1255 /* Clamp to the framebuffer size as a last check */
1257 minx
= MIN2(ctx
->pipe_framebuffer
.width
, minx
);
1258 maxx
= MIN2(ctx
->pipe_framebuffer
.width
, maxx
);
1260 miny
= MIN2(ctx
->pipe_framebuffer
.height
, miny
);
1261 maxy
= MIN2(ctx
->pipe_framebuffer
.height
, maxy
);
1263 /* Update the job, unless we're doing wallpapering (whose lack of
1264 * scissor we can ignore, since if we "miss" a tile of wallpaper, it'll
1265 * just... be faster :) */
1267 if (!ctx
->wallpaper_batch
)
1268 panfrost_batch_union_scissor(batch
, minx
, miny
, maxx
, maxy
);
1272 view
.viewport0
[0] = minx
;
1273 view
.viewport1
[0] = MALI_POSITIVE(maxx
);
1275 view
.viewport0
[1] = miny
;
1276 view
.viewport1
[1] = MALI_POSITIVE(maxy
);
1278 view
.clip_minz
= minz
;
1279 view
.clip_maxz
= maxz
;
1281 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.viewport
=
1282 panfrost_upload_transient(batch
,
1284 sizeof(struct mali_viewport
));
1289 /* Corresponds to exactly one draw, but does not submit anything */
1292 panfrost_queue_draw(struct panfrost_context
*ctx
)
1294 /* Handle dirty flags now */
1295 panfrost_emit_for_draw(ctx
, true);
1297 /* If rasterizer discard is enable, only submit the vertex */
1299 bool rasterizer_discard
= ctx
->rasterizer
1300 && ctx
->rasterizer
->base
.rasterizer_discard
;
1302 struct panfrost_transfer vertex
= panfrost_vertex_tiler_job(ctx
, false);
1303 struct panfrost_transfer tiler
;
1305 if (!rasterizer_discard
)
1306 tiler
= panfrost_vertex_tiler_job(ctx
, true);
1308 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1310 if (rasterizer_discard
)
1311 panfrost_scoreboard_queue_vertex_job(batch
, vertex
, FALSE
);
1312 else if (ctx
->wallpaper_batch
)
1313 panfrost_scoreboard_queue_fused_job_prepend(batch
, vertex
, tiler
);
1315 panfrost_scoreboard_queue_fused_job(batch
, vertex
, tiler
);
1318 /* The entire frame is in memory -- send it off to the kernel! */
1322 struct pipe_context
*pipe
,
1323 struct pipe_fence_handle
**fence
,
1326 struct panfrost_context
*ctx
= pan_context(pipe
);
1327 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1329 /* Submit the frame itself */
1330 panfrost_batch_submit(batch
);
1333 struct panfrost_fence
*f
= panfrost_fence_create(ctx
);
1334 pipe
->screen
->fence_reference(pipe
->screen
, fence
, NULL
);
1335 *fence
= (struct pipe_fence_handle
*)f
;
1339 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
1342 g2m_draw_mode(enum pipe_prim_type mode
)
1345 DEFINE_CASE(POINTS
);
1347 DEFINE_CASE(LINE_LOOP
);
1348 DEFINE_CASE(LINE_STRIP
);
1349 DEFINE_CASE(TRIANGLES
);
1350 DEFINE_CASE(TRIANGLE_STRIP
);
1351 DEFINE_CASE(TRIANGLE_FAN
);
1353 DEFINE_CASE(QUAD_STRIP
);
1354 DEFINE_CASE(POLYGON
);
1357 unreachable("Invalid draw mode");
1364 panfrost_translate_index_size(unsigned size
)
1368 return MALI_DRAW_INDEXED_UINT8
;
1371 return MALI_DRAW_INDEXED_UINT16
;
1374 return MALI_DRAW_INDEXED_UINT32
;
1377 unreachable("Invalid index size");
1381 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
1382 * good for the duration of the draw (transient), could last longer */
1385 panfrost_get_index_buffer_mapped(struct panfrost_context
*ctx
, const struct pipe_draw_info
*info
)
1387 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
1389 off_t offset
= info
->start
* info
->index_size
;
1390 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1392 if (!info
->has_user_indices
) {
1393 /* Only resources can be directly mapped */
1394 panfrost_batch_add_bo(batch
, rsrc
->bo
);
1395 return rsrc
->bo
->gpu
+ offset
;
1397 /* Otherwise, we need to upload to transient memory */
1398 const uint8_t *ibuf8
= (const uint8_t *) info
->index
.user
;
1399 return panfrost_upload_transient(batch
, ibuf8
+ offset
, info
->count
* info
->index_size
);
1404 panfrost_scissor_culls_everything(struct panfrost_context
*ctx
)
1406 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1408 /* Check if we're scissoring at all */
1410 if (!(ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
))
1413 return (ss
->minx
== ss
->maxx
) || (ss
->miny
== ss
->maxy
);
1416 /* Count generated primitives (when there is no geom/tess shaders) for
1417 * transform feedback */
1420 panfrost_statistics_record(
1421 struct panfrost_context
*ctx
,
1422 const struct pipe_draw_info
*info
)
1424 if (!ctx
->active_queries
)
1427 uint32_t prims
= u_prims_for_vertices(info
->mode
, info
->count
);
1428 ctx
->prims_generated
+= prims
;
1430 if (!ctx
->streamout
.num_targets
)
1433 ctx
->tf_prims_generated
+= prims
;
1438 struct pipe_context
*pipe
,
1439 const struct pipe_draw_info
*info
)
1441 struct panfrost_context
*ctx
= pan_context(pipe
);
1443 /* First of all, check the scissor to see if anything is drawn at all.
1444 * If it's not, we drop the draw (mostly a conformance issue;
1445 * well-behaved apps shouldn't hit this) */
1447 if (panfrost_scissor_culls_everything(ctx
))
1450 int mode
= info
->mode
;
1452 /* Fallback unsupported restart index */
1453 unsigned primitive_index
= (1 << (info
->index_size
* 8)) - 1;
1455 if (info
->primitive_restart
&& info
->index_size
1456 && info
->restart_index
!= primitive_index
) {
1457 util_draw_vbo_without_prim_restart(pipe
, info
);
1461 /* Fallback for unsupported modes */
1463 assert(ctx
->rasterizer
!= NULL
);
1465 if (!(ctx
->draw_modes
& (1 << mode
))) {
1466 if (mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && !ctx
->rasterizer
->base
.flatshade
) {
1467 mode
= PIPE_PRIM_TRIANGLE_FAN
;
1469 if (info
->count
< 4) {
1470 /* Degenerate case? */
1474 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
1475 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
1480 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= info
->start
;
1481 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= info
->start
;
1483 /* Now that we have a guaranteed terminating path, find the job.
1484 * Assignment commented out to prevent unused warning */
1486 /* struct panfrost_batch *batch = */ panfrost_get_batch_for_fbo(ctx
);
1488 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
= g2m_draw_mode(mode
);
1490 /* Take into account a negative bias */
1491 ctx
->vertex_count
= info
->count
+ abs(info
->index_bias
);
1492 ctx
->instance_count
= info
->instance_count
;
1493 ctx
->active_prim
= info
->mode
;
1495 /* For non-indexed draws, they're the same */
1496 unsigned vertex_count
= ctx
->vertex_count
;
1498 unsigned draw_flags
= 0;
1500 /* The draw flags interpret how primitive size is interpreted */
1502 if (panfrost_writes_point_size(ctx
))
1503 draw_flags
|= MALI_DRAW_VARYING_SIZE
;
1505 if (info
->primitive_restart
)
1506 draw_flags
|= MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX
;
1508 /* For higher amounts of vertices (greater than what fits in a 16-bit
1509 * short), the other value is needed, otherwise there will be bizarre
1510 * rendering artefacts. It's not clear what these values mean yet. This
1511 * change is also needed for instancing and sometimes points (perhaps
1512 * related to dynamically setting gl_PointSize) */
1514 bool is_points
= mode
== PIPE_PRIM_POINTS
;
1515 bool many_verts
= ctx
->vertex_count
> 0xFFFF;
1516 bool instanced
= ctx
->instance_count
> 1;
1518 draw_flags
|= (is_points
|| many_verts
|| instanced
) ? 0x3000 : 0x18000;
1520 /* This doesn't make much sense */
1521 if (mode
== PIPE_PRIM_LINE_STRIP
) {
1522 draw_flags
|= 0x800;
1525 panfrost_statistics_record(ctx
, info
);
1527 if (info
->index_size
) {
1528 /* Calculate the min/max index used so we can figure out how
1529 * many times to invoke the vertex shader */
1531 /* Fetch / calculate index bounds */
1532 unsigned min_index
= 0, max_index
= 0;
1534 if (info
->max_index
== ~0u) {
1535 u_vbuf_get_minmax_index(pipe
, info
, &min_index
, &max_index
);
1537 min_index
= info
->min_index
;
1538 max_index
= info
->max_index
;
1541 /* Use the corresponding values */
1542 vertex_count
= max_index
- min_index
+ 1;
1543 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= min_index
+ info
->index_bias
;
1544 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= min_index
+ info
->index_bias
;
1546 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= -min_index
;
1547 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(info
->count
);
1549 //assert(!info->restart_index); /* TODO: Research */
1551 draw_flags
|= panfrost_translate_index_size(info
->index_size
);
1552 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
= panfrost_get_index_buffer_mapped(ctx
, info
);
1554 /* Index count == vertex count, if no indexing is applied, as
1555 * if it is internally indexed in the expected order */
1557 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= 0;
1558 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(ctx
->vertex_count
);
1560 /* Reverse index state */
1561 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
= (u64
) NULL
;
1564 /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
1565 * vertex_count, 1) */
1567 panfrost_pack_work_groups_fused(
1568 &ctx
->payloads
[PIPE_SHADER_VERTEX
].prefix
,
1569 &ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
,
1570 1, vertex_count
, info
->instance_count
,
1573 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.unknown_draw
= draw_flags
;
1575 /* Encode the padded vertex count */
1577 if (info
->instance_count
> 1) {
1578 /* Triangles have non-even vertex counts so they change how
1579 * padding works internally */
1582 mode
== PIPE_PRIM_TRIANGLES
||
1583 mode
== PIPE_PRIM_TRIANGLE_STRIP
||
1584 mode
== PIPE_PRIM_TRIANGLE_FAN
;
1586 struct pan_shift_odd so
=
1587 panfrost_padded_vertex_count(vertex_count
, !is_triangle
);
1589 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= so
.shift
;
1590 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= so
.shift
;
1592 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= so
.odd
;
1593 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= so
.odd
;
1595 ctx
->padded_count
= pan_expand_shift_odd(so
);
1597 ctx
->padded_count
= ctx
->vertex_count
;
1599 /* Reset instancing state */
1600 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= 0;
1601 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= 0;
1602 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= 0;
1603 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= 0;
1606 /* Fire off the draw itself */
1607 panfrost_queue_draw(ctx
);
1609 /* Increment transform feedback offsets */
1611 for (unsigned i
= 0; i
< ctx
->streamout
.num_targets
; ++i
) {
1612 unsigned output_count
= u_stream_outputs_for_vertices(
1613 ctx
->active_prim
, ctx
->vertex_count
);
1615 ctx
->streamout
.offsets
[i
] += output_count
;
1622 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
1628 panfrost_create_rasterizer_state(
1629 struct pipe_context
*pctx
,
1630 const struct pipe_rasterizer_state
*cso
)
1632 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
1636 /* Bitmask, unknown meaning of the start value. 0x105 on 32-bit T6XX */
1637 so
->tiler_gl_enables
= 0x7;
1640 so
->tiler_gl_enables
|= MALI_FRONT_CCW_TOP
;
1642 if (cso
->cull_face
& PIPE_FACE_FRONT
)
1643 so
->tiler_gl_enables
|= MALI_CULL_FACE_FRONT
;
1645 if (cso
->cull_face
& PIPE_FACE_BACK
)
1646 so
->tiler_gl_enables
|= MALI_CULL_FACE_BACK
;
1652 panfrost_bind_rasterizer_state(
1653 struct pipe_context
*pctx
,
1656 struct panfrost_context
*ctx
= pan_context(pctx
);
1658 /* TODO: Why can't rasterizer be NULL ever? Other drivers are fine.. */
1662 ctx
->rasterizer
= hwcso
;
1663 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
1665 ctx
->fragment_shader_core
.depth_units
= ctx
->rasterizer
->base
.offset_units
;
1666 ctx
->fragment_shader_core
.depth_factor
= ctx
->rasterizer
->base
.offset_scale
;
1668 /* Gauranteed with the core GL call, so don't expose ARB_polygon_offset */
1669 assert(ctx
->rasterizer
->base
.offset_clamp
== 0.0);
1671 /* XXX: Which bit is which? Does this maybe allow offseting not-tri? */
1673 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_DEPTH_RANGE_A
, ctx
->rasterizer
->base
.offset_tri
);
1674 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_DEPTH_RANGE_B
, ctx
->rasterizer
->base
.offset_tri
);
1676 /* Point sprites are emulated */
1678 struct panfrost_shader_state
*variant
=
1679 ctx
->shader
[PIPE_SHADER_FRAGMENT
] ? &ctx
->shader
[PIPE_SHADER_FRAGMENT
]->variants
[ctx
->shader
[PIPE_SHADER_FRAGMENT
]->active_variant
] : NULL
;
1681 if (ctx
->rasterizer
->base
.sprite_coord_enable
|| (variant
&& variant
->point_sprite_mask
))
1682 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
1686 panfrost_create_vertex_elements_state(
1687 struct pipe_context
*pctx
,
1688 unsigned num_elements
,
1689 const struct pipe_vertex_element
*elements
)
1691 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
1693 so
->num_elements
= num_elements
;
1694 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
1696 for (int i
= 0; i
< num_elements
; ++i
) {
1697 so
->hw
[i
].index
= i
;
1699 enum pipe_format fmt
= elements
[i
].src_format
;
1700 const struct util_format_description
*desc
= util_format_description(fmt
);
1701 so
->hw
[i
].unknown1
= 0x2;
1702 so
->hw
[i
].swizzle
= panfrost_get_default_swizzle(desc
->nr_channels
);
1704 so
->hw
[i
].format
= panfrost_find_format(desc
);
1706 /* The field itself should probably be shifted over */
1707 so
->hw
[i
].src_offset
= elements
[i
].src_offset
;
1714 panfrost_bind_vertex_elements_state(
1715 struct pipe_context
*pctx
,
1718 struct panfrost_context
*ctx
= pan_context(pctx
);
1720 ctx
->vertex
= hwcso
;
1721 ctx
->dirty
|= PAN_DIRTY_VERTEX
;
1725 panfrost_create_shader_state(
1726 struct pipe_context
*pctx
,
1727 const struct pipe_shader_state
*cso
)
1729 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
1732 /* Token deep copy to prevent memory corruption */
1734 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
1735 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
1741 panfrost_delete_shader_state(
1742 struct pipe_context
*pctx
,
1745 struct panfrost_shader_variants
*cso
= (struct panfrost_shader_variants
*) so
;
1747 if (cso
->base
.type
== PIPE_SHADER_IR_TGSI
) {
1748 DBG("Deleting TGSI shader leaks duplicated tokens\n");
1751 for (unsigned i
= 0; i
< cso
->variant_count
; ++i
) {
1752 struct panfrost_shader_state
*shader_state
= &cso
->variants
[i
];
1753 panfrost_bo_unreference(pctx
->screen
, shader_state
->bo
);
1754 shader_state
->bo
= NULL
;
1761 panfrost_create_sampler_state(
1762 struct pipe_context
*pctx
,
1763 const struct pipe_sampler_state
*cso
)
1765 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
1768 /* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
1770 bool min_nearest
= cso
->min_img_filter
== PIPE_TEX_FILTER_NEAREST
;
1771 bool mag_nearest
= cso
->mag_img_filter
== PIPE_TEX_FILTER_NEAREST
;
1772 bool mip_linear
= cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_LINEAR
;
1774 unsigned min_filter
= min_nearest
? MALI_SAMP_MIN_NEAREST
: 0;
1775 unsigned mag_filter
= mag_nearest
? MALI_SAMP_MAG_NEAREST
: 0;
1776 unsigned mip_filter
= mip_linear
?
1777 (MALI_SAMP_MIP_LINEAR_1
| MALI_SAMP_MIP_LINEAR_2
) : 0;
1778 unsigned normalized
= cso
->normalized_coords
? MALI_SAMP_NORM_COORDS
: 0;
1780 struct mali_sampler_descriptor sampler_descriptor
= {
1781 .filter_mode
= min_filter
| mag_filter
| mip_filter
| normalized
,
1782 .wrap_s
= translate_tex_wrap(cso
->wrap_s
),
1783 .wrap_t
= translate_tex_wrap(cso
->wrap_t
),
1784 .wrap_r
= translate_tex_wrap(cso
->wrap_r
),
1785 .compare_func
= panfrost_translate_alt_compare_func(cso
->compare_func
),
1787 cso
->border_color
.f
[0],
1788 cso
->border_color
.f
[1],
1789 cso
->border_color
.f
[2],
1790 cso
->border_color
.f
[3]
1792 .min_lod
= FIXED_16(cso
->min_lod
),
1793 .max_lod
= FIXED_16(cso
->max_lod
),
1794 .seamless_cube_map
= cso
->seamless_cube_map
,
1797 /* If necessary, we disable mipmapping in the sampler descriptor by
1798 * clamping the LOD as tight as possible (from 0 to epsilon,
1799 * essentially -- remember these are fixed point numbers, so
1802 if (cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
)
1803 sampler_descriptor
.max_lod
= sampler_descriptor
.min_lod
;
1805 /* Enforce that there is something in the middle by adding epsilon*/
1807 if (sampler_descriptor
.min_lod
== sampler_descriptor
.max_lod
)
1808 sampler_descriptor
.max_lod
++;
1811 assert(sampler_descriptor
.max_lod
> sampler_descriptor
.min_lod
);
1813 so
->hw
= sampler_descriptor
;
1819 panfrost_bind_sampler_states(
1820 struct pipe_context
*pctx
,
1821 enum pipe_shader_type shader
,
1822 unsigned start_slot
, unsigned num_sampler
,
1825 assert(start_slot
== 0);
1827 struct panfrost_context
*ctx
= pan_context(pctx
);
1829 /* XXX: Should upload, not just copy? */
1830 ctx
->sampler_count
[shader
] = num_sampler
;
1831 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
1833 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
;
1837 panfrost_variant_matches(
1838 struct panfrost_context
*ctx
,
1839 struct panfrost_shader_state
*variant
,
1840 enum pipe_shader_type type
)
1842 struct pipe_rasterizer_state
*rasterizer
= &ctx
->rasterizer
->base
;
1843 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
1845 bool is_fragment
= (type
== PIPE_SHADER_FRAGMENT
);
1847 if (is_fragment
&& (alpha
->enabled
|| variant
->alpha_state
.enabled
)) {
1848 /* Make sure enable state is at least the same */
1849 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
1853 /* Check that the contents of the test are the same */
1854 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
1855 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
1857 if (!(same_func
&& same_ref
)) {
1862 if (is_fragment
&& rasterizer
&& (rasterizer
->sprite_coord_enable
|
1863 variant
->point_sprite_mask
)) {
1864 /* Ensure the same varyings are turned to point sprites */
1865 if (rasterizer
->sprite_coord_enable
!= variant
->point_sprite_mask
)
1868 /* Ensure the orientation is correct */
1870 rasterizer
->sprite_coord_mode
==
1871 PIPE_SPRITE_COORD_UPPER_LEFT
;
1873 if (variant
->point_sprite_upper_left
!= upper_left
)
1877 /* Otherwise, we're good to go */
1882 * Fix an uncompiled shader's stream output info, and produce a bitmask
1883 * of which VARYING_SLOT_* are captured for stream output.
1885 * Core Gallium stores output->register_index as a "slot" number, where
1886 * slots are assigned consecutively to all outputs in info->outputs_written.
1887 * This naive packing of outputs doesn't work for us - we too have slots,
1888 * but the layout is defined by the VUE map, which we won't have until we
1889 * compile a specific shader variant. So, we remap these and simply store
1890 * VARYING_SLOT_* in our copy's output->register_index fields.
1892 * We then produce a bitmask of outputs which are used for SO.
1894 * Implementation from iris.
1898 update_so_info(struct pipe_stream_output_info
*so_info
,
1899 uint64_t outputs_written
)
1901 uint64_t so_outputs
= 0;
1902 uint8_t reverse_map
[64] = {};
1905 while (outputs_written
)
1906 reverse_map
[slot
++] = u_bit_scan64(&outputs_written
);
1908 for (unsigned i
= 0; i
< so_info
->num_outputs
; i
++) {
1909 struct pipe_stream_output
*output
= &so_info
->output
[i
];
1911 /* Map Gallium's condensed "slots" back to real VARYING_SLOT_* enums */
1912 output
->register_index
= reverse_map
[output
->register_index
];
1914 so_outputs
|= 1ull << output
->register_index
;
1921 panfrost_bind_shader_state(
1922 struct pipe_context
*pctx
,
1924 enum pipe_shader_type type
)
1926 struct panfrost_context
*ctx
= pan_context(pctx
);
1928 ctx
->shader
[type
] = hwcso
;
1930 if (type
== PIPE_SHADER_FRAGMENT
)
1931 ctx
->dirty
|= PAN_DIRTY_FS
;
1933 ctx
->dirty
|= PAN_DIRTY_VS
;
1937 /* Match the appropriate variant */
1939 signed variant
= -1;
1940 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
1942 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
1943 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
], type
)) {
1949 if (variant
== -1) {
1950 /* No variant matched, so create a new one */
1951 variant
= variants
->variant_count
++;
1952 assert(variants
->variant_count
< MAX_SHADER_VARIANTS
);
1954 struct panfrost_shader_state
*v
=
1955 &variants
->variants
[variant
];
1957 if (type
== PIPE_SHADER_FRAGMENT
) {
1958 v
->alpha_state
= ctx
->depth_stencil
->alpha
;
1960 if (ctx
->rasterizer
) {
1961 v
->point_sprite_mask
= ctx
->rasterizer
->base
.sprite_coord_enable
;
1962 v
->point_sprite_upper_left
=
1963 ctx
->rasterizer
->base
.sprite_coord_mode
==
1964 PIPE_SPRITE_COORD_UPPER_LEFT
;
1968 variants
->variants
[variant
].tripipe
= calloc(1, sizeof(struct mali_shader_meta
));
1972 /* Select this variant */
1973 variants
->active_variant
= variant
;
1975 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
1976 assert(panfrost_variant_matches(ctx
, shader_state
, type
));
1978 /* We finally have a variant, so compile it */
1980 if (!shader_state
->compiled
) {
1981 uint64_t outputs_written
= 0;
1983 panfrost_shader_compile(ctx
, shader_state
->tripipe
,
1984 variants
->base
.type
,
1985 variants
->base
.type
== PIPE_SHADER_IR_NIR
?
1986 variants
->base
.ir
.nir
:
1987 variants
->base
.tokens
,
1988 tgsi_processor_to_shader_stage(type
), shader_state
,
1991 shader_state
->compiled
= true;
1993 /* Fixup the stream out information, since what Gallium returns
1994 * normally is mildly insane */
1996 shader_state
->stream_output
= variants
->base
.stream_output
;
1997 shader_state
->so_mask
=
1998 update_so_info(&shader_state
->stream_output
, outputs_written
);
2003 panfrost_bind_vs_state(struct pipe_context
*pctx
, void *hwcso
)
2005 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
2009 panfrost_bind_fs_state(struct pipe_context
*pctx
, void *hwcso
)
2011 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
2015 panfrost_set_vertex_buffers(
2016 struct pipe_context
*pctx
,
2017 unsigned start_slot
,
2018 unsigned num_buffers
,
2019 const struct pipe_vertex_buffer
*buffers
)
2021 struct panfrost_context
*ctx
= pan_context(pctx
);
2023 util_set_vertex_buffers_mask(ctx
->vertex_buffers
, &ctx
->vb_mask
, buffers
, start_slot
, num_buffers
);
2027 panfrost_set_constant_buffer(
2028 struct pipe_context
*pctx
,
2029 enum pipe_shader_type shader
, uint index
,
2030 const struct pipe_constant_buffer
*buf
)
2032 struct panfrost_context
*ctx
= pan_context(pctx
);
2033 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
2035 util_copy_constant_buffer(&pbuf
->cb
[index
], buf
);
2037 unsigned mask
= (1 << index
);
2039 if (unlikely(!buf
)) {
2040 pbuf
->enabled_mask
&= ~mask
;
2041 pbuf
->dirty_mask
&= ~mask
;
2045 pbuf
->enabled_mask
|= mask
;
2046 pbuf
->dirty_mask
|= mask
;
2050 panfrost_set_stencil_ref(
2051 struct pipe_context
*pctx
,
2052 const struct pipe_stencil_ref
*ref
)
2054 struct panfrost_context
*ctx
= pan_context(pctx
);
2055 ctx
->stencil_ref
= *ref
;
2057 /* Shader core dirty */
2058 ctx
->dirty
|= PAN_DIRTY_FS
;
2061 static enum mali_texture_type
2062 panfrost_translate_texture_type(enum pipe_texture_target t
) {
2066 case PIPE_TEXTURE_1D
:
2067 case PIPE_TEXTURE_1D_ARRAY
:
2070 case PIPE_TEXTURE_2D
:
2071 case PIPE_TEXTURE_2D_ARRAY
:
2072 case PIPE_TEXTURE_RECT
:
2075 case PIPE_TEXTURE_3D
:
2078 case PIPE_TEXTURE_CUBE
:
2079 case PIPE_TEXTURE_CUBE_ARRAY
:
2080 return MALI_TEX_CUBE
;
2083 unreachable("Unknown target");
2087 static struct pipe_sampler_view
*
2088 panfrost_create_sampler_view(
2089 struct pipe_context
*pctx
,
2090 struct pipe_resource
*texture
,
2091 const struct pipe_sampler_view
*template)
2093 struct panfrost_sampler_view
*so
= rzalloc(pctx
, struct panfrost_sampler_view
);
2094 int bytes_per_pixel
= util_format_get_blocksize(texture
->format
);
2096 pipe_reference(NULL
, &texture
->reference
);
2098 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
2101 so
->base
= *template;
2102 so
->base
.texture
= texture
;
2103 so
->base
.reference
.count
= 1;
2104 so
->base
.context
= pctx
;
2106 /* sampler_views correspond to texture descriptors, minus the texture
2107 * (data) itself. So, we serialise the descriptor here and cache it for
2110 const struct util_format_description
*desc
= util_format_description(prsrc
->base
.format
);
2112 unsigned char user_swizzle
[4] = {
2113 template->swizzle_r
,
2114 template->swizzle_g
,
2115 template->swizzle_b
,
2119 enum mali_format format
= panfrost_find_format(desc
);
2121 /* Check if we need to set a custom stride by computing the "expected"
2122 * stride and comparing it to what the BO actually wants. Only applies
2123 * to linear textures, since tiled/compressed textures have strict
2124 * alignment requirements for their strides as it is */
2126 unsigned first_level
= template->u
.tex
.first_level
;
2127 unsigned last_level
= template->u
.tex
.last_level
;
2129 if (prsrc
->layout
== PAN_LINEAR
) {
2130 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
2131 unsigned actual_stride
= prsrc
->slices
[l
].stride
;
2132 unsigned width
= u_minify(texture
->width0
, l
);
2133 unsigned comp_stride
= width
* bytes_per_pixel
;
2135 if (comp_stride
!= actual_stride
) {
2136 so
->manual_stride
= true;
2142 /* In the hardware, array_size refers specifically to array textures,
2143 * whereas in Gallium, it also covers cubemaps */
2145 unsigned array_size
= texture
->array_size
;
2147 if (template->target
== PIPE_TEXTURE_CUBE
) {
2148 /* TODO: Cubemap arrays */
2149 assert(array_size
== 6);
2153 struct mali_texture_descriptor texture_descriptor
= {
2154 .width
= MALI_POSITIVE(u_minify(texture
->width0
, first_level
)),
2155 .height
= MALI_POSITIVE(u_minify(texture
->height0
, first_level
)),
2156 .depth
= MALI_POSITIVE(u_minify(texture
->depth0
, first_level
)),
2157 .array_size
= MALI_POSITIVE(array_size
),
2160 .swizzle
= panfrost_translate_swizzle_4(desc
->swizzle
),
2162 .srgb
= desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
,
2163 .type
= panfrost_translate_texture_type(template->target
),
2167 .swizzle
= panfrost_translate_swizzle_4(user_swizzle
)
2170 texture_descriptor
.levels
= last_level
- first_level
;
2172 so
->hw
= texture_descriptor
;
2174 return (struct pipe_sampler_view
*) so
;
2178 panfrost_set_sampler_views(
2179 struct pipe_context
*pctx
,
2180 enum pipe_shader_type shader
,
2181 unsigned start_slot
, unsigned num_views
,
2182 struct pipe_sampler_view
**views
)
2184 struct panfrost_context
*ctx
= pan_context(pctx
);
2186 assert(start_slot
== 0);
2188 unsigned new_nr
= 0;
2189 for (unsigned i
= 0; i
< num_views
; ++i
) {
2194 ctx
->sampler_view_count
[shader
] = new_nr
;
2195 memcpy(ctx
->sampler_views
[shader
], views
, num_views
* sizeof (void *));
2197 ctx
->dirty
|= PAN_DIRTY_TEXTURES
;
2201 panfrost_sampler_view_destroy(
2202 struct pipe_context
*pctx
,
2203 struct pipe_sampler_view
*view
)
2205 pipe_resource_reference(&view
->texture
, NULL
);
2210 panfrost_set_shader_buffers(
2211 struct pipe_context
*pctx
,
2212 enum pipe_shader_type shader
,
2213 unsigned start
, unsigned count
,
2214 const struct pipe_shader_buffer
*buffers
,
2215 unsigned writable_bitmask
)
2217 struct panfrost_context
*ctx
= pan_context(pctx
);
2219 util_set_shader_buffers_mask(ctx
->ssbo
[shader
], &ctx
->ssbo_mask
[shader
],
2220 buffers
, start
, count
);
2223 /* Hints that a framebuffer should use AFBC where possible */
2227 struct panfrost_screen
*screen
,
2228 const struct pipe_framebuffer_state
*fb
)
2230 /* AFBC implemenation incomplete; hide it */
2231 if (!(pan_debug
& PAN_DBG_AFBC
)) return;
2233 /* Hint AFBC to the resources bound to each color buffer */
2235 for (unsigned i
= 0; i
< fb
->nr_cbufs
; ++i
) {
2236 struct pipe_surface
*surf
= fb
->cbufs
[i
];
2237 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
2238 panfrost_resource_hint_layout(screen
, rsrc
, PAN_AFBC
, 1);
2241 /* Also hint it to the depth buffer */
2244 struct panfrost_resource
*rsrc
= pan_resource(fb
->zsbuf
->texture
);
2245 panfrost_resource_hint_layout(screen
, rsrc
, PAN_AFBC
, 1);
2250 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
2251 const struct pipe_framebuffer_state
*fb
)
2253 struct panfrost_context
*ctx
= pan_context(pctx
);
2255 /* Flush when switching framebuffers, but not if the framebuffer
2256 * state is being restored by u_blitter
2259 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
2260 bool is_scanout
= panfrost_batch_is_scanout(batch
);
2261 bool has_draws
= batch
->last_job
.gpu
;
2263 /* Bail out early when the current and new states are the same. */
2264 if (util_framebuffer_state_equal(&ctx
->pipe_framebuffer
, fb
))
2267 /* The wallpaper logic sets a new FB state before doing the blit and
2268 * restore the old one when it's done. Those FB states are reported to
2269 * be different because the surface they are pointing to are different,
2270 * but those surfaces actually point to the same cbufs/zbufs. In that
2271 * case we definitely don't want new FB descs to be emitted/attached
2272 * since the job is expected to be flushed just after the blit is done,
2273 * so let's just copy the new state and return here.
2275 if (ctx
->wallpaper_batch
) {
2276 util_copy_framebuffer_state(&ctx
->pipe_framebuffer
, fb
);
2280 if (!is_scanout
|| has_draws
)
2281 panfrost_flush(pctx
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2283 assert(!ctx
->payloads
[PIPE_SHADER_VERTEX
].postfix
.framebuffer
&&
2284 !ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.framebuffer
);
2286 /* Invalidate the FBO job cache since we've just been assigned a new
2291 util_copy_framebuffer_state(&ctx
->pipe_framebuffer
, fb
);
2293 /* Given that we're rendering, we'd love to have compression */
2294 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
2296 panfrost_hint_afbc(screen
, &ctx
->pipe_framebuffer
);
2297 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
2298 ctx
->payloads
[i
].postfix
.framebuffer
= 0;
2302 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
2303 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
2305 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
2309 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
2312 struct panfrost_context
*ctx
= pan_context(pipe
);
2313 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
2314 ctx
->depth_stencil
= depth_stencil
;
2319 /* Alpha does not exist in the hardware (it's not in ES3), so it's
2320 * emulated in the fragment shader */
2322 if (depth_stencil
->alpha
.enabled
) {
2323 /* We need to trigger a new shader (maybe) */
2324 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
2328 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_STENCIL_TEST
, depth_stencil
->stencil
[0].enabled
);
2330 panfrost_make_stencil_state(&depth_stencil
->stencil
[0], &ctx
->fragment_shader_core
.stencil_front
);
2331 ctx
->fragment_shader_core
.stencil_mask_front
= depth_stencil
->stencil
[0].writemask
;
2333 /* If back-stencil is not enabled, use the front values */
2334 bool back_enab
= ctx
->depth_stencil
->stencil
[1].enabled
;
2335 unsigned back_index
= back_enab
? 1 : 0;
2337 panfrost_make_stencil_state(&depth_stencil
->stencil
[back_index
], &ctx
->fragment_shader_core
.stencil_back
);
2338 ctx
->fragment_shader_core
.stencil_mask_back
= depth_stencil
->stencil
[back_index
].writemask
;
2340 /* Depth state (TODO: Refactor) */
2341 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_DEPTH_TEST
, depth_stencil
->depth
.enabled
);
2343 int func
= depth_stencil
->depth
.enabled
? depth_stencil
->depth
.func
: PIPE_FUNC_ALWAYS
;
2345 ctx
->fragment_shader_core
.unknown2_3
&= ~MALI_DEPTH_FUNC_MASK
;
2346 ctx
->fragment_shader_core
.unknown2_3
|= MALI_DEPTH_FUNC(panfrost_translate_compare_func(func
));
2348 /* Bounds test not implemented */
2349 assert(!depth_stencil
->depth
.bounds_test
);
2351 ctx
->dirty
|= PAN_DIRTY_FS
;
2355 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
2361 panfrost_set_sample_mask(struct pipe_context
*pipe
,
2362 unsigned sample_mask
)
2367 panfrost_set_clip_state(struct pipe_context
*pipe
,
2368 const struct pipe_clip_state
*clip
)
2370 //struct panfrost_context *panfrost = pan_context(pipe);
2374 panfrost_set_viewport_states(struct pipe_context
*pipe
,
2375 unsigned start_slot
,
2376 unsigned num_viewports
,
2377 const struct pipe_viewport_state
*viewports
)
2379 struct panfrost_context
*ctx
= pan_context(pipe
);
2381 assert(start_slot
== 0);
2382 assert(num_viewports
== 1);
2384 ctx
->pipe_viewport
= *viewports
;
2388 panfrost_set_scissor_states(struct pipe_context
*pipe
,
2389 unsigned start_slot
,
2390 unsigned num_scissors
,
2391 const struct pipe_scissor_state
*scissors
)
2393 struct panfrost_context
*ctx
= pan_context(pipe
);
2395 assert(start_slot
== 0);
2396 assert(num_scissors
== 1);
2398 ctx
->scissor
= *scissors
;
2402 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
2403 const struct pipe_poly_stipple
*stipple
)
2405 //struct panfrost_context *panfrost = pan_context(pipe);
2409 panfrost_set_active_query_state(struct pipe_context
*pipe
,
2412 struct panfrost_context
*ctx
= pan_context(pipe
);
2413 ctx
->active_queries
= enable
;
2417 panfrost_destroy(struct pipe_context
*pipe
)
2419 struct panfrost_context
*panfrost
= pan_context(pipe
);
2420 struct panfrost_screen
*screen
= pan_screen(pipe
->screen
);
2422 if (panfrost
->blitter
)
2423 util_blitter_destroy(panfrost
->blitter
);
2425 if (panfrost
->blitter_wallpaper
)
2426 util_blitter_destroy(panfrost
->blitter_wallpaper
);
2428 panfrost_bo_release(screen
, panfrost
->scratchpad
, false);
2429 panfrost_bo_release(screen
, panfrost
->tiler_heap
, false);
2430 panfrost_bo_release(screen
, panfrost
->tiler_dummy
, false);
2435 static struct pipe_query
*
2436 panfrost_create_query(struct pipe_context
*pipe
,
2440 struct panfrost_query
*q
= rzalloc(pipe
, struct panfrost_query
);
2445 return (struct pipe_query
*) q
;
2449 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2455 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2457 struct panfrost_context
*ctx
= pan_context(pipe
);
2458 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2459 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
2461 switch (query
->type
) {
2462 case PIPE_QUERY_OCCLUSION_COUNTER
:
2463 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2464 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2465 /* Allocate a word for the query results to be stored */
2466 query
->transfer
= panfrost_allocate_transient(batch
, sizeof(unsigned));
2467 ctx
->occlusion_query
= query
;
2470 /* Geometry statistics are computed in the driver. XXX: geom/tess
2473 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2474 query
->start
= ctx
->prims_generated
;
2476 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2477 query
->start
= ctx
->tf_prims_generated
;
2481 fprintf(stderr
, "Skipping query %u\n", query
->type
);
2489 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2491 struct panfrost_context
*ctx
= pan_context(pipe
);
2492 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2494 switch (query
->type
) {
2495 case PIPE_QUERY_OCCLUSION_COUNTER
:
2496 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2497 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2498 ctx
->occlusion_query
= NULL
;
2500 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2501 query
->end
= ctx
->prims_generated
;
2503 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2504 query
->end
= ctx
->tf_prims_generated
;
2512 panfrost_get_query_result(struct pipe_context
*pipe
,
2513 struct pipe_query
*q
,
2515 union pipe_query_result
*vresult
)
2517 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2520 switch (query
->type
) {
2521 case PIPE_QUERY_OCCLUSION_COUNTER
:
2522 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2523 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2525 panfrost_flush(pipe
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2527 /* Read back the query results */
2528 unsigned *result
= (unsigned *) query
->transfer
.cpu
;
2529 unsigned passed
= *result
;
2531 if (query
->type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
2532 vresult
->u64
= passed
;
2534 vresult
->b
= !!passed
;
2539 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2540 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2541 panfrost_flush(pipe
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
2542 vresult
->u64
= query
->end
- query
->start
;
2546 DBG("Skipped query get %u\n", query
->type
);
2553 static struct pipe_stream_output_target
*
2554 panfrost_create_stream_output_target(struct pipe_context
*pctx
,
2555 struct pipe_resource
*prsc
,
2556 unsigned buffer_offset
,
2557 unsigned buffer_size
)
2559 struct pipe_stream_output_target
*target
;
2561 target
= rzalloc(pctx
, struct pipe_stream_output_target
);
2566 pipe_reference_init(&target
->reference
, 1);
2567 pipe_resource_reference(&target
->buffer
, prsc
);
2569 target
->context
= pctx
;
2570 target
->buffer_offset
= buffer_offset
;
2571 target
->buffer_size
= buffer_size
;
2577 panfrost_stream_output_target_destroy(struct pipe_context
*pctx
,
2578 struct pipe_stream_output_target
*target
)
2580 pipe_resource_reference(&target
->buffer
, NULL
);
2581 ralloc_free(target
);
2585 panfrost_set_stream_output_targets(struct pipe_context
*pctx
,
2586 unsigned num_targets
,
2587 struct pipe_stream_output_target
**targets
,
2588 const unsigned *offsets
)
2590 struct panfrost_context
*ctx
= pan_context(pctx
);
2591 struct panfrost_streamout
*so
= &ctx
->streamout
;
2593 assert(num_targets
<= ARRAY_SIZE(so
->targets
));
2595 for (unsigned i
= 0; i
< num_targets
; i
++) {
2596 if (offsets
[i
] != -1)
2597 so
->offsets
[i
] = offsets
[i
];
2599 pipe_so_target_reference(&so
->targets
[i
], targets
[i
]);
2602 for (unsigned i
= 0; i
< so
->num_targets
; i
++)
2603 pipe_so_target_reference(&so
->targets
[i
], NULL
);
2605 so
->num_targets
= num_targets
;
2609 panfrost_setup_hardware(struct panfrost_context
*ctx
)
2611 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2612 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
2614 ctx
->scratchpad
= panfrost_bo_create(screen
, 64 * 4 * 4096, 0);
2615 ctx
->tiler_heap
= panfrost_bo_create(screen
, 4096 * 4096,
2618 ctx
->tiler_dummy
= panfrost_bo_create(screen
, 4096,
2620 assert(ctx
->scratchpad
&& ctx
->tiler_heap
&& ctx
->tiler_dummy
);
2623 /* New context creation, which also does hardware initialisation since I don't
2624 * know the better way to structure this :smirk: */
2626 struct pipe_context
*
2627 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
2629 struct panfrost_context
*ctx
= rzalloc(screen
, struct panfrost_context
);
2630 struct panfrost_screen
*pscreen
= pan_screen(screen
);
2631 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2633 ctx
->is_t6xx
= pscreen
->gpu_id
< 0x0700; /* Literally, "earlier than T700" */
2635 gallium
->screen
= screen
;
2637 gallium
->destroy
= panfrost_destroy
;
2639 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
2641 gallium
->flush
= panfrost_flush
;
2642 gallium
->clear
= panfrost_clear
;
2643 gallium
->draw_vbo
= panfrost_draw_vbo
;
2645 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
2646 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
2647 gallium
->set_shader_buffers
= panfrost_set_shader_buffers
;
2649 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
2651 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
2652 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
2653 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
2655 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
2656 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
2657 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
2659 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
2660 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
2661 gallium
->delete_vertex_elements_state
= panfrost_generic_cso_delete
;
2663 gallium
->create_fs_state
= panfrost_create_shader_state
;
2664 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
2665 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
2667 gallium
->create_vs_state
= panfrost_create_shader_state
;
2668 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
2669 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
2671 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
2672 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
2673 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
2675 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
2676 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
2677 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
2679 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
2681 gallium
->set_clip_state
= panfrost_set_clip_state
;
2682 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
2683 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
2684 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
2685 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
2687 gallium
->create_query
= panfrost_create_query
;
2688 gallium
->destroy_query
= panfrost_destroy_query
;
2689 gallium
->begin_query
= panfrost_begin_query
;
2690 gallium
->end_query
= panfrost_end_query
;
2691 gallium
->get_query_result
= panfrost_get_query_result
;
2693 gallium
->create_stream_output_target
= panfrost_create_stream_output_target
;
2694 gallium
->stream_output_target_destroy
= panfrost_stream_output_target_destroy
;
2695 gallium
->set_stream_output_targets
= panfrost_set_stream_output_targets
;
2697 panfrost_resource_context_init(gallium
);
2698 panfrost_blend_context_init(gallium
);
2699 panfrost_compute_context_init(gallium
);
2703 ret
= drmSyncobjCreate(pscreen
->fd
, DRM_SYNCOBJ_CREATE_SIGNALED
,
2707 panfrost_setup_hardware(ctx
);
2710 gallium
->stream_uploader
= u_upload_create_default(gallium
);
2711 gallium
->const_uploader
= gallium
->stream_uploader
;
2712 assert(gallium
->stream_uploader
);
2714 /* Midgard supports ES modes, plus QUADS/QUAD_STRIPS/POLYGON */
2715 ctx
->draw_modes
= (1 << (PIPE_PRIM_POLYGON
+ 1)) - 1;
2717 ctx
->primconvert
= util_primconvert_create(gallium
, ctx
->draw_modes
);
2719 ctx
->blitter
= util_blitter_create(gallium
);
2720 ctx
->blitter_wallpaper
= util_blitter_create(gallium
);
2722 assert(ctx
->blitter
);
2723 assert(ctx
->blitter_wallpaper
);
2725 /* Prepare for render! */
2727 panfrost_batch_init(ctx
);
2728 panfrost_emit_vertex_payload(ctx
);
2729 panfrost_emit_tiler_payload(ctx
);
2730 panfrost_invalidate_frame(ctx
);
2731 panfrost_default_shader_backend(ctx
);