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 "freedreno_query_hw.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "fd3_blend.h"
30bf215546Sopenharmony_ci#include "fd3_context.h"
31bf215546Sopenharmony_ci#include "fd3_draw.h"
32bf215546Sopenharmony_ci#include "fd3_emit.h"
33bf215546Sopenharmony_ci#include "fd3_gmem.h"
34bf215546Sopenharmony_ci#include "fd3_program.h"
35bf215546Sopenharmony_ci#include "fd3_query.h"
36bf215546Sopenharmony_ci#include "fd3_rasterizer.h"
37bf215546Sopenharmony_ci#include "fd3_texture.h"
38bf215546Sopenharmony_ci#include "fd3_zsa.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistatic void
41bf215546Sopenharmony_cifd3_context_destroy(struct pipe_context *pctx) in_dt
42bf215546Sopenharmony_ci{
43bf215546Sopenharmony_ci   struct fd3_context *fd3_ctx = fd3_context(fd_context(pctx));
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   u_upload_destroy(fd3_ctx->border_color_uploader);
46bf215546Sopenharmony_ci   pipe_resource_reference(&fd3_ctx->border_color_buf, NULL);
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   fd_context_destroy(pctx);
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   fd_bo_del(fd3_ctx->vs_pvt_mem);
51bf215546Sopenharmony_ci   fd_bo_del(fd3_ctx->fs_pvt_mem);
52bf215546Sopenharmony_ci   fd_bo_del(fd3_ctx->vsc_size_mem);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci   fd_context_cleanup_common_vbos(&fd3_ctx->base);
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   fd_hw_query_fini(pctx);
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   free(fd3_ctx);
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistruct pipe_context *
62bf215546Sopenharmony_cifd3_context_create(struct pipe_screen *pscreen, void *priv,
63bf215546Sopenharmony_ci                   unsigned flags) in_dt
64bf215546Sopenharmony_ci{
65bf215546Sopenharmony_ci   struct fd_screen *screen = fd_screen(pscreen);
66bf215546Sopenharmony_ci   struct fd3_context *fd3_ctx = CALLOC_STRUCT(fd3_context);
67bf215546Sopenharmony_ci   struct pipe_context *pctx;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci   if (!fd3_ctx)
70bf215546Sopenharmony_ci      return NULL;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   pctx = &fd3_ctx->base.base;
73bf215546Sopenharmony_ci   pctx->screen = pscreen;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   fd3_ctx->base.flags = flags;
76bf215546Sopenharmony_ci   fd3_ctx->base.dev = fd_device_ref(screen->dev);
77bf215546Sopenharmony_ci   fd3_ctx->base.screen = fd_screen(pscreen);
78bf215546Sopenharmony_ci   fd3_ctx->base.last.key = &fd3_ctx->last_key;
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci   pctx->destroy = fd3_context_destroy;
81bf215546Sopenharmony_ci   pctx->create_blend_state = fd3_blend_state_create;
82bf215546Sopenharmony_ci   pctx->create_rasterizer_state = fd3_rasterizer_state_create;
83bf215546Sopenharmony_ci   pctx->create_depth_stencil_alpha_state = fd3_zsa_state_create;
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci   fd3_draw_init(pctx);
86bf215546Sopenharmony_ci   fd3_gmem_init(pctx);
87bf215546Sopenharmony_ci   fd3_texture_init(pctx);
88bf215546Sopenharmony_ci   fd3_prog_init(pctx);
89bf215546Sopenharmony_ci   fd3_emit_init(pctx);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci   pctx = fd_context_init(&fd3_ctx->base, pscreen, priv, flags);
92bf215546Sopenharmony_ci   if (!pctx)
93bf215546Sopenharmony_ci      return NULL;
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   fd_hw_query_init(pctx);
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   fd3_ctx->vs_pvt_mem =
98bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x2000, 0, "vs_pvt");
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci   fd3_ctx->fs_pvt_mem =
101bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x2000, 0, "fs_pvt");
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   fd3_ctx->vsc_size_mem =
104bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x1000, 0, "vsc_size");
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci   fd_context_setup_common_vbos(&fd3_ctx->base);
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   fd3_query_context_init(pctx);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   fd3_ctx->border_color_uploader =
111bf215546Sopenharmony_ci      u_upload_create(pctx, 4096, 0, PIPE_USAGE_STREAM, 0);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   return pctx;
114bf215546Sopenharmony_ci}
115