2019-06-07 10:32:17 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 VMware, Inc.
|
|
|
|
* Copyright (C) 2014 Broadcom
|
|
|
|
* Copyright (C) 2018-2019 Alyssa Rosenzweig
|
2019-06-25 13:30:17 -07:00
|
|
|
* Copyright (C) 2019 Collabora, Ltd.
|
2019-02-05 04:32:27 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
2019-06-07 10:32:17 -07:00
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
2019-02-05 04:32:27 +00:00
|
|
|
*
|
2019-06-07 10:32:17 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2019-02-05 04:32:27 +00:00
|
|
|
*
|
2019-06-07 10:32:17 -07:00
|
|
|
* Authors (Collabora):
|
|
|
|
* Tomeu Vizoso <tomeu.vizoso@collabora.com>
|
|
|
|
* Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
|
2019-02-05 04:32:27 +00:00
|
|
|
*
|
2019-06-07 10:32:17 -07:00
|
|
|
*/
|
2019-02-05 04:32:27 +00:00
|
|
|
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <fcntl.h>
|
2019-02-12 18:18:03 +00:00
|
|
|
#include "drm-uapi/drm_fourcc.h"
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-12-03 18:01:31 -05:00
|
|
|
#include "frontend/winsys_handle.h"
|
2019-06-27 15:05:31 -07:00
|
|
|
#include "util/format/u_format.h"
|
2019-02-05 04:32:27 +00:00
|
|
|
#include "util/u_memory.h"
|
|
|
|
#include "util/u_surface.h"
|
|
|
|
#include "util/u_transfer.h"
|
|
|
|
#include "util/u_transfer_helper.h"
|
2019-06-21 13:57:42 -07:00
|
|
|
#include "util/u_gen_mipmap.h"
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-09-14 09:58:55 +02:00
|
|
|
#include "pan_bo.h"
|
2019-02-05 04:32:27 +00:00
|
|
|
#include "pan_context.h"
|
|
|
|
#include "pan_screen.h"
|
|
|
|
#include "pan_resource.h"
|
2019-03-08 15:24:57 +01:00
|
|
|
#include "pan_util.h"
|
2019-06-18 10:43:07 -07:00
|
|
|
#include "pan_tiling.h"
|
2020-03-23 19:36:46 -04:00
|
|
|
#include "pandecode/decode.h"
|
2020-01-10 13:12:35 -05:00
|
|
|
#include "panfrost-quirks.h"
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2020-03-23 19:36:46 -04:00
|
|
|
/* Wrapper around panfrost_bo_create that handles pandecode */
|
|
|
|
|
|
|
|
struct panfrost_bo *
|
|
|
|
pan_bo_create(struct panfrost_device *dev, size_t size, uint32_t flags)
|
|
|
|
{
|
|
|
|
struct panfrost_bo *bo = panfrost_bo_create(dev, size, flags);
|
|
|
|
|
|
|
|
if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) {
|
|
|
|
if (flags & PAN_BO_INVISIBLE)
|
|
|
|
pandecode_inject_mmap(bo->gpu, NULL, bo->size, NULL);
|
|
|
|
else if (!(flags & PAN_BO_DELAY_MMAP))
|
|
|
|
pandecode_inject_mmap(bo->gpu, bo->cpu, bo->size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
|
2019-11-14 09:35:27 +01:00
|
|
|
void
|
2019-08-28 16:52:37 +02:00
|
|
|
panfrost_resource_reset_damage(struct panfrost_resource *pres)
|
|
|
|
{
|
|
|
|
/* We set the damage extent to the full resource size but keep the
|
|
|
|
* damage box empty so that the FB content is reloaded by default.
|
|
|
|
*/
|
|
|
|
memset(&pres->damage, 0, sizeof(pres->damage));
|
|
|
|
pres->damage.extent.maxx = pres->base.width0;
|
|
|
|
pres->damage.extent.maxy = pres->base.height0;
|
|
|
|
}
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
static struct pipe_resource *
|
|
|
|
panfrost_resource_from_handle(struct pipe_screen *pscreen,
|
|
|
|
const struct pipe_resource *templat,
|
|
|
|
struct winsys_handle *whandle,
|
|
|
|
unsigned usage)
|
|
|
|
{
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(pscreen);
|
2019-02-05 04:32:27 +00:00
|
|
|
struct panfrost_resource *rsc;
|
|
|
|
struct pipe_resource *prsc;
|
|
|
|
|
|
|
|
assert(whandle->type == WINSYS_HANDLE_TYPE_FD);
|
|
|
|
|
2019-06-18 14:24:57 +02:00
|
|
|
rsc = rzalloc(pscreen, struct panfrost_resource);
|
2019-02-05 04:32:27 +00:00
|
|
|
if (!rsc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
prsc = &rsc->base;
|
|
|
|
|
|
|
|
*prsc = *templat;
|
|
|
|
|
|
|
|
pipe_reference_init(&prsc->reference, 1);
|
|
|
|
prsc->screen = pscreen;
|
|
|
|
|
2020-03-23 18:44:21 -04:00
|
|
|
rsc->bo = panfrost_bo_import(dev, whandle->handle);
|
2020-01-02 16:44:18 +01:00
|
|
|
rsc->internal_format = templat->format;
|
2020-02-18 09:49:13 -05:00
|
|
|
rsc->layout = MALI_TEXTURE_LINEAR;
|
2019-07-10 10:10:31 -07:00
|
|
|
rsc->slices[0].stride = whandle->stride;
|
2019-10-17 13:49:54 +02:00
|
|
|
rsc->slices[0].offset = whandle->offset;
|
2019-07-10 10:10:31 -07:00
|
|
|
rsc->slices[0].initialized = true;
|
2019-08-28 16:52:37 +02:00
|
|
|
panfrost_resource_reset_damage(rsc);
|
2019-07-10 10:10:31 -07:00
|
|
|
|
2020-04-27 16:49:22 +02:00
|
|
|
if (dev->quirks & IS_BIFROST &&
|
|
|
|
templat->bind & PIPE_BIND_RENDER_TARGET) {
|
|
|
|
unsigned size = panfrost_compute_checksum_size(
|
|
|
|
&rsc->slices[0], templat->width0, templat->height0);
|
|
|
|
rsc->slices[0].checksum_bo = pan_bo_create(dev, size, 0);
|
|
|
|
rsc->checksummed = true;
|
|
|
|
}
|
|
|
|
|
2020-03-23 18:44:21 -04:00
|
|
|
if (dev->ro) {
|
2019-07-10 10:10:31 -07:00
|
|
|
rsc->scanout =
|
2020-03-23 18:44:21 -04:00
|
|
|
renderonly_create_gpu_import_for_resource(prsc, dev->ro, NULL);
|
2019-07-10 10:10:31 -07:00
|
|
|
/* failure is expected in some cases.. */
|
|
|
|
}
|
2019-03-08 10:27:07 +01:00
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
return prsc;
|
|
|
|
}
|
|
|
|
|
2019-07-04 11:41:41 -04:00
|
|
|
static bool
|
2019-02-05 04:32:27 +00:00
|
|
|
panfrost_resource_get_handle(struct pipe_screen *pscreen,
|
|
|
|
struct pipe_context *ctx,
|
|
|
|
struct pipe_resource *pt,
|
|
|
|
struct winsys_handle *handle,
|
|
|
|
unsigned usage)
|
|
|
|
{
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(pscreen);
|
2019-02-05 04:32:27 +00:00
|
|
|
struct panfrost_resource *rsrc = (struct panfrost_resource *) pt;
|
|
|
|
struct renderonly_scanout *scanout = rsrc->scanout;
|
|
|
|
|
|
|
|
handle->modifier = DRM_FORMAT_MOD_INVALID;
|
|
|
|
|
2019-07-10 10:10:31 -07:00
|
|
|
if (handle->type == WINSYS_HANDLE_TYPE_SHARED) {
|
2019-07-04 11:41:41 -04:00
|
|
|
return false;
|
2019-07-10 10:10:31 -07:00
|
|
|
} else if (handle->type == WINSYS_HANDLE_TYPE_KMS) {
|
|
|
|
if (renderonly_get_handle(scanout, handle))
|
2019-07-04 11:41:41 -04:00
|
|
|
return true;
|
2019-03-08 10:27:07 +01:00
|
|
|
|
2019-07-10 10:10:31 -07:00
|
|
|
handle->handle = rsrc->bo->gem_handle;
|
|
|
|
handle->stride = rsrc->slices[0].stride;
|
2019-10-17 13:49:54 +02:00
|
|
|
handle->offset = rsrc->slices[0].offset;
|
2019-07-10 10:10:31 -07:00
|
|
|
return TRUE;
|
|
|
|
} else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
|
2019-02-05 04:32:27 +00:00
|
|
|
if (scanout) {
|
|
|
|
struct drm_prime_handle args = {
|
|
|
|
.handle = scanout->handle,
|
|
|
|
.flags = DRM_CLOEXEC,
|
|
|
|
};
|
|
|
|
|
2020-03-23 18:44:21 -04:00
|
|
|
int ret = drmIoctl(dev->ro->kms_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
|
2019-02-05 04:32:27 +00:00
|
|
|
if (ret == -1)
|
2019-07-04 11:41:41 -04:00
|
|
|
return false;
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-03-18 16:07:00 +00:00
|
|
|
handle->stride = scanout->stride;
|
2019-02-05 04:32:27 +00:00
|
|
|
handle->handle = args.fd;
|
|
|
|
|
2019-07-04 11:41:41 -04:00
|
|
|
return true;
|
2019-07-02 12:53:17 +02:00
|
|
|
} else {
|
2019-09-14 10:35:47 +02:00
|
|
|
int fd = panfrost_bo_export(rsrc->bo);
|
2019-07-02 12:53:17 +02:00
|
|
|
|
|
|
|
if (fd < 0)
|
2019-07-04 11:41:41 -04:00
|
|
|
return false;
|
2019-07-02 12:53:17 +02:00
|
|
|
|
|
|
|
handle->handle = fd;
|
|
|
|
handle->stride = rsrc->slices[0].stride;
|
2019-10-17 13:49:54 +02:00
|
|
|
handle->offset = rsrc->slices[0].offset;
|
2019-07-04 11:41:41 -04:00
|
|
|
return true;
|
2019-07-10 10:10:31 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-07-04 11:41:41 -04:00
|
|
|
return false;
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
panfrost_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
|
|
|
|
{
|
2019-03-08 15:24:57 +01:00
|
|
|
//DBG("TODO %s\n", __func__);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pipe_surface *
|
|
|
|
panfrost_create_surface(struct pipe_context *pipe,
|
|
|
|
struct pipe_resource *pt,
|
|
|
|
const struct pipe_surface *surf_tmpl)
|
|
|
|
{
|
|
|
|
struct pipe_surface *ps = NULL;
|
|
|
|
|
2019-06-18 14:24:57 +02:00
|
|
|
ps = rzalloc(pipe, struct pipe_surface);
|
2019-02-05 04:32:27 +00:00
|
|
|
|
|
|
|
if (ps) {
|
|
|
|
pipe_reference_init(&ps->reference, 1);
|
|
|
|
pipe_resource_reference(&ps->texture, pt);
|
|
|
|
ps->context = pipe;
|
|
|
|
ps->format = surf_tmpl->format;
|
|
|
|
|
|
|
|
if (pt->target != PIPE_BUFFER) {
|
|
|
|
assert(surf_tmpl->u.tex.level <= pt->last_level);
|
|
|
|
ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level);
|
|
|
|
ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level);
|
|
|
|
ps->u.tex.level = surf_tmpl->u.tex.level;
|
|
|
|
ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
|
|
|
|
ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
|
|
|
|
} else {
|
|
|
|
/* setting width as number of elements should get us correct renderbuffer width */
|
|
|
|
ps->width = surf_tmpl->u.buf.last_element - surf_tmpl->u.buf.first_element + 1;
|
|
|
|
ps->height = pt->height0;
|
|
|
|
ps->u.buf.first_element = surf_tmpl->u.buf.first_element;
|
|
|
|
ps->u.buf.last_element = surf_tmpl->u.buf.last_element;
|
|
|
|
assert(ps->u.buf.first_element <= ps->u.buf.last_element);
|
|
|
|
assert(ps->u.buf.last_element < ps->width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
panfrost_surface_destroy(struct pipe_context *pipe,
|
|
|
|
struct pipe_surface *surf)
|
|
|
|
{
|
|
|
|
assert(surf->texture);
|
|
|
|
pipe_resource_reference(&surf->texture, NULL);
|
2019-06-18 14:24:57 +02:00
|
|
|
ralloc_free(surf);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 10:12:10 +02:00
|
|
|
static struct pipe_resource *
|
|
|
|
panfrost_create_scanout_res(struct pipe_screen *screen,
|
|
|
|
const struct pipe_resource *template)
|
|
|
|
{
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(screen);
|
2019-07-02 10:12:10 +02:00
|
|
|
struct pipe_resource scanout_templat = *template;
|
|
|
|
struct renderonly_scanout *scanout;
|
|
|
|
struct winsys_handle handle;
|
|
|
|
struct pipe_resource *res;
|
|
|
|
|
|
|
|
scanout = renderonly_scanout_for_resource(&scanout_templat,
|
2020-03-23 18:44:21 -04:00
|
|
|
dev->ro, &handle);
|
2019-07-02 10:12:10 +02:00
|
|
|
if (!scanout)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
assert(handle.type == WINSYS_HANDLE_TYPE_FD);
|
|
|
|
/* TODO: handle modifiers? */
|
|
|
|
res = screen->resource_from_handle(screen, template, &handle,
|
|
|
|
PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE);
|
|
|
|
close(handle.handle);
|
|
|
|
if (!res)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
struct panfrost_resource *pres = pan_resource(res);
|
|
|
|
|
|
|
|
pres->scanout = scanout;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-06-24 07:08:52 -07:00
|
|
|
/* Setup the mip tree given a particular layout, possibly with checksumming */
|
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
static void
|
2019-07-02 11:37:40 +02:00
|
|
|
panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
|
2019-02-07 06:00:11 +00:00
|
|
|
{
|
2019-07-02 11:37:40 +02:00
|
|
|
struct pipe_resource *res = &pres->base;
|
|
|
|
unsigned width = res->width0;
|
|
|
|
unsigned height = res->height0;
|
|
|
|
unsigned depth = res->depth0;
|
|
|
|
unsigned bytes_per_pixel = util_format_get_blocksize(res->format);
|
2019-02-14 04:00:19 +00:00
|
|
|
|
2019-06-14 16:11:56 -07:00
|
|
|
assert(depth > 0);
|
|
|
|
|
2019-06-06 14:36:41 -07:00
|
|
|
/* Tiled operates blockwise; linear is packed. Also, anything
|
|
|
|
* we render to has to be tile-aligned. Maybe not strictly
|
|
|
|
* necessary, but we're not *that* pressed for memory and it
|
|
|
|
* makes code a lot simpler */
|
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
bool renderable = res->bind &
|
2019-07-10 10:10:31 -07:00
|
|
|
(PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
|
2020-02-18 09:49:13 -05:00
|
|
|
bool afbc = pres->layout == MALI_TEXTURE_AFBC;
|
|
|
|
bool tiled = pres->layout == MALI_TEXTURE_TILED;
|
2019-06-06 14:36:41 -07:00
|
|
|
bool should_align = renderable || tiled;
|
|
|
|
|
2019-06-14 16:11:56 -07:00
|
|
|
/* We don't know how to specify a 2D stride for 3D textures */
|
|
|
|
|
2019-06-20 08:19:06 -07:00
|
|
|
bool can_align_stride =
|
2019-07-02 11:37:40 +02:00
|
|
|
res->target != PIPE_TEXTURE_3D;
|
2019-06-14 16:11:56 -07:00
|
|
|
|
2019-06-20 08:19:06 -07:00
|
|
|
should_align &= can_align_stride;
|
2019-06-14 16:11:56 -07:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
unsigned offset = 0;
|
2019-06-14 16:11:56 -07:00
|
|
|
unsigned size_2d = 0;
|
2019-02-14 04:00:19 +00:00
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
for (unsigned l = 0; l <= res->last_level; ++l) {
|
|
|
|
struct panfrost_slice *slice = &pres->slices[l];
|
2019-02-07 06:00:11 +00:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
unsigned effective_width = width;
|
|
|
|
unsigned effective_height = height;
|
2019-06-14 16:11:56 -07:00
|
|
|
unsigned effective_depth = depth;
|
2019-02-07 06:00:11 +00:00
|
|
|
|
2019-06-06 14:36:41 -07:00
|
|
|
if (should_align) {
|
2019-07-05 08:25:56 -07:00
|
|
|
effective_width = ALIGN_POT(effective_width, 16);
|
|
|
|
effective_height = ALIGN_POT(effective_height, 16);
|
2019-06-14 16:11:56 -07:00
|
|
|
|
|
|
|
/* We don't need to align depth */
|
2019-03-21 02:54:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 15:34:50 -07:00
|
|
|
/* Align levels to cache-line as a performance improvement for
|
|
|
|
* linear/tiled and as a requirement for AFBC */
|
|
|
|
|
|
|
|
offset = ALIGN_POT(offset, 64);
|
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
slice->offset = offset;
|
2019-06-07 08:58:16 -07:00
|
|
|
|
|
|
|
/* Compute the would-be stride */
|
|
|
|
unsigned stride = bytes_per_pixel * effective_width;
|
|
|
|
|
2020-01-11 20:00:38 +13:00
|
|
|
if (util_format_is_compressed(res->format))
|
|
|
|
stride /= 4;
|
|
|
|
|
2019-06-07 08:58:16 -07:00
|
|
|
/* ..but cache-line align it for performance */
|
2020-02-18 09:49:13 -05:00
|
|
|
if (can_align_stride && pres->layout == MALI_TEXTURE_LINEAR)
|
2019-07-05 08:25:56 -07:00
|
|
|
stride = ALIGN_POT(stride, 64);
|
2019-06-14 16:11:56 -07:00
|
|
|
|
2019-06-07 08:58:16 -07:00
|
|
|
slice->stride = stride;
|
2019-03-21 02:54:38 +00:00
|
|
|
|
2019-06-14 16:11:56 -07:00
|
|
|
unsigned slice_one_size = slice->stride * effective_height;
|
|
|
|
unsigned slice_full_size = slice_one_size * effective_depth;
|
|
|
|
|
2020-01-02 11:27:00 +01:00
|
|
|
slice->size0 = slice_one_size;
|
|
|
|
|
2019-06-14 16:11:56 -07:00
|
|
|
/* Report 2D size for 3D texturing */
|
|
|
|
|
|
|
|
if (l == 0)
|
|
|
|
size_2d = slice_one_size;
|
|
|
|
|
2019-06-21 14:54:44 -07:00
|
|
|
/* Compute AFBC sizes if necessary */
|
|
|
|
if (afbc) {
|
|
|
|
slice->header_size =
|
|
|
|
panfrost_afbc_header_size(width, height);
|
|
|
|
|
|
|
|
offset += slice->header_size;
|
|
|
|
}
|
|
|
|
|
2019-06-14 16:11:56 -07:00
|
|
|
offset += slice_full_size;
|
2019-03-21 02:54:38 +00:00
|
|
|
|
2019-06-24 07:08:52 -07:00
|
|
|
/* Add a checksum region if necessary */
|
2019-07-02 11:37:40 +02:00
|
|
|
if (pres->checksummed) {
|
2019-06-24 07:08:52 -07:00
|
|
|
slice->checksum_offset = offset;
|
|
|
|
|
2020-02-18 12:07:47 -05:00
|
|
|
unsigned size = panfrost_compute_checksum_size(
|
2019-07-10 10:10:31 -07:00
|
|
|
slice, width, height);
|
2019-06-24 07:08:52 -07:00
|
|
|
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
width = u_minify(width, 1);
|
|
|
|
height = u_minify(height, 1);
|
2019-06-14 16:11:56 -07:00
|
|
|
depth = u_minify(depth, 1);
|
2019-03-21 02:54:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
assert(res->array_size);
|
2019-03-27 04:37:26 +00:00
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
if (res->target != PIPE_TEXTURE_3D) {
|
2019-06-14 16:11:56 -07:00
|
|
|
/* Arrays and cubemaps have the entire miptree duplicated */
|
|
|
|
|
2019-07-05 08:25:56 -07:00
|
|
|
pres->cubemap_stride = ALIGN_POT(offset, 64);
|
|
|
|
*bo_size = ALIGN_POT(pres->cubemap_stride * res->array_size, 4096);
|
2019-06-14 16:11:56 -07:00
|
|
|
} else {
|
|
|
|
/* 3D strides across the 2D layers */
|
2019-07-02 11:37:40 +02:00
|
|
|
assert(res->array_size == 1);
|
2019-06-14 16:11:56 -07:00
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
pres->cubemap_stride = size_2d;
|
2019-07-05 08:25:56 -07:00
|
|
|
*bo_size = ALIGN_POT(offset, 4096);
|
2019-06-14 16:11:56 -07:00
|
|
|
}
|
2019-03-21 02:54:38 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
static void
|
2020-03-23 18:44:21 -04:00
|
|
|
panfrost_resource_create_bo(struct panfrost_device *dev, struct panfrost_resource *pres)
|
2019-03-21 02:54:38 +00:00
|
|
|
{
|
2019-07-10 10:10:31 -07:00
|
|
|
struct pipe_resource *res = &pres->base;
|
2019-03-13 00:53:34 +00:00
|
|
|
|
2019-03-07 03:52:20 +00:00
|
|
|
/* Based on the usage, figure out what storing will be used. There are
|
|
|
|
* various tradeoffs:
|
|
|
|
*
|
|
|
|
* Linear: the basic format, bad for memory bandwidth, bad for cache
|
|
|
|
* use. Zero-copy, though. Renderable.
|
|
|
|
*
|
|
|
|
* Tiled: Not compressed, but cache-optimized. Expensive to write into
|
|
|
|
* (due to software tiling), but cheap to sample from. Ideal for most
|
2019-07-10 10:10:31 -07:00
|
|
|
* textures.
|
2019-03-07 03:52:20 +00:00
|
|
|
*
|
|
|
|
* AFBC: Compressed and renderable (so always desirable for non-scanout
|
|
|
|
* rendertargets). Cheap to sample from. The format is black box, so we
|
|
|
|
* can't read/write from software.
|
2020-01-04 13:00:50 -05:00
|
|
|
*
|
|
|
|
* Tiling textures is almost always faster, unless we only use it once.
|
|
|
|
* Only a few types of resources can be tiled, ensure the bind is only
|
|
|
|
* (a combination of) one of the following */
|
2019-06-14 16:11:56 -07:00
|
|
|
|
2020-01-04 13:00:50 -05:00
|
|
|
const unsigned valid_binding =
|
2020-01-10 13:12:35 -05:00
|
|
|
PIPE_BIND_DEPTH_STENCIL |
|
2020-01-04 13:00:50 -05:00
|
|
|
PIPE_BIND_RENDER_TARGET |
|
|
|
|
PIPE_BIND_BLENDABLE |
|
|
|
|
PIPE_BIND_SAMPLER_VIEW |
|
|
|
|
PIPE_BIND_DISPLAY_TARGET;
|
2019-03-07 03:52:20 +00:00
|
|
|
|
2020-01-15 13:15:01 -05:00
|
|
|
unsigned bpp = util_format_get_blocksizebits(res->format);
|
2020-01-04 13:00:50 -05:00
|
|
|
bool is_2d = (res->target == PIPE_TEXTURE_2D);
|
2020-01-15 13:15:01 -05:00
|
|
|
bool is_sane_bpp = bpp == 8 || bpp == 16 || bpp == 32 || bpp == 64 || bpp == 128;
|
2020-01-04 13:00:50 -05:00
|
|
|
bool should_tile = (res->usage != PIPE_USAGE_STREAM);
|
2020-03-23 18:44:21 -04:00
|
|
|
bool must_tile = (res->bind & PIPE_BIND_DEPTH_STENCIL) && (dev->quirks & MIDGARD_SFBD);
|
2020-01-15 13:15:01 -05:00
|
|
|
bool can_tile = is_2d && is_sane_bpp && ((res->bind & ~valid_binding) == 0);
|
2019-06-21 14:41:14 -07:00
|
|
|
|
2019-06-24 07:08:52 -07:00
|
|
|
/* FBOs we would like to checksum, if at all possible */
|
2020-01-04 13:00:50 -05:00
|
|
|
bool can_checksum = !(res->bind & ~valid_binding);
|
2019-07-02 11:37:40 +02:00
|
|
|
bool should_checksum = res->bind & PIPE_BIND_RENDER_TARGET;
|
2019-06-24 07:08:52 -07:00
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
pres->checksummed = can_checksum && should_checksum;
|
2019-06-24 07:08:52 -07:00
|
|
|
|
2019-03-07 03:52:20 +00:00
|
|
|
/* Set the layout appropriately */
|
2020-01-10 13:12:35 -05:00
|
|
|
assert(!(must_tile && !can_tile)); /* must_tile => can_tile */
|
2020-02-18 09:49:13 -05:00
|
|
|
pres->layout = ((can_tile && should_tile) || must_tile) ? MALI_TEXTURE_TILED : MALI_TEXTURE_LINEAR;
|
2019-07-02 11:37:40 +02:00
|
|
|
|
|
|
|
size_t bo_size;
|
2019-02-07 06:00:11 +00:00
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
panfrost_setup_slices(pres, &bo_size);
|
2019-07-12 15:50:58 -07:00
|
|
|
|
|
|
|
/* We create a BO immediately but don't bother mapping, since we don't
|
|
|
|
* care to map e.g. FBOs which the CPU probably won't touch */
|
2020-03-23 19:36:46 -04:00
|
|
|
pres->bo = pan_bo_create(dev, bo_size, PAN_BO_DELAY_MMAP);
|
2019-02-07 06:00:11 +00:00
|
|
|
}
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-08-12 12:07:08 +02:00
|
|
|
void
|
|
|
|
panfrost_resource_set_damage_region(struct pipe_screen *screen,
|
|
|
|
struct pipe_resource *res,
|
|
|
|
unsigned int nrects,
|
|
|
|
const struct pipe_box *rects)
|
|
|
|
{
|
|
|
|
struct panfrost_resource *pres = pan_resource(res);
|
|
|
|
struct pipe_box *damage_rect = &pres->damage.biggest_rect;
|
|
|
|
struct pipe_scissor_state *damage_extent = &pres->damage.extent;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!nrects) {
|
|
|
|
panfrost_resource_reset_damage(pres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We keep track of 2 different things here:
|
|
|
|
* 1 the damage extent: the quad including all damage regions. Will be
|
|
|
|
* used restrict the rendering area
|
|
|
|
* 2 the biggest damage rectangle: when there are more than one damage
|
|
|
|
* rect we keep the biggest one and will generate 4 wallpaper quads
|
|
|
|
* out of it (see panfrost_draw_wallpaper() for more details). We
|
|
|
|
* might want to do something smarter at some point.
|
|
|
|
*
|
|
|
|
* _________________________________
|
|
|
|
* | |
|
|
|
|
* | _________________________ |
|
|
|
|
* | | rect1| _________| |
|
|
|
|
* | |______|_____ | rect 3: | |
|
|
|
|
* | | | rect2 | | biggest | |
|
|
|
|
* | | |_______| | rect | |
|
|
|
|
* | |_______________|_________| |
|
|
|
|
* | damage extent |
|
|
|
|
* |_______________________________|
|
|
|
|
* resource
|
|
|
|
*/
|
|
|
|
memset(&pres->damage, 0, sizeof(pres->damage));
|
|
|
|
damage_extent->minx = 0xffff;
|
|
|
|
damage_extent->miny = 0xffff;
|
|
|
|
for (i = 0; i < nrects; i++) {
|
|
|
|
int x = rects[i].x, w = rects[i].width, h = rects[i].height;
|
|
|
|
int y = res->height0 - (rects[i].y + h);
|
|
|
|
|
|
|
|
/* Clamp x,y,w,h to prevent negative values. */
|
|
|
|
if (x < 0) {
|
|
|
|
h += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
w += y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
w = MAX2(w, 0);
|
|
|
|
h = MAX2(h, 0);
|
|
|
|
|
|
|
|
if (damage_rect->width * damage_rect->height < w * h)
|
|
|
|
u_box_2d(x, y, w, h, damage_rect);
|
|
|
|
|
|
|
|
damage_extent->minx = MIN2(damage_extent->minx, x);
|
|
|
|
damage_extent->miny = MIN2(damage_extent->miny, y);
|
|
|
|
damage_extent->maxx = MAX2(damage_extent->maxx,
|
|
|
|
MIN2(x + w, res->width0));
|
|
|
|
damage_extent->maxy = MAX2(damage_extent->maxy,
|
|
|
|
MIN2(y + h, res->height0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
static struct pipe_resource *
|
|
|
|
panfrost_resource_create(struct pipe_screen *screen,
|
|
|
|
const struct pipe_resource *template)
|
|
|
|
{
|
|
|
|
/* Make sure we're familiar */
|
|
|
|
switch (template->target) {
|
2019-07-10 10:10:31 -07:00
|
|
|
case PIPE_BUFFER:
|
|
|
|
case PIPE_TEXTURE_1D:
|
|
|
|
case PIPE_TEXTURE_2D:
|
|
|
|
case PIPE_TEXTURE_3D:
|
|
|
|
case PIPE_TEXTURE_CUBE:
|
|
|
|
case PIPE_TEXTURE_RECT:
|
|
|
|
case PIPE_TEXTURE_2D_ARRAY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBG("Unknown texture target %d\n", template->target);
|
|
|
|
assert(0);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 10:12:10 +02:00
|
|
|
if (template->bind &
|
|
|
|
(PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED))
|
|
|
|
return panfrost_create_scanout_res(screen, template);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
|
2019-07-02 10:12:10 +02:00
|
|
|
struct panfrost_resource *so = rzalloc(screen, struct panfrost_resource);
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(screen);
|
2019-07-02 10:12:10 +02:00
|
|
|
|
|
|
|
so->base = *template;
|
|
|
|
so->base.screen = screen;
|
2020-01-02 16:44:18 +01:00
|
|
|
so->internal_format = template->format;
|
2019-07-02 10:12:10 +02:00
|
|
|
|
|
|
|
pipe_reference_init(&so->base.reference, 1);
|
|
|
|
|
|
|
|
util_range_init(&so->valid_buffer_range);
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2020-03-23 18:44:21 -04:00
|
|
|
panfrost_resource_create_bo(dev, so);
|
2019-08-12 12:07:08 +02:00
|
|
|
panfrost_resource_reset_damage(so);
|
|
|
|
|
2020-02-19 10:32:20 -05:00
|
|
|
if (template->bind & PIPE_BIND_INDEX_BUFFER)
|
|
|
|
so->index_cache = rzalloc(so, struct panfrost_minmax_cache);
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
return (struct pipe_resource *)so;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
panfrost_resource_destroy(struct pipe_screen *screen,
|
|
|
|
struct pipe_resource *pt)
|
|
|
|
{
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(screen);
|
2019-02-05 04:32:27 +00:00
|
|
|
struct panfrost_resource *rsrc = (struct panfrost_resource *) pt;
|
|
|
|
|
2019-07-10 10:10:31 -07:00
|
|
|
if (rsrc->scanout)
|
2020-03-23 18:44:21 -04:00
|
|
|
renderonly_scanout_destroy(rsrc->scanout, dev->ro);
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-07-10 10:10:31 -07:00
|
|
|
if (rsrc->bo)
|
2019-09-14 10:35:47 +02:00
|
|
|
panfrost_bo_unreference(rsrc->bo);
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2020-04-27 16:49:22 +02:00
|
|
|
if (rsrc->slices[0].checksum_bo)
|
|
|
|
panfrost_bo_unreference(rsrc->slices[0].checksum_bo);
|
|
|
|
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
util_range_destroy(&rsrc->valid_buffer_range);
|
2019-07-10 10:10:31 -07:00
|
|
|
ralloc_free(rsrc);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 10:32:20 -05:00
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
static void *
|
|
|
|
panfrost_transfer_map(struct pipe_context *pctx,
|
|
|
|
struct pipe_resource *resource,
|
|
|
|
unsigned level,
|
|
|
|
unsigned usage, /* a combination of PIPE_TRANSFER_x */
|
|
|
|
const struct pipe_box *box,
|
|
|
|
struct pipe_transfer **out_transfer)
|
|
|
|
{
|
2020-02-18 08:30:10 -05:00
|
|
|
struct panfrost_context *ctx = pan_context(pctx);
|
2019-02-05 04:32:27 +00:00
|
|
|
int bytes_per_pixel = util_format_get_blocksize(resource->format);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
struct panfrost_resource *rsrc = pan_resource(resource);
|
|
|
|
struct panfrost_bo *bo = rsrc->bo;
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-06-18 14:24:57 +02:00
|
|
|
struct panfrost_gtransfer *transfer = rzalloc(pctx, struct panfrost_gtransfer);
|
2019-03-21 02:54:38 +00:00
|
|
|
transfer->base.level = level;
|
|
|
|
transfer->base.usage = usage;
|
|
|
|
transfer->base.box = *box;
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
pipe_resource_reference(&transfer->base.resource, resource);
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
*out_transfer = &transfer->base;
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-07-12 15:50:58 -07:00
|
|
|
/* If we haven't already mmaped, now's the time */
|
2019-09-14 10:35:47 +02:00
|
|
|
panfrost_bo_mmap(bo);
|
2019-07-12 15:50:58 -07:00
|
|
|
|
2020-03-23 19:36:46 -04:00
|
|
|
if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC))
|
|
|
|
pandecode_inject_mmap(bo->gpu, bo->cpu, bo->size, NULL);
|
|
|
|
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
|
2019-10-10 15:12:30 +02:00
|
|
|
/* If the BO is used by one of the pending batches or if it's
|
|
|
|
* not ready yet (still accessed by one of the already flushed
|
|
|
|
* batches), we try to allocate a new one to avoid waiting.
|
|
|
|
*/
|
|
|
|
if (panfrost_pending_batches_access_bo(ctx, bo) ||
|
|
|
|
!panfrost_bo_wait(bo, 0, PAN_BO_ACCESS_RW)) {
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev = pan_device(pctx->screen);
|
2019-10-10 15:12:30 +02:00
|
|
|
/* We want the BO to be MMAPed. */
|
|
|
|
uint32_t flags = bo->flags & ~PAN_BO_DELAY_MMAP;
|
|
|
|
struct panfrost_bo *newbo = NULL;
|
|
|
|
|
|
|
|
/* When the BO has been imported/exported, we can't
|
|
|
|
* replace it by another one, otherwise the
|
|
|
|
* importer/exporter wouldn't see the change we're
|
|
|
|
* doing to it.
|
|
|
|
*/
|
|
|
|
if (!(bo->flags & (PAN_BO_IMPORTED | PAN_BO_EXPORTED)))
|
2020-03-23 19:36:46 -04:00
|
|
|
newbo = pan_bo_create(dev, bo->size,
|
2019-10-10 15:12:30 +02:00
|
|
|
flags);
|
|
|
|
|
|
|
|
if (newbo) {
|
|
|
|
panfrost_bo_unreference(bo);
|
|
|
|
rsrc->bo = newbo;
|
|
|
|
bo = newbo;
|
|
|
|
} else {
|
|
|
|
uint32_t access = PAN_BO_ACCESS_RW;
|
|
|
|
|
|
|
|
/* Allocation failed or was impossible, let's
|
|
|
|
* fall back on a flush+wait.
|
|
|
|
*/
|
|
|
|
panfrost_flush_batches_accessing_bo(ctx, bo,
|
|
|
|
access);
|
|
|
|
panfrost_bo_wait(bo, INT64_MAX, access);
|
|
|
|
}
|
|
|
|
}
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
} else if ((usage & PIPE_TRANSFER_WRITE)
|
2019-07-10 10:10:31 -07:00
|
|
|
&& resource->target == PIPE_BUFFER
|
|
|
|
&& !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width)) {
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
/* No flush for writes to uninitialized */
|
|
|
|
} else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
|
|
|
|
if (usage & PIPE_TRANSFER_WRITE) {
|
2019-09-15 20:35:52 +02:00
|
|
|
panfrost_flush_batches_accessing_bo(ctx, bo, PAN_BO_ACCESS_RW);
|
|
|
|
panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_RW);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
} else if (usage & PIPE_TRANSFER_READ) {
|
2019-09-15 20:35:52 +02:00
|
|
|
panfrost_flush_batches_accessing_bo(ctx, bo, PAN_BO_ACCESS_WRITE);
|
|
|
|
panfrost_bo_wait(bo, INT64_MAX, PAN_BO_ACCESS_WRITE);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 09:49:13 -05:00
|
|
|
if (rsrc->layout != MALI_TEXTURE_LINEAR) {
|
2019-03-21 02:54:38 +00:00
|
|
|
/* Non-linear resources need to be indirectly mapped */
|
2019-02-05 04:32:27 +00:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
|
|
|
|
return NULL;
|
|
|
|
|
2019-04-03 03:52:36 +00:00
|
|
|
transfer->base.stride = box->width * bytes_per_pixel;
|
|
|
|
transfer->base.layer_stride = transfer->base.stride * box->height;
|
2019-06-18 14:24:57 +02:00
|
|
|
transfer->map = rzalloc_size(transfer, transfer->base.layer_stride * box->depth);
|
2019-06-18 10:48:43 -07:00
|
|
|
assert(box->depth == 1);
|
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
if ((usage & PIPE_TRANSFER_READ) && rsrc->slices[level].initialized) {
|
2020-02-18 09:49:13 -05:00
|
|
|
if (rsrc->layout == MALI_TEXTURE_AFBC) {
|
2019-06-18 10:48:43 -07:00
|
|
|
DBG("Unimplemented: reads from AFBC");
|
2020-02-18 09:49:13 -05:00
|
|
|
} else if (rsrc->layout == MALI_TEXTURE_TILED) {
|
2019-06-18 10:48:43 -07:00
|
|
|
panfrost_load_tiled_image(
|
2019-07-10 10:10:31 -07:00
|
|
|
transfer->map,
|
|
|
|
bo->cpu + rsrc->slices[level].offset,
|
2020-01-14 12:52:02 -05:00
|
|
|
box->x, box->y, box->width, box->height,
|
2019-07-10 10:10:31 -07:00
|
|
|
transfer->base.stride,
|
|
|
|
rsrc->slices[level].stride,
|
2020-01-15 13:15:01 -05:00
|
|
|
resource->format);
|
2019-06-18 10:48:43 -07:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 02:54:38 +00:00
|
|
|
|
|
|
|
return transfer->map;
|
|
|
|
} else {
|
2020-02-19 10:32:20 -05:00
|
|
|
/* Direct, persistent writes create holes in time for
|
|
|
|
* caching... I don't know if this is actually possible but we
|
|
|
|
* should still get it right */
|
|
|
|
|
|
|
|
unsigned dpw = PIPE_TRANSFER_MAP_DIRECTLY | PIPE_TRANSFER_WRITE | PIPE_TRANSFER_PERSISTENT;
|
|
|
|
|
|
|
|
if ((usage & dpw) == dpw && rsrc->index_cache)
|
|
|
|
return NULL;
|
|
|
|
|
2019-07-02 11:37:40 +02:00
|
|
|
transfer->base.stride = rsrc->slices[level].stride;
|
2020-02-18 14:20:16 -05:00
|
|
|
transfer->base.layer_stride = panfrost_get_layer_stride(
|
|
|
|
rsrc->slices, rsrc->base.target == PIPE_TEXTURE_3D,
|
|
|
|
rsrc->cubemap_stride, level);
|
2019-04-03 03:52:36 +00:00
|
|
|
|
2019-06-20 14:05:33 -07:00
|
|
|
/* By mapping direct-write, we're implicitly already
|
|
|
|
* initialized (maybe), so be conservative */
|
|
|
|
|
2020-02-19 10:32:20 -05:00
|
|
|
if ((usage & PIPE_TRANSFER_WRITE) && (usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
|
2019-07-02 11:37:40 +02:00
|
|
|
rsrc->slices[level].initialized = true;
|
2020-03-03 21:31:51 -08:00
|
|
|
panfrost_minmax_cache_invalidate(rsrc->index_cache, &transfer->base);
|
2020-02-19 10:32:20 -05:00
|
|
|
}
|
2019-06-20 14:05:33 -07:00
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
return bo->cpu
|
2019-07-10 10:10:31 -07:00
|
|
|
+ rsrc->slices[level].offset
|
2020-01-02 11:27:00 +01:00
|
|
|
+ transfer->base.box.z * transfer->base.layer_stride
|
2019-07-10 10:10:31 -07:00
|
|
|
+ transfer->base.box.y * rsrc->slices[level].stride
|
|
|
|
+ transfer->base.box.x * bytes_per_pixel;
|
2019-03-21 02:54:38 +00:00
|
|
|
}
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 06:00:11 +00:00
|
|
|
static void
|
2019-04-03 02:15:18 +00:00
|
|
|
panfrost_transfer_unmap(struct pipe_context *pctx,
|
|
|
|
struct pipe_transfer *transfer)
|
2019-02-07 06:00:11 +00:00
|
|
|
{
|
2019-04-03 02:15:18 +00:00
|
|
|
/* Gallium expects writeback here, so we tile */
|
|
|
|
|
2019-03-21 02:54:38 +00:00
|
|
|
struct panfrost_gtransfer *trans = pan_transfer(transfer);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
struct panfrost_resource *prsrc = (struct panfrost_resource *) transfer->resource;
|
2019-02-07 06:00:11 +00:00
|
|
|
|
2019-07-19 16:11:27 -07:00
|
|
|
/* Mark whatever we wrote as written */
|
|
|
|
if (transfer->usage & PIPE_TRANSFER_WRITE)
|
|
|
|
prsrc->slices[transfer->level].initialized = true;
|
|
|
|
|
2019-04-03 02:15:18 +00:00
|
|
|
if (trans->map) {
|
|
|
|
struct panfrost_bo *bo = prsrc->bo;
|
|
|
|
|
|
|
|
if (transfer->usage & PIPE_TRANSFER_WRITE) {
|
2020-02-18 09:49:13 -05:00
|
|
|
if (prsrc->layout == MALI_TEXTURE_AFBC) {
|
2019-04-03 02:15:18 +00:00
|
|
|
DBG("Unimplemented: writes to AFBC\n");
|
2020-02-18 09:49:13 -05:00
|
|
|
} else if (prsrc->layout == MALI_TEXTURE_TILED) {
|
2019-04-03 02:15:18 +00:00
|
|
|
assert(transfer->box.depth == 1);
|
2019-06-18 10:43:07 -07:00
|
|
|
|
|
|
|
panfrost_store_tiled_image(
|
2019-07-19 16:11:27 -07:00
|
|
|
bo->cpu + prsrc->slices[transfer->level].offset,
|
2019-07-10 10:10:31 -07:00
|
|
|
trans->map,
|
2020-01-14 12:52:02 -05:00
|
|
|
transfer->box.x, transfer->box.y,
|
|
|
|
transfer->box.width, transfer->box.height,
|
2019-07-19 16:11:27 -07:00
|
|
|
prsrc->slices[transfer->level].stride,
|
2019-07-10 10:10:31 -07:00
|
|
|
transfer->stride,
|
2020-01-15 13:15:01 -05:00
|
|
|
prsrc->base.format);
|
2019-04-03 02:15:18 +00:00
|
|
|
}
|
2019-02-07 06:00:11 +00:00
|
|
|
}
|
2019-04-03 02:15:18 +00:00
|
|
|
}
|
2019-02-05 04:32:27 +00:00
|
|
|
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
|
2019-09-25 21:38:40 -04:00
|
|
|
util_range_add(&prsrc->base, &prsrc->valid_buffer_range,
|
2019-07-10 10:10:31 -07:00
|
|
|
transfer->box.x,
|
|
|
|
transfer->box.x + transfer->box.width);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
|
2020-03-03 21:31:51 -08:00
|
|
|
panfrost_minmax_cache_invalidate(prsrc->index_cache, transfer);
|
2020-02-19 10:32:20 -05:00
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
/* Derefence the resource */
|
|
|
|
pipe_resource_reference(&transfer->resource, NULL);
|
|
|
|
|
2019-06-18 14:24:57 +02:00
|
|
|
/* Transfer itself is RALLOCed at the moment */
|
|
|
|
ralloc_free(transfer);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
static void
|
|
|
|
panfrost_transfer_flush_region(struct pipe_context *pctx,
|
2019-07-10 10:10:31 -07:00
|
|
|
struct pipe_transfer *transfer,
|
|
|
|
const struct pipe_box *box)
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
{
|
2019-07-10 10:10:31 -07:00
|
|
|
struct panfrost_resource *rsc = pan_resource(transfer->resource);
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
|
2019-07-10 10:10:31 -07:00
|
|
|
if (transfer->resource->target == PIPE_BUFFER) {
|
2019-09-25 21:38:40 -04:00
|
|
|
util_range_add(&rsc->base, &rsc->valid_buffer_range,
|
2019-07-10 10:10:31 -07:00
|
|
|
transfer->box.x + box->x,
|
|
|
|
transfer->box.x + box->x + box->width);
|
2019-07-19 16:11:27 -07:00
|
|
|
} else {
|
|
|
|
unsigned level = transfer->level;
|
|
|
|
rsc->slices[level].initialized = true;
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
static void
|
|
|
|
panfrost_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
|
|
|
|
{
|
2019-03-08 15:24:57 +01:00
|
|
|
//DBG("TODO %s\n", __func__);
|
2019-02-05 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 23:59:58 +00:00
|
|
|
static enum pipe_format
|
2020-01-02 16:44:18 +01:00
|
|
|
panfrost_resource_get_internal_format(struct pipe_resource *rsrc) {
|
|
|
|
struct panfrost_resource *prsrc = (struct panfrost_resource *) rsrc;
|
|
|
|
return prsrc->internal_format;
|
2019-02-15 23:59:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 11:41:41 -04:00
|
|
|
static bool
|
2019-06-21 13:57:42 -07:00
|
|
|
panfrost_generate_mipmap(
|
2019-07-10 10:10:31 -07:00
|
|
|
struct pipe_context *pctx,
|
|
|
|
struct pipe_resource *prsrc,
|
|
|
|
enum pipe_format format,
|
|
|
|
unsigned base_level,
|
|
|
|
unsigned last_level,
|
|
|
|
unsigned first_layer,
|
|
|
|
unsigned last_layer)
|
2019-06-21 13:57:42 -07:00
|
|
|
{
|
|
|
|
struct panfrost_context *ctx = pan_context(pctx);
|
|
|
|
struct panfrost_resource *rsrc = pan_resource(prsrc);
|
|
|
|
|
|
|
|
/* Generating a mipmap invalidates the written levels, so make that
|
|
|
|
* explicit so we don't try to wallpaper them back and end up with
|
|
|
|
* u_blitter recursion */
|
|
|
|
|
|
|
|
assert(rsrc->bo);
|
|
|
|
for (unsigned l = base_level + 1; l <= last_level; ++l)
|
2019-07-02 11:37:40 +02:00
|
|
|
rsrc->slices[l].initialized = false;
|
2019-06-21 13:57:42 -07:00
|
|
|
|
|
|
|
/* Beyond that, we just delegate the hard stuff. We're careful to
|
|
|
|
* include flushes on both ends to make sure the data is really valid.
|
|
|
|
* We could be doing a lot better perf-wise, especially once we have
|
|
|
|
* reorder-type optimizations in place. But for now prioritize
|
|
|
|
* correctness. */
|
|
|
|
|
2019-09-15 20:35:52 +02:00
|
|
|
panfrost_flush_batches_accessing_bo(ctx, rsrc->bo, PAN_BO_ACCESS_RW);
|
|
|
|
panfrost_bo_wait(rsrc->bo, INT64_MAX, PAN_BO_ACCESS_RW);
|
2019-06-21 13:57:42 -07:00
|
|
|
|
|
|
|
/* We've flushed the original buffer if needed, now trigger a blit */
|
|
|
|
|
|
|
|
bool blit_res = util_gen_mipmap(
|
2019-07-10 10:10:31 -07:00
|
|
|
pctx, prsrc, format,
|
|
|
|
base_level, last_level,
|
|
|
|
first_layer, last_layer,
|
|
|
|
PIPE_TEX_FILTER_LINEAR);
|
2019-06-21 13:57:42 -07:00
|
|
|
|
|
|
|
/* If the blit was successful, flush once more. If it wasn't, well, let
|
2019-12-03 20:38:14 -05:00
|
|
|
* the gallium frontend deal with it. */
|
2019-06-21 13:57:42 -07:00
|
|
|
|
2019-09-15 20:35:52 +02:00
|
|
|
if (blit_res) {
|
|
|
|
panfrost_flush_batches_accessing_bo(ctx, rsrc->bo, PAN_BO_ACCESS_WRITE);
|
|
|
|
panfrost_bo_wait(rsrc->bo, INT64_MAX, PAN_BO_ACCESS_WRITE);
|
|
|
|
}
|
2019-06-21 13:57:42 -07:00
|
|
|
|
|
|
|
return blit_res;
|
|
|
|
}
|
|
|
|
|
2019-06-21 17:23:49 -07:00
|
|
|
/* Computes the address to a texture at a particular slice */
|
|
|
|
|
|
|
|
mali_ptr
|
|
|
|
panfrost_get_texture_address(
|
2019-07-10 10:10:31 -07:00
|
|
|
struct panfrost_resource *rsrc,
|
|
|
|
unsigned level, unsigned face)
|
2019-06-21 17:23:49 -07:00
|
|
|
{
|
2020-02-18 14:20:16 -05:00
|
|
|
bool is_3d = rsrc->base.target == PIPE_TEXTURE_3D;
|
|
|
|
return rsrc->bo->gpu + panfrost_texture_offset(rsrc->slices, is_3d, rsrc->cubemap_stride, level, face);
|
2019-06-21 17:23:49 -07:00
|
|
|
}
|
|
|
|
|
2019-07-15 14:15:24 -07:00
|
|
|
/* Given a resource that has already been allocated, hint that it should use a
|
|
|
|
* given layout. These are suggestions, not commands; it is perfectly legal to
|
|
|
|
* stub out this function, but there will be performance implications. */
|
|
|
|
|
|
|
|
void
|
|
|
|
panfrost_resource_hint_layout(
|
2020-03-23 18:44:21 -04:00
|
|
|
struct panfrost_device *dev,
|
2019-07-15 14:15:24 -07:00
|
|
|
struct panfrost_resource *rsrc,
|
2020-02-18 09:49:13 -05:00
|
|
|
enum mali_texture_layout layout,
|
2019-07-15 14:15:24 -07:00
|
|
|
signed weight)
|
|
|
|
{
|
|
|
|
/* Nothing to do, although a sophisticated implementation might store
|
|
|
|
* the hint */
|
|
|
|
|
|
|
|
if (rsrc->layout == layout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We don't use the weight yet, but we should check that it's positive
|
|
|
|
* (semantically meaning that we should choose the given `layout`) */
|
|
|
|
|
|
|
|
if (weight <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if the preferred layout is legal for this buffer */
|
|
|
|
|
2020-02-18 09:49:13 -05:00
|
|
|
if (layout == MALI_TEXTURE_AFBC) {
|
2019-07-15 14:15:24 -07:00
|
|
|
bool can_afbc = panfrost_format_supports_afbc(rsrc->base.format);
|
|
|
|
bool is_scanout = rsrc->base.bind &
|
|
|
|
(PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
|
|
|
|
|
|
|
|
if (!can_afbc || is_scanout)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple heuristic so far: if the resource is uninitialized, switch to
|
|
|
|
* the hinted layout. If it is initialized, keep the original layout.
|
|
|
|
* This misses some cases where it would be beneficial to switch and
|
|
|
|
* blit. */
|
|
|
|
|
|
|
|
bool is_initialized = false;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < MAX_MIP_LEVELS; ++i)
|
|
|
|
is_initialized |= rsrc->slices[i].initialized;
|
|
|
|
|
|
|
|
if (is_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We're uninitialized, so do a layout switch. Reinitialize slices. */
|
|
|
|
|
|
|
|
size_t new_size;
|
|
|
|
rsrc->layout = layout;
|
|
|
|
panfrost_setup_slices(rsrc, &new_size);
|
|
|
|
|
|
|
|
/* If we grew in size, reallocate the BO */
|
|
|
|
if (new_size > rsrc->bo->size) {
|
2019-09-14 11:23:51 +02:00
|
|
|
panfrost_bo_unreference(rsrc->bo);
|
2020-03-23 19:36:46 -04:00
|
|
|
rsrc->bo = pan_bo_create(dev, new_size, PAN_BO_DELAY_MMAP);
|
2019-07-15 14:15:24 -07:00
|
|
|
}
|
2020-02-18 14:20:16 -05:00
|
|
|
|
|
|
|
/* TODO: If there are textures bound, regenerate their descriptors */
|
2019-07-15 14:15:24 -07:00
|
|
|
}
|
|
|
|
|
2019-02-15 23:59:58 +00:00
|
|
|
static void
|
|
|
|
panfrost_resource_set_stencil(struct pipe_resource *prsrc,
|
|
|
|
struct pipe_resource *stencil)
|
|
|
|
{
|
|
|
|
pan_resource(prsrc)->separate_stencil = pan_resource(stencil);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pipe_resource *
|
|
|
|
panfrost_resource_get_stencil(struct pipe_resource *prsrc)
|
|
|
|
{
|
|
|
|
return &pan_resource(prsrc)->separate_stencil->base;
|
|
|
|
}
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
static const struct u_transfer_vtbl transfer_vtbl = {
|
|
|
|
.resource_create = panfrost_resource_create,
|
|
|
|
.resource_destroy = panfrost_resource_destroy,
|
|
|
|
.transfer_map = panfrost_transfer_map,
|
|
|
|
.transfer_unmap = panfrost_transfer_unmap,
|
panfrost: Track BO lifetime with jobs and reference counts
This (fairly large) patch continues work surrounding the panfrost_job
abstraction to improve job lifetime management. In particular, we add
infrastructure to track which BOs are used by a particular job
(currently limited to the vertex buffer BOs), to reference count these
BOs, and to automatically manage the BOs memory based on the reference
count. This set of changes serves as a code cleanup, as a way of future
proofing for allowing flushing BOs, and immediately as a bugfix to
workaround the missing reference counting for vertex buffer BOs.
Meanwhile, there are a few cleanups to vertex buffer handling code
itself, so in the short-term, this allows us to remove the costly VBO
staging workaround, since this patch addresses the underlying causes.
v2: Use pipe_reference for BO reference counting, rather than managing
it ourselves. Don't duplicate hash-table key removal. Fix vertex buffer
counting.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2019-04-14 22:42:44 +00:00
|
|
|
.transfer_flush_region = panfrost_transfer_flush_region,
|
2019-02-15 23:59:58 +00:00
|
|
|
.get_internal_format = panfrost_resource_get_internal_format,
|
|
|
|
.set_stencil = panfrost_resource_set_stencil,
|
|
|
|
.get_stencil = panfrost_resource_get_stencil,
|
2019-02-05 04:32:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2020-03-23 18:44:21 -04:00
|
|
|
panfrost_resource_screen_init(struct pipe_screen *pscreen)
|
2019-02-05 04:32:27 +00:00
|
|
|
{
|
|
|
|
//pscreen->base.resource_create_with_modifiers =
|
|
|
|
// panfrost_resource_create_with_modifiers;
|
2020-03-23 18:44:21 -04:00
|
|
|
pscreen->resource_create = u_transfer_helper_resource_create;
|
|
|
|
pscreen->resource_destroy = u_transfer_helper_resource_destroy;
|
|
|
|
pscreen->resource_from_handle = panfrost_resource_from_handle;
|
|
|
|
pscreen->resource_get_handle = panfrost_resource_get_handle;
|
|
|
|
pscreen->transfer_helper = u_transfer_helper_create(&transfer_vtbl,
|
2019-07-10 10:10:31 -07:00
|
|
|
true, false,
|
|
|
|
true, true);
|
2019-06-18 14:24:57 +02:00
|
|
|
}
|
|
|
|
|
2019-02-05 04:32:27 +00:00
|
|
|
void
|
|
|
|
panfrost_resource_context_init(struct pipe_context *pctx)
|
|
|
|
{
|
|
|
|
pctx->transfer_map = u_transfer_helper_transfer_map;
|
|
|
|
pctx->transfer_unmap = u_transfer_helper_transfer_unmap;
|
|
|
|
pctx->create_surface = panfrost_create_surface;
|
|
|
|
pctx->surface_destroy = panfrost_surface_destroy;
|
|
|
|
pctx->resource_copy_region = util_resource_copy_region;
|
|
|
|
pctx->blit = panfrost_blit;
|
2019-06-21 13:57:42 -07:00
|
|
|
pctx->generate_mipmap = panfrost_generate_mipmap;
|
2019-02-05 04:32:27 +00:00
|
|
|
pctx->flush_resource = panfrost_flush_resource;
|
|
|
|
pctx->invalidate_resource = panfrost_invalidate_resource;
|
|
|
|
pctx->transfer_flush_region = u_transfer_helper_transfer_flush_region;
|
|
|
|
pctx->buffer_subdata = u_default_buffer_subdata;
|
|
|
|
pctx->texture_subdata = u_default_texture_subdata;
|
|
|
|
}
|