1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2014 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 "fd4_blend.h"
30bf215546Sopenharmony_ci#include "fd4_compute.h"
31bf215546Sopenharmony_ci#include "fd4_context.h"
32bf215546Sopenharmony_ci#include "fd4_draw.h"
33bf215546Sopenharmony_ci#include "fd4_emit.h"
34bf215546Sopenharmony_ci#include "fd4_gmem.h"
35bf215546Sopenharmony_ci#include "fd4_program.h"
36bf215546Sopenharmony_ci#include "fd4_query.h"
37bf215546Sopenharmony_ci#include "fd4_rasterizer.h"
38bf215546Sopenharmony_ci#include "fd4_texture.h"
39bf215546Sopenharmony_ci#include "fd4_zsa.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_cistatic void
42bf215546Sopenharmony_cifd4_context_destroy(struct pipe_context *pctx) in_dt
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci   struct fd4_context *fd4_ctx = fd4_context(fd_context(pctx));
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   u_upload_destroy(fd4_ctx->border_color_uploader);
47bf215546Sopenharmony_ci   pipe_resource_reference(&fd4_ctx->border_color_buf, NULL);
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   fd_context_destroy(pctx);
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   fd_bo_del(fd4_ctx->vs_pvt_mem);
52bf215546Sopenharmony_ci   fd_bo_del(fd4_ctx->fs_pvt_mem);
53bf215546Sopenharmony_ci   fd_bo_del(fd4_ctx->vsc_size_mem);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   fd_context_cleanup_common_vbos(&fd4_ctx->base);
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   fd_hw_query_fini(pctx);
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   free(fd4_ctx);
60bf215546Sopenharmony_ci}
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_cistruct pipe_context *
63bf215546Sopenharmony_cifd4_context_create(struct pipe_screen *pscreen, void *priv,
64bf215546Sopenharmony_ci                   unsigned flags) in_dt
65bf215546Sopenharmony_ci{
66bf215546Sopenharmony_ci   struct fd_screen *screen = fd_screen(pscreen);
67bf215546Sopenharmony_ci   struct fd4_context *fd4_ctx = CALLOC_STRUCT(fd4_context);
68bf215546Sopenharmony_ci   struct pipe_context *pctx;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   if (!fd4_ctx)
71bf215546Sopenharmony_ci      return NULL;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   pctx = &fd4_ctx->base.base;
74bf215546Sopenharmony_ci   pctx->screen = pscreen;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   fd4_ctx->base.flags = flags;
77bf215546Sopenharmony_ci   fd4_ctx->base.dev = fd_device_ref(screen->dev);
78bf215546Sopenharmony_ci   fd4_ctx->base.screen = fd_screen(pscreen);
79bf215546Sopenharmony_ci   fd4_ctx->base.last.key = &fd4_ctx->last_key;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   pctx->destroy = fd4_context_destroy;
82bf215546Sopenharmony_ci   pctx->create_blend_state = fd4_blend_state_create;
83bf215546Sopenharmony_ci   pctx->create_rasterizer_state = fd4_rasterizer_state_create;
84bf215546Sopenharmony_ci   pctx->create_depth_stencil_alpha_state = fd4_zsa_state_create;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   fd4_draw_init(pctx);
87bf215546Sopenharmony_ci   fd4_compute_init(pctx);
88bf215546Sopenharmony_ci   fd4_gmem_init(pctx);
89bf215546Sopenharmony_ci   fd4_texture_init(pctx);
90bf215546Sopenharmony_ci   fd4_prog_init(pctx);
91bf215546Sopenharmony_ci   fd4_emit_init(pctx);
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   pctx = fd_context_init(&fd4_ctx->base, pscreen, priv, flags);
94bf215546Sopenharmony_ci   if (!pctx)
95bf215546Sopenharmony_ci      return NULL;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   fd_hw_query_init(pctx);
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   fd4_ctx->vs_pvt_mem =
100bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x2000, 0, "vs_pvt");
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   fd4_ctx->fs_pvt_mem =
103bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x2000, 0, "fs_pvt");
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci   fd4_ctx->vsc_size_mem =
106bf215546Sopenharmony_ci      fd_bo_new(screen->dev, 0x1000, 0, "vsc_size");
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   fd_context_setup_common_vbos(&fd4_ctx->base);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   fd4_query_context_init(pctx);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   fd4_ctx->border_color_uploader =
113bf215546Sopenharmony_ci      u_upload_create(pctx, 4096, 0, PIPE_USAGE_STREAM, 0);
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   for (int i = 0; i < 16; i++) {
116bf215546Sopenharmony_ci      fd4_ctx->vsampler_swizzles[i] = 0x688;
117bf215546Sopenharmony_ci      fd4_ctx->fsampler_swizzles[i] = 0x688;
118bf215546Sopenharmony_ci      fd4_ctx->csampler_swizzles[i] = 0x688;
119bf215546Sopenharmony_ci   }
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   return pctx;
122bf215546Sopenharmony_ci}
123