Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a2xx/fd2_context.c
4574 views
/*1* Copyright (C) 2013 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 "fd2_context.h"27#include "fd2_blend.h"28#include "fd2_draw.h"29#include "fd2_emit.h"30#include "fd2_gmem.h"31#include "fd2_program.h"32#include "fd2_query.h"33#include "fd2_rasterizer.h"34#include "fd2_texture.h"35#include "fd2_zsa.h"3637static void38fd2_context_destroy(struct pipe_context *pctx) in_dt39{40fd_context_destroy(pctx);41free(pctx);42}4344static struct pipe_resource *45create_solid_vertexbuf(struct pipe_context *pctx)46{47/* clang-format off */48static const float init_shader_const[] = {49/* for clear/gmem2mem/mem2gmem (vertices): */50-1.000000, +1.000000, +1.000000,51+1.000000, +1.000000, +1.000000,52-1.000000, -1.000000, +1.000000,53/* for mem2gmem: (tex coords) */54+0.000000, +0.000000,55+1.000000, +0.000000,56+0.000000, +1.000000,57/* SCREEN_SCISSOR_BR value (must be at 60 byte offset in page) */580.0,59/* zero indices dummy draw workaround (3 16-bit zeros) */600.0, 0.0,61};62/* clang-format on */6364struct pipe_resource *prsc =65pipe_buffer_create(pctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE,66sizeof(init_shader_const));67pipe_buffer_write(pctx, prsc, 0, sizeof(init_shader_const),68init_shader_const);69return prsc;70}7172/* clang-format off */73static const uint8_t a22x_primtypes[PIPE_PRIM_MAX] = {74[PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,75[PIPE_PRIM_LINES] = DI_PT_LINELIST,76[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,77[PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,78[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,79[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,80[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,81};8283static const uint8_t a20x_primtypes[PIPE_PRIM_MAX] = {84[PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,85[PIPE_PRIM_LINES] = DI_PT_LINELIST,86[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,87[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,88[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,89[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,90};91/* clang-format on */9293struct pipe_context *94fd2_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)95{96struct fd_screen *screen = fd_screen(pscreen);97struct fd2_context *fd2_ctx = CALLOC_STRUCT(fd2_context);98struct pipe_context *pctx;99100if (!fd2_ctx)101return NULL;102103pctx = &fd2_ctx->base.base;104pctx->screen = pscreen;105106fd2_ctx->base.dev = fd_device_ref(screen->dev);107fd2_ctx->base.screen = fd_screen(pscreen);108109pctx->destroy = fd2_context_destroy;110pctx->create_blend_state = fd2_blend_state_create;111pctx->create_rasterizer_state = fd2_rasterizer_state_create;112pctx->create_depth_stencil_alpha_state = fd2_zsa_state_create;113114fd2_draw_init(pctx);115fd2_gmem_init(pctx);116fd2_texture_init(pctx);117fd2_prog_init(pctx);118fd2_emit_init(pctx);119120pctx = fd_context_init(121&fd2_ctx->base, pscreen,122(screen->gpu_id >= 220) ? a22x_primtypes : a20x_primtypes, priv, flags);123if (!pctx)124return NULL;125126/* construct vertex state used for solid ops (clear, and gmem<->mem) */127fd2_ctx->solid_vertexbuf = create_solid_vertexbuf(pctx);128129fd2_query_context_init(pctx);130131return pctx;132}133134135