2 * Copyright (C) 2008 VMware, Inc.
3 * Copyright (C) 2014 Broadcom
4 * Copyright (C) 2018-2019 Alyssa Rosenzweig
5 * Copyright (C) 2019 Collabora
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Authors (Collabora):
27 * Tomeu Vizoso <tomeu.vizoso@collabora.com>
28 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
34 #include "drm-uapi/drm_fourcc.h"
36 #include "state_tracker/winsys_handle.h"
37 #include "util/u_format.h"
38 #include "util/u_memory.h"
39 #include "util/u_surface.h"
40 #include "util/u_transfer.h"
41 #include "util/u_transfer_helper.h"
42 #include "util/u_gen_mipmap.h"
44 #include "pan_context.h"
45 #include "pan_screen.h"
46 #include "pan_resource.h"
48 #include "pan_tiling.h"
50 static struct pipe_resource
*
51 panfrost_resource_from_handle(struct pipe_screen
*pscreen
,
52 const struct pipe_resource
*templat
,
53 struct winsys_handle
*whandle
,
56 struct panfrost_screen
*screen
= pan_screen(pscreen
);
57 struct panfrost_resource
*rsc
;
58 struct pipe_resource
*prsc
;
60 assert(whandle
->type
== WINSYS_HANDLE_TYPE_FD
);
62 rsc
= rzalloc(pscreen
, struct panfrost_resource
);
70 pipe_reference_init(&prsc
->reference
, 1);
71 prsc
->screen
= pscreen
;
73 rsc
->bo
= panfrost_drm_import_bo(screen
, whandle
);
74 rsc
->bo
->slices
[0].stride
= whandle
->stride
;
75 rsc
->bo
->slices
[0].initialized
= true;
79 renderonly_create_gpu_import_for_resource(prsc
, screen
->ro
, NULL
);
80 /* failure is expected in some cases.. */
87 panfrost_resource_get_handle(struct pipe_screen
*pscreen
,
88 struct pipe_context
*ctx
,
89 struct pipe_resource
*pt
,
90 struct winsys_handle
*handle
,
93 struct panfrost_screen
*screen
= pan_screen(pscreen
);
94 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) pt
;
95 struct renderonly_scanout
*scanout
= rsrc
->scanout
;
97 handle
->modifier
= DRM_FORMAT_MOD_INVALID
;
99 if (handle
->type
== WINSYS_HANDLE_TYPE_SHARED
) {
101 } else if (handle
->type
== WINSYS_HANDLE_TYPE_KMS
) {
102 if (renderonly_get_handle(scanout
, handle
))
105 handle
->handle
= rsrc
->bo
->gem_handle
;
106 handle
->stride
= rsrc
->bo
->slices
[0].stride
;
108 } else if (handle
->type
== WINSYS_HANDLE_TYPE_FD
) {
110 struct drm_prime_handle args
= {
111 .handle
= scanout
->handle
,
112 .flags
= DRM_CLOEXEC
,
115 int ret
= drmIoctl(screen
->ro
->kms_fd
, DRM_IOCTL_PRIME_HANDLE_TO_FD
, &args
);
119 handle
->stride
= scanout
->stride
;
120 handle
->handle
= args
.fd
;
124 return panfrost_drm_export_bo(screen
, rsrc
->bo
->gem_handle
,
125 rsrc
->bo
->slices
[0].stride
,
133 panfrost_flush_resource(struct pipe_context
*pctx
, struct pipe_resource
*prsc
)
135 //DBG("TODO %s\n", __func__);
138 static struct pipe_surface
*
139 panfrost_create_surface(struct pipe_context
*pipe
,
140 struct pipe_resource
*pt
,
141 const struct pipe_surface
*surf_tmpl
)
143 struct pipe_surface
*ps
= NULL
;
145 ps
= rzalloc(pipe
, struct pipe_surface
);
148 pipe_reference_init(&ps
->reference
, 1);
149 pipe_resource_reference(&ps
->texture
, pt
);
151 ps
->format
= surf_tmpl
->format
;
153 if (pt
->target
!= PIPE_BUFFER
) {
154 assert(surf_tmpl
->u
.tex
.level
<= pt
->last_level
);
155 ps
->width
= u_minify(pt
->width0
, surf_tmpl
->u
.tex
.level
);
156 ps
->height
= u_minify(pt
->height0
, surf_tmpl
->u
.tex
.level
);
157 ps
->u
.tex
.level
= surf_tmpl
->u
.tex
.level
;
158 ps
->u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
159 ps
->u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
161 /* setting width as number of elements should get us correct renderbuffer width */
162 ps
->width
= surf_tmpl
->u
.buf
.last_element
- surf_tmpl
->u
.buf
.first_element
+ 1;
163 ps
->height
= pt
->height0
;
164 ps
->u
.buf
.first_element
= surf_tmpl
->u
.buf
.first_element
;
165 ps
->u
.buf
.last_element
= surf_tmpl
->u
.buf
.last_element
;
166 assert(ps
->u
.buf
.first_element
<= ps
->u
.buf
.last_element
);
167 assert(ps
->u
.buf
.last_element
< ps
->width
);
175 panfrost_surface_destroy(struct pipe_context
*pipe
,
176 struct pipe_surface
*surf
)
178 assert(surf
->texture
);
179 pipe_resource_reference(&surf
->texture
, NULL
);
184 panfrost_setup_slices(const struct pipe_resource
*tmpl
, struct panfrost_bo
*bo
)
186 unsigned width
= tmpl
->width0
;
187 unsigned height
= tmpl
->height0
;
188 unsigned depth
= tmpl
->depth0
;
189 unsigned bytes_per_pixel
= util_format_get_blocksize(tmpl
->format
);
193 /* Tiled operates blockwise; linear is packed. Also, anything
194 * we render to has to be tile-aligned. Maybe not strictly
195 * necessary, but we're not *that* pressed for memory and it
196 * makes code a lot simpler */
198 bool renderable
= tmpl
->bind
&
199 (PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DEPTH_STENCIL
);
200 bool afbc
= bo
->layout
== PAN_AFBC
;
201 bool tiled
= bo
->layout
== PAN_TILED
;
202 bool should_align
= renderable
|| tiled
;
204 /* We don't know how to specify a 2D stride for 3D textures */
206 bool can_align_stride
=
207 tmpl
->target
!= PIPE_TEXTURE_3D
;
209 should_align
&= can_align_stride
;
212 unsigned size_2d
= 0;
214 for (unsigned l
= 0; l
<= tmpl
->last_level
; ++l
) {
215 struct panfrost_slice
*slice
= &bo
->slices
[l
];
217 unsigned effective_width
= width
;
218 unsigned effective_height
= height
;
219 unsigned effective_depth
= depth
;
222 effective_width
= ALIGN(effective_width
, 16);
223 effective_height
= ALIGN(effective_height
, 16);
225 /* We don't need to align depth */
228 slice
->offset
= offset
;
230 /* Compute the would-be stride */
231 unsigned stride
= bytes_per_pixel
* effective_width
;
233 /* ..but cache-line align it for performance */
234 if (can_align_stride
&& bo
->layout
== PAN_LINEAR
)
235 stride
= ALIGN(stride
, 64);
237 slice
->stride
= stride
;
239 unsigned slice_one_size
= slice
->stride
* effective_height
;
240 unsigned slice_full_size
= slice_one_size
* effective_depth
;
242 /* Report 2D size for 3D texturing */
245 size_2d
= slice_one_size
;
247 /* Compute AFBC sizes if necessary */
250 panfrost_afbc_header_size(width
, height
);
252 offset
+= slice
->header_size
;
255 offset
+= slice_full_size
;
257 width
= u_minify(width
, 1);
258 height
= u_minify(height
, 1);
259 depth
= u_minify(depth
, 1);
262 assert(tmpl
->array_size
);
264 if (tmpl
->target
!= PIPE_TEXTURE_3D
) {
265 /* Arrays and cubemaps have the entire miptree duplicated */
267 bo
->cubemap_stride
= ALIGN(offset
, 64);
268 bo
->size
= ALIGN(bo
->cubemap_stride
* tmpl
->array_size
, 4096);
270 /* 3D strides across the 2D layers */
271 assert(tmpl
->array_size
== 1);
273 bo
->cubemap_stride
= size_2d
;
274 bo
->size
= ALIGN(offset
, 4096);
278 static struct panfrost_bo
*
279 panfrost_create_bo(struct panfrost_screen
*screen
, const struct pipe_resource
*template)
281 struct panfrost_bo
*bo
= rzalloc(screen
, struct panfrost_bo
);
282 pipe_reference_init(&bo
->reference
, 1);
284 /* Based on the usage, figure out what storing will be used. There are
287 * Linear: the basic format, bad for memory bandwidth, bad for cache
288 * use. Zero-copy, though. Renderable.
290 * Tiled: Not compressed, but cache-optimized. Expensive to write into
291 * (due to software tiling), but cheap to sample from. Ideal for most
294 * AFBC: Compressed and renderable (so always desirable for non-scanout
295 * rendertargets). Cheap to sample from. The format is black box, so we
296 * can't read/write from software.
299 /* Tiling textures is almost always faster, unless we only use it once */
301 bool is_texture
= (template->bind
& PIPE_BIND_SAMPLER_VIEW
);
302 bool is_2d
= template->depth0
== 1 && template->array_size
== 1;
303 bool is_streaming
= (template->usage
!= PIPE_USAGE_STREAM
);
305 bool should_tile
= is_streaming
&& is_texture
&& is_2d
;
307 /* Depth/stencil can't be tiled, only linear or AFBC */
308 should_tile
&= !(template->bind
& PIPE_BIND_DEPTH_STENCIL
);
310 /* Set the layout appropriately */
311 bo
->layout
= should_tile
? PAN_TILED
: PAN_LINEAR
;
313 panfrost_setup_slices(template, bo
);
315 struct panfrost_memory mem
;
317 panfrost_drm_allocate_slab(screen
, &mem
, bo
->size
/ 4096, true, 0, 0, 0);
321 bo
->gem_handle
= mem
.gem_handle
;
326 static struct pipe_resource
*
327 panfrost_resource_create(struct pipe_screen
*screen
,
328 const struct pipe_resource
*template)
330 struct panfrost_resource
*so
= rzalloc(screen
, struct panfrost_resource
);
331 struct panfrost_screen
*pscreen
= (struct panfrost_screen
*) screen
;
333 so
->base
= *template;
334 so
->base
.screen
= screen
;
336 pipe_reference_init(&so
->base
.reference
, 1);
338 /* Make sure we're familiar */
339 switch (template->target
) {
341 case PIPE_TEXTURE_1D
:
342 case PIPE_TEXTURE_2D
:
343 case PIPE_TEXTURE_3D
:
344 case PIPE_TEXTURE_CUBE
:
345 case PIPE_TEXTURE_RECT
:
346 case PIPE_TEXTURE_2D_ARRAY
:
349 DBG("Unknown texture target %d\n", template->target
);
353 util_range_init(&so
->valid_buffer_range
);
355 if (template->bind
& PIPE_BIND_DISPLAY_TARGET
||
356 template->bind
& PIPE_BIND_SCANOUT
||
357 template->bind
& PIPE_BIND_SHARED
) {
358 struct pipe_resource scanout_templat
= *template;
359 struct renderonly_scanout
*scanout
;
360 struct winsys_handle handle
;
362 scanout
= renderonly_scanout_for_resource(&scanout_templat
,
363 pscreen
->ro
, &handle
);
367 assert(handle
.type
== WINSYS_HANDLE_TYPE_FD
);
368 /* TODO: handle modifiers? */
369 so
= pan_resource(screen
->resource_from_handle(screen
, template,
371 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
));
372 close(handle
.handle
);
376 so
->scanout
= scanout
;
377 pscreen
->display_target
= so
;
379 so
->bo
= panfrost_create_bo(pscreen
, template);
382 return (struct pipe_resource
*)so
;
386 panfrost_destroy_bo(struct panfrost_screen
*screen
, struct panfrost_bo
*bo
)
389 struct panfrost_memory mem
= {
393 .gem_handle
= bo
->gem_handle
,
396 panfrost_drm_free_slab(screen
, &mem
);
399 if (bo
->has_checksum
) {
400 struct panfrost_memory mem
= {
401 .cpu
= bo
->checksum_slab
.cpu
,
402 .gpu
= bo
->checksum_slab
.gpu
,
403 .size
= bo
->checksum_slab
.size
,
404 .gem_handle
= bo
->checksum_slab
.gem_handle
,
407 panfrost_drm_free_slab(screen
, &mem
);
411 panfrost_drm_free_imported_bo(screen
, bo
);
418 panfrost_bo_reference(struct panfrost_bo
*bo
)
420 pipe_reference(NULL
, &bo
->reference
);
424 panfrost_bo_unreference(struct pipe_screen
*screen
, struct panfrost_bo
*bo
)
426 /* When the reference count goes to zero, we need to cleanup */
428 if (pipe_reference(&bo
->reference
, NULL
)) {
429 panfrost_destroy_bo(pan_screen(screen
), bo
);
434 panfrost_resource_destroy(struct pipe_screen
*screen
,
435 struct pipe_resource
*pt
)
437 struct panfrost_screen
*pscreen
= pan_screen(screen
);
438 struct panfrost_resource
*rsrc
= (struct panfrost_resource
*) pt
;
441 renderonly_scanout_destroy(rsrc
->scanout
, pscreen
->ro
);
444 panfrost_bo_unreference(screen
, rsrc
->bo
);
446 util_range_destroy(&rsrc
->valid_buffer_range
);
451 panfrost_transfer_map(struct pipe_context
*pctx
,
452 struct pipe_resource
*resource
,
454 unsigned usage
, /* a combination of PIPE_TRANSFER_x */
455 const struct pipe_box
*box
,
456 struct pipe_transfer
**out_transfer
)
458 int bytes_per_pixel
= util_format_get_blocksize(resource
->format
);
459 struct panfrost_resource
*rsrc
= pan_resource(resource
);
460 struct panfrost_bo
*bo
= rsrc
->bo
;
462 struct panfrost_gtransfer
*transfer
= rzalloc(pctx
, struct panfrost_gtransfer
);
463 transfer
->base
.level
= level
;
464 transfer
->base
.usage
= usage
;
465 transfer
->base
.box
= *box
;
467 pipe_resource_reference(&transfer
->base
.resource
, resource
);
469 *out_transfer
= &transfer
->base
;
471 /* Check if we're bound for rendering and this is a read pixels. If so,
472 * we need to flush */
474 struct panfrost_context
*ctx
= pan_context(pctx
);
475 struct pipe_framebuffer_state
*fb
= &ctx
->pipe_framebuffer
;
477 bool is_bound
= false;
479 for (unsigned c
= 0; c
< fb
->nr_cbufs
; ++c
) {
480 is_bound
|= fb
->cbufs
[c
]->texture
== resource
;
483 if (is_bound
&& (usage
& PIPE_TRANSFER_READ
)) {
485 panfrost_flush(pctx
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
488 /* TODO: Respect usage flags */
490 if (usage
& PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
) {
491 /* TODO: reallocate */
492 //printf("debug: Missed reallocate\n");
493 } else if ((usage
& PIPE_TRANSFER_WRITE
)
494 && resource
->target
== PIPE_BUFFER
495 && !util_ranges_intersect(&rsrc
->valid_buffer_range
, box
->x
, box
->x
+ box
->width
)) {
496 /* No flush for writes to uninitialized */
497 } else if (!(usage
& PIPE_TRANSFER_UNSYNCHRONIZED
)) {
498 if (usage
& PIPE_TRANSFER_WRITE
) {
499 /* STUB: flush reading */
500 //printf("debug: missed reading flush %d\n", resource->target);
501 } else if (usage
& PIPE_TRANSFER_READ
) {
502 /* STUB: flush writing */
503 //printf("debug: missed writing flush %d (%d-%d)\n", resource->target, box->x, box->x + box->width);
505 /* Why are you even mapping?! */
509 if (bo
->layout
!= PAN_LINEAR
) {
510 /* Non-linear resources need to be indirectly mapped */
512 if (usage
& PIPE_TRANSFER_MAP_DIRECTLY
)
515 transfer
->base
.stride
= box
->width
* bytes_per_pixel
;
516 transfer
->base
.layer_stride
= transfer
->base
.stride
* box
->height
;
517 transfer
->map
= rzalloc_size(transfer
, transfer
->base
.layer_stride
* box
->depth
);
518 assert(box
->depth
== 1);
520 if ((usage
& PIPE_TRANSFER_READ
) && bo
->slices
[level
].initialized
) {
521 if (bo
->layout
== PAN_AFBC
) {
522 DBG("Unimplemented: reads from AFBC");
523 } else if (bo
->layout
== PAN_TILED
) {
524 panfrost_load_tiled_image(
526 bo
->cpu
+ bo
->slices
[level
].offset
,
528 transfer
->base
.stride
,
529 bo
->slices
[level
].stride
,
530 util_format_get_blocksize(resource
->format
));
534 return transfer
->map
;
536 transfer
->base
.stride
= bo
->slices
[level
].stride
;
537 transfer
->base
.layer_stride
= bo
->cubemap_stride
;
539 /* By mapping direct-write, we're implicitly already
540 * initialized (maybe), so be conservative */
542 if ((usage
& PIPE_TRANSFER_WRITE
) && (usage
& PIPE_TRANSFER_MAP_DIRECTLY
))
543 bo
->slices
[level
].initialized
= true;
546 + bo
->slices
[level
].offset
547 + transfer
->base
.box
.z
* bo
->cubemap_stride
548 + transfer
->base
.box
.y
* bo
->slices
[level
].stride
549 + transfer
->base
.box
.x
* bytes_per_pixel
;
554 panfrost_transfer_unmap(struct pipe_context
*pctx
,
555 struct pipe_transfer
*transfer
)
557 /* Gallium expects writeback here, so we tile */
559 struct panfrost_gtransfer
*trans
= pan_transfer(transfer
);
560 struct panfrost_resource
*prsrc
= (struct panfrost_resource
*) transfer
->resource
;
563 struct panfrost_bo
*bo
= prsrc
->bo
;
565 if (transfer
->usage
& PIPE_TRANSFER_WRITE
) {
566 unsigned level
= transfer
->level
;
567 bo
->slices
[level
].initialized
= true;
569 if (bo
->layout
== PAN_AFBC
) {
570 DBG("Unimplemented: writes to AFBC\n");
571 } else if (bo
->layout
== PAN_TILED
) {
572 assert(transfer
->box
.depth
== 1);
574 panfrost_store_tiled_image(
575 bo
->cpu
+ bo
->slices
[level
].offset
,
578 bo
->slices
[level
].stride
,
580 util_format_get_blocksize(prsrc
->base
.format
));
586 util_range_add(&prsrc
->valid_buffer_range
,
588 transfer
->box
.x
+ transfer
->box
.width
);
590 /* Derefence the resource */
591 pipe_resource_reference(&transfer
->resource
, NULL
);
593 /* Transfer itself is RALLOCed at the moment */
594 ralloc_free(transfer
);
598 panfrost_transfer_flush_region(struct pipe_context
*pctx
,
599 struct pipe_transfer
*transfer
,
600 const struct pipe_box
*box
)
602 struct panfrost_resource
*rsc
= pan_resource(transfer
->resource
);
604 if (transfer
->resource
->target
== PIPE_BUFFER
) {
605 util_range_add(&rsc
->valid_buffer_range
,
606 transfer
->box
.x
+ box
->x
,
607 transfer
->box
.x
+ box
->x
+ box
->width
);
611 static struct pb_slab
*
612 panfrost_slab_alloc(void *priv
, unsigned heap
, unsigned entry_size
, unsigned group_index
)
614 struct panfrost_screen
*screen
= (struct panfrost_screen
*) priv
;
615 struct panfrost_memory
*mem
= rzalloc(screen
, struct panfrost_memory
);
617 size_t slab_size
= (1 << (MAX_SLAB_ENTRY_SIZE
+ 1));
619 mem
->slab
.num_entries
= slab_size
/ entry_size
;
620 mem
->slab
.num_free
= mem
->slab
.num_entries
;
622 LIST_INITHEAD(&mem
->slab
.free
);
623 for (unsigned i
= 0; i
< mem
->slab
.num_entries
; ++i
) {
624 /* Create a slab entry */
625 struct panfrost_memory_entry
*entry
= rzalloc(mem
, struct panfrost_memory_entry
);
626 entry
->offset
= entry_size
* i
;
628 entry
->base
.slab
= &mem
->slab
;
629 entry
->base
.group_index
= group_index
;
631 LIST_ADDTAIL(&entry
->base
.head
, &mem
->slab
.free
);
634 /* Actually allocate the memory from kernel-space. Mapped, same_va, no
637 panfrost_drm_allocate_slab(screen
, mem
, slab_size
/ 4096, true, 0, 0, 0);
643 panfrost_slab_can_reclaim(void *priv
, struct pb_slab_entry
*entry
)
645 struct panfrost_memory_entry
*p_entry
= (struct panfrost_memory_entry
*) entry
;
646 return p_entry
->freed
;
650 panfrost_slab_free(void *priv
, struct pb_slab
*slab
)
652 struct panfrost_memory
*mem
= (struct panfrost_memory
*) slab
;
653 struct panfrost_screen
*screen
= (struct panfrost_screen
*) priv
;
655 panfrost_drm_free_slab(screen
, mem
);
660 panfrost_invalidate_resource(struct pipe_context
*pctx
, struct pipe_resource
*prsc
)
662 //DBG("TODO %s\n", __func__);
665 static enum pipe_format
666 panfrost_resource_get_internal_format(struct pipe_resource
*prsrc
)
668 return prsrc
->format
;
672 panfrost_generate_mipmap(
673 struct pipe_context
*pctx
,
674 struct pipe_resource
*prsrc
,
675 enum pipe_format format
,
678 unsigned first_layer
,
681 struct panfrost_context
*ctx
= pan_context(pctx
);
682 struct panfrost_resource
*rsrc
= pan_resource(prsrc
);
684 /* Generating a mipmap invalidates the written levels, so make that
685 * explicit so we don't try to wallpaper them back and end up with
686 * u_blitter recursion */
689 for (unsigned l
= base_level
+ 1; l
<= last_level
; ++l
)
690 rsrc
->bo
->slices
[l
].initialized
= false;
692 /* Beyond that, we just delegate the hard stuff. We're careful to
693 * include flushes on both ends to make sure the data is really valid.
694 * We could be doing a lot better perf-wise, especially once we have
695 * reorder-type optimizations in place. But for now prioritize
698 struct panfrost_job
*job
= panfrost_get_job_for_fbo(ctx
);
699 bool has_draws
= job
->last_job
.gpu
;
702 panfrost_flush(pctx
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
704 /* We've flushed the original buffer if needed, now trigger a blit */
706 bool blit_res
= util_gen_mipmap(
708 base_level
, last_level
,
709 first_layer
, last_layer
,
710 PIPE_TEX_FILTER_LINEAR
);
712 /* If the blit was successful, flush once more. If it wasn't, well, let
713 * the state tracker deal with it. */
716 panfrost_flush(pctx
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
721 /* Computes the address to a texture at a particular slice */
724 panfrost_get_texture_address(
725 struct panfrost_resource
*rsrc
,
726 unsigned level
, unsigned face
)
728 unsigned level_offset
= rsrc
->bo
->slices
[level
].offset
;
729 unsigned face_offset
= face
* rsrc
->bo
->cubemap_stride
;
731 /* Lower-bit is set when sampling from colour AFBC */
732 bool is_afbc
= rsrc
->bo
->layout
== PAN_AFBC
;
733 bool is_zs
= rsrc
->base
.bind
& PIPE_BIND_DEPTH_STENCIL
;
734 unsigned afbc_bit
= (is_afbc
&& !is_zs
) ? 1 : 0;
736 return rsrc
->bo
->gpu
+ level_offset
+ face_offset
+ afbc_bit
;
740 panfrost_resource_set_stencil(struct pipe_resource
*prsrc
,
741 struct pipe_resource
*stencil
)
743 pan_resource(prsrc
)->separate_stencil
= pan_resource(stencil
);
746 static struct pipe_resource
*
747 panfrost_resource_get_stencil(struct pipe_resource
*prsrc
)
749 return &pan_resource(prsrc
)->separate_stencil
->base
;
752 static const struct u_transfer_vtbl transfer_vtbl
= {
753 .resource_create
= panfrost_resource_create
,
754 .resource_destroy
= panfrost_resource_destroy
,
755 .transfer_map
= panfrost_transfer_map
,
756 .transfer_unmap
= panfrost_transfer_unmap
,
757 .transfer_flush_region
= panfrost_transfer_flush_region
,
758 .get_internal_format
= panfrost_resource_get_internal_format
,
759 .set_stencil
= panfrost_resource_set_stencil
,
760 .get_stencil
= panfrost_resource_get_stencil
,
764 panfrost_resource_screen_init(struct panfrost_screen
*pscreen
)
766 //pscreen->base.resource_create_with_modifiers =
767 // panfrost_resource_create_with_modifiers;
768 pscreen
->base
.resource_create
= u_transfer_helper_resource_create
;
769 pscreen
->base
.resource_destroy
= u_transfer_helper_resource_destroy
;
770 pscreen
->base
.resource_from_handle
= panfrost_resource_from_handle
;
771 pscreen
->base
.resource_get_handle
= panfrost_resource_get_handle
;
772 pscreen
->base
.transfer_helper
= u_transfer_helper_create(&transfer_vtbl
,
776 pb_slabs_init(&pscreen
->slabs
,
780 3, /* Number of heaps */
784 panfrost_slab_can_reclaim
,
790 panfrost_resource_screen_deinit(struct panfrost_screen
*pscreen
)
792 pb_slabs_deinit(&pscreen
->slabs
);
796 panfrost_resource_context_init(struct pipe_context
*pctx
)
798 pctx
->transfer_map
= u_transfer_helper_transfer_map
;
799 pctx
->transfer_flush_region
= u_transfer_helper_transfer_flush_region
;
800 pctx
->transfer_unmap
= u_transfer_helper_transfer_unmap
;
801 pctx
->buffer_subdata
= u_default_buffer_subdata
;
802 pctx
->create_surface
= panfrost_create_surface
;
803 pctx
->surface_destroy
= panfrost_surface_destroy
;
804 pctx
->resource_copy_region
= util_resource_copy_region
;
805 pctx
->blit
= panfrost_blit
;
806 pctx
->generate_mipmap
= panfrost_generate_mipmap
;
807 pctx
->flush_resource
= panfrost_flush_resource
;
808 pctx
->invalidate_resource
= panfrost_invalidate_resource
;
809 pctx
->transfer_flush_region
= u_transfer_helper_transfer_flush_region
;
810 pctx
->buffer_subdata
= u_default_buffer_subdata
;
811 pctx
->texture_subdata
= u_default_texture_subdata
;