Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_context.c
4574 views
/*1* Copyright (C) 2016 Rob Clark <[email protected]>2* Copyright © 2018 Google, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* 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 THE21* SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25*/2627#include "freedreno_query_acc.h"28#include "freedreno_state.h"2930#include "fd6_blend.h"31#include "fd6_blitter.h"32#include "fd6_compute.h"33#include "fd6_context.h"34#include "fd6_draw.h"35#include "fd6_emit.h"36#include "fd6_gmem.h"37#include "fd6_image.h"38#include "fd6_program.h"39#include "fd6_query.h"40#include "fd6_rasterizer.h"41#include "fd6_resource.h"42#include "fd6_texture.h"43#include "fd6_zsa.h"4445static void46fd6_context_destroy(struct pipe_context *pctx) in_dt47{48struct fd6_context *fd6_ctx = fd6_context(fd_context(pctx));4950u_upload_destroy(fd6_ctx->border_color_uploader);51pipe_resource_reference(&fd6_ctx->border_color_buf, NULL);5253fd_context_destroy(pctx);5455if (fd6_ctx->vsc_draw_strm)56fd_bo_del(fd6_ctx->vsc_draw_strm);57if (fd6_ctx->vsc_prim_strm)58fd_bo_del(fd6_ctx->vsc_prim_strm);59fd_bo_del(fd6_ctx->control_mem);6061fd_context_cleanup_common_vbos(&fd6_ctx->base);6263fd6_texture_fini(pctx);6465free(fd6_ctx);66}6768/* clang-format off */69static const uint8_t primtypes[] = {70[PIPE_PRIM_POINTS] = DI_PT_POINTLIST,71[PIPE_PRIM_LINES] = DI_PT_LINELIST,72[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,73[PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,74[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,75[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,76[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,77[PIPE_PRIM_LINES_ADJACENCY] = DI_PT_LINE_ADJ,78[PIPE_PRIM_LINE_STRIP_ADJACENCY] = DI_PT_LINESTRIP_ADJ,79[PIPE_PRIM_TRIANGLES_ADJACENCY] = DI_PT_TRI_ADJ,80[PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = DI_PT_TRISTRIP_ADJ,81[PIPE_PRIM_PATCHES] = DI_PT_PATCHES0,82[PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */83};84/* clang-format on */8586static void *87fd6_vertex_state_create(struct pipe_context *pctx, unsigned num_elements,88const struct pipe_vertex_element *elements)89{90struct fd_context *ctx = fd_context(pctx);9192struct fd6_vertex_stateobj *state = CALLOC_STRUCT(fd6_vertex_stateobj);93memcpy(state->base.pipe, elements, sizeof(*elements) * num_elements);94state->base.num_elements = num_elements;95state->stateobj =96fd_ringbuffer_new_object(ctx->pipe, 4 * (num_elements * 2 + 1));97struct fd_ringbuffer *ring = state->stateobj;9899OUT_PKT4(ring, REG_A6XX_VFD_DECODE(0), 2 * num_elements);100for (int32_t i = 0; i < num_elements; i++) {101const struct pipe_vertex_element *elem = &elements[i];102enum pipe_format pfmt = elem->src_format;103enum a6xx_format fmt = fd6_pipe2vtx(pfmt);104bool isint = util_format_is_pure_integer(pfmt);105debug_assert(fmt != FMT6_NONE);106107OUT_RING(ring, A6XX_VFD_DECODE_INSTR_IDX(elem->vertex_buffer_index) |108A6XX_VFD_DECODE_INSTR_OFFSET(elem->src_offset) |109A6XX_VFD_DECODE_INSTR_FORMAT(fmt) |110COND(elem->instance_divisor,111A6XX_VFD_DECODE_INSTR_INSTANCED) |112A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt)) |113A6XX_VFD_DECODE_INSTR_UNK30 |114COND(!isint, A6XX_VFD_DECODE_INSTR_FLOAT));115OUT_RING(ring,116MAX2(1, elem->instance_divisor)); /* VFD_DECODE[j].STEP_RATE */117}118119return state;120}121122static void123fd6_vertex_state_delete(struct pipe_context *pctx, void *hwcso)124{125struct fd6_vertex_stateobj *so = hwcso;126127fd_ringbuffer_del(so->stateobj);128FREE(hwcso);129}130131static void132validate_surface(struct pipe_context *pctx, struct pipe_surface *psurf)133assert_dt134{135fd6_validate_format(fd_context(pctx), fd_resource(psurf->texture),136psurf->format);137}138139static void140fd6_set_framebuffer_state(struct pipe_context *pctx,141const struct pipe_framebuffer_state *pfb)142in_dt143{144if (pfb->zsbuf)145validate_surface(pctx, pfb->zsbuf);146147for (unsigned i = 0; i < pfb->nr_cbufs; i++) {148if (!pfb->cbufs[i])149continue;150validate_surface(pctx, pfb->cbufs[i]);151}152153fd_set_framebuffer_state(pctx, pfb);154}155156157static void158setup_state_map(struct fd_context *ctx)159{160STATIC_ASSERT(FD6_GROUP_NON_GROUP < 32);161162fd_context_add_map(ctx, FD_DIRTY_VTXSTATE, BIT(FD6_GROUP_VTXSTATE));163fd_context_add_map(ctx, FD_DIRTY_VTXBUF, BIT(FD6_GROUP_VBO));164fd_context_add_map(ctx, FD_DIRTY_ZSA | FD_DIRTY_RASTERIZER,165BIT(FD6_GROUP_ZSA));166fd_context_add_map(ctx, FD_DIRTY_ZSA | FD_DIRTY_BLEND | FD_DIRTY_PROG,167BIT(FD6_GROUP_LRZ) | BIT(FD6_GROUP_LRZ_BINNING));168fd_context_add_map(ctx, FD_DIRTY_PROG, BIT(FD6_GROUP_PROG));169fd_context_add_map(ctx, FD_DIRTY_RASTERIZER, BIT(FD6_GROUP_RASTERIZER));170fd_context_add_map(ctx,171FD_DIRTY_FRAMEBUFFER | FD_DIRTY_RASTERIZER_DISCARD |172FD_DIRTY_PROG | FD_DIRTY_BLEND_DUAL,173BIT(FD6_GROUP_PROG_FB_RAST));174fd_context_add_map(ctx, FD_DIRTY_BLEND | FD_DIRTY_SAMPLE_MASK,175BIT(FD6_GROUP_BLEND));176fd_context_add_map(ctx, FD_DIRTY_BLEND_COLOR, BIT(FD6_GROUP_BLEND_COLOR));177fd_context_add_map(ctx, FD_DIRTY_SSBO | FD_DIRTY_IMAGE | FD_DIRTY_PROG,178BIT(FD6_GROUP_IBO));179fd_context_add_map(ctx, FD_DIRTY_PROG,180BIT(FD6_GROUP_VS_TEX) | BIT(FD6_GROUP_HS_TEX) |181BIT(FD6_GROUP_DS_TEX) | BIT(FD6_GROUP_GS_TEX) |182BIT(FD6_GROUP_FS_TEX));183fd_context_add_map(ctx, FD_DIRTY_PROG | FD_DIRTY_CONST,184BIT(FD6_GROUP_CONST));185fd_context_add_map(ctx, FD_DIRTY_STREAMOUT, BIT(FD6_GROUP_SO));186187fd_context_add_shader_map(ctx, PIPE_SHADER_VERTEX, FD_DIRTY_SHADER_TEX,188BIT(FD6_GROUP_VS_TEX));189fd_context_add_shader_map(ctx, PIPE_SHADER_TESS_CTRL, FD_DIRTY_SHADER_TEX,190BIT(FD6_GROUP_HS_TEX));191fd_context_add_shader_map(ctx, PIPE_SHADER_TESS_EVAL, FD_DIRTY_SHADER_TEX,192BIT(FD6_GROUP_DS_TEX));193fd_context_add_shader_map(ctx, PIPE_SHADER_GEOMETRY, FD_DIRTY_SHADER_TEX,194BIT(FD6_GROUP_GS_TEX));195fd_context_add_shader_map(ctx, PIPE_SHADER_FRAGMENT, FD_DIRTY_SHADER_TEX,196BIT(FD6_GROUP_FS_TEX));197198/* NOTE: scissor enabled bit is part of rasterizer state, but199* fd_rasterizer_state_bind() will mark scissor dirty if needed:200*/201fd_context_add_map(ctx, FD_DIRTY_SCISSOR, BIT(FD6_GROUP_SCISSOR));202203/* Stuff still emit in IB2204*205* NOTE: viewport state doesn't seem to change frequently, so possibly206* move it into FD6_GROUP_RASTERIZER?207*/208fd_context_add_map(209ctx, FD_DIRTY_STENCIL_REF | FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER,210BIT(FD6_GROUP_NON_GROUP));211}212213struct pipe_context *214fd6_context_create(struct pipe_screen *pscreen, void *priv,215unsigned flags) disable_thread_safety_analysis216{217struct fd_screen *screen = fd_screen(pscreen);218struct fd6_context *fd6_ctx = CALLOC_STRUCT(fd6_context);219struct pipe_context *pctx;220221if (!fd6_ctx)222return NULL;223224pctx = &fd6_ctx->base.base;225pctx->screen = pscreen;226227fd6_ctx->base.dev = fd_device_ref(screen->dev);228fd6_ctx->base.screen = fd_screen(pscreen);229fd6_ctx->base.last.key = &fd6_ctx->last_key;230231pctx->destroy = fd6_context_destroy;232pctx->create_blend_state = fd6_blend_state_create;233pctx->create_rasterizer_state = fd6_rasterizer_state_create;234pctx->create_depth_stencil_alpha_state = fd6_zsa_state_create;235pctx->create_vertex_elements_state = fd6_vertex_state_create;236237fd6_draw_init(pctx);238fd6_compute_init(pctx);239fd6_gmem_init(pctx);240fd6_texture_init(pctx);241fd6_prog_init(pctx);242fd6_emit_init(pctx);243fd6_query_context_init(pctx);244245setup_state_map(&fd6_ctx->base);246247pctx = fd_context_init(&fd6_ctx->base, pscreen, primtypes, priv, flags);248if (!pctx)249return NULL;250251pctx->set_framebuffer_state = fd6_set_framebuffer_state;252253/* after fd_context_init() to override set_shader_images() */254fd6_image_init(pctx);255256util_blitter_set_texture_multisample(fd6_ctx->base.blitter, true);257258pctx->delete_vertex_elements_state = fd6_vertex_state_delete;259260/* fd_context_init overwrites delete_rasterizer_state, so set this261* here. */262pctx->delete_rasterizer_state = fd6_rasterizer_state_delete;263pctx->delete_blend_state = fd6_blend_state_delete;264pctx->delete_depth_stencil_alpha_state = fd6_zsa_state_delete;265266/* initial sizes for VSC buffers (or rather the per-pipe sizes267* which is used to derive entire buffer size:268*/269fd6_ctx->vsc_draw_strm_pitch = 0x440;270fd6_ctx->vsc_prim_strm_pitch = 0x1040;271272fd6_ctx->control_mem =273fd_bo_new(screen->dev, 0x1000, 0, "control");274275memset(fd_bo_map(fd6_ctx->control_mem), 0, sizeof(struct fd6_control));276277fd_context_setup_common_vbos(&fd6_ctx->base);278279fd6_blitter_init(pctx);280281fd6_ctx->border_color_uploader =282u_upload_create(pctx, 4096, 0, PIPE_USAGE_STREAM, 0);283284return fd_context_init_tc(pctx, flags);285}286287288