Merge remote branch 'origin/master' into glsl2
[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_UNIMPLEMENTED:
79 *out = i - 1;
80 return FALSE;
81 default:
82 assert(!"Unsupported check");
83 return FALSE;
84 }
85 }
86
87 *out = i;
88 return TRUE;
89 }
90
91 /**
92 * Iterates over a list of caps checks as defined in u_caps.h.
93 * Returns TRUE if all caps checks pass returns FALSE otherwise.
94 */
95 boolean
96 util_check_caps(struct pipe_screen *screen, const unsigned *list)
97 {
98 int out;
99 return util_check_caps_out(screen, list, &out);
100 }
101
102
103 /*
104 * Below follows some demo lists.
105 *
106 * None of these lists are exhausting lists of what is
107 * actually needed to support said API and more here for
108 * as example on how to uses the above functions. Especially
109 * for DX10 and DX11 where Gallium is missing features.
110 */
111
112 /* DX 9_1 */
113 static unsigned caps_dx_9_1[] = {
114 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
115 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
116 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
117 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
118 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2),
119 UTIL_CHECK_TERMINATE
120 };
121
122 /* DX 9_2 */
123 static unsigned caps_dx_9_2[] = {
124 UTIL_CHECK_CAP(OCCLUSION_QUERY),
125 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
126 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
127 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
128 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
129 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
130 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
131 UTIL_CHECK_TERMINATE
132 };
133
134 /* DX 9_3 */
135 static unsigned caps_dx_9_3[] = {
136 UTIL_CHECK_CAP(SM3),
137 //UTIL_CHECK_CAP(INSTANCING),
138 UTIL_CHECK_CAP(OCCLUSION_QUERY),
139 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4),
140 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */
141 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
142 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
143 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
144 UTIL_CHECK_TERMINATE
145 };
146
147 /* DX 10 */
148 static unsigned caps_dx_10[] = {
149 UTIL_CHECK_CAP(SM3),
150 //UTIL_CHECK_CAP(INSTANCING),
151 UTIL_CHECK_CAP(OCCLUSION_QUERY),
152 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
153 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */
154 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
155 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */
156 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
157 UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
158 UTIL_CHECK_TERMINATE
159 };
160
161 /* DX11 */
162 static unsigned caps_dx_11[] = {
163 UTIL_CHECK_CAP(SM3),
164 //UTIL_CHECK_CAP(INSTANCING),
165 UTIL_CHECK_CAP(OCCLUSION_QUERY),
166 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
167 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */
168 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
169 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */
170 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
171 UTIL_CHECK_FORMAT(B8G8R8A8_UNORM),
172 UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
173 UTIL_CHECK_TERMINATE
174 };
175
176 /* OpenGL 2.1 */
177 static unsigned caps_opengl_2_1[] = {
178 UTIL_CHECK_CAP(GLSL),
179 UTIL_CHECK_CAP(OCCLUSION_QUERY),
180 UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
181 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
182 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2),
183 UTIL_CHECK_TERMINATE
184 };
185
186 /* OpenGL 3.0 */
187 /* UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), */
188
189 /* Shader Model 3 */
190 static unsigned caps_sm3[] = {
191 UTIL_CHECK_INT(MAX_FS_INSTRUCTIONS, 512),
192 UTIL_CHECK_INT(MAX_FS_INPUTS, 10),
193 UTIL_CHECK_INT(MAX_FS_TEMPS, 32),
194 UTIL_CHECK_INT(MAX_FS_ADDRS, 1),
195 UTIL_CHECK_INT(MAX_FS_CONSTS, 224),
196
197 UTIL_CHECK_INT(MAX_VS_INSTRUCTIONS, 512),
198 UTIL_CHECK_INT(MAX_VS_INPUTS, 16),
199 UTIL_CHECK_INT(MAX_VS_TEMPS, 32),
200 UTIL_CHECK_INT(MAX_VS_ADDRS, 2),
201 UTIL_CHECK_INT(MAX_VS_CONSTS, 256),
202
203 UTIL_CHECK_TERMINATE
204 };
205
206 /**
207 * Demo function which checks against theoretical caps needed for different APIs.
208 */
209 void util_caps_demo_print(struct pipe_screen *screen)
210 {
211 struct {
212 char* name;
213 unsigned *list;
214 } list[] = {
215 {"DX 9.1", caps_dx_9_1},
216 {"DX 9.2", caps_dx_9_2},
217 {"DX 9.3", caps_dx_9_3},
218 {"DX 10", caps_dx_10},
219 {"DX 11", caps_dx_11},
220 {"OpenGL 2.1", caps_opengl_2_1},
221 /* {"OpenGL 3.0", caps_opengl_3_0},*/
222 {"SM3", caps_sm3},
223 {NULL, NULL}
224 };
225 int i, out = 0;
226
227 for (i = 0; list[i].name; i++) {
228 if (util_check_caps_out(screen, list[i].list, &out)) {
229 debug_printf("%s: %s yes\n", __FUNCTION__, list[i].name);
230 continue;
231 }
232 switch (list[i].list[out]) {
233 case UTIL_CAPS_CHECK_CAP:
234 debug_printf("%s: %s no (cap %u not supported)\n", __FUNCTION__,
235 list[i].name,
236 list[i].list[out + 1]);
237 break;
238 case UTIL_CAPS_CHECK_INT:
239 debug_printf("%s: %s no (cap %u less then %u)\n", __FUNCTION__,
240 list[i].name,
241 list[i].list[out + 1],
242 list[i].list[out + 2]);
243 break;
244 case UTIL_CAPS_CHECK_FLOAT:
245 debug_printf("%s: %s no (cap %u less then %f)\n", __FUNCTION__,
246 list[i].name,
247 list[i].list[out + 1],
248 (double)(int)list[i].list[out + 2]);
249 break;
250 case UTIL_CAPS_CHECK_FORMAT:
251 debug_printf("%s: %s no (format %s not supported)\n", __FUNCTION__,
252 list[i].name,
253 util_format_name(list[i].list[out + 1]) + 12);
254 break;
255 case UTIL_CAPS_CHECK_UNIMPLEMENTED:
256 debug_printf("%s: %s no (not implemented in gallium or state tracker)\n",
257 __FUNCTION__, list[i].name);
258 break;
259 default:
260 assert(!"Unsupported check");
261 }
262 }
263 }