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