1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "fd2_context.h" 28bf215546Sopenharmony_ci#include "fd2_blend.h" 29bf215546Sopenharmony_ci#include "fd2_draw.h" 30bf215546Sopenharmony_ci#include "fd2_emit.h" 31bf215546Sopenharmony_ci#include "fd2_gmem.h" 32bf215546Sopenharmony_ci#include "fd2_program.h" 33bf215546Sopenharmony_ci#include "fd2_query.h" 34bf215546Sopenharmony_ci#include "fd2_rasterizer.h" 35bf215546Sopenharmony_ci#include "fd2_texture.h" 36bf215546Sopenharmony_ci#include "fd2_zsa.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_cistatic void 39bf215546Sopenharmony_cifd2_context_destroy(struct pipe_context *pctx) in_dt 40bf215546Sopenharmony_ci{ 41bf215546Sopenharmony_ci fd_context_destroy(pctx); 42bf215546Sopenharmony_ci free(pctx); 43bf215546Sopenharmony_ci} 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_cistatic struct pipe_resource * 46bf215546Sopenharmony_cicreate_solid_vertexbuf(struct pipe_context *pctx) 47bf215546Sopenharmony_ci{ 48bf215546Sopenharmony_ci /* clang-format off */ 49bf215546Sopenharmony_ci static const float init_shader_const[] = { 50bf215546Sopenharmony_ci /* for clear/gmem2mem/mem2gmem (vertices): */ 51bf215546Sopenharmony_ci -1.000000f, +1.000000f, +1.000000f, 52bf215546Sopenharmony_ci +1.000000f, +1.000000f, +1.000000f, 53bf215546Sopenharmony_ci -1.000000f, -1.000000f, +1.000000f, 54bf215546Sopenharmony_ci /* for mem2gmem: (tex coords) */ 55bf215546Sopenharmony_ci +0.000000f, +0.000000f, 56bf215546Sopenharmony_ci +1.000000f, +0.000000f, 57bf215546Sopenharmony_ci +0.000000f, +1.000000f, 58bf215546Sopenharmony_ci /* SCREEN_SCISSOR_BR value (must be at 60 byte offset in page) */ 59bf215546Sopenharmony_ci 0.0f, 60bf215546Sopenharmony_ci /* zero indices dummy draw workaround (3 16-bit zeros) */ 61bf215546Sopenharmony_ci 0.0f, 0.0f, 62bf215546Sopenharmony_ci }; 63bf215546Sopenharmony_ci /* clang-format on */ 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci struct pipe_resource *prsc = 66bf215546Sopenharmony_ci pipe_buffer_create(pctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, 67bf215546Sopenharmony_ci sizeof(init_shader_const)); 68bf215546Sopenharmony_ci pipe_buffer_write(pctx, prsc, 0, sizeof(init_shader_const), 69bf215546Sopenharmony_ci init_shader_const); 70bf215546Sopenharmony_ci return prsc; 71bf215546Sopenharmony_ci} 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_cistruct pipe_context * 74bf215546Sopenharmony_cifd2_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) 75bf215546Sopenharmony_ci{ 76bf215546Sopenharmony_ci struct fd_screen *screen = fd_screen(pscreen); 77bf215546Sopenharmony_ci struct fd2_context *fd2_ctx = CALLOC_STRUCT(fd2_context); 78bf215546Sopenharmony_ci struct pipe_context *pctx; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci if (!fd2_ctx) 81bf215546Sopenharmony_ci return NULL; 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci pctx = &fd2_ctx->base.base; 84bf215546Sopenharmony_ci pctx->screen = pscreen; 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci fd2_ctx->base.flags = flags; 87bf215546Sopenharmony_ci fd2_ctx->base.dev = fd_device_ref(screen->dev); 88bf215546Sopenharmony_ci fd2_ctx->base.screen = fd_screen(pscreen); 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci pctx->destroy = fd2_context_destroy; 91bf215546Sopenharmony_ci pctx->create_blend_state = fd2_blend_state_create; 92bf215546Sopenharmony_ci pctx->create_rasterizer_state = fd2_rasterizer_state_create; 93bf215546Sopenharmony_ci pctx->create_depth_stencil_alpha_state = fd2_zsa_state_create; 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci fd2_draw_init(pctx); 96bf215546Sopenharmony_ci fd2_gmem_init(pctx); 97bf215546Sopenharmony_ci fd2_texture_init(pctx); 98bf215546Sopenharmony_ci fd2_prog_init(pctx); 99bf215546Sopenharmony_ci fd2_emit_init(pctx); 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci pctx = fd_context_init(&fd2_ctx->base, pscreen, priv, flags); 102bf215546Sopenharmony_ci if (!pctx) 103bf215546Sopenharmony_ci return NULL; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci /* construct vertex state used for solid ops (clear, and gmem<->mem) */ 106bf215546Sopenharmony_ci fd2_ctx->solid_vertexbuf = create_solid_vertexbuf(pctx); 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci fd2_query_context_init(pctx); 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci return pctx; 111bf215546Sopenharmony_ci} 112