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/format/u_format.h"
33 #include "util/u_screen.h"
34 #include "util/u_string.h"
35 #include "util/format/u_format_s3tc.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_screen.h"
38 #include "draw/draw_context.h"
39 #include "gallivm/lp_bld_type.h"
40 #include "gallivm/lp_bld_nir.h"
41 #include "util/disk_cache.h"
42 #include "util/os_misc.h"
43 #include "util/os_time.h"
44 #include "lp_texture.h"
45 #include "lp_fence.h"
46 #include "lp_jit.h"
47 #include "lp_screen.h"
48 #include "lp_context.h"
49 #include "lp_debug.h"
50 #include "lp_public.h"
51 #include "lp_limits.h"
52 #include "lp_rast.h"
53 #include "lp_cs_tpool.h"
54 #include "lp_flush.h"
55
56 #include "frontend/sw_winsys.h"
57
58 #include "nir.h"
59
60 #ifdef DEBUG
61 int LP_DEBUG = 0;
62
63 static const struct debug_named_value lp_debug_flags[] = {
64 { "pipe", DEBUG_PIPE, NULL },
65 { "tgsi", DEBUG_TGSI, NULL },
66 { "tex", DEBUG_TEX, NULL },
67 { "setup", DEBUG_SETUP, NULL },
68 { "rast", DEBUG_RAST, NULL },
69 { "query", DEBUG_QUERY, NULL },
70 { "screen", DEBUG_SCREEN, NULL },
71 { "counters", DEBUG_COUNTERS, NULL },
72 { "scene", DEBUG_SCENE, NULL },
73 { "fence", DEBUG_FENCE, NULL },
74 { "no_fastpath", DEBUG_NO_FASTPATH, NULL },
75 { "linear", DEBUG_LINEAR, NULL },
76 { "linear2", DEBUG_LINEAR2, NULL },
77 { "mem", DEBUG_MEM, NULL },
78 { "fs", DEBUG_FS, NULL },
79 { "cs", DEBUG_CS, NULL },
80 { "tgsi_ir", DEBUG_TGSI_IR, NULL },
81 { "cache_stats", DEBUG_CACHE_STATS, NULL },
82 { "accurate_a0", DEBUG_ACCURATE_A0 },
83 DEBUG_NAMED_VALUE_END
84 };
85 #endif
86
87 int LP_PERF = 0;
88 static const struct debug_named_value lp_perf_flags[] = {
89 { "texmem", PERF_TEX_MEM, NULL },
90 { "no_mipmap", PERF_NO_MIPMAPS, NULL },
91 { "no_linear", PERF_NO_LINEAR, NULL },
92 { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL },
93 { "no_tex", PERF_NO_TEX, NULL },
94 { "no_blend", PERF_NO_BLEND, NULL },
95 { "no_depth", PERF_NO_DEPTH, NULL },
96 { "no_alphatest", PERF_NO_ALPHATEST, NULL },
97 { "no_rast_linear", PERF_NO_RAST_LINEAR, NULL },
98 { "no_shade", PERF_NO_SHADE, NULL },
99 DEBUG_NAMED_VALUE_END
100 };
101
102
103 static const char *
llvmpipe_get_vendor(struct pipe_screen * screen)104 llvmpipe_get_vendor(struct pipe_screen *screen)
105 {
106 return "Mesa/X.org";
107 }
108
109
110 static const char *
llvmpipe_get_name(struct pipe_screen * screen)111 llvmpipe_get_name(struct pipe_screen *screen)
112 {
113 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
114 return lscreen->renderer_string;
115 }
116
117
118 static int
llvmpipe_get_param(struct pipe_screen * screen,enum pipe_cap param)119 llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
120 {
121 switch (param) {
122 case PIPE_CAP_NPOT_TEXTURES:
123 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
124 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
125 case PIPE_CAP_ANISOTROPIC_FILTER:
126 return 1;
127 case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
128 case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
129 return 1;
130 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
131 return 1;
132 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
133 return PIPE_MAX_SO_BUFFERS;
134 case PIPE_CAP_POINT_SPRITE:
135 return 1;
136 case PIPE_CAP_MAX_RENDER_TARGETS:
137 return PIPE_MAX_COLOR_BUFS;
138 case PIPE_CAP_OCCLUSION_QUERY:
139 case PIPE_CAP_QUERY_TIMESTAMP:
140 case PIPE_CAP_QUERY_TIME_ELAPSED:
141 return 1;
142 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
143 return 1;
144 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
145 case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
146 return 1;
147 case PIPE_CAP_TEXTURE_SWIZZLE:
148 case PIPE_CAP_TEXTURE_SHADOW_LOD:
149 return 1;
150 case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
151 return 1 << (LP_MAX_TEXTURE_2D_LEVELS - 1);
152 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
153 return LP_MAX_TEXTURE_3D_LEVELS;
154 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
155 return LP_MAX_TEXTURE_CUBE_LEVELS;
156 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
157 return LP_MAX_TEXTURE_ARRAY_LAYERS;
158 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
159 return 1;
160 case PIPE_CAP_INDEP_BLEND_ENABLE:
161 return 1;
162 case PIPE_CAP_INDEP_BLEND_FUNC:
163 return 1;
164 case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
165 case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
166 case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
167 return 1;
168 case PIPE_CAP_PRIMITIVE_RESTART:
169 case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
170 return 1;
171 case PIPE_CAP_DEPTH_CLIP_DISABLE:
172 return 1;
173 case PIPE_CAP_DEPTH_CLAMP_ENABLE:
174 return 1;
175 case PIPE_CAP_SHADER_STENCIL_EXPORT:
176 return 1;
177 case PIPE_CAP_VS_INSTANCEID:
178 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
179 case PIPE_CAP_START_INSTANCE:
180 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
181 return 1;
182 case PIPE_CAP_SEAMLESS_CUBE_MAP:
183 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
184 return 1;
185 /* this is a lie could support arbitrary large offsets */
186 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
187 case PIPE_CAP_MIN_TEXEL_OFFSET:
188 return -32;
189 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
190 case PIPE_CAP_MAX_TEXEL_OFFSET:
191 return 31;
192 case PIPE_CAP_CONDITIONAL_RENDER:
193 case PIPE_CAP_TEXTURE_BARRIER:
194 return 1;
195 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
196 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
197 return 16*4;
198 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
199 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
200 return 1024;
201 case PIPE_CAP_MAX_VERTEX_STREAMS: {
202 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
203 return lscreen->use_tgsi ? 1 : 4;
204 }
205 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
206 return 2048;
207 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
208 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
209 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
210 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
211 return 1;
212 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
213 case PIPE_CAP_GLSL_FEATURE_LEVEL: {
214 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
215 return lscreen->use_tgsi ? 330 : 450;
216 }
217 case PIPE_CAP_COMPUTE:
218 return GALLIVM_COROUTINES;
219 case PIPE_CAP_USER_VERTEX_BUFFERS:
220 return 1;
221 case PIPE_CAP_TGSI_TEXCOORD:
222 case PIPE_CAP_DRAW_INDIRECT:
223 return 1;
224
225 case PIPE_CAP_CUBE_MAP_ARRAY:
226 return 1;
227 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
228 return 16;
229 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
230 return 64;
231 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
232 return 1;
233 /* Adressing that many 64bpp texels fits in an i32 so this is a reasonable value */
234 case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
235 return 134217728;
236 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
237 return 16;
238 case PIPE_CAP_TEXTURE_TRANSFER_MODES:
239 return 0;
240 case PIPE_CAP_MAX_VIEWPORTS:
241 return PIPE_MAX_VIEWPORTS;
242 case PIPE_CAP_ENDIANNESS:
243 return PIPE_ENDIAN_NATIVE;
244 case PIPE_CAP_TES_LAYER_VIEWPORT:
245 case PIPE_CAP_VS_LAYER_VIEWPORT:
246 return 1;
247 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
248 return 1;
249 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
250 return 4;
251 case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
252 return 1;
253 case PIPE_CAP_FS_FINE_DERIVATIVE:
254 return 1;
255 case PIPE_CAP_TGSI_TEX_TXF_LZ:
256 case PIPE_CAP_SAMPLER_VIEW_TARGET:
257 return 1;
258 case PIPE_CAP_FAKE_SW_MSAA: {
259 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
260 return lscreen->use_tgsi ? 1 : 0;
261 }
262 case PIPE_CAP_TEXTURE_QUERY_LOD:
263 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
264 case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
265 case PIPE_CAP_DOUBLES:
266 case PIPE_CAP_INT64:
267 case PIPE_CAP_INT64_DIVMOD:
268 case PIPE_CAP_QUERY_SO_OVERFLOW:
269 case PIPE_CAP_TGSI_DIV:
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_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_MAX_VARYINGS:
308 return 32;
309 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
310 return 16;
311 case PIPE_CAP_QUERY_BUFFER_OBJECT:
312 return 1;
313 case PIPE_CAP_DRAW_PARAMETERS:
314 return 1;
315 case PIPE_CAP_FBFETCH:
316 return 8;
317 case PIPE_CAP_FBFETCH_COHERENT:
318 case PIPE_CAP_FBFETCH_ZS:
319 case PIPE_CAP_MULTI_DRAW_INDIRECT:
320 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
321 return 1;
322 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
323 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
324 return 1;
325 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
326 return 32;
327 case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
328 return 8;
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_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
334 return 0;
335
336 case PIPE_CAP_SHAREABLE_SHADERS:
337 /* Can't expose shareable shaders because the draw shaders reference the
338 * draw module's state, which is per-context.
339 */
340 return 0;
341
342 case PIPE_CAP_MAX_GS_INVOCATIONS:
343 return 32;
344 case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
345 return LP_MAX_TGSI_SHADER_BUFFER_SIZE;
346 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
347 case PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE:
348 case PIPE_CAP_FS_FACE_IS_INTEGER_SYSVAL:
349 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
350 case PIPE_CAP_IMAGE_STORE_FORMATTED:
351 return 1;
352 #ifdef PIPE_MEMORY_FD
353 case PIPE_CAP_MEMOBJ:
354 return 1;
355 #endif
356 case PIPE_CAP_SAMPLER_REDUCTION_MINMAX:
357 case PIPE_CAP_TEXTURE_QUERY_SAMPLES:
358 case PIPE_CAP_SHADER_GROUP_VOTE:
359 case PIPE_CAP_SHADER_BALLOT:
360 case PIPE_CAP_LOAD_CONSTBUF:
361 case PIPE_CAP_TEXTURE_MULTISAMPLE:
362 case PIPE_CAP_SAMPLE_SHADING:
363 case PIPE_CAP_GL_SPIRV:
364 case PIPE_CAP_POST_DEPTH_COVERAGE:
365 case PIPE_CAP_PACKED_UNIFORMS: {
366 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
367 return !lscreen->use_tgsi;
368 }
369 default:
370 return u_pipe_screen_get_param_defaults(screen, param);
371 }
372 }
373
374 static int
llvmpipe_get_shader_param(struct pipe_screen * screen,enum pipe_shader_type shader,enum pipe_shader_cap param)375 llvmpipe_get_shader_param(struct pipe_screen *screen,
376 enum pipe_shader_type shader,
377 enum pipe_shader_cap param)
378 {
379 struct llvmpipe_screen *lscreen = llvmpipe_screen(screen);
380 switch(shader)
381 {
382 case PIPE_SHADER_COMPUTE:
383 if ((lscreen->allow_cl) && param == PIPE_SHADER_CAP_SUPPORTED_IRS)
384 return (1 << PIPE_SHADER_IR_TGSI) | (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_NIR_SERIALIZED);
385 FALLTHROUGH;
386 case PIPE_SHADER_FRAGMENT:
387 if (param == PIPE_SHADER_CAP_PREFERRED_IR) {
388 if (lscreen->use_tgsi)
389 return PIPE_SHADER_IR_TGSI;
390 else
391 return PIPE_SHADER_IR_NIR;
392 }
393
394 return gallivm_get_shader_param(param);
395 case PIPE_SHADER_TESS_CTRL:
396 case PIPE_SHADER_TESS_EVAL:
397 /* Tessellation shader needs llvm coroutines support */
398 if (!GALLIVM_COROUTINES || lscreen->use_tgsi)
399 return 0;
400 FALLTHROUGH;
401 case PIPE_SHADER_VERTEX:
402 case PIPE_SHADER_GEOMETRY:
403 if (param == PIPE_SHADER_CAP_PREFERRED_IR) {
404 if (lscreen->use_tgsi)
405 return PIPE_SHADER_IR_TGSI;
406 else
407 return PIPE_SHADER_IR_NIR;
408 }
409
410 switch (param) {
411 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
412 /* At this time, the draw module and llvmpipe driver only
413 * support vertex shader texture lookups when LLVM is enabled in
414 * the draw module.
415 */
416 if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
417 return PIPE_MAX_SAMPLERS;
418 else
419 return 0;
420 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
421 if (debug_get_bool_option("DRAW_USE_LLVM", TRUE))
422 return PIPE_MAX_SHADER_SAMPLER_VIEWS;
423 else
424 return 0;
425 default:
426 return draw_get_shader_param(shader, param);
427 }
428 default:
429 return 0;
430 }
431 }
432
433 static float
llvmpipe_get_paramf(struct pipe_screen * screen,enum pipe_capf param)434 llvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
435 {
436 switch (param) {
437 case PIPE_CAPF_MIN_LINE_WIDTH:
438 case PIPE_CAPF_MIN_LINE_WIDTH_AA:
439 case PIPE_CAPF_MIN_POINT_SIZE:
440 case PIPE_CAPF_MIN_POINT_SIZE_AA:
441 return 1;
442 case PIPE_CAPF_POINT_SIZE_GRANULARITY:
443 case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
444 return 0.1;
445 case PIPE_CAPF_MAX_LINE_WIDTH:
446 FALLTHROUGH;
447 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
448 return 255.0; /* arbitrary */
449 case PIPE_CAPF_MAX_POINT_SIZE:
450 FALLTHROUGH;
451 case PIPE_CAPF_MAX_POINT_SIZE_AA:
452 return LP_MAX_POINT_WIDTH; /* arbitrary */
453 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
454 return 16.0; /* not actually signficant at this time */
455 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
456 return 16.0; /* arbitrary */
457 case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
458 return 0.0;
459 case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
460 return 0.0;
461 case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
462 return 0.0;
463 }
464 /* should only get here on unhandled cases */
465 debug_printf("Unexpected PIPE_CAP %d query\n", param);
466 return 0.0;
467 }
468
469 static int
llvmpipe_get_compute_param(struct pipe_screen * _screen,enum pipe_shader_ir ir_type,enum pipe_compute_cap param,void * ret)470 llvmpipe_get_compute_param(struct pipe_screen *_screen,
471 enum pipe_shader_ir ir_type,
472 enum pipe_compute_cap param,
473 void *ret)
474 {
475 switch (param) {
476 case PIPE_COMPUTE_CAP_IR_TARGET:
477 return 0;
478 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
479 if (ret) {
480 uint64_t *grid_size = ret;
481 grid_size[0] = 65535;
482 grid_size[1] = 65535;
483 grid_size[2] = 65535;
484 }
485 return 3 * sizeof(uint64_t) ;
486 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
487 if (ret) {
488 uint64_t *block_size = ret;
489 block_size[0] = 1024;
490 block_size[1] = 1024;
491 block_size[2] = 1024;
492 }
493 return 3 * sizeof(uint64_t);
494 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
495 if (ret) {
496 uint64_t *max_threads_per_block = ret;
497 *max_threads_per_block = 1024;
498 }
499 return sizeof(uint64_t);
500 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
501 if (ret) {
502 uint64_t *max_local_size = ret;
503 *max_local_size = 32768;
504 }
505 return sizeof(uint64_t);
506 case PIPE_COMPUTE_CAP_GRID_DIMENSION:
507 if (ret) {
508 uint64_t *grid_dim = ret;
509 *grid_dim = 3;
510 }
511 return sizeof(uint64_t);
512 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
513 if (ret) {
514 uint64_t *max_global_size = ret;
515 *max_global_size = (1ULL << 31);
516 }
517 return sizeof(uint64_t);
518 case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
519 if (ret) {
520 uint64_t *max_mem_alloc_size = ret;
521 *max_mem_alloc_size = (1ULL << 31);
522 }
523 return sizeof(uint64_t);
524 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
525 if (ret) {
526 uint64_t *max_private = ret;
527 *max_private = (1UL << 31);
528 }
529 return sizeof(uint64_t);
530 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
531 if (ret) {
532 uint64_t *max_input = ret;
533 *max_input = 1576;
534 }
535 return sizeof(uint64_t);
536 case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
537 if (ret) {
538 uint32_t *images = ret;
539 *images = LP_MAX_TGSI_SHADER_IMAGES;
540 }
541 return sizeof(uint32_t);
542 case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
543 return 0;
544 case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
545 if (ret) {
546 uint32_t *subgroup_size = ret;
547 *subgroup_size = 32;
548 }
549 return sizeof(uint32_t);
550 case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
551 if (ret) {
552 uint32_t *max_compute_units = ret;
553 *max_compute_units = 8;
554 }
555 return sizeof(uint32_t);
556 case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
557 if (ret) {
558 uint32_t *max_clock_freq = ret;
559 *max_clock_freq = 300;
560 }
561 return sizeof(uint32_t);
562 case PIPE_COMPUTE_CAP_ADDRESS_BITS:
563 if (ret) {
564 uint32_t *address_bits = ret;
565 *address_bits = 64;
566 }
567 return sizeof(uint32_t);
568 }
569 return 0;
570 }
571
572 static void
llvmpipe_get_driver_uuid(struct pipe_screen * pscreen,char * uuid)573 llvmpipe_get_driver_uuid(struct pipe_screen *pscreen, char *uuid)
574 {
575 memset(uuid, 0, PIPE_UUID_SIZE);
576 snprintf(uuid, PIPE_UUID_SIZE, "llvmpipeUUID");
577 }
578
579 static void
llvmpipe_get_device_uuid(struct pipe_screen * pscreen,char * uuid)580 llvmpipe_get_device_uuid(struct pipe_screen *pscreen, char *uuid)
581 {
582 memset(uuid, 0, PIPE_UUID_SIZE);
583 snprintf(uuid, PIPE_UUID_SIZE, "mesa" PACKAGE_VERSION);
584 }
585
586 static const struct nir_shader_compiler_options gallivm_nir_options = {
587 .lower_scmp = true,
588 .lower_flrp32 = true,
589 .lower_flrp64 = true,
590 .lower_fsat = true,
591 .lower_bitfield_insert_to_shifts = true,
592 .lower_bitfield_extract_to_shifts = true,
593 .lower_fdot = true,
594 .lower_fdph = true,
595 .lower_ffma16 = true,
596 .lower_ffma32 = true,
597 .lower_ffma64 = true,
598 .lower_flrp16 = true,
599 .lower_fmod = true,
600 .lower_hadd = true,
601 .lower_uadd_sat = true,
602 .lower_usub_sat = true,
603 .lower_iadd_sat = true,
604 .lower_ldexp = true,
605 .lower_pack_snorm_2x16 = true,
606 .lower_pack_snorm_4x8 = true,
607 .lower_pack_unorm_2x16 = true,
608 .lower_pack_unorm_4x8 = true,
609 .lower_pack_half_2x16 = true,
610 .lower_pack_split = true,
611 .lower_unpack_snorm_2x16 = true,
612 .lower_unpack_snorm_4x8 = true,
613 .lower_unpack_unorm_2x16 = true,
614 .lower_unpack_unorm_4x8 = true,
615 .lower_unpack_half_2x16 = true,
616 .lower_extract_byte = true,
617 .lower_extract_word = true,
618 .lower_insert_byte = true,
619 .lower_insert_word = true,
620 .lower_rotate = true,
621 .lower_uadd_carry = true,
622 .lower_usub_borrow = true,
623 .lower_mul_2x32_64 = true,
624 .lower_ifind_msb = true,
625 .lower_int64_options = nir_lower_imul_2x32_64,
626 .max_unroll_iterations = 32,
627 .use_interpolated_input_intrinsics = true,
628 .lower_to_scalar = true,
629 .lower_uniforms_to_ubo = true,
630 .lower_vector_cmp = true,
631 .lower_device_index_to_zero = true,
632 .support_16bit_alu = true,
633 .lower_fisnormal = true,
634 .use_scoped_barrier = true,
635 };
636
637 static char *
llvmpipe_finalize_nir(struct pipe_screen * screen,void * nirptr)638 llvmpipe_finalize_nir(struct pipe_screen *screen,
639 void *nirptr)
640 {
641 struct nir_shader *nir = (struct nir_shader *)nirptr;
642 lp_build_opt_nir(nir);
643 return NULL;
644 }
645
646 static inline const void *
llvmpipe_get_compiler_options(struct pipe_screen * screen,enum pipe_shader_ir ir,enum pipe_shader_type shader)647 llvmpipe_get_compiler_options(struct pipe_screen *screen,
648 enum pipe_shader_ir ir,
649 enum pipe_shader_type shader)
650 {
651 assert(ir == PIPE_SHADER_IR_NIR);
652 return &gallivm_nir_options;
653 }
654
655 /**
656 * Query format support for creating a texture, drawing surface, etc.
657 * \param format the format to test
658 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
659 */
660 static bool
llvmpipe_is_format_supported(struct pipe_screen * _screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned bind)661 llvmpipe_is_format_supported( struct pipe_screen *_screen,
662 enum pipe_format format,
663 enum pipe_texture_target target,
664 unsigned sample_count,
665 unsigned storage_sample_count,
666 unsigned bind)
667 {
668 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
669 struct sw_winsys *winsys = screen->winsys;
670 const struct util_format_description *format_desc;
671
672 format_desc = util_format_description(format);
673
674 assert(target == PIPE_BUFFER ||
675 target == PIPE_TEXTURE_1D ||
676 target == PIPE_TEXTURE_1D_ARRAY ||
677 target == PIPE_TEXTURE_2D ||
678 target == PIPE_TEXTURE_2D_ARRAY ||
679 target == PIPE_TEXTURE_RECT ||
680 target == PIPE_TEXTURE_3D ||
681 target == PIPE_TEXTURE_CUBE ||
682 target == PIPE_TEXTURE_CUBE_ARRAY);
683
684 if (sample_count != 0 && sample_count != 1 && sample_count != 4)
685 return false;
686
687 if (bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SHADER_IMAGE)) {
688 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
689 /* this is a lie actually other formats COULD exist where we would fail */
690 if (format_desc->nr_channels < 3)
691 return false;
692 }
693 else if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB)
694 return false;
695
696 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN &&
697 format != PIPE_FORMAT_R11G11B10_FLOAT)
698 return false;
699
700 assert(format_desc->block.width == 1);
701 assert(format_desc->block.height == 1);
702
703 if (format_desc->is_mixed)
704 return false;
705
706 if (!format_desc->is_array && !format_desc->is_bitmask &&
707 format != PIPE_FORMAT_R11G11B10_FLOAT)
708 return false;
709 }
710
711 if (bind & PIPE_BIND_SHADER_IMAGE) {
712 switch (format) {
713 case PIPE_FORMAT_R32G32B32A32_FLOAT:
714 case PIPE_FORMAT_R16G16B16A16_FLOAT:
715 case PIPE_FORMAT_R32G32_FLOAT:
716 case PIPE_FORMAT_R16G16_FLOAT:
717 case PIPE_FORMAT_R11G11B10_FLOAT:
718 case PIPE_FORMAT_R32_FLOAT:
719 case PIPE_FORMAT_R16_FLOAT:
720 case PIPE_FORMAT_R32G32B32A32_UINT:
721 case PIPE_FORMAT_R16G16B16A16_UINT:
722 case PIPE_FORMAT_R10G10B10A2_UINT:
723 case PIPE_FORMAT_R8G8B8A8_UINT:
724 case PIPE_FORMAT_R32G32_UINT:
725 case PIPE_FORMAT_R16G16_UINT:
726 case PIPE_FORMAT_R8G8_UINT:
727 case PIPE_FORMAT_R32_UINT:
728 case PIPE_FORMAT_R16_UINT:
729 case PIPE_FORMAT_R8_UINT:
730 case PIPE_FORMAT_R32G32B32A32_SINT:
731 case PIPE_FORMAT_R16G16B16A16_SINT:
732 case PIPE_FORMAT_R8G8B8A8_SINT:
733 case PIPE_FORMAT_R32G32_SINT:
734 case PIPE_FORMAT_R16G16_SINT:
735 case PIPE_FORMAT_R8G8_SINT:
736 case PIPE_FORMAT_R32_SINT:
737 case PIPE_FORMAT_R16_SINT:
738 case PIPE_FORMAT_R8_SINT:
739 case PIPE_FORMAT_R16G16B16A16_UNORM:
740 case PIPE_FORMAT_R10G10B10A2_UNORM:
741 case PIPE_FORMAT_R8G8B8A8_UNORM:
742 case PIPE_FORMAT_R16G16_UNORM:
743 case PIPE_FORMAT_R8G8_UNORM:
744 case PIPE_FORMAT_R16_UNORM:
745 case PIPE_FORMAT_R8_UNORM:
746 case PIPE_FORMAT_R16G16B16A16_SNORM:
747 case PIPE_FORMAT_R8G8B8A8_SNORM:
748 case PIPE_FORMAT_R16G16_SNORM:
749 case PIPE_FORMAT_R8G8_SNORM:
750 case PIPE_FORMAT_R16_SNORM:
751 case PIPE_FORMAT_R8_SNORM:
752 case PIPE_FORMAT_B8G8R8A8_UNORM:
753 break;
754
755 default:
756 return false;
757 }
758 }
759
760 if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
761 ((bind & PIPE_BIND_DISPLAY_TARGET) == 0)) {
762 /* Disable all 3-channel formats, where channel size != 32 bits.
763 * In some cases we run into crashes (in generate_unswizzled_blend()),
764 * for 3-channel RGB16 variants, there was an apparent LLVM bug.
765 * In any case, disabling the shallower 3-channel formats avoids a
766 * number of issues with GL_ARB_copy_image support.
767 */
768 if (format_desc->is_array &&
769 format_desc->nr_channels == 3 &&
770 format_desc->block.bits != 96) {
771 return false;
772 }
773
774 /* Disable 64-bit integer formats for RT/samplers.
775 * VK CTS crashes with these and they don't make much sense.
776 */
777 int c = util_format_get_first_non_void_channel(format_desc->format);
778 if (c >= 0) {
779 if (format_desc->channel[c].pure_integer && format_desc->channel[c].size == 64)
780 return false;
781 }
782
783 }
784
785 if (!(bind & PIPE_BIND_VERTEX_BUFFER) &&
786 util_format_is_scaled(format))
787 return false;
788
789 if (bind & PIPE_BIND_DISPLAY_TARGET) {
790 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
791 return false;
792 }
793
794 if (bind & PIPE_BIND_DEPTH_STENCIL) {
795 if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
796 return false;
797
798 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
799 return false;
800 }
801
802 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC ||
803 format_desc->layout == UTIL_FORMAT_LAYOUT_ATC) {
804 /* Software decoding is not hooked up. */
805 return false;
806 }
807
808 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
809 format != PIPE_FORMAT_ETC1_RGB8)
810 return false;
811
812 /*
813 * Everything can be supported by u_format
814 * (those without fetch_rgba_float might be not but shouldn't hit that)
815 */
816
817 return true;
818 }
819
820
821
822
823 static void
llvmpipe_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_context * _pipe,struct pipe_resource * resource,unsigned level,unsigned layer,void * context_private,struct pipe_box * sub_box)824 llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
825 struct pipe_context *_pipe,
826 struct pipe_resource *resource,
827 unsigned level, unsigned layer,
828 void *context_private,
829 struct pipe_box *sub_box)
830 {
831 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
832 struct sw_winsys *winsys = screen->winsys;
833 struct llvmpipe_resource *texture = llvmpipe_resource(resource);
834
835 assert(texture->dt);
836
837 if (texture->dt) {
838 if (_pipe)
839 llvmpipe_flush_resource(_pipe, resource, 0, true, true, false, "frontbuffer");
840 winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box);
841 }
842 }
843
844 static void
llvmpipe_destroy_screen(struct pipe_screen * _screen)845 llvmpipe_destroy_screen( struct pipe_screen *_screen )
846 {
847 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
848 struct sw_winsys *winsys = screen->winsys;
849
850 if (screen->cs_tpool)
851 lp_cs_tpool_destroy(screen->cs_tpool);
852
853 if (screen->rast)
854 lp_rast_destroy(screen->rast);
855
856 lp_jit_screen_cleanup(screen);
857
858 if (LP_DEBUG & DEBUG_CACHE_STATS)
859 printf("disk shader cache: hits = %u, misses = %u\n", screen->num_disk_shader_cache_hits,
860 screen->num_disk_shader_cache_misses);
861 disk_cache_destroy(screen->disk_shader_cache);
862 if(winsys->destroy)
863 winsys->destroy(winsys);
864
865 glsl_type_singleton_decref();
866
867 mtx_destroy(&screen->rast_mutex);
868 mtx_destroy(&screen->cs_mutex);
869 FREE(screen);
870 }
871
872
873
874
875 /**
876 * Fence reference counting.
877 */
878 static void
llvmpipe_fence_reference(struct pipe_screen * screen,struct pipe_fence_handle ** ptr,struct pipe_fence_handle * fence)879 llvmpipe_fence_reference(struct pipe_screen *screen,
880 struct pipe_fence_handle **ptr,
881 struct pipe_fence_handle *fence)
882 {
883 struct lp_fence **old = (struct lp_fence **) ptr;
884 struct lp_fence *f = (struct lp_fence *) fence;
885
886 lp_fence_reference(old, f);
887 }
888
889
890 /**
891 * Wait for the fence to finish.
892 */
893 static bool
llvmpipe_fence_finish(struct pipe_screen * screen,struct pipe_context * ctx,struct pipe_fence_handle * fence_handle,uint64_t timeout)894 llvmpipe_fence_finish(struct pipe_screen *screen,
895 struct pipe_context *ctx,
896 struct pipe_fence_handle *fence_handle,
897 uint64_t timeout)
898 {
899 struct lp_fence *f = (struct lp_fence *) fence_handle;
900
901 if (!timeout)
902 return lp_fence_signalled(f);
903
904 if (!lp_fence_signalled(f)) {
905 if (timeout != PIPE_TIMEOUT_INFINITE)
906 return lp_fence_timedwait(f, timeout);
907
908 lp_fence_wait(f);
909 }
910 return true;
911 }
912
913 static uint64_t
llvmpipe_get_timestamp(struct pipe_screen * _screen)914 llvmpipe_get_timestamp(struct pipe_screen *_screen)
915 {
916 return os_time_get_nano();
917 }
918
update_cache_sha1_cpu(struct mesa_sha1 * ctx)919 static void update_cache_sha1_cpu(struct mesa_sha1 *ctx)
920 {
921 const struct util_cpu_caps_t *cpu_caps = util_get_cpu_caps();
922 /*
923 * Don't need the cpu cache affinity stuff. The rest
924 * is contained in first 5 dwords.
925 */
926 STATIC_ASSERT(offsetof(struct util_cpu_caps_t, num_L3_caches) == 6 * sizeof(uint32_t));
927 _mesa_sha1_update(ctx, cpu_caps, 6 * sizeof(uint32_t));
928 }
929
lp_disk_cache_create(struct llvmpipe_screen * screen)930 static void lp_disk_cache_create(struct llvmpipe_screen *screen)
931 {
932 struct mesa_sha1 ctx;
933 unsigned gallivm_perf = gallivm_get_perf_flags();
934 unsigned char sha1[20];
935 char cache_id[20 * 2 + 1];
936 _mesa_sha1_init(&ctx);
937
938 if (!disk_cache_get_function_identifier(lp_disk_cache_create, &ctx) ||
939 !disk_cache_get_function_identifier(LLVMLinkInMCJIT, &ctx))
940 return;
941
942 _mesa_sha1_update(&ctx, &gallivm_perf, sizeof(gallivm_perf));
943 update_cache_sha1_cpu(&ctx);
944 _mesa_sha1_final(&ctx, sha1);
945 disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
946
947 screen->disk_shader_cache = disk_cache_create("llvmpipe", cache_id, 0);
948 }
949
lp_get_disk_shader_cache(struct pipe_screen * _screen)950 static struct disk_cache *lp_get_disk_shader_cache(struct pipe_screen *_screen)
951 {
952 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
953
954 return screen->disk_shader_cache;
955 }
956
lp_disk_cache_find_shader(struct llvmpipe_screen * screen,struct lp_cached_code * cache,unsigned char ir_sha1_cache_key[20])957 void lp_disk_cache_find_shader(struct llvmpipe_screen *screen,
958 struct lp_cached_code *cache,
959 unsigned char ir_sha1_cache_key[20])
960 {
961 unsigned char sha1[CACHE_KEY_SIZE];
962
963 if (!screen->disk_shader_cache)
964 return;
965 disk_cache_compute_key(screen->disk_shader_cache, ir_sha1_cache_key, 20, sha1);
966
967 size_t binary_size;
968 uint8_t *buffer = disk_cache_get(screen->disk_shader_cache, sha1, &binary_size);
969 if (!buffer) {
970 cache->data_size = 0;
971 p_atomic_inc(&screen->num_disk_shader_cache_misses);
972 return;
973 }
974 cache->data_size = binary_size;
975 cache->data = buffer;
976 p_atomic_inc(&screen->num_disk_shader_cache_hits);
977 }
978
lp_disk_cache_insert_shader(struct llvmpipe_screen * screen,struct lp_cached_code * cache,unsigned char ir_sha1_cache_key[20])979 void lp_disk_cache_insert_shader(struct llvmpipe_screen *screen,
980 struct lp_cached_code *cache,
981 unsigned char ir_sha1_cache_key[20])
982 {
983 unsigned char sha1[CACHE_KEY_SIZE];
984
985 if (!screen->disk_shader_cache || !cache->data_size || cache->dont_cache)
986 return;
987 disk_cache_compute_key(screen->disk_shader_cache, ir_sha1_cache_key, 20, sha1);
988 disk_cache_put(screen->disk_shader_cache, sha1, cache->data, cache->data_size, NULL);
989 }
990
991 bool
llvmpipe_screen_late_init(struct llvmpipe_screen * screen)992 llvmpipe_screen_late_init(struct llvmpipe_screen *screen)
993 {
994 bool ret = true;
995 mtx_lock(&screen->late_mutex);
996
997 if (screen->late_init_done)
998 goto out;
999
1000 screen->rast = lp_rast_create(screen->num_threads);
1001 if (!screen->rast) {
1002 ret = false;
1003 goto out;
1004 }
1005
1006 screen->cs_tpool = lp_cs_tpool_create(screen->num_threads);
1007 if (!screen->cs_tpool) {
1008 lp_rast_destroy(screen->rast);
1009 ret = false;
1010 goto out;
1011 }
1012
1013 lp_disk_cache_create(screen);
1014 screen->late_init_done = true;
1015 out:
1016 mtx_unlock(&screen->late_mutex);
1017 return ret;
1018 }
1019
1020 /**
1021 * Create a new pipe_screen object
1022 * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen).
1023 */
1024 struct pipe_screen *
llvmpipe_create_screen(struct sw_winsys * winsys)1025 llvmpipe_create_screen(struct sw_winsys *winsys)
1026 {
1027 struct llvmpipe_screen *screen;
1028
1029 glsl_type_singleton_init_or_ref();
1030
1031 #ifdef DEBUG
1032 LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 );
1033 #endif
1034
1035 LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 );
1036
1037 screen = CALLOC_STRUCT(llvmpipe_screen);
1038 if (!screen)
1039 return NULL;
1040
1041 if (!lp_jit_screen_init(screen)) {
1042 FREE(screen);
1043 return NULL;
1044 }
1045
1046 screen->winsys = winsys;
1047
1048 screen->base.destroy = llvmpipe_destroy_screen;
1049
1050 screen->base.get_name = llvmpipe_get_name;
1051 screen->base.get_vendor = llvmpipe_get_vendor;
1052 screen->base.get_device_vendor = llvmpipe_get_vendor; // TODO should be the CPU vendor
1053 screen->base.get_param = llvmpipe_get_param;
1054 screen->base.get_shader_param = llvmpipe_get_shader_param;
1055 screen->base.get_compute_param = llvmpipe_get_compute_param;
1056 screen->base.get_paramf = llvmpipe_get_paramf;
1057 screen->base.get_compiler_options = llvmpipe_get_compiler_options;
1058 screen->base.is_format_supported = llvmpipe_is_format_supported;
1059
1060 screen->base.context_create = llvmpipe_create_context;
1061 screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
1062 screen->base.fence_reference = llvmpipe_fence_reference;
1063 screen->base.fence_finish = llvmpipe_fence_finish;
1064
1065 screen->base.get_timestamp = llvmpipe_get_timestamp;
1066
1067 screen->base.get_driver_uuid = llvmpipe_get_driver_uuid;
1068 screen->base.get_device_uuid = llvmpipe_get_device_uuid;
1069
1070 screen->base.finalize_nir = llvmpipe_finalize_nir;
1071
1072 screen->base.get_disk_shader_cache = lp_get_disk_shader_cache;
1073 llvmpipe_init_screen_resource_funcs(&screen->base);
1074
1075 screen->allow_cl = !!getenv("LP_CL");
1076 screen->use_tgsi = (LP_DEBUG & DEBUG_TGSI_IR);
1077 screen->num_threads = util_get_cpu_caps()->nr_cpus > 1 ? util_get_cpu_caps()->nr_cpus : 0;
1078 #ifdef EMBEDDED_DEVICE
1079 screen->num_threads = MIN2(screen->num_threads, 2);
1080 #endif
1081 screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads);
1082 screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS);
1083
1084 lp_build_init(); /* get lp_native_vector_width initialised */
1085
1086 snprintf(screen->renderer_string, sizeof(screen->renderer_string), "llvmpipe (LLVM " MESA_LLVM_VERSION_STRING ", %u bits)", lp_native_vector_width );
1087
1088 list_inithead(&screen->ctx_list);
1089 (void) mtx_init(&screen->ctx_mutex, mtx_plain);
1090 (void) mtx_init(&screen->cs_mutex, mtx_plain);
1091 (void) mtx_init(&screen->rast_mutex, mtx_plain);
1092
1093 (void) mtx_init(&screen->late_mutex, mtx_plain);
1094
1095 return &screen->base;
1096 }
1097