• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2 
3 /*
4  * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28 
29 #include "pipe/p_screen.h"
30 #include "util/u_format.h"
31 
32 #include "fd2_screen.h"
33 #include "fd2_context.h"
34 #include "fd2_util.h"
35 
36 static boolean
fd2_screen_is_format_supported(struct pipe_screen * pscreen,enum pipe_format format,enum pipe_texture_target target,unsigned 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 usage)
42 {
43 	unsigned retval = 0;
44 
45 	if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
46 			(sample_count > 1) || /* TODO add MSAA */
47 			!util_format_is_supported(format, usage)) {
48 		DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
49 				util_format_name(format), target, sample_count, usage);
50 		return FALSE;
51 	}
52 
53 	/* TODO figure out how to render to other formats.. */
54 	if ((usage & PIPE_BIND_RENDER_TARGET) &&
55 			((format != PIPE_FORMAT_B5G6R5_UNORM) &&
56 			 (format != PIPE_FORMAT_B5G5R5A1_UNORM) &&
57 			 (format != PIPE_FORMAT_B5G5R5X1_UNORM) &&
58 			 (format != PIPE_FORMAT_B4G4R4A4_UNORM) &&
59 			 (format != PIPE_FORMAT_B4G4R4X4_UNORM) &&
60 			 (format != PIPE_FORMAT_B8G8R8A8_UNORM) &&
61 			 (format != PIPE_FORMAT_B8G8R8X8_UNORM) &&
62 			 (format != PIPE_FORMAT_R8G8B8A8_UNORM) &&
63 			 (format != PIPE_FORMAT_R8G8B8X8_UNORM))) {
64 		DBG("not supported render target: 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_SAMPLER_VIEW |
70 				PIPE_BIND_VERTEX_BUFFER)) &&
71 			(fd2_pipe2surface(format) != (enum a2xx_sq_surfaceformat)~0)) {
72 		retval |= usage & (PIPE_BIND_SAMPLER_VIEW |
73 				PIPE_BIND_VERTEX_BUFFER);
74 	}
75 
76 	if ((usage & (PIPE_BIND_RENDER_TARGET |
77 				PIPE_BIND_DISPLAY_TARGET |
78 				PIPE_BIND_SCANOUT |
79 				PIPE_BIND_SHARED)) &&
80 			(fd2_pipe2color(format) != (enum a2xx_colorformatx)~0)) {
81 		retval |= usage & (PIPE_BIND_RENDER_TARGET |
82 				PIPE_BIND_DISPLAY_TARGET |
83 				PIPE_BIND_SCANOUT |
84 				PIPE_BIND_SHARED);
85 	}
86 
87 	if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
88 			(fd_pipe2depth(format) != (enum adreno_rb_depth_format)~0)) {
89 		retval |= PIPE_BIND_DEPTH_STENCIL;
90 	}
91 
92 	if ((usage & PIPE_BIND_INDEX_BUFFER) &&
93 			(fd_pipe2index(format) != (enum pc_di_index_size)~0)) {
94 		retval |= PIPE_BIND_INDEX_BUFFER;
95 	}
96 
97 	if (retval != usage) {
98 		DBG("not supported: format=%s, target=%d, sample_count=%d, "
99 				"usage=%x, retval=%x", util_format_name(format),
100 				target, sample_count, usage, retval);
101 	}
102 
103 	return retval == usage;
104 }
105 
106 void
fd2_screen_init(struct pipe_screen * pscreen)107 fd2_screen_init(struct pipe_screen *pscreen)
108 {
109 	fd_screen(pscreen)->max_rts = 1;
110 	pscreen->context_create = fd2_context_create;
111 	pscreen->is_format_supported = fd2_screen_is_format_supported;
112 }
113