freedreno/a6xx: fix srgb
[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_context.h"
33 #include "fd6_format.h"
34 #include "fd6_resource.h"
35
36 #include "ir3_compiler.h"
37
38 static boolean
39 fd6_screen_is_format_supported(struct pipe_screen *pscreen,
40 enum pipe_format format,
41 enum pipe_texture_target target,
42 unsigned sample_count,
43 unsigned storage_sample_count,
44 unsigned usage)
45 {
46 unsigned retval = 0;
47
48 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
49 (sample_count > 1)) { /* TODO add MSAA */
50 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
51 util_format_name(format), target, sample_count, usage);
52 return FALSE;
53 }
54
55 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
56 return false;
57
58 if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
59 (fd6_pipe2vtx(format) != (enum a6xx_vtx_fmt)~0)) {
60 retval |= PIPE_BIND_VERTEX_BUFFER;
61 }
62
63 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
64 (target == PIPE_BUFFER ||
65 util_format_get_blocksize(format) != 12) &&
66 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
67 retval |= PIPE_BIND_SAMPLER_VIEW;
68 }
69
70 if ((usage & (PIPE_BIND_RENDER_TARGET |
71 PIPE_BIND_DISPLAY_TARGET |
72 PIPE_BIND_SCANOUT |
73 PIPE_BIND_SHARED |
74 PIPE_BIND_COMPUTE_RESOURCE)) &&
75 (fd6_pipe2color(format) != (enum a6xx_color_fmt)~0) &&
76 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
77 retval |= usage & (PIPE_BIND_RENDER_TARGET |
78 PIPE_BIND_DISPLAY_TARGET |
79 PIPE_BIND_SCANOUT |
80 PIPE_BIND_SHARED |
81 PIPE_BIND_COMPUTE_RESOURCE);
82 }
83
84 /* For ARB_framebuffer_no_attachments: */
85 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
86 retval |= usage & PIPE_BIND_RENDER_TARGET;
87 }
88
89 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
90 (fd6_pipe2depth(format) != (enum a6xx_depth_format)~0) &&
91 (fd6_pipe2tex(format) != (enum a6xx_tex_fmt)~0)) {
92 retval |= PIPE_BIND_DEPTH_STENCIL;
93 }
94
95 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
96 (fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
97 retval |= PIPE_BIND_INDEX_BUFFER;
98 }
99
100 if (retval != usage) {
101 DBG("not supported: format=%s, target=%d, sample_count=%d, "
102 "usage=%x, retval=%x", util_format_name(format),
103 target, sample_count, usage, retval);
104 }
105
106 return retval == usage;
107 }
108
109 void
110 fd6_screen_init(struct pipe_screen *pscreen)
111 {
112 struct fd_screen *screen = fd_screen(pscreen);
113 screen->max_rts = A6XX_MAX_RENDER_TARGETS;
114 screen->compiler = ir3_compiler_create(screen->dev, screen->gpu_id);
115 pscreen->context_create = fd6_context_create;
116 pscreen->is_format_supported = fd6_screen_is_format_supported;
117
118 screen->setup_slices = fd6_setup_slices;
119 }