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