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/u_format.h"
29
30#include "fd2_screen.h"
31#include "fd2_context.h"
32#include "fd2_util.h"
33#include "fd2_resource.h"
34
35static boolean
36fd2_screen_is_format_supported(struct pipe_screen *pscreen,
37		enum pipe_format format,
38		enum pipe_texture_target target,
39		unsigned sample_count,
40		unsigned storage_sample_count,
41		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	/* TODO figure out how to render to other formats.. */
56	if ((usage & PIPE_BIND_RENDER_TARGET) &&
57			((format != PIPE_FORMAT_B5G6R5_UNORM) &&
58			 (format != PIPE_FORMAT_B5G5R5A1_UNORM) &&
59			 (format != PIPE_FORMAT_B5G5R5X1_UNORM) &&
60			 (format != PIPE_FORMAT_B4G4R4A4_UNORM) &&
61			 (format != PIPE_FORMAT_B4G4R4X4_UNORM) &&
62			 (format != PIPE_FORMAT_B8G8R8A8_UNORM) &&
63			 (format != PIPE_FORMAT_B8G8R8X8_UNORM) &&
64			 (format != PIPE_FORMAT_R8G8B8A8_UNORM) &&
65			 (format != PIPE_FORMAT_R8G8B8X8_UNORM))) {
66		DBG("not supported render target: format=%s, target=%d, sample_count=%d, usage=%x",
67				util_format_name(format), target, sample_count, usage);
68		return FALSE;
69	}
70
71	if ((usage & (PIPE_BIND_SAMPLER_VIEW |
72				PIPE_BIND_VERTEX_BUFFER)) &&
73			(fd2_pipe2surface(format) != (enum a2xx_sq_surfaceformat)~0)) {
74		retval |= usage & (PIPE_BIND_SAMPLER_VIEW |
75				PIPE_BIND_VERTEX_BUFFER);
76	}
77
78	if ((usage & (PIPE_BIND_RENDER_TARGET |
79				PIPE_BIND_DISPLAY_TARGET |
80				PIPE_BIND_SCANOUT |
81				PIPE_BIND_SHARED)) &&
82			(fd2_pipe2color(format) != (enum a2xx_colorformatx)~0)) {
83		retval |= usage & (PIPE_BIND_RENDER_TARGET |
84				PIPE_BIND_DISPLAY_TARGET |
85				PIPE_BIND_SCANOUT |
86				PIPE_BIND_SHARED);
87	}
88
89	if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
90			(fd_pipe2depth(format) != (enum adreno_rb_depth_format)~0)) {
91		retval |= PIPE_BIND_DEPTH_STENCIL;
92	}
93
94	if ((usage & PIPE_BIND_INDEX_BUFFER) &&
95			(fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
96		retval |= PIPE_BIND_INDEX_BUFFER;
97	}
98
99	if (retval != usage) {
100		DBG("not supported: format=%s, target=%d, sample_count=%d, "
101				"usage=%x, retval=%x", util_format_name(format),
102				target, sample_count, usage, retval);
103	}
104
105	return retval == usage;
106}
107
108extern const struct fd_perfcntr_group a2xx_perfcntr_groups[];
109extern const unsigned a2xx_num_perfcntr_groups;
110
111void
112fd2_screen_init(struct pipe_screen *pscreen)
113{
114	struct fd_screen *screen = fd_screen(pscreen);
115
116	screen->max_rts = 1;
117	pscreen->context_create = fd2_context_create;
118	pscreen->is_format_supported = fd2_screen_is_format_supported;
119	screen->setup_slices = fd2_setup_slices;
120
121	if (fd_mesa_debug & FD_DBG_PERFC) {
122		screen->perfcntr_groups = a2xx_perfcntr_groups;
123		screen->num_perfcntr_groups = a2xx_num_perfcntr_groups;
124	}
125}
126