gallium drivers: report that user vertex buffers are supported
[mesa.git] / src / gallium / drivers / llvmpipe / lp_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_math.h"
31 #include "util/u_cpu_detect.h"
32 #include "util/u_format.h"
33 #include "util/u_string.h"
34 #include "util/u_format_s3tc.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
37 #include "draw/draw_context.h"
38
39 #include "lp_texture.h"
40 #include "lp_fence.h"
41 #include "lp_jit.h"
42 #include "lp_screen.h"
43 #include "lp_context.h"
44 #include "lp_debug.h"
45 #include "lp_public.h"
46 #include "lp_limits.h"
47 #include "lp_rast.h"
48
49 #include "state_tracker/sw_winsys.h"
50
51 #ifdef DEBUG
52 int LP_DEBUG = 0;
53
54 static const struct debug_named_value lp_debug_flags[] = {
55 { "pipe", DEBUG_PIPE, NULL },
56 { "tgsi", DEBUG_TGSI, NULL },
57 { "tex", DEBUG_TEX, NULL },
58 { "setup", DEBUG_SETUP, NULL },
59 { "rast", DEBUG_RAST, NULL },
60 { "query", DEBUG_QUERY, NULL },
61 { "screen", DEBUG_SCREEN, NULL },
62 { "show_tiles", DEBUG_SHOW_TILES, NULL },
63 { "show_subtiles", DEBUG_SHOW_SUBTILES, NULL },
64 { "counters", DEBUG_COUNTERS, NULL },
65 { "scene", DEBUG_SCENE, NULL },
66 { "fence", DEBUG_FENCE, NULL },
67 { "mem", DEBUG_MEM, NULL },
68 { "fs", DEBUG_FS, NULL },
69 DEBUG_NAMED_VALUE_END
70 };
71 #endif
72
73 int LP_PERF = 0;
74 static const struct debug_named_value lp_perf_flags[] = {
75 { "texmem", PERF_TEX_MEM, NULL },
76 { "no_mipmap", PERF_NO_MIPMAPS, NULL },
77 { "no_linear", PERF_NO_LINEAR, NULL },
78 { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL },
79 { "no_tex", PERF_NO_TEX, NULL },
80 { "no_blend", PERF_NO_BLEND, NULL },
81 { "no_depth", PERF_NO_DEPTH, NULL },
82 { "no_alphatest", PERF_NO_ALPHATEST, NULL },
83 DEBUG_NAMED_VALUE_END
84 };
85
86
87 static const char *
88 llvmpipe_get_vendor(struct pipe_screen *screen)
89 {
90 return "VMware, Inc.";
91 }
92
93
94 static const char *
95 llvmpipe_get_name(struct pipe_screen *screen)
96 {
97 static char buf[100];
98 util_snprintf(buf, sizeof(buf), "llvmpipe (LLVM 0x%x)", HAVE_LLVM);
99 return buf;
100 }
101
102
103 static int
104 llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
105 {
106 switch (param) {
107 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
108 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
109 case PIPE_CAP_NPOT_TEXTURES:
110 return 1;
111 case PIPE_CAP_TWO_SIDED_STENCIL:
112 return 1;
113 case PIPE_CAP_SM3:
114 return 1;
115 case PIPE_CAP_ANISOTROPIC_FILTER:
116 return 0;
117 case PIPE_CAP_POINT_SPRITE:
118 return 1;
119 case PIPE_CAP_MAX_RENDER_TARGETS:
120 return PIPE_MAX_COLOR_BUFS;
121 case PIPE_CAP_OCCLUSION_QUERY:
122 return 1;
123 case PIPE_CAP_TIMER_QUERY:
124 return 0;
125 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
126 return 1;
127 case PIPE_CAP_TEXTURE_SHADOW_MAP:
128 return 1;
129 case PIPE_CAP_TEXTURE_SWIZZLE:
130 return 1;
131 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
132 return LP_MAX_TEXTURE_2D_LEVELS;
133 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
134 return LP_MAX_TEXTURE_3D_LEVELS;
135 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
136 return LP_MAX_TEXTURE_2D_LEVELS;
137 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
138 return 1;
139 case PIPE_CAP_INDEP_BLEND_ENABLE:
140 return 1;
141 case PIPE_CAP_INDEP_BLEND_FUNC:
142 return 1;
143 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
144 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
145 return 1;
146 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
147 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
148 return 0;
149 case PIPE_CAP_PRIMITIVE_RESTART:
150 return 1;
151 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
152 return 1;
153 case PIPE_CAP_DEPTH_CLIP_DISABLE:
154 return 0;
155 case PIPE_CAP_TGSI_INSTANCEID:
156 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
157 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
158 case PIPE_CAP_CONDITIONAL_RENDER:
159 return 1;
160 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
161 return 0;
162 case PIPE_CAP_USER_VERTEX_BUFFERS:
163 return 1;
164 default:
165 return 0;
166 }
167 }
168
169 static int
170 llvmpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param)
171 {
172 switch(shader)
173 {
174 case PIPE_SHADER_FRAGMENT:
175 switch (param) {
176 case PIPE_SHADER_CAP_INTEGERS:
177 return 0;
178 default:
179 return tgsi_exec_get_shader_param(param);
180 }
181 case PIPE_SHADER_VERTEX:
182 case PIPE_SHADER_GEOMETRY:
183 switch (param) {
184 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
185 /* At this time, the draw module and llvmpipe driver only
186 * support vertex shader texture lookups when LLVM is enabled in
187 * the draw module.
188 */
189 if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
190 return PIPE_MAX_VERTEX_SAMPLERS;
191 else
192 return 0;
193 case PIPE_SHADER_CAP_INTEGERS:
194 return 0;
195 default:
196 return draw_get_shader_param(shader, param);
197 }
198 default:
199 return 0;
200 }
201 }
202
203 static float
204 llvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
205 {
206 switch (param) {
207 case PIPE_CAPF_MAX_LINE_WIDTH:
208 /* fall-through */
209 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
210 return 255.0; /* arbitrary */
211 case PIPE_CAPF_MAX_POINT_WIDTH:
212 /* fall-through */
213 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
214 return 255.0; /* arbitrary */
215 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
216 return 16.0; /* not actually signficant at this time */
217 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
218 return 16.0; /* arbitrary */
219 case PIPE_CAPF_GUARD_BAND_LEFT:
220 case PIPE_CAPF_GUARD_BAND_TOP:
221 case PIPE_CAPF_GUARD_BAND_RIGHT:
222 case PIPE_CAPF_GUARD_BAND_BOTTOM:
223 return 0.0;
224 default:
225 assert(0);
226 return 0;
227 }
228 }
229
230
231 /**
232 * Query format support for creating a texture, drawing surface, etc.
233 * \param format the format to test
234 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
235 */
236 static boolean
237 llvmpipe_is_format_supported( struct pipe_screen *_screen,
238 enum pipe_format format,
239 enum pipe_texture_target target,
240 unsigned sample_count,
241 unsigned bind)
242 {
243 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
244 struct sw_winsys *winsys = screen->winsys;
245 const struct util_format_description *format_desc;
246
247 format_desc = util_format_description(format);
248 if (!format_desc)
249 return FALSE;
250
251 assert(target == PIPE_BUFFER ||
252 target == PIPE_TEXTURE_1D ||
253 target == PIPE_TEXTURE_2D ||
254 target == PIPE_TEXTURE_RECT ||
255 target == PIPE_TEXTURE_3D ||
256 target == PIPE_TEXTURE_CUBE);
257
258 if (sample_count > 1)
259 return FALSE;
260
261 if (format_desc->format == PIPE_FORMAT_R11G11B10_FLOAT ||
262 format_desc->format == PIPE_FORMAT_R9G9B9E5_FLOAT)
263 return TRUE;
264
265 if (bind & PIPE_BIND_RENDER_TARGET) {
266 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS ||
267 format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
268 return FALSE;
269
270 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
271 return FALSE;
272
273 if (format_desc->block.width != 1 ||
274 format_desc->block.height != 1)
275 return FALSE;
276 }
277
278 if (bind & PIPE_BIND_DISPLAY_TARGET) {
279 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
280 return FALSE;
281 }
282
283 if (bind & PIPE_BIND_DEPTH_STENCIL) {
284 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
285 return FALSE;
286
287 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
288 return FALSE;
289
290 /* FIXME: Temporary restriction. See lp_state_fs.c. */
291 if (format_desc->block.bits != 32)
292 return FALSE;
293 }
294
295 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
296 return util_format_s3tc_enabled;
297 }
298
299 /*
300 * Everything can be supported by u_format.
301 */
302
303 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS &&
304 !format_desc->fetch_rgba_float) {
305 return FALSE;
306 }
307
308 return TRUE;
309 }
310
311
312
313
314 static void
315 llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
316 struct pipe_resource *resource,
317 unsigned level, unsigned layer,
318 void *context_private)
319 {
320 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
321 struct sw_winsys *winsys = screen->winsys;
322 struct llvmpipe_resource *texture = llvmpipe_resource(resource);
323
324 assert(texture->dt);
325 if (texture->dt)
326 winsys->displaytarget_display(winsys, texture->dt, context_private);
327 }
328
329
330 static void
331 llvmpipe_destroy_screen( struct pipe_screen *_screen )
332 {
333 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
334 struct sw_winsys *winsys = screen->winsys;
335
336 if (screen->rast)
337 lp_rast_destroy(screen->rast);
338
339 lp_jit_screen_cleanup(screen);
340
341 if(winsys->destroy)
342 winsys->destroy(winsys);
343
344 pipe_mutex_destroy(screen->rast_mutex);
345
346 FREE(screen);
347 }
348
349
350
351
352 /**
353 * Fence reference counting.
354 */
355 static void
356 llvmpipe_fence_reference(struct pipe_screen *screen,
357 struct pipe_fence_handle **ptr,
358 struct pipe_fence_handle *fence)
359 {
360 struct lp_fence **old = (struct lp_fence **) ptr;
361 struct lp_fence *f = (struct lp_fence *) fence;
362
363 lp_fence_reference(old, f);
364 }
365
366
367 /**
368 * Has the fence been executed/finished?
369 */
370 static boolean
371 llvmpipe_fence_signalled(struct pipe_screen *screen,
372 struct pipe_fence_handle *fence)
373 {
374 struct lp_fence *f = (struct lp_fence *) fence;
375 return lp_fence_signalled(f);
376 }
377
378
379 /**
380 * Wait for the fence to finish.
381 */
382 static boolean
383 llvmpipe_fence_finish(struct pipe_screen *screen,
384 struct pipe_fence_handle *fence_handle,
385 uint64_t timeout)
386 {
387 struct lp_fence *f = (struct lp_fence *) fence_handle;
388
389 lp_fence_wait(f);
390 return TRUE;
391 }
392
393
394
395 /**
396 * Create a new pipe_screen object
397 * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen).
398 */
399 struct pipe_screen *
400 llvmpipe_create_screen(struct sw_winsys *winsys)
401 {
402 struct llvmpipe_screen *screen;
403
404 #ifdef PIPE_ARCH_X86
405 /* require SSE2 due to LLVM PR6960. */
406 util_cpu_detect();
407 if (!util_cpu_caps.has_sse2)
408 return NULL;
409 #endif
410
411 #ifdef DEBUG
412 LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 );
413 #endif
414
415 LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 );
416
417 screen = CALLOC_STRUCT(llvmpipe_screen);
418 if (!screen)
419 return NULL;
420
421 screen->winsys = winsys;
422
423 screen->base.destroy = llvmpipe_destroy_screen;
424
425 screen->base.get_name = llvmpipe_get_name;
426 screen->base.get_vendor = llvmpipe_get_vendor;
427 screen->base.get_param = llvmpipe_get_param;
428 screen->base.get_shader_param = llvmpipe_get_shader_param;
429 screen->base.get_paramf = llvmpipe_get_paramf;
430 screen->base.is_format_supported = llvmpipe_is_format_supported;
431
432 screen->base.context_create = llvmpipe_create_context;
433 screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
434 screen->base.fence_reference = llvmpipe_fence_reference;
435 screen->base.fence_signalled = llvmpipe_fence_signalled;
436 screen->base.fence_finish = llvmpipe_fence_finish;
437
438 llvmpipe_init_screen_resource_funcs(&screen->base);
439
440 lp_jit_screen_init(screen);
441
442 screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0;
443 #ifdef PIPE_SUBSYSTEM_EMBEDDED
444 screen->num_threads = 0;
445 #endif
446 screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads);
447 screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS);
448
449 screen->rast = lp_rast_create(screen->num_threads);
450 if (!screen->rast) {
451 lp_jit_screen_cleanup(screen);
452 FREE(screen);
453 return NULL;
454 }
455 pipe_mutex_init(screen->rast_mutex);
456
457 util_format_s3tc_init();
458
459 return &screen->base;
460 }