2012-10-27 17:07:34 +01:00
|
|
|
/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Rob Clark <robclark@freedesktop.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util/u_format.h"
|
|
|
|
#include "util/u_inlines.h"
|
|
|
|
#include "util/u_transfer.h"
|
|
|
|
#include "util/u_string.h"
|
2013-03-21 21:32:00 +00:00
|
|
|
#include "util/u_surface.h"
|
2012-10-27 17:07:34 +01:00
|
|
|
|
|
|
|
#include "freedreno_resource.h"
|
|
|
|
#include "freedreno_screen.h"
|
|
|
|
#include "freedreno_surface.h"
|
|
|
|
#include "freedreno_context.h"
|
2014-05-10 18:45:54 +01:00
|
|
|
#include "freedreno_query_hw.h"
|
2012-10-27 17:07:34 +01:00
|
|
|
#include "freedreno_util.h"
|
|
|
|
|
2013-09-11 15:08:08 +01:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
realloc_bo(struct fd_resource *rsc, uint32_t size)
|
|
|
|
{
|
|
|
|
struct fd_screen *screen = fd_screen(rsc->base.b.screen);
|
|
|
|
uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
|
|
|
|
DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
|
|
|
|
|
2014-05-24 15:07:13 +01:00
|
|
|
/* if we start using things other than write-combine,
|
|
|
|
* be sure to check for PIPE_RESOURCE_FLAG_MAP_COHERENT
|
|
|
|
*/
|
|
|
|
|
2013-09-11 15:08:08 +01:00
|
|
|
if (rsc->bo)
|
|
|
|
fd_bo_del(rsc->bo);
|
|
|
|
|
|
|
|
rsc->bo = fd_bo_new(screen->dev, size, flags);
|
|
|
|
rsc->timestamp = 0;
|
|
|
|
rsc->dirty = false;
|
|
|
|
}
|
|
|
|
|
2013-05-26 22:13:27 +01:00
|
|
|
static void fd_resource_transfer_flush_region(struct pipe_context *pctx,
|
|
|
|
struct pipe_transfer *ptrans,
|
|
|
|
const struct pipe_box *box)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fd_resource_transfer_unmap(struct pipe_context *pctx,
|
|
|
|
struct pipe_transfer *ptrans)
|
|
|
|
{
|
|
|
|
struct fd_context *ctx = fd_context(pctx);
|
2013-08-29 22:24:33 +01:00
|
|
|
struct fd_resource *rsc = fd_resource(ptrans->resource);
|
|
|
|
if (!(ptrans->usage & PIPE_TRANSFER_UNSYNCHRONIZED))
|
|
|
|
fd_bo_cpu_fini(rsc->bo);
|
2013-05-26 22:13:27 +01:00
|
|
|
pipe_resource_reference(&ptrans->resource, NULL);
|
|
|
|
util_slab_free(&ctx->transfer_pool, ptrans);
|
|
|
|
}
|
|
|
|
|
2012-10-27 17:07:34 +01:00
|
|
|
static void *
|
|
|
|
fd_resource_transfer_map(struct pipe_context *pctx,
|
|
|
|
struct pipe_resource *prsc,
|
|
|
|
unsigned level, unsigned usage,
|
|
|
|
const struct pipe_box *box,
|
|
|
|
struct pipe_transfer **pptrans)
|
|
|
|
{
|
|
|
|
struct fd_context *ctx = fd_context(pctx);
|
|
|
|
struct fd_resource *rsc = fd_resource(prsc);
|
2013-08-31 14:14:27 +01:00
|
|
|
struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
|
|
|
|
struct pipe_transfer *ptrans;
|
2012-10-27 17:07:34 +01:00
|
|
|
enum pipe_format format = prsc->format;
|
2013-08-29 22:24:33 +01:00
|
|
|
uint32_t op = 0;
|
2014-12-12 18:38:05 +00:00
|
|
|
uint32_t offset;
|
2012-10-27 17:07:34 +01:00
|
|
|
char *buf;
|
2013-09-11 15:08:08 +01:00
|
|
|
int ret = 0;
|
2012-10-27 17:07:34 +01:00
|
|
|
|
2014-10-22 21:36:24 +01:00
|
|
|
DBG("prsc=%p, level=%u, usage=%x", prsc, level, usage);
|
|
|
|
|
2013-08-31 14:14:27 +01:00
|
|
|
ptrans = util_slab_alloc(&ctx->transfer_pool);
|
2012-10-27 17:07:34 +01:00
|
|
|
if (!ptrans)
|
|
|
|
return NULL;
|
|
|
|
|
2013-08-29 22:24:33 +01:00
|
|
|
/* util_slab_alloc() doesn't zero: */
|
2013-05-26 22:13:27 +01:00
|
|
|
memset(ptrans, 0, sizeof(*ptrans));
|
|
|
|
|
|
|
|
pipe_resource_reference(&ptrans->resource, prsc);
|
2012-10-27 17:07:34 +01:00
|
|
|
ptrans->level = level;
|
|
|
|
ptrans->usage = usage;
|
|
|
|
ptrans->box = *box;
|
2013-08-31 14:14:27 +01:00
|
|
|
ptrans->stride = slice->pitch * rsc->cpp;
|
2014-10-15 15:29:17 +01:00
|
|
|
ptrans->layer_stride = slice->size0;
|
2012-10-27 17:07:34 +01:00
|
|
|
|
2013-09-11 15:08:08 +01:00
|
|
|
if (usage & PIPE_TRANSFER_READ)
|
|
|
|
op |= DRM_FREEDRENO_PREP_READ;
|
|
|
|
|
|
|
|
if (usage & PIPE_TRANSFER_WRITE)
|
|
|
|
op |= DRM_FREEDRENO_PREP_WRITE;
|
|
|
|
|
2014-10-22 21:36:24 +01:00
|
|
|
if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
|
|
|
|
realloc_bo(rsc, fd_bo_size(rsc->bo));
|
|
|
|
} else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
|
2015-04-03 03:28:21 +01:00
|
|
|
/* If the GPU is writing to the resource, or if it is reading from the
|
|
|
|
* resource and we're trying to write to it, flush the renders.
|
|
|
|
*/
|
2015-04-03 07:25:58 +01:00
|
|
|
if (rsc->dirty ||
|
|
|
|
((ptrans->usage & PIPE_TRANSFER_WRITE) && rsc->reading))
|
2015-04-03 03:28:21 +01:00
|
|
|
fd_context_render(pctx);
|
|
|
|
|
|
|
|
/* The GPU keeps track of how the various bo's are being used, and
|
|
|
|
* will wait if necessary for the proper operation to have
|
|
|
|
* completed.
|
|
|
|
*/
|
2013-09-11 15:08:08 +01:00
|
|
|
ret = fd_bo_cpu_prep(rsc->bo, ctx->screen->pipe, op);
|
2014-10-22 21:36:24 +01:00
|
|
|
if (ret)
|
2013-09-11 15:08:08 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2013-05-26 22:13:27 +01:00
|
|
|
|
2012-10-27 17:07:34 +01:00
|
|
|
buf = fd_bo_map(rsc->bo);
|
2013-05-26 22:13:27 +01:00
|
|
|
if (!buf) {
|
|
|
|
fd_resource_transfer_unmap(pctx, ptrans);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-27 17:07:34 +01:00
|
|
|
|
|
|
|
*pptrans = ptrans;
|
|
|
|
|
2014-12-12 18:38:05 +00:00
|
|
|
if (rsc->layer_first) {
|
|
|
|
offset = slice->offset +
|
|
|
|
box->y / util_format_get_blockheight(format) * ptrans->stride +
|
|
|
|
box->x / util_format_get_blockwidth(format) * rsc->cpp +
|
|
|
|
box->z * rsc->layer_size;
|
|
|
|
} else {
|
|
|
|
offset = slice->offset +
|
|
|
|
box->y / util_format_get_blockheight(format) * ptrans->stride +
|
|
|
|
box->x / util_format_get_blockwidth(format) * rsc->cpp +
|
|
|
|
box->z * slice->size0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf + offset;
|
2013-09-11 15:08:08 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
fd_resource_transfer_unmap(pctx, ptrans);
|
|
|
|
return NULL;
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fd_resource_destroy(struct pipe_screen *pscreen,
|
|
|
|
struct pipe_resource *prsc)
|
|
|
|
{
|
|
|
|
struct fd_resource *rsc = fd_resource(prsc);
|
2013-09-27 20:35:19 +01:00
|
|
|
if (rsc->bo)
|
|
|
|
fd_bo_del(rsc->bo);
|
2012-10-27 17:07:34 +01:00
|
|
|
FREE(rsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean
|
|
|
|
fd_resource_get_handle(struct pipe_screen *pscreen,
|
|
|
|
struct pipe_resource *prsc,
|
|
|
|
struct winsys_handle *handle)
|
|
|
|
{
|
|
|
|
struct fd_resource *rsc = fd_resource(prsc);
|
|
|
|
|
2013-05-26 22:13:27 +01:00
|
|
|
return fd_screen_bo_get_handle(pscreen, rsc->bo,
|
2013-08-31 14:14:27 +01:00
|
|
|
rsc->slices[0].pitch * rsc->cpp, handle);
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-26 22:13:27 +01:00
|
|
|
static const struct u_resource_vtbl fd_resource_vtbl = {
|
2012-10-27 17:07:34 +01:00
|
|
|
.resource_get_handle = fd_resource_get_handle,
|
|
|
|
.resource_destroy = fd_resource_destroy,
|
|
|
|
.transfer_map = fd_resource_transfer_map,
|
|
|
|
.transfer_flush_region = fd_resource_transfer_flush_region,
|
|
|
|
.transfer_unmap = fd_resource_transfer_unmap,
|
|
|
|
.transfer_inline_write = u_default_transfer_inline_write,
|
|
|
|
};
|
|
|
|
|
2013-08-31 14:14:27 +01:00
|
|
|
static uint32_t
|
2014-12-04 21:56:33 +00:00
|
|
|
setup_slices(struct fd_resource *rsc, uint32_t alignment)
|
2013-08-31 14:14:27 +01:00
|
|
|
{
|
|
|
|
struct pipe_resource *prsc = &rsc->base.b;
|
|
|
|
uint32_t level, size = 0;
|
|
|
|
uint32_t width = prsc->width0;
|
|
|
|
uint32_t height = prsc->height0;
|
|
|
|
uint32_t depth = prsc->depth0;
|
2014-12-12 18:38:05 +00:00
|
|
|
/* in layer_first layout, the level (slice) contains just one
|
|
|
|
* layer (since in fact the layer contains the slices)
|
|
|
|
*/
|
|
|
|
uint32_t layers_in_level = rsc->layer_first ? 1 : prsc->array_size;
|
2013-08-31 14:14:27 +01:00
|
|
|
|
|
|
|
for (level = 0; level <= prsc->last_level; level++) {
|
|
|
|
struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
|
|
|
|
|
2015-03-13 05:36:57 +00:00
|
|
|
slice->pitch = width = align(width, 32);
|
2013-08-31 14:14:27 +01:00
|
|
|
slice->offset = size;
|
2015-03-15 20:38:42 +00:00
|
|
|
/* 1d array and 2d array textures must all have the same layer size
|
|
|
|
* for each miplevel on a3xx. 3d textures can have different layer
|
|
|
|
* sizes for high levels, but the hw auto-sizer is buggy (or at least
|
|
|
|
* different than what this code does), so as soon as the layer size
|
|
|
|
* range gets into range, we stop reducing it.
|
2015-03-13 04:53:49 +00:00
|
|
|
*/
|
2015-03-15 20:38:42 +00:00
|
|
|
if (prsc->target == PIPE_TEXTURE_3D && (
|
|
|
|
level == 1 ||
|
|
|
|
(level > 1 && rsc->slices[level - 1].size0 > 0xf000)))
|
|
|
|
slice->size0 = align(slice->pitch * height * rsc->cpp, alignment);
|
|
|
|
else if (level == 0 || rsc->layer_first || alignment == 1)
|
2015-03-13 04:53:49 +00:00
|
|
|
slice->size0 = align(slice->pitch * height * rsc->cpp, alignment);
|
|
|
|
else
|
2015-03-15 20:38:42 +00:00
|
|
|
slice->size0 = rsc->slices[level - 1].size0;
|
2013-08-31 14:14:27 +01:00
|
|
|
|
2014-12-12 18:38:05 +00:00
|
|
|
size += slice->size0 * depth * layers_in_level;
|
2013-08-31 14:14:27 +01:00
|
|
|
|
|
|
|
width = u_minify(width, 1);
|
|
|
|
height = u_minify(height, 1);
|
|
|
|
depth = u_minify(depth, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2014-09-13 13:25:51 +01:00
|
|
|
static uint32_t
|
2014-12-04 21:56:33 +00:00
|
|
|
slice_alignment(struct pipe_screen *pscreen, const struct pipe_resource *tmpl)
|
2014-09-13 13:25:51 +01:00
|
|
|
{
|
2014-12-04 21:56:33 +00:00
|
|
|
/* on a3xx, 2d array and 3d textures seem to want their
|
|
|
|
* layers aligned to page boundaries:
|
|
|
|
*/
|
|
|
|
switch (tmpl->target) {
|
|
|
|
case PIPE_TEXTURE_3D:
|
|
|
|
case PIPE_TEXTURE_1D_ARRAY:
|
|
|
|
case PIPE_TEXTURE_2D_ARRAY:
|
|
|
|
return 4096;
|
|
|
|
default:
|
|
|
|
return 1;
|
2014-09-13 13:25:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 17:07:34 +01:00
|
|
|
/**
|
|
|
|
* Create a new texture object, using the given template info.
|
|
|
|
*/
|
|
|
|
static struct pipe_resource *
|
|
|
|
fd_resource_create(struct pipe_screen *pscreen,
|
|
|
|
const struct pipe_resource *tmpl)
|
|
|
|
{
|
|
|
|
struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
|
|
|
|
struct pipe_resource *prsc = &rsc->base.b;
|
2013-09-11 15:08:08 +01:00
|
|
|
uint32_t size;
|
2012-10-27 17:07:34 +01:00
|
|
|
|
2013-08-31 14:14:27 +01:00
|
|
|
DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
|
2012-10-27 17:07:34 +01:00
|
|
|
"nr_samples=%u, usage=%u, bind=%x, flags=%x",
|
|
|
|
tmpl->target, util_format_name(tmpl->format),
|
|
|
|
tmpl->width0, tmpl->height0, tmpl->depth0,
|
|
|
|
tmpl->array_size, tmpl->last_level, tmpl->nr_samples,
|
|
|
|
tmpl->usage, tmpl->bind, tmpl->flags);
|
|
|
|
|
|
|
|
if (!rsc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*prsc = *tmpl;
|
|
|
|
|
|
|
|
pipe_reference_init(&prsc->reference, 1);
|
|
|
|
prsc->screen = pscreen;
|
|
|
|
|
|
|
|
rsc->base.vtbl = &fd_resource_vtbl;
|
|
|
|
rsc->cpp = util_format_get_blocksize(tmpl->format);
|
|
|
|
|
2013-05-26 22:13:27 +01:00
|
|
|
assert(rsc->cpp);
|
|
|
|
|
2014-12-12 18:38:05 +00:00
|
|
|
if (is_a4xx(fd_screen(pscreen))) {
|
|
|
|
switch (tmpl->target) {
|
|
|
|
case PIPE_TEXTURE_3D:
|
|
|
|
/* TODO 3D_ARRAY? */
|
|
|
|
rsc->layer_first = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rsc->layer_first = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 21:56:33 +00:00
|
|
|
size = setup_slices(rsc, slice_alignment(pscreen, tmpl));
|
2013-08-31 14:14:27 +01:00
|
|
|
|
2014-12-12 18:38:05 +00:00
|
|
|
if (rsc->layer_first) {
|
|
|
|
rsc->layer_size = align(size, 4096);
|
|
|
|
size = rsc->layer_size * prsc->array_size;
|
|
|
|
}
|
|
|
|
|
2013-09-11 15:08:08 +01:00
|
|
|
realloc_bo(rsc, size);
|
2013-09-27 20:35:19 +01:00
|
|
|
if (!rsc->bo)
|
|
|
|
goto fail;
|
2012-10-27 17:07:34 +01:00
|
|
|
|
|
|
|
return prsc;
|
2013-09-27 20:35:19 +01:00
|
|
|
fail:
|
|
|
|
fd_resource_destroy(pscreen, prsc);
|
|
|
|
return NULL;
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a texture from a winsys_handle. The handle is often created in
|
|
|
|
* another process by first creating a pipe texture and then calling
|
|
|
|
* resource_get_handle.
|
|
|
|
*/
|
|
|
|
static struct pipe_resource *
|
|
|
|
fd_resource_from_handle(struct pipe_screen *pscreen,
|
|
|
|
const struct pipe_resource *tmpl,
|
|
|
|
struct winsys_handle *handle)
|
|
|
|
{
|
|
|
|
struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
|
2013-08-31 14:14:27 +01:00
|
|
|
struct fd_resource_slice *slice = &rsc->slices[0];
|
2012-10-27 17:07:34 +01:00
|
|
|
struct pipe_resource *prsc = &rsc->base.b;
|
|
|
|
|
2013-08-31 14:14:27 +01:00
|
|
|
DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
|
2012-10-27 17:07:34 +01:00
|
|
|
"nr_samples=%u, usage=%u, bind=%x, flags=%x",
|
|
|
|
tmpl->target, util_format_name(tmpl->format),
|
|
|
|
tmpl->width0, tmpl->height0, tmpl->depth0,
|
|
|
|
tmpl->array_size, tmpl->last_level, tmpl->nr_samples,
|
|
|
|
tmpl->usage, tmpl->bind, tmpl->flags);
|
|
|
|
|
|
|
|
if (!rsc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*prsc = *tmpl;
|
|
|
|
|
|
|
|
pipe_reference_init(&prsc->reference, 1);
|
|
|
|
prsc->screen = pscreen;
|
|
|
|
|
2013-08-31 14:14:27 +01:00
|
|
|
rsc->bo = fd_screen_bo_from_handle(pscreen, handle, &slice->pitch);
|
2013-09-27 20:35:19 +01:00
|
|
|
if (!rsc->bo)
|
|
|
|
goto fail;
|
2012-10-27 17:07:34 +01:00
|
|
|
|
|
|
|
rsc->base.vtbl = &fd_resource_vtbl;
|
2013-05-26 22:13:27 +01:00
|
|
|
rsc->cpp = util_format_get_blocksize(tmpl->format);
|
2013-08-31 14:14:27 +01:00
|
|
|
slice->pitch /= rsc->cpp;
|
2013-05-26 22:13:27 +01:00
|
|
|
|
|
|
|
assert(rsc->cpp);
|
2012-10-27 17:07:34 +01:00
|
|
|
|
|
|
|
return prsc;
|
2013-09-27 20:35:19 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
fd_resource_destroy(pscreen, prsc);
|
|
|
|
return NULL;
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:33:15 +01:00
|
|
|
static void fd_blitter_pipe_begin(struct fd_context *ctx);
|
|
|
|
static void fd_blitter_pipe_end(struct fd_context *ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _copy_region using pipe (3d engine)
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
fd_blitter_pipe_copy_region(struct fd_context *ctx,
|
|
|
|
struct pipe_resource *dst,
|
|
|
|
unsigned dst_level,
|
|
|
|
unsigned dstx, unsigned dsty, unsigned dstz,
|
|
|
|
struct pipe_resource *src,
|
|
|
|
unsigned src_level,
|
|
|
|
const struct pipe_box *src_box)
|
|
|
|
{
|
|
|
|
/* not until we allow rendertargets to be buffers */
|
|
|
|
if (dst->target == PIPE_BUFFER || src->target == PIPE_BUFFER)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!util_blitter_is_copy_supported(ctx->blitter, dst, src))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fd_blitter_pipe_begin(ctx);
|
|
|
|
util_blitter_copy_texture(ctx->blitter,
|
|
|
|
dst, dst_level, dstx, dsty, dstz,
|
|
|
|
src, src_level, src_box);
|
|
|
|
fd_blitter_pipe_end(ctx);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-14 18:57:06 +01:00
|
|
|
|
2012-10-27 17:07:34 +01:00
|
|
|
/**
|
|
|
|
* Copy a block of pixels from one resource to another.
|
|
|
|
* The resource must be of the same format.
|
|
|
|
* Resources with nr_samples > 1 are not allowed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fd_resource_copy_region(struct pipe_context *pctx,
|
|
|
|
struct pipe_resource *dst,
|
|
|
|
unsigned dst_level,
|
|
|
|
unsigned dstx, unsigned dsty, unsigned dstz,
|
|
|
|
struct pipe_resource *src,
|
|
|
|
unsigned src_level,
|
|
|
|
const struct pipe_box *src_box)
|
|
|
|
{
|
2014-08-22 23:33:15 +01:00
|
|
|
struct fd_context *ctx = fd_context(pctx);
|
|
|
|
|
2013-05-14 18:57:06 +01:00
|
|
|
/* TODO if we have 2d core, or other DMA engine that could be used
|
|
|
|
* for simple copies and reasonably easily synchronized with the 3d
|
|
|
|
* core, this is where we'd plug it in..
|
|
|
|
*/
|
2014-08-22 23:33:15 +01:00
|
|
|
|
|
|
|
/* try blit on 3d pipe: */
|
|
|
|
if (fd_blitter_pipe_copy_region(ctx,
|
|
|
|
dst, dst_level, dstx, dsty, dstz,
|
|
|
|
src, src_level, src_box))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* else fallback to pure sw: */
|
|
|
|
util_resource_copy_region(pctx,
|
|
|
|
dst, dst_level, dstx, dsty, dstz,
|
|
|
|
src, src_level, src_box);
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:33:15 +01:00
|
|
|
/**
|
|
|
|
* Optimal hardware path for blitting pixels.
|
2012-10-27 17:07:34 +01:00
|
|
|
* Scaling, format conversion, up- and downsampling (resolve) are allowed.
|
|
|
|
*/
|
|
|
|
static void
|
2013-03-21 21:32:00 +00:00
|
|
|
fd_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
|
2012-10-27 17:07:34 +01:00
|
|
|
{
|
2014-08-22 23:33:15 +01:00
|
|
|
struct fd_context *ctx = fd_context(pctx);
|
2013-03-21 21:32:00 +00:00
|
|
|
struct pipe_blit_info info = *blit_info;
|
|
|
|
|
|
|
|
if (info.src.resource->nr_samples > 1 &&
|
|
|
|
info.dst.resource->nr_samples <= 1 &&
|
|
|
|
!util_format_is_depth_or_stencil(info.src.resource->format) &&
|
|
|
|
!util_format_is_pure_integer(info.src.resource->format)) {
|
|
|
|
DBG("color resolve unimplemented");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util_try_blit_via_copy_region(pctx, &info)) {
|
|
|
|
return; /* done */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.mask & PIPE_MASK_S) {
|
|
|
|
DBG("cannot blit stencil, skipping");
|
|
|
|
info.mask &= ~PIPE_MASK_S;
|
|
|
|
}
|
|
|
|
|
2014-08-22 23:33:15 +01:00
|
|
|
if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
|
2013-03-21 21:32:00 +00:00
|
|
|
DBG("blit unsupported %s -> %s",
|
2014-08-22 23:33:15 +01:00
|
|
|
util_format_short_name(info.src.resource->format),
|
|
|
|
util_format_short_name(info.dst.resource->format));
|
|
|
|
return;
|
2013-03-21 21:32:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:33:15 +01:00
|
|
|
fd_blitter_pipe_begin(ctx);
|
|
|
|
util_blitter_blit(ctx->blitter, &info);
|
|
|
|
fd_blitter_pipe_end(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fd_blitter_pipe_begin(struct fd_context *ctx)
|
|
|
|
{
|
2014-10-14 17:20:54 +01:00
|
|
|
util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vtx.vertexbuf.vb);
|
|
|
|
util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx.vtx);
|
2013-03-21 21:32:00 +00:00
|
|
|
util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vp);
|
|
|
|
util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
|
|
|
|
util_blitter_save_viewport(ctx->blitter, &ctx->viewport);
|
|
|
|
util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
|
|
|
|
util_blitter_save_fragment_shader(ctx->blitter, ctx->prog.fp);
|
|
|
|
util_blitter_save_blend(ctx->blitter, ctx->blend);
|
|
|
|
util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
|
|
|
|
util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref);
|
|
|
|
util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
|
2013-03-06 15:45:58 +00:00
|
|
|
util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer);
|
2013-03-21 21:32:00 +00:00
|
|
|
util_blitter_save_fragment_sampler_states(ctx->blitter,
|
|
|
|
ctx->fragtex.num_samplers,
|
|
|
|
(void **)ctx->fragtex.samplers);
|
|
|
|
util_blitter_save_fragment_sampler_views(ctx->blitter,
|
|
|
|
ctx->fragtex.num_textures, ctx->fragtex.textures);
|
|
|
|
|
2014-05-10 18:45:54 +01:00
|
|
|
fd_hw_query_set_stage(ctx, ctx->ring, FD_STAGE_BLIT);
|
2014-08-22 23:33:15 +01:00
|
|
|
}
|
2013-05-14 18:57:06 +01:00
|
|
|
|
2014-08-22 23:33:15 +01:00
|
|
|
static void
|
|
|
|
fd_blitter_pipe_end(struct fd_context *ctx)
|
|
|
|
{
|
|
|
|
fd_hw_query_set_stage(ctx, ctx->ring, FD_STAGE_NULL);
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|
|
|
|
|
2013-09-20 14:08:29 +01:00
|
|
|
static void
|
2014-08-23 14:33:50 +01:00
|
|
|
fd_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
|
2013-09-20 14:08:29 +01:00
|
|
|
{
|
2014-08-23 14:33:50 +01:00
|
|
|
struct fd_resource *rsc = fd_resource(prsc);
|
|
|
|
|
|
|
|
if (rsc->dirty)
|
|
|
|
fd_context_render(pctx);
|
2013-09-20 14:08:29 +01:00
|
|
|
}
|
|
|
|
|
2012-10-27 17:07:34 +01:00
|
|
|
void
|
|
|
|
fd_resource_screen_init(struct pipe_screen *pscreen)
|
|
|
|
{
|
|
|
|
pscreen->resource_create = fd_resource_create;
|
|
|
|
pscreen->resource_from_handle = fd_resource_from_handle;
|
|
|
|
pscreen->resource_get_handle = u_resource_get_handle_vtbl;
|
|
|
|
pscreen->resource_destroy = u_resource_destroy_vtbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_resource_context_init(struct pipe_context *pctx)
|
|
|
|
{
|
|
|
|
pctx->transfer_map = u_transfer_map_vtbl;
|
|
|
|
pctx->transfer_flush_region = u_transfer_flush_region_vtbl;
|
|
|
|
pctx->transfer_unmap = u_transfer_unmap_vtbl;
|
|
|
|
pctx->transfer_inline_write = u_transfer_inline_write_vtbl;
|
|
|
|
pctx->create_surface = fd_create_surface;
|
|
|
|
pctx->surface_destroy = fd_surface_destroy;
|
|
|
|
pctx->resource_copy_region = fd_resource_copy_region;
|
|
|
|
pctx->blit = fd_blit;
|
2013-09-20 14:08:29 +01:00
|
|
|
pctx->flush_resource = fd_flush_resource;
|
2012-10-27 17:07:34 +01:00
|
|
|
}
|