1 /**************************************************************************
2 *
3 * Copyright 2008 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
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 #include "gallivm/lp_bld_type.h"
39
40 #include "os/os_misc.h"
41 #include "os/os_time.h"
42 #include "lp_texture.h"
43 #include "lp_fence.h"
44 #include "lp_jit.h"
45 #include "lp_screen.h"
46 #include "lp_context.h"
47 #include "lp_debug.h"
48 #include "lp_public.h"
49 #include "lp_limits.h"
50 #include "lp_rast.h"
51
52 #include "state_tracker/sw_winsys.h"
53
54 #ifdef DEBUG
55 int LP_DEBUG = 0;
56
57 static const struct debug_named_value lp_debug_flags[] = {
58 { "pipe", DEBUG_PIPE, NULL },
59 { "tgsi", DEBUG_TGSI, NULL },
60 { "tex", DEBUG_TEX, NULL },
61 { "setup", DEBUG_SETUP, NULL },
62 { "rast", DEBUG_RAST, NULL },
63 { "query", DEBUG_QUERY, NULL },
64 { "screen", DEBUG_SCREEN, NULL },
65 { "counters", DEBUG_COUNTERS, NULL },
66 { "scene", DEBUG_SCENE, NULL },
67 { "fence", DEBUG_FENCE, NULL },
68 { "mem", DEBUG_MEM, NULL },
69 { "fs", DEBUG_FS, NULL },
70 DEBUG_NAMED_VALUE_END
71 };
72 #endif
73
74 int LP_PERF = 0;
75 static const struct debug_named_value lp_perf_flags[] = {
76 { "texmem", PERF_TEX_MEM, NULL },
77 { "no_mipmap", PERF_NO_MIPMAPS, NULL },
78 { "no_linear", PERF_NO_LINEAR, NULL },
79 { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL },
80 { "no_tex", PERF_NO_TEX, NULL },
81 { "no_blend", PERF_NO_BLEND, NULL },
82 { "no_depth", PERF_NO_DEPTH, NULL },
83 { "no_alphatest", PERF_NO_ALPHATEST, NULL },
84 DEBUG_NAMED_VALUE_END
85 };
86
87
88 static const char *
llvmpipe_get_vendor(struct pipe_screen * screen)89 llvmpipe_get_vendor(struct pipe_screen *screen)
90 {
91 return "VMware, Inc.";
92 }
93
94
95 static const char *
llvmpipe_get_name(struct pipe_screen * screen)96 llvmpipe_get_name(struct pipe_screen *screen)
97 {
98 static char buf[100];
99 util_snprintf(buf, sizeof(buf), "llvmpipe (LLVM %u.%u, %u bits)",
100 HAVE_LLVM >> 8, HAVE_LLVM & 0xff,
101 lp_native_vector_width );
102 return buf;
103 }
104
105
106 static int
llvmpipe_get_param(struct pipe_screen * screen,enum pipe_cap param)107 llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
108 {
109 switch (param) {
110 case PIPE_CAP_NPOT_TEXTURES:
111 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
112 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
113 return 1;
114 case PIPE_CAP_TWO_SIDED_STENCIL:
115 return 1;
116 case PIPE_CAP_SM3:
117 return 1;
118 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
119 return 1;
120 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
121 return PIPE_MAX_SO_BUFFERS;
122 case PIPE_CAP_ANISOTROPIC_FILTER:
123 return 0;
124 case PIPE_CAP_POINT_SPRITE:
125 return 1;
126 case PIPE_CAP_MAX_RENDER_TARGETS:
127 return PIPE_MAX_COLOR_BUFS;
128 case PIPE_CAP_OCCLUSION_QUERY:
129 return 1;
130 case PIPE_CAP_QUERY_TIME_ELAPSED:
131 return 0;
132 case PIPE_CAP_QUERY_TIMESTAMP:
133 return 1;
134 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
135 return 0;
136 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
137 return 1;
138 case PIPE_CAP_TEXTURE_SHADOW_MAP:
139 return 1;
140 case PIPE_CAP_TEXTURE_SWIZZLE:
141 return 1;
142 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
143 return 0;
144 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
145 return LP_MAX_TEXTURE_2D_LEVELS;
146 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
147 return LP_MAX_TEXTURE_3D_LEVELS;
148 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
149 return LP_MAX_TEXTURE_CUBE_LEVELS;
150 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
151 return LP_MAX_TEXTURE_ARRAY_LAYERS;
152 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
153 return 1;
154 case PIPE_CAP_INDEP_BLEND_ENABLE:
155 return 1;
156 case PIPE_CAP_INDEP_BLEND_FUNC:
157 return 1;
158 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
159 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
160 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
161 return 1;
162 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
163 return 0;
164 case PIPE_CAP_PRIMITIVE_RESTART:
165 return 1;
166 case PIPE_CAP_DEPTH_CLIP_DISABLE:
167 return 1;
168 case PIPE_CAP_SHADER_STENCIL_EXPORT:
169 return 1;
170 case PIPE_CAP_TGSI_INSTANCEID:
171 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
172 case PIPE_CAP_START_INSTANCE:
173 return 1;
174 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
175 return 0;
176 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
177 return 1;
178 case PIPE_CAP_SEAMLESS_CUBE_MAP:
179 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
180 return 1;
181 /* this is a lie could support arbitrary large offsets */
182 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
183 case PIPE_CAP_MIN_TEXEL_OFFSET:
184 return -32;
185 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
186 case PIPE_CAP_MAX_TEXEL_OFFSET:
187 return 31;
188 case PIPE_CAP_CONDITIONAL_RENDER:
189 return 1;
190 case PIPE_CAP_TEXTURE_BARRIER:
191 return 0;
192 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
193 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
194 return 16*4;
195 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
196 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
197 return 1024;
198 case PIPE_CAP_MAX_VERTEX_STREAMS:
199 return 1;
200 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
201 return 2048;
202 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
203 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
204 return 1;
205 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
206 return 0;
207 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
208 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
209 return 1;
210 case PIPE_CAP_GLSL_FEATURE_LEVEL:
211 return 330;
212 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
213 return 0;
214 case PIPE_CAP_COMPUTE:
215 return 0;
216 case PIPE_CAP_USER_VERTEX_BUFFERS:
217 case PIPE_CAP_USER_INDEX_BUFFERS:
218 return 1;
219 case PIPE_CAP_USER_CONSTANT_BUFFERS:
220 return 0;
221 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
222 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
223 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
224 case PIPE_CAP_TGSI_TEXCOORD:
225 return 0;
226 case PIPE_CAP_DRAW_INDIRECT:
227 return 1;
228
229 case PIPE_CAP_CUBE_MAP_ARRAY:
230 return 1;
231 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
232 return 16;
233 case PIPE_CAP_TEXTURE_MULTISAMPLE:
234 return 0;
235 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
236 return 64;
237 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
238 return 1;
239 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
240 return 65536;
241 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
242 return 1;
243 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
244 return 0;
245 case PIPE_CAP_MAX_VIEWPORTS:
246 return PIPE_MAX_VIEWPORTS;
247 case PIPE_CAP_ENDIANNESS:
248 return PIPE_ENDIAN_NATIVE;
249 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
250 return 1;
251 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
252 return 1;
253 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
254 return 4;
255 case PIPE_CAP_TEXTURE_GATHER_SM5:
256 case PIPE_CAP_TEXTURE_QUERY_LOD:
257 case PIPE_CAP_SAMPLE_SHADING:
258 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
259 return 0;
260 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
261 return 1;
262 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
263 return 0;
264 case PIPE_CAP_SAMPLER_VIEW_TARGET:
265 return 1;
266 case PIPE_CAP_FAKE_SW_MSAA:
267 return 1;
268 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
269 case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
270 return 1;
271
272 case PIPE_CAP_VENDOR_ID:
273 return 0xFFFFFFFF;
274 case PIPE_CAP_DEVICE_ID:
275 return 0xFFFFFFFF;
276 case PIPE_CAP_ACCELERATED:
277 return 0;
278 case PIPE_CAP_VIDEO_MEMORY: {
279 /* XXX: Do we want to return the full amount fo system memory ? */
280 uint64_t system_memory;
281
282 if (!os_get_total_physical_memory(&system_memory))
283 return 0;
284
285 if (sizeof(void *) == 4)
286 /* Cap to 2 GB on 32 bits system. We do this because llvmpipe does
287 * eat application memory, which is quite limited on 32 bits. App
288 * shouldn't expect too much available memory. */
289 system_memory = MIN2(system_memory, 2048 << 20);
290
291 return (int)(system_memory >> 20);
292 }
293 case PIPE_CAP_UMA:
294 return 0;
295 case PIPE_CAP_CLIP_HALFZ:
296 return 1;
297 case PIPE_CAP_VERTEXID_NOBASE:
298 return 0;
299 case PIPE_CAP_POLYGON_OFFSET_CLAMP:
300 case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
301 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
302 return 1;
303 case PIPE_CAP_CULL_DISTANCE:
304 return 1;
305 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
306 return 1;
307 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
308 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
309 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
310 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
311 case PIPE_CAP_DEPTH_BOUNDS_TEST:
312 case PIPE_CAP_TGSI_TXQS:
313 case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
314 case PIPE_CAP_SHAREABLE_SHADERS:
315 case PIPE_CAP_CLEAR_TEXTURE:
316 case PIPE_CAP_DRAW_PARAMETERS:
317 case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
318 case PIPE_CAP_MULTI_DRAW_INDIRECT:
319 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
320 case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
321 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
322 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
323 case PIPE_CAP_INVALIDATE_BUFFER:
324 case PIPE_CAP_GENERATE_MIPMAP:
325 case PIPE_CAP_STRING_MARKER:
326 case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
327 case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
328 case PIPE_CAP_QUERY_BUFFER_OBJECT:
329 case PIPE_CAP_QUERY_MEMORY_INFO:
330 case PIPE_CAP_PCI_GROUP:
331 case PIPE_CAP_PCI_BUS:
332 case PIPE_CAP_PCI_DEVICE:
333 case PIPE_CAP_PCI_FUNCTION:
334 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
335 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
336 case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
337 case PIPE_CAP_TGSI_VOTE:
338 case PIPE_CAP_MAX_WINDOW_RECTANGLES:
339 case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
340 case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
341 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
342 case PIPE_CAP_NATIVE_FENCE_FD:
343 case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
344 case PIPE_CAP_TGSI_FS_FBFETCH:
345 return 0;
346 }
347 /* should only get here on unhandled cases */
348 debug_printf("Unexpected PIPE_CAP %d query\n", param);
349 return 0;
350 }
351
352 static int
llvmpipe_get_shader_param(struct pipe_screen * screen,unsigned shader,enum pipe_shader_cap param)353 llvmpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param)
354 {
355 switch(shader)
356 {
357 case PIPE_SHADER_FRAGMENT:
358 switch (param) {
359 default:
360 return gallivm_get_shader_param(param);
361 }
362 case PIPE_SHADER_VERTEX:
363 case PIPE_SHADER_GEOMETRY:
364 switch (param) {
365 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
366 /* At this time, the draw module and llvmpipe driver only
367 * support vertex shader texture lookups when LLVM is enabled in
368 * the draw module.
369 */
370 if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
371 return PIPE_MAX_SAMPLERS;
372 else
373 return 0;
374 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
375 if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
376 return PIPE_MAX_SHADER_SAMPLER_VIEWS;
377 else
378 return 0;
379 default:
380 return draw_get_shader_param(shader, param);
381 }
382 default:
383 return 0;
384 }
385 }
386
387 static float
llvmpipe_get_paramf(struct pipe_screen * screen,enum pipe_capf param)388 llvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
389 {
390 switch (param) {
391 case PIPE_CAPF_MAX_LINE_WIDTH:
392 /* fall-through */
393 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
394 return 255.0; /* arbitrary */
395 case PIPE_CAPF_MAX_POINT_WIDTH:
396 /* fall-through */
397 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
398 return 255.0; /* arbitrary */
399 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
400 return 16.0; /* not actually signficant at this time */
401 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
402 return 16.0; /* arbitrary */
403 case PIPE_CAPF_GUARD_BAND_LEFT:
404 case PIPE_CAPF_GUARD_BAND_TOP:
405 case PIPE_CAPF_GUARD_BAND_RIGHT:
406 case PIPE_CAPF_GUARD_BAND_BOTTOM:
407 return 0.0;
408 }
409 /* should only get here on unhandled cases */
410 debug_printf("Unexpected PIPE_CAP %d query\n", param);
411 return 0.0;
412 }
413
414
415 /**
416 * Query format support for creating a texture, drawing surface, etc.
417 * \param format the format to test
418 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
419 */
420 static boolean
llvmpipe_is_format_supported(struct pipe_screen * _screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned bind)421 llvmpipe_is_format_supported( struct pipe_screen *_screen,
422 enum pipe_format format,
423 enum pipe_texture_target target,
424 unsigned sample_count,
425 unsigned bind)
426 {
427 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
428 struct sw_winsys *winsys = screen->winsys;
429 const struct util_format_description *format_desc;
430
431 format_desc = util_format_description(format);
432 if (!format_desc)
433 return FALSE;
434
435 assert(target == PIPE_BUFFER ||
436 target == PIPE_TEXTURE_1D ||
437 target == PIPE_TEXTURE_1D_ARRAY ||
438 target == PIPE_TEXTURE_2D ||
439 target == PIPE_TEXTURE_2D_ARRAY ||
440 target == PIPE_TEXTURE_RECT ||
441 target == PIPE_TEXTURE_3D ||
442 target == PIPE_TEXTURE_CUBE ||
443 target == PIPE_TEXTURE_CUBE_ARRAY);
444
445 if (sample_count > 1)
446 return FALSE;
447
448 if (bind & PIPE_BIND_RENDER_TARGET) {
449 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
450 /* this is a lie actually other formats COULD exist where we would fail */
451 if (format_desc->nr_channels < 3)
452 return FALSE;
453 }
454 else if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB)
455 return FALSE;
456
457 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN &&
458 format != PIPE_FORMAT_R11G11B10_FLOAT)
459 return FALSE;
460
461 assert(format_desc->block.width == 1);
462 assert(format_desc->block.height == 1);
463
464 if (format_desc->is_mixed)
465 return FALSE;
466
467 if (!format_desc->is_array && !format_desc->is_bitmask &&
468 format != PIPE_FORMAT_R11G11B10_FLOAT)
469 return FALSE;
470 }
471
472 if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
473 ((bind & PIPE_BIND_DISPLAY_TARGET) == 0)) {
474 /* Disable all 3-channel formats, where channel size != 32 bits.
475 * In some cases we run into crashes (in generate_unswizzled_blend()),
476 * for 3-channel RGB16 variants, there was an apparent LLVM bug.
477 * In any case, disabling the shallower 3-channel formats avoids a
478 * number of issues with GL_ARB_copy_image support.
479 */
480 if (format_desc->is_array &&
481 format_desc->nr_channels == 3 &&
482 format_desc->block.bits != 96) {
483 return FALSE;
484 }
485 }
486
487 if (bind & PIPE_BIND_DISPLAY_TARGET) {
488 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
489 return FALSE;
490 }
491
492 if (bind & PIPE_BIND_DEPTH_STENCIL) {
493 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
494 return FALSE;
495
496 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
497 return FALSE;
498
499 /* TODO: Support stencil-only formats */
500 if (format_desc->swizzle[0] == PIPE_SWIZZLE_NONE) {
501 return FALSE;
502 }
503 }
504
505 if (format_desc->layout == UTIL_FORMAT_LAYOUT_BPTC ||
506 format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
507 /* Software decoding is not hooked up. */
508 return FALSE;
509 }
510
511 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
512 format != PIPE_FORMAT_ETC1_RGB8)
513 return FALSE;
514
515 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
516 return util_format_s3tc_enabled;
517 }
518
519 /*
520 * Everything can be supported by u_format
521 * (those without fetch_rgba_float might be not but shouldn't hit that)
522 */
523
524 return TRUE;
525 }
526
527
528
529
530 static void
llvmpipe_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_resource * resource,unsigned level,unsigned layer,void * context_private,struct pipe_box * sub_box)531 llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
532 struct pipe_resource *resource,
533 unsigned level, unsigned layer,
534 void *context_private,
535 struct pipe_box *sub_box)
536 {
537 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
538 struct sw_winsys *winsys = screen->winsys;
539 struct llvmpipe_resource *texture = llvmpipe_resource(resource);
540
541 assert(texture->dt);
542 if (texture->dt)
543 winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box);
544 }
545
546 static void
llvmpipe_destroy_screen(struct pipe_screen * _screen)547 llvmpipe_destroy_screen( struct pipe_screen *_screen )
548 {
549 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
550 struct sw_winsys *winsys = screen->winsys;
551
552 if (screen->rast)
553 lp_rast_destroy(screen->rast);
554
555 lp_jit_screen_cleanup(screen);
556
557 if(winsys->destroy)
558 winsys->destroy(winsys);
559
560 pipe_mutex_destroy(screen->rast_mutex);
561
562 FREE(screen);
563 }
564
565
566
567
568 /**
569 * Fence reference counting.
570 */
571 static void
llvmpipe_fence_reference(struct pipe_screen * screen,struct pipe_fence_handle ** ptr,struct pipe_fence_handle * fence)572 llvmpipe_fence_reference(struct pipe_screen *screen,
573 struct pipe_fence_handle **ptr,
574 struct pipe_fence_handle *fence)
575 {
576 struct lp_fence **old = (struct lp_fence **) ptr;
577 struct lp_fence *f = (struct lp_fence *) fence;
578
579 lp_fence_reference(old, f);
580 }
581
582
583 /**
584 * Wait for the fence to finish.
585 */
586 static boolean
llvmpipe_fence_finish(struct pipe_screen * screen,struct pipe_context * ctx,struct pipe_fence_handle * fence_handle,uint64_t timeout)587 llvmpipe_fence_finish(struct pipe_screen *screen,
588 struct pipe_context *ctx,
589 struct pipe_fence_handle *fence_handle,
590 uint64_t timeout)
591 {
592 struct lp_fence *f = (struct lp_fence *) fence_handle;
593
594 if (!timeout)
595 return lp_fence_signalled(f);
596
597 lp_fence_wait(f);
598 return TRUE;
599 }
600
601 static uint64_t
llvmpipe_get_timestamp(struct pipe_screen * _screen)602 llvmpipe_get_timestamp(struct pipe_screen *_screen)
603 {
604 return os_time_get_nano();
605 }
606
607 /**
608 * Create a new pipe_screen object
609 * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen).
610 */
611 struct pipe_screen *
llvmpipe_create_screen(struct sw_winsys * winsys)612 llvmpipe_create_screen(struct sw_winsys *winsys)
613 {
614 struct llvmpipe_screen *screen;
615
616 util_cpu_detect();
617
618 #ifdef DEBUG
619 LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 );
620 #endif
621
622 LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 );
623
624 screen = CALLOC_STRUCT(llvmpipe_screen);
625 if (!screen)
626 return NULL;
627
628 if (!lp_jit_screen_init(screen)) {
629 FREE(screen);
630 return NULL;
631 }
632
633 screen->winsys = winsys;
634
635 screen->base.destroy = llvmpipe_destroy_screen;
636
637 screen->base.get_name = llvmpipe_get_name;
638 screen->base.get_vendor = llvmpipe_get_vendor;
639 screen->base.get_device_vendor = llvmpipe_get_vendor; // TODO should be the CPU vendor
640 screen->base.get_param = llvmpipe_get_param;
641 screen->base.get_shader_param = llvmpipe_get_shader_param;
642 screen->base.get_paramf = llvmpipe_get_paramf;
643 screen->base.is_format_supported = llvmpipe_is_format_supported;
644
645 screen->base.context_create = llvmpipe_create_context;
646 screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
647 screen->base.fence_reference = llvmpipe_fence_reference;
648 screen->base.fence_finish = llvmpipe_fence_finish;
649
650 screen->base.get_timestamp = llvmpipe_get_timestamp;
651
652 llvmpipe_init_screen_resource_funcs(&screen->base);
653
654 screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0;
655 #ifdef PIPE_SUBSYSTEM_EMBEDDED
656 screen->num_threads = 0;
657 #endif
658 screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads);
659 screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS);
660
661 screen->rast = lp_rast_create(screen->num_threads);
662 if (!screen->rast) {
663 lp_jit_screen_cleanup(screen);
664 FREE(screen);
665 return NULL;
666 }
667 pipe_mutex_init(screen->rast_mutex);
668
669 util_format_s3tc_init();
670
671 return &screen->base;
672 }
673