"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/freedreno/a3xx/fd3_draw.c" (16 Sep 2020, 5908 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 "fd3_draw.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) 2013 Rob Clark <robclark@freedesktop.org>
    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, sublicense,
    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 next
   12  * paragraph) shall be included in all copies or substantial portions of the
   13  * 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 NONINFRINGEMENT.  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 FROM,
   20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   21  * SOFTWARE.
   22  *
   23  * Authors:
   24  *    Rob Clark <robclark@freedesktop.org>
   25  */
   26 
   27 #include "pipe/p_state.h"
   28 #include "util/u_string.h"
   29 #include "util/u_memory.h"
   30 #include "util/u_prim.h"
   31 #include "util/format/u_format.h"
   32 
   33 #include "freedreno_state.h"
   34 #include "freedreno_resource.h"
   35 
   36 #include "fd3_draw.h"
   37 #include "fd3_context.h"
   38 #include "fd3_emit.h"
   39 #include "fd3_program.h"
   40 #include "fd3_format.h"
   41 #include "fd3_zsa.h"
   42 
   43 static inline uint32_t
   44 add_sat(uint32_t a, int32_t b)
   45 {
   46     int64_t ret = (uint64_t)a + (int64_t)b;
   47     if (ret > ~0U)
   48         return ~0U;
   49     if (ret < 0)
   50         return 0;
   51     return (uint32_t)ret;
   52 }
   53 
   54 static void
   55 draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,
   56         struct fd3_emit *emit, unsigned index_offset)
   57 {
   58     const struct pipe_draw_info *info = emit->info;
   59     enum pc_di_primtype primtype = ctx->primtypes[info->mode];
   60 
   61     fd3_emit_state(ctx, ring, emit);
   62 
   63     if (emit->dirty & (FD_DIRTY_VTXBUF | FD_DIRTY_VTXSTATE))
   64         fd3_emit_vertex_bufs(ring, emit);
   65 
   66     OUT_PKT0(ring, REG_A3XX_PC_VERTEX_REUSE_BLOCK_CNTL, 1);
   67     OUT_RING(ring, 0x0000000b);             /* PC_VERTEX_REUSE_BLOCK_CNTL */
   68 
   69     OUT_PKT0(ring, REG_A3XX_VFD_INDEX_MIN, 4);
   70     OUT_RING(ring, add_sat(info->min_index, info->index_bias)); /* VFD_INDEX_MIN */
   71     OUT_RING(ring, add_sat(info->max_index, info->index_bias)); /* VFD_INDEX_MAX */
   72     OUT_RING(ring, info->start_instance);   /* VFD_INSTANCEID_OFFSET */
   73     OUT_RING(ring, info->index_size ? info->index_bias : info->start); /* VFD_INDEX_OFFSET */
   74 
   75     OUT_PKT0(ring, REG_A3XX_PC_RESTART_INDEX, 1);
   76     OUT_RING(ring, info->primitive_restart ? /* PC_RESTART_INDEX */
   77             info->restart_index : 0xffffffff);
   78 
   79     /* points + psize -> spritelist: */
   80     if (ctx->rasterizer->point_size_per_vertex &&
   81             fd3_emit_get_vp(emit)->writes_psize &&
   82             (info->mode == PIPE_PRIM_POINTS))
   83         primtype = DI_PT_POINTLIST_PSIZE;
   84 
   85     fd_draw_emit(ctx->batch, ring, primtype,
   86             emit->binning_pass ? IGNORE_VISIBILITY : USE_VISIBILITY,
   87             info, index_offset);
   88 }
   89 
   90 /* fixup dirty shader state in case some "unrelated" (from the state-
   91  * tracker's perspective) state change causes us to switch to a
   92  * different variant.
   93  */
   94 static void
   95 fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
   96 {
   97     struct fd3_context *fd3_ctx = fd3_context(ctx);
   98     struct ir3_shader_key *last_key = &fd3_ctx->last_key;
   99 
  100     if (!ir3_shader_key_equal(last_key, key)) {
  101         if (ir3_shader_key_changes_fs(last_key, key)) {
  102             ctx->dirty_shader[PIPE_SHADER_FRAGMENT] |= FD_DIRTY_SHADER_PROG;
  103             ctx->dirty |= FD_DIRTY_PROG;
  104         }
  105 
  106         if (ir3_shader_key_changes_vs(last_key, key)) {
  107             ctx->dirty_shader[PIPE_SHADER_VERTEX] |= FD_DIRTY_SHADER_PROG;
  108             ctx->dirty |= FD_DIRTY_PROG;
  109         }
  110 
  111         fd3_ctx->last_key = *key;
  112     }
  113 }
  114 
  115 static bool
  116 fd3_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
  117              unsigned index_offset)
  118 {
  119     struct fd3_context *fd3_ctx = fd3_context(ctx);
  120     struct fd3_emit emit = {
  121         .debug = &ctx->debug,
  122         .vtx  = &ctx->vtx,
  123         .prog = &ctx->prog,
  124         .info = info,
  125         .key = {
  126             .color_two_side = ctx->rasterizer->light_twoside,
  127             .vclamp_color = ctx->rasterizer->clamp_vertex_color,
  128             .fclamp_color = ctx->rasterizer->clamp_fragment_color,
  129             .half_precision = ctx->in_discard_blit &&
  130                     fd_half_precision(&ctx->batch->framebuffer),
  131             .has_per_samp = (fd3_ctx->fsaturate || fd3_ctx->vsaturate),
  132             .vsaturate_s = fd3_ctx->vsaturate_s,
  133             .vsaturate_t = fd3_ctx->vsaturate_t,
  134             .vsaturate_r = fd3_ctx->vsaturate_r,
  135             .fsaturate_s = fd3_ctx->fsaturate_s,
  136             .fsaturate_t = fd3_ctx->fsaturate_t,
  137             .fsaturate_r = fd3_ctx->fsaturate_r,
  138         },
  139         .rasterflat = ctx->rasterizer->flatshade,
  140         .sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
  141         .sprite_coord_mode = ctx->rasterizer->sprite_coord_mode,
  142     };
  143 
  144     if (fd3_needs_manual_clipping(ctx->prog.vs, ctx->rasterizer))
  145         emit.key.ucp_enables = ctx->rasterizer->clip_plane_enable;
  146 
  147     fixup_shader_state(ctx, &emit.key);
  148 
  149     unsigned dirty = ctx->dirty;
  150     const struct ir3_shader_variant *vp = fd3_emit_get_vp(&emit);
  151     const struct ir3_shader_variant *fp = fd3_emit_get_fp(&emit);
  152 
  153     /* do regular pass first, since that is more likely to fail compiling: */
  154 
  155     if (!vp || !fp)
  156         return false;
  157 
  158     ctx->stats.vs_regs += ir3_shader_halfregs(vp);
  159     ctx->stats.fs_regs += ir3_shader_halfregs(fp);
  160 
  161     emit.binning_pass = false;
  162     emit.dirty = dirty;
  163     draw_impl(ctx, ctx->batch->draw, &emit, index_offset);
  164 
  165     /* and now binning pass: */
  166     emit.binning_pass = true;
  167     emit.dirty = dirty & ~(FD_DIRTY_BLEND);
  168     emit.vs = NULL;   /* we changed key so need to refetch vs */
  169     emit.fs = NULL;
  170     draw_impl(ctx, ctx->batch->binning, &emit, index_offset);
  171 
  172     fd_context_all_clean(ctx);
  173 
  174     return true;
  175 }
  176 
  177 void
  178 fd3_draw_init(struct pipe_context *pctx)
  179 {
  180     struct fd_context *ctx = fd_context(pctx);
  181     ctx->draw_vbo = fd3_draw_vbo;
  182 }