1 /*
2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #include "pipe/p_screen.h"
28 #include "util/format/u_format.h"
29
30 #include "fd5_blitter.h"
31 #include "fd5_context.h"
32 #include "fd5_emit.h"
33 #include "fd5_format.h"
34 #include "fd5_resource.h"
35 #include "fd5_screen.h"
36
37 #include "ir3/ir3_compiler.h"
38
39 static bool
valid_sample_count(unsigned sample_count)40 valid_sample_count(unsigned sample_count)
41 {
42 switch (sample_count) {
43 case 0:
44 case 1:
45 case 2:
46 case 4:
47 return true;
48 default:
49 return false;
50 }
51 }
52
53 static bool
fd5_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)54 fd5_screen_is_format_supported(struct pipe_screen *pscreen,
55 enum pipe_format format,
56 enum pipe_texture_target target,
57 unsigned sample_count,
58 unsigned storage_sample_count, unsigned usage)
59 {
60 unsigned retval = 0;
61
62 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
63 !valid_sample_count(sample_count)) {
64 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
65 util_format_name(format), target, sample_count, usage);
66 return false;
67 }
68
69 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
70 return false;
71
72 if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
73 (fd5_pipe2vtx(format) != VFMT5_NONE)) {
74 retval |= PIPE_BIND_VERTEX_BUFFER;
75 }
76
77 if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
78 (fd5_pipe2tex(format) != TFMT5_NONE) &&
79 (target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {
80 retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
81 }
82
83 if ((usage &
84 (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
85 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) &&
86 (fd5_pipe2color(format) != RB5_NONE) &&
87 (fd5_pipe2tex(format) != TFMT5_NONE)) {
88 retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
89 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |
90 PIPE_BIND_COMPUTE_RESOURCE);
91 }
92
93 if (usage & PIPE_BIND_SHADER_IMAGE) {
94 if (sample_count > 1)
95 return false;
96 }
97
98 /* For ARB_framebuffer_no_attachments: */
99 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
100 retval |= usage & PIPE_BIND_RENDER_TARGET;
101 }
102
103 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
104 (fd5_pipe2depth(format) != (enum a5xx_depth_format) ~0) &&
105 (fd5_pipe2tex(format) != TFMT5_NONE)) {
106 retval |= PIPE_BIND_DEPTH_STENCIL;
107 }
108
109 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
110 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
111 retval |= PIPE_BIND_INDEX_BUFFER;
112 }
113
114 if (retval != usage) {
115 DBG("not supported: format=%s, target=%d, sample_count=%d, "
116 "usage=%x, retval=%x",
117 util_format_name(format), target, sample_count, usage, retval);
118 }
119
120 return retval == usage;
121 }
122
123 /* clang-format off */
124 static const enum pc_di_primtype primtypes[] = {
125 [PIPE_PRIM_POINTS] = DI_PT_POINTLIST,
126 [PIPE_PRIM_LINES] = DI_PT_LINELIST,
127 [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
128 [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
129 [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
130 [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
131 [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
132 [PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */
133 };
134 /* clang-format on */
135
136 void
fd5_screen_init(struct pipe_screen * pscreen)137 fd5_screen_init(struct pipe_screen *pscreen)
138 {
139 struct fd_screen *screen = fd_screen(pscreen);
140 screen->max_rts = A5XX_MAX_RENDER_TARGETS;
141 pscreen->context_create = fd5_context_create;
142 pscreen->is_format_supported = fd5_screen_is_format_supported;
143
144 screen->setup_slices = fd5_setup_slices;
145 if (FD_DBG(TTILE))
146 screen->tile_mode = fd5_tile_mode;
147
148 fd5_emit_init_screen(pscreen);
149 ir3_screen_init(pscreen);
150
151 screen->primtypes = primtypes;
152 }
153