rgtc: llvmpipe/softpipe refuse RGTC until u_format has support.
[mesa.git] / src / gallium / drivers / softpipe / sp_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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
29 #include "util/u_memory.h"
30 #include "util/u_format.h"
31 #include "util/u_format_s3tc.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_screen.h"
34 #include "draw/draw_context.h"
35
36 #include "state_tracker/sw_winsys.h"
37 #include "tgsi/tgsi_exec.h"
38
39 #include "sp_texture.h"
40 #include "sp_screen.h"
41 #include "sp_context.h"
42 #include "sp_fence.h"
43 #include "sp_public.h"
44
45
46 static const char *
47 softpipe_get_vendor(struct pipe_screen *screen)
48 {
49 return "VMware, Inc.";
50 }
51
52
53 static const char *
54 softpipe_get_name(struct pipe_screen *screen)
55 {
56 return "softpipe";
57 }
58
59
60 static int
61 softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
62 {
63 switch (param) {
64 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
65 return PIPE_MAX_SAMPLERS;
66 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
67 #ifdef HAVE_LLVM
68 /* Softpipe doesn't yet know how to tell draw/llvm about textures */
69 return 0;
70 #else
71 return PIPE_MAX_VERTEX_SAMPLERS;
72 #endif
73 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
74 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
75 case PIPE_CAP_NPOT_TEXTURES:
76 return 1;
77 case PIPE_CAP_TWO_SIDED_STENCIL:
78 return 1;
79 case PIPE_CAP_GLSL:
80 return 1;
81 case PIPE_CAP_SM3:
82 return 1;
83 case PIPE_CAP_ANISOTROPIC_FILTER:
84 return 0;
85 case PIPE_CAP_POINT_SPRITE:
86 return 1;
87 case PIPE_CAP_MAX_RENDER_TARGETS:
88 return PIPE_MAX_COLOR_BUFS;
89 case PIPE_CAP_OCCLUSION_QUERY:
90 return 1;
91 case PIPE_CAP_TIMER_QUERY:
92 return 1;
93 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
94 return 1;
95 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
96 return 1;
97 case PIPE_CAP_TEXTURE_SHADOW_MAP:
98 return 1;
99 case PIPE_CAP_TEXTURE_SWIZZLE:
100 return 1;
101 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
102 return SP_MAX_TEXTURE_2D_LEVELS;
103 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
104 return SP_MAX_TEXTURE_3D_LEVELS;
105 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
106 return SP_MAX_TEXTURE_2D_LEVELS;
107 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
108 return 1;
109 case PIPE_CAP_INDEP_BLEND_ENABLE:
110 return 1;
111 case PIPE_CAP_INDEP_BLEND_FUNC:
112 return 1;
113 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
114 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
115 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
116 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
117 return 1;
118 case PIPE_CAP_STREAM_OUTPUT:
119 return 1;
120 case PIPE_CAP_PRIMITIVE_RESTART:
121 return 1;
122 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
123 return 0;
124 case PIPE_CAP_SHADER_STENCIL_EXPORT:
125 return 1;
126 case PIPE_CAP_INSTANCED_DRAWING:
127 return 1;
128 case PIPE_CAP_ARRAY_TEXTURES:
129 return 1;
130 default:
131 return 0;
132 }
133 }
134
135 static int
136 softpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param)
137 {
138 switch(shader)
139 {
140 case PIPE_SHADER_FRAGMENT:
141 return tgsi_exec_get_shader_param(param);
142 case PIPE_SHADER_VERTEX:
143 case PIPE_SHADER_GEOMETRY:
144 return draw_get_shader_param(shader, param);
145 default:
146 return 0;
147 }
148 }
149
150 static float
151 softpipe_get_paramf(struct pipe_screen *screen, enum pipe_cap param)
152 {
153 switch (param) {
154 case PIPE_CAP_MAX_LINE_WIDTH:
155 /* fall-through */
156 case PIPE_CAP_MAX_LINE_WIDTH_AA:
157 return 255.0; /* arbitrary */
158 case PIPE_CAP_MAX_POINT_WIDTH:
159 /* fall-through */
160 case PIPE_CAP_MAX_POINT_WIDTH_AA:
161 return 255.0; /* arbitrary */
162 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
163 return 16.0; /* not actually signficant at this time */
164 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
165 return 16.0; /* arbitrary */
166 default:
167 return 0;
168 }
169 }
170
171
172 /**
173 * Query format support for creating a texture, drawing surface, etc.
174 * \param format the format to test
175 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
176 */
177 static boolean
178 softpipe_is_format_supported( struct pipe_screen *screen,
179 enum pipe_format format,
180 enum pipe_texture_target target,
181 unsigned sample_count,
182 unsigned bind,
183 unsigned geom_flags )
184 {
185 struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
186 const struct util_format_description *format_desc;
187
188 assert(target == PIPE_BUFFER ||
189 target == PIPE_TEXTURE_1D ||
190 target == PIPE_TEXTURE_1D_ARRAY ||
191 target == PIPE_TEXTURE_2D ||
192 target == PIPE_TEXTURE_2D_ARRAY ||
193 target == PIPE_TEXTURE_RECT ||
194 target == PIPE_TEXTURE_3D ||
195 target == PIPE_TEXTURE_CUBE);
196
197 format_desc = util_format_description(format);
198 if (!format_desc)
199 return FALSE;
200
201 if (sample_count > 1)
202 return FALSE;
203
204 if (bind & (PIPE_BIND_DISPLAY_TARGET |
205 PIPE_BIND_SCANOUT |
206 PIPE_BIND_SHARED)) {
207 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
208 return FALSE;
209 }
210
211 if (bind & PIPE_BIND_RENDER_TARGET) {
212 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
213 return FALSE;
214
215 /*
216 * Although possible, it is unnatural to render into compressed or YUV
217 * surfaces. So disable these here to avoid going into weird paths
218 * inside the state trackers.
219 */
220 if (format_desc->block.width != 1 ||
221 format_desc->block.height != 1)
222 return FALSE;
223 }
224
225 if (bind & PIPE_BIND_DEPTH_STENCIL) {
226 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
227 return FALSE;
228
229 /*
230 * TODO: Unfortunately we cannot render into anything more than 32 bits
231 * because we encode depth and stencil clear values into a 32bit word.
232 */
233 if (format_desc->block.bits > 32)
234 return FALSE;
235
236 /*
237 * TODO: eliminate this restriction
238 */
239 if (format == PIPE_FORMAT_Z32_FLOAT)
240 return FALSE;
241 }
242
243 /*
244 * All other operations (sampling, transfer, etc).
245 */
246
247 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
248 return util_format_s3tc_enabled;
249 }
250
251 /* u_format doesn't implement RGTC yet */
252 if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
253 return FALSE;
254 }
255
256 /*
257 * Everything else should be supported by u_format.
258 */
259 return TRUE;
260 }
261
262
263 static void
264 softpipe_destroy_screen( struct pipe_screen *screen )
265 {
266 struct softpipe_screen *sp_screen = softpipe_screen(screen);
267 struct sw_winsys *winsys = sp_screen->winsys;
268
269 if(winsys->destroy)
270 winsys->destroy(winsys);
271
272 FREE(screen);
273 }
274
275
276 /* This is often overriden by the co-state tracker.
277 */
278 static void
279 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
280 struct pipe_resource *resource,
281 unsigned level, unsigned layer,
282 void *context_private)
283 {
284 struct softpipe_screen *screen = softpipe_screen(_screen);
285 struct sw_winsys *winsys = screen->winsys;
286 struct softpipe_resource *texture = softpipe_resource(resource);
287
288 assert(texture->dt);
289 if (texture->dt)
290 winsys->displaytarget_display(winsys, texture->dt, context_private);
291 }
292
293 /**
294 * Create a new pipe_screen object
295 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
296 */
297 struct pipe_screen *
298 softpipe_create_screen(struct sw_winsys *winsys)
299 {
300 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
301
302 if (!screen)
303 return NULL;
304
305 screen->winsys = winsys;
306
307 screen->base.winsys = NULL;
308 screen->base.destroy = softpipe_destroy_screen;
309
310 screen->base.get_name = softpipe_get_name;
311 screen->base.get_vendor = softpipe_get_vendor;
312 screen->base.get_param = softpipe_get_param;
313 screen->base.get_shader_param = softpipe_get_shader_param;
314 screen->base.get_paramf = softpipe_get_paramf;
315 screen->base.is_format_supported = softpipe_is_format_supported;
316 screen->base.context_create = softpipe_create_context;
317 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
318
319 util_format_s3tc_init();
320
321 softpipe_init_screen_texture_funcs(&screen->base);
322 softpipe_init_screen_fence_funcs(&screen->base);
323
324 return &screen->base;
325 }