1 /*
2 * Copyright © 2013 Rob Clark <[email protected]>
3 * SPDX-License-Identifier: MIT
4 *
5 * Authors:
6 * Rob Clark <[email protected]>
7 */
8
9 #include "freedreno_query_hw.h"
10
11 #include "fd3_blend.h"
12 #include "fd3_context.h"
13 #include "fd3_draw.h"
14 #include "fd3_emit.h"
15 #include "fd3_gmem.h"
16 #include "fd3_program.h"
17 #include "fd3_query.h"
18 #include "fd3_rasterizer.h"
19 #include "fd3_texture.h"
20 #include "fd3_zsa.h"
21
22 static void
fd3_context_destroy(struct pipe_context * pctx)23 fd3_context_destroy(struct pipe_context *pctx) in_dt
24 {
25 struct fd3_context *fd3_ctx = fd3_context(fd_context(pctx));
26
27 u_upload_destroy(fd3_ctx->border_color_uploader);
28 pipe_resource_reference(&fd3_ctx->border_color_buf, NULL);
29
30 fd_context_destroy(pctx);
31
32 fd_bo_del(fd3_ctx->vs_pvt_mem);
33 fd_bo_del(fd3_ctx->fs_pvt_mem);
34 fd_bo_del(fd3_ctx->vsc_size_mem);
35
36 fd_context_cleanup_common_vbos(&fd3_ctx->base);
37
38 fd_hw_query_fini(pctx);
39
40 free(fd3_ctx);
41 }
42
43 struct pipe_context *
fd3_context_create(struct pipe_screen * pscreen,void * priv,unsigned flags)44 fd3_context_create(struct pipe_screen *pscreen, void *priv,
45 unsigned flags) in_dt
46 {
47 struct fd_screen *screen = fd_screen(pscreen);
48 struct fd3_context *fd3_ctx = CALLOC_STRUCT(fd3_context);
49 struct pipe_context *pctx;
50
51 if (!fd3_ctx)
52 return NULL;
53
54 pctx = &fd3_ctx->base.base;
55 pctx->screen = pscreen;
56
57 fd3_ctx->base.flags = flags;
58 fd3_ctx->base.dev = fd_device_ref(screen->dev);
59 fd3_ctx->base.screen = fd_screen(pscreen);
60 fd3_ctx->base.last.key = &fd3_ctx->last_key;
61
62 pctx->destroy = fd3_context_destroy;
63 pctx->create_blend_state = fd3_blend_state_create;
64 pctx->create_rasterizer_state = fd3_rasterizer_state_create;
65 pctx->create_depth_stencil_alpha_state = fd3_zsa_state_create;
66
67 fd3_draw_init(pctx);
68 fd3_gmem_init(pctx);
69 fd3_texture_init(pctx);
70 fd3_prog_init(pctx);
71 fd3_emit_init(pctx);
72
73 pctx = fd_context_init(&fd3_ctx->base, pscreen, priv, flags);
74 if (!pctx)
75 return NULL;
76
77 fd_hw_query_init(pctx);
78
79 fd3_ctx->vs_pvt_mem =
80 fd_bo_new(screen->dev, 0x2000, 0, "vs_pvt");
81
82 fd3_ctx->fs_pvt_mem =
83 fd_bo_new(screen->dev, 0x2000, 0, "fs_pvt");
84
85 fd3_ctx->vsc_size_mem =
86 fd_bo_new(screen->dev, 0x1000, 0, "vsc_size");
87
88 fd_context_setup_common_vbos(&fd3_ctx->base);
89
90 fd3_query_context_init(pctx);
91
92 fd3_ctx->border_color_uploader =
93 u_upload_create(pctx, 4096, 0, PIPE_USAGE_STREAM, 0);
94
95 return pctx;
96 }
97