panfrost: Linear depth/stencil should be aligned
[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 bytes_per_pixel = util_format_get_blocksize(tmpl->format);
185
186 /* Tiled operates blockwise; linear is packed. Also, anything
187 * we render to has to be tile-aligned. Maybe not strictly
188 * necessary, but we're not *that* pressed for memory and it
189 * makes code a lot simpler */
190
191 bool renderable = tmpl->bind &
192 (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
193 bool tiled = bo->layout == PAN_TILED;
194 bool should_align = renderable || tiled;
195
196 unsigned offset = 0;
197
198 for (unsigned l = 0; l <= tmpl->last_level; ++l) {
199 struct panfrost_slice *slice = &bo->slices[l];
200
201 unsigned effective_width = width;
202 unsigned effective_height = height;
203
204 if (should_align) {
205 effective_width = ALIGN(effective_width, 16);
206 effective_height = ALIGN(effective_height, 16);
207 }
208
209 slice->offset = offset;
210
211 /* Compute the would-be stride */
212 unsigned stride = bytes_per_pixel * effective_width;
213
214 /* ..but cache-line align it for performance */
215 stride = ALIGN(stride, 64);
216 slice->stride = stride;
217
218 offset += slice->stride * effective_height;
219
220 width = u_minify(width, 1);
221 height = u_minify(height, 1);
222 }
223
224 assert(tmpl->array_size);
225
226 bo->cubemap_stride = ALIGN(offset, 64);
227 bo->size = ALIGN(bo->cubemap_stride * tmpl->array_size, 4096);
228 }
229
230 static struct panfrost_bo *
231 panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *template)
232 {
233 struct panfrost_bo *bo = CALLOC_STRUCT(panfrost_bo);
234 pipe_reference_init(&bo->reference, 1);
235
236 /* Based on the usage, figure out what storing will be used. There are
237 * various tradeoffs:
238 *
239 * Linear: the basic format, bad for memory bandwidth, bad for cache
240 * use. Zero-copy, though. Renderable.
241 *
242 * Tiled: Not compressed, but cache-optimized. Expensive to write into
243 * (due to software tiling), but cheap to sample from. Ideal for most
244 * textures.
245 *
246 * AFBC: Compressed and renderable (so always desirable for non-scanout
247 * rendertargets). Cheap to sample from. The format is black box, so we
248 * can't read/write from software.
249 */
250
251 /* Tiling textures is almost always faster, unless we only use it once */
252 bool should_tile = (template->usage != PIPE_USAGE_STREAM) && (template->bind & PIPE_BIND_SAMPLER_VIEW);
253
254 /* For unclear reasons, depth/stencil is faster linear than AFBC, so
255 * make sure it's linear */
256
257 if (template->bind & PIPE_BIND_DEPTH_STENCIL)
258 should_tile = false;
259
260 /* Set the layout appropriately */
261 bo->layout = should_tile ? PAN_TILED : PAN_LINEAR;
262
263 panfrost_setup_slices(template, bo);
264
265 if (bo->layout == PAN_TILED || bo->layout == PAN_LINEAR) {
266 struct panfrost_memory mem;
267
268 screen->driver->allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
269
270 bo->cpu = mem.cpu;
271 bo->gpu = mem.gpu;
272 bo->gem_handle = mem.gem_handle;
273 }
274
275 return bo;
276 }
277
278 static struct pipe_resource *
279 panfrost_resource_create(struct pipe_screen *screen,
280 const struct pipe_resource *template)
281 {
282 struct panfrost_resource *so = CALLOC_STRUCT(panfrost_resource);
283 struct panfrost_screen *pscreen = (struct panfrost_screen *) screen;
284
285 so->base = *template;
286 so->base.screen = screen;
287
288 pipe_reference_init(&so->base.reference, 1);
289
290 /* Make sure we're familiar */
291 switch (template->target) {
292 case PIPE_BUFFER:
293 case PIPE_TEXTURE_1D:
294 case PIPE_TEXTURE_2D:
295 case PIPE_TEXTURE_3D:
296 case PIPE_TEXTURE_CUBE:
297 case PIPE_TEXTURE_RECT:
298 break;
299 default:
300 DBG("Unknown texture target %d\n", template->target);
301 assert(0);
302 }
303
304 util_range_init(&so->valid_buffer_range);
305
306 if (template->bind & PIPE_BIND_DISPLAY_TARGET ||
307 template->bind & PIPE_BIND_SCANOUT ||
308 template->bind & PIPE_BIND_SHARED) {
309 struct pipe_resource scanout_templat = *template;
310 struct renderonly_scanout *scanout;
311 struct winsys_handle handle;
312
313 scanout = renderonly_scanout_for_resource(&scanout_templat,
314 pscreen->ro, &handle);
315 if (!scanout)
316 return NULL;
317
318 assert(handle.type == WINSYS_HANDLE_TYPE_FD);
319 /* TODO: handle modifiers? */
320 so = pan_resource(screen->resource_from_handle(screen, template,
321 &handle,
322 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE));
323 close(handle.handle);
324 if (!so)
325 return NULL;
326
327 so->scanout = scanout;
328 pscreen->display_target = so;
329 } else {
330 so->bo = panfrost_create_bo(pscreen, template);
331 }
332
333 return (struct pipe_resource *)so;
334 }
335
336 static void
337 panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
338 {
339 struct panfrost_bo *bo = (struct panfrost_bo *)pbo;
340
341 if ((bo->layout == PAN_LINEAR || bo->layout == PAN_TILED) &&
342 !bo->imported) {
343 struct panfrost_memory mem = {
344 .cpu = bo->cpu,
345 .gpu = bo->gpu,
346 .size = bo->size,
347 .gem_handle = bo->gem_handle,
348 };
349
350 screen->driver->free_slab(screen, &mem);
351 }
352
353 if (bo->layout == PAN_AFBC) {
354 /* TODO */
355 DBG("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size);
356 }
357
358 if (bo->has_checksum) {
359 struct panfrost_memory mem = {
360 .cpu = bo->checksum_slab.cpu,
361 .gpu = bo->checksum_slab.gpu,
362 .size = bo->checksum_slab.size,
363 .gem_handle = bo->checksum_slab.gem_handle,
364 };
365
366 screen->driver->free_slab(screen, &mem);
367 }
368
369 if (bo->imported) {
370 screen->driver->free_imported_bo(screen, bo);
371 }
372 }
373
374 void
375 panfrost_bo_reference(struct panfrost_bo *bo)
376 {
377 pipe_reference(NULL, &bo->reference);
378 }
379
380 void
381 panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
382 {
383 /* When the reference count goes to zero, we need to cleanup */
384
385 if (pipe_reference(&bo->reference, NULL)) {
386 panfrost_destroy_bo(pan_screen(screen), bo);
387 }
388 }
389
390 static void
391 panfrost_resource_destroy(struct pipe_screen *screen,
392 struct pipe_resource *pt)
393 {
394 struct panfrost_screen *pscreen = pan_screen(screen);
395 struct panfrost_resource *rsrc = (struct panfrost_resource *) pt;
396
397 if (rsrc->scanout)
398 renderonly_scanout_destroy(rsrc->scanout, pscreen->ro);
399
400 if (rsrc->bo)
401 panfrost_bo_unreference(screen, rsrc->bo);
402
403 util_range_destroy(&rsrc->valid_buffer_range);
404 FREE(rsrc);
405 }
406
407 static void *
408 panfrost_transfer_map(struct pipe_context *pctx,
409 struct pipe_resource *resource,
410 unsigned level,
411 unsigned usage, /* a combination of PIPE_TRANSFER_x */
412 const struct pipe_box *box,
413 struct pipe_transfer **out_transfer)
414 {
415 int bytes_per_pixel = util_format_get_blocksize(resource->format);
416 struct panfrost_resource *rsrc = pan_resource(resource);
417 struct panfrost_bo *bo = rsrc->bo;
418
419 struct panfrost_gtransfer *transfer = CALLOC_STRUCT(panfrost_gtransfer);
420 transfer->base.level = level;
421 transfer->base.usage = usage;
422 transfer->base.box = *box;
423
424 pipe_resource_reference(&transfer->base.resource, resource);
425
426 *out_transfer = &transfer->base;
427
428 /* Check if we're bound for rendering and this is a read pixels. If so,
429 * we need to flush */
430
431 struct panfrost_context *ctx = pan_context(pctx);
432 struct pipe_framebuffer_state *fb = &ctx->pipe_framebuffer;
433
434 bool is_bound = false;
435
436 for (unsigned c = 0; c < fb->nr_cbufs; ++c) {
437 is_bound |= fb->cbufs[c]->texture == resource;
438 }
439
440 if (is_bound && (usage & PIPE_TRANSFER_READ)) {
441 assert(level == 0);
442 panfrost_flush(pctx, NULL, PIPE_FLUSH_END_OF_FRAME);
443 }
444
445 /* TODO: Respect usage flags */
446
447 if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
448 /* TODO: reallocate */
449 //printf("debug: Missed reallocate\n");
450 } else if ((usage & PIPE_TRANSFER_WRITE)
451 && resource->target == PIPE_BUFFER
452 && !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width)) {
453 /* No flush for writes to uninitialized */
454 } else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
455 if (usage & PIPE_TRANSFER_WRITE) {
456 /* STUB: flush reading */
457 //printf("debug: missed reading flush %d\n", resource->target);
458 } else if (usage & PIPE_TRANSFER_READ) {
459 /* STUB: flush writing */
460 //printf("debug: missed writing flush %d (%d-%d)\n", resource->target, box->x, box->x + box->width);
461 } else {
462 /* Why are you even mapping?! */
463 }
464 }
465
466 if (bo->layout != PAN_LINEAR) {
467 /* Non-linear resources need to be indirectly mapped */
468
469 if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
470 return NULL;
471
472 transfer->base.stride = box->width * bytes_per_pixel;
473 transfer->base.layer_stride = transfer->base.stride * box->height;
474
475 /* TODO: Reads */
476 transfer->map = malloc(transfer->base.layer_stride * box->depth);
477
478 return transfer->map;
479 } else {
480 transfer->base.stride = bo->slices[level].stride;
481 transfer->base.layer_stride = bo->cubemap_stride;
482
483 return bo->cpu
484 + bo->slices[level].offset
485 + transfer->base.box.z * bo->cubemap_stride
486 + transfer->base.box.y * bo->slices[level].stride
487 + transfer->base.box.x * bytes_per_pixel;
488 }
489 }
490
491 static void
492 panfrost_tile_texture(struct panfrost_screen *screen, struct panfrost_resource *rsrc, struct panfrost_gtransfer *trans)
493 {
494 struct panfrost_bo *bo = (struct panfrost_bo *)rsrc->bo;
495
496 unsigned level = trans->base.level;
497
498 panfrost_texture_swizzle(
499 trans->base.box.x,
500 trans->base.box.y,
501 trans->base.box.width,
502 trans->base.box.height,
503 util_format_get_blocksize(rsrc->base.format),
504 u_minify(rsrc->base.width0, level),
505 trans->map,
506 bo->cpu
507 + bo->slices[level].offset
508 + bo->cubemap_stride * trans->base.box.z
509 );
510 }
511
512 static void
513 panfrost_transfer_unmap(struct pipe_context *pctx,
514 struct pipe_transfer *transfer)
515 {
516 struct panfrost_context *ctx = pan_context(pctx);
517
518 /* Gallium expects writeback here, so we tile */
519
520 struct panfrost_gtransfer *trans = pan_transfer(transfer);
521 struct panfrost_resource *prsrc = (struct panfrost_resource *) transfer->resource;
522
523 if (trans->map) {
524 struct panfrost_bo *bo = prsrc->bo;
525
526 if (transfer->usage & PIPE_TRANSFER_WRITE) {
527
528 if (bo->layout == PAN_AFBC) {
529 DBG("Unimplemented: writes to AFBC\n");
530 } else if (bo->layout == PAN_TILED) {
531 struct pipe_context *gallium = (struct pipe_context *) ctx;
532 struct panfrost_screen *screen = pan_screen(gallium->screen);
533 assert(transfer->box.depth == 1);
534 panfrost_tile_texture(screen, prsrc, trans);
535 }
536 }
537
538 free(trans->map);
539 }
540
541
542 util_range_add(&prsrc->valid_buffer_range,
543 transfer->box.x,
544 transfer->box.x + transfer->box.width);
545
546 /* Derefence the resource */
547 pipe_resource_reference(&transfer->resource, NULL);
548
549 /* Transfer itself is CALLOCed at the moment */
550 free(transfer);
551 }
552
553 static void
554 panfrost_transfer_flush_region(struct pipe_context *pctx,
555 struct pipe_transfer *transfer,
556 const struct pipe_box *box)
557 {
558 struct panfrost_resource *rsc = pan_resource(transfer->resource);
559
560 if (transfer->resource->target == PIPE_BUFFER) {
561 util_range_add(&rsc->valid_buffer_range,
562 transfer->box.x + box->x,
563 transfer->box.x + box->x + box->width);
564 }
565 }
566
567 static struct pb_slab *
568 panfrost_slab_alloc(void *priv, unsigned heap, unsigned entry_size, unsigned group_index)
569 {
570 struct panfrost_screen *screen = (struct panfrost_screen *) priv;
571 struct panfrost_memory *mem = CALLOC_STRUCT(panfrost_memory);
572
573 size_t slab_size = (1 << (MAX_SLAB_ENTRY_SIZE + 1));
574
575 mem->slab.num_entries = slab_size / entry_size;
576 mem->slab.num_free = mem->slab.num_entries;
577
578 LIST_INITHEAD(&mem->slab.free);
579 for (unsigned i = 0; i < mem->slab.num_entries; ++i) {
580 /* Create a slab entry */
581 struct panfrost_memory_entry *entry = CALLOC_STRUCT(panfrost_memory_entry);
582 entry->offset = entry_size * i;
583
584 entry->base.slab = &mem->slab;
585 entry->base.group_index = group_index;
586
587 LIST_ADDTAIL(&entry->base.head, &mem->slab.free);
588 }
589
590 /* Actually allocate the memory from kernel-space. Mapped, same_va, no
591 * special flags */
592
593 screen->driver->allocate_slab(screen, mem, slab_size / 4096, true, 0, 0, 0);
594
595 return &mem->slab;
596 }
597
598 static bool
599 panfrost_slab_can_reclaim(void *priv, struct pb_slab_entry *entry)
600 {
601 struct panfrost_memory_entry *p_entry = (struct panfrost_memory_entry *) entry;
602 return p_entry->freed;
603 }
604
605 static void
606 panfrost_slab_free(void *priv, struct pb_slab *slab)
607 {
608 struct panfrost_memory *mem = (struct panfrost_memory *) slab;
609 struct panfrost_screen *screen = (struct panfrost_screen *) priv;
610
611 screen->driver->free_slab(screen, mem);
612 }
613
614 static void
615 panfrost_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
616 {
617 //DBG("TODO %s\n", __func__);
618 }
619
620 static enum pipe_format
621 panfrost_resource_get_internal_format(struct pipe_resource *prsrc)
622 {
623 return prsrc->format;
624 }
625
626 static void
627 panfrost_resource_set_stencil(struct pipe_resource *prsrc,
628 struct pipe_resource *stencil)
629 {
630 pan_resource(prsrc)->separate_stencil = pan_resource(stencil);
631 }
632
633 static struct pipe_resource *
634 panfrost_resource_get_stencil(struct pipe_resource *prsrc)
635 {
636 return &pan_resource(prsrc)->separate_stencil->base;
637 }
638
639 static const struct u_transfer_vtbl transfer_vtbl = {
640 .resource_create = panfrost_resource_create,
641 .resource_destroy = panfrost_resource_destroy,
642 .transfer_map = panfrost_transfer_map,
643 .transfer_unmap = panfrost_transfer_unmap,
644 .transfer_flush_region = panfrost_transfer_flush_region,
645 .get_internal_format = panfrost_resource_get_internal_format,
646 .set_stencil = panfrost_resource_set_stencil,
647 .get_stencil = panfrost_resource_get_stencil,
648 };
649
650 void
651 panfrost_resource_screen_init(struct panfrost_screen *pscreen)
652 {
653 //pscreen->base.resource_create_with_modifiers =
654 // panfrost_resource_create_with_modifiers;
655 pscreen->base.resource_create = u_transfer_helper_resource_create;
656 pscreen->base.resource_destroy = u_transfer_helper_resource_destroy;
657 pscreen->base.resource_from_handle = panfrost_resource_from_handle;
658 pscreen->base.resource_get_handle = panfrost_resource_get_handle;
659 pscreen->base.transfer_helper = u_transfer_helper_create(&transfer_vtbl,
660 true, false,
661 true, true);
662
663 pb_slabs_init(&pscreen->slabs,
664 MIN_SLAB_ENTRY_SIZE,
665 MAX_SLAB_ENTRY_SIZE,
666
667 3, /* Number of heaps */
668
669 pscreen,
670
671 panfrost_slab_can_reclaim,
672 panfrost_slab_alloc,
673 panfrost_slab_free);
674 }
675
676 void
677 panfrost_resource_context_init(struct pipe_context *pctx)
678 {
679 pctx->transfer_map = u_transfer_helper_transfer_map;
680 pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
681 pctx->transfer_unmap = u_transfer_helper_transfer_unmap;
682 pctx->buffer_subdata = u_default_buffer_subdata;
683 pctx->create_surface = panfrost_create_surface;
684 pctx->surface_destroy = panfrost_surface_destroy;
685 pctx->resource_copy_region = util_resource_copy_region;
686 pctx->blit = panfrost_blit;
687 pctx->flush_resource = panfrost_flush_resource;
688 pctx->invalidate_resource = panfrost_invalidate_resource;
689 pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
690 pctx->buffer_subdata = u_default_buffer_subdata;
691 pctx->texture_subdata = u_default_texture_subdata;
692 }