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