"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c" (16 Sep 2020, 10195 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "etnaviv_clear_blit.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.1.5_vs_20.2.0-rc1.

    1 /*
    2  * Copyright (c) 2012-2015 Etnaviv Project
    3  *
    4  * Permission is hereby granted, free of charge, to any person obtaining a
    5  * copy of this software and associated documentation files (the "Software"),
    6  * to deal in the Software without restriction, including without limitation
    7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
    8  * and/or sell copies of the Software, and to permit persons to whom the
    9  * Software is furnished to do so, subject to the following conditions:
   10  *
   11  * The above copyright notice and this permission notice (including the
   12  * next paragraph) shall be included in all copies or substantial portions
   13  * of the Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
   18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   21  * DEALINGS IN THE SOFTWARE.
   22  *
   23  * Authors:
   24  *    Wladimir J. van der Laan <laanwj@gmail.com>
   25  */
   26 
   27 #include "etnaviv_clear_blit.h"
   28 
   29 #include "hw/common.xml.h"
   30 
   31 #include "etnaviv_blt.h"
   32 #include "etnaviv_context.h"
   33 #include "etnaviv_emit.h"
   34 #include "etnaviv_format.h"
   35 #include "etnaviv_resource.h"
   36 #include "etnaviv_rs.h"
   37 #include "etnaviv_surface.h"
   38 #include "etnaviv_translate.h"
   39 
   40 #include "pipe/p_defines.h"
   41 #include "pipe/p_state.h"
   42 #include "util/u_blitter.h"
   43 #include "util/u_inlines.h"
   44 #include "util/u_memory.h"
   45 #include "util/u_surface.h"
   46 
   47 /* Save current state for blitter operation */
   48 void
   49 etna_blit_save_state(struct etna_context *ctx)
   50 {
   51    util_blitter_save_fragment_constant_buffer_slot(ctx->blitter,
   52                                                    ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb);
   53    util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer.vb);
   54    util_blitter_save_vertex_elements(ctx->blitter, ctx->vertex_elements);
   55    util_blitter_save_vertex_shader(ctx->blitter, ctx->shader.bind_vs);
   56    util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
   57    util_blitter_save_viewport(ctx->blitter, &ctx->viewport_s);
   58    util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
   59    util_blitter_save_fragment_shader(ctx->blitter, ctx->shader.bind_fs);
   60    util_blitter_save_blend(ctx->blitter, ctx->blend);
   61    util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
   62    util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref_s);
   63    util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
   64    util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer_s);
   65    util_blitter_save_fragment_sampler_states(ctx->blitter,
   66          ctx->num_fragment_samplers, (void **)ctx->sampler);
   67    util_blitter_save_fragment_sampler_views(ctx->blitter,
   68          ctx->num_fragment_sampler_views, ctx->sampler_view);
   69 }
   70 
   71 uint64_t
   72 etna_clear_blit_pack_rgba(enum pipe_format format, const union pipe_color_union *color)
   73 {
   74    union util_color uc;
   75 
   76    if (util_format_is_pure_uint(format)) {
   77       util_format_write_4ui(format, color->ui, 0, &uc, 0, 0, 0, 1, 1);
   78    } else if (util_format_is_pure_sint(format)) {
   79       util_format_write_4i(format, color->i, 0, &uc, 0, 0, 0, 1, 1);
   80    } else {
   81       util_pack_color(color->f, format, &uc);
   82    }
   83 
   84    switch (util_format_get_blocksize(format)) {
   85    case 1:
   86       uc.ui[0] = uc.ui[0] << 8 | (uc.ui[0] & 0xff);
   87    case 2:
   88       uc.ui[0] =  uc.ui[0] << 16 | (uc.ui[0] & 0xffff);
   89    case 4:
   90       uc.ui[1] = uc.ui[0];
   91    default:
   92       return (uint64_t) uc.ui[1] << 32 | uc.ui[0];
   93    }
   94 }
   95 
   96 static void
   97 etna_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
   98 {
   99    struct etna_context *ctx = etna_context(pctx);
  100    struct pipe_blit_info info = *blit_info;
  101 
  102    if (ctx->blit(pctx, &info))
  103       return;
  104 
  105    if (util_try_blit_via_copy_region(pctx, &info))
  106       return;
  107 
  108    if (info.mask & PIPE_MASK_S) {
  109       DBG("cannot blit stencil, skipping");
  110       info.mask &= ~PIPE_MASK_S;
  111    }
  112 
  113    if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
  114       DBG("blit unsupported %s -> %s",
  115           util_format_short_name(info.src.resource->format),
  116           util_format_short_name(info.dst.resource->format));
  117       return;
  118    }
  119 
  120    etna_blit_save_state(ctx);
  121    util_blitter_blit(ctx->blitter, &info);
  122 }
  123 
  124 static void
  125 etna_clear_render_target(struct pipe_context *pctx, struct pipe_surface *dst,
  126                          const union pipe_color_union *color, unsigned dstx,
  127                          unsigned dsty, unsigned width, unsigned height,
  128                          bool render_condition_enabled)
  129 {
  130    struct etna_context *ctx = etna_context(pctx);
  131 
  132    /* XXX could fall back to RS when target area is full screen / resolveable
  133     * and no TS. */
  134    etna_blit_save_state(ctx);
  135    util_blitter_clear_render_target(ctx->blitter, dst, color, dstx, dsty, width, height);
  136 }
  137 
  138 static void
  139 etna_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *dst,
  140                          unsigned clear_flags, double depth, unsigned stencil,
  141                          unsigned dstx, unsigned dsty, unsigned width,
  142                          unsigned height, bool render_condition_enabled)
  143 {
  144    struct etna_context *ctx = etna_context(pctx);
  145 
  146    /* XXX could fall back to RS when target area is full screen / resolveable
  147     * and no TS. */
  148    etna_blit_save_state(ctx);
  149    util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth,
  150                                     stencil, dstx, dsty, width, height);
  151 }
  152 
  153 static void
  154 etna_resource_copy_region(struct pipe_context *pctx, struct pipe_resource *dst,
  155                           unsigned dst_level, unsigned dstx, unsigned dsty,
  156                           unsigned dstz, struct pipe_resource *src,
  157                           unsigned src_level, const struct pipe_box *src_box)
  158 {
  159    struct etna_context *ctx = etna_context(pctx);
  160 
  161    /* XXX we can use the RS as a literal copy engine here
  162     * the only complexity is tiling; the size of the boxes needs to be aligned
  163     * to the tile size
  164     * how to handle the case where a resource is copied from/to a non-aligned
  165     * position?
  166     * from non-aligned: can fall back to rendering-based copy?
  167     * to non-aligned: can fall back to rendering-based copy?
  168     * XXX this goes wrong when source surface is supertiled.
  169     */
  170    if (util_blitter_is_copy_supported(ctx->blitter, dst, src)) {
  171       etna_blit_save_state(ctx);
  172       util_blitter_copy_texture(ctx->blitter, dst, dst_level, dstx, dsty, dstz,
  173                                 src, src_level, src_box);
  174    } else {
  175       util_resource_copy_region(pctx, dst, dst_level, dstx, dsty, dstz, src,
  176                                 src_level, src_box);
  177    }
  178 }
  179 
  180 static void
  181 etna_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
  182 {
  183    struct etna_resource *rsc = etna_resource(prsc);
  184 
  185    if (rsc->render) {
  186       if (etna_resource_older(rsc, etna_resource(rsc->render))) {
  187          etna_copy_resource(pctx, prsc, rsc->render, 0, 0);
  188          rsc->seqno = etna_resource(rsc->render)->seqno;
  189       }
  190    } else if (etna_resource_needs_flush(rsc)) {
  191       etna_copy_resource(pctx, prsc, prsc, 0, 0);
  192       rsc->flush_seqno = rsc->seqno;
  193    }
  194 }
  195 
  196 void
  197 etna_copy_resource(struct pipe_context *pctx, struct pipe_resource *dst,
  198                    struct pipe_resource *src, int first_level, int last_level)
  199 {
  200    struct etna_resource *src_priv = etna_resource(src);
  201    struct etna_resource *dst_priv = etna_resource(dst);
  202 
  203    assert(src->format == dst->format);
  204    assert(src->array_size == dst->array_size);
  205    assert(last_level <= dst->last_level && last_level <= src->last_level);
  206 
  207    struct pipe_blit_info blit = {};
  208    blit.mask = util_format_get_mask(dst->format);
  209    blit.filter = PIPE_TEX_FILTER_NEAREST;
  210    blit.src.resource = src;
  211    blit.src.format = src->format;
  212    blit.dst.resource = dst;
  213    blit.dst.format = dst->format;
  214    blit.dst.box.depth = blit.src.box.depth = 1;
  215 
  216    /* Copy each level and each layer */
  217    for (int level = first_level; level <= last_level; level++) {
  218       blit.src.level = blit.dst.level = level;
  219       blit.src.box.width = blit.dst.box.width =
  220          MIN2(src_priv->levels[level].padded_width, dst_priv->levels[level].padded_width);
  221       blit.src.box.height = blit.dst.box.height =
  222          MIN2(src_priv->levels[level].padded_height, dst_priv->levels[level].padded_height);
  223       unsigned depth = MIN2(src_priv->levels[level].depth, dst_priv->levels[level].depth);
  224       if (dst->array_size > 1) {
  225          assert(depth == 1); /* no array of 3d texture */
  226          depth = dst->array_size;
  227       }
  228 
  229       for (int z = 0; z < depth; z++) {
  230          blit.src.box.z = blit.dst.box.z = z;
  231          pctx->blit(pctx, &blit);
  232       }
  233    }
  234 }
  235 
  236 void
  237 etna_copy_resource_box(struct pipe_context *pctx, struct pipe_resource *dst,
  238                        struct pipe_resource *src, int level,
  239                        struct pipe_box *box)
  240 {
  241    assert(src->format == dst->format);
  242    assert(src->array_size == dst->array_size);
  243 
  244    struct pipe_blit_info blit = {};
  245    blit.mask = util_format_get_mask(dst->format);
  246    blit.filter = PIPE_TEX_FILTER_NEAREST;
  247    blit.src.resource = src;
  248    blit.src.format = src->format;
  249    blit.src.box = *box;
  250    blit.dst.resource = dst;
  251    blit.dst.format = dst->format;
  252    blit.dst.box = *box;
  253 
  254    blit.dst.box.depth = blit.src.box.depth = 1;
  255    blit.src.level = blit.dst.level = level;
  256 
  257    for (int z = 0; z < box->depth; z++) {
  258       blit.src.box.z = blit.dst.box.z = box->z + z;
  259       pctx->blit(pctx, &blit);
  260    }
  261 }
  262 
  263 void
  264 etna_clear_blit_init(struct pipe_context *pctx)
  265 {
  266    struct etna_context *ctx = etna_context(pctx);
  267    struct etna_screen *screen = ctx->screen;
  268 
  269    pctx->blit = etna_blit;
  270    pctx->clear_render_target = etna_clear_render_target;
  271    pctx->clear_depth_stencil = etna_clear_depth_stencil;
  272    pctx->resource_copy_region = etna_resource_copy_region;
  273    pctx->flush_resource = etna_flush_resource;
  274 
  275    if (screen->specs.use_blt)
  276       etna_clear_blit_blt_init(pctx);
  277    else
  278       etna_clear_blit_rs_init(pctx);
  279 }