Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_context.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 "freedreno_query_hw.h"2728#include "fd4_blend.h"29#include "fd4_context.h"30#include "fd4_draw.h"31#include "fd4_emit.h"32#include "fd4_gmem.h"33#include "fd4_program.h"34#include "fd4_query.h"35#include "fd4_rasterizer.h"36#include "fd4_texture.h"37#include "fd4_zsa.h"3839static void40fd4_context_destroy(struct pipe_context *pctx) in_dt41{42struct fd4_context *fd4_ctx = fd4_context(fd_context(pctx));4344u_upload_destroy(fd4_ctx->border_color_uploader);45pipe_resource_reference(&fd4_ctx->border_color_buf, NULL);4647fd_context_destroy(pctx);4849fd_bo_del(fd4_ctx->vs_pvt_mem);50fd_bo_del(fd4_ctx->fs_pvt_mem);51fd_bo_del(fd4_ctx->vsc_size_mem);5253fd_context_cleanup_common_vbos(&fd4_ctx->base);5455fd_hw_query_fini(pctx);5657free(fd4_ctx);58}5960/* clang-format off */61static const uint8_t primtypes[] = {62[PIPE_PRIM_POINTS] = DI_PT_POINTLIST,63[PIPE_PRIM_LINES] = DI_PT_LINELIST,64[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,65[PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,66[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,67[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,68[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,69[PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */70};71/* clang-format on */7273struct pipe_context *74fd4_context_create(struct pipe_screen *pscreen, void *priv,75unsigned flags) in_dt76{77struct fd_screen *screen = fd_screen(pscreen);78struct fd4_context *fd4_ctx = CALLOC_STRUCT(fd4_context);79struct pipe_context *pctx;8081if (!fd4_ctx)82return NULL;8384pctx = &fd4_ctx->base.base;85pctx->screen = pscreen;8687fd4_ctx->base.dev = fd_device_ref(screen->dev);88fd4_ctx->base.screen = fd_screen(pscreen);89fd4_ctx->base.last.key = &fd4_ctx->last_key;9091pctx->destroy = fd4_context_destroy;92pctx->create_blend_state = fd4_blend_state_create;93pctx->create_rasterizer_state = fd4_rasterizer_state_create;94pctx->create_depth_stencil_alpha_state = fd4_zsa_state_create;9596fd4_draw_init(pctx);97fd4_gmem_init(pctx);98fd4_texture_init(pctx);99fd4_prog_init(pctx);100fd4_emit_init(pctx);101102pctx = fd_context_init(&fd4_ctx->base, pscreen, primtypes, priv, flags);103if (!pctx)104return NULL;105106fd_hw_query_init(pctx);107108fd4_ctx->vs_pvt_mem =109fd_bo_new(screen->dev, 0x2000, 0, "vs_pvt");110111fd4_ctx->fs_pvt_mem =112fd_bo_new(screen->dev, 0x2000, 0, "fs_pvt");113114fd4_ctx->vsc_size_mem =115fd_bo_new(screen->dev, 0x1000, 0, "vsc_size");116117fd_context_setup_common_vbos(&fd4_ctx->base);118119fd4_query_context_init(pctx);120121fd4_ctx->border_color_uploader =122u_upload_create(pctx, 4096, 0, PIPE_USAGE_STREAM, 0);123124return pctx;125}126127128