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 #define FD_BO_NO_HARDPIN 1
29
30 #include "drm-uapi/drm_fourcc.h"
31 #include "pipe/p_screen.h"
32 #include "util/format/u_format.h"
33
34 #include "fd6_blitter.h"
35 #include "fd6_context.h"
36 #include "fd6_emit.h"
37 #include "fd6_resource.h"
38 #include "fd6_screen.h"
39
40 #include "ir3/ir3_compiler.h"
41
42 static bool
valid_sample_count(unsigned sample_count)43 valid_sample_count(unsigned sample_count)
44 {
45 switch (sample_count) {
46 case 0:
47 case 1:
48 case 2:
49 case 4:
50 // TODO seems 8x works, but increases lrz width or height.. but the
51 // blob I have doesn't seem to expose any egl configs w/ 8x, so
52 // just hide it for now and revisit later.
53 // case 8:
54 return true;
55 default:
56 return false;
57 }
58 }
59
60 static bool
fd6_screen_is_format_supported(struct pipe_screen * pscreen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned usage)61 fd6_screen_is_format_supported(struct pipe_screen *pscreen,
62 enum pipe_format format,
63 enum pipe_texture_target target,
64 unsigned sample_count,
65 unsigned storage_sample_count, unsigned usage)
66 {
67 unsigned retval = 0;
68
69 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
70 !valid_sample_count(sample_count)) {
71 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
72 util_format_name(format), target, sample_count, usage);
73 return false;
74 }
75
76 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
77 return false;
78
79 if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
80 (fd6_vertex_format(format) != FMT6_NONE)) {
81 retval |= PIPE_BIND_VERTEX_BUFFER;
82 }
83
84 bool has_color = fd6_color_format(format, TILE6_LINEAR) != FMT6_NONE;
85 bool has_tex = fd6_texture_format(format, TILE6_LINEAR) != FMT6_NONE;
86
87 if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
88 has_tex &&
89 (target == PIPE_BUFFER ||
90 util_is_power_of_two_or_zero(util_format_get_blocksize(format)))) {
91 retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
92 }
93
94 if (usage & PIPE_BIND_SHADER_IMAGE) {
95 if (sample_count > 1)
96 return false;
97 }
98
99 if ((usage &
100 (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
101 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) &&
102 has_color && has_tex) {
103 retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
104 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |
105 PIPE_BIND_COMPUTE_RESOURCE);
106 }
107
108 /* For ARB_framebuffer_no_attachments: */
109 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
110 retval |= usage & PIPE_BIND_RENDER_TARGET;
111 }
112
113 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
114 (fd6_pipe2depth(format) != (enum a6xx_depth_format) ~0) && has_tex) {
115 retval |= PIPE_BIND_DEPTH_STENCIL;
116 }
117
118 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
119 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
120 retval |= PIPE_BIND_INDEX_BUFFER;
121 }
122
123 if ((usage & PIPE_BIND_BLENDABLE) && has_color &&
124 !util_format_is_pure_integer(format)) {
125 retval |= PIPE_BIND_BLENDABLE;
126 }
127
128 if (retval != usage) {
129 DBG("not supported: format=%s, target=%d, sample_count=%d, "
130 "usage=%x, retval=%x",
131 util_format_name(format), target, sample_count, usage, retval);
132 }
133
134 return retval == usage;
135 }
136
137 /* clang-format off */
138 static const enum pc_di_primtype primtypes[] = {
139 [MESA_PRIM_POINTS] = DI_PT_POINTLIST,
140 [MESA_PRIM_LINES] = DI_PT_LINELIST,
141 [MESA_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
142 [MESA_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
143 [MESA_PRIM_TRIANGLES] = DI_PT_TRILIST,
144 [MESA_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
145 [MESA_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
146 [MESA_PRIM_QUADS] = DI_PT_NONE, /* unsupported */
147 [MESA_PRIM_QUAD_STRIP] = DI_PT_NONE, /* unsupported */
148 [MESA_PRIM_POLYGON] = DI_PT_NONE, /* unsupported */
149 [MESA_PRIM_LINES_ADJACENCY] = DI_PT_LINE_ADJ,
150 [MESA_PRIM_LINE_STRIP_ADJACENCY] = DI_PT_LINESTRIP_ADJ,
151 [MESA_PRIM_TRIANGLES_ADJACENCY] = DI_PT_TRI_ADJ,
152 [MESA_PRIM_TRIANGLE_STRIP_ADJACENCY] = DI_PT_TRISTRIP_ADJ,
153 [MESA_PRIM_PATCHES] = DI_PT_PATCHES0,
154 [MESA_PRIM_COUNT] = DI_PT_RECTLIST, /* internal clear blits */
155 };
156 /* clang-format on */
157
158 void
fd6_screen_init(struct pipe_screen * pscreen)159 fd6_screen_init(struct pipe_screen *pscreen)
160 {
161 struct fd_screen *screen = fd_screen(pscreen);
162
163 screen->max_rts = A6XX_MAX_RENDER_TARGETS;
164
165 uint32_t depth_cache_size =
166 screen->info->num_ccu * screen->info->a6xx.sysmem_per_ccu_depth_cache_size;
167 uint32_t color_cache_size =
168 (screen->info->num_ccu * screen->info->a6xx.sysmem_per_ccu_color_cache_size) /
169 (1 << screen->info->a6xx.gmem_ccu_color_cache_fraction);
170
171 screen->ccu_offset_bypass = depth_cache_size;
172 screen->ccu_offset_gmem = screen->gmemsize_bytes - color_cache_size;
173
174 /* Currently only FB_READ forces GMEM path, mostly because we'd have to
175 * deal with cmdstream patching otherwise..
176 */
177 screen->gmem_reason_mask = (enum fd_gmem_reason)(
178 FD_GMEM_CLEARS_DEPTH_STENCIL |
179 FD_GMEM_DEPTH_ENABLED | FD_GMEM_STENCIL_ENABLED |
180 FD_GMEM_BLEND_ENABLED | FD_GMEM_LOGICOP_ENABLED);
181
182 if (screen->gen == 7) {
183 pscreen->context_create = fd6_context_create<A7XX>;
184 } else {
185 pscreen->context_create = fd6_context_create<A6XX>;
186 }
187 pscreen->is_format_supported = fd6_screen_is_format_supported;
188
189 screen->tile_mode = fd6_tile_mode;
190
191 fd6_resource_screen_init(pscreen);
192 fd6_emit_init_screen(pscreen);
193 ir3_screen_init(pscreen);
194
195 screen->primtypes = primtypes;
196 }
197