panfrost: Implement 3D texture resource management
[mesa.git] / src / gallium / drivers / panfrost / pan_resource.c
1 /*
2 * Copyright (C) 2008 VMware, Inc.
3 * Copyright (C) 2014 Broadcom
4 * Copyright (C) 2018-2019 Alyssa Rosenzweig
5 * Copyright (C) 2019 Collabora
6 *
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:
13 *
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
16 * Software.
17 *
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
24 * SOFTWARE.
25 *
26 * Authors (Collabora):
27 * Tomeu Vizoso <tomeu.vizoso@collabora.com>
28 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
29 *
30 */
31
32 #include <xf86drm.h>
33 #include <fcntl.h>
34 #include "drm-uapi/drm_fourcc.h"
35
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
43 #include "pan_context.h"
44 #include "pan_screen.h"
45 #include "pan_resource.h"
46 #include "pan_swizzle.h"
47 #include "pan_util.h"
48
49 static struct pipe_resource *
50 panfrost_resource_from_handle(struct pipe_screen *pscreen,
51 const struct pipe_resource *templat,
52 struct winsys_handle *whandle,
53 unsigned usage)
54 {
55 struct panfrost_screen *screen = pan_screen(pscreen);
56 struct panfrost_resource *rsc;
57 struct pipe_resource *prsc;
58
59 assert(whandle->type == WINSYS_HANDLE_TYPE_FD);
60
61 rsc = CALLOC_STRUCT(panfrost_resource);
62 if (!rsc)
63 return NULL;
64
65 prsc = &rsc->base;
66
67 *prsc = *templat;
68
69 pipe_reference_init(&prsc->reference, 1);
70 prsc->screen = pscreen;
71
72 rsc->bo = screen->driver->import_bo(screen, whandle);
73 rsc->bo->slices[0].stride = whandle->stride;
74
75 if (screen->ro) {
76 rsc->scanout =
77 renderonly_create_gpu_import_for_resource(prsc, screen->ro, NULL);
78 /* failure is expected in some cases.. */
79 }
80
81 return prsc;
82 }
83
84 static boolean
85 panfrost_resource_get_handle(struct pipe_screen *pscreen,
86 struct pipe_context *ctx,
87 struct pipe_resource *pt,
88 struct winsys_handle *handle,
89 unsigned usage)
90 {
91 struct panfrost_screen *screen = pan_screen(pscreen);
92 struct panfrost_resource *rsrc = (struct panfrost_resource *) pt;
93 struct renderonly_scanout *scanout = rsrc->scanout;
94
95 handle->modifier = DRM_FORMAT_MOD_INVALID;
96
97 if (handle->type == WINSYS_HANDLE_TYPE_SHARED) {
98 return FALSE;
99 } else if (handle->type == WINSYS_HANDLE_TYPE_KMS) {
100 if (renderonly_get_handle(scanout, handle))
101 return TRUE;
102
103 handle->handle = rsrc->bo->gem_handle;
104 handle->stride = rsrc->bo->slices[0].stride;
105 return TRUE;
106 } else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
107 if (scanout) {
108 struct drm_prime_handle args = {
109 .handle = scanout->handle,
110 .flags = DRM_CLOEXEC,
111 };
112
113 int ret = drmIoctl(screen->ro->kms_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
114 if (ret == -1)
115 return FALSE;
116
117 handle->stride = scanout->stride;
118 handle->handle = args.fd;
119
120 return TRUE;
121 } else
122 return screen->driver->export_bo(screen, rsrc->bo->gem_handle, rsrc->bo->slices[0].stride, handle);
123 }
124
125 return FALSE;
126 }
127
128 static void
129 panfrost_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
130 {
131 //DBG("TODO %s\n", __func__);
132 }
133
134 static struct pipe_surface *
135 panfrost_create_surface(struct pipe_context *pipe,
136 struct pipe_resource *pt,
137 const struct pipe_surface *surf_tmpl)
138 {
139 struct pipe_surface *ps = NULL;
140
141 ps = CALLOC_STRUCT(pipe_surface);
142
143 if (ps) {
144 pipe_reference_init(&ps->reference, 1);
145 pipe_resource_reference(&ps->texture, pt);
146 ps->context = pipe;
147 ps->format = surf_tmpl->format;
148
149 if (pt->target != PIPE_BUFFER) {
150 assert(surf_tmpl->u.tex.level <= pt->last_level);
151 ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level);
152 ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level);
153 ps->u.tex.level = surf_tmpl->u.tex.level;
154 ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
155 ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
156 } else {
157 /* setting width as number of elements should get us correct renderbuffer width */
158 ps->width = surf_tmpl->u.buf.last_element - surf_tmpl->u.buf.first_element + 1;
159 ps->height = pt->height0;
160 ps->u.buf.first_element = surf_tmpl->u.buf.first_element;
161 ps->u.buf.last_element = surf_tmpl->u.buf.last_element;
162 assert(ps->u.buf.first_element <= ps->u.buf.last_element);
163 assert(ps->u.buf.last_element < ps->width);
164 }
165 }
166
167 return ps;
168 }
169
170 static void
171 panfrost_surface_destroy(struct pipe_context *pipe,
172 struct pipe_surface *surf)
173 {
174 assert(surf->texture);
175 pipe_resource_reference(&surf->texture, NULL);
176 free(surf);
177 }
178
179 static void
180 panfrost_setup_slices(const struct pipe_resource *tmpl, struct panfrost_bo *bo)
181 {
182 unsigned width = tmpl->width0;
183 unsigned height = tmpl->height0;
184 unsigned depth = tmpl->depth0;
185 unsigned bytes_per_pixel = util_format_get_blocksize(tmpl->format);
186
187 assert(depth > 0);
188
189 /* Tiled operates blockwise; linear is packed. Also, anything
190 * we render to has to be tile-aligned. Maybe not strictly
191 * necessary, but we're not *that* pressed for memory and it
192 * makes code a lot simpler */
193
194 bool renderable = tmpl->bind &
195 (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
196 bool tiled = bo->layout == PAN_TILED;
197 bool should_align = renderable || tiled;
198
199 /* We don't know how to specify a 2D stride for 3D textures */
200
201 bool should_align_stride =
202 tmpl->target != PIPE_TEXTURE_3D;
203
204 should_align &= should_align_stride;
205
206 unsigned offset = 0;
207 unsigned size_2d = 0;
208
209 for (unsigned l = 0; l <= tmpl->last_level; ++l) {
210 struct panfrost_slice *slice = &bo->slices[l];
211
212 unsigned effective_width = width;
213 unsigned effective_height = height;
214 unsigned effective_depth = depth;
215
216 if (should_align) {
217 effective_width = ALIGN(effective_width, 16);
218 effective_height = ALIGN(effective_height, 16);
219
220 /* We don't need to align depth */
221 }
222
223 slice->offset = offset;
224
225 /* Compute the would-be stride */
226 unsigned stride = bytes_per_pixel * effective_width;
227
228 /* ..but cache-line align it for performance */
229 if (should_align_stride)
230 stride = ALIGN(stride, 64);
231
232 slice->stride = stride;
233
234 unsigned slice_one_size = slice->stride * effective_height;
235 unsigned slice_full_size = slice_one_size * effective_depth;
236
237 /* Report 2D size for 3D texturing */
238
239 if (l == 0)
240 size_2d = slice_one_size;
241
242 offset += slice_full_size;
243
244 width = u_minify(width, 1);
245 height = u_minify(height, 1);
246 depth = u_minify(depth, 1);
247 }
248
249 assert(tmpl->array_size);
250
251 if (tmpl->target != PIPE_TEXTURE_3D) {
252 /* Arrays and cubemaps have the entire miptree duplicated */
253
254 bo->cubemap_stride = ALIGN(offset, 64);
255 bo->size = ALIGN(bo->cubemap_stride * tmpl->array_size, 4096);
256 } else {
257 /* 3D strides across the 2D layers */
258 assert(tmpl->array_size == 1);
259
260 bo->cubemap_stride = size_2d;
261 bo->size = ALIGN(offset, 4096);
262 }
263 }
264
265 static struct panfrost_bo *
266 panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *template)
267 {
268 struct panfrost_bo *bo = CALLOC_STRUCT(panfrost_bo);
269 pipe_reference_init(&bo->reference, 1);
270
271 /* Based on the usage, figure out what storing will be used. There are
272 * various tradeoffs:
273 *
274 * Linear: the basic format, bad for memory bandwidth, bad for cache
275 * use. Zero-copy, though. Renderable.
276 *
277 * Tiled: Not compressed, but cache-optimized. Expensive to write into
278 * (due to software tiling), but cheap to sample from. Ideal for most
279 * textures.
280 *
281 * AFBC: Compressed and renderable (so always desirable for non-scanout
282 * rendertargets). Cheap to sample from. The format is black box, so we
283 * can't read/write from software.
284 */
285
286 /* Tiling textures is almost always faster, unless we only use it once */
287
288 bool is_texture = (template->bind & PIPE_BIND_SAMPLER_VIEW);
289 bool is_2d = template->depth0 == 1;
290 bool is_streaming = (template->usage != PIPE_USAGE_STREAM);
291
292 bool should_tile = is_streaming && is_texture && is_2d;
293
294 /* Set the layout appropriately */
295 bo->layout = should_tile ? PAN_TILED : PAN_LINEAR;
296
297 panfrost_setup_slices(template, bo);
298
299 if (bo->layout == PAN_TILED || bo->layout == PAN_LINEAR) {
300 struct panfrost_memory mem;
301
302 screen->driver->allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
303
304 bo->cpu = mem.cpu;
305 bo->gpu = mem.gpu;
306 bo->gem_handle = mem.gem_handle;
307 }
308
309 return bo;
310 }
311
312 static struct pipe_resource *
313 panfrost_resource_create(struct pipe_screen *screen,
314 const struct pipe_resource *template)
315 {
316 struct panfrost_resource *so = CALLOC_STRUCT(panfrost_resource);
317 struct panfrost_screen *pscreen = (struct panfrost_screen *) screen;
318
319 so->base = *template;
320 so->base.screen = screen;
321
322 pipe_reference_init(&so->base.reference, 1);
323
324 /* Make sure we're familiar */
325 switch (template->target) {
326 case PIPE_BUFFER:
327 case PIPE_TEXTURE_1D:
328 case PIPE_TEXTURE_2D:
329 case PIPE_TEXTURE_3D:
330 case PIPE_TEXTURE_CUBE:
331 case PIPE_TEXTURE_RECT:
332 break;
333 default:
334 DBG("Unknown texture target %d\n", template->target);
335 assert(0);
336 }
337
338 util_range_init(&so->valid_buffer_range);
339
340 if (template->bind & PIPE_BIND_DISPLAY_TARGET ||
341 template->bind & PIPE_BIND_SCANOUT ||
342 template->bind & PIPE_BIND_SHARED) {
343 struct pipe_resource scanout_templat = *template;
344 struct renderonly_scanout *scanout;
345 struct winsys_handle handle;
346
347 scanout = renderonly_scanout_for_resource(&scanout_templat,
348 pscreen->ro, &handle);
349 if (!scanout)
350 return NULL;
351
352 assert(handle.type == WINSYS_HANDLE_TYPE_FD);
353 /* TODO: handle modifiers? */
354 so = pan_resource(screen->resource_from_handle(screen, template,
355 &handle,
356 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE));
357 close(handle.handle);
358 if (!so)
359 return NULL;
360
361 so->scanout = scanout;
362 pscreen->display_target = so;
363 } else {
364 so->bo = panfrost_create_bo(pscreen, template);
365 }
366
367 return (struct pipe_resource *)so;
368 }
369
370 static void
371 panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
372 {
373 struct panfrost_bo *bo = (struct panfrost_bo *)pbo;
374
375 if ((bo->layout == PAN_LINEAR || bo->layout == PAN_TILED) &&
376 !bo->imported) {
377 struct panfrost_memory mem = {
378 .cpu = bo->cpu,
379 .gpu = bo->gpu,
380 .size = bo->size,
381 .gem_handle = bo->gem_handle,
382 };
383
384 screen->driver->free_slab(screen, &mem);
385 }
386
387 if (bo->layout == PAN_AFBC) {
388 /* TODO */
389 DBG("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size);
390 }
391
392 if (bo->has_checksum) {
393 struct panfrost_memory mem = {
394 .cpu = bo->checksum_slab.cpu,
395 .gpu = bo->checksum_slab.gpu,
396 .size = bo->checksum_slab.size,
397 .gem_handle = bo->checksum_slab.gem_handle,
398 };
399
400 screen->driver->free_slab(screen, &mem);
401 }
402
403 if (bo->imported) {
404 screen->driver->free_imported_bo(screen, bo);
405 }
406 }
407
408 void
409 panfrost_bo_reference(struct panfrost_bo *bo)
410 {
411 pipe_reference(NULL, &bo->reference);
412 }
413
414 void
415 panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
416 {
417 /* When the reference count goes to zero, we need to cleanup */
418
419 if (pipe_reference(&bo->reference, NULL)) {
420 panfrost_destroy_bo(pan_screen(screen), bo);
421 }
422 }
423
424 static void
425 panfrost_resource_destroy(struct pipe_screen *screen,
426 struct pipe_resource *pt)
427 {
428 struct panfrost_screen *pscreen = pan_screen(screen);
429 struct panfrost_resource *rsrc = (struct panfrost_resource *) pt;
430
431 if (rsrc->scanout)
432 renderonly_scanout_destroy(rsrc->scanout, pscreen->ro);
433
434 if (rsrc->bo)
435 panfrost_bo_unreference(screen, rsrc->bo);
436
437 util_range_destroy(&rsrc->valid_buffer_range);
438 FREE(rsrc);
439 }
440
441 static void *
442 panfrost_transfer_map(struct pipe_context *pctx,
443 struct pipe_resource *resource,
444 unsigned level,
445 unsigned usage, /* a combination of PIPE_TRANSFER_x */
446 const struct pipe_box *box,
447 struct pipe_transfer **out_transfer)
448 {
449 int bytes_per_pixel = util_format_get_blocksize(resource->format);
450 struct panfrost_resource *rsrc = pan_resource(resource);
451 struct panfrost_bo *bo = rsrc->bo;
452
453 struct panfrost_gtransfer *transfer = CALLOC_STRUCT(panfrost_gtransfer);
454 transfer->base.level = level;
455 transfer->base.usage = usage;
456 transfer->base.box = *box;
457
458 pipe_resource_reference(&transfer->base.resource, resource);
459
460 *out_transfer = &transfer->base;
461
462 /* Check if we're bound for rendering and this is a read pixels. If so,
463 * we need to flush */
464
465 struct panfrost_context *ctx = pan_context(pctx);
466 struct pipe_framebuffer_state *fb = &ctx->pipe_framebuffer;
467
468 bool is_bound = false;
469
470 for (unsigned c = 0; c < fb->nr_cbufs; ++c) {
471 is_bound |= fb->cbufs[c]->texture == resource;
472 }
473
474 if (is_bound && (usage & PIPE_TRANSFER_READ)) {
475 assert(level == 0);
476 panfrost_flush(pctx, NULL, PIPE_FLUSH_END_OF_FRAME);
477 }
478
479 /* TODO: Respect usage flags */
480
481 if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
482 /* TODO: reallocate */
483 //printf("debug: Missed reallocate\n");
484 } else if ((usage & PIPE_TRANSFER_WRITE)
485 && resource->target == PIPE_BUFFER
486 && !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width)) {
487 /* No flush for writes to uninitialized */
488 } else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
489 if (usage & PIPE_TRANSFER_WRITE) {
490 /* STUB: flush reading */
491 //printf("debug: missed reading flush %d\n", resource->target);
492 } else if (usage & PIPE_TRANSFER_READ) {
493 /* STUB: flush writing */
494 //printf("debug: missed writing flush %d (%d-%d)\n", resource->target, box->x, box->x + box->width);
495 } else {
496 /* Why are you even mapping?! */
497 }
498 }
499
500 if (bo->layout != PAN_LINEAR) {
501 /* Non-linear resources need to be indirectly mapped */
502
503 if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
504 return NULL;
505
506 transfer->base.stride = box->width * bytes_per_pixel;
507 transfer->base.layer_stride = transfer->base.stride * box->height;
508
509 /* TODO: Reads */
510 transfer->map = malloc(transfer->base.layer_stride * box->depth);
511
512 return transfer->map;
513 } else {
514 transfer->base.stride = bo->slices[level].stride;
515 transfer->base.layer_stride = bo->cubemap_stride;
516
517 return bo->cpu
518 + bo->slices[level].offset
519 + transfer->base.box.z * bo->cubemap_stride
520 + transfer->base.box.y * bo->slices[level].stride
521 + transfer->base.box.x * bytes_per_pixel;
522 }
523 }
524
525 static void
526 panfrost_tile_texture(struct panfrost_screen *screen, struct panfrost_resource *rsrc, struct panfrost_gtransfer *trans)
527 {
528 struct panfrost_bo *bo = (struct panfrost_bo *)rsrc->bo;
529
530 unsigned level = trans->base.level;
531
532 panfrost_texture_swizzle(
533 trans->base.box.x,
534 trans->base.box.y,
535 trans->base.box.width,
536 trans->base.box.height,
537 util_format_get_blocksize(rsrc->base.format),
538 u_minify(rsrc->base.width0, level),
539 trans->map,
540 bo->cpu
541 + bo->slices[level].offset
542 + bo->cubemap_stride * trans->base.box.z
543 );
544 }
545
546 static void
547 panfrost_transfer_unmap(struct pipe_context *pctx,
548 struct pipe_transfer *transfer)
549 {
550 struct panfrost_context *ctx = pan_context(pctx);
551
552 /* Gallium expects writeback here, so we tile */
553
554 struct panfrost_gtransfer *trans = pan_transfer(transfer);
555 struct panfrost_resource *prsrc = (struct panfrost_resource *) transfer->resource;
556
557 if (trans->map) {
558 struct panfrost_bo *bo = prsrc->bo;
559
560 if (transfer->usage & PIPE_TRANSFER_WRITE) {
561
562 if (bo->layout == PAN_AFBC) {
563 DBG("Unimplemented: writes to AFBC\n");
564 } else if (bo->layout == PAN_TILED) {
565 struct pipe_context *gallium = (struct pipe_context *) ctx;
566 struct panfrost_screen *screen = pan_screen(gallium->screen);
567 assert(transfer->box.depth == 1);
568 panfrost_tile_texture(screen, prsrc, trans);
569 }
570 }
571
572 free(trans->map);
573 }
574
575
576 util_range_add(&prsrc->valid_buffer_range,
577 transfer->box.x,
578 transfer->box.x + transfer->box.width);
579
580 /* Derefence the resource */
581 pipe_resource_reference(&transfer->resource, NULL);
582
583 /* Transfer itself is CALLOCed at the moment */
584 free(transfer);
585 }
586
587 static void
588 panfrost_transfer_flush_region(struct pipe_context *pctx,
589 struct pipe_transfer *transfer,
590 const struct pipe_box *box)
591 {
592 struct panfrost_resource *rsc = pan_resource(transfer->resource);
593
594 if (transfer->resource->target == PIPE_BUFFER) {
595 util_range_add(&rsc->valid_buffer_range,
596 transfer->box.x + box->x,
597 transfer->box.x + box->x + box->width);
598 }
599 }
600
601 static struct pb_slab *
602 panfrost_slab_alloc(void *priv, unsigned heap, unsigned entry_size, unsigned group_index)
603 {
604 struct panfrost_screen *screen = (struct panfrost_screen *) priv;
605 struct panfrost_memory *mem = CALLOC_STRUCT(panfrost_memory);
606
607 size_t slab_size = (1 << (MAX_SLAB_ENTRY_SIZE + 1));
608
609 mem->slab.num_entries = slab_size / entry_size;
610 mem->slab.num_free = mem->slab.num_entries;
611
612 LIST_INITHEAD(&mem->slab.free);
613 for (unsigned i = 0; i < mem->slab.num_entries; ++i) {
614 /* Create a slab entry */
615 struct panfrost_memory_entry *entry = CALLOC_STRUCT(panfrost_memory_entry);
616 entry->offset = entry_size * i;
617
618 entry->base.slab = &mem->slab;
619 entry->base.group_index = group_index;
620
621 LIST_ADDTAIL(&entry->base.head, &mem->slab.free);
622 }
623
624 /* Actually allocate the memory from kernel-space. Mapped, same_va, no
625 * special flags */
626
627 screen->driver->allocate_slab(screen, mem, slab_size / 4096, true, 0, 0, 0);
628
629 return &mem->slab;
630 }
631
632 static bool
633 panfrost_slab_can_reclaim(void *priv, struct pb_slab_entry *entry)
634 {
635 struct panfrost_memory_entry *p_entry = (struct panfrost_memory_entry *) entry;
636 return p_entry->freed;
637 }
638
639 static void
640 panfrost_slab_free(void *priv, struct pb_slab *slab)
641 {
642 struct panfrost_memory *mem = (struct panfrost_memory *) slab;
643 struct panfrost_screen *screen = (struct panfrost_screen *) priv;
644
645 screen->driver->free_slab(screen, mem);
646 }
647
648 static void
649 panfrost_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
650 {
651 //DBG("TODO %s\n", __func__);
652 }
653
654 static enum pipe_format
655 panfrost_resource_get_internal_format(struct pipe_resource *prsrc)
656 {
657 return prsrc->format;
658 }
659
660 static void
661 panfrost_resource_set_stencil(struct pipe_resource *prsrc,
662 struct pipe_resource *stencil)
663 {
664 pan_resource(prsrc)->separate_stencil = pan_resource(stencil);
665 }
666
667 static struct pipe_resource *
668 panfrost_resource_get_stencil(struct pipe_resource *prsrc)
669 {
670 return &pan_resource(prsrc)->separate_stencil->base;
671 }
672
673 static const struct u_transfer_vtbl transfer_vtbl = {
674 .resource_create = panfrost_resource_create,
675 .resource_destroy = panfrost_resource_destroy,
676 .transfer_map = panfrost_transfer_map,
677 .transfer_unmap = panfrost_transfer_unmap,
678 .transfer_flush_region = panfrost_transfer_flush_region,
679 .get_internal_format = panfrost_resource_get_internal_format,
680 .set_stencil = panfrost_resource_set_stencil,
681 .get_stencil = panfrost_resource_get_stencil,
682 };
683
684 void
685 panfrost_resource_screen_init(struct panfrost_screen *pscreen)
686 {
687 //pscreen->base.resource_create_with_modifiers =
688 // panfrost_resource_create_with_modifiers;
689 pscreen->base.resource_create = u_transfer_helper_resource_create;
690 pscreen->base.resource_destroy = u_transfer_helper_resource_destroy;
691 pscreen->base.resource_from_handle = panfrost_resource_from_handle;
692 pscreen->base.resource_get_handle = panfrost_resource_get_handle;
693 pscreen->base.transfer_helper = u_transfer_helper_create(&transfer_vtbl,
694 true, false,
695 true, true);
696
697 pb_slabs_init(&pscreen->slabs,
698 MIN_SLAB_ENTRY_SIZE,
699 MAX_SLAB_ENTRY_SIZE,
700
701 3, /* Number of heaps */
702
703 pscreen,
704
705 panfrost_slab_can_reclaim,
706 panfrost_slab_alloc,
707 panfrost_slab_free);
708 }
709
710 void
711 panfrost_resource_context_init(struct pipe_context *pctx)
712 {
713 pctx->transfer_map = u_transfer_helper_transfer_map;
714 pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
715 pctx->transfer_unmap = u_transfer_helper_transfer_unmap;
716 pctx->buffer_subdata = u_default_buffer_subdata;
717 pctx->create_surface = panfrost_create_surface;
718 pctx->surface_destroy = panfrost_surface_destroy;
719 pctx->resource_copy_region = util_resource_copy_region;
720 pctx->blit = panfrost_blit;
721 pctx->flush_resource = panfrost_flush_resource;
722 pctx->invalidate_resource = panfrost_invalidate_resource;
723 pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
724 pctx->buffer_subdata = u_default_buffer_subdata;
725 pctx->texture_subdata = u_default_texture_subdata;
726 }