Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_draw.c
4574 views
/*1* Copyright (C) 2014 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#include "pipe/p_state.h"27#include "util/u_memory.h"28#include "util/u_prim.h"29#include "util/u_string.h"3031#include "freedreno_resource.h"32#include "freedreno_state.h"3334#include "fd4_context.h"35#include "fd4_draw.h"36#include "fd4_emit.h"37#include "fd4_format.h"38#include "fd4_program.h"39#include "fd4_zsa.h"4041static void42draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,43struct fd4_emit *emit, unsigned index_offset) assert_dt44{45const struct pipe_draw_info *info = emit->info;46enum pc_di_primtype primtype = ctx->primtypes[info->mode];4748fd4_emit_state(ctx, ring, emit);4950if (emit->dirty & (FD_DIRTY_VTXBUF | FD_DIRTY_VTXSTATE))51fd4_emit_vertex_bufs(ring, emit);5253OUT_PKT0(ring, REG_A4XX_VFD_INDEX_OFFSET, 2);54OUT_RING(ring, info->index_size ? emit->draw->index_bias55: emit->draw->start); /* VFD_INDEX_OFFSET */56OUT_RING(ring, info->start_instance); /* ??? UNKNOWN_2209 */5758OUT_PKT0(ring, REG_A4XX_PC_RESTART_INDEX, 1);59OUT_RING(ring, info->primitive_restart ? /* PC_RESTART_INDEX */60info->restart_index61: 0xffffffff);6263/* points + psize -> spritelist: */64if (ctx->rasterizer->point_size_per_vertex &&65fd4_emit_get_vp(emit)->writes_psize && (info->mode == PIPE_PRIM_POINTS))66primtype = DI_PT_POINTLIST_PSIZE;6768fd4_draw_emit(ctx->batch, ring, primtype,69emit->binning_pass ? IGNORE_VISIBILITY : USE_VISIBILITY, info,70emit->indirect, emit->draw, index_offset);71}7273static bool74fd4_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,75unsigned drawid_offset,76const struct pipe_draw_indirect_info *indirect,77const struct pipe_draw_start_count_bias *draw,78unsigned index_offset) in_dt79{80struct fd4_context *fd4_ctx = fd4_context(ctx);81struct fd4_emit emit = {82.debug = &ctx->debug,83.vtx = &ctx->vtx,84.info = info,85.drawid_offset = drawid_offset,86.indirect = indirect,87.draw = draw,88.key = {89.vs = ctx->prog.vs,90.fs = ctx->prog.fs,91.key = {92.rasterflat = ctx->rasterizer->flatshade,93.ucp_enables = ctx->rasterizer->clip_plane_enable,94.has_per_samp = fd4_ctx->fastc_srgb || fd4_ctx->vastc_srgb,95.vastc_srgb = fd4_ctx->vastc_srgb,96.fastc_srgb = fd4_ctx->fastc_srgb,97},98},99.rasterflat = ctx->rasterizer->flatshade,100.sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,101.sprite_coord_mode = ctx->rasterizer->sprite_coord_mode,102};103104if (info->mode != PIPE_PRIM_MAX && !indirect && !info->primitive_restart &&105!u_trim_pipe_prim(info->mode, (unsigned *)&draw->count))106return false;107108ir3_fixup_shader_state(&ctx->base, &emit.key.key);109110enum fd_dirty_3d_state dirty = ctx->dirty;111112emit.prog = fd4_program_state(113ir3_cache_lookup(ctx->shader_cache, &emit.key, &ctx->debug));114115/* bail if compile failed: */116if (!emit.prog)117return false;118119const struct ir3_shader_variant *vp = fd4_emit_get_vp(&emit);120const struct ir3_shader_variant *fp = fd4_emit_get_fp(&emit);121122ir3_update_max_tf_vtx(ctx, vp);123124/* do regular pass first: */125126if (unlikely(ctx->stats_users > 0)) {127ctx->stats.vs_regs += ir3_shader_halfregs(vp);128ctx->stats.fs_regs += ir3_shader_halfregs(fp);129}130131emit.binning_pass = false;132emit.dirty = dirty;133134struct fd_ringbuffer *ring = ctx->batch->draw;135136if (ctx->rasterizer->rasterizer_discard) {137fd_wfi(ctx->batch, ring);138OUT_PKT3(ring, CP_REG_RMW, 3);139OUT_RING(ring, REG_A4XX_RB_RENDER_CONTROL);140OUT_RING(ring, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);141OUT_RING(ring, A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);142}143144draw_impl(ctx, ctx->batch->draw, &emit, index_offset);145146if (ctx->rasterizer->rasterizer_discard) {147fd_wfi(ctx->batch, ring);148OUT_PKT3(ring, CP_REG_RMW, 3);149OUT_RING(ring, REG_A4XX_RB_RENDER_CONTROL);150OUT_RING(ring, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);151OUT_RING(ring, 0);152}153154/* and now binning pass: */155emit.binning_pass = true;156emit.dirty = dirty & ~(FD_DIRTY_BLEND);157emit.vs = NULL; /* we changed key so need to refetch vs */158emit.fs = NULL;159draw_impl(ctx, ctx->batch->binning, &emit, index_offset);160161fd_context_all_clean(ctx);162163return true;164}165166void167fd4_draw_init(struct pipe_context *pctx) disable_thread_safety_analysis168{169struct fd_context *ctx = fd_context(pctx);170ctx->draw_vbo = fd4_draw_vbo;171}172173174