1 /*
2 * Copyright (C) 2013 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 "fd2_context.h"
31 #include "fd2_emit.h"
32 #include "fd2_resource.h"
33 #include "fd2_screen.h"
34 #include "fd2_util.h"
35
36 static bool
fd2_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)37 fd2_screen_is_format_supported(struct pipe_screen *pscreen,
38 enum pipe_format format,
39 enum pipe_texture_target target,
40 unsigned sample_count,
41 unsigned storage_sample_count, unsigned usage)
42 {
43 unsigned retval = 0;
44
45 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
46 (sample_count > 1)) { /* TODO add MSAA */
47 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
48 util_format_name(format), target, sample_count, usage);
49 return false;
50 }
51
52 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
53 return false;
54
55 if ((usage & PIPE_BIND_RENDER_TARGET) &&
56 fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0) {
57 retval |= PIPE_BIND_RENDER_TARGET;
58 }
59
60 if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_VERTEX_BUFFER)) &&
61 !util_format_is_srgb(format) && !util_format_is_pure_integer(format) &&
62 fd2_pipe2surface(format).format != FMT_INVALID) {
63 retval |= usage & PIPE_BIND_VERTEX_BUFFER;
64 /* the only npot blocksize supported texture format is R32G32B32_FLOAT */
65 if (util_is_power_of_two_or_zero(util_format_get_blocksize(format)) ||
66 format == PIPE_FORMAT_R32G32B32_FLOAT)
67 retval |= usage & PIPE_BIND_SAMPLER_VIEW;
68 }
69
70 if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
71 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) &&
72 (fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0)) {
73 retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
74 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
75 }
76
77 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
78 (fd_pipe2depth(format) != (enum adreno_rb_depth_format) ~0)) {
79 retval |= PIPE_BIND_DEPTH_STENCIL;
80 }
81
82 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
83 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
84 retval |= PIPE_BIND_INDEX_BUFFER;
85 }
86
87 if (retval != usage) {
88 DBG("not supported: format=%s, target=%d, sample_count=%d, "
89 "usage=%x, retval=%x",
90 util_format_name(format), target, sample_count, usage, retval);
91 }
92
93 return retval == usage;
94 }
95
96 /* clang-format off */
97 static const enum pc_di_primtype a22x_primtypes[PIPE_PRIM_MAX] = {
98 [PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,
99 [PIPE_PRIM_LINES] = DI_PT_LINELIST,
100 [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
101 [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
102 [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
103 [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
104 [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
105 };
106
107 static const enum pc_di_primtype a20x_primtypes[PIPE_PRIM_MAX] = {
108 [PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,
109 [PIPE_PRIM_LINES] = DI_PT_LINELIST,
110 [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
111 [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
112 [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
113 [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
114 };
115 /* clang-format on */
116
117 void
fd2_screen_init(struct pipe_screen * pscreen)118 fd2_screen_init(struct pipe_screen *pscreen)
119 {
120 struct fd_screen *screen = fd_screen(pscreen);
121
122 screen->max_rts = 1;
123 pscreen->context_create = fd2_context_create;
124 pscreen->is_format_supported = fd2_screen_is_format_supported;
125
126 screen->setup_slices = fd2_setup_slices;
127 if (FD_DBG(TTILE))
128 screen->tile_mode = fd2_tile_mode;
129
130 fd2_emit_init_screen(pscreen);
131
132 if (screen->gpu_id >= 220) {
133 screen->primtypes = a22x_primtypes;
134 } else {
135 screen->primtypes = a20x_primtypes;
136 }
137 }
138