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_minmax_cache.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"
54 #include "pan_cmdstream.h"
56 #include "pandecode/decode.h"
58 struct midgard_tiler_descriptor
59 panfrost_emit_midg_tiler(struct panfrost_batch
*batch
, unsigned vertex_count
)
61 struct panfrost_device
*device
= pan_device(batch
->ctx
->base
.screen
);
62 bool hierarchy
= !(device
->quirks
& MIDGARD_NO_HIER_TILING
);
63 struct midgard_tiler_descriptor t
= {0};
64 unsigned height
= batch
->key
.height
;
65 unsigned width
= batch
->key
.width
;
68 panfrost_choose_hierarchy_mask(width
, height
, vertex_count
, hierarchy
);
70 /* Compute the polygon header size and use that to offset the body */
72 unsigned header_size
= panfrost_tiler_header_size(
73 width
, height
, t
.hierarchy_mask
, hierarchy
);
75 t
.polygon_list_size
= panfrost_tiler_full_size(
76 width
, height
, t
.hierarchy_mask
, hierarchy
);
81 struct panfrost_bo
*tiler_heap
;
83 tiler_heap
= panfrost_batch_get_tiler_heap(batch
);
84 t
.polygon_list
= panfrost_batch_get_polygon_list(batch
,
89 /* Allow the entire tiler heap */
90 t
.heap_start
= tiler_heap
->gpu
;
91 t
.heap_end
= tiler_heap
->gpu
+ tiler_heap
->size
;
93 struct panfrost_bo
*tiler_dummy
;
95 tiler_dummy
= panfrost_batch_get_tiler_dummy(batch
);
96 header_size
= MALI_TILER_MINIMUM_HEADER_SIZE
;
98 /* The tiler is disabled, so don't allow the tiler heap */
99 t
.heap_start
= tiler_dummy
->gpu
;
100 t
.heap_end
= t
.heap_start
;
102 /* Use a dummy polygon list */
103 t
.polygon_list
= tiler_dummy
->gpu
;
105 /* Disable the tiler */
107 t
.hierarchy_mask
|= MALI_TILER_DISABLED
;
109 t
.hierarchy_mask
= MALI_TILER_USER
;
110 t
.polygon_list_size
= MALI_TILER_MINIMUM_HEADER_SIZE
+ 4;
112 /* We don't have a WRITE_VALUE job, so write the polygon list manually */
113 uint32_t *polygon_list_body
= (uint32_t *) (tiler_dummy
->cpu
+ header_size
);
114 polygon_list_body
[0] = 0xa0000000; /* TODO: Just that? */
118 t
.polygon_list_body
=
119 t
.polygon_list
+ header_size
;
126 struct pipe_context
*pipe
,
128 const struct pipe_scissor_state
*scissor_state
,
129 const union pipe_color_union
*color
,
130 double depth
, unsigned stencil
)
132 struct panfrost_context
*ctx
= pan_context(pipe
);
134 /* TODO: panfrost_get_fresh_batch_for_fbo() instantiates a new batch if
135 * the existing batch targeting this FBO has draws. We could probably
136 * avoid that by replacing plain clears by quad-draws with a specific
137 * color/depth/stencil value, thus avoiding the generation of extra
140 struct panfrost_batch
*batch
= panfrost_get_fresh_batch_for_fbo(ctx
);
142 panfrost_batch_add_fbo_bos(batch
);
143 panfrost_batch_clear(batch
, buffers
, color
, depth
, stencil
);
146 /* Reset per-frame context, called on context initialisation as well as after
147 * flushing a frame */
150 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
152 /* TODO: When does this need to be handled? */
153 ctx
->active_queries
= true;
157 panfrost_writes_point_size(struct panfrost_context
*ctx
)
159 assert(ctx
->shader
[PIPE_SHADER_VERTEX
]);
160 struct panfrost_shader_state
*vs
= panfrost_get_shader_state(ctx
, PIPE_SHADER_VERTEX
);
162 return vs
->writes_point_size
&& ctx
->active_prim
== PIPE_PRIM_POINTS
;
166 panfrost_vertex_state_upd_attr_offs(struct panfrost_context
*ctx
,
167 struct mali_vertex_tiler_postfix
*vertex_postfix
)
172 struct panfrost_vertex_state
*so
= ctx
->vertex
;
174 /* Fixup offsets for the second pass. Recall that the hardware
175 * calculates attribute addresses as:
177 * addr = base + (stride * vtx) + src_offset;
179 * However, on Mali, base must be aligned to 64-bytes, so we
182 * base' = base & ~63 = base - (base & 63)
184 * To compensate when using base' (see emit_vertex_data), we have
185 * to adjust src_offset by the masked off piece:
187 * addr' = base' + (stride * vtx) + (src_offset + (base & 63))
188 * = base - (base & 63) + (stride * vtx) + src_offset + (base & 63)
189 * = base + (stride * vtx) + src_offset
195 unsigned start
= vertex_postfix
->offset_start
;
197 for (unsigned i
= 0; i
< so
->num_elements
; ++i
) {
198 unsigned vbi
= so
->pipe
[i
].vertex_buffer_index
;
199 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[vbi
];
201 /* Adjust by the masked off bits of the offset. Make sure we
202 * read src_offset from so->hw (which is not GPU visible)
203 * rather than target (which is) due to caching effects */
205 unsigned src_offset
= so
->pipe
[i
].src_offset
;
207 /* BOs aligned to 4k so guaranteed aligned to 64 */
208 src_offset
+= (buf
->buffer_offset
& 63);
210 /* Also, somewhat obscurely per-instance data needs to be
211 * offset in response to a delayed start in an indexed draw */
213 if (so
->pipe
[i
].instance_divisor
&& ctx
->instance_count
> 1 && start
)
214 src_offset
-= buf
->stride
* start
;
216 so
->hw
[i
].src_offset
= src_offset
;
220 /* Compute number of UBOs active (more specifically, compute the highest UBO
221 * number addressable -- if there are gaps, include them in the count anyway).
222 * We always include UBO #0 in the count, since we *need* uniforms enabled for
226 panfrost_ubo_count(struct panfrost_context
*ctx
, enum pipe_shader_type stage
)
228 unsigned mask
= ctx
->constant_buffer
[stage
].enabled_mask
| 1;
229 return 32 - __builtin_clz(mask
);
232 /* The entire frame is in memory -- send it off to the kernel! */
236 struct pipe_context
*pipe
,
237 struct pipe_fence_handle
**fence
,
240 struct panfrost_context
*ctx
= pan_context(pipe
);
241 struct util_dynarray fences
;
243 /* We must collect the fences before the flush is done, otherwise we'll
244 * lose track of them.
247 util_dynarray_init(&fences
, NULL
);
248 hash_table_foreach(ctx
->batches
, hentry
) {
249 struct panfrost_batch
*batch
= hentry
->data
;
251 panfrost_batch_fence_reference(batch
->out_sync
);
252 util_dynarray_append(&fences
,
253 struct panfrost_batch_fence
*,
258 /* Submit all pending jobs */
259 panfrost_flush_all_batches(ctx
, false);
262 struct panfrost_fence
*f
= panfrost_fence_create(ctx
, &fences
);
263 pipe
->screen
->fence_reference(pipe
->screen
, fence
, NULL
);
264 *fence
= (struct pipe_fence_handle
*)f
;
266 util_dynarray_foreach(&fences
, struct panfrost_batch_fence
*, fence
)
267 panfrost_batch_fence_unreference(*fence
);
269 util_dynarray_fini(&fences
);
272 if (pan_debug
& PAN_DBG_TRACE
)
273 pandecode_next_frame();
276 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
279 g2m_draw_mode(enum pipe_prim_type mode
)
284 DEFINE_CASE(LINE_LOOP
);
285 DEFINE_CASE(LINE_STRIP
);
286 DEFINE_CASE(TRIANGLES
);
287 DEFINE_CASE(TRIANGLE_STRIP
);
288 DEFINE_CASE(TRIANGLE_FAN
);
290 DEFINE_CASE(QUAD_STRIP
);
291 DEFINE_CASE(POLYGON
);
294 unreachable("Invalid draw mode");
301 panfrost_scissor_culls_everything(struct panfrost_context
*ctx
)
303 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
305 /* Check if we're scissoring at all */
307 if (!(ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
))
310 return (ss
->minx
== ss
->maxx
) || (ss
->miny
== ss
->maxy
);
313 /* Count generated primitives (when there is no geom/tess shaders) for
314 * transform feedback */
317 panfrost_statistics_record(
318 struct panfrost_context
*ctx
,
319 const struct pipe_draw_info
*info
)
321 if (!ctx
->active_queries
)
324 uint32_t prims
= u_prims_for_vertices(info
->mode
, info
->count
);
325 ctx
->prims_generated
+= prims
;
327 if (!ctx
->streamout
.num_targets
)
330 ctx
->tf_prims_generated
+= prims
;
334 panfrost_update_streamout_offsets(struct panfrost_context
*ctx
)
336 for (unsigned i
= 0; i
< ctx
->streamout
.num_targets
; ++i
) {
339 count
= u_stream_outputs_for_vertices(ctx
->active_prim
,
341 ctx
->streamout
.offsets
[i
] += count
;
347 struct pipe_context
*pipe
,
348 const struct pipe_draw_info
*info
)
350 struct panfrost_context
*ctx
= pan_context(pipe
);
352 /* First of all, check the scissor to see if anything is drawn at all.
353 * If it's not, we drop the draw (mostly a conformance issue;
354 * well-behaved apps shouldn't hit this) */
356 if (panfrost_scissor_culls_everything(ctx
))
359 int mode
= info
->mode
;
361 /* Fallback unsupported restart index */
362 unsigned primitive_index
= (1 << (info
->index_size
* 8)) - 1;
364 if (info
->primitive_restart
&& info
->index_size
365 && info
->restart_index
!= primitive_index
) {
366 util_draw_vbo_without_prim_restart(pipe
, info
);
370 /* Fallback for unsupported modes */
372 assert(ctx
->rasterizer
!= NULL
);
374 if (!(ctx
->draw_modes
& (1 << mode
))) {
375 if (mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && !ctx
->rasterizer
->base
.flatshade
) {
376 mode
= PIPE_PRIM_TRIANGLE_FAN
;
378 if (info
->count
< 4) {
379 /* Degenerate case? */
383 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
384 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
389 /* Now that we have a guaranteed terminating path, find the job.
390 * Assignment commented out to prevent unused warning */
392 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
394 panfrost_batch_add_fbo_bos(batch
);
395 panfrost_batch_set_requirements(batch
);
397 /* Take into account a negative bias */
398 ctx
->vertex_count
= info
->count
+ abs(info
->index_bias
);
399 ctx
->instance_count
= info
->instance_count
;
400 ctx
->active_prim
= info
->mode
;
402 struct mali_vertex_tiler_prefix vertex_prefix
, tiler_prefix
;
403 struct mali_vertex_tiler_postfix vertex_postfix
, tiler_postfix
;
404 union midgard_primitive_size primitive_size
;
405 unsigned vertex_count
;
407 panfrost_vt_init(ctx
, PIPE_SHADER_VERTEX
, &vertex_prefix
, &vertex_postfix
);
408 panfrost_vt_init(ctx
, PIPE_SHADER_FRAGMENT
, &tiler_prefix
, &tiler_postfix
);
410 panfrost_vt_set_draw_info(ctx
, info
, g2m_draw_mode(mode
),
411 &vertex_postfix
, &tiler_prefix
,
412 &tiler_postfix
, &vertex_count
,
415 panfrost_statistics_record(ctx
, info
);
417 /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
418 * vertex_count, 1) */
420 panfrost_pack_work_groups_fused(&vertex_prefix
, &tiler_prefix
,
421 1, vertex_count
, info
->instance_count
,
424 /* Emit all sort of descriptors. */
425 panfrost_emit_vertex_data(batch
, &vertex_postfix
);
426 panfrost_emit_varying_descriptor(batch
,
429 &vertex_postfix
, &tiler_postfix
,
431 panfrost_emit_shader_meta(batch
, PIPE_SHADER_VERTEX
, &vertex_postfix
);
432 panfrost_emit_shader_meta(batch
, PIPE_SHADER_FRAGMENT
, &tiler_postfix
);
433 panfrost_emit_vertex_attr_meta(batch
, &vertex_postfix
);
434 panfrost_emit_sampler_descriptors(batch
, PIPE_SHADER_VERTEX
, &vertex_postfix
);
435 panfrost_emit_sampler_descriptors(batch
, PIPE_SHADER_FRAGMENT
, &tiler_postfix
);
436 panfrost_emit_texture_descriptors(batch
, PIPE_SHADER_VERTEX
, &vertex_postfix
);
437 panfrost_emit_texture_descriptors(batch
, PIPE_SHADER_FRAGMENT
, &tiler_postfix
);
438 panfrost_emit_const_buf(batch
, PIPE_SHADER_VERTEX
, &vertex_postfix
);
439 panfrost_emit_const_buf(batch
, PIPE_SHADER_FRAGMENT
, &tiler_postfix
);
440 panfrost_emit_viewport(batch
, &tiler_postfix
);
442 panfrost_vt_update_primitive_size(ctx
, &tiler_prefix
, &primitive_size
);
444 /* Fire off the draw itself */
445 panfrost_emit_vertex_tiler_jobs(batch
, &vertex_prefix
, &vertex_postfix
,
446 &tiler_prefix
, &tiler_postfix
,
449 /* Adjust the batch stack size based on the new shader stack sizes. */
450 panfrost_batch_adjust_stack_size(batch
);
452 /* Increment transform feedback offsets */
453 panfrost_update_streamout_offsets(ctx
);
459 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
465 panfrost_create_rasterizer_state(
466 struct pipe_context
*pctx
,
467 const struct pipe_rasterizer_state
*cso
)
469 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
477 panfrost_bind_rasterizer_state(
478 struct pipe_context
*pctx
,
481 struct panfrost_context
*ctx
= pan_context(pctx
);
483 ctx
->rasterizer
= hwcso
;
488 /* Gauranteed with the core GL call, so don't expose ARB_polygon_offset */
489 assert(ctx
->rasterizer
->base
.offset_clamp
== 0.0);
491 /* Point sprites are emulated */
493 struct panfrost_shader_state
*variant
= panfrost_get_shader_state(ctx
, PIPE_SHADER_FRAGMENT
);
495 if (ctx
->rasterizer
->base
.sprite_coord_enable
|| (variant
&& variant
->point_sprite_mask
))
496 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
500 panfrost_create_vertex_elements_state(
501 struct pipe_context
*pctx
,
502 unsigned num_elements
,
503 const struct pipe_vertex_element
*elements
)
505 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
506 struct panfrost_device
*dev
= pan_device(pctx
->screen
);
508 so
->num_elements
= num_elements
;
509 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
511 for (int i
= 0; i
< num_elements
; ++i
) {
514 enum pipe_format fmt
= elements
[i
].src_format
;
515 const struct util_format_description
*desc
= util_format_description(fmt
);
516 so
->hw
[i
].unknown1
= 0x2;
518 if (dev
->quirks
& HAS_SWIZZLES
)
519 so
->hw
[i
].swizzle
= panfrost_translate_swizzle_4(desc
->swizzle
);
521 so
->hw
[i
].swizzle
= panfrost_bifrost_swizzle(desc
->nr_channels
);
523 enum mali_format hw_format
= panfrost_pipe_format_table
[desc
->format
].hw
;
524 so
->hw
[i
].format
= hw_format
;
528 /* Let's also prepare vertex builtins */
529 so
->hw
[PAN_VERTEX_ID
].format
= MALI_R32UI
;
530 if (dev
->quirks
& HAS_SWIZZLES
)
531 so
->hw
[PAN_VERTEX_ID
].swizzle
= panfrost_get_default_swizzle(1);
533 so
->hw
[PAN_VERTEX_ID
].swizzle
= panfrost_bifrost_swizzle(1);
535 so
->hw
[PAN_INSTANCE_ID
].format
= MALI_R32UI
;
536 if (dev
->quirks
& HAS_SWIZZLES
)
537 so
->hw
[PAN_INSTANCE_ID
].swizzle
= panfrost_get_default_swizzle(1);
539 so
->hw
[PAN_INSTANCE_ID
].swizzle
= panfrost_bifrost_swizzle(1);
545 panfrost_bind_vertex_elements_state(
546 struct pipe_context
*pctx
,
549 struct panfrost_context
*ctx
= pan_context(pctx
);
554 panfrost_create_shader_state(
555 struct pipe_context
*pctx
,
556 const struct pipe_shader_state
*cso
,
557 enum pipe_shader_type stage
)
559 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
562 /* Token deep copy to prevent memory corruption */
564 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
565 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
567 /* Precompile for shader-db if we need to */
568 if (unlikely((pan_debug
& PAN_DBG_PRECOMPILE
) && cso
->type
== PIPE_SHADER_IR_NIR
)) {
569 struct panfrost_context
*ctx
= pan_context(pctx
);
571 struct panfrost_shader_state state
;
572 uint64_t outputs_written
;
574 panfrost_shader_compile(ctx
, PIPE_SHADER_IR_NIR
,
576 tgsi_processor_to_shader_stage(stage
),
577 &state
, &outputs_written
);
584 panfrost_delete_shader_state(
585 struct pipe_context
*pctx
,
588 struct panfrost_shader_variants
*cso
= (struct panfrost_shader_variants
*) so
;
590 if (cso
->base
.type
== PIPE_SHADER_IR_TGSI
) {
591 DBG("Deleting TGSI shader leaks duplicated tokens\n");
594 for (unsigned i
= 0; i
< cso
->variant_count
; ++i
) {
595 struct panfrost_shader_state
*shader_state
= &cso
->variants
[i
];
596 panfrost_bo_unreference(shader_state
->bo
);
597 shader_state
->bo
= NULL
;
605 panfrost_create_sampler_state(
606 struct pipe_context
*pctx
,
607 const struct pipe_sampler_state
*cso
)
609 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
610 struct panfrost_device
*device
= pan_device(pctx
->screen
);
614 if (device
->quirks
& IS_BIFROST
)
615 panfrost_sampler_desc_init_bifrost(cso
, &so
->bifrost_hw
);
617 panfrost_sampler_desc_init(cso
, &so
->midgard_hw
);
623 panfrost_bind_sampler_states(
624 struct pipe_context
*pctx
,
625 enum pipe_shader_type shader
,
626 unsigned start_slot
, unsigned num_sampler
,
629 assert(start_slot
== 0);
631 struct panfrost_context
*ctx
= pan_context(pctx
);
633 /* XXX: Should upload, not just copy? */
634 ctx
->sampler_count
[shader
] = num_sampler
;
635 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
639 panfrost_variant_matches(
640 struct panfrost_context
*ctx
,
641 struct panfrost_shader_state
*variant
,
642 enum pipe_shader_type type
)
644 struct pipe_rasterizer_state
*rasterizer
= &ctx
->rasterizer
->base
;
645 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
647 bool is_fragment
= (type
== PIPE_SHADER_FRAGMENT
);
649 if (is_fragment
&& (alpha
->enabled
|| variant
->alpha_state
.enabled
)) {
650 /* Make sure enable state is at least the same */
651 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
655 /* Check that the contents of the test are the same */
656 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
657 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
659 if (!(same_func
&& same_ref
)) {
664 if (is_fragment
&& rasterizer
&& (rasterizer
->sprite_coord_enable
|
665 variant
->point_sprite_mask
)) {
666 /* Ensure the same varyings are turned to point sprites */
667 if (rasterizer
->sprite_coord_enable
!= variant
->point_sprite_mask
)
670 /* Ensure the orientation is correct */
672 rasterizer
->sprite_coord_mode
==
673 PIPE_SPRITE_COORD_UPPER_LEFT
;
675 if (variant
->point_sprite_upper_left
!= upper_left
)
679 /* Otherwise, we're good to go */
684 * Fix an uncompiled shader's stream output info, and produce a bitmask
685 * of which VARYING_SLOT_* are captured for stream output.
687 * Core Gallium stores output->register_index as a "slot" number, where
688 * slots are assigned consecutively to all outputs in info->outputs_written.
689 * This naive packing of outputs doesn't work for us - we too have slots,
690 * but the layout is defined by the VUE map, which we won't have until we
691 * compile a specific shader variant. So, we remap these and simply store
692 * VARYING_SLOT_* in our copy's output->register_index fields.
694 * We then produce a bitmask of outputs which are used for SO.
696 * Implementation from iris.
700 update_so_info(struct pipe_stream_output_info
*so_info
,
701 uint64_t outputs_written
)
703 uint64_t so_outputs
= 0;
704 uint8_t reverse_map
[64] = {0};
707 while (outputs_written
)
708 reverse_map
[slot
++] = u_bit_scan64(&outputs_written
);
710 for (unsigned i
= 0; i
< so_info
->num_outputs
; i
++) {
711 struct pipe_stream_output
*output
= &so_info
->output
[i
];
713 /* Map Gallium's condensed "slots" back to real VARYING_SLOT_* enums */
714 output
->register_index
= reverse_map
[output
->register_index
];
716 so_outputs
|= 1ull << output
->register_index
;
723 panfrost_bind_shader_state(
724 struct pipe_context
*pctx
,
726 enum pipe_shader_type type
)
728 struct panfrost_context
*ctx
= pan_context(pctx
);
729 ctx
->shader
[type
] = hwcso
;
733 /* Match the appropriate variant */
736 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
738 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
739 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
], type
)) {
746 /* No variant matched, so create a new one */
747 variant
= variants
->variant_count
++;
749 if (variants
->variant_count
> variants
->variant_space
) {
750 unsigned old_space
= variants
->variant_space
;
752 variants
->variant_space
*= 2;
753 if (variants
->variant_space
== 0)
754 variants
->variant_space
= 1;
756 /* Arbitrary limit to stop runaway programs from
757 * creating an unbounded number of shader variants. */
758 assert(variants
->variant_space
< 1024);
760 unsigned msize
= sizeof(struct panfrost_shader_state
);
761 variants
->variants
= realloc(variants
->variants
,
762 variants
->variant_space
* msize
);
764 memset(&variants
->variants
[old_space
], 0,
765 (variants
->variant_space
- old_space
) * msize
);
768 struct panfrost_shader_state
*v
=
769 &variants
->variants
[variant
];
771 if (type
== PIPE_SHADER_FRAGMENT
) {
772 v
->alpha_state
= ctx
->depth_stencil
->alpha
;
774 if (ctx
->rasterizer
) {
775 v
->point_sprite_mask
= ctx
->rasterizer
->base
.sprite_coord_enable
;
776 v
->point_sprite_upper_left
=
777 ctx
->rasterizer
->base
.sprite_coord_mode
==
778 PIPE_SPRITE_COORD_UPPER_LEFT
;
783 /* Select this variant */
784 variants
->active_variant
= variant
;
786 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
787 assert(panfrost_variant_matches(ctx
, shader_state
, type
));
789 /* We finally have a variant, so compile it */
791 if (!shader_state
->compiled
) {
792 uint64_t outputs_written
= 0;
794 panfrost_shader_compile(ctx
, variants
->base
.type
,
795 variants
->base
.type
== PIPE_SHADER_IR_NIR
?
796 variants
->base
.ir
.nir
:
797 variants
->base
.tokens
,
798 tgsi_processor_to_shader_stage(type
),
802 shader_state
->compiled
= true;
804 /* Fixup the stream out information, since what Gallium returns
805 * normally is mildly insane */
807 shader_state
->stream_output
= variants
->base
.stream_output
;
808 shader_state
->so_mask
=
809 update_so_info(&shader_state
->stream_output
, outputs_written
);
814 panfrost_create_vs_state(struct pipe_context
*pctx
, const struct pipe_shader_state
*hwcso
)
816 return panfrost_create_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
820 panfrost_create_fs_state(struct pipe_context
*pctx
, const struct pipe_shader_state
*hwcso
)
822 return panfrost_create_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
826 panfrost_bind_vs_state(struct pipe_context
*pctx
, void *hwcso
)
828 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
832 panfrost_bind_fs_state(struct pipe_context
*pctx
, void *hwcso
)
834 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
838 panfrost_set_vertex_buffers(
839 struct pipe_context
*pctx
,
841 unsigned num_buffers
,
842 const struct pipe_vertex_buffer
*buffers
)
844 struct panfrost_context
*ctx
= pan_context(pctx
);
846 util_set_vertex_buffers_mask(ctx
->vertex_buffers
, &ctx
->vb_mask
, buffers
, start_slot
, num_buffers
);
850 panfrost_set_constant_buffer(
851 struct pipe_context
*pctx
,
852 enum pipe_shader_type shader
, uint index
,
853 const struct pipe_constant_buffer
*buf
)
855 struct panfrost_context
*ctx
= pan_context(pctx
);
856 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
858 util_copy_constant_buffer(&pbuf
->cb
[index
], buf
);
860 unsigned mask
= (1 << index
);
862 if (unlikely(!buf
)) {
863 pbuf
->enabled_mask
&= ~mask
;
864 pbuf
->dirty_mask
&= ~mask
;
868 pbuf
->enabled_mask
|= mask
;
869 pbuf
->dirty_mask
|= mask
;
873 panfrost_set_stencil_ref(
874 struct pipe_context
*pctx
,
875 const struct pipe_stencil_ref
*ref
)
877 struct panfrost_context
*ctx
= pan_context(pctx
);
878 ctx
->stencil_ref
= *ref
;
881 static enum mali_texture_type
882 panfrost_translate_texture_type(enum pipe_texture_target t
) {
886 case PIPE_TEXTURE_1D
:
887 case PIPE_TEXTURE_1D_ARRAY
:
890 case PIPE_TEXTURE_2D
:
891 case PIPE_TEXTURE_2D_ARRAY
:
892 case PIPE_TEXTURE_RECT
:
895 case PIPE_TEXTURE_3D
:
898 case PIPE_TEXTURE_CUBE
:
899 case PIPE_TEXTURE_CUBE_ARRAY
:
900 return MALI_TEX_CUBE
;
903 unreachable("Unknown target");
907 static struct pipe_sampler_view
*
908 panfrost_create_sampler_view(
909 struct pipe_context
*pctx
,
910 struct pipe_resource
*texture
,
911 const struct pipe_sampler_view
*template)
913 struct panfrost_device
*device
= pan_device(pctx
->screen
);
914 struct panfrost_sampler_view
*so
= rzalloc(pctx
, struct panfrost_sampler_view
);
916 pipe_reference(NULL
, &texture
->reference
);
918 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
921 so
->base
= *template;
922 so
->base
.texture
= texture
;
923 so
->base
.reference
.count
= 1;
924 so
->base
.context
= pctx
;
926 unsigned char user_swizzle
[4] = {
933 /* In the hardware, array_size refers specifically to array textures,
934 * whereas in Gallium, it also covers cubemaps */
936 unsigned array_size
= texture
->array_size
;
938 if (template->target
== PIPE_TEXTURE_CUBE
) {
939 /* TODO: Cubemap arrays */
940 assert(array_size
== 6);
944 enum mali_texture_type type
=
945 panfrost_translate_texture_type(template->target
);
947 if (device
->quirks
& IS_BIFROST
) {
948 const struct util_format_description
*desc
=
949 util_format_description(template->format
);
950 unsigned char composed_swizzle
[4];
951 util_format_compose_swizzles(desc
->swizzle
, user_swizzle
, composed_swizzle
);
953 unsigned size
= panfrost_estimate_texture_payload_size(
954 template->u
.tex
.first_level
,
955 template->u
.tex
.last_level
,
956 template->u
.tex
.first_layer
,
957 template->u
.tex
.last_layer
,
958 type
, prsrc
->layout
);
960 so
->bifrost_bo
= pan_bo_create(device
, size
, 0);
962 so
->bifrost_descriptor
= rzalloc(pctx
, struct bifrost_texture_descriptor
);
963 panfrost_new_texture_bifrost(
964 so
->bifrost_descriptor
,
965 texture
->width0
, texture
->height0
,
966 texture
->depth0
, array_size
,
969 template->u
.tex
.first_level
,
970 template->u
.tex
.last_level
,
971 template->u
.tex
.first_layer
,
972 template->u
.tex
.last_layer
,
973 prsrc
->cubemap_stride
,
974 panfrost_translate_swizzle_4(composed_swizzle
),
979 unsigned size
= panfrost_estimate_texture_payload_size(
980 template->u
.tex
.first_level
,
981 template->u
.tex
.last_level
,
982 template->u
.tex
.first_layer
,
983 template->u
.tex
.last_layer
,
984 type
, prsrc
->layout
);
985 size
+= sizeof(struct mali_texture_descriptor
);
987 so
->midgard_bo
= pan_bo_create(device
, size
, 0);
989 panfrost_new_texture(
991 texture
->width0
, texture
->height0
,
992 texture
->depth0
, array_size
,
995 template->u
.tex
.first_level
,
996 template->u
.tex
.last_level
,
997 template->u
.tex
.first_layer
,
998 template->u
.tex
.last_layer
,
999 prsrc
->cubemap_stride
,
1000 panfrost_translate_swizzle_4(user_swizzle
),
1005 return (struct pipe_sampler_view
*) so
;
1009 panfrost_set_sampler_views(
1010 struct pipe_context
*pctx
,
1011 enum pipe_shader_type shader
,
1012 unsigned start_slot
, unsigned num_views
,
1013 struct pipe_sampler_view
**views
)
1015 struct panfrost_context
*ctx
= pan_context(pctx
);
1016 unsigned new_nr
= 0;
1019 assert(start_slot
== 0);
1021 for (i
= 0; i
< num_views
; ++i
) {
1024 pipe_sampler_view_reference((struct pipe_sampler_view
**)&ctx
->sampler_views
[shader
][i
],
1028 for (; i
< ctx
->sampler_view_count
[shader
]; i
++) {
1029 pipe_sampler_view_reference((struct pipe_sampler_view
**)&ctx
->sampler_views
[shader
][i
],
1032 ctx
->sampler_view_count
[shader
] = new_nr
;
1036 panfrost_sampler_view_destroy(
1037 struct pipe_context
*pctx
,
1038 struct pipe_sampler_view
*pview
)
1040 struct panfrost_sampler_view
*view
= (struct panfrost_sampler_view
*) pview
;
1042 pipe_resource_reference(&pview
->texture
, NULL
);
1043 panfrost_bo_unreference(view
->midgard_bo
);
1044 panfrost_bo_unreference(view
->bifrost_bo
);
1045 if (view
->bifrost_descriptor
)
1046 ralloc_free(view
->bifrost_descriptor
);
1051 panfrost_set_shader_buffers(
1052 struct pipe_context
*pctx
,
1053 enum pipe_shader_type shader
,
1054 unsigned start
, unsigned count
,
1055 const struct pipe_shader_buffer
*buffers
,
1056 unsigned writable_bitmask
)
1058 struct panfrost_context
*ctx
= pan_context(pctx
);
1060 util_set_shader_buffers_mask(ctx
->ssbo
[shader
], &ctx
->ssbo_mask
[shader
],
1061 buffers
, start
, count
);
1064 /* Hints that a framebuffer should use AFBC where possible */
1068 struct panfrost_device
*device
,
1069 const struct pipe_framebuffer_state
*fb
)
1071 /* AFBC implemenation incomplete; hide it */
1072 if (!(pan_debug
& PAN_DBG_AFBC
)) return;
1074 /* Hint AFBC to the resources bound to each color buffer */
1076 for (unsigned i
= 0; i
< fb
->nr_cbufs
; ++i
) {
1077 struct pipe_surface
*surf
= fb
->cbufs
[i
];
1078 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
1079 panfrost_resource_hint_layout(device
, rsrc
, MALI_TEXTURE_AFBC
, 1);
1082 /* Also hint it to the depth buffer */
1085 struct panfrost_resource
*rsrc
= pan_resource(fb
->zsbuf
->texture
);
1086 panfrost_resource_hint_layout(device
, rsrc
, MALI_TEXTURE_AFBC
, 1);
1091 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
1092 const struct pipe_framebuffer_state
*fb
)
1094 struct panfrost_context
*ctx
= pan_context(pctx
);
1096 panfrost_hint_afbc(pan_device(pctx
->screen
), fb
);
1097 util_copy_framebuffer_state(&ctx
->pipe_framebuffer
, fb
);
1099 panfrost_invalidate_frame(ctx
);
1103 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
1104 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
1106 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
1110 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
1113 struct panfrost_context
*ctx
= pan_context(pipe
);
1114 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
1115 ctx
->depth_stencil
= depth_stencil
;
1120 /* Alpha does not exist in the hardware (it's not in ES3), so it's
1121 * emulated in the fragment shader */
1123 if (depth_stencil
->alpha
.enabled
) {
1124 /* We need to trigger a new shader (maybe) */
1125 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
1128 /* Bounds test not implemented */
1129 assert(!depth_stencil
->depth
.bounds_test
);
1133 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
1139 panfrost_set_sample_mask(struct pipe_context
*pipe
,
1140 unsigned sample_mask
)
1145 panfrost_set_clip_state(struct pipe_context
*pipe
,
1146 const struct pipe_clip_state
*clip
)
1148 //struct panfrost_context *panfrost = pan_context(pipe);
1152 panfrost_set_viewport_states(struct pipe_context
*pipe
,
1153 unsigned start_slot
,
1154 unsigned num_viewports
,
1155 const struct pipe_viewport_state
*viewports
)
1157 struct panfrost_context
*ctx
= pan_context(pipe
);
1159 assert(start_slot
== 0);
1160 assert(num_viewports
== 1);
1162 ctx
->pipe_viewport
= *viewports
;
1166 panfrost_set_scissor_states(struct pipe_context
*pipe
,
1167 unsigned start_slot
,
1168 unsigned num_scissors
,
1169 const struct pipe_scissor_state
*scissors
)
1171 struct panfrost_context
*ctx
= pan_context(pipe
);
1173 assert(start_slot
== 0);
1174 assert(num_scissors
== 1);
1176 ctx
->scissor
= *scissors
;
1180 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
1181 const struct pipe_poly_stipple
*stipple
)
1183 //struct panfrost_context *panfrost = pan_context(pipe);
1187 panfrost_set_active_query_state(struct pipe_context
*pipe
,
1190 struct panfrost_context
*ctx
= pan_context(pipe
);
1191 ctx
->active_queries
= enable
;
1195 panfrost_destroy(struct pipe_context
*pipe
)
1197 struct panfrost_context
*panfrost
= pan_context(pipe
);
1199 if (panfrost
->blitter
)
1200 util_blitter_destroy(panfrost
->blitter
);
1202 if (panfrost
->blitter_wallpaper
)
1203 util_blitter_destroy(panfrost
->blitter_wallpaper
);
1205 util_unreference_framebuffer_state(&panfrost
->pipe_framebuffer
);
1206 u_upload_destroy(pipe
->stream_uploader
);
1211 static struct pipe_query
*
1212 panfrost_create_query(struct pipe_context
*pipe
,
1216 struct panfrost_query
*q
= rzalloc(pipe
, struct panfrost_query
);
1221 return (struct pipe_query
*) q
;
1225 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1227 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1230 panfrost_bo_unreference(query
->bo
);
1238 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1240 struct panfrost_context
*ctx
= pan_context(pipe
);
1241 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1243 switch (query
->type
) {
1244 case PIPE_QUERY_OCCLUSION_COUNTER
:
1245 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1246 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1247 /* Allocate a bo for the query results to be stored */
1249 query
->bo
= pan_bo_create(
1250 pan_device(ctx
->base
.screen
),
1251 sizeof(unsigned), 0);
1254 unsigned *result
= (unsigned *)query
->bo
->cpu
;
1255 *result
= 0; /* Default to 0 if nothing at all drawn. */
1256 ctx
->occlusion_query
= query
;
1259 /* Geometry statistics are computed in the driver. XXX: geom/tess
1262 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1263 query
->start
= ctx
->prims_generated
;
1265 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1266 query
->start
= ctx
->tf_prims_generated
;
1270 DBG("Skipping query %u\n", query
->type
);
1278 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1280 struct panfrost_context
*ctx
= pan_context(pipe
);
1281 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1283 switch (query
->type
) {
1284 case PIPE_QUERY_OCCLUSION_COUNTER
:
1285 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1286 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1287 ctx
->occlusion_query
= NULL
;
1289 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1290 query
->end
= ctx
->prims_generated
;
1292 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1293 query
->end
= ctx
->tf_prims_generated
;
1301 panfrost_get_query_result(struct pipe_context
*pipe
,
1302 struct pipe_query
*q
,
1304 union pipe_query_result
*vresult
)
1306 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1307 struct panfrost_context
*ctx
= pan_context(pipe
);
1310 switch (query
->type
) {
1311 case PIPE_QUERY_OCCLUSION_COUNTER
:
1312 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1313 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1315 panfrost_flush_all_batches(ctx
, true);
1317 /* Read back the query results */
1318 unsigned *result
= (unsigned *) query
->bo
->cpu
;
1319 unsigned passed
= *result
;
1321 if (query
->type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
1322 vresult
->u64
= passed
;
1324 vresult
->b
= !!passed
;
1329 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1330 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1331 panfrost_flush_all_batches(ctx
, true);
1332 vresult
->u64
= query
->end
- query
->start
;
1336 DBG("Skipped query get %u\n", query
->type
);
1343 static struct pipe_stream_output_target
*
1344 panfrost_create_stream_output_target(struct pipe_context
*pctx
,
1345 struct pipe_resource
*prsc
,
1346 unsigned buffer_offset
,
1347 unsigned buffer_size
)
1349 struct pipe_stream_output_target
*target
;
1351 target
= rzalloc(pctx
, struct pipe_stream_output_target
);
1356 pipe_reference_init(&target
->reference
, 1);
1357 pipe_resource_reference(&target
->buffer
, prsc
);
1359 target
->context
= pctx
;
1360 target
->buffer_offset
= buffer_offset
;
1361 target
->buffer_size
= buffer_size
;
1367 panfrost_stream_output_target_destroy(struct pipe_context
*pctx
,
1368 struct pipe_stream_output_target
*target
)
1370 pipe_resource_reference(&target
->buffer
, NULL
);
1371 ralloc_free(target
);
1375 panfrost_set_stream_output_targets(struct pipe_context
*pctx
,
1376 unsigned num_targets
,
1377 struct pipe_stream_output_target
**targets
,
1378 const unsigned *offsets
)
1380 struct panfrost_context
*ctx
= pan_context(pctx
);
1381 struct panfrost_streamout
*so
= &ctx
->streamout
;
1383 assert(num_targets
<= ARRAY_SIZE(so
->targets
));
1385 for (unsigned i
= 0; i
< num_targets
; i
++) {
1386 if (offsets
[i
] != -1)
1387 so
->offsets
[i
] = offsets
[i
];
1389 pipe_so_target_reference(&so
->targets
[i
], targets
[i
]);
1392 for (unsigned i
= 0; i
< so
->num_targets
; i
++)
1393 pipe_so_target_reference(&so
->targets
[i
], NULL
);
1395 so
->num_targets
= num_targets
;
1398 struct pipe_context
*
1399 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
1401 struct panfrost_context
*ctx
= rzalloc(screen
, struct panfrost_context
);
1402 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
1404 gallium
->screen
= screen
;
1406 gallium
->destroy
= panfrost_destroy
;
1408 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
1410 gallium
->flush
= panfrost_flush
;
1411 gallium
->clear
= panfrost_clear
;
1412 gallium
->draw_vbo
= panfrost_draw_vbo
;
1414 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
1415 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
1416 gallium
->set_shader_buffers
= panfrost_set_shader_buffers
;
1418 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
1420 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
1421 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
1422 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
1424 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
1425 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
1426 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
1428 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
1429 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
1430 gallium
->delete_vertex_elements_state
= panfrost_generic_cso_delete
;
1432 gallium
->create_fs_state
= panfrost_create_fs_state
;
1433 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
1434 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
1436 gallium
->create_vs_state
= panfrost_create_vs_state
;
1437 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
1438 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
1440 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
1441 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
1442 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
1444 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
1445 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
1446 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
1448 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
1450 gallium
->set_clip_state
= panfrost_set_clip_state
;
1451 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
1452 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
1453 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
1454 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
1456 gallium
->create_query
= panfrost_create_query
;
1457 gallium
->destroy_query
= panfrost_destroy_query
;
1458 gallium
->begin_query
= panfrost_begin_query
;
1459 gallium
->end_query
= panfrost_end_query
;
1460 gallium
->get_query_result
= panfrost_get_query_result
;
1462 gallium
->create_stream_output_target
= panfrost_create_stream_output_target
;
1463 gallium
->stream_output_target_destroy
= panfrost_stream_output_target_destroy
;
1464 gallium
->set_stream_output_targets
= panfrost_set_stream_output_targets
;
1466 panfrost_resource_context_init(gallium
);
1467 panfrost_blend_context_init(gallium
);
1468 panfrost_compute_context_init(gallium
);
1471 gallium
->stream_uploader
= u_upload_create_default(gallium
);
1472 gallium
->const_uploader
= gallium
->stream_uploader
;
1473 assert(gallium
->stream_uploader
);
1475 /* Midgard supports ES modes, plus QUADS/QUAD_STRIPS/POLYGON */
1476 ctx
->draw_modes
= (1 << (PIPE_PRIM_POLYGON
+ 1)) - 1;
1478 ctx
->primconvert
= util_primconvert_create(gallium
, ctx
->draw_modes
);
1480 ctx
->blitter
= util_blitter_create(gallium
);
1481 ctx
->blitter_wallpaper
= util_blitter_create(gallium
);
1483 assert(ctx
->blitter
);
1484 assert(ctx
->blitter_wallpaper
);
1486 /* Prepare for render! */
1488 panfrost_batch_init(ctx
);
1489 panfrost_invalidate_frame(ctx
);