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