freedreno/a5xx: MSAA
[mesa.git] / src / gallium / drivers / freedreno / a5xx / fd5_screen.c
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/u_format.h"
29
30 #include "fd5_screen.h"
31 #include "fd5_blitter.h"
32 #include "fd5_context.h"
33 #include "fd5_format.h"
34 #include "fd5_resource.h"
35
36 #include "ir3_compiler.h"
37
38 static bool
39 valid_sample_count(unsigned sample_count)
40 {
41 switch (sample_count) {
42 case 0:
43 case 1:
44 case 2:
45 case 4:
46 return true;
47 default:
48 return false;
49 }
50 }
51
52 static boolean
53 fd5_screen_is_format_supported(struct pipe_screen *pscreen,
54 enum pipe_format format,
55 enum pipe_texture_target target,
56 unsigned sample_count,
57 unsigned usage)
58 {
59 unsigned retval = 0;
60
61 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
62 !valid_sample_count(sample_count) ||
63 !util_format_is_supported(format, usage)) {
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 ((usage & PIPE_BIND_VERTEX_BUFFER) &&
70 (fd5_pipe2vtx(format) != (enum a5xx_vtx_fmt)~0)) {
71 retval |= PIPE_BIND_VERTEX_BUFFER;
72 }
73
74 if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
75 (target == PIPE_BUFFER ||
76 util_format_get_blocksize(format) != 12) &&
77 (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
78 retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
79 }
80
81 if ((usage & (PIPE_BIND_RENDER_TARGET |
82 PIPE_BIND_DISPLAY_TARGET |
83 PIPE_BIND_SCANOUT |
84 PIPE_BIND_SHARED |
85 PIPE_BIND_COMPUTE_RESOURCE)) &&
86 (fd5_pipe2color(format) != (enum a5xx_color_fmt)~0) &&
87 (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
88 retval |= usage & (PIPE_BIND_RENDER_TARGET |
89 PIPE_BIND_DISPLAY_TARGET |
90 PIPE_BIND_SCANOUT |
91 PIPE_BIND_SHARED |
92 PIPE_BIND_COMPUTE_RESOURCE);
93 }
94
95 /* For ARB_framebuffer_no_attachments: */
96 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
97 retval |= usage & PIPE_BIND_RENDER_TARGET;
98 }
99
100 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
101 (fd5_pipe2depth(format) != (enum a5xx_depth_format)~0) &&
102 (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
103 retval |= PIPE_BIND_DEPTH_STENCIL;
104 }
105
106 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
107 (fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
108 retval |= PIPE_BIND_INDEX_BUFFER;
109 }
110
111 if (retval != usage) {
112 DBG("not supported: format=%s, target=%d, sample_count=%d, "
113 "usage=%x, retval=%x", util_format_name(format),
114 target, sample_count, usage, retval);
115 }
116
117 return retval == usage;
118 }
119
120 void
121 fd5_screen_init(struct pipe_screen *pscreen)
122 {
123 struct fd_screen *screen = fd_screen(pscreen);
124 screen->max_rts = A5XX_MAX_RENDER_TARGETS;
125 screen->compiler = ir3_compiler_create(screen->dev, screen->gpu_id);
126 pscreen->context_create = fd5_context_create;
127 pscreen->is_format_supported = fd5_screen_is_format_supported;
128
129 screen->setup_slices = fd5_setup_slices;
130 if (fd_mesa_debug & FD_DBG_TTILE)
131 screen->tile_mode = fd5_tile_mode;
132 }