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_format.h" 31#include "util/u_format_s3tc.h" 32#include "util/u_screen.h" 33#include "util/u_video.h" 34#include "util/os_misc.h" 35#include "util/os_time.h" 36#include "pipe/p_defines.h" 37#include "pipe/p_screen.h" 38#include "draw/draw_context.h" 39 40#include "state_tracker/sw_winsys.h" 41#include "tgsi/tgsi_exec.h" 42 43#include "sp_texture.h" 44#include "sp_screen.h" 45#include "sp_context.h" 46#include "sp_fence.h" 47#include "sp_public.h" 48 49DEBUG_GET_ONCE_BOOL_OPTION(use_llvm, "SOFTPIPE_USE_LLVM", FALSE) 50 51static const char * 52softpipe_get_vendor(struct pipe_screen *screen) 53{ 54 return "VMware, Inc."; 55} 56 57 58static const char * 59softpipe_get_name(struct pipe_screen *screen) 60{ 61 return "softpipe"; 62} 63 64 65static int 66softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) 67{ 68 struct softpipe_screen *sp_screen = softpipe_screen(screen); 69 switch (param) { 70 case PIPE_CAP_NPOT_TEXTURES: 71 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: 72 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: 73 return 1; 74 case PIPE_CAP_SM3: 75 return 1; 76 case PIPE_CAP_ANISOTROPIC_FILTER: 77 return 1; 78 case PIPE_CAP_POINT_SPRITE: 79 return 1; 80 case PIPE_CAP_MAX_RENDER_TARGETS: 81 return PIPE_MAX_COLOR_BUFS; 82 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS: 83 return 1; 84 case PIPE_CAP_OCCLUSION_QUERY: 85 return 1; 86 case PIPE_CAP_QUERY_TIME_ELAPSED: 87 return 1; 88 case PIPE_CAP_QUERY_PIPELINE_STATISTICS: 89 return 1; 90 case PIPE_CAP_TEXTURE_MIRROR_CLAMP: 91 case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE: 92 return 1; 93 case PIPE_CAP_TEXTURE_SWIZZLE: 94 return 1; 95 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK: 96 case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET: 97 return 0; 98 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: 99 return SP_MAX_TEXTURE_2D_LEVELS; 100 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: 101 return SP_MAX_TEXTURE_3D_LEVELS; 102 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: 103 return SP_MAX_TEXTURE_CUBE_LEVELS; 104 case PIPE_CAP_BLEND_EQUATION_SEPARATE: 105 return 1; 106 case PIPE_CAP_INDEP_BLEND_ENABLE: 107 return 1; 108 case PIPE_CAP_INDEP_BLEND_FUNC: 109 return 1; 110 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: 111 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: 112 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: 113 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: 114 return 1; 115 case PIPE_CAP_DEPTH_CLIP_DISABLE: 116 return 1; 117 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: 118 return PIPE_MAX_SO_BUFFERS; 119 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: 120 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: 121 return 16*4; 122 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES: 123 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS: 124 return 1024; 125 case PIPE_CAP_MAX_VERTEX_STREAMS: 126 if (sp_screen->use_llvm) 127 return 1; 128 else 129 return PIPE_MAX_VERTEX_STREAMS; 130 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE: 131 return 2048; 132 case PIPE_CAP_PRIMITIVE_RESTART: 133 return 1; 134 case PIPE_CAP_SHADER_STENCIL_EXPORT: 135 return 1; 136 case PIPE_CAP_TGSI_ATOMFADD: 137 case PIPE_CAP_TGSI_INSTANCEID: 138 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: 139 case PIPE_CAP_START_INSTANCE: 140 return 1; 141 case PIPE_CAP_SEAMLESS_CUBE_MAP: 142 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: 143 return 1; 144 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: 145 return 256; /* for GL3 */ 146 case PIPE_CAP_MIN_TEXEL_OFFSET: 147 return -8; 148 case PIPE_CAP_MAX_TEXEL_OFFSET: 149 return 7; 150 case PIPE_CAP_CONDITIONAL_RENDER: 151 return 1; 152 case PIPE_CAP_TEXTURE_BARRIER: 153 case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE: 154 return 0; 155 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED: 156 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: /* draw module */ 157 case PIPE_CAP_VERTEX_COLOR_CLAMPED: /* draw module */ 158 return 1; 159 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: 160 return 1; 161 case PIPE_CAP_GLSL_FEATURE_LEVEL: 162 return 400; 163 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY: 164 return 140; 165 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: 166 case PIPE_CAP_TGSI_TEX_TXF_LZ: 167 return 0; 168 case PIPE_CAP_COMPUTE: 169 return 1; 170 case PIPE_CAP_USER_VERTEX_BUFFERS: 171 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME: 172 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS: 173 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT: 174 case PIPE_CAP_DOUBLES: 175 case PIPE_CAP_INT64: 176 case PIPE_CAP_INT64_DIVMOD: 177 case PIPE_CAP_TGSI_DIV: 178 return 1; 179 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: 180 return 16; 181 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: 182 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: 183 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: 184 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: 185 case PIPE_CAP_TEXTURE_MULTISAMPLE: 186 return 0; 187 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: 188 return 64; 189 case PIPE_CAP_QUERY_TIMESTAMP: 190 case PIPE_CAP_CUBE_MAP_ARRAY: 191 return 1; 192 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS: 193 return 1; 194 case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY: 195 return 0; 196 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE: 197 return 65536; 198 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT: 199 return 16; 200 case PIPE_CAP_TGSI_TEXCOORD: 201 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER: 202 return 0; 203 case PIPE_CAP_MAX_VIEWPORTS: 204 return PIPE_MAX_VIEWPORTS; 205 case PIPE_CAP_ENDIANNESS: 206 return PIPE_ENDIAN_NATIVE; 207 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS: 208 return 4; 209 case PIPE_CAP_TEXTURE_GATHER_SM5: 210 case PIPE_CAP_TEXTURE_QUERY_LOD: 211 return 1; 212 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT: 213 case PIPE_CAP_SAMPLE_SHADING: 214 case PIPE_CAP_TEXTURE_GATHER_OFFSETS: 215 return 0; 216 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION: 217 return 1; 218 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE: 219 return 0; 220 case PIPE_CAP_SAMPLER_VIEW_TARGET: 221 return 1; 222 case PIPE_CAP_FAKE_SW_MSAA: 223 return 1; 224 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: 225 return -32; 226 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: 227 return 31; 228 case PIPE_CAP_DRAW_INDIRECT: 229 return 1; 230 case PIPE_CAP_QUERY_SO_OVERFLOW: 231 return 1; 232 233 case PIPE_CAP_VENDOR_ID: 234 return 0xFFFFFFFF; 235 case PIPE_CAP_DEVICE_ID: 236 return 0xFFFFFFFF; 237 case PIPE_CAP_ACCELERATED: 238 return 0; 239 case PIPE_CAP_VIDEO_MEMORY: { 240 /* XXX: Do we want to return the full amount fo system memory ? */ 241 uint64_t system_memory; 242 243 if (!os_get_total_physical_memory(&system_memory)) 244 return 0; 245 246 if (sizeof(void *) == 4) 247 /* Cap to 2 GB on 32 bits system. We do this because softpipe does 248 * eat application memory, which is quite limited on 32 bits. App 249 * shouldn't expect too much available memory. */ 250 system_memory = MIN2(system_memory, 2048 << 20); 251 252 return (int)(system_memory >> 20); 253 } 254 case PIPE_CAP_UMA: 255 return 0; 256 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED: 257 return 1; 258 case PIPE_CAP_CLIP_HALFZ: 259 case PIPE_CAP_TEXTURE_FLOAT_LINEAR: 260 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR: 261 return 1; 262 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT: 263 case PIPE_CAP_CULL_DISTANCE: 264 return 1; 265 case PIPE_CAP_VERTEXID_NOBASE: 266 return 0; 267 case PIPE_CAP_POLYGON_OFFSET_CLAMP: 268 return 0; 269 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS: 270 case PIPE_CAP_TGSI_ARRAY_COMPONENTS: 271 return 1; 272 case PIPE_CAP_CLEAR_TEXTURE: 273 return 1; 274 case PIPE_CAP_MAX_VARYINGS: 275 return TGSI_EXEC_MAX_INPUT_ATTRIBS; 276 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE: 277 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY: 278 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY: 279 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS: 280 case PIPE_CAP_DEPTH_BOUNDS_TEST: 281 case PIPE_CAP_TGSI_TXQS: 282 case PIPE_CAP_FORCE_PERSAMPLE_INTERP: 283 case PIPE_CAP_SHAREABLE_SHADERS: 284 case PIPE_CAP_DRAW_PARAMETERS: 285 case PIPE_CAP_TGSI_PACK_HALF_FLOAT: 286 case PIPE_CAP_MULTI_DRAW_INDIRECT: 287 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS: 288 case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL: 289 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL: 290 case PIPE_CAP_INVALIDATE_BUFFER: 291 case PIPE_CAP_GENERATE_MIPMAP: 292 case PIPE_CAP_STRING_MARKER: 293 case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS: 294 case PIPE_CAP_QUERY_BUFFER_OBJECT: 295 case PIPE_CAP_QUERY_MEMORY_INFO: 296 case PIPE_CAP_PCI_GROUP: 297 case PIPE_CAP_PCI_BUS: 298 case PIPE_CAP_PCI_DEVICE: 299 case PIPE_CAP_PCI_FUNCTION: 300 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR: 301 case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES: 302 case PIPE_CAP_TGSI_VOTE: 303 case PIPE_CAP_MAX_WINDOW_RECTANGLES: 304 case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED: 305 case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS: 306 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS: 307 case PIPE_CAP_NATIVE_FENCE_FD: 308 case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY: 309 case PIPE_CAP_TGSI_FS_FBFETCH: 310 case PIPE_CAP_TGSI_MUL_ZERO_WINS: 311 case PIPE_CAP_TGSI_CLOCK: 312 case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE: 313 case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE: 314 case PIPE_CAP_TGSI_BALLOT: 315 case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT: 316 case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX: 317 case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION: 318 case PIPE_CAP_POST_DEPTH_COVERAGE: 319 case PIPE_CAP_BINDLESS_TEXTURE: 320 case PIPE_CAP_NIR_SAMPLERS_AS_DEREF: 321 case PIPE_CAP_MEMOBJ: 322 case PIPE_CAP_LOAD_CONSTBUF: 323 case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS: 324 case PIPE_CAP_TILE_RASTER_ORDER: 325 case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES: 326 case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS: 327 case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET: 328 case PIPE_CAP_CONTEXT_PRIORITY_MASK: 329 case PIPE_CAP_FENCE_SIGNAL: 330 case PIPE_CAP_CONSTBUF0_FLAGS: 331 case PIPE_CAP_PACKED_UNIFORMS: 332 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES: 333 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES: 334 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES: 335 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES: 336 case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE: 337 case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS: 338 case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS: 339 return 0; 340 case PIPE_CAP_MAX_GS_INVOCATIONS: 341 return 32; 342 case PIPE_CAP_MAX_SHADER_BUFFER_SIZE: 343 return 1 << 27; 344 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT: 345 return 4; 346 default: 347 return u_pipe_screen_get_param_defaults(screen, param); 348 } 349} 350 351static int 352softpipe_get_shader_param(struct pipe_screen *screen, 353 enum pipe_shader_type shader, 354 enum pipe_shader_cap param) 355{ 356 struct softpipe_screen *sp_screen = softpipe_screen(screen); 357 switch(shader) 358 { 359 case PIPE_SHADER_FRAGMENT: 360 return tgsi_exec_get_shader_param(param); 361 case PIPE_SHADER_COMPUTE: 362 return tgsi_exec_get_shader_param(param); 363 case PIPE_SHADER_VERTEX: 364 case PIPE_SHADER_GEOMETRY: 365 if (sp_screen->use_llvm) 366 return draw_get_shader_param(shader, param); 367 else 368 return draw_get_shader_param_no_llvm(shader, param); 369 default: 370 return 0; 371 } 372} 373 374static float 375softpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param) 376{ 377 switch (param) { 378 case PIPE_CAPF_MAX_LINE_WIDTH: 379 /* fall-through */ 380 case PIPE_CAPF_MAX_LINE_WIDTH_AA: 381 return 255.0; /* arbitrary */ 382 case PIPE_CAPF_MAX_POINT_WIDTH: 383 /* fall-through */ 384 case PIPE_CAPF_MAX_POINT_WIDTH_AA: 385 return 255.0; /* arbitrary */ 386 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: 387 return 16.0; 388 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: 389 return 16.0; /* arbitrary */ 390 case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE: 391 return 0.0; 392 case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE: 393 return 0.0; 394 case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY: 395 return 0.0; 396 } 397 /* should only get here on unhandled cases */ 398 debug_printf("Unexpected PIPE_CAPF %d query\n", param); 399 return 0.0; 400} 401 402/** 403 * Query format support for creating a texture, drawing surface, etc. 404 * \param format the format to test 405 * \param type one of PIPE_TEXTURE, PIPE_SURFACE 406 */ 407static boolean 408softpipe_is_format_supported( struct pipe_screen *screen, 409 enum pipe_format format, 410 enum pipe_texture_target target, 411 unsigned sample_count, 412 unsigned storage_sample_count, 413 unsigned bind) 414{ 415 struct sw_winsys *winsys = softpipe_screen(screen)->winsys; 416 const struct util_format_description *format_desc; 417 418 assert(target == PIPE_BUFFER || 419 target == PIPE_TEXTURE_1D || 420 target == PIPE_TEXTURE_1D_ARRAY || 421 target == PIPE_TEXTURE_2D || 422 target == PIPE_TEXTURE_2D_ARRAY || 423 target == PIPE_TEXTURE_RECT || 424 target == PIPE_TEXTURE_3D || 425 target == PIPE_TEXTURE_CUBE || 426 target == PIPE_TEXTURE_CUBE_ARRAY); 427 428 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 429 return false; 430 431 format_desc = util_format_description(format); 432 if (!format_desc) 433 return FALSE; 434 435 if (sample_count > 1) 436 return FALSE; 437 438 if (bind & (PIPE_BIND_DISPLAY_TARGET | 439 PIPE_BIND_SCANOUT | 440 PIPE_BIND_SHARED)) { 441 if(!winsys->is_displaytarget_format_supported(winsys, bind, format)) 442 return FALSE; 443 } 444 445 if (bind & PIPE_BIND_RENDER_TARGET) { 446 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) 447 return FALSE; 448 449 /* 450 * Although possible, it is unnatural to render into compressed or YUV 451 * surfaces. So disable these here to avoid going into weird paths 452 * inside the state trackers. 453 */ 454 if (format_desc->block.width != 1 || 455 format_desc->block.height != 1) 456 return FALSE; 457 } 458 459 if (bind & PIPE_BIND_DEPTH_STENCIL) { 460 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) 461 return FALSE; 462 } 463 464 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC || 465 format_desc->layout == UTIL_FORMAT_LAYOUT_ATC) { 466 /* Software decoding is not hooked up. */ 467 return FALSE; 468 } 469 470 if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) && 471 ((bind & PIPE_BIND_DISPLAY_TARGET) == 0) && 472 target != PIPE_BUFFER) { 473 const struct util_format_description *desc = 474 util_format_description(format); 475 if (desc->nr_channels == 3 && desc->is_array) { 476 /* Don't support any 3-component formats for rendering/texturing 477 * since we don't support the corresponding 8-bit 3 channel UNORM 478 * formats. This allows us to support GL_ARB_copy_image between 479 * GL_RGB8 and GL_RGB8UI, for example. Otherwise, we may be asked to 480 * do a resource copy between PIPE_FORMAT_R8G8B8_UINT and 481 * PIPE_FORMAT_R8G8B8X8_UNORM, for example, which will not work 482 * (different bpp). 483 */ 484 return FALSE; 485 } 486 } 487 488 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC && 489 format != PIPE_FORMAT_ETC1_RGB8) 490 return FALSE; 491 492 /* 493 * All other operations (sampling, transfer, etc). 494 */ 495 496 /* 497 * Everything else should be supported by u_format. 498 */ 499 return TRUE; 500} 501 502 503static void 504softpipe_destroy_screen( struct pipe_screen *screen ) 505{ 506 struct softpipe_screen *sp_screen = softpipe_screen(screen); 507 struct sw_winsys *winsys = sp_screen->winsys; 508 509 if(winsys->destroy) 510 winsys->destroy(winsys); 511 512 FREE(screen); 513} 514 515 516/* This is often overriden by the co-state tracker. 517 */ 518static void 519softpipe_flush_frontbuffer(struct pipe_screen *_screen, 520 struct pipe_resource *resource, 521 unsigned level, unsigned layer, 522 void *context_private, 523 struct pipe_box *sub_box) 524{ 525 struct softpipe_screen *screen = softpipe_screen(_screen); 526 struct sw_winsys *winsys = screen->winsys; 527 struct softpipe_resource *texture = softpipe_resource(resource); 528 529 assert(texture->dt); 530 if (texture->dt) 531 winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box); 532} 533 534static uint64_t 535softpipe_get_timestamp(struct pipe_screen *_screen) 536{ 537 return os_time_get_nano(); 538} 539 540static int 541softpipe_get_compute_param(struct pipe_screen *_screen, 542 enum pipe_shader_ir ir_type, 543 enum pipe_compute_cap param, 544 void *ret) 545{ 546 switch (param) { 547 case PIPE_COMPUTE_CAP_IR_TARGET: 548 return 0; 549 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE: 550 if (ret) { 551 uint64_t *grid_size = ret; 552 grid_size[0] = 65535; 553 grid_size[1] = 65535; 554 grid_size[2] = 65535; 555 } 556 return 3 * sizeof(uint64_t) ; 557 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE: 558 if (ret) { 559 uint64_t *block_size = ret; 560 block_size[0] = 1024; 561 block_size[1] = 1024; 562 block_size[2] = 1024; 563 } 564 return 3 * sizeof(uint64_t); 565 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK: 566 if (ret) { 567 uint64_t *max_threads_per_block = ret; 568 *max_threads_per_block = 1024; 569 } 570 return sizeof(uint64_t); 571 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: 572 if (ret) { 573 uint64_t *max_local_size = ret; 574 *max_local_size = 32768; 575 } 576 return sizeof(uint64_t); 577 case PIPE_COMPUTE_CAP_GRID_DIMENSION: 578 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: 579 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: 580 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: 581 case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE: 582 case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY: 583 case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS: 584 case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED: 585 case PIPE_COMPUTE_CAP_SUBGROUP_SIZE: 586 case PIPE_COMPUTE_CAP_ADDRESS_BITS: 587 case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK: 588 break; 589 } 590 return 0; 591} 592 593/** 594 * Create a new pipe_screen object 595 * Note: we're not presently subclassing pipe_screen (no softpipe_screen). 596 */ 597struct pipe_screen * 598softpipe_create_screen(struct sw_winsys *winsys) 599{ 600 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen); 601 602 if (!screen) 603 return NULL; 604 605 screen->winsys = winsys; 606 607 screen->base.destroy = softpipe_destroy_screen; 608 609 screen->base.get_name = softpipe_get_name; 610 screen->base.get_vendor = softpipe_get_vendor; 611 screen->base.get_device_vendor = softpipe_get_vendor; // TODO should be the CPU vendor 612 screen->base.get_param = softpipe_get_param; 613 screen->base.get_shader_param = softpipe_get_shader_param; 614 screen->base.get_paramf = softpipe_get_paramf; 615 screen->base.get_timestamp = softpipe_get_timestamp; 616 screen->base.is_format_supported = softpipe_is_format_supported; 617 screen->base.context_create = softpipe_create_context; 618 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer; 619 screen->base.get_compute_param = softpipe_get_compute_param; 620 screen->use_llvm = debug_get_option_use_llvm(); 621 622 softpipe_init_screen_texture_funcs(&screen->base); 623 softpipe_init_screen_fence_funcs(&screen->base); 624 625 return &screen->base; 626} 627