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