2016-12-23 19:58:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2015 Etnaviv Project
|
|
|
|
*
|
|
|
|
* 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, sub license,
|
|
|
|
* 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 NON-INFRINGEMENT. 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:
|
|
|
|
* Wladimir J. van der Laan <laanwj@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "etnaviv_clear_blit.h"
|
|
|
|
|
|
|
|
#include "hw/common.xml.h"
|
|
|
|
|
2017-11-18 09:44:31 +00:00
|
|
|
#include "etnaviv_blt.h"
|
2016-12-23 19:58:23 +00:00
|
|
|
#include "etnaviv_context.h"
|
|
|
|
#include "etnaviv_emit.h"
|
|
|
|
#include "etnaviv_format.h"
|
|
|
|
#include "etnaviv_resource.h"
|
2017-11-18 09:44:30 +00:00
|
|
|
#include "etnaviv_rs.h"
|
2016-12-23 19:58:23 +00:00
|
|
|
#include "etnaviv_surface.h"
|
|
|
|
#include "etnaviv_translate.h"
|
|
|
|
|
|
|
|
#include "pipe/p_defines.h"
|
|
|
|
#include "pipe/p_state.h"
|
|
|
|
#include "util/u_blitter.h"
|
|
|
|
#include "util/u_inlines.h"
|
|
|
|
#include "util/u_memory.h"
|
|
|
|
#include "util/u_surface.h"
|
|
|
|
|
|
|
|
/* Save current state for blitter operation */
|
2017-11-18 09:44:30 +00:00
|
|
|
void
|
2016-12-23 19:58:23 +00:00
|
|
|
etna_blit_save_state(struct etna_context *ctx)
|
|
|
|
{
|
2019-08-11 12:48:43 +01:00
|
|
|
util_blitter_save_fragment_constant_buffer_slot(ctx->blitter,
|
|
|
|
ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
|
2016-12-23 19:58:23 +00:00
|
|
|
util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer.vb);
|
|
|
|
util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements);
|
2017-03-19 16:19:10 +00:00
|
|
|
util_blitter_save_vertex_shader(ctx->blitter, ctx->shader.bind_vs);
|
2016-12-23 19:58:23 +00:00
|
|
|
util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
|
|
|
|
util_blitter_save_viewport(ctx->blitter, &ctx->viewport_s);
|
2020-03-22 10:16:58 +00:00
|
|
|
util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
|
2017-03-19 16:19:10 +00:00
|
|
|
util_blitter_save_fragment_shader(ctx->blitter, ctx->shader.bind_fs);
|
2016-12-23 19:58:23 +00:00
|
|
|
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_s);
|
|
|
|
util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
|
|
|
|
util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer_s);
|
|
|
|
util_blitter_save_fragment_sampler_states(ctx->blitter,
|
|
|
|
ctx->num_fragment_samplers, (void **)ctx->sampler);
|
|
|
|
util_blitter_save_fragment_sampler_views(ctx->blitter,
|
|
|
|
ctx->num_fragment_sampler_views, ctx->sampler_view);
|
|
|
|
}
|
|
|
|
|
2019-08-12 16:43:26 +01:00
|
|
|
uint64_t
|
|
|
|
etna_clear_blit_pack_rgba(enum pipe_format format, const union pipe_color_union *color)
|
2017-06-04 20:06:31 +01:00
|
|
|
{
|
|
|
|
union util_color uc;
|
2019-08-12 16:43:26 +01:00
|
|
|
|
2020-07-02 00:14:40 +01:00
|
|
|
util_pack_color_union(format, &uc, color);
|
2019-08-12 16:43:26 +01:00
|
|
|
|
|
|
|
switch (util_format_get_blocksize(format)) {
|
|
|
|
case 1:
|
|
|
|
uc.ui[0] = uc.ui[0] << 8 | (uc.ui[0] & 0xff);
|
2020-07-08 10:31:21 +01:00
|
|
|
/* fallthrough */
|
2019-08-12 16:43:26 +01:00
|
|
|
case 2:
|
|
|
|
uc.ui[0] = uc.ui[0] << 16 | (uc.ui[0] & 0xffff);
|
2020-07-08 10:31:21 +01:00
|
|
|
/* fallthrough */
|
2019-08-12 16:43:26 +01:00
|
|
|
case 4:
|
|
|
|
uc.ui[1] = uc.ui[0];
|
2020-07-08 10:31:21 +01:00
|
|
|
/* fallthrough */
|
2019-08-12 16:43:26 +01:00
|
|
|
default:
|
|
|
|
return (uint64_t) uc.ui[1] << 32 | uc.ui[0];
|
|
|
|
}
|
2017-06-04 20:06:31 +01:00
|
|
|
}
|
|
|
|
|
2019-08-11 13:03:13 +01:00
|
|
|
static void
|
|
|
|
etna_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
|
|
|
|
{
|
|
|
|
struct etna_context *ctx = etna_context(pctx);
|
|
|
|
struct pipe_blit_info info = *blit_info;
|
|
|
|
|
|
|
|
if (ctx->blit(pctx, &info))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (util_try_blit_via_copy_region(pctx, &info))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info.mask & PIPE_MASK_S) {
|
|
|
|
DBG("cannot blit stencil, skipping");
|
|
|
|
info.mask &= ~PIPE_MASK_S;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
|
|
|
|
DBG("blit unsupported %s -> %s",
|
|
|
|
util_format_short_name(info.src.resource->format),
|
|
|
|
util_format_short_name(info.dst.resource->format));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
etna_blit_save_state(ctx);
|
|
|
|
util_blitter_blit(ctx->blitter, &info);
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:58:23 +00:00
|
|
|
static void
|
|
|
|
etna_clear_render_target(struct pipe_context *pctx, struct pipe_surface *dst,
|
|
|
|
const union pipe_color_union *color, unsigned dstx,
|
|
|
|
unsigned dsty, unsigned width, unsigned height,
|
|
|
|
bool render_condition_enabled)
|
|
|
|
{
|
|
|
|
struct etna_context *ctx = etna_context(pctx);
|
|
|
|
|
|
|
|
/* XXX could fall back to RS when target area is full screen / resolveable
|
|
|
|
* and no TS. */
|
|
|
|
etna_blit_save_state(ctx);
|
|
|
|
util_blitter_clear_render_target(ctx->blitter, dst, color, dstx, dsty, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
etna_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *dst,
|
|
|
|
unsigned clear_flags, double depth, unsigned stencil,
|
|
|
|
unsigned dstx, unsigned dsty, unsigned width,
|
|
|
|
unsigned height, bool render_condition_enabled)
|
|
|
|
{
|
|
|
|
struct etna_context *ctx = etna_context(pctx);
|
|
|
|
|
|
|
|
/* XXX could fall back to RS when target area is full screen / resolveable
|
|
|
|
* and no TS. */
|
|
|
|
etna_blit_save_state(ctx);
|
|
|
|
util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth,
|
|
|
|
stencil, dstx, dsty, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
etna_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)
|
|
|
|
{
|
|
|
|
struct etna_context *ctx = etna_context(pctx);
|
|
|
|
|
|
|
|
/* XXX we can use the RS as a literal copy engine here
|
|
|
|
* the only complexity is tiling; the size of the boxes needs to be aligned
|
|
|
|
* to the tile size
|
|
|
|
* how to handle the case where a resource is copied from/to a non-aligned
|
|
|
|
* position?
|
|
|
|
* from non-aligned: can fall back to rendering-based copy?
|
|
|
|
* to non-aligned: can fall back to rendering-based copy?
|
|
|
|
* XXX this goes wrong when source surface is supertiled.
|
|
|
|
*/
|
|
|
|
if (util_blitter_is_copy_supported(ctx->blitter, dst, src)) {
|
|
|
|
etna_blit_save_state(ctx);
|
|
|
|
util_blitter_copy_texture(ctx->blitter, dst, dst_level, dstx, dsty, dstz,
|
|
|
|
src, src_level, src_box);
|
|
|
|
} else {
|
|
|
|
util_resource_copy_region(pctx, dst, dst_level, dstx, dsty, dstz, src,
|
|
|
|
src_level, src_box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
etna_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
|
|
|
|
{
|
|
|
|
struct etna_resource *rsc = etna_resource(prsc);
|
|
|
|
|
2019-08-10 22:00:32 +01:00
|
|
|
if (rsc->render) {
|
|
|
|
if (etna_resource_older(rsc, etna_resource(rsc->render))) {
|
|
|
|
etna_copy_resource(pctx, prsc, rsc->render, 0, 0);
|
|
|
|
rsc->seqno = etna_resource(rsc->render)->seqno;
|
2017-06-26 11:25:08 +01:00
|
|
|
}
|
2017-04-12 15:13:37 +01:00
|
|
|
} else if (etna_resource_needs_flush(rsc)) {
|
|
|
|
etna_copy_resource(pctx, prsc, prsc, 0, 0);
|
|
|
|
rsc->flush_seqno = rsc->seqno;
|
2017-04-12 15:13:36 +01:00
|
|
|
}
|
2016-12-23 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
etna_copy_resource(struct pipe_context *pctx, struct pipe_resource *dst,
|
|
|
|
struct pipe_resource *src, int first_level, int last_level)
|
|
|
|
{
|
|
|
|
struct etna_resource *src_priv = etna_resource(src);
|
|
|
|
struct etna_resource *dst_priv = etna_resource(dst);
|
|
|
|
|
|
|
|
assert(src->format == dst->format);
|
|
|
|
assert(src->array_size == dst->array_size);
|
|
|
|
assert(last_level <= dst->last_level && last_level <= src->last_level);
|
|
|
|
|
|
|
|
struct pipe_blit_info blit = {};
|
|
|
|
blit.mask = util_format_get_mask(dst->format);
|
|
|
|
blit.filter = PIPE_TEX_FILTER_NEAREST;
|
|
|
|
blit.src.resource = src;
|
|
|
|
blit.src.format = src->format;
|
|
|
|
blit.dst.resource = dst;
|
|
|
|
blit.dst.format = dst->format;
|
|
|
|
blit.dst.box.depth = blit.src.box.depth = 1;
|
|
|
|
|
|
|
|
/* Copy each level and each layer */
|
|
|
|
for (int level = first_level; level <= last_level; level++) {
|
|
|
|
blit.src.level = blit.dst.level = level;
|
|
|
|
blit.src.box.width = blit.dst.box.width =
|
2017-06-04 20:06:29 +01:00
|
|
|
MIN2(src_priv->levels[level].padded_width, dst_priv->levels[level].padded_width);
|
2016-12-23 19:58:23 +00:00
|
|
|
blit.src.box.height = blit.dst.box.height =
|
2017-06-04 20:06:29 +01:00
|
|
|
MIN2(src_priv->levels[level].padded_height, dst_priv->levels[level].padded_height);
|
2019-07-24 15:30:08 +01:00
|
|
|
unsigned depth = MIN2(src_priv->levels[level].depth, dst_priv->levels[level].depth);
|
|
|
|
if (dst->array_size > 1) {
|
|
|
|
assert(depth == 1); /* no array of 3d texture */
|
|
|
|
depth = dst->array_size;
|
|
|
|
}
|
2016-12-23 19:58:23 +00:00
|
|
|
|
2019-07-24 15:30:08 +01:00
|
|
|
for (int z = 0; z < depth; z++) {
|
|
|
|
blit.src.box.z = blit.dst.box.z = z;
|
2016-12-23 19:58:23 +00:00
|
|
|
pctx->blit(pctx, &blit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-06 13:28:21 +01:00
|
|
|
void
|
|
|
|
etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
|
|
|
|
struct pipe_resource *src, int level,
|
|
|
|
struct pipe_box *box)
|
|
|
|
{
|
|
|
|
assert(src->format == dst->format);
|
|
|
|
assert(src->array_size == dst->array_size);
|
|
|
|
|
|
|
|
struct pipe_blit_info blit = {};
|
|
|
|
blit.mask = util_format_get_mask(dst->format);
|
|
|
|
blit.filter = PIPE_TEX_FILTER_NEAREST;
|
|
|
|
blit.src.resource = src;
|
|
|
|
blit.src.format = src->format;
|
|
|
|
blit.src.box = *box;
|
|
|
|
blit.dst.resource = dst;
|
|
|
|
blit.dst.format = dst->format;
|
|
|
|
blit.dst.box = *box;
|
|
|
|
|
|
|
|
blit.dst.box.depth = blit.src.box.depth = 1;
|
|
|
|
blit.src.level = blit.dst.level = level;
|
|
|
|
|
2019-07-24 15:30:08 +01:00
|
|
|
for (int z = 0; z < box->depth; z++) {
|
|
|
|
blit.src.box.z = blit.dst.box.z = box->z + z;
|
2017-09-06 13:28:21 +01:00
|
|
|
pctx->blit(pctx, &blit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:58:23 +00:00
|
|
|
void
|
|
|
|
etna_clear_blit_init(struct pipe_context *pctx)
|
|
|
|
{
|
2017-11-18 09:44:31 +00:00
|
|
|
struct etna_context *ctx = etna_context(pctx);
|
2020-03-06 22:23:47 +00:00
|
|
|
struct etna_screen *screen = ctx->screen;
|
2017-11-18 09:44:31 +00:00
|
|
|
|
2019-08-11 13:03:13 +01:00
|
|
|
pctx->blit = etna_blit;
|
2016-12-23 19:58:23 +00:00
|
|
|
pctx->clear_render_target = etna_clear_render_target;
|
|
|
|
pctx->clear_depth_stencil = etna_clear_depth_stencil;
|
|
|
|
pctx->resource_copy_region = etna_resource_copy_region;
|
|
|
|
pctx->flush_resource = etna_flush_resource;
|
2017-11-18 09:44:30 +00:00
|
|
|
|
2020-03-06 22:23:47 +00:00
|
|
|
if (screen->specs.use_blt)
|
2017-11-18 09:44:31 +00:00
|
|
|
etna_clear_blit_blt_init(pctx);
|
|
|
|
else
|
|
|
|
etna_clear_blit_rs_init(pctx);
|
2016-12-23 19:58:23 +00:00
|
|
|
}
|