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 /* For ARB_framebuffer_no_attachments: */
94 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
95 retval |= usage & PIPE_BIND_RENDER_TARGET;
96 }
97
98 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
99 (fd5_pipe2depth(format) != (enum a5xx_depth_format) ~0) &&
100 (fd5_pipe2tex(format) != TFMT5_NONE)) {
101 retval |= PIPE_BIND_DEPTH_STENCIL;
102 }
103
104 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
105 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
106 retval |= PIPE_BIND_INDEX_BUFFER;
107 }
108
109 if (retval != usage) {
110 DBG("not supported: format=%s, target=%d, sample_count=%d, "
111 "usage=%x, retval=%x",
112 util_format_name(format), target, sample_count, usage, retval);
113 }
114
115 return retval == usage;
116 }
117
118 /* clang-format off */
119 static const uint8_t primtypes[] = {
120 [PIPE_PRIM_POINTS] = DI_PT_POINTLIST,
121 [PIPE_PRIM_LINES] = DI_PT_LINELIST,
122 [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
123 [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
124 [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
125 [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
126 [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
127 [PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */
128 };
129 /* clang-format on */
130
131 void
fd5_screen_init(struct pipe_screen * pscreen)132 fd5_screen_init(struct pipe_screen *pscreen)
133 {
134 struct fd_screen *screen = fd_screen(pscreen);
135 screen->max_rts = A5XX_MAX_RENDER_TARGETS;
136 pscreen->context_create = fd5_context_create;
137 pscreen->is_format_supported = fd5_screen_is_format_supported;
138
139 screen->setup_slices = fd5_setup_slices;
140 if (FD_DBG(TTILE))
141 screen->tile_mode = fd5_tile_mode;
142
143 fd5_emit_init_screen(pscreen);
144 ir3_screen_init(pscreen);
145
146 screen->primtypes = primtypes;
147 }
148