Merge branch 'master' into pipe-video
[mesa.git] / src / gallium / auxiliary / util / u_caps.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Vmware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "pipe/p_screen.h"
29 #include "util/u_format.h"
30 #include "util/u_debug.h"
31 #include "u_caps.h"
32
33 /**
34 * Iterates over a list of caps checks as defined in u_caps.h. Should
35 * all checks pass returns TRUE and out is set to the last element of
36 * the list (TERMINATE). Should any check fail returns FALSE and set
37 * out to the index of the start of the first failing check.
38 */
39 boolean
40 util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out)
41 {
42 int i, tmpi;
43 float tmpf;
44
45 for (i = 0; list[i];) {
46 switch(list[i++]) {
47 case UTIL_CAPS_CHECK_CAP:
48 if (!screen->get_param(screen, list[i++])) {
49 *out = i - 2;
50 return FALSE;
51 }
52 break;
53 case UTIL_CAPS_CHECK_INT:
54 tmpi = screen->get_param(screen, list[i++]);
55 if (tmpi < (int)list[i++]) {
56 *out = i - 3;
57 return FALSE;
58 }
59 break;
60 case UTIL_CAPS_CHECK_FLOAT:
61 tmpf = screen->get_paramf(screen, list[i++]);
62 if (tmpf < (float)list[i++]) {
63 *out = i - 3;
64 return FALSE;
65 }
66 break;
67 case UTIL_CAPS_CHECK_FORMAT:
68 if (!screen->is_format_supported(screen,
69 list[i++],
70 PIPE_TEXTURE_2D,
71 0,
72 PIPE_BIND_SAMPLER_VIEW,
73 0)) {
74 *out = i - 2;
75 return FALSE;
76 }
77 break;
78 case UTIL_CAPS_CHECK_SHADER:
79 tmpi = screen->get_shader_param(screen, list[i] >> 24, list[i] & ((1 << 24) - 1));
80 ++i;
81 if (tmpi < (int)list[i++]) {
82 *out = i - 3;
83 return FALSE;
84 }
85 break;
86 case UTIL_CAPS_CHECK_UNIMPLEMENTED:
87 *out = i - 1;
88 return FALSE;
89 default:
90 assert(!"Unsupported check");
91 return FALSE;
92 }
93 }
94
95 *out = i;
96 return TRUE;
97 }
98
99 /**
100 * Iterates over a list of caps checks as defined in u_caps.h.
101 * Returns TRUE if all caps checks pass returns FALSE otherwise.
102 */
103 boolean
104 util_check_caps(struct pipe_screen *screen, const unsigned *list)
105 {
106 int out;
107 return util_check_caps_out(screen, list, &out);
108 }
109
110
111 /*
112 * Below follows some demo lists.
113 *
114 * None of these lists are exhausting lists of what is
115 * actually needed to support said API and more here for
116 * as example on how to uses the above functions. Especially
117 * for DX10 and DX11 where Gallium is missing features.
118 */
119
120 /* DX 9_1 */
121 static unsigned caps_dx_9_1[] = {
122 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
123 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
124 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
125 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
126 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2),
127 UTIL_CHECK_TERMINATE
128 };
129
130 /* DX 9_2 */
131 static unsigned caps_dx_9_2[] = {
132 UTIL_CHECK_CAP(OCCLUSION_QUERY),
133 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
134 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
135 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
136 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
137 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
138 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
139 UTIL_CHECK_TERMINATE
140 };
141
142 /* DX 9_3 */
143 static unsigned caps_dx_9_3[] = {
144 UTIL_CHECK_CAP(SM3),
145 //UTIL_CHECK_CAP(INSTANCING),
146 UTIL_CHECK_CAP(OCCLUSION_QUERY),
147 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4),
148 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */
149 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
150 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
151 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
152 UTIL_CHECK_TERMINATE
153 };
154
155 /* DX 10 */
156 static unsigned caps_dx_10[] = {
157 UTIL_CHECK_CAP(SM3),
158 //UTIL_CHECK_CAP(INSTANCING),
159 UTIL_CHECK_CAP(OCCLUSION_QUERY),
160 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
161 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */
162 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
163 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */
164 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
165 UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
166 UTIL_CHECK_TERMINATE
167 };
168
169 /* DX11 */
170 static unsigned caps_dx_11[] = {
171 UTIL_CHECK_CAP(SM3),
172 //UTIL_CHECK_CAP(INSTANCING),
173 UTIL_CHECK_CAP(OCCLUSION_QUERY),
174 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
175 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */
176 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
177 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */
178 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
179 UTIL_CHECK_FORMAT(B8G8R8A8_UNORM),
180 UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
181 UTIL_CHECK_TERMINATE
182 };
183
184 /* OpenGL 2.1 */
185 static unsigned caps_opengl_2_1[] = {
186 UTIL_CHECK_CAP(GLSL),
187 UTIL_CHECK_CAP(OCCLUSION_QUERY),
188 UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
189 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
190 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2),
191 UTIL_CHECK_TERMINATE
192 };
193
194 /* OpenGL 3.0 */
195 /* UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), */
196
197 /* Shader Model 3 */
198 static unsigned caps_sm3[] = {
199 UTIL_CHECK_SHADER(FRAGMENT, MAX_INSTRUCTIONS, 512),
200 UTIL_CHECK_SHADER(FRAGMENT, MAX_INPUTS, 10),
201 UTIL_CHECK_SHADER(FRAGMENT, MAX_TEMPS, 32),
202 UTIL_CHECK_SHADER(FRAGMENT, MAX_ADDRS, 1),
203 UTIL_CHECK_SHADER(FRAGMENT, MAX_CONSTS, 224),
204
205 UTIL_CHECK_SHADER(VERTEX, MAX_INSTRUCTIONS, 512),
206 UTIL_CHECK_SHADER(VERTEX, MAX_INPUTS, 16),
207 UTIL_CHECK_SHADER(VERTEX, MAX_TEMPS, 32),
208 UTIL_CHECK_SHADER(VERTEX, MAX_ADDRS, 2),
209 UTIL_CHECK_SHADER(VERTEX, MAX_CONSTS, 256),
210
211 UTIL_CHECK_TERMINATE
212 };
213
214 /**
215 * Demo function which checks against theoretical caps needed for different APIs.
216 */
217 void util_caps_demo_print(struct pipe_screen *screen)
218 {
219 struct {
220 char* name;
221 unsigned *list;
222 } list[] = {
223 {"DX 9.1", caps_dx_9_1},
224 {"DX 9.2", caps_dx_9_2},
225 {"DX 9.3", caps_dx_9_3},
226 {"DX 10", caps_dx_10},
227 {"DX 11", caps_dx_11},
228 {"OpenGL 2.1", caps_opengl_2_1},
229 /* {"OpenGL 3.0", caps_opengl_3_0},*/
230 {"SM3", caps_sm3},
231 {NULL, NULL}
232 };
233 int i, out = 0;
234
235 for (i = 0; list[i].name; i++) {
236 if (util_check_caps_out(screen, list[i].list, &out)) {
237 debug_printf("%s: %s yes\n", __FUNCTION__, list[i].name);
238 continue;
239 }
240 switch (list[i].list[out]) {
241 case UTIL_CAPS_CHECK_CAP:
242 debug_printf("%s: %s no (cap %u not supported)\n", __FUNCTION__,
243 list[i].name,
244 list[i].list[out + 1]);
245 break;
246 case UTIL_CAPS_CHECK_INT:
247 debug_printf("%s: %s no (cap %u less then %u)\n", __FUNCTION__,
248 list[i].name,
249 list[i].list[out + 1],
250 list[i].list[out + 2]);
251 break;
252 case UTIL_CAPS_CHECK_FLOAT:
253 debug_printf("%s: %s no (cap %u less then %f)\n", __FUNCTION__,
254 list[i].name,
255 list[i].list[out + 1],
256 (double)(int)list[i].list[out + 2]);
257 break;
258 case UTIL_CAPS_CHECK_FORMAT:
259 debug_printf("%s: %s no (format %s not supported)\n", __FUNCTION__,
260 list[i].name,
261 util_format_name(list[i].list[out + 1]) + 12);
262 break;
263 case UTIL_CAPS_CHECK_UNIMPLEMENTED:
264 debug_printf("%s: %s no (not implemented in gallium or state tracker)\n",
265 __FUNCTION__, list[i].name);
266 break;
267 default:
268 assert(!"Unsupported check");
269 }
270 }
271 }