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
31 #include "pan_context.h"
32 #include "pan_format.h"
33 #include "panfrost-quirks.h"
35 #include "util/macros.h"
36 #include "util/format/u_format.h"
37 #include "util/u_inlines.h"
38 #include "util/u_upload_mgr.h"
39 #include "util/u_memory.h"
40 #include "util/u_vbuf.h"
41 #include "util/half_float.h"
42 #include "util/u_helpers.h"
43 #include "util/format/u_format.h"
44 #include "util/u_prim.h"
45 #include "util/u_prim_restart.h"
46 #include "indices/u_primconvert.h"
47 #include "tgsi/tgsi_parse.h"
48 #include "tgsi/tgsi_from_mesa.h"
49 #include "util/u_math.h"
51 #include "pan_screen.h"
52 #include "pan_blending.h"
53 #include "pan_blend_shaders.h"
56 /* Framebuffer descriptor */
58 static struct midgard_tiler_descriptor
59 panfrost_emit_midg_tiler(struct panfrost_batch
*batch
, unsigned vertex_count
)
61 struct panfrost_screen
*screen
= pan_screen(batch
->ctx
->base
.screen
);
62 struct midgard_tiler_descriptor t
= {0};
63 unsigned height
= batch
->key
.height
;
64 unsigned width
= batch
->key
.width
;
67 panfrost_choose_hierarchy_mask(width
, height
, vertex_count
);
69 /* Compute the polygon header size and use that to offset the body */
71 unsigned header_size
= panfrost_tiler_header_size(
72 width
, height
, t
.hierarchy_mask
);
74 t
.polygon_list_size
= panfrost_tiler_full_size(
75 width
, height
, t
.hierarchy_mask
);
79 if (t
.hierarchy_mask
) {
80 struct panfrost_bo
*tiler_heap
;
82 tiler_heap
= panfrost_batch_get_tiler_heap(batch
);
83 t
.polygon_list
= panfrost_batch_get_polygon_list(batch
,
88 /* Allow the entire tiler heap */
89 t
.heap_start
= tiler_heap
->gpu
;
90 t
.heap_end
= tiler_heap
->gpu
+ tiler_heap
->size
;
92 struct panfrost_bo
*tiler_dummy
;
94 tiler_dummy
= panfrost_batch_get_tiler_dummy(batch
);
96 /* The tiler is disabled, so don't allow the tiler heap */
97 t
.heap_start
= tiler_dummy
->gpu
;
98 t
.heap_end
= t
.heap_start
;
100 /* Use a dummy polygon list */
101 t
.polygon_list
= tiler_dummy
->gpu
;
103 /* Disable the tiler */
104 t
.hierarchy_mask
|= MALI_TILER_DISABLED
;
106 if (screen
->quirks
& MIDGARD_SFBD
) {
107 t
.hierarchy_mask
= 0xFFF; /* TODO: What's this? */
108 t
.polygon_list_size
= 0x200;
110 /* We don't have a SET_VALUE job, so write the polygon list manually */
111 uint32_t *polygon_list_body
= (uint32_t *) (tiler_dummy
->cpu
+ header_size
);
112 polygon_list_body
[0] = 0xa0000000; /* TODO: Just that? */
116 t
.polygon_list_body
=
117 t
.polygon_list
+ header_size
;
122 struct mali_single_framebuffer
123 panfrost_emit_sfbd(struct panfrost_batch
*batch
, unsigned vertex_count
)
125 unsigned width
= batch
->key
.width
;
126 unsigned height
= batch
->key
.height
;
128 struct mali_single_framebuffer framebuffer
= {
129 .width
= MALI_POSITIVE(width
),
130 .height
= MALI_POSITIVE(height
),
135 .clear_flags
= 0x1000,
136 .unknown_address_0
= panfrost_batch_get_scratchpad(batch
)->gpu
,
137 .tiler
= panfrost_emit_midg_tiler(batch
, vertex_count
),
143 struct bifrost_framebuffer
144 panfrost_emit_mfbd(struct panfrost_batch
*batch
, unsigned vertex_count
)
146 unsigned width
= batch
->key
.width
;
147 unsigned height
= batch
->key
.height
;
149 struct bifrost_framebuffer framebuffer
= {
150 .unk0
= 0x1e5, /* 1e4 if no spill */
151 .width1
= MALI_POSITIVE(width
),
152 .height1
= MALI_POSITIVE(height
),
153 .width2
= MALI_POSITIVE(width
),
154 .height2
= MALI_POSITIVE(height
),
158 .rt_count_1
= MALI_POSITIVE(batch
->key
.nr_cbufs
),
163 .scratchpad
= panfrost_batch_get_scratchpad(batch
)->gpu
,
164 .tiler
= panfrost_emit_midg_tiler(batch
, vertex_count
)
172 struct pipe_context
*pipe
,
174 const union pipe_color_union
*color
,
175 double depth
, unsigned stencil
)
177 struct panfrost_context
*ctx
= pan_context(pipe
);
179 /* TODO: panfrost_get_fresh_batch_for_fbo() instantiates a new batch if
180 * the existing batch targeting this FBO has draws. We could probably
181 * avoid that by replacing plain clears by quad-draws with a specific
182 * color/depth/stencil value, thus avoiding the generation of extra
183 * fragment/set_value jobs.
185 struct panfrost_batch
*batch
= panfrost_get_fresh_batch_for_fbo(ctx
);
187 panfrost_batch_add_fbo_bos(batch
);
188 panfrost_batch_clear(batch
, buffers
, color
, depth
, stencil
);
192 panfrost_attach_vt_mfbd(struct panfrost_batch
*batch
)
194 struct bifrost_framebuffer mfbd
= panfrost_emit_mfbd(batch
, ~0);
196 return panfrost_upload_transient(batch
, &mfbd
, sizeof(mfbd
)) | MALI_MFBD
;
200 panfrost_attach_vt_sfbd(struct panfrost_batch
*batch
)
202 struct mali_single_framebuffer sfbd
= panfrost_emit_sfbd(batch
, ~0);
204 return panfrost_upload_transient(batch
, &sfbd
, sizeof(sfbd
)) | MALI_SFBD
;
208 panfrost_attach_vt_framebuffer(struct panfrost_context
*ctx
)
210 /* Skip the attach if we can */
212 if (ctx
->payloads
[PIPE_SHADER_VERTEX
].postfix
.framebuffer
) {
213 assert(ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.framebuffer
);
217 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
218 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
220 if (!batch
->framebuffer
)
221 batch
->framebuffer
= (screen
->quirks
& MIDGARD_SFBD
) ?
222 panfrost_attach_vt_sfbd(batch
) :
223 panfrost_attach_vt_mfbd(batch
);
225 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
226 ctx
->payloads
[i
].postfix
.framebuffer
= batch
->framebuffer
;
229 /* Reset per-frame context, called on context initialisation as well as after
230 * flushing a frame */
233 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
235 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
236 ctx
->payloads
[i
].postfix
.framebuffer
= 0;
239 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
242 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
| PAN_DIRTY_TEXTURES
;
244 /* TODO: When does this need to be handled? */
245 ctx
->active_queries
= true;
248 /* In practice, every field of these payloads should be configurable
249 * arbitrarily, which means these functions are basically catch-all's for
250 * as-of-yet unwavering unknowns */
253 panfrost_emit_vertex_payload(struct panfrost_context
*ctx
)
255 /* 0x2 bit clear on 32-bit T6XX */
257 struct midgard_payload_vertex_tiler payload
= {
258 .gl_enables
= 0x4 | 0x2,
261 /* Vertex and compute are closely coupled, so share a payload */
263 memcpy(&ctx
->payloads
[PIPE_SHADER_VERTEX
], &payload
, sizeof(payload
));
264 memcpy(&ctx
->payloads
[PIPE_SHADER_COMPUTE
], &payload
, sizeof(payload
));
268 panfrost_emit_tiler_payload(struct panfrost_context
*ctx
)
270 struct midgard_payload_vertex_tiler payload
= {
272 .zero1
= 0xffff, /* Why is this only seen on test-quad-textured? */
276 memcpy(&ctx
->payloads
[PIPE_SHADER_FRAGMENT
], &payload
, sizeof(payload
));
280 translate_tex_wrap(enum pipe_tex_wrap w
)
283 case PIPE_TEX_WRAP_REPEAT
:
284 return MALI_WRAP_REPEAT
;
286 /* TODO: lower GL_CLAMP? */
287 case PIPE_TEX_WRAP_CLAMP
:
288 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
289 return MALI_WRAP_CLAMP_TO_EDGE
;
291 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
292 return MALI_WRAP_CLAMP_TO_BORDER
;
294 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
295 return MALI_WRAP_MIRRORED_REPEAT
;
298 unreachable("Invalid wrap");
303 panfrost_translate_compare_func(enum pipe_compare_func in
)
306 case PIPE_FUNC_NEVER
:
307 return MALI_FUNC_NEVER
;
310 return MALI_FUNC_LESS
;
312 case PIPE_FUNC_EQUAL
:
313 return MALI_FUNC_EQUAL
;
315 case PIPE_FUNC_LEQUAL
:
316 return MALI_FUNC_LEQUAL
;
318 case PIPE_FUNC_GREATER
:
319 return MALI_FUNC_GREATER
;
321 case PIPE_FUNC_NOTEQUAL
:
322 return MALI_FUNC_NOTEQUAL
;
324 case PIPE_FUNC_GEQUAL
:
325 return MALI_FUNC_GEQUAL
;
327 case PIPE_FUNC_ALWAYS
:
328 return MALI_FUNC_ALWAYS
;
331 unreachable("Invalid func");
336 panfrost_translate_alt_compare_func(enum pipe_compare_func in
)
339 case PIPE_FUNC_NEVER
:
340 return MALI_ALT_FUNC_NEVER
;
343 return MALI_ALT_FUNC_LESS
;
345 case PIPE_FUNC_EQUAL
:
346 return MALI_ALT_FUNC_EQUAL
;
348 case PIPE_FUNC_LEQUAL
:
349 return MALI_ALT_FUNC_LEQUAL
;
351 case PIPE_FUNC_GREATER
:
352 return MALI_ALT_FUNC_GREATER
;
354 case PIPE_FUNC_NOTEQUAL
:
355 return MALI_ALT_FUNC_NOTEQUAL
;
357 case PIPE_FUNC_GEQUAL
:
358 return MALI_ALT_FUNC_GEQUAL
;
360 case PIPE_FUNC_ALWAYS
:
361 return MALI_ALT_FUNC_ALWAYS
;
364 unreachable("Invalid alt func");
369 panfrost_translate_stencil_op(enum pipe_stencil_op in
)
372 case PIPE_STENCIL_OP_KEEP
:
373 return MALI_STENCIL_KEEP
;
375 case PIPE_STENCIL_OP_ZERO
:
376 return MALI_STENCIL_ZERO
;
378 case PIPE_STENCIL_OP_REPLACE
:
379 return MALI_STENCIL_REPLACE
;
381 case PIPE_STENCIL_OP_INCR
:
382 return MALI_STENCIL_INCR
;
384 case PIPE_STENCIL_OP_DECR
:
385 return MALI_STENCIL_DECR
;
387 case PIPE_STENCIL_OP_INCR_WRAP
:
388 return MALI_STENCIL_INCR_WRAP
;
390 case PIPE_STENCIL_OP_DECR_WRAP
:
391 return MALI_STENCIL_DECR_WRAP
;
393 case PIPE_STENCIL_OP_INVERT
:
394 return MALI_STENCIL_INVERT
;
397 unreachable("Invalid stencil op");
402 panfrost_make_stencil_state(const struct pipe_stencil_state
*in
, struct mali_stencil_test
*out
)
404 out
->ref
= 0; /* Gallium gets it from elsewhere */
406 out
->mask
= in
->valuemask
;
407 out
->func
= panfrost_translate_compare_func(in
->func
);
408 out
->sfail
= panfrost_translate_stencil_op(in
->fail_op
);
409 out
->dpfail
= panfrost_translate_stencil_op(in
->zfail_op
);
410 out
->dppass
= panfrost_translate_stencil_op(in
->zpass_op
);
414 panfrost_default_shader_backend(struct panfrost_context
*ctx
)
416 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
417 struct mali_shader_meta shader
= {
418 .alpha_coverage
= ~MALI_ALPHA_COVERAGE(0.000000),
420 .unknown2_3
= MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS
) | 0x3010,
421 .unknown2_4
= MALI_NO_MSAA
| 0x4e0,
424 /* unknown2_4 has 0x10 bit set on T6XX and T720. We don't know why this is
425 * required (independent of 32-bit/64-bit descriptors), or why it's not
426 * used on later GPU revisions. Otherwise, all shader jobs fault on
427 * these earlier chips (perhaps this is a chicken bit of some kind).
428 * More investigation is needed. */
430 if (screen
->quirks
& MIDGARD_SFBD
)
431 shader
.unknown2_4
|= 0x10;
433 struct pipe_stencil_state default_stencil
= {
435 .func
= PIPE_FUNC_ALWAYS
,
436 .fail_op
= MALI_STENCIL_KEEP
,
437 .zfail_op
= MALI_STENCIL_KEEP
,
438 .zpass_op
= MALI_STENCIL_KEEP
,
443 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_front
);
444 shader
.stencil_mask_front
= default_stencil
.writemask
;
446 panfrost_make_stencil_state(&default_stencil
, &shader
.stencil_back
);
447 shader
.stencil_mask_back
= default_stencil
.writemask
;
449 if (default_stencil
.enabled
)
450 shader
.unknown2_4
|= MALI_STENCIL_TEST
;
452 memcpy(&ctx
->fragment_shader_core
, &shader
, sizeof(shader
));
455 /* Generates a vertex/tiler job. This is, in some sense, the heart of the
456 * graphics command stream. It should be called once per draw, accordding to
457 * presentations. Set is_tiler for "tiler" jobs (fragment shader jobs, but in
458 * Mali parlance, "fragment" refers to framebuffer writeout). Clear it for
461 struct panfrost_transfer
462 panfrost_vertex_tiler_job(struct panfrost_context
*ctx
, bool is_tiler
)
464 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
465 struct mali_job_descriptor_header job
= {
466 .job_type
= is_tiler
? JOB_TYPE_TILER
: JOB_TYPE_VERTEX
,
467 .job_descriptor_size
= 1,
470 struct midgard_payload_vertex_tiler
*payload
= is_tiler
? &ctx
->payloads
[PIPE_SHADER_FRAGMENT
] : &ctx
->payloads
[PIPE_SHADER_VERTEX
];
472 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, sizeof(job
) + sizeof(*payload
));
473 memcpy(transfer
.cpu
, &job
, sizeof(job
));
474 memcpy(transfer
.cpu
+ sizeof(job
), payload
, sizeof(*payload
));
479 panfrost_vertex_buffer_address(struct panfrost_context
*ctx
, unsigned i
)
481 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[i
];
482 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (buf
->buffer
.resource
);
484 return rsrc
->bo
->gpu
+ buf
->buffer_offset
;
488 panfrost_writes_point_size(struct panfrost_context
*ctx
)
490 assert(ctx
->shader
[PIPE_SHADER_VERTEX
]);
491 struct panfrost_shader_state
*vs
= &ctx
->shader
[PIPE_SHADER_VERTEX
]->variants
[ctx
->shader
[PIPE_SHADER_VERTEX
]->active_variant
];
493 return vs
->writes_point_size
&& ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
== MALI_POINTS
;
496 /* Stage the attribute descriptors so we can adjust src_offset
497 * to let BOs align nicely */
500 panfrost_stage_attributes(struct panfrost_context
*ctx
)
502 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
503 struct panfrost_vertex_state
*so
= ctx
->vertex
;
505 size_t sz
= sizeof(struct mali_attr_meta
) * so
->num_elements
;
506 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, sz
);
507 struct mali_attr_meta
*target
= (struct mali_attr_meta
*) transfer
.cpu
;
509 /* Copy as-is for the first pass */
510 memcpy(target
, so
->hw
, sz
);
512 /* Fixup offsets for the second pass. Recall that the hardware
513 * calculates attribute addresses as:
515 * addr = base + (stride * vtx) + src_offset;
517 * However, on Mali, base must be aligned to 64-bytes, so we
520 * base' = base & ~63 = base - (base & 63)
522 * To compensate when using base' (see emit_vertex_data), we have
523 * to adjust src_offset by the masked off piece:
525 * addr' = base' + (stride * vtx) + (src_offset + (base & 63))
526 * = base - (base & 63) + (stride * vtx) + src_offset + (base & 63)
527 * = base + (stride * vtx) + src_offset
533 unsigned start
= ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
;
535 for (unsigned i
= 0; i
< so
->num_elements
; ++i
) {
536 unsigned vbi
= so
->pipe
[i
].vertex_buffer_index
;
537 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[vbi
];
538 mali_ptr addr
= panfrost_vertex_buffer_address(ctx
, vbi
);
540 /* Adjust by the masked off bits of the offset */
541 target
[i
].src_offset
+= (addr
& 63);
543 /* Also, somewhat obscurely per-instance data needs to be
544 * offset in response to a delayed start in an indexed draw */
546 if (so
->pipe
[i
].instance_divisor
&& ctx
->instance_count
> 1 && start
) {
547 target
[i
].src_offset
-= buf
->stride
* start
;
553 ctx
->payloads
[PIPE_SHADER_VERTEX
].postfix
.attribute_meta
= transfer
.gpu
;
557 panfrost_upload_sampler_descriptors(struct panfrost_context
*ctx
)
559 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
560 size_t desc_size
= sizeof(struct mali_sampler_descriptor
);
562 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
565 if (ctx
->sampler_count
[t
] && ctx
->sampler_view_count
[t
]) {
566 size_t transfer_size
= desc_size
* ctx
->sampler_count
[t
];
568 struct panfrost_transfer transfer
=
569 panfrost_allocate_transient(batch
, transfer_size
);
571 struct mali_sampler_descriptor
*desc
=
572 (struct mali_sampler_descriptor
*) transfer
.cpu
;
574 for (int i
= 0; i
< ctx
->sampler_count
[t
]; ++i
)
575 desc
[i
] = ctx
->samplers
[t
][i
]->hw
;
577 upload
= transfer
.gpu
;
580 ctx
->payloads
[t
].postfix
.sampler_descriptor
= upload
;
584 static enum mali_texture_layout
585 panfrost_layout_for_texture(struct panfrost_resource
*rsrc
)
587 /* TODO: other linear depth textures */
588 bool is_depth
= rsrc
->base
.format
== PIPE_FORMAT_Z32_UNORM
;
590 switch (rsrc
->layout
) {
592 return MALI_TEXTURE_AFBC
;
595 return MALI_TEXTURE_TILED
;
597 return is_depth
? MALI_TEXTURE_TILED
: MALI_TEXTURE_LINEAR
;
599 unreachable("Invalid texture layout");
605 struct panfrost_context
*ctx
,
606 enum pipe_shader_type st
,
607 struct panfrost_sampler_view
*view
)
612 struct pipe_sampler_view
*pview
= &view
->base
;
613 struct panfrost_resource
*rsrc
= pan_resource(pview
->texture
);
615 /* Do we interleave an explicit stride with every element? */
617 bool has_manual_stride
= view
->manual_stride
;
619 /* For easy access */
621 bool is_buffer
= pview
->target
== PIPE_BUFFER
;
622 unsigned first_level
= is_buffer
? 0 : pview
->u
.tex
.first_level
;
623 unsigned last_level
= is_buffer
? 0 : pview
->u
.tex
.last_level
;
624 unsigned first_layer
= is_buffer
? 0 : pview
->u
.tex
.first_layer
;
625 unsigned last_layer
= is_buffer
? 0 : pview
->u
.tex
.last_layer
;
627 /* Lower-bit is set when sampling from colour AFBC */
628 bool is_afbc
= rsrc
->layout
== PAN_AFBC
;
629 bool is_zs
= rsrc
->base
.bind
& PIPE_BIND_DEPTH_STENCIL
;
630 unsigned afbc_bit
= (is_afbc
&& !is_zs
) ? 1 : 0;
632 /* Add the BO to the job so it's retained until the job is done. */
633 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
634 panfrost_batch_add_bo(batch
, rsrc
->bo
,
635 PAN_BO_ACCESS_SHARED
| PAN_BO_ACCESS_READ
|
636 panfrost_bo_access_for_stage(st
));
638 /* Add the usage flags in, since they can change across the CSO
639 * lifetime due to layout switches */
641 view
->hw
.format
.layout
= panfrost_layout_for_texture(rsrc
);
642 view
->hw
.format
.manual_stride
= has_manual_stride
;
644 /* Inject the addresses in, interleaving mip levels, cube faces, and
645 * strides in that order */
649 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
650 for (unsigned f
= first_layer
; f
<= last_layer
; ++f
) {
652 view
->hw
.payload
[idx
++] =
653 panfrost_get_texture_address(rsrc
, l
, f
) + afbc_bit
;
655 if (has_manual_stride
) {
656 view
->hw
.payload
[idx
++] =
657 rsrc
->slices
[l
].stride
;
662 return panfrost_upload_transient(batch
, &view
->hw
,
663 sizeof(struct mali_texture_descriptor
));
667 panfrost_upload_texture_descriptors(struct panfrost_context
*ctx
)
669 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
671 for (int t
= 0; t
<= PIPE_SHADER_FRAGMENT
; ++t
) {
672 mali_ptr trampoline
= 0;
674 if (ctx
->sampler_view_count
[t
]) {
675 uint64_t trampolines
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
677 for (int i
= 0; i
< ctx
->sampler_view_count
[t
]; ++i
)
679 panfrost_upload_tex(ctx
, t
, ctx
->sampler_views
[t
][i
]);
681 trampoline
= panfrost_upload_transient(batch
, trampolines
, sizeof(uint64_t) * ctx
->sampler_view_count
[t
]);
684 ctx
->payloads
[t
].postfix
.texture_trampoline
= trampoline
;
688 struct sysval_uniform
{
697 static void panfrost_upload_viewport_scale_sysval(struct panfrost_context
*ctx
,
698 struct sysval_uniform
*uniform
)
700 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
702 uniform
->f
[0] = vp
->scale
[0];
703 uniform
->f
[1] = vp
->scale
[1];
704 uniform
->f
[2] = vp
->scale
[2];
707 static void panfrost_upload_viewport_offset_sysval(struct panfrost_context
*ctx
,
708 struct sysval_uniform
*uniform
)
710 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
712 uniform
->f
[0] = vp
->translate
[0];
713 uniform
->f
[1] = vp
->translate
[1];
714 uniform
->f
[2] = vp
->translate
[2];
717 static void panfrost_upload_txs_sysval(struct panfrost_context
*ctx
,
718 enum pipe_shader_type st
,
719 unsigned int sysvalid
,
720 struct sysval_uniform
*uniform
)
722 unsigned texidx
= PAN_SYSVAL_ID_TO_TXS_TEX_IDX(sysvalid
);
723 unsigned dim
= PAN_SYSVAL_ID_TO_TXS_DIM(sysvalid
);
724 bool is_array
= PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(sysvalid
);
725 struct pipe_sampler_view
*tex
= &ctx
->sampler_views
[st
][texidx
]->base
;
728 uniform
->i
[0] = u_minify(tex
->texture
->width0
, tex
->u
.tex
.first_level
);
731 uniform
->i
[1] = u_minify(tex
->texture
->height0
,
732 tex
->u
.tex
.first_level
);
735 uniform
->i
[2] = u_minify(tex
->texture
->depth0
,
736 tex
->u
.tex
.first_level
);
739 uniform
->i
[dim
] = tex
->texture
->array_size
;
742 static void panfrost_upload_ssbo_sysval(
743 struct panfrost_context
*ctx
,
744 enum pipe_shader_type st
,
746 struct sysval_uniform
*uniform
)
748 assert(ctx
->ssbo_mask
[st
] & (1 << ssbo_id
));
749 struct pipe_shader_buffer sb
= ctx
->ssbo
[st
][ssbo_id
];
751 /* Compute address */
752 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
753 struct panfrost_bo
*bo
= pan_resource(sb
.buffer
)->bo
;
755 panfrost_batch_add_bo(batch
, bo
,
756 PAN_BO_ACCESS_SHARED
| PAN_BO_ACCESS_RW
|
757 panfrost_bo_access_for_stage(st
));
759 /* Upload address and size as sysval */
760 uniform
->du
[0] = bo
->gpu
+ sb
.buffer_offset
;
761 uniform
->u
[2] = sb
.buffer_size
;
765 panfrost_upload_sampler_sysval(
766 struct panfrost_context
*ctx
,
767 enum pipe_shader_type st
,
768 unsigned sampler_index
,
769 struct sysval_uniform
*uniform
)
771 struct pipe_sampler_state
*sampl
=
772 &ctx
->samplers
[st
][sampler_index
]->base
;
774 uniform
->f
[0] = sampl
->min_lod
;
775 uniform
->f
[1] = sampl
->max_lod
;
776 uniform
->f
[2] = sampl
->lod_bias
;
778 /* Even without any errata, Midgard represents "no mipmapping" as
779 * fixing the LOD with the clamps; keep behaviour consistent. c.f.
780 * panfrost_create_sampler_state which also explains our choice of
781 * epsilon value (again to keep behaviour consistent) */
783 if (sampl
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
)
784 uniform
->f
[1] = uniform
->f
[0] + (1.0/256.0);
787 static void panfrost_upload_num_work_groups_sysval(struct panfrost_context
*ctx
,
788 struct sysval_uniform
*uniform
)
790 uniform
->u
[0] = ctx
->compute_grid
->grid
[0];
791 uniform
->u
[1] = ctx
->compute_grid
->grid
[1];
792 uniform
->u
[2] = ctx
->compute_grid
->grid
[2];
795 static void panfrost_upload_sysvals(struct panfrost_context
*ctx
, void *buf
,
796 struct panfrost_shader_state
*ss
,
797 enum pipe_shader_type st
)
799 struct sysval_uniform
*uniforms
= (void *)buf
;
801 for (unsigned i
= 0; i
< ss
->sysval_count
; ++i
) {
802 int sysval
= ss
->sysval
[i
];
804 switch (PAN_SYSVAL_TYPE(sysval
)) {
805 case PAN_SYSVAL_VIEWPORT_SCALE
:
806 panfrost_upload_viewport_scale_sysval(ctx
, &uniforms
[i
]);
808 case PAN_SYSVAL_VIEWPORT_OFFSET
:
809 panfrost_upload_viewport_offset_sysval(ctx
, &uniforms
[i
]);
811 case PAN_SYSVAL_TEXTURE_SIZE
:
812 panfrost_upload_txs_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
815 case PAN_SYSVAL_SSBO
:
816 panfrost_upload_ssbo_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
819 case PAN_SYSVAL_NUM_WORK_GROUPS
:
820 panfrost_upload_num_work_groups_sysval(ctx
, &uniforms
[i
]);
822 case PAN_SYSVAL_SAMPLER
:
823 panfrost_upload_sampler_sysval(ctx
, st
, PAN_SYSVAL_ID(sysval
),
833 panfrost_map_constant_buffer_cpu(struct panfrost_constant_buffer
*buf
, unsigned index
)
835 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
836 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
839 return rsrc
->bo
->cpu
;
840 else if (cb
->user_buffer
)
841 return cb
->user_buffer
;
843 unreachable("No constant buffer");
847 panfrost_map_constant_buffer_gpu(
848 struct panfrost_context
*ctx
,
849 enum pipe_shader_type st
,
850 struct panfrost_constant_buffer
*buf
,
853 struct pipe_constant_buffer
*cb
= &buf
->cb
[index
];
854 struct panfrost_resource
*rsrc
= pan_resource(cb
->buffer
);
855 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
858 panfrost_batch_add_bo(batch
, rsrc
->bo
,
859 PAN_BO_ACCESS_SHARED
|
861 panfrost_bo_access_for_stage(st
));
862 return rsrc
->bo
->gpu
;
863 } else if (cb
->user_buffer
) {
864 return panfrost_upload_transient(batch
, cb
->user_buffer
, cb
->buffer_size
);
866 unreachable("No constant buffer");
870 /* Compute number of UBOs active (more specifically, compute the highest UBO
871 * number addressable -- if there are gaps, include them in the count anyway).
872 * We always include UBO #0 in the count, since we *need* uniforms enabled for
876 panfrost_ubo_count(struct panfrost_context
*ctx
, enum pipe_shader_type stage
)
878 unsigned mask
= ctx
->constant_buffer
[stage
].enabled_mask
| 1;
879 return 32 - __builtin_clz(mask
);
882 /* Fixes up a shader state with current state, returning a GPU address to the
886 panfrost_patch_shader_state(
887 struct panfrost_context
*ctx
,
888 struct panfrost_shader_state
*ss
,
889 enum pipe_shader_type stage
,
892 ss
->tripipe
->texture_count
= ctx
->sampler_view_count
[stage
];
893 ss
->tripipe
->sampler_count
= ctx
->sampler_count
[stage
];
895 ss
->tripipe
->midgard1
.flags
= 0x220;
897 unsigned ubo_count
= panfrost_ubo_count(ctx
, stage
);
898 ss
->tripipe
->midgard1
.uniform_buffer_count
= ubo_count
;
900 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
902 /* Add the shader BO to the batch. */
903 panfrost_batch_add_bo(batch
, ss
->bo
,
904 PAN_BO_ACCESS_PRIVATE
|
906 panfrost_bo_access_for_stage(stage
));
908 /* We can't reuse over frames; that's not safe. The descriptor must be
909 * transient uploaded */
912 return panfrost_upload_transient(batch
, ss
->tripipe
,
913 sizeof(struct mali_shader_meta
));
916 /* If we don't need an upload, don't bother */
922 panfrost_patch_shader_state_compute(
923 struct panfrost_context
*ctx
,
924 enum pipe_shader_type stage
,
927 struct panfrost_shader_variants
*all
= ctx
->shader
[stage
];
930 ctx
->payloads
[stage
].postfix
.shader
= 0;
934 struct panfrost_shader_state
*s
= &all
->variants
[all
->active_variant
];
936 ctx
->payloads
[stage
].postfix
.shader
=
937 panfrost_patch_shader_state(ctx
, s
, stage
, should_upload
);
940 /* Go through dirty flags and actualise them in the cmdstream. */
943 panfrost_emit_for_draw(struct panfrost_context
*ctx
, bool with_vertex_data
)
945 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
946 struct panfrost_screen
*screen
= pan_screen(ctx
->base
.screen
);
948 panfrost_batch_add_fbo_bos(batch
);
949 panfrost_attach_vt_framebuffer(ctx
);
951 if (with_vertex_data
) {
952 panfrost_emit_vertex_data(batch
);
954 /* Varyings emitted for -all- geometry */
955 unsigned total_count
= ctx
->padded_count
* ctx
->instance_count
;
956 panfrost_emit_varying_descriptor(ctx
, total_count
);
959 bool msaa
= ctx
->rasterizer
->base
.multisample
;
961 if (ctx
->dirty
& PAN_DIRTY_RASTERIZER
) {
962 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].gl_enables
= ctx
->rasterizer
->tiler_gl_enables
;
964 /* TODO: Sample size */
965 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_HAS_MSAA
, msaa
);
966 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_NO_MSAA
, !msaa
);
969 panfrost_batch_set_requirements(batch
);
971 if (ctx
->occlusion_query
) {
972 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].gl_enables
|= MALI_OCCLUSION_QUERY
;
973 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.occlusion_counter
= ctx
->occlusion_query
->bo
->gpu
;
976 panfrost_patch_shader_state_compute(ctx
, PIPE_SHADER_VERTEX
, true);
977 panfrost_patch_shader_state_compute(ctx
, PIPE_SHADER_COMPUTE
, true);
979 if (ctx
->dirty
& (PAN_DIRTY_RASTERIZER
| PAN_DIRTY_VS
)) {
980 /* Check if we need to link the gl_PointSize varying */
981 if (!panfrost_writes_point_size(ctx
)) {
982 /* If the size is constant, write it out. Otherwise,
983 * don't touch primitive_size (since we would clobber
984 * the pointer there) */
986 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].primitive_size
.constant
= ctx
->rasterizer
->base
.line_width
;
990 /* TODO: Maybe dirty track FS, maybe not. For now, it's transient. */
991 if (ctx
->shader
[PIPE_SHADER_FRAGMENT
])
992 ctx
->dirty
|= PAN_DIRTY_FS
;
994 if (ctx
->dirty
& PAN_DIRTY_FS
) {
995 assert(ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
996 struct panfrost_shader_state
*variant
= &ctx
->shader
[PIPE_SHADER_FRAGMENT
]->variants
[ctx
->shader
[PIPE_SHADER_FRAGMENT
]->active_variant
];
998 panfrost_patch_shader_state(ctx
, variant
, PIPE_SHADER_FRAGMENT
, false);
1000 #define COPY(name) ctx->fragment_shader_core.name = variant->tripipe->name
1003 COPY(attribute_count
);
1004 COPY(varying_count
);
1005 COPY(texture_count
);
1006 COPY(sampler_count
);
1007 COPY(midgard1
.uniform_count
);
1008 COPY(midgard1
.uniform_buffer_count
);
1009 COPY(midgard1
.work_count
);
1010 COPY(midgard1
.flags
);
1011 COPY(midgard1
.unknown2
);
1015 /* Get blending setup */
1016 unsigned rt_count
= MAX2(ctx
->pipe_framebuffer
.nr_cbufs
, 1);
1018 struct panfrost_blend_final blend
[PIPE_MAX_COLOR_BUFS
];
1020 for (unsigned c
= 0; c
< rt_count
; ++c
)
1021 blend
[c
] = panfrost_get_blend_for_context(ctx
, c
);
1023 /* If there is a blend shader, work registers are shared. XXX: opt */
1025 for (unsigned c
= 0; c
< rt_count
; ++c
) {
1026 if (blend
[c
].is_shader
)
1027 ctx
->fragment_shader_core
.midgard1
.work_count
= 16;
1030 /* Depending on whether it's legal to in the given shader, we
1031 * try to enable early-z testing (or forward-pixel kill?) */
1033 SET_BIT(ctx
->fragment_shader_core
.midgard1
.flags
, MALI_EARLY_Z
, !variant
->can_discard
);
1035 /* Any time texturing is used, derivatives are implicitly
1036 * calculated, so we need to enable helper invocations */
1038 SET_BIT(ctx
->fragment_shader_core
.midgard1
.flags
, MALI_HELPER_INVOCATIONS
, variant
->helper_invocations
);
1040 /* Assign the stencil refs late */
1042 unsigned front_ref
= ctx
->stencil_ref
.ref_value
[0];
1043 unsigned back_ref
= ctx
->stencil_ref
.ref_value
[1];
1044 bool back_enab
= ctx
->depth_stencil
->stencil
[1].enabled
;
1046 ctx
->fragment_shader_core
.stencil_front
.ref
= front_ref
;
1047 ctx
->fragment_shader_core
.stencil_back
.ref
= back_enab
? back_ref
: front_ref
;
1049 /* CAN_DISCARD should be set if the fragment shader possibly
1050 * contains a 'discard' instruction. It is likely this is
1051 * related to optimizations related to forward-pixel kill, as
1052 * per "Mali Performance 3: Is EGL_BUFFER_PRESERVED a good
1053 * thing?" by Peter Harris
1056 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_CAN_DISCARD
, variant
->can_discard
);
1057 SET_BIT(ctx
->fragment_shader_core
.midgard1
.flags
, 0x400, variant
->can_discard
);
1059 /* Even on MFBD, the shader descriptor gets blend shaders. It's
1060 * *also* copied to the blend_meta appended (by convention),
1061 * but this is the field actually read by the hardware. (Or
1062 * maybe both are read...?) */
1064 if (blend
[0].is_shader
) {
1065 ctx
->fragment_shader_core
.blend
.shader
=
1066 blend
[0].shader
.bo
->gpu
| blend
[0].shader
.first_tag
;
1068 ctx
->fragment_shader_core
.blend
.shader
= 0;
1071 if (screen
->quirks
& MIDGARD_SFBD
) {
1072 /* When only a single render target platform is used, the blend
1073 * information is inside the shader meta itself. We
1074 * additionally need to signal CAN_DISCARD for nontrivial blend
1075 * modes (so we're able to read back the destination buffer) */
1077 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_HAS_BLEND_SHADER
, blend
[0].is_shader
);
1079 if (!blend
[0].is_shader
) {
1080 ctx
->fragment_shader_core
.blend
.equation
=
1081 *blend
[0].equation
.equation
;
1082 ctx
->fragment_shader_core
.blend
.constant
=
1083 blend
[0].equation
.constant
;
1086 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_CAN_DISCARD
, !blend
[0].no_blending
);
1089 size_t size
= sizeof(struct mali_shader_meta
) + (sizeof(struct midgard_blend_rt
) * rt_count
);
1090 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, size
);
1091 memcpy(transfer
.cpu
, &ctx
->fragment_shader_core
, sizeof(struct mali_shader_meta
));
1093 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.shader
= transfer
.gpu
;
1095 if (!(screen
->quirks
& MIDGARD_SFBD
)) {
1096 /* Additional blend descriptor tacked on for jobs using MFBD */
1098 struct midgard_blend_rt rts
[4];
1100 for (unsigned i
= 0; i
< rt_count
; ++i
) {
1101 rts
[i
].flags
= 0x200;
1104 (ctx
->pipe_framebuffer
.nr_cbufs
> i
) &&
1105 (ctx
->pipe_framebuffer
.cbufs
[i
]) &&
1106 util_format_is_srgb(ctx
->pipe_framebuffer
.cbufs
[i
]->format
);
1108 SET_BIT(rts
[i
].flags
, MALI_BLEND_MRT_SHADER
, blend
[i
].is_shader
);
1109 SET_BIT(rts
[i
].flags
, MALI_BLEND_LOAD_TIB
, !blend
[i
].no_blending
);
1110 SET_BIT(rts
[i
].flags
, MALI_BLEND_SRGB
, is_srgb
);
1111 SET_BIT(rts
[i
].flags
, MALI_BLEND_NO_DITHER
, !ctx
->blend
->base
.dither
);
1113 /* TODO: sRGB in blend shaders is currently
1114 * unimplemented. Contact me (Alyssa) if you're
1115 * interested in working on this. We have
1116 * native Midgard ops for helping here, but
1117 * they're not well-understood yet. */
1119 assert(!(is_srgb
&& blend
[i
].is_shader
));
1121 if (blend
[i
].is_shader
) {
1122 rts
[i
].blend
.shader
= blend
[i
].shader
.bo
->gpu
| blend
[i
].shader
.first_tag
;
1124 rts
[i
].blend
.equation
= *blend
[i
].equation
.equation
;
1125 rts
[i
].blend
.constant
= blend
[i
].equation
.constant
;
1129 memcpy(transfer
.cpu
+ sizeof(struct mali_shader_meta
), rts
, sizeof(rts
[0]) * rt_count
);
1133 /* We stage to transient, so always dirty.. */
1135 panfrost_stage_attributes(ctx
);
1137 if (ctx
->dirty
& PAN_DIRTY_SAMPLERS
)
1138 panfrost_upload_sampler_descriptors(ctx
);
1140 if (ctx
->dirty
& PAN_DIRTY_TEXTURES
)
1141 panfrost_upload_texture_descriptors(ctx
);
1143 const struct pipe_viewport_state
*vp
= &ctx
->pipe_viewport
;
1145 for (int i
= 0; i
< PIPE_SHADER_TYPES
; ++i
) {
1146 struct panfrost_shader_variants
*all
= ctx
->shader
[i
];
1151 struct panfrost_constant_buffer
*buf
= &ctx
->constant_buffer
[i
];
1153 struct panfrost_shader_state
*ss
= &all
->variants
[all
->active_variant
];
1155 /* Uniforms are implicitly UBO #0 */
1156 bool has_uniforms
= buf
->enabled_mask
& (1 << 0);
1158 /* Allocate room for the sysval and the uniforms */
1159 size_t sys_size
= sizeof(float) * 4 * ss
->sysval_count
;
1160 size_t uniform_size
= has_uniforms
? (buf
->cb
[0].buffer_size
) : 0;
1161 size_t size
= sys_size
+ uniform_size
;
1162 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, size
);
1164 /* Upload sysvals requested by the shader */
1165 panfrost_upload_sysvals(ctx
, transfer
.cpu
, ss
, i
);
1167 /* Upload uniforms */
1169 const void *cpu
= panfrost_map_constant_buffer_cpu(buf
, 0);
1170 memcpy(transfer
.cpu
+ sys_size
, cpu
, uniform_size
);
1174 ctx
->shader
[i
]->variants
[ctx
->shader
[i
]->active_variant
].uniform_count
;
1176 struct mali_vertex_tiler_postfix
*postfix
=
1177 &ctx
->payloads
[i
].postfix
;
1179 /* Next up, attach UBOs. UBO #0 is the uniforms we just
1182 unsigned ubo_count
= panfrost_ubo_count(ctx
, i
);
1183 assert(ubo_count
>= 1);
1185 size_t sz
= sizeof(struct mali_uniform_buffer_meta
) * ubo_count
;
1186 struct mali_uniform_buffer_meta ubos
[PAN_MAX_CONST_BUFFERS
];
1188 /* Upload uniforms as a UBO */
1189 ubos
[0].size
= MALI_POSITIVE((2 + uniform_count
));
1190 ubos
[0].ptr
= transfer
.gpu
>> 2;
1192 /* The rest are honest-to-goodness UBOs */
1194 for (unsigned ubo
= 1; ubo
< ubo_count
; ++ubo
) {
1195 size_t usz
= buf
->cb
[ubo
].buffer_size
;
1197 bool enabled
= buf
->enabled_mask
& (1 << ubo
);
1198 bool empty
= usz
== 0;
1200 if (!enabled
|| empty
) {
1201 /* Stub out disabled UBOs to catch accesses */
1204 ubos
[ubo
].ptr
= 0xDEAD0000;
1208 mali_ptr gpu
= panfrost_map_constant_buffer_gpu(ctx
, i
, buf
, ubo
);
1210 unsigned bytes_per_field
= 16;
1211 unsigned aligned
= ALIGN_POT(usz
, bytes_per_field
);
1212 unsigned fields
= aligned
/ bytes_per_field
;
1214 ubos
[ubo
].size
= MALI_POSITIVE(fields
);
1215 ubos
[ubo
].ptr
= gpu
>> 2;
1218 mali_ptr ubufs
= panfrost_upload_transient(batch
, ubos
, sz
);
1219 postfix
->uniforms
= transfer
.gpu
;
1220 postfix
->uniform_buffers
= ubufs
;
1222 buf
->dirty_mask
= 0;
1225 /* TODO: Upload the viewport somewhere more appropriate */
1227 /* Clip bounds are encoded as floats. The viewport itself is encoded as
1228 * (somewhat) asymmetric ints. */
1229 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1231 struct mali_viewport view
= {
1232 /* By default, do no viewport clipping, i.e. clip to (-inf,
1233 * inf) in each direction. Clipping to the viewport in theory
1234 * should work, but in practice causes issues when we're not
1235 * explicitly trying to scissor */
1237 .clip_minx
= -INFINITY
,
1238 .clip_miny
= -INFINITY
,
1239 .clip_maxx
= INFINITY
,
1240 .clip_maxy
= INFINITY
,
1243 /* Always scissor to the viewport by default. */
1244 float vp_minx
= (int) (vp
->translate
[0] - fabsf(vp
->scale
[0]));
1245 float vp_maxx
= (int) (vp
->translate
[0] + fabsf(vp
->scale
[0]));
1247 float vp_miny
= (int) (vp
->translate
[1] - fabsf(vp
->scale
[1]));
1248 float vp_maxy
= (int) (vp
->translate
[1] + fabsf(vp
->scale
[1]));
1250 float minz
= (vp
->translate
[2] - fabsf(vp
->scale
[2]));
1251 float maxz
= (vp
->translate
[2] + fabsf(vp
->scale
[2]));
1253 /* Apply the scissor test */
1255 unsigned minx
, miny
, maxx
, maxy
;
1257 if (ss
&& ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
) {
1258 minx
= MAX2(ss
->minx
, vp_minx
);
1259 miny
= MAX2(ss
->miny
, vp_miny
);
1260 maxx
= MIN2(ss
->maxx
, vp_maxx
);
1261 maxy
= MIN2(ss
->maxy
, vp_maxy
);
1269 /* Hardware needs the min/max to be strictly ordered, so flip if we
1270 * need to. The viewport transformation in the vertex shader will
1271 * handle the negatives if we don't */
1274 unsigned temp
= miny
;
1280 unsigned temp
= minx
;
1291 /* Clamp to the framebuffer size as a last check */
1293 minx
= MIN2(ctx
->pipe_framebuffer
.width
, minx
);
1294 maxx
= MIN2(ctx
->pipe_framebuffer
.width
, maxx
);
1296 miny
= MIN2(ctx
->pipe_framebuffer
.height
, miny
);
1297 maxy
= MIN2(ctx
->pipe_framebuffer
.height
, maxy
);
1299 /* Update the job, unless we're doing wallpapering (whose lack of
1300 * scissor we can ignore, since if we "miss" a tile of wallpaper, it'll
1301 * just... be faster :) */
1303 if (!ctx
->wallpaper_batch
)
1304 panfrost_batch_union_scissor(batch
, minx
, miny
, maxx
, maxy
);
1308 view
.viewport0
[0] = minx
;
1309 view
.viewport1
[0] = MALI_POSITIVE(maxx
);
1311 view
.viewport0
[1] = miny
;
1312 view
.viewport1
[1] = MALI_POSITIVE(maxy
);
1314 view
.clip_minz
= minz
;
1315 view
.clip_maxz
= maxz
;
1317 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].postfix
.viewport
=
1318 panfrost_upload_transient(batch
,
1320 sizeof(struct mali_viewport
));
1325 /* Corresponds to exactly one draw, but does not submit anything */
1328 panfrost_queue_draw(struct panfrost_context
*ctx
)
1330 /* Handle dirty flags now */
1331 panfrost_emit_for_draw(ctx
, true);
1333 /* If rasterizer discard is enable, only submit the vertex */
1335 bool rasterizer_discard
= ctx
->rasterizer
1336 && ctx
->rasterizer
->base
.rasterizer_discard
;
1338 struct panfrost_transfer vertex
= panfrost_vertex_tiler_job(ctx
, false);
1339 struct panfrost_transfer tiler
;
1341 if (!rasterizer_discard
)
1342 tiler
= panfrost_vertex_tiler_job(ctx
, true);
1344 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1346 if (rasterizer_discard
)
1347 panfrost_scoreboard_queue_vertex_job(batch
, vertex
, FALSE
);
1348 else if (ctx
->wallpaper_batch
&& batch
->first_tiler
.gpu
)
1349 panfrost_scoreboard_queue_fused_job_prepend(batch
, vertex
, tiler
);
1351 panfrost_scoreboard_queue_fused_job(batch
, vertex
, tiler
);
1354 /* The entire frame is in memory -- send it off to the kernel! */
1358 struct pipe_context
*pipe
,
1359 struct pipe_fence_handle
**fence
,
1362 struct panfrost_context
*ctx
= pan_context(pipe
);
1363 struct util_dynarray fences
;
1365 /* We must collect the fences before the flush is done, otherwise we'll
1366 * lose track of them.
1369 util_dynarray_init(&fences
, NULL
);
1370 hash_table_foreach(ctx
->batches
, hentry
) {
1371 struct panfrost_batch
*batch
= hentry
->data
;
1373 panfrost_batch_fence_reference(batch
->out_sync
);
1374 util_dynarray_append(&fences
,
1375 struct panfrost_batch_fence
*,
1380 /* Submit all pending jobs */
1381 panfrost_flush_all_batches(ctx
, false);
1384 struct panfrost_fence
*f
= panfrost_fence_create(ctx
, &fences
);
1385 pipe
->screen
->fence_reference(pipe
->screen
, fence
, NULL
);
1386 *fence
= (struct pipe_fence_handle
*)f
;
1388 util_dynarray_foreach(&fences
, struct panfrost_batch_fence
*, fence
)
1389 panfrost_batch_fence_unreference(*fence
);
1391 util_dynarray_fini(&fences
);
1395 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
1398 g2m_draw_mode(enum pipe_prim_type mode
)
1401 DEFINE_CASE(POINTS
);
1403 DEFINE_CASE(LINE_LOOP
);
1404 DEFINE_CASE(LINE_STRIP
);
1405 DEFINE_CASE(TRIANGLES
);
1406 DEFINE_CASE(TRIANGLE_STRIP
);
1407 DEFINE_CASE(TRIANGLE_FAN
);
1409 DEFINE_CASE(QUAD_STRIP
);
1410 DEFINE_CASE(POLYGON
);
1413 unreachable("Invalid draw mode");
1420 panfrost_translate_index_size(unsigned size
)
1424 return MALI_DRAW_INDEXED_UINT8
;
1427 return MALI_DRAW_INDEXED_UINT16
;
1430 return MALI_DRAW_INDEXED_UINT32
;
1433 unreachable("Invalid index size");
1437 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
1438 * good for the duration of the draw (transient), could last longer */
1441 panfrost_get_index_buffer_mapped(struct panfrost_context
*ctx
, const struct pipe_draw_info
*info
)
1443 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
1445 off_t offset
= info
->start
* info
->index_size
;
1446 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1448 if (!info
->has_user_indices
) {
1449 /* Only resources can be directly mapped */
1450 panfrost_batch_add_bo(batch
, rsrc
->bo
,
1451 PAN_BO_ACCESS_SHARED
|
1452 PAN_BO_ACCESS_READ
|
1453 PAN_BO_ACCESS_VERTEX_TILER
);
1454 return rsrc
->bo
->gpu
+ offset
;
1456 /* Otherwise, we need to upload to transient memory */
1457 const uint8_t *ibuf8
= (const uint8_t *) info
->index
.user
;
1458 return panfrost_upload_transient(batch
, ibuf8
+ offset
, info
->count
* info
->index_size
);
1463 panfrost_scissor_culls_everything(struct panfrost_context
*ctx
)
1465 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
1467 /* Check if we're scissoring at all */
1469 if (!(ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
))
1472 return (ss
->minx
== ss
->maxx
) || (ss
->miny
== ss
->maxy
);
1475 /* Count generated primitives (when there is no geom/tess shaders) for
1476 * transform feedback */
1479 panfrost_statistics_record(
1480 struct panfrost_context
*ctx
,
1481 const struct pipe_draw_info
*info
)
1483 if (!ctx
->active_queries
)
1486 uint32_t prims
= u_prims_for_vertices(info
->mode
, info
->count
);
1487 ctx
->prims_generated
+= prims
;
1489 if (!ctx
->streamout
.num_targets
)
1492 ctx
->tf_prims_generated
+= prims
;
1497 struct pipe_context
*pipe
,
1498 const struct pipe_draw_info
*info
)
1500 struct panfrost_context
*ctx
= pan_context(pipe
);
1502 /* First of all, check the scissor to see if anything is drawn at all.
1503 * If it's not, we drop the draw (mostly a conformance issue;
1504 * well-behaved apps shouldn't hit this) */
1506 if (panfrost_scissor_culls_everything(ctx
))
1509 int mode
= info
->mode
;
1511 /* Fallback unsupported restart index */
1512 unsigned primitive_index
= (1 << (info
->index_size
* 8)) - 1;
1514 if (info
->primitive_restart
&& info
->index_size
1515 && info
->restart_index
!= primitive_index
) {
1516 util_draw_vbo_without_prim_restart(pipe
, info
);
1520 /* Fallback for unsupported modes */
1522 assert(ctx
->rasterizer
!= NULL
);
1524 if (!(ctx
->draw_modes
& (1 << mode
))) {
1525 if (mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && !ctx
->rasterizer
->base
.flatshade
) {
1526 mode
= PIPE_PRIM_TRIANGLE_FAN
;
1528 if (info
->count
< 4) {
1529 /* Degenerate case? */
1533 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
1534 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
1539 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= info
->start
;
1540 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= info
->start
;
1542 /* Now that we have a guaranteed terminating path, find the job.
1543 * Assignment commented out to prevent unused warning */
1545 /* struct panfrost_batch *batch = */ panfrost_get_batch_for_fbo(ctx
);
1547 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
= g2m_draw_mode(mode
);
1549 /* Take into account a negative bias */
1550 ctx
->vertex_count
= info
->count
+ abs(info
->index_bias
);
1551 ctx
->instance_count
= info
->instance_count
;
1552 ctx
->active_prim
= info
->mode
;
1554 /* For non-indexed draws, they're the same */
1555 unsigned vertex_count
= ctx
->vertex_count
;
1557 unsigned draw_flags
= 0;
1559 /* The draw flags interpret how primitive size is interpreted */
1561 if (panfrost_writes_point_size(ctx
))
1562 draw_flags
|= MALI_DRAW_VARYING_SIZE
;
1564 if (info
->primitive_restart
)
1565 draw_flags
|= MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX
;
1567 /* For higher amounts of vertices (greater than what fits in a 16-bit
1568 * short), the other value is needed, otherwise there will be bizarre
1569 * rendering artefacts. It's not clear what these values mean yet. This
1570 * change is also needed for instancing and sometimes points (perhaps
1571 * related to dynamically setting gl_PointSize) */
1573 bool is_points
= mode
== PIPE_PRIM_POINTS
;
1574 bool many_verts
= ctx
->vertex_count
> 0xFFFF;
1575 bool instanced
= ctx
->instance_count
> 1;
1577 draw_flags
|= (is_points
|| many_verts
|| instanced
) ? 0x3000 : 0x18000;
1579 /* This doesn't make much sense */
1580 if (mode
== PIPE_PRIM_LINE_STRIP
) {
1581 draw_flags
|= 0x800;
1584 panfrost_statistics_record(ctx
, info
);
1586 if (info
->index_size
) {
1587 /* Calculate the min/max index used so we can figure out how
1588 * many times to invoke the vertex shader */
1590 /* Fetch / calculate index bounds */
1591 unsigned min_index
= 0, max_index
= 0;
1593 if (info
->max_index
== ~0u) {
1594 u_vbuf_get_minmax_index(pipe
, info
, &min_index
, &max_index
);
1596 min_index
= info
->min_index
;
1597 max_index
= info
->max_index
;
1600 /* Use the corresponding values */
1601 vertex_count
= max_index
- min_index
+ 1;
1602 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= min_index
+ info
->index_bias
;
1603 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= min_index
+ info
->index_bias
;
1605 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= -min_index
;
1606 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(info
->count
);
1608 //assert(!info->restart_index); /* TODO: Research */
1610 draw_flags
|= panfrost_translate_index_size(info
->index_size
);
1611 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
= panfrost_get_index_buffer_mapped(ctx
, info
);
1613 /* Index count == vertex count, if no indexing is applied, as
1614 * if it is internally indexed in the expected order */
1616 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= 0;
1617 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(ctx
->vertex_count
);
1619 /* Reverse index state */
1620 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
= (u64
) NULL
;
1623 /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
1624 * vertex_count, 1) */
1626 panfrost_pack_work_groups_fused(
1627 &ctx
->payloads
[PIPE_SHADER_VERTEX
].prefix
,
1628 &ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
,
1629 1, vertex_count
, info
->instance_count
,
1632 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.unknown_draw
= draw_flags
;
1634 /* Encode the padded vertex count */
1636 if (info
->instance_count
> 1) {
1637 /* Triangles have non-even vertex counts so they change how
1638 * padding works internally */
1641 mode
== PIPE_PRIM_TRIANGLES
||
1642 mode
== PIPE_PRIM_TRIANGLE_STRIP
||
1643 mode
== PIPE_PRIM_TRIANGLE_FAN
;
1645 struct pan_shift_odd so
=
1646 panfrost_padded_vertex_count(vertex_count
, !is_triangle
);
1648 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= so
.shift
;
1649 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= so
.shift
;
1651 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= so
.odd
;
1652 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= so
.odd
;
1654 ctx
->padded_count
= pan_expand_shift_odd(so
);
1656 ctx
->padded_count
= vertex_count
;
1658 /* Reset instancing state */
1659 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= 0;
1660 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= 0;
1661 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= 0;
1662 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= 0;
1665 /* Fire off the draw itself */
1666 panfrost_queue_draw(ctx
);
1668 /* Increment transform feedback offsets */
1670 for (unsigned i
= 0; i
< ctx
->streamout
.num_targets
; ++i
) {
1671 unsigned output_count
= u_stream_outputs_for_vertices(
1672 ctx
->active_prim
, ctx
->vertex_count
);
1674 ctx
->streamout
.offsets
[i
] += output_count
;
1681 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
1687 panfrost_create_rasterizer_state(
1688 struct pipe_context
*pctx
,
1689 const struct pipe_rasterizer_state
*cso
)
1691 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
1695 /* Bitmask, unknown meaning of the start value. 0x105 on 32-bit T6XX */
1696 so
->tiler_gl_enables
= 0x7;
1699 so
->tiler_gl_enables
|= MALI_FRONT_CCW_TOP
;
1701 if (cso
->cull_face
& PIPE_FACE_FRONT
)
1702 so
->tiler_gl_enables
|= MALI_CULL_FACE_FRONT
;
1704 if (cso
->cull_face
& PIPE_FACE_BACK
)
1705 so
->tiler_gl_enables
|= MALI_CULL_FACE_BACK
;
1711 panfrost_bind_rasterizer_state(
1712 struct pipe_context
*pctx
,
1715 struct panfrost_context
*ctx
= pan_context(pctx
);
1717 /* TODO: Why can't rasterizer be NULL ever? Other drivers are fine.. */
1721 ctx
->rasterizer
= hwcso
;
1722 ctx
->dirty
|= PAN_DIRTY_RASTERIZER
;
1724 ctx
->fragment_shader_core
.depth_units
= ctx
->rasterizer
->base
.offset_units
* 2.0f
;
1725 ctx
->fragment_shader_core
.depth_factor
= ctx
->rasterizer
->base
.offset_scale
;
1727 /* Gauranteed with the core GL call, so don't expose ARB_polygon_offset */
1728 assert(ctx
->rasterizer
->base
.offset_clamp
== 0.0);
1730 /* XXX: Which bit is which? Does this maybe allow offseting not-tri? */
1732 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_DEPTH_RANGE_A
, ctx
->rasterizer
->base
.offset_tri
);
1733 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_DEPTH_RANGE_B
, ctx
->rasterizer
->base
.offset_tri
);
1735 /* Point sprites are emulated */
1737 struct panfrost_shader_state
*variant
=
1738 ctx
->shader
[PIPE_SHADER_FRAGMENT
] ? &ctx
->shader
[PIPE_SHADER_FRAGMENT
]->variants
[ctx
->shader
[PIPE_SHADER_FRAGMENT
]->active_variant
] : NULL
;
1740 if (ctx
->rasterizer
->base
.sprite_coord_enable
|| (variant
&& variant
->point_sprite_mask
))
1741 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
1745 panfrost_create_vertex_elements_state(
1746 struct pipe_context
*pctx
,
1747 unsigned num_elements
,
1748 const struct pipe_vertex_element
*elements
)
1750 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
1752 so
->num_elements
= num_elements
;
1753 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
1755 for (int i
= 0; i
< num_elements
; ++i
) {
1756 so
->hw
[i
].index
= i
;
1758 enum pipe_format fmt
= elements
[i
].src_format
;
1759 const struct util_format_description
*desc
= util_format_description(fmt
);
1760 so
->hw
[i
].unknown1
= 0x2;
1761 so
->hw
[i
].swizzle
= panfrost_get_default_swizzle(desc
->nr_channels
);
1763 so
->hw
[i
].format
= panfrost_find_format(desc
);
1765 /* The field itself should probably be shifted over */
1766 so
->hw
[i
].src_offset
= elements
[i
].src_offset
;
1773 panfrost_bind_vertex_elements_state(
1774 struct pipe_context
*pctx
,
1777 struct panfrost_context
*ctx
= pan_context(pctx
);
1779 ctx
->vertex
= hwcso
;
1780 ctx
->dirty
|= PAN_DIRTY_VERTEX
;
1784 panfrost_create_shader_state(
1785 struct pipe_context
*pctx
,
1786 const struct pipe_shader_state
*cso
)
1788 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
1791 /* Token deep copy to prevent memory corruption */
1793 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
1794 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
1800 panfrost_delete_shader_state(
1801 struct pipe_context
*pctx
,
1804 struct panfrost_shader_variants
*cso
= (struct panfrost_shader_variants
*) so
;
1806 if (cso
->base
.type
== PIPE_SHADER_IR_TGSI
) {
1807 DBG("Deleting TGSI shader leaks duplicated tokens\n");
1810 for (unsigned i
= 0; i
< cso
->variant_count
; ++i
) {
1811 struct panfrost_shader_state
*shader_state
= &cso
->variants
[i
];
1812 panfrost_bo_unreference(shader_state
->bo
);
1813 shader_state
->bo
= NULL
;
1820 panfrost_create_sampler_state(
1821 struct pipe_context
*pctx
,
1822 const struct pipe_sampler_state
*cso
)
1824 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
1827 /* sampler_state corresponds to mali_sampler_descriptor, which we can generate entirely here */
1829 bool min_nearest
= cso
->min_img_filter
== PIPE_TEX_FILTER_NEAREST
;
1830 bool mag_nearest
= cso
->mag_img_filter
== PIPE_TEX_FILTER_NEAREST
;
1831 bool mip_linear
= cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_LINEAR
;
1833 unsigned min_filter
= min_nearest
? MALI_SAMP_MIN_NEAREST
: 0;
1834 unsigned mag_filter
= mag_nearest
? MALI_SAMP_MAG_NEAREST
: 0;
1835 unsigned mip_filter
= mip_linear
?
1836 (MALI_SAMP_MIP_LINEAR_1
| MALI_SAMP_MIP_LINEAR_2
) : 0;
1837 unsigned normalized
= cso
->normalized_coords
? MALI_SAMP_NORM_COORDS
: 0;
1839 struct mali_sampler_descriptor sampler_descriptor
= {
1840 .filter_mode
= min_filter
| mag_filter
| mip_filter
| normalized
,
1841 .wrap_s
= translate_tex_wrap(cso
->wrap_s
),
1842 .wrap_t
= translate_tex_wrap(cso
->wrap_t
),
1843 .wrap_r
= translate_tex_wrap(cso
->wrap_r
),
1844 .compare_func
= panfrost_translate_alt_compare_func(cso
->compare_func
),
1846 cso
->border_color
.f
[0],
1847 cso
->border_color
.f
[1],
1848 cso
->border_color
.f
[2],
1849 cso
->border_color
.f
[3]
1851 .min_lod
= FIXED_16(cso
->min_lod
),
1852 .max_lod
= FIXED_16(cso
->max_lod
),
1853 .lod_bias
= FIXED_16(cso
->lod_bias
),
1854 .seamless_cube_map
= cso
->seamless_cube_map
,
1857 /* If necessary, we disable mipmapping in the sampler descriptor by
1858 * clamping the LOD as tight as possible (from 0 to epsilon,
1859 * essentially -- remember these are fixed point numbers, so
1862 if (cso
->min_mip_filter
== PIPE_TEX_MIPFILTER_NONE
)
1863 sampler_descriptor
.max_lod
= sampler_descriptor
.min_lod
;
1865 /* Enforce that there is something in the middle by adding epsilon*/
1867 if (sampler_descriptor
.min_lod
== sampler_descriptor
.max_lod
)
1868 sampler_descriptor
.max_lod
++;
1871 assert(sampler_descriptor
.max_lod
> sampler_descriptor
.min_lod
);
1873 so
->hw
= sampler_descriptor
;
1879 panfrost_bind_sampler_states(
1880 struct pipe_context
*pctx
,
1881 enum pipe_shader_type shader
,
1882 unsigned start_slot
, unsigned num_sampler
,
1885 assert(start_slot
== 0);
1887 struct panfrost_context
*ctx
= pan_context(pctx
);
1889 /* XXX: Should upload, not just copy? */
1890 ctx
->sampler_count
[shader
] = num_sampler
;
1891 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
1893 ctx
->dirty
|= PAN_DIRTY_SAMPLERS
;
1897 panfrost_variant_matches(
1898 struct panfrost_context
*ctx
,
1899 struct panfrost_shader_state
*variant
,
1900 enum pipe_shader_type type
)
1902 struct pipe_rasterizer_state
*rasterizer
= &ctx
->rasterizer
->base
;
1903 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
1905 bool is_fragment
= (type
== PIPE_SHADER_FRAGMENT
);
1907 if (is_fragment
&& (alpha
->enabled
|| variant
->alpha_state
.enabled
)) {
1908 /* Make sure enable state is at least the same */
1909 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
1913 /* Check that the contents of the test are the same */
1914 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
1915 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
1917 if (!(same_func
&& same_ref
)) {
1922 if (is_fragment
&& rasterizer
&& (rasterizer
->sprite_coord_enable
|
1923 variant
->point_sprite_mask
)) {
1924 /* Ensure the same varyings are turned to point sprites */
1925 if (rasterizer
->sprite_coord_enable
!= variant
->point_sprite_mask
)
1928 /* Ensure the orientation is correct */
1930 rasterizer
->sprite_coord_mode
==
1931 PIPE_SPRITE_COORD_UPPER_LEFT
;
1933 if (variant
->point_sprite_upper_left
!= upper_left
)
1937 /* Otherwise, we're good to go */
1942 * Fix an uncompiled shader's stream output info, and produce a bitmask
1943 * of which VARYING_SLOT_* are captured for stream output.
1945 * Core Gallium stores output->register_index as a "slot" number, where
1946 * slots are assigned consecutively to all outputs in info->outputs_written.
1947 * This naive packing of outputs doesn't work for us - we too have slots,
1948 * but the layout is defined by the VUE map, which we won't have until we
1949 * compile a specific shader variant. So, we remap these and simply store
1950 * VARYING_SLOT_* in our copy's output->register_index fields.
1952 * We then produce a bitmask of outputs which are used for SO.
1954 * Implementation from iris.
1958 update_so_info(struct pipe_stream_output_info
*so_info
,
1959 uint64_t outputs_written
)
1961 uint64_t so_outputs
= 0;
1962 uint8_t reverse_map
[64] = {0};
1965 while (outputs_written
)
1966 reverse_map
[slot
++] = u_bit_scan64(&outputs_written
);
1968 for (unsigned i
= 0; i
< so_info
->num_outputs
; i
++) {
1969 struct pipe_stream_output
*output
= &so_info
->output
[i
];
1971 /* Map Gallium's condensed "slots" back to real VARYING_SLOT_* enums */
1972 output
->register_index
= reverse_map
[output
->register_index
];
1974 so_outputs
|= 1ull << output
->register_index
;
1981 panfrost_bind_shader_state(
1982 struct pipe_context
*pctx
,
1984 enum pipe_shader_type type
)
1986 struct panfrost_context
*ctx
= pan_context(pctx
);
1988 ctx
->shader
[type
] = hwcso
;
1990 if (type
== PIPE_SHADER_FRAGMENT
)
1991 ctx
->dirty
|= PAN_DIRTY_FS
;
1993 ctx
->dirty
|= PAN_DIRTY_VS
;
1997 /* Match the appropriate variant */
1999 signed variant
= -1;
2000 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
2002 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
2003 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
], type
)) {
2009 if (variant
== -1) {
2010 /* No variant matched, so create a new one */
2011 variant
= variants
->variant_count
++;
2012 assert(variants
->variant_count
< MAX_SHADER_VARIANTS
);
2014 struct panfrost_shader_state
*v
=
2015 &variants
->variants
[variant
];
2017 if (type
== PIPE_SHADER_FRAGMENT
) {
2018 v
->alpha_state
= ctx
->depth_stencil
->alpha
;
2020 if (ctx
->rasterizer
) {
2021 v
->point_sprite_mask
= ctx
->rasterizer
->base
.sprite_coord_enable
;
2022 v
->point_sprite_upper_left
=
2023 ctx
->rasterizer
->base
.sprite_coord_mode
==
2024 PIPE_SPRITE_COORD_UPPER_LEFT
;
2028 variants
->variants
[variant
].tripipe
= calloc(1, sizeof(struct mali_shader_meta
));
2032 /* Select this variant */
2033 variants
->active_variant
= variant
;
2035 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
2036 assert(panfrost_variant_matches(ctx
, shader_state
, type
));
2038 /* We finally have a variant, so compile it */
2040 if (!shader_state
->compiled
) {
2041 uint64_t outputs_written
= 0;
2043 panfrost_shader_compile(ctx
, shader_state
->tripipe
,
2044 variants
->base
.type
,
2045 variants
->base
.type
== PIPE_SHADER_IR_NIR
?
2046 variants
->base
.ir
.nir
:
2047 variants
->base
.tokens
,
2048 tgsi_processor_to_shader_stage(type
), shader_state
,
2051 shader_state
->compiled
= true;
2053 /* Fixup the stream out information, since what Gallium returns
2054 * normally is mildly insane */
2056 shader_state
->stream_output
= variants
->base
.stream_output
;
2057 shader_state
->so_mask
=
2058 update_so_info(&shader_state
->stream_output
, outputs_written
);
2063 panfrost_bind_vs_state(struct pipe_context
*pctx
, void *hwcso
)
2065 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
2069 panfrost_bind_fs_state(struct pipe_context
*pctx
, void *hwcso
)
2071 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
2075 panfrost_set_vertex_buffers(
2076 struct pipe_context
*pctx
,
2077 unsigned start_slot
,
2078 unsigned num_buffers
,
2079 const struct pipe_vertex_buffer
*buffers
)
2081 struct panfrost_context
*ctx
= pan_context(pctx
);
2083 util_set_vertex_buffers_mask(ctx
->vertex_buffers
, &ctx
->vb_mask
, buffers
, start_slot
, num_buffers
);
2087 panfrost_set_constant_buffer(
2088 struct pipe_context
*pctx
,
2089 enum pipe_shader_type shader
, uint index
,
2090 const struct pipe_constant_buffer
*buf
)
2092 struct panfrost_context
*ctx
= pan_context(pctx
);
2093 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
2095 util_copy_constant_buffer(&pbuf
->cb
[index
], buf
);
2097 unsigned mask
= (1 << index
);
2099 if (unlikely(!buf
)) {
2100 pbuf
->enabled_mask
&= ~mask
;
2101 pbuf
->dirty_mask
&= ~mask
;
2105 pbuf
->enabled_mask
|= mask
;
2106 pbuf
->dirty_mask
|= mask
;
2110 panfrost_set_stencil_ref(
2111 struct pipe_context
*pctx
,
2112 const struct pipe_stencil_ref
*ref
)
2114 struct panfrost_context
*ctx
= pan_context(pctx
);
2115 ctx
->stencil_ref
= *ref
;
2117 /* Shader core dirty */
2118 ctx
->dirty
|= PAN_DIRTY_FS
;
2121 static enum mali_texture_type
2122 panfrost_translate_texture_type(enum pipe_texture_target t
) {
2126 case PIPE_TEXTURE_1D
:
2127 case PIPE_TEXTURE_1D_ARRAY
:
2130 case PIPE_TEXTURE_2D
:
2131 case PIPE_TEXTURE_2D_ARRAY
:
2132 case PIPE_TEXTURE_RECT
:
2135 case PIPE_TEXTURE_3D
:
2138 case PIPE_TEXTURE_CUBE
:
2139 case PIPE_TEXTURE_CUBE_ARRAY
:
2140 return MALI_TEX_CUBE
;
2143 unreachable("Unknown target");
2147 static struct pipe_sampler_view
*
2148 panfrost_create_sampler_view(
2149 struct pipe_context
*pctx
,
2150 struct pipe_resource
*texture
,
2151 const struct pipe_sampler_view
*template)
2153 struct panfrost_sampler_view
*so
= rzalloc(pctx
, struct panfrost_sampler_view
);
2154 int bytes_per_pixel
= util_format_get_blocksize(texture
->format
);
2156 pipe_reference(NULL
, &texture
->reference
);
2158 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
2161 so
->base
= *template;
2162 so
->base
.texture
= texture
;
2163 so
->base
.reference
.count
= 1;
2164 so
->base
.context
= pctx
;
2166 /* sampler_views correspond to texture descriptors, minus the texture
2167 * (data) itself. So, we serialise the descriptor here and cache it for
2170 const struct util_format_description
*desc
= util_format_description(prsrc
->base
.format
);
2172 unsigned char user_swizzle
[4] = {
2173 template->swizzle_r
,
2174 template->swizzle_g
,
2175 template->swizzle_b
,
2179 enum mali_format format
= panfrost_find_format(desc
);
2181 /* Check if we need to set a custom stride by computing the "expected"
2182 * stride and comparing it to what the BO actually wants. Only applies
2183 * to linear textures, since tiled/compressed textures have strict
2184 * alignment requirements for their strides as it is */
2186 unsigned first_level
= template->u
.tex
.first_level
;
2187 unsigned last_level
= template->u
.tex
.last_level
;
2189 if (prsrc
->layout
== PAN_LINEAR
) {
2190 for (unsigned l
= first_level
; l
<= last_level
; ++l
) {
2191 unsigned actual_stride
= prsrc
->slices
[l
].stride
;
2192 unsigned width
= u_minify(texture
->width0
, l
);
2193 unsigned comp_stride
= width
* bytes_per_pixel
;
2195 if (comp_stride
!= actual_stride
) {
2196 so
->manual_stride
= true;
2202 /* In the hardware, array_size refers specifically to array textures,
2203 * whereas in Gallium, it also covers cubemaps */
2205 unsigned array_size
= texture
->array_size
;
2207 if (template->target
== PIPE_TEXTURE_CUBE
) {
2208 /* TODO: Cubemap arrays */
2209 assert(array_size
== 6);
2213 struct mali_texture_descriptor texture_descriptor
= {
2214 .width
= MALI_POSITIVE(u_minify(texture
->width0
, first_level
)),
2215 .height
= MALI_POSITIVE(u_minify(texture
->height0
, first_level
)),
2216 .depth
= MALI_POSITIVE(u_minify(texture
->depth0
, first_level
)),
2217 .array_size
= MALI_POSITIVE(array_size
),
2220 .swizzle
= panfrost_translate_swizzle_4(desc
->swizzle
),
2222 .srgb
= desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
,
2223 .type
= panfrost_translate_texture_type(template->target
),
2227 .swizzle
= panfrost_translate_swizzle_4(user_swizzle
)
2230 texture_descriptor
.levels
= last_level
- first_level
;
2232 so
->hw
= texture_descriptor
;
2234 return (struct pipe_sampler_view
*) so
;
2238 panfrost_set_sampler_views(
2239 struct pipe_context
*pctx
,
2240 enum pipe_shader_type shader
,
2241 unsigned start_slot
, unsigned num_views
,
2242 struct pipe_sampler_view
**views
)
2244 struct panfrost_context
*ctx
= pan_context(pctx
);
2246 assert(start_slot
== 0);
2248 unsigned new_nr
= 0;
2249 for (unsigned i
= 0; i
< num_views
; ++i
) {
2254 ctx
->sampler_view_count
[shader
] = new_nr
;
2255 memcpy(ctx
->sampler_views
[shader
], views
, num_views
* sizeof (void *));
2257 ctx
->dirty
|= PAN_DIRTY_TEXTURES
;
2261 panfrost_sampler_view_destroy(
2262 struct pipe_context
*pctx
,
2263 struct pipe_sampler_view
*view
)
2265 pipe_resource_reference(&view
->texture
, NULL
);
2270 panfrost_set_shader_buffers(
2271 struct pipe_context
*pctx
,
2272 enum pipe_shader_type shader
,
2273 unsigned start
, unsigned count
,
2274 const struct pipe_shader_buffer
*buffers
,
2275 unsigned writable_bitmask
)
2277 struct panfrost_context
*ctx
= pan_context(pctx
);
2279 util_set_shader_buffers_mask(ctx
->ssbo
[shader
], &ctx
->ssbo_mask
[shader
],
2280 buffers
, start
, count
);
2283 /* Hints that a framebuffer should use AFBC where possible */
2287 struct panfrost_screen
*screen
,
2288 const struct pipe_framebuffer_state
*fb
)
2290 /* AFBC implemenation incomplete; hide it */
2291 if (!(pan_debug
& PAN_DBG_AFBC
)) return;
2293 /* Hint AFBC to the resources bound to each color buffer */
2295 for (unsigned i
= 0; i
< fb
->nr_cbufs
; ++i
) {
2296 struct pipe_surface
*surf
= fb
->cbufs
[i
];
2297 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
2298 panfrost_resource_hint_layout(screen
, rsrc
, PAN_AFBC
, 1);
2301 /* Also hint it to the depth buffer */
2304 struct panfrost_resource
*rsrc
= pan_resource(fb
->zsbuf
->texture
);
2305 panfrost_resource_hint_layout(screen
, rsrc
, PAN_AFBC
, 1);
2310 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
2311 const struct pipe_framebuffer_state
*fb
)
2313 struct panfrost_context
*ctx
= pan_context(pctx
);
2315 panfrost_hint_afbc(pan_screen(pctx
->screen
), fb
);
2316 util_copy_framebuffer_state(&ctx
->pipe_framebuffer
, fb
);
2318 panfrost_invalidate_frame(ctx
);
2322 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
2323 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
2325 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
2329 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
2332 struct panfrost_context
*ctx
= pan_context(pipe
);
2333 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
2334 ctx
->depth_stencil
= depth_stencil
;
2339 /* Alpha does not exist in the hardware (it's not in ES3), so it's
2340 * emulated in the fragment shader */
2342 if (depth_stencil
->alpha
.enabled
) {
2343 /* We need to trigger a new shader (maybe) */
2344 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
2348 SET_BIT(ctx
->fragment_shader_core
.unknown2_4
, MALI_STENCIL_TEST
, depth_stencil
->stencil
[0].enabled
);
2350 panfrost_make_stencil_state(&depth_stencil
->stencil
[0], &ctx
->fragment_shader_core
.stencil_front
);
2351 ctx
->fragment_shader_core
.stencil_mask_front
= depth_stencil
->stencil
[0].writemask
;
2353 /* If back-stencil is not enabled, use the front values */
2354 bool back_enab
= ctx
->depth_stencil
->stencil
[1].enabled
;
2355 unsigned back_index
= back_enab
? 1 : 0;
2357 panfrost_make_stencil_state(&depth_stencil
->stencil
[back_index
], &ctx
->fragment_shader_core
.stencil_back
);
2358 ctx
->fragment_shader_core
.stencil_mask_back
= depth_stencil
->stencil
[back_index
].writemask
;
2360 /* Depth state (TODO: Refactor) */
2361 SET_BIT(ctx
->fragment_shader_core
.unknown2_3
, MALI_DEPTH_WRITEMASK
,
2362 depth_stencil
->depth
.writemask
);
2364 int func
= depth_stencil
->depth
.enabled
? depth_stencil
->depth
.func
: PIPE_FUNC_ALWAYS
;
2366 ctx
->fragment_shader_core
.unknown2_3
&= ~MALI_DEPTH_FUNC_MASK
;
2367 ctx
->fragment_shader_core
.unknown2_3
|= MALI_DEPTH_FUNC(panfrost_translate_compare_func(func
));
2369 /* Bounds test not implemented */
2370 assert(!depth_stencil
->depth
.bounds_test
);
2372 ctx
->dirty
|= PAN_DIRTY_FS
;
2376 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
2382 panfrost_set_sample_mask(struct pipe_context
*pipe
,
2383 unsigned sample_mask
)
2388 panfrost_set_clip_state(struct pipe_context
*pipe
,
2389 const struct pipe_clip_state
*clip
)
2391 //struct panfrost_context *panfrost = pan_context(pipe);
2395 panfrost_set_viewport_states(struct pipe_context
*pipe
,
2396 unsigned start_slot
,
2397 unsigned num_viewports
,
2398 const struct pipe_viewport_state
*viewports
)
2400 struct panfrost_context
*ctx
= pan_context(pipe
);
2402 assert(start_slot
== 0);
2403 assert(num_viewports
== 1);
2405 ctx
->pipe_viewport
= *viewports
;
2409 panfrost_set_scissor_states(struct pipe_context
*pipe
,
2410 unsigned start_slot
,
2411 unsigned num_scissors
,
2412 const struct pipe_scissor_state
*scissors
)
2414 struct panfrost_context
*ctx
= pan_context(pipe
);
2416 assert(start_slot
== 0);
2417 assert(num_scissors
== 1);
2419 ctx
->scissor
= *scissors
;
2423 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
2424 const struct pipe_poly_stipple
*stipple
)
2426 //struct panfrost_context *panfrost = pan_context(pipe);
2430 panfrost_set_active_query_state(struct pipe_context
*pipe
,
2433 struct panfrost_context
*ctx
= pan_context(pipe
);
2434 ctx
->active_queries
= enable
;
2438 panfrost_destroy(struct pipe_context
*pipe
)
2440 struct panfrost_context
*panfrost
= pan_context(pipe
);
2442 if (panfrost
->blitter
)
2443 util_blitter_destroy(panfrost
->blitter
);
2445 if (panfrost
->blitter_wallpaper
)
2446 util_blitter_destroy(panfrost
->blitter_wallpaper
);
2448 util_unreference_framebuffer_state(&panfrost
->pipe_framebuffer
);
2449 u_upload_destroy(pipe
->stream_uploader
);
2454 static struct pipe_query
*
2455 panfrost_create_query(struct pipe_context
*pipe
,
2459 struct panfrost_query
*q
= rzalloc(pipe
, struct panfrost_query
);
2464 return (struct pipe_query
*) q
;
2468 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2470 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2473 panfrost_bo_unreference(query
->bo
);
2481 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2483 struct panfrost_context
*ctx
= pan_context(pipe
);
2484 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2486 switch (query
->type
) {
2487 case PIPE_QUERY_OCCLUSION_COUNTER
:
2488 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2489 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2490 /* Allocate a bo for the query results to be stored */
2492 query
->bo
= panfrost_bo_create(
2493 pan_screen(ctx
->base
.screen
),
2494 sizeof(unsigned), 0);
2497 unsigned *result
= (unsigned *)query
->bo
->cpu
;
2498 *result
= 0; /* Default to 0 if nothing at all drawn. */
2499 ctx
->occlusion_query
= query
;
2502 /* Geometry statistics are computed in the driver. XXX: geom/tess
2505 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2506 query
->start
= ctx
->prims_generated
;
2508 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2509 query
->start
= ctx
->tf_prims_generated
;
2513 fprintf(stderr
, "Skipping query %u\n", query
->type
);
2521 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
2523 struct panfrost_context
*ctx
= pan_context(pipe
);
2524 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2526 switch (query
->type
) {
2527 case PIPE_QUERY_OCCLUSION_COUNTER
:
2528 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2529 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2530 ctx
->occlusion_query
= NULL
;
2532 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2533 query
->end
= ctx
->prims_generated
;
2535 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2536 query
->end
= ctx
->tf_prims_generated
;
2544 panfrost_get_query_result(struct pipe_context
*pipe
,
2545 struct pipe_query
*q
,
2547 union pipe_query_result
*vresult
)
2549 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
2550 struct panfrost_context
*ctx
= pan_context(pipe
);
2553 switch (query
->type
) {
2554 case PIPE_QUERY_OCCLUSION_COUNTER
:
2555 case PIPE_QUERY_OCCLUSION_PREDICATE
:
2556 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
2558 panfrost_flush_all_batches(ctx
, true);
2560 /* Read back the query results */
2561 unsigned *result
= (unsigned *) query
->bo
->cpu
;
2562 unsigned passed
= *result
;
2564 if (query
->type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
2565 vresult
->u64
= passed
;
2567 vresult
->b
= !!passed
;
2572 case PIPE_QUERY_PRIMITIVES_GENERATED
:
2573 case PIPE_QUERY_PRIMITIVES_EMITTED
:
2574 panfrost_flush_all_batches(ctx
, true);
2575 vresult
->u64
= query
->end
- query
->start
;
2579 DBG("Skipped query get %u\n", query
->type
);
2586 static struct pipe_stream_output_target
*
2587 panfrost_create_stream_output_target(struct pipe_context
*pctx
,
2588 struct pipe_resource
*prsc
,
2589 unsigned buffer_offset
,
2590 unsigned buffer_size
)
2592 struct pipe_stream_output_target
*target
;
2594 target
= rzalloc(pctx
, struct pipe_stream_output_target
);
2599 pipe_reference_init(&target
->reference
, 1);
2600 pipe_resource_reference(&target
->buffer
, prsc
);
2602 target
->context
= pctx
;
2603 target
->buffer_offset
= buffer_offset
;
2604 target
->buffer_size
= buffer_size
;
2610 panfrost_stream_output_target_destroy(struct pipe_context
*pctx
,
2611 struct pipe_stream_output_target
*target
)
2613 pipe_resource_reference(&target
->buffer
, NULL
);
2614 ralloc_free(target
);
2618 panfrost_set_stream_output_targets(struct pipe_context
*pctx
,
2619 unsigned num_targets
,
2620 struct pipe_stream_output_target
**targets
,
2621 const unsigned *offsets
)
2623 struct panfrost_context
*ctx
= pan_context(pctx
);
2624 struct panfrost_streamout
*so
= &ctx
->streamout
;
2626 assert(num_targets
<= ARRAY_SIZE(so
->targets
));
2628 for (unsigned i
= 0; i
< num_targets
; i
++) {
2629 if (offsets
[i
] != -1)
2630 so
->offsets
[i
] = offsets
[i
];
2632 pipe_so_target_reference(&so
->targets
[i
], targets
[i
]);
2635 for (unsigned i
= 0; i
< so
->num_targets
; i
++)
2636 pipe_so_target_reference(&so
->targets
[i
], NULL
);
2638 so
->num_targets
= num_targets
;
2641 struct pipe_context
*
2642 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
2644 struct panfrost_context
*ctx
= rzalloc(screen
, struct panfrost_context
);
2645 struct panfrost_screen
*pscreen
= pan_screen(screen
);
2646 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
2648 gallium
->screen
= screen
;
2650 gallium
->destroy
= panfrost_destroy
;
2652 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
2654 gallium
->flush
= panfrost_flush
;
2655 gallium
->clear
= panfrost_clear
;
2656 gallium
->draw_vbo
= panfrost_draw_vbo
;
2658 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
2659 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
2660 gallium
->set_shader_buffers
= panfrost_set_shader_buffers
;
2662 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
2664 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
2665 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
2666 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
2668 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
2669 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
2670 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
2672 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
2673 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
2674 gallium
->delete_vertex_elements_state
= panfrost_generic_cso_delete
;
2676 gallium
->create_fs_state
= panfrost_create_shader_state
;
2677 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
2678 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
2680 gallium
->create_vs_state
= panfrost_create_shader_state
;
2681 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
2682 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
2684 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
2685 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
2686 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
2688 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
2689 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
2690 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
2692 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
2694 gallium
->set_clip_state
= panfrost_set_clip_state
;
2695 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
2696 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
2697 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
2698 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
2700 gallium
->create_query
= panfrost_create_query
;
2701 gallium
->destroy_query
= panfrost_destroy_query
;
2702 gallium
->begin_query
= panfrost_begin_query
;
2703 gallium
->end_query
= panfrost_end_query
;
2704 gallium
->get_query_result
= panfrost_get_query_result
;
2706 gallium
->create_stream_output_target
= panfrost_create_stream_output_target
;
2707 gallium
->stream_output_target_destroy
= panfrost_stream_output_target_destroy
;
2708 gallium
->set_stream_output_targets
= panfrost_set_stream_output_targets
;
2710 panfrost_resource_context_init(gallium
);
2711 panfrost_blend_context_init(gallium
);
2712 panfrost_compute_context_init(gallium
);
2715 gallium
->stream_uploader
= u_upload_create_default(gallium
);
2716 gallium
->const_uploader
= gallium
->stream_uploader
;
2717 assert(gallium
->stream_uploader
);
2719 /* Midgard supports ES modes, plus QUADS/QUAD_STRIPS/POLYGON */
2720 ctx
->draw_modes
= (1 << (PIPE_PRIM_POLYGON
+ 1)) - 1;
2722 ctx
->primconvert
= util_primconvert_create(gallium
, ctx
->draw_modes
);
2724 ctx
->blitter
= util_blitter_create(gallium
);
2725 ctx
->blitter_wallpaper
= util_blitter_create(gallium
);
2727 assert(ctx
->blitter
);
2728 assert(ctx
->blitter_wallpaper
);
2730 /* Prepare for render! */
2732 panfrost_batch_init(ctx
);
2733 panfrost_emit_vertex_payload(ctx
);
2734 panfrost_emit_tiler_payload(ctx
);
2735 panfrost_invalidate_frame(ctx
);
2736 panfrost_default_shader_backend(ctx
);