freedreno/a6xx: handle non-UWC-compatible image views
[mesa.git] / src / gallium / drivers / freedreno / a6xx / fd6_context.c
1 /*
2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Rob Clark <robclark@freedesktop.org>
26 */
27
28 #include "freedreno_query_acc.h"
29
30 #include "fd6_context.h"
31 #include "fd6_compute.h"
32 #include "fd6_blend.h"
33 #include "fd6_blitter.h"
34 #include "fd6_draw.h"
35 #include "fd6_emit.h"
36 #include "fd6_gmem.h"
37 #include "fd6_image.h"
38 #include "fd6_program.h"
39 #include "fd6_query.h"
40 #include "fd6_rasterizer.h"
41 #include "fd6_texture.h"
42 #include "fd6_zsa.h"
43
44 static void
45 fd6_context_destroy(struct pipe_context *pctx)
46 {
47 struct fd6_context *fd6_ctx = fd6_context(fd_context(pctx));
48
49 u_upload_destroy(fd6_ctx->border_color_uploader);
50
51 fd_context_destroy(pctx);
52
53 fd_bo_del(fd6_ctx->vsc_data);
54 fd_bo_del(fd6_ctx->vsc_data2);
55 fd_bo_del(fd6_ctx->blit_mem);
56
57 fd_context_cleanup_common_vbos(&fd6_ctx->base);
58
59 ir3_cache_destroy(fd6_ctx->shader_cache);
60
61 fd6_texture_fini(pctx);
62
63 free(fd6_ctx);
64 }
65
66 static const uint8_t primtypes[] = {
67 [PIPE_PRIM_POINTS] = DI_PT_POINTLIST,
68 [PIPE_PRIM_LINES] = DI_PT_LINELIST,
69 [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
70 [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
71 [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
72 [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
73 [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
74 [PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */
75 };
76
77 struct pipe_context *
78 fd6_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
79 {
80 struct fd_screen *screen = fd_screen(pscreen);
81 struct fd6_context *fd6_ctx = CALLOC_STRUCT(fd6_context);
82 struct pipe_context *pctx;
83
84 if (!fd6_ctx)
85 return NULL;
86
87 pctx = &fd6_ctx->base.base;
88 pctx->screen = pscreen;
89
90 fd6_ctx->base.dev = fd_device_ref(screen->dev);
91 fd6_ctx->base.screen = fd_screen(pscreen);
92
93 pctx->destroy = fd6_context_destroy;
94 pctx->create_blend_state = fd6_blend_state_create;
95 pctx->create_rasterizer_state = fd6_rasterizer_state_create;
96 pctx->create_depth_stencil_alpha_state = fd6_zsa_state_create;
97
98 fd6_draw_init(pctx);
99 fd6_compute_init(pctx);
100 fd6_gmem_init(pctx);
101 fd6_texture_init(pctx);
102 fd6_prog_init(pctx);
103 fd6_emit_init(pctx);
104
105 pctx = fd_context_init(&fd6_ctx->base, pscreen, primtypes, priv, flags);
106 if (!pctx)
107 return NULL;
108
109 /* after fd_context_init() to override set_shader_images() */
110 fd6_image_init(pctx);
111
112 util_blitter_set_texture_multisample(fd6_ctx->base.blitter, true);
113
114 /* fd_context_init overwrites delete_rasterizer_state, so set this
115 * here. */
116 pctx->delete_rasterizer_state = fd6_rasterizer_state_delete;
117 pctx->delete_depth_stencil_alpha_state = fd6_depth_stencil_alpha_state_delete;
118
119 fd6_ctx->vsc_data = fd_bo_new(screen->dev,
120 (A6XX_VSC_DATA_PITCH * 32) + 0x100,
121 DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_data");
122
123 fd6_ctx->vsc_data2 = fd_bo_new(screen->dev,
124 A6XX_VSC_DATA2_PITCH * 32,
125 DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_data2");
126
127 fd6_ctx->blit_mem = fd_bo_new(screen->dev, 0x1000,
128 DRM_FREEDRENO_GEM_TYPE_KMEM, "blit");
129
130 fd_context_setup_common_vbos(&fd6_ctx->base);
131
132 fd6_query_context_init(pctx);
133 fd6_blitter_init(pctx);
134
135 fd6_ctx->border_color_uploader = u_upload_create(pctx, 4096, 0,
136 PIPE_USAGE_STREAM, 0);
137
138 return pctx;
139 }