util: Add small caps checker helper
[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 boolean
34 util_check_caps_out(struct pipe_screen *screen, unsigned *list, int *out)
35 {
36 int i, tmpi;
37 float tmpf;
38
39 for (i = 0; list[i];) {
40 switch(list[i++]) {
41 case UTIL_CAPS_CHECK_CAP:
42 if (!screen->get_param(screen, list[i++])) {
43 *out = i - 2;
44 return FALSE;
45 }
46 break;
47 case UTIL_CAPS_CHECK_INT:
48 tmpi = screen->get_param(screen, list[i++]);
49 if (tmpi < (int)list[i++]) {
50 *out = i - 3;
51 return FALSE;
52 }
53 break;
54 case UTIL_CAPS_CHECK_FLOAT:
55 tmpf = screen->get_paramf(screen, list[i++]);
56 if (tmpf < (float)list[i++]) {
57 *out = i - 3;
58 return FALSE;
59 }
60 break;
61 case UTIL_CAPS_CHECK_FORMAT:
62 if (!screen->is_format_supported(screen,
63 list[i++],
64 PIPE_TEXTURE_2D,
65 PIPE_BIND_SAMPLER_VIEW,
66 0)) {
67 *out = i - 2;
68 return FALSE;
69 }
70 break;
71 default:
72 assert(!"Unsupported check");
73 return FALSE;
74 }
75 }
76 return TRUE;
77 }
78
79 boolean
80 util_check_caps(struct pipe_screen *screen, unsigned *list)
81 {
82 int out;
83 return util_check_caps_out(screen, list, &out);
84 }
85
86 /* DX 9_1 */
87 static unsigned caps_dx_9_1[] = {
88 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
89 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
90 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
91 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
92 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2),
93 UTIL_CHECK_TERMINATE
94 };
95
96 /* DX 9_2 */
97 static unsigned caps_dx_9_2[] = {
98 UTIL_CHECK_CAP(OCCLUSION_QUERY),
99 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
100 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
101 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
102 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
103 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
104 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
105 UTIL_CHECK_TERMINATE
106 };
107
108 /* DX 9_3 */
109 static unsigned caps_dx_9_3[] = {
110 UTIL_CHECK_CAP(SM3),
111 //UTIL_CHECK_CAP(INSTANCING),
112 UTIL_CHECK_CAP(OCCLUSION_QUERY),
113 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4),
114 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */
115 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
116 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
117 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
118 UTIL_CHECK_TERMINATE
119 };
120
121 /* DX 10 */
122 static unsigned caps_dx_10[] = {
123 UTIL_CHECK_CAP(SM3),
124 //UTIL_CHECK_CAP(INSTANCING),
125 UTIL_CHECK_CAP(OCCLUSION_QUERY),
126 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
127 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */
128 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
129 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */
130 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
131 UTIL_CHECK_TERMINATE
132 };
133
134 /* DX 11 */
135 static unsigned caps_dx_11[] = {
136 UTIL_CHECK_CAP(SM3),
137 //UTIL_CHECK_CAP(INSTANCING),
138 UTIL_CHECK_CAP(OCCLUSION_QUERY),
139 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
140 UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */
141 UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
142 UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */
143 UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
144 UTIL_CHECK_FORMAT(B8G8R8A8_UNORM),
145 UTIL_CHECK_TERMINATE
146 };
147
148 /* OpenGL 2.1 */
149 static unsigned caps_opengl_2_1[] = {
150 UTIL_CHECK_CAP(GLSL),
151 UTIL_CHECK_CAP(OCCLUSION_QUERY),
152 UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
153 UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
154 UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2), /* XXX 4? */
155 UTIL_CHECK_TERMINATE
156 };
157
158 void util_caps_print_debug(struct pipe_screen *screen)
159 {
160 struct {
161 char* name;
162 unsigned *list;
163 } list[] = {
164 {"DX 9.1", caps_dx_9_1},
165 {"DX 9.2", caps_dx_9_2},
166 {"DX 9.3", caps_dx_9_3},
167 {"DX 10", caps_dx_10},
168 {"DX 11", caps_dx_11},
169 {"OpenGL 2.1", caps_opengl_2_1},
170 {NULL, NULL}
171 };
172 int i, out = 0;
173
174 for (i = 0; list[i].name; i++) {
175 if (util_check_caps_out(screen, list[i].list, &out)) {
176 debug_printf("%s: %s yes\n", __func__, list[i].name);
177 continue;
178 }
179 switch (list[i].list[out]) {
180 case UTIL_CAPS_CHECK_CAP:
181 debug_printf("%s: %s no (cap %u not supported)\n", __func__,
182 list[i].name,
183 list[i].list[out + 1]);
184 break;
185 case UTIL_CAPS_CHECK_INT:
186 debug_printf("%s: %s no (cap %u less then %u)\n", __func__,
187 list[i].name,
188 list[i].list[out + 1],
189 list[i].list[out + 2]);
190 break;
191 case UTIL_CAPS_CHECK_FLOAT:
192 debug_printf("%s: %s no (cap %u less then %f)\n", __func__,
193 list[i].name,
194 list[i].list[out + 1],
195 (double)(int)list[i].list[out + 2]);
196 break;
197 case UTIL_CAPS_CHECK_FORMAT:
198 debug_printf("%s: %s no (format %s not supported)\n", __func__,
199 list[i].name,
200 util_format_name(list[i].list[out + 1]) + 12);
201 break;
202 default:
203 assert(!"Unsupported check");
204 }
205 }
206 }