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_screen
*screen
= pan_screen(batch
->ctx
->base
.screen
);
62 bool hierarchy
= !(screen
->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 union pipe_color_union
*color
,
129 double depth
, unsigned stencil
)
131 struct panfrost_context
*ctx
= pan_context(pipe
);
133 /* TODO: panfrost_get_fresh_batch_for_fbo() instantiates a new batch if
134 * the existing batch targeting this FBO has draws. We could probably
135 * avoid that by replacing plain clears by quad-draws with a specific
136 * color/depth/stencil value, thus avoiding the generation of extra
139 struct panfrost_batch
*batch
= panfrost_get_fresh_batch_for_fbo(ctx
);
141 panfrost_batch_add_fbo_bos(batch
);
142 panfrost_batch_clear(batch
, buffers
, color
, depth
, stencil
);
145 /* Reset per-frame context, called on context initialisation as well as after
146 * flushing a frame */
149 panfrost_invalidate_frame(struct panfrost_context
*ctx
)
151 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
)
152 ctx
->payloads
[i
].postfix
.shared_memory
= 0;
154 /* TODO: When does this need to be handled? */
155 ctx
->active_queries
= true;
158 /* In practice, every field of these payloads should be configurable
159 * arbitrarily, which means these functions are basically catch-all's for
160 * as-of-yet unwavering unknowns */
163 panfrost_emit_vertex_payload(struct panfrost_context
*ctx
)
165 /* 0x2 bit clear on 32-bit T6XX */
167 struct midgard_payload_vertex_tiler payload
= {
168 .gl_enables
= 0x4 | 0x2,
171 /* Vertex and compute are closely coupled, so share a payload */
173 memcpy(&ctx
->payloads
[PIPE_SHADER_VERTEX
], &payload
, sizeof(payload
));
174 memcpy(&ctx
->payloads
[PIPE_SHADER_COMPUTE
], &payload
, sizeof(payload
));
178 panfrost_writes_point_size(struct panfrost_context
*ctx
)
180 assert(ctx
->shader
[PIPE_SHADER_VERTEX
]);
181 struct panfrost_shader_state
*vs
= panfrost_get_shader_state(ctx
, PIPE_SHADER_VERTEX
);
183 return vs
->writes_point_size
&& ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
== MALI_POINTS
;
187 panfrost_vertex_state_upd_attr_offs(struct panfrost_context
*ctx
,
188 struct midgard_payload_vertex_tiler
*vp
)
193 struct panfrost_vertex_state
*so
= ctx
->vertex
;
195 /* Fixup offsets for the second pass. Recall that the hardware
196 * calculates attribute addresses as:
198 * addr = base + (stride * vtx) + src_offset;
200 * However, on Mali, base must be aligned to 64-bytes, so we
203 * base' = base & ~63 = base - (base & 63)
205 * To compensate when using base' (see emit_vertex_data), we have
206 * to adjust src_offset by the masked off piece:
208 * addr' = base' + (stride * vtx) + (src_offset + (base & 63))
209 * = base - (base & 63) + (stride * vtx) + src_offset + (base & 63)
210 * = base + (stride * vtx) + src_offset
216 unsigned start
= vp
->offset_start
;
218 for (unsigned i
= 0; i
< so
->num_elements
; ++i
) {
219 unsigned vbi
= so
->pipe
[i
].vertex_buffer_index
;
220 struct pipe_vertex_buffer
*buf
= &ctx
->vertex_buffers
[vbi
];
222 /* Adjust by the masked off bits of the offset. Make sure we
223 * read src_offset from so->hw (which is not GPU visible)
224 * rather than target (which is) due to caching effects */
226 unsigned src_offset
= so
->pipe
[i
].src_offset
;
228 /* BOs aligned to 4k so guaranteed aligned to 64 */
229 src_offset
+= (buf
->buffer_offset
& 63);
231 /* Also, somewhat obscurely per-instance data needs to be
232 * offset in response to a delayed start in an indexed draw */
234 if (so
->pipe
[i
].instance_divisor
&& ctx
->instance_count
> 1 && start
)
235 src_offset
-= buf
->stride
* start
;
237 so
->hw
[i
].src_offset
= src_offset
;
241 /* Compute number of UBOs active (more specifically, compute the highest UBO
242 * number addressable -- if there are gaps, include them in the count anyway).
243 * We always include UBO #0 in the count, since we *need* uniforms enabled for
247 panfrost_ubo_count(struct panfrost_context
*ctx
, enum pipe_shader_type stage
)
249 unsigned mask
= ctx
->constant_buffer
[stage
].enabled_mask
| 1;
250 return 32 - __builtin_clz(mask
);
253 /* Go through dirty flags and actualise them in the cmdstream. */
256 panfrost_emit_for_draw(struct panfrost_context
*ctx
)
258 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
260 panfrost_batch_add_fbo_bos(batch
);
262 for (int i
= 0; i
<= PIPE_SHADER_FRAGMENT
; ++i
)
263 panfrost_vt_attach_framebuffer(ctx
, &ctx
->payloads
[i
]);
265 panfrost_emit_vertex_data(batch
);
267 /* Varyings emitted for -all- geometry */
268 unsigned total_count
= ctx
->padded_count
* ctx
->instance_count
;
269 panfrost_emit_varying_descriptor(ctx
, total_count
);
271 panfrost_batch_set_requirements(batch
);
273 panfrost_vt_update_rasterizer(ctx
, &ctx
->payloads
[PIPE_SHADER_FRAGMENT
]);
274 panfrost_vt_update_occlusion_query(ctx
, &ctx
->payloads
[PIPE_SHADER_FRAGMENT
]);
276 panfrost_emit_shader_meta(batch
, PIPE_SHADER_VERTEX
,
277 &ctx
->payloads
[PIPE_SHADER_VERTEX
]);
278 panfrost_emit_shader_meta(batch
, PIPE_SHADER_FRAGMENT
,
279 &ctx
->payloads
[PIPE_SHADER_FRAGMENT
]);
281 panfrost_emit_vertex_attr_meta(batch
,
282 &ctx
->payloads
[PIPE_SHADER_VERTEX
]);
284 for (int i
= 0; i
<= PIPE_SHADER_FRAGMENT
; ++i
) {
285 panfrost_emit_sampler_descriptors(batch
, i
, &ctx
->payloads
[i
]);
286 panfrost_emit_texture_descriptors(batch
, i
, &ctx
->payloads
[i
]);
287 panfrost_emit_const_buf(batch
, i
, &ctx
->payloads
[i
]);
290 /* TODO: Upload the viewport somewhere more appropriate */
292 panfrost_emit_viewport(batch
, &ctx
->payloads
[PIPE_SHADER_FRAGMENT
]);
295 /* Corresponds to exactly one draw, but does not submit anything */
298 panfrost_queue_draw(struct panfrost_context
*ctx
)
300 /* Handle dirty flags now */
301 panfrost_emit_for_draw(ctx
);
303 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
305 panfrost_emit_vertex_tiler_jobs(batch
,
306 &ctx
->payloads
[PIPE_SHADER_VERTEX
],
307 &ctx
->payloads
[PIPE_SHADER_FRAGMENT
]);
308 panfrost_batch_adjust_stack_size(batch
);
311 /* The entire frame is in memory -- send it off to the kernel! */
315 struct pipe_context
*pipe
,
316 struct pipe_fence_handle
**fence
,
319 struct panfrost_context
*ctx
= pan_context(pipe
);
320 struct util_dynarray fences
;
322 /* We must collect the fences before the flush is done, otherwise we'll
323 * lose track of them.
326 util_dynarray_init(&fences
, NULL
);
327 hash_table_foreach(ctx
->batches
, hentry
) {
328 struct panfrost_batch
*batch
= hentry
->data
;
330 panfrost_batch_fence_reference(batch
->out_sync
);
331 util_dynarray_append(&fences
,
332 struct panfrost_batch_fence
*,
337 /* Submit all pending jobs */
338 panfrost_flush_all_batches(ctx
, false);
341 struct panfrost_fence
*f
= panfrost_fence_create(ctx
, &fences
);
342 pipe
->screen
->fence_reference(pipe
->screen
, fence
, NULL
);
343 *fence
= (struct pipe_fence_handle
*)f
;
345 util_dynarray_foreach(&fences
, struct panfrost_batch_fence
*, fence
)
346 panfrost_batch_fence_unreference(*fence
);
348 util_dynarray_fini(&fences
);
351 if (pan_debug
& PAN_DBG_TRACE
)
352 pandecode_next_frame();
355 #define DEFINE_CASE(c) case PIPE_PRIM_##c: return MALI_##c;
358 g2m_draw_mode(enum pipe_prim_type mode
)
363 DEFINE_CASE(LINE_LOOP
);
364 DEFINE_CASE(LINE_STRIP
);
365 DEFINE_CASE(TRIANGLES
);
366 DEFINE_CASE(TRIANGLE_STRIP
);
367 DEFINE_CASE(TRIANGLE_FAN
);
369 DEFINE_CASE(QUAD_STRIP
);
370 DEFINE_CASE(POLYGON
);
373 unreachable("Invalid draw mode");
380 panfrost_translate_index_size(unsigned size
)
384 return MALI_DRAW_INDEXED_UINT8
;
387 return MALI_DRAW_INDEXED_UINT16
;
390 return MALI_DRAW_INDEXED_UINT32
;
393 unreachable("Invalid index size");
397 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
398 * good for the duration of the draw (transient), could last longer. Also get
399 * the bounds on the index buffer for the range accessed by the draw. We do
400 * these operations together because there are natural optimizations which
401 * require them to be together. */
404 panfrost_get_index_buffer_bounded(struct panfrost_context
*ctx
, const struct pipe_draw_info
*info
, unsigned *min_index
, unsigned *max_index
)
406 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) (info
->index
.resource
);
408 off_t offset
= info
->start
* info
->index_size
;
409 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
412 bool needs_indices
= true;
414 if (info
->max_index
!= ~0u) {
415 *min_index
= info
->min_index
;
416 *max_index
= info
->max_index
;
417 needs_indices
= false;
420 if (!info
->has_user_indices
) {
421 /* Only resources can be directly mapped */
422 panfrost_batch_add_bo(batch
, rsrc
->bo
,
423 PAN_BO_ACCESS_SHARED
|
425 PAN_BO_ACCESS_VERTEX_TILER
);
426 out
= rsrc
->bo
->gpu
+ offset
;
428 /* Check the cache */
429 needs_indices
= !panfrost_minmax_cache_get(rsrc
->index_cache
, info
->start
, info
->count
,
430 min_index
, max_index
);
432 /* Otherwise, we need to upload to transient memory */
433 const uint8_t *ibuf8
= (const uint8_t *) info
->index
.user
;
434 out
= panfrost_upload_transient(batch
, ibuf8
+ offset
, info
->count
* info
->index_size
);
439 u_vbuf_get_minmax_index(&ctx
->base
, info
, min_index
, max_index
);
441 if (!info
->has_user_indices
) {
442 panfrost_minmax_cache_add(rsrc
->index_cache
, info
->start
, info
->count
,
443 *min_index
, *max_index
);
452 panfrost_scissor_culls_everything(struct panfrost_context
*ctx
)
454 const struct pipe_scissor_state
*ss
= &ctx
->scissor
;
456 /* Check if we're scissoring at all */
458 if (!(ctx
->rasterizer
&& ctx
->rasterizer
->base
.scissor
))
461 return (ss
->minx
== ss
->maxx
) || (ss
->miny
== ss
->maxy
);
464 /* Count generated primitives (when there is no geom/tess shaders) for
465 * transform feedback */
468 panfrost_statistics_record(
469 struct panfrost_context
*ctx
,
470 const struct pipe_draw_info
*info
)
472 if (!ctx
->active_queries
)
475 uint32_t prims
= u_prims_for_vertices(info
->mode
, info
->count
);
476 ctx
->prims_generated
+= prims
;
478 if (!ctx
->streamout
.num_targets
)
481 ctx
->tf_prims_generated
+= prims
;
486 struct pipe_context
*pipe
,
487 const struct pipe_draw_info
*info
)
489 struct panfrost_context
*ctx
= pan_context(pipe
);
491 /* First of all, check the scissor to see if anything is drawn at all.
492 * If it's not, we drop the draw (mostly a conformance issue;
493 * well-behaved apps shouldn't hit this) */
495 if (panfrost_scissor_culls_everything(ctx
))
498 int mode
= info
->mode
;
500 /* Fallback unsupported restart index */
501 unsigned primitive_index
= (1 << (info
->index_size
* 8)) - 1;
503 if (info
->primitive_restart
&& info
->index_size
504 && info
->restart_index
!= primitive_index
) {
505 util_draw_vbo_without_prim_restart(pipe
, info
);
509 /* Fallback for unsupported modes */
511 assert(ctx
->rasterizer
!= NULL
);
513 if (!(ctx
->draw_modes
& (1 << mode
))) {
514 if (mode
== PIPE_PRIM_QUADS
&& info
->count
== 4 && !ctx
->rasterizer
->base
.flatshade
) {
515 mode
= PIPE_PRIM_TRIANGLE_FAN
;
517 if (info
->count
< 4) {
518 /* Degenerate case? */
522 util_primconvert_save_rasterizer_state(ctx
->primconvert
, &ctx
->rasterizer
->base
);
523 util_primconvert_draw_vbo(ctx
->primconvert
, info
);
528 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= info
->start
;
529 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= info
->start
;
531 /* Now that we have a guaranteed terminating path, find the job.
532 * Assignment commented out to prevent unused warning */
534 /* struct panfrost_batch *batch = */ panfrost_get_batch_for_fbo(ctx
);
536 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.draw_mode
= g2m_draw_mode(mode
);
538 /* Take into account a negative bias */
539 ctx
->vertex_count
= info
->count
+ abs(info
->index_bias
);
540 ctx
->instance_count
= info
->instance_count
;
541 ctx
->active_prim
= info
->mode
;
543 /* For non-indexed draws, they're the same */
544 unsigned vertex_count
= ctx
->vertex_count
;
546 unsigned draw_flags
= 0;
548 /* The draw flags interpret how primitive size is interpreted */
550 if (panfrost_writes_point_size(ctx
))
551 draw_flags
|= MALI_DRAW_VARYING_SIZE
;
553 if (info
->primitive_restart
)
554 draw_flags
|= MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX
;
556 /* These doesn't make much sense */
558 draw_flags
|= 0x3000;
560 if (ctx
->rasterizer
&& ctx
->rasterizer
->base
.flatshade_first
)
561 draw_flags
|= MALI_DRAW_FLATSHADE_FIRST
;
563 panfrost_statistics_record(ctx
, info
);
565 if (info
->index_size
) {
566 unsigned min_index
= 0, max_index
= 0;
567 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
=
568 panfrost_get_index_buffer_bounded(ctx
, info
, &min_index
, &max_index
);
570 /* Use the corresponding values */
571 vertex_count
= max_index
- min_index
+ 1;
572 ctx
->payloads
[PIPE_SHADER_VERTEX
].offset_start
= min_index
+ info
->index_bias
;
573 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].offset_start
= min_index
+ info
->index_bias
;
575 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= -min_index
;
576 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(info
->count
);
578 draw_flags
|= panfrost_translate_index_size(info
->index_size
);
580 /* Index count == vertex count, if no indexing is applied, as
581 * if it is internally indexed in the expected order */
583 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.offset_bias_correction
= 0;
584 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.index_count
= MALI_POSITIVE(ctx
->vertex_count
);
586 /* Reverse index state */
587 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.indices
= (mali_ptr
) 0;
590 /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
591 * vertex_count, 1) */
593 panfrost_pack_work_groups_fused(
594 &ctx
->payloads
[PIPE_SHADER_VERTEX
].prefix
,
595 &ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
,
596 1, vertex_count
, info
->instance_count
,
599 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].prefix
.unknown_draw
= draw_flags
;
601 /* Encode the padded vertex count */
603 if (info
->instance_count
> 1) {
604 ctx
->padded_count
= panfrost_padded_vertex_count(vertex_count
);
606 unsigned shift
= __builtin_ctz(ctx
->padded_count
);
607 unsigned k
= ctx
->padded_count
>> (shift
+ 1);
609 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= shift
;
610 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= shift
;
612 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= k
;
613 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= k
;
615 ctx
->padded_count
= vertex_count
;
617 /* Reset instancing state */
618 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_shift
= 0;
619 ctx
->payloads
[PIPE_SHADER_VERTEX
].instance_odd
= 0;
620 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_shift
= 0;
621 ctx
->payloads
[PIPE_SHADER_FRAGMENT
].instance_odd
= 0;
624 /* Fire off the draw itself */
625 panfrost_queue_draw(ctx
);
627 /* Increment transform feedback offsets */
629 for (unsigned i
= 0; i
< ctx
->streamout
.num_targets
; ++i
) {
630 unsigned output_count
= u_stream_outputs_for_vertices(
631 ctx
->active_prim
, ctx
->vertex_count
);
633 ctx
->streamout
.offsets
[i
] += output_count
;
640 panfrost_generic_cso_delete(struct pipe_context
*pctx
, void *hwcso
)
646 panfrost_create_rasterizer_state(
647 struct pipe_context
*pctx
,
648 const struct pipe_rasterizer_state
*cso
)
650 struct panfrost_rasterizer
*so
= CALLOC_STRUCT(panfrost_rasterizer
);
658 panfrost_bind_rasterizer_state(
659 struct pipe_context
*pctx
,
662 struct panfrost_context
*ctx
= pan_context(pctx
);
664 ctx
->rasterizer
= hwcso
;
669 /* Gauranteed with the core GL call, so don't expose ARB_polygon_offset */
670 assert(ctx
->rasterizer
->base
.offset_clamp
== 0.0);
672 /* Point sprites are emulated */
674 struct panfrost_shader_state
*variant
= panfrost_get_shader_state(ctx
, PIPE_SHADER_FRAGMENT
);
676 if (ctx
->rasterizer
->base
.sprite_coord_enable
|| (variant
&& variant
->point_sprite_mask
))
677 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
681 panfrost_create_vertex_elements_state(
682 struct pipe_context
*pctx
,
683 unsigned num_elements
,
684 const struct pipe_vertex_element
*elements
)
686 struct panfrost_vertex_state
*so
= CALLOC_STRUCT(panfrost_vertex_state
);
688 so
->num_elements
= num_elements
;
689 memcpy(so
->pipe
, elements
, sizeof(*elements
) * num_elements
);
691 for (int i
= 0; i
< num_elements
; ++i
) {
694 enum pipe_format fmt
= elements
[i
].src_format
;
695 const struct util_format_description
*desc
= util_format_description(fmt
);
696 so
->hw
[i
].unknown1
= 0x2;
697 so
->hw
[i
].swizzle
= panfrost_get_default_swizzle(desc
->nr_channels
);
699 so
->hw
[i
].format
= panfrost_find_format(desc
);
702 /* Let's also prepare vertex builtins */
703 so
->hw
[PAN_VERTEX_ID
].format
= MALI_R32UI
;
704 so
->hw
[PAN_VERTEX_ID
].swizzle
= panfrost_get_default_swizzle(1);
705 so
->hw
[PAN_INSTANCE_ID
].format
= MALI_R32UI
;
706 so
->hw
[PAN_INSTANCE_ID
].swizzle
= panfrost_get_default_swizzle(1);
712 panfrost_bind_vertex_elements_state(
713 struct pipe_context
*pctx
,
716 struct panfrost_context
*ctx
= pan_context(pctx
);
721 panfrost_create_shader_state(
722 struct pipe_context
*pctx
,
723 const struct pipe_shader_state
*cso
,
724 enum pipe_shader_type stage
)
726 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
729 /* Token deep copy to prevent memory corruption */
731 if (cso
->type
== PIPE_SHADER_IR_TGSI
)
732 so
->base
.tokens
= tgsi_dup_tokens(so
->base
.tokens
);
734 /* Precompile for shader-db if we need to */
735 if (unlikely((pan_debug
& PAN_DBG_PRECOMPILE
) && cso
->type
== PIPE_SHADER_IR_NIR
)) {
736 struct panfrost_context
*ctx
= pan_context(pctx
);
738 struct panfrost_shader_state state
;
739 uint64_t outputs_written
;
741 panfrost_shader_compile(ctx
, PIPE_SHADER_IR_NIR
,
743 tgsi_processor_to_shader_stage(stage
),
744 &state
, &outputs_written
);
751 panfrost_delete_shader_state(
752 struct pipe_context
*pctx
,
755 struct panfrost_shader_variants
*cso
= (struct panfrost_shader_variants
*) so
;
757 if (cso
->base
.type
== PIPE_SHADER_IR_TGSI
) {
758 DBG("Deleting TGSI shader leaks duplicated tokens\n");
761 for (unsigned i
= 0; i
< cso
->variant_count
; ++i
) {
762 struct panfrost_shader_state
*shader_state
= &cso
->variants
[i
];
763 panfrost_bo_unreference(shader_state
->bo
);
764 shader_state
->bo
= NULL
;
772 panfrost_create_sampler_state(
773 struct pipe_context
*pctx
,
774 const struct pipe_sampler_state
*cso
)
776 struct panfrost_sampler_state
*so
= CALLOC_STRUCT(panfrost_sampler_state
);
779 panfrost_sampler_desc_init(cso
, &so
->hw
);
785 panfrost_bind_sampler_states(
786 struct pipe_context
*pctx
,
787 enum pipe_shader_type shader
,
788 unsigned start_slot
, unsigned num_sampler
,
791 assert(start_slot
== 0);
793 struct panfrost_context
*ctx
= pan_context(pctx
);
795 /* XXX: Should upload, not just copy? */
796 ctx
->sampler_count
[shader
] = num_sampler
;
797 memcpy(ctx
->samplers
[shader
], sampler
, num_sampler
* sizeof (void *));
801 panfrost_variant_matches(
802 struct panfrost_context
*ctx
,
803 struct panfrost_shader_state
*variant
,
804 enum pipe_shader_type type
)
806 struct pipe_rasterizer_state
*rasterizer
= &ctx
->rasterizer
->base
;
807 struct pipe_alpha_state
*alpha
= &ctx
->depth_stencil
->alpha
;
809 bool is_fragment
= (type
== PIPE_SHADER_FRAGMENT
);
811 if (is_fragment
&& (alpha
->enabled
|| variant
->alpha_state
.enabled
)) {
812 /* Make sure enable state is at least the same */
813 if (alpha
->enabled
!= variant
->alpha_state
.enabled
) {
817 /* Check that the contents of the test are the same */
818 bool same_func
= alpha
->func
== variant
->alpha_state
.func
;
819 bool same_ref
= alpha
->ref_value
== variant
->alpha_state
.ref_value
;
821 if (!(same_func
&& same_ref
)) {
826 if (is_fragment
&& rasterizer
&& (rasterizer
->sprite_coord_enable
|
827 variant
->point_sprite_mask
)) {
828 /* Ensure the same varyings are turned to point sprites */
829 if (rasterizer
->sprite_coord_enable
!= variant
->point_sprite_mask
)
832 /* Ensure the orientation is correct */
834 rasterizer
->sprite_coord_mode
==
835 PIPE_SPRITE_COORD_UPPER_LEFT
;
837 if (variant
->point_sprite_upper_left
!= upper_left
)
841 /* Otherwise, we're good to go */
846 * Fix an uncompiled shader's stream output info, and produce a bitmask
847 * of which VARYING_SLOT_* are captured for stream output.
849 * Core Gallium stores output->register_index as a "slot" number, where
850 * slots are assigned consecutively to all outputs in info->outputs_written.
851 * This naive packing of outputs doesn't work for us - we too have slots,
852 * but the layout is defined by the VUE map, which we won't have until we
853 * compile a specific shader variant. So, we remap these and simply store
854 * VARYING_SLOT_* in our copy's output->register_index fields.
856 * We then produce a bitmask of outputs which are used for SO.
858 * Implementation from iris.
862 update_so_info(struct pipe_stream_output_info
*so_info
,
863 uint64_t outputs_written
)
865 uint64_t so_outputs
= 0;
866 uint8_t reverse_map
[64] = {0};
869 while (outputs_written
)
870 reverse_map
[slot
++] = u_bit_scan64(&outputs_written
);
872 for (unsigned i
= 0; i
< so_info
->num_outputs
; i
++) {
873 struct pipe_stream_output
*output
= &so_info
->output
[i
];
875 /* Map Gallium's condensed "slots" back to real VARYING_SLOT_* enums */
876 output
->register_index
= reverse_map
[output
->register_index
];
878 so_outputs
|= 1ull << output
->register_index
;
885 panfrost_bind_shader_state(
886 struct pipe_context
*pctx
,
888 enum pipe_shader_type type
)
890 struct panfrost_context
*ctx
= pan_context(pctx
);
891 ctx
->shader
[type
] = hwcso
;
895 /* Match the appropriate variant */
898 struct panfrost_shader_variants
*variants
= (struct panfrost_shader_variants
*) hwcso
;
900 for (unsigned i
= 0; i
< variants
->variant_count
; ++i
) {
901 if (panfrost_variant_matches(ctx
, &variants
->variants
[i
], type
)) {
908 /* No variant matched, so create a new one */
909 variant
= variants
->variant_count
++;
911 if (variants
->variant_count
> variants
->variant_space
) {
912 unsigned old_space
= variants
->variant_space
;
914 variants
->variant_space
*= 2;
915 if (variants
->variant_space
== 0)
916 variants
->variant_space
= 1;
918 /* Arbitrary limit to stop runaway programs from
919 * creating an unbounded number of shader variants. */
920 assert(variants
->variant_space
< 1024);
922 unsigned msize
= sizeof(struct panfrost_shader_state
);
923 variants
->variants
= realloc(variants
->variants
,
924 variants
->variant_space
* msize
);
926 memset(&variants
->variants
[old_space
], 0,
927 (variants
->variant_space
- old_space
) * msize
);
930 struct panfrost_shader_state
*v
=
931 &variants
->variants
[variant
];
933 if (type
== PIPE_SHADER_FRAGMENT
) {
934 v
->alpha_state
= ctx
->depth_stencil
->alpha
;
936 if (ctx
->rasterizer
) {
937 v
->point_sprite_mask
= ctx
->rasterizer
->base
.sprite_coord_enable
;
938 v
->point_sprite_upper_left
=
939 ctx
->rasterizer
->base
.sprite_coord_mode
==
940 PIPE_SPRITE_COORD_UPPER_LEFT
;
945 /* Select this variant */
946 variants
->active_variant
= variant
;
948 struct panfrost_shader_state
*shader_state
= &variants
->variants
[variant
];
949 assert(panfrost_variant_matches(ctx
, shader_state
, type
));
951 /* We finally have a variant, so compile it */
953 if (!shader_state
->compiled
) {
954 uint64_t outputs_written
= 0;
956 panfrost_shader_compile(ctx
, variants
->base
.type
,
957 variants
->base
.type
== PIPE_SHADER_IR_NIR
?
958 variants
->base
.ir
.nir
:
959 variants
->base
.tokens
,
960 tgsi_processor_to_shader_stage(type
),
964 shader_state
->compiled
= true;
966 /* Fixup the stream out information, since what Gallium returns
967 * normally is mildly insane */
969 shader_state
->stream_output
= variants
->base
.stream_output
;
970 shader_state
->so_mask
=
971 update_so_info(&shader_state
->stream_output
, outputs_written
);
976 panfrost_create_vs_state(struct pipe_context
*pctx
, const struct pipe_shader_state
*hwcso
)
978 return panfrost_create_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
982 panfrost_create_fs_state(struct pipe_context
*pctx
, const struct pipe_shader_state
*hwcso
)
984 return panfrost_create_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
988 panfrost_bind_vs_state(struct pipe_context
*pctx
, void *hwcso
)
990 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_VERTEX
);
994 panfrost_bind_fs_state(struct pipe_context
*pctx
, void *hwcso
)
996 panfrost_bind_shader_state(pctx
, hwcso
, PIPE_SHADER_FRAGMENT
);
1000 panfrost_set_vertex_buffers(
1001 struct pipe_context
*pctx
,
1002 unsigned start_slot
,
1003 unsigned num_buffers
,
1004 const struct pipe_vertex_buffer
*buffers
)
1006 struct panfrost_context
*ctx
= pan_context(pctx
);
1008 util_set_vertex_buffers_mask(ctx
->vertex_buffers
, &ctx
->vb_mask
, buffers
, start_slot
, num_buffers
);
1012 panfrost_set_constant_buffer(
1013 struct pipe_context
*pctx
,
1014 enum pipe_shader_type shader
, uint index
,
1015 const struct pipe_constant_buffer
*buf
)
1017 struct panfrost_context
*ctx
= pan_context(pctx
);
1018 struct panfrost_constant_buffer
*pbuf
= &ctx
->constant_buffer
[shader
];
1020 util_copy_constant_buffer(&pbuf
->cb
[index
], buf
);
1022 unsigned mask
= (1 << index
);
1024 if (unlikely(!buf
)) {
1025 pbuf
->enabled_mask
&= ~mask
;
1026 pbuf
->dirty_mask
&= ~mask
;
1030 pbuf
->enabled_mask
|= mask
;
1031 pbuf
->dirty_mask
|= mask
;
1035 panfrost_set_stencil_ref(
1036 struct pipe_context
*pctx
,
1037 const struct pipe_stencil_ref
*ref
)
1039 struct panfrost_context
*ctx
= pan_context(pctx
);
1040 ctx
->stencil_ref
= *ref
;
1043 static enum mali_texture_type
1044 panfrost_translate_texture_type(enum pipe_texture_target t
) {
1048 case PIPE_TEXTURE_1D
:
1049 case PIPE_TEXTURE_1D_ARRAY
:
1052 case PIPE_TEXTURE_2D
:
1053 case PIPE_TEXTURE_2D_ARRAY
:
1054 case PIPE_TEXTURE_RECT
:
1057 case PIPE_TEXTURE_3D
:
1060 case PIPE_TEXTURE_CUBE
:
1061 case PIPE_TEXTURE_CUBE_ARRAY
:
1062 return MALI_TEX_CUBE
;
1065 unreachable("Unknown target");
1069 static struct pipe_sampler_view
*
1070 panfrost_create_sampler_view(
1071 struct pipe_context
*pctx
,
1072 struct pipe_resource
*texture
,
1073 const struct pipe_sampler_view
*template)
1075 struct panfrost_screen
*screen
= pan_screen(pctx
->screen
);
1076 struct panfrost_sampler_view
*so
= rzalloc(pctx
, struct panfrost_sampler_view
);
1078 pipe_reference(NULL
, &texture
->reference
);
1080 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) texture
;
1083 so
->base
= *template;
1084 so
->base
.texture
= texture
;
1085 so
->base
.reference
.count
= 1;
1086 so
->base
.context
= pctx
;
1088 unsigned char user_swizzle
[4] = {
1089 template->swizzle_r
,
1090 template->swizzle_g
,
1091 template->swizzle_b
,
1095 /* In the hardware, array_size refers specifically to array textures,
1096 * whereas in Gallium, it also covers cubemaps */
1098 unsigned array_size
= texture
->array_size
;
1100 if (template->target
== PIPE_TEXTURE_CUBE
) {
1101 /* TODO: Cubemap arrays */
1102 assert(array_size
== 6);
1106 enum mali_texture_type type
=
1107 panfrost_translate_texture_type(template->target
);
1109 unsigned size
= panfrost_estimate_texture_size(
1110 template->u
.tex
.first_level
,
1111 template->u
.tex
.last_level
,
1112 template->u
.tex
.first_layer
,
1113 template->u
.tex
.last_layer
,
1114 type
, prsrc
->layout
);
1116 so
->bo
= panfrost_bo_create(screen
, size
, 0);
1118 panfrost_new_texture(
1120 texture
->width0
, texture
->height0
,
1121 texture
->depth0
, array_size
,
1123 type
, prsrc
->layout
,
1124 template->u
.tex
.first_level
,
1125 template->u
.tex
.last_level
,
1126 template->u
.tex
.first_layer
,
1127 template->u
.tex
.last_layer
,
1128 prsrc
->cubemap_stride
,
1129 panfrost_translate_swizzle_4(user_swizzle
),
1133 return (struct pipe_sampler_view
*) so
;
1137 panfrost_set_sampler_views(
1138 struct pipe_context
*pctx
,
1139 enum pipe_shader_type shader
,
1140 unsigned start_slot
, unsigned num_views
,
1141 struct pipe_sampler_view
**views
)
1143 struct panfrost_context
*ctx
= pan_context(pctx
);
1144 unsigned new_nr
= 0;
1147 assert(start_slot
== 0);
1149 for (i
= 0; i
< num_views
; ++i
) {
1152 pipe_sampler_view_reference((struct pipe_sampler_view
**)&ctx
->sampler_views
[shader
][i
],
1156 for (; i
< ctx
->sampler_view_count
[shader
]; i
++) {
1157 pipe_sampler_view_reference((struct pipe_sampler_view
**)&ctx
->sampler_views
[shader
][i
],
1160 ctx
->sampler_view_count
[shader
] = new_nr
;
1164 panfrost_sampler_view_destroy(
1165 struct pipe_context
*pctx
,
1166 struct pipe_sampler_view
*pview
)
1168 struct panfrost_sampler_view
*view
= (struct panfrost_sampler_view
*) pview
;
1170 pipe_resource_reference(&pview
->texture
, NULL
);
1171 panfrost_bo_unreference(view
->bo
);
1176 panfrost_set_shader_buffers(
1177 struct pipe_context
*pctx
,
1178 enum pipe_shader_type shader
,
1179 unsigned start
, unsigned count
,
1180 const struct pipe_shader_buffer
*buffers
,
1181 unsigned writable_bitmask
)
1183 struct panfrost_context
*ctx
= pan_context(pctx
);
1185 util_set_shader_buffers_mask(ctx
->ssbo
[shader
], &ctx
->ssbo_mask
[shader
],
1186 buffers
, start
, count
);
1189 /* Hints that a framebuffer should use AFBC where possible */
1193 struct panfrost_screen
*screen
,
1194 const struct pipe_framebuffer_state
*fb
)
1196 /* AFBC implemenation incomplete; hide it */
1197 if (!(pan_debug
& PAN_DBG_AFBC
)) return;
1199 /* Hint AFBC to the resources bound to each color buffer */
1201 for (unsigned i
= 0; i
< fb
->nr_cbufs
; ++i
) {
1202 struct pipe_surface
*surf
= fb
->cbufs
[i
];
1203 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
1204 panfrost_resource_hint_layout(screen
, rsrc
, MALI_TEXTURE_AFBC
, 1);
1207 /* Also hint it to the depth buffer */
1210 struct panfrost_resource
*rsrc
= pan_resource(fb
->zsbuf
->texture
);
1211 panfrost_resource_hint_layout(screen
, rsrc
, MALI_TEXTURE_AFBC
, 1);
1216 panfrost_set_framebuffer_state(struct pipe_context
*pctx
,
1217 const struct pipe_framebuffer_state
*fb
)
1219 struct panfrost_context
*ctx
= pan_context(pctx
);
1221 panfrost_hint_afbc(pan_screen(pctx
->screen
), fb
);
1222 util_copy_framebuffer_state(&ctx
->pipe_framebuffer
, fb
);
1224 panfrost_invalidate_frame(ctx
);
1228 panfrost_create_depth_stencil_state(struct pipe_context
*pipe
,
1229 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
1231 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
1235 panfrost_bind_depth_stencil_state(struct pipe_context
*pipe
,
1238 struct panfrost_context
*ctx
= pan_context(pipe
);
1239 struct pipe_depth_stencil_alpha_state
*depth_stencil
= cso
;
1240 ctx
->depth_stencil
= depth_stencil
;
1245 /* Alpha does not exist in the hardware (it's not in ES3), so it's
1246 * emulated in the fragment shader */
1248 if (depth_stencil
->alpha
.enabled
) {
1249 /* We need to trigger a new shader (maybe) */
1250 ctx
->base
.bind_fs_state(&ctx
->base
, ctx
->shader
[PIPE_SHADER_FRAGMENT
]);
1253 /* Bounds test not implemented */
1254 assert(!depth_stencil
->depth
.bounds_test
);
1258 panfrost_delete_depth_stencil_state(struct pipe_context
*pipe
, void *depth
)
1264 panfrost_set_sample_mask(struct pipe_context
*pipe
,
1265 unsigned sample_mask
)
1270 panfrost_set_clip_state(struct pipe_context
*pipe
,
1271 const struct pipe_clip_state
*clip
)
1273 //struct panfrost_context *panfrost = pan_context(pipe);
1277 panfrost_set_viewport_states(struct pipe_context
*pipe
,
1278 unsigned start_slot
,
1279 unsigned num_viewports
,
1280 const struct pipe_viewport_state
*viewports
)
1282 struct panfrost_context
*ctx
= pan_context(pipe
);
1284 assert(start_slot
== 0);
1285 assert(num_viewports
== 1);
1287 ctx
->pipe_viewport
= *viewports
;
1291 panfrost_set_scissor_states(struct pipe_context
*pipe
,
1292 unsigned start_slot
,
1293 unsigned num_scissors
,
1294 const struct pipe_scissor_state
*scissors
)
1296 struct panfrost_context
*ctx
= pan_context(pipe
);
1298 assert(start_slot
== 0);
1299 assert(num_scissors
== 1);
1301 ctx
->scissor
= *scissors
;
1305 panfrost_set_polygon_stipple(struct pipe_context
*pipe
,
1306 const struct pipe_poly_stipple
*stipple
)
1308 //struct panfrost_context *panfrost = pan_context(pipe);
1312 panfrost_set_active_query_state(struct pipe_context
*pipe
,
1315 struct panfrost_context
*ctx
= pan_context(pipe
);
1316 ctx
->active_queries
= enable
;
1320 panfrost_destroy(struct pipe_context
*pipe
)
1322 struct panfrost_context
*panfrost
= pan_context(pipe
);
1324 if (panfrost
->blitter
)
1325 util_blitter_destroy(panfrost
->blitter
);
1327 if (panfrost
->blitter_wallpaper
)
1328 util_blitter_destroy(panfrost
->blitter_wallpaper
);
1330 util_unreference_framebuffer_state(&panfrost
->pipe_framebuffer
);
1331 u_upload_destroy(pipe
->stream_uploader
);
1336 static struct pipe_query
*
1337 panfrost_create_query(struct pipe_context
*pipe
,
1341 struct panfrost_query
*q
= rzalloc(pipe
, struct panfrost_query
);
1346 return (struct pipe_query
*) q
;
1350 panfrost_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1352 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1355 panfrost_bo_unreference(query
->bo
);
1363 panfrost_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1365 struct panfrost_context
*ctx
= pan_context(pipe
);
1366 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1368 switch (query
->type
) {
1369 case PIPE_QUERY_OCCLUSION_COUNTER
:
1370 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1371 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1372 /* Allocate a bo for the query results to be stored */
1374 query
->bo
= panfrost_bo_create(
1375 pan_screen(ctx
->base
.screen
),
1376 sizeof(unsigned), 0);
1379 unsigned *result
= (unsigned *)query
->bo
->cpu
;
1380 *result
= 0; /* Default to 0 if nothing at all drawn. */
1381 ctx
->occlusion_query
= query
;
1384 /* Geometry statistics are computed in the driver. XXX: geom/tess
1387 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1388 query
->start
= ctx
->prims_generated
;
1390 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1391 query
->start
= ctx
->tf_prims_generated
;
1395 DBG("Skipping query %u\n", query
->type
);
1403 panfrost_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
1405 struct panfrost_context
*ctx
= pan_context(pipe
);
1406 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1408 switch (query
->type
) {
1409 case PIPE_QUERY_OCCLUSION_COUNTER
:
1410 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1411 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1412 ctx
->occlusion_query
= NULL
;
1414 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1415 query
->end
= ctx
->prims_generated
;
1417 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1418 query
->end
= ctx
->tf_prims_generated
;
1426 panfrost_get_query_result(struct pipe_context
*pipe
,
1427 struct pipe_query
*q
,
1429 union pipe_query_result
*vresult
)
1431 struct panfrost_query
*query
= (struct panfrost_query
*) q
;
1432 struct panfrost_context
*ctx
= pan_context(pipe
);
1435 switch (query
->type
) {
1436 case PIPE_QUERY_OCCLUSION_COUNTER
:
1437 case PIPE_QUERY_OCCLUSION_PREDICATE
:
1438 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
1440 panfrost_flush_all_batches(ctx
, true);
1442 /* Read back the query results */
1443 unsigned *result
= (unsigned *) query
->bo
->cpu
;
1444 unsigned passed
= *result
;
1446 if (query
->type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
1447 vresult
->u64
= passed
;
1449 vresult
->b
= !!passed
;
1454 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1455 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1456 panfrost_flush_all_batches(ctx
, true);
1457 vresult
->u64
= query
->end
- query
->start
;
1461 DBG("Skipped query get %u\n", query
->type
);
1468 static struct pipe_stream_output_target
*
1469 panfrost_create_stream_output_target(struct pipe_context
*pctx
,
1470 struct pipe_resource
*prsc
,
1471 unsigned buffer_offset
,
1472 unsigned buffer_size
)
1474 struct pipe_stream_output_target
*target
;
1476 target
= rzalloc(pctx
, struct pipe_stream_output_target
);
1481 pipe_reference_init(&target
->reference
, 1);
1482 pipe_resource_reference(&target
->buffer
, prsc
);
1484 target
->context
= pctx
;
1485 target
->buffer_offset
= buffer_offset
;
1486 target
->buffer_size
= buffer_size
;
1492 panfrost_stream_output_target_destroy(struct pipe_context
*pctx
,
1493 struct pipe_stream_output_target
*target
)
1495 pipe_resource_reference(&target
->buffer
, NULL
);
1496 ralloc_free(target
);
1500 panfrost_set_stream_output_targets(struct pipe_context
*pctx
,
1501 unsigned num_targets
,
1502 struct pipe_stream_output_target
**targets
,
1503 const unsigned *offsets
)
1505 struct panfrost_context
*ctx
= pan_context(pctx
);
1506 struct panfrost_streamout
*so
= &ctx
->streamout
;
1508 assert(num_targets
<= ARRAY_SIZE(so
->targets
));
1510 for (unsigned i
= 0; i
< num_targets
; i
++) {
1511 if (offsets
[i
] != -1)
1512 so
->offsets
[i
] = offsets
[i
];
1514 pipe_so_target_reference(&so
->targets
[i
], targets
[i
]);
1517 for (unsigned i
= 0; i
< so
->num_targets
; i
++)
1518 pipe_so_target_reference(&so
->targets
[i
], NULL
);
1520 so
->num_targets
= num_targets
;
1523 struct pipe_context
*
1524 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
1526 struct panfrost_context
*ctx
= rzalloc(screen
, struct panfrost_context
);
1527 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
1529 gallium
->screen
= screen
;
1531 gallium
->destroy
= panfrost_destroy
;
1533 gallium
->set_framebuffer_state
= panfrost_set_framebuffer_state
;
1535 gallium
->flush
= panfrost_flush
;
1536 gallium
->clear
= panfrost_clear
;
1537 gallium
->draw_vbo
= panfrost_draw_vbo
;
1539 gallium
->set_vertex_buffers
= panfrost_set_vertex_buffers
;
1540 gallium
->set_constant_buffer
= panfrost_set_constant_buffer
;
1541 gallium
->set_shader_buffers
= panfrost_set_shader_buffers
;
1543 gallium
->set_stencil_ref
= panfrost_set_stencil_ref
;
1545 gallium
->create_sampler_view
= panfrost_create_sampler_view
;
1546 gallium
->set_sampler_views
= panfrost_set_sampler_views
;
1547 gallium
->sampler_view_destroy
= panfrost_sampler_view_destroy
;
1549 gallium
->create_rasterizer_state
= panfrost_create_rasterizer_state
;
1550 gallium
->bind_rasterizer_state
= panfrost_bind_rasterizer_state
;
1551 gallium
->delete_rasterizer_state
= panfrost_generic_cso_delete
;
1553 gallium
->create_vertex_elements_state
= panfrost_create_vertex_elements_state
;
1554 gallium
->bind_vertex_elements_state
= panfrost_bind_vertex_elements_state
;
1555 gallium
->delete_vertex_elements_state
= panfrost_generic_cso_delete
;
1557 gallium
->create_fs_state
= panfrost_create_fs_state
;
1558 gallium
->delete_fs_state
= panfrost_delete_shader_state
;
1559 gallium
->bind_fs_state
= panfrost_bind_fs_state
;
1561 gallium
->create_vs_state
= panfrost_create_vs_state
;
1562 gallium
->delete_vs_state
= panfrost_delete_shader_state
;
1563 gallium
->bind_vs_state
= panfrost_bind_vs_state
;
1565 gallium
->create_sampler_state
= panfrost_create_sampler_state
;
1566 gallium
->delete_sampler_state
= panfrost_generic_cso_delete
;
1567 gallium
->bind_sampler_states
= panfrost_bind_sampler_states
;
1569 gallium
->create_depth_stencil_alpha_state
= panfrost_create_depth_stencil_state
;
1570 gallium
->bind_depth_stencil_alpha_state
= panfrost_bind_depth_stencil_state
;
1571 gallium
->delete_depth_stencil_alpha_state
= panfrost_delete_depth_stencil_state
;
1573 gallium
->set_sample_mask
= panfrost_set_sample_mask
;
1575 gallium
->set_clip_state
= panfrost_set_clip_state
;
1576 gallium
->set_viewport_states
= panfrost_set_viewport_states
;
1577 gallium
->set_scissor_states
= panfrost_set_scissor_states
;
1578 gallium
->set_polygon_stipple
= panfrost_set_polygon_stipple
;
1579 gallium
->set_active_query_state
= panfrost_set_active_query_state
;
1581 gallium
->create_query
= panfrost_create_query
;
1582 gallium
->destroy_query
= panfrost_destroy_query
;
1583 gallium
->begin_query
= panfrost_begin_query
;
1584 gallium
->end_query
= panfrost_end_query
;
1585 gallium
->get_query_result
= panfrost_get_query_result
;
1587 gallium
->create_stream_output_target
= panfrost_create_stream_output_target
;
1588 gallium
->stream_output_target_destroy
= panfrost_stream_output_target_destroy
;
1589 gallium
->set_stream_output_targets
= panfrost_set_stream_output_targets
;
1591 panfrost_resource_context_init(gallium
);
1592 panfrost_blend_context_init(gallium
);
1593 panfrost_compute_context_init(gallium
);
1596 gallium
->stream_uploader
= u_upload_create_default(gallium
);
1597 gallium
->const_uploader
= gallium
->stream_uploader
;
1598 assert(gallium
->stream_uploader
);
1600 /* Midgard supports ES modes, plus QUADS/QUAD_STRIPS/POLYGON */
1601 ctx
->draw_modes
= (1 << (PIPE_PRIM_POLYGON
+ 1)) - 1;
1603 ctx
->primconvert
= util_primconvert_create(gallium
, ctx
->draw_modes
);
1605 ctx
->blitter
= util_blitter_create(gallium
);
1606 ctx
->blitter_wallpaper
= util_blitter_create(gallium
);
1608 assert(ctx
->blitter
);
1609 assert(ctx
->blitter_wallpaper
);
1611 /* Prepare for render! */
1613 panfrost_batch_init(ctx
);
1614 panfrost_emit_vertex_payload(ctx
);
1615 panfrost_invalidate_frame(ctx
);