freedreno/a6xx: Move blit check so as to restore comment
[mesa.git] / src / gallium / drivers / freedreno / a6xx / fd6_screen.c
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 "pipe/p_screen.h"
29 #include "util/u_format.h"
30
31 #include "fd6_screen.h"
32 #include "fd6_blitter.h"
33 #include "fd6_context.h"
34 #include "fd6_format.h"
35 #include "fd6_resource.h"
36
37 #include "ir3/ir3_compiler.h"
38
39 static bool
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 // TODO seems 8x works, but increases lrz width or height.. but the
48 // blob I have doesn't seem to expose any egl configs w/ 8x, so
49 // just hide it for now and revisit later.
50 // case 8:
51 return true;
52 default:
53 return false;
54 }
55 }
56
57 static boolean
58 fd6_screen_is_format_supported(struct pipe_screen *pscreen,
59 enum pipe_format format,
60 enum pipe_texture_target target,
61 unsigned sample_count,
62 unsigned storage_sample_count,
63 unsigned usage)
64 {
65 unsigned retval = 0;
66
67 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
68 !valid_sample_count(sample_count)) {
69 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
70 util_format_name(format), target, sample_count, usage);
71 return FALSE;
72 }
73
74 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
75 return false;
76
77 if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
78 (fd6_pipe2vtx(format) != (enum a6xx_vtx_fmt)~0)) {
79 retval |= PIPE_BIND_VERTEX_BUFFER;
80 }
81
82 if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
83 (target == PIPE_BUFFER ||
84 util_format_get_blocksize(format) != 12) &&
85 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
86 retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
87 }
88
89 if ((usage & (PIPE_BIND_RENDER_TARGET |
90 PIPE_BIND_DISPLAY_TARGET |
91 PIPE_BIND_SCANOUT |
92 PIPE_BIND_SHARED |
93 PIPE_BIND_COMPUTE_RESOURCE)) &&
94 (fd6_pipe2color(format) != (enum a6xx_color_fmt)~0) &&
95 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
96 retval |= usage & (PIPE_BIND_RENDER_TARGET |
97 PIPE_BIND_DISPLAY_TARGET |
98 PIPE_BIND_SCANOUT |
99 PIPE_BIND_SHARED |
100 PIPE_BIND_COMPUTE_RESOURCE);
101 }
102
103 /* For ARB_framebuffer_no_attachments: */
104 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
105 retval |= usage & PIPE_BIND_RENDER_TARGET;
106 }
107
108 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
109 (fd6_pipe2depth(format) != (enum a6xx_depth_format)~0) &&
110 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
111 retval |= PIPE_BIND_DEPTH_STENCIL;
112 }
113
114 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
115 (fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
116 retval |= PIPE_BIND_INDEX_BUFFER;
117 }
118
119 if (retval != usage) {
120 DBG("not supported: format=%s, target=%d, sample_count=%d, "
121 "usage=%x, retval=%x", util_format_name(format),
122 target, sample_count, usage, retval);
123 }
124
125 return retval == usage;
126 }
127
128 void
129 fd6_screen_init(struct pipe_screen *pscreen)
130 {
131 struct fd_screen *screen = fd_screen(pscreen);
132 screen->max_rts = A6XX_MAX_RENDER_TARGETS;
133 screen->compiler = ir3_compiler_create(screen->dev, screen->gpu_id);
134 pscreen->context_create = fd6_context_create;
135 pscreen->is_format_supported = fd6_screen_is_format_supported;
136
137 screen->setup_slices = fd6_setup_slices;
138 screen->tile_mode = fd6_tile_mode;
139 }