1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2008 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg 29848b8605Smrg#include "util/u_memory.h" 30848b8605Smrg#include "util/u_math.h" 31848b8605Smrg#include "util/u_cpu_detect.h" 32848b8605Smrg#include "util/u_format.h" 33b8e80941Smrg#include "util/u_screen.h" 34848b8605Smrg#include "util/u_string.h" 35848b8605Smrg#include "util/u_format_s3tc.h" 36848b8605Smrg#include "pipe/p_defines.h" 37848b8605Smrg#include "pipe/p_screen.h" 38848b8605Smrg#include "draw/draw_context.h" 39848b8605Smrg#include "gallivm/lp_bld_type.h" 40848b8605Smrg 41b8e80941Smrg#include "util/os_misc.h" 42b8e80941Smrg#include "util/os_time.h" 43848b8605Smrg#include "lp_texture.h" 44848b8605Smrg#include "lp_fence.h" 45848b8605Smrg#include "lp_jit.h" 46848b8605Smrg#include "lp_screen.h" 47848b8605Smrg#include "lp_context.h" 48848b8605Smrg#include "lp_debug.h" 49848b8605Smrg#include "lp_public.h" 50848b8605Smrg#include "lp_limits.h" 51848b8605Smrg#include "lp_rast.h" 52848b8605Smrg 53848b8605Smrg#include "state_tracker/sw_winsys.h" 54848b8605Smrg 55848b8605Smrg#ifdef DEBUG 56848b8605Smrgint LP_DEBUG = 0; 57848b8605Smrg 58848b8605Smrgstatic const struct debug_named_value lp_debug_flags[] = { 59848b8605Smrg { "pipe", DEBUG_PIPE, NULL }, 60848b8605Smrg { "tgsi", DEBUG_TGSI, NULL }, 61848b8605Smrg { "tex", DEBUG_TEX, NULL }, 62848b8605Smrg { "setup", DEBUG_SETUP, NULL }, 63848b8605Smrg { "rast", DEBUG_RAST, NULL }, 64848b8605Smrg { "query", DEBUG_QUERY, NULL }, 65848b8605Smrg { "screen", DEBUG_SCREEN, NULL }, 66848b8605Smrg { "counters", DEBUG_COUNTERS, NULL }, 67848b8605Smrg { "scene", DEBUG_SCENE, NULL }, 68848b8605Smrg { "fence", DEBUG_FENCE, NULL }, 69848b8605Smrg { "mem", DEBUG_MEM, NULL }, 70848b8605Smrg { "fs", DEBUG_FS, NULL }, 71848b8605Smrg DEBUG_NAMED_VALUE_END 72848b8605Smrg}; 73848b8605Smrg#endif 74848b8605Smrg 75848b8605Smrgint LP_PERF = 0; 76848b8605Smrgstatic const struct debug_named_value lp_perf_flags[] = { 77848b8605Smrg { "texmem", PERF_TEX_MEM, NULL }, 78848b8605Smrg { "no_mipmap", PERF_NO_MIPMAPS, NULL }, 79848b8605Smrg { "no_linear", PERF_NO_LINEAR, NULL }, 80848b8605Smrg { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL }, 81848b8605Smrg { "no_tex", PERF_NO_TEX, NULL }, 82848b8605Smrg { "no_blend", PERF_NO_BLEND, NULL }, 83848b8605Smrg { "no_depth", PERF_NO_DEPTH, NULL }, 84848b8605Smrg { "no_alphatest", PERF_NO_ALPHATEST, NULL }, 85848b8605Smrg DEBUG_NAMED_VALUE_END 86848b8605Smrg}; 87848b8605Smrg 88848b8605Smrg 89848b8605Smrgstatic const char * 90848b8605Smrgllvmpipe_get_vendor(struct pipe_screen *screen) 91848b8605Smrg{ 92848b8605Smrg return "VMware, Inc."; 93848b8605Smrg} 94848b8605Smrg 95848b8605Smrg 96848b8605Smrgstatic const char * 97848b8605Smrgllvmpipe_get_name(struct pipe_screen *screen) 98848b8605Smrg{ 99848b8605Smrg static char buf[100]; 100848b8605Smrg util_snprintf(buf, sizeof(buf), "llvmpipe (LLVM %u.%u, %u bits)", 101848b8605Smrg HAVE_LLVM >> 8, HAVE_LLVM & 0xff, 102848b8605Smrg lp_native_vector_width ); 103848b8605Smrg return buf; 104848b8605Smrg} 105848b8605Smrg 106848b8605Smrg 107848b8605Smrgstatic int 108848b8605Smrgllvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) 109848b8605Smrg{ 110848b8605Smrg switch (param) { 111848b8605Smrg case PIPE_CAP_NPOT_TEXTURES: 112848b8605Smrg case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: 113b8e80941Smrg case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: 114848b8605Smrg return 1; 115848b8605Smrg case PIPE_CAP_SM3: 116848b8605Smrg return 1; 117848b8605Smrg case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS: 118848b8605Smrg return 1; 119848b8605Smrg case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: 120848b8605Smrg return PIPE_MAX_SO_BUFFERS; 121848b8605Smrg case PIPE_CAP_ANISOTROPIC_FILTER: 122848b8605Smrg return 0; 123848b8605Smrg case PIPE_CAP_POINT_SPRITE: 124848b8605Smrg return 1; 125848b8605Smrg case PIPE_CAP_MAX_RENDER_TARGETS: 126848b8605Smrg return PIPE_MAX_COLOR_BUFS; 127848b8605Smrg case PIPE_CAP_OCCLUSION_QUERY: 128848b8605Smrg return 1; 129848b8605Smrg case PIPE_CAP_QUERY_TIME_ELAPSED: 130848b8605Smrg return 0; 131848b8605Smrg case PIPE_CAP_QUERY_TIMESTAMP: 132848b8605Smrg return 1; 133848b8605Smrg case PIPE_CAP_QUERY_PIPELINE_STATISTICS: 134848b8605Smrg return 1; 135b8e80941Smrg case PIPE_CAP_TEXTURE_MIRROR_CLAMP: 136b8e80941Smrg case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE: 137848b8605Smrg return 1; 138848b8605Smrg case PIPE_CAP_TEXTURE_SWIZZLE: 139848b8605Smrg return 1; 140848b8605Smrg case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK: 141b8e80941Smrg case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET: 142848b8605Smrg return 0; 143848b8605Smrg case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: 144848b8605Smrg return LP_MAX_TEXTURE_2D_LEVELS; 145848b8605Smrg case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: 146848b8605Smrg return LP_MAX_TEXTURE_3D_LEVELS; 147848b8605Smrg case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: 148848b8605Smrg return LP_MAX_TEXTURE_CUBE_LEVELS; 149848b8605Smrg case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: 150848b8605Smrg return LP_MAX_TEXTURE_ARRAY_LAYERS; 151848b8605Smrg case PIPE_CAP_BLEND_EQUATION_SEPARATE: 152848b8605Smrg return 1; 153848b8605Smrg case PIPE_CAP_INDEP_BLEND_ENABLE: 154848b8605Smrg return 1; 155848b8605Smrg case PIPE_CAP_INDEP_BLEND_FUNC: 156848b8605Smrg return 1; 157848b8605Smrg case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: 158848b8605Smrg case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: 159848b8605Smrg case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: 160848b8605Smrg return 1; 161848b8605Smrg case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: 162b8e80941Smrg case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE: 163848b8605Smrg return 0; 164848b8605Smrg case PIPE_CAP_PRIMITIVE_RESTART: 165848b8605Smrg return 1; 166848b8605Smrg case PIPE_CAP_DEPTH_CLIP_DISABLE: 167848b8605Smrg return 1; 168848b8605Smrg case PIPE_CAP_SHADER_STENCIL_EXPORT: 169b8e80941Smrg return 1; 170848b8605Smrg case PIPE_CAP_TGSI_INSTANCEID: 171848b8605Smrg case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: 172b8e80941Smrg case PIPE_CAP_START_INSTANCE: 173848b8605Smrg return 1; 174848b8605Smrg case PIPE_CAP_FRAGMENT_COLOR_CLAMPED: 175848b8605Smrg return 0; 176848b8605Smrg case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: 177848b8605Smrg return 1; 178848b8605Smrg case PIPE_CAP_SEAMLESS_CUBE_MAP: 179848b8605Smrg case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: 180848b8605Smrg return 1; 181848b8605Smrg /* this is a lie could support arbitrary large offsets */ 182848b8605Smrg case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: 183848b8605Smrg case PIPE_CAP_MIN_TEXEL_OFFSET: 184b8e80941Smrg return -32; 185848b8605Smrg case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: 186848b8605Smrg case PIPE_CAP_MAX_TEXEL_OFFSET: 187b8e80941Smrg return 31; 188848b8605Smrg case PIPE_CAP_CONDITIONAL_RENDER: 189848b8605Smrg return 1; 190848b8605Smrg case PIPE_CAP_TEXTURE_BARRIER: 191848b8605Smrg return 0; 192848b8605Smrg case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: 193848b8605Smrg case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: 194848b8605Smrg return 16*4; 195848b8605Smrg case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES: 196848b8605Smrg case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS: 197848b8605Smrg return 1024; 198848b8605Smrg case PIPE_CAP_MAX_VERTEX_STREAMS: 199848b8605Smrg return 1; 200b8e80941Smrg case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE: 201b8e80941Smrg return 2048; 202848b8605Smrg case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME: 203b8e80941Smrg case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS: 204848b8605Smrg return 1; 205848b8605Smrg case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: 206848b8605Smrg return 0; 207848b8605Smrg case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: 208848b8605Smrg case PIPE_CAP_VERTEX_COLOR_CLAMPED: 209848b8605Smrg return 1; 210848b8605Smrg case PIPE_CAP_GLSL_FEATURE_LEVEL: 211848b8605Smrg return 330; 212b8e80941Smrg case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY: 213b8e80941Smrg return 140; 214848b8605Smrg case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: 215848b8605Smrg return 0; 216848b8605Smrg case PIPE_CAP_COMPUTE: 217848b8605Smrg return 0; 218848b8605Smrg case PIPE_CAP_USER_VERTEX_BUFFERS: 219848b8605Smrg return 1; 220848b8605Smrg case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: 221848b8605Smrg case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: 222848b8605Smrg case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: 223848b8605Smrg case PIPE_CAP_TGSI_TEXCOORD: 224848b8605Smrg return 0; 225848b8605Smrg case PIPE_CAP_DRAW_INDIRECT: 226848b8605Smrg return 1; 227848b8605Smrg 228b8e80941Smrg case PIPE_CAP_CUBE_MAP_ARRAY: 229b8e80941Smrg return 1; 230848b8605Smrg case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: 231848b8605Smrg return 16; 232848b8605Smrg case PIPE_CAP_TEXTURE_MULTISAMPLE: 233848b8605Smrg return 0; 234848b8605Smrg case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: 235848b8605Smrg return 64; 236848b8605Smrg case PIPE_CAP_TEXTURE_BUFFER_OBJECTS: 237848b8605Smrg return 1; 238848b8605Smrg case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE: 239848b8605Smrg return 65536; 240848b8605Smrg case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT: 241848b8605Smrg return 1; 242848b8605Smrg case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER: 243848b8605Smrg return 0; 244848b8605Smrg case PIPE_CAP_MAX_VIEWPORTS: 245848b8605Smrg return PIPE_MAX_VIEWPORTS; 246848b8605Smrg case PIPE_CAP_ENDIANNESS: 247848b8605Smrg return PIPE_ENDIAN_NATIVE; 248848b8605Smrg case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT: 249b8e80941Smrg return 1; 250b8e80941Smrg case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT: 251b8e80941Smrg return 1; 252848b8605Smrg case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS: 253b8e80941Smrg return 4; 254848b8605Smrg case PIPE_CAP_TEXTURE_GATHER_SM5: 255848b8605Smrg case PIPE_CAP_SAMPLE_SHADING: 256848b8605Smrg case PIPE_CAP_TEXTURE_GATHER_OFFSETS: 257b8e80941Smrg return 0; 258848b8605Smrg case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION: 259b8e80941Smrg return 1; 260848b8605Smrg case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE: 261b8e80941Smrg case PIPE_CAP_TGSI_TEX_TXF_LZ: 262848b8605Smrg return 0; 263b8e80941Smrg case PIPE_CAP_SAMPLER_VIEW_TARGET: 264b8e80941Smrg return 1; 265848b8605Smrg case PIPE_CAP_FAKE_SW_MSAA: 266848b8605Smrg return 1; 267b8e80941Smrg case PIPE_CAP_TEXTURE_QUERY_LOD: 268848b8605Smrg case PIPE_CAP_CONDITIONAL_RENDER_INVERTED: 269b8e80941Smrg case PIPE_CAP_TGSI_ARRAY_COMPONENTS: 270b8e80941Smrg case PIPE_CAP_DOUBLES: 271b8e80941Smrg case PIPE_CAP_INT64: 272b8e80941Smrg case PIPE_CAP_INT64_DIVMOD: 273b8e80941Smrg case PIPE_CAP_QUERY_SO_OVERFLOW: 274b8e80941Smrg case PIPE_CAP_TGSI_DIV: 275848b8605Smrg return 1; 276848b8605Smrg 277848b8605Smrg case PIPE_CAP_VENDOR_ID: 278848b8605Smrg return 0xFFFFFFFF; 279848b8605Smrg case PIPE_CAP_DEVICE_ID: 280848b8605Smrg return 0xFFFFFFFF; 281848b8605Smrg case PIPE_CAP_ACCELERATED: 282848b8605Smrg return 0; 283848b8605Smrg case PIPE_CAP_VIDEO_MEMORY: { 284848b8605Smrg /* XXX: Do we want to return the full amount fo system memory ? */ 285848b8605Smrg uint64_t system_memory; 286848b8605Smrg 287848b8605Smrg if (!os_get_total_physical_memory(&system_memory)) 288848b8605Smrg return 0; 289848b8605Smrg 290b8e80941Smrg if (sizeof(void *) == 4) 291b8e80941Smrg /* Cap to 2 GB on 32 bits system. We do this because llvmpipe does 292b8e80941Smrg * eat application memory, which is quite limited on 32 bits. App 293b8e80941Smrg * shouldn't expect too much available memory. */ 294b8e80941Smrg system_memory = MIN2(system_memory, 2048 << 20); 295b8e80941Smrg 296848b8605Smrg return (int)(system_memory >> 20); 297848b8605Smrg } 298848b8605Smrg case PIPE_CAP_UMA: 299848b8605Smrg return 0; 300b8e80941Smrg case PIPE_CAP_CLIP_HALFZ: 301b8e80941Smrg return 1; 302b8e80941Smrg case PIPE_CAP_VERTEXID_NOBASE: 303b8e80941Smrg return 0; 304b8e80941Smrg case PIPE_CAP_POLYGON_OFFSET_CLAMP: 305b8e80941Smrg case PIPE_CAP_TEXTURE_FLOAT_LINEAR: 306b8e80941Smrg case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR: 307b8e80941Smrg return 1; 308b8e80941Smrg case PIPE_CAP_CULL_DISTANCE: 309b8e80941Smrg return 1; 310b8e80941Smrg case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS: 311b8e80941Smrg return 1; 312b8e80941Smrg case PIPE_CAP_CLEAR_TEXTURE: 313b8e80941Smrg return 1; 314b8e80941Smrg case PIPE_CAP_MAX_VARYINGS: 315b8e80941Smrg return 32; 316b8e80941Smrg case PIPE_CAP_MULTISAMPLE_Z_RESOLVE: 317b8e80941Smrg case PIPE_CAP_RESOURCE_FROM_USER_MEMORY: 318b8e80941Smrg case PIPE_CAP_DEVICE_RESET_STATUS_QUERY: 319b8e80941Smrg case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS: 320b8e80941Smrg case PIPE_CAP_DEPTH_BOUNDS_TEST: 321b8e80941Smrg case PIPE_CAP_TGSI_TXQS: 322b8e80941Smrg case PIPE_CAP_FORCE_PERSAMPLE_INTERP: 323b8e80941Smrg case PIPE_CAP_SHAREABLE_SHADERS: 324b8e80941Smrg case PIPE_CAP_DRAW_PARAMETERS: 325b8e80941Smrg case PIPE_CAP_TGSI_PACK_HALF_FLOAT: 326b8e80941Smrg case PIPE_CAP_MULTI_DRAW_INDIRECT: 327b8e80941Smrg case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS: 328b8e80941Smrg case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL: 329b8e80941Smrg case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL: 330b8e80941Smrg case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT: 331b8e80941Smrg case PIPE_CAP_INVALIDATE_BUFFER: 332b8e80941Smrg case PIPE_CAP_GENERATE_MIPMAP: 333b8e80941Smrg case PIPE_CAP_STRING_MARKER: 334b8e80941Smrg case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY: 335b8e80941Smrg case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS: 336b8e80941Smrg case PIPE_CAP_QUERY_BUFFER_OBJECT: 337b8e80941Smrg case PIPE_CAP_QUERY_MEMORY_INFO: 338b8e80941Smrg case PIPE_CAP_PCI_GROUP: 339b8e80941Smrg case PIPE_CAP_PCI_BUS: 340b8e80941Smrg case PIPE_CAP_PCI_DEVICE: 341b8e80941Smrg case PIPE_CAP_PCI_FUNCTION: 342b8e80941Smrg case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT: 343b8e80941Smrg case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR: 344b8e80941Smrg case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES: 345b8e80941Smrg case PIPE_CAP_TGSI_VOTE: 346b8e80941Smrg case PIPE_CAP_MAX_WINDOW_RECTANGLES: 347b8e80941Smrg case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED: 348b8e80941Smrg case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS: 349b8e80941Smrg case PIPE_CAP_TGSI_CAN_READ_OUTPUTS: 350b8e80941Smrg case PIPE_CAP_NATIVE_FENCE_FD: 351b8e80941Smrg case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY: 352b8e80941Smrg case PIPE_CAP_TGSI_FS_FBFETCH: 353b8e80941Smrg case PIPE_CAP_TGSI_MUL_ZERO_WINS: 354b8e80941Smrg case PIPE_CAP_TGSI_CLOCK: 355b8e80941Smrg case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE: 356b8e80941Smrg case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE: 357b8e80941Smrg case PIPE_CAP_TGSI_BALLOT: 358b8e80941Smrg case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT: 359b8e80941Smrg case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX: 360b8e80941Smrg case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION: 361b8e80941Smrg case PIPE_CAP_POST_DEPTH_COVERAGE: 362b8e80941Smrg case PIPE_CAP_BINDLESS_TEXTURE: 363b8e80941Smrg case PIPE_CAP_NIR_SAMPLERS_AS_DEREF: 364b8e80941Smrg case PIPE_CAP_MEMOBJ: 365b8e80941Smrg case PIPE_CAP_LOAD_CONSTBUF: 366b8e80941Smrg case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS: 367b8e80941Smrg case PIPE_CAP_TILE_RASTER_ORDER: 368b8e80941Smrg case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES: 369b8e80941Smrg case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS: 370b8e80941Smrg case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET: 371b8e80941Smrg case PIPE_CAP_CONTEXT_PRIORITY_MASK: 372b8e80941Smrg case PIPE_CAP_FENCE_SIGNAL: 373b8e80941Smrg case PIPE_CAP_CONSTBUF0_FLAGS: 374b8e80941Smrg case PIPE_CAP_PACKED_UNIFORMS: 375b8e80941Smrg case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES: 376b8e80941Smrg case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES: 377b8e80941Smrg case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES: 378b8e80941Smrg case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES: 379b8e80941Smrg case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE: 380b8e80941Smrg case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS: 381b8e80941Smrg case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS: 382b8e80941Smrg return 0; 383b8e80941Smrg case PIPE_CAP_MAX_GS_INVOCATIONS: 384b8e80941Smrg return 32; 385b8e80941Smrg case PIPE_CAP_MAX_SHADER_BUFFER_SIZE: 386b8e80941Smrg return 1 << 27; 387b8e80941Smrg 388b8e80941Smrg default: 389b8e80941Smrg return u_pipe_screen_get_param_defaults(screen, param); 390848b8605Smrg } 391848b8605Smrg} 392848b8605Smrg 393848b8605Smrgstatic int 394b8e80941Smrgllvmpipe_get_shader_param(struct pipe_screen *screen, 395b8e80941Smrg enum pipe_shader_type shader, 396b8e80941Smrg enum pipe_shader_cap param) 397848b8605Smrg{ 398848b8605Smrg switch(shader) 399848b8605Smrg { 400848b8605Smrg case PIPE_SHADER_FRAGMENT: 401848b8605Smrg switch (param) { 402848b8605Smrg default: 403848b8605Smrg return gallivm_get_shader_param(param); 404848b8605Smrg } 405848b8605Smrg case PIPE_SHADER_VERTEX: 406848b8605Smrg case PIPE_SHADER_GEOMETRY: 407848b8605Smrg switch (param) { 408848b8605Smrg case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: 409848b8605Smrg /* At this time, the draw module and llvmpipe driver only 410848b8605Smrg * support vertex shader texture lookups when LLVM is enabled in 411848b8605Smrg * the draw module. 412848b8605Smrg */ 413848b8605Smrg if (debug_get_bool_option("DRAW_USE_LLVM", TRUE)) 414848b8605Smrg return PIPE_MAX_SAMPLERS; 415848b8605Smrg else 416848b8605Smrg return 0; 417848b8605Smrg case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: 418848b8605Smrg if (debug_get_bool_option("DRAW_USE_LLVM", TRUE)) 419848b8605Smrg return PIPE_MAX_SHADER_SAMPLER_VIEWS; 420848b8605Smrg else 421848b8605Smrg return 0; 422848b8605Smrg default: 423848b8605Smrg return draw_get_shader_param(shader, param); 424848b8605Smrg } 425848b8605Smrg default: 426848b8605Smrg return 0; 427848b8605Smrg } 428848b8605Smrg} 429848b8605Smrg 430848b8605Smrgstatic float 431848b8605Smrgllvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param) 432848b8605Smrg{ 433848b8605Smrg switch (param) { 434848b8605Smrg case PIPE_CAPF_MAX_LINE_WIDTH: 435848b8605Smrg /* fall-through */ 436848b8605Smrg case PIPE_CAPF_MAX_LINE_WIDTH_AA: 437848b8605Smrg return 255.0; /* arbitrary */ 438848b8605Smrg case PIPE_CAPF_MAX_POINT_WIDTH: 439848b8605Smrg /* fall-through */ 440848b8605Smrg case PIPE_CAPF_MAX_POINT_WIDTH_AA: 441848b8605Smrg return 255.0; /* arbitrary */ 442848b8605Smrg case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: 443848b8605Smrg return 16.0; /* not actually signficant at this time */ 444848b8605Smrg case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: 445848b8605Smrg return 16.0; /* arbitrary */ 446b8e80941Smrg case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE: 447b8e80941Smrg return 0.0; 448b8e80941Smrg case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE: 449b8e80941Smrg return 0.0; 450b8e80941Smrg case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY: 451848b8605Smrg return 0.0; 452848b8605Smrg } 453848b8605Smrg /* should only get here on unhandled cases */ 454848b8605Smrg debug_printf("Unexpected PIPE_CAP %d query\n", param); 455848b8605Smrg return 0.0; 456848b8605Smrg} 457848b8605Smrg 458848b8605Smrg 459848b8605Smrg/** 460848b8605Smrg * Query format support for creating a texture, drawing surface, etc. 461848b8605Smrg * \param format the format to test 462848b8605Smrg * \param type one of PIPE_TEXTURE, PIPE_SURFACE 463848b8605Smrg */ 464848b8605Smrgstatic boolean 465848b8605Smrgllvmpipe_is_format_supported( struct pipe_screen *_screen, 466848b8605Smrg enum pipe_format format, 467848b8605Smrg enum pipe_texture_target target, 468848b8605Smrg unsigned sample_count, 469b8e80941Smrg unsigned storage_sample_count, 470848b8605Smrg unsigned bind) 471848b8605Smrg{ 472848b8605Smrg struct llvmpipe_screen *screen = llvmpipe_screen(_screen); 473848b8605Smrg struct sw_winsys *winsys = screen->winsys; 474848b8605Smrg const struct util_format_description *format_desc; 475848b8605Smrg 476848b8605Smrg format_desc = util_format_description(format); 477848b8605Smrg if (!format_desc) 478848b8605Smrg return FALSE; 479848b8605Smrg 480848b8605Smrg assert(target == PIPE_BUFFER || 481848b8605Smrg target == PIPE_TEXTURE_1D || 482848b8605Smrg target == PIPE_TEXTURE_1D_ARRAY || 483848b8605Smrg target == PIPE_TEXTURE_2D || 484848b8605Smrg target == PIPE_TEXTURE_2D_ARRAY || 485848b8605Smrg target == PIPE_TEXTURE_RECT || 486848b8605Smrg target == PIPE_TEXTURE_3D || 487848b8605Smrg target == PIPE_TEXTURE_CUBE || 488848b8605Smrg target == PIPE_TEXTURE_CUBE_ARRAY); 489848b8605Smrg 490848b8605Smrg if (sample_count > 1) 491848b8605Smrg return FALSE; 492848b8605Smrg 493b8e80941Smrg if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 494b8e80941Smrg return false; 495b8e80941Smrg 496848b8605Smrg if (bind & PIPE_BIND_RENDER_TARGET) { 497848b8605Smrg if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { 498848b8605Smrg /* this is a lie actually other formats COULD exist where we would fail */ 499848b8605Smrg if (format_desc->nr_channels < 3) 500848b8605Smrg return FALSE; 501848b8605Smrg } 502848b8605Smrg else if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB) 503848b8605Smrg return FALSE; 504848b8605Smrg 505848b8605Smrg if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN && 506848b8605Smrg format != PIPE_FORMAT_R11G11B10_FLOAT) 507848b8605Smrg return FALSE; 508848b8605Smrg 509848b8605Smrg assert(format_desc->block.width == 1); 510848b8605Smrg assert(format_desc->block.height == 1); 511848b8605Smrg 512848b8605Smrg if (format_desc->is_mixed) 513848b8605Smrg return FALSE; 514848b8605Smrg 515848b8605Smrg if (!format_desc->is_array && !format_desc->is_bitmask && 516848b8605Smrg format != PIPE_FORMAT_R11G11B10_FLOAT) 517848b8605Smrg return FALSE; 518b8e80941Smrg } 519848b8605Smrg 520b8e80941Smrg if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) && 521b8e80941Smrg ((bind & PIPE_BIND_DISPLAY_TARGET) == 0)) { 522b8e80941Smrg /* Disable all 3-channel formats, where channel size != 32 bits. 523b8e80941Smrg * In some cases we run into crashes (in generate_unswizzled_blend()), 524b8e80941Smrg * for 3-channel RGB16 variants, there was an apparent LLVM bug. 525b8e80941Smrg * In any case, disabling the shallower 3-channel formats avoids a 526b8e80941Smrg * number of issues with GL_ARB_copy_image support. 527848b8605Smrg */ 528b8e80941Smrg if (format_desc->is_array && 529b8e80941Smrg format_desc->nr_channels == 3 && 530b8e80941Smrg format_desc->block.bits != 96) { 531b8e80941Smrg return FALSE; 532848b8605Smrg } 533848b8605Smrg } 534848b8605Smrg 535848b8605Smrg if (bind & PIPE_BIND_DISPLAY_TARGET) { 536848b8605Smrg if(!winsys->is_displaytarget_format_supported(winsys, bind, format)) 537848b8605Smrg return FALSE; 538848b8605Smrg } 539848b8605Smrg 540848b8605Smrg if (bind & PIPE_BIND_DEPTH_STENCIL) { 541848b8605Smrg if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) 542848b8605Smrg return FALSE; 543848b8605Smrg 544848b8605Smrg if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) 545848b8605Smrg return FALSE; 546848b8605Smrg 547848b8605Smrg /* TODO: Support stencil-only formats */ 548b8e80941Smrg if (format_desc->swizzle[0] == PIPE_SWIZZLE_NONE) { 549848b8605Smrg return FALSE; 550848b8605Smrg } 551848b8605Smrg } 552848b8605Smrg 553b8e80941Smrg if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC || 554b8e80941Smrg format_desc->layout == UTIL_FORMAT_LAYOUT_ATC) { 555848b8605Smrg /* Software decoding is not hooked up. */ 556848b8605Smrg return FALSE; 557848b8605Smrg } 558848b8605Smrg 559b8e80941Smrg if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC && 560b8e80941Smrg format != PIPE_FORMAT_ETC1_RGB8) 561b8e80941Smrg return FALSE; 562848b8605Smrg 563848b8605Smrg /* 564848b8605Smrg * Everything can be supported by u_format 565848b8605Smrg * (those without fetch_rgba_float might be not but shouldn't hit that) 566848b8605Smrg */ 567848b8605Smrg 568848b8605Smrg return TRUE; 569848b8605Smrg} 570848b8605Smrg 571848b8605Smrg 572848b8605Smrg 573848b8605Smrg 574848b8605Smrgstatic void 575848b8605Smrgllvmpipe_flush_frontbuffer(struct pipe_screen *_screen, 576848b8605Smrg struct pipe_resource *resource, 577848b8605Smrg unsigned level, unsigned layer, 578848b8605Smrg void *context_private, 579848b8605Smrg struct pipe_box *sub_box) 580848b8605Smrg{ 581848b8605Smrg struct llvmpipe_screen *screen = llvmpipe_screen(_screen); 582848b8605Smrg struct sw_winsys *winsys = screen->winsys; 583848b8605Smrg struct llvmpipe_resource *texture = llvmpipe_resource(resource); 584848b8605Smrg 585848b8605Smrg assert(texture->dt); 586848b8605Smrg if (texture->dt) 587848b8605Smrg winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box); 588848b8605Smrg} 589848b8605Smrg 590848b8605Smrgstatic void 591848b8605Smrgllvmpipe_destroy_screen( struct pipe_screen *_screen ) 592848b8605Smrg{ 593848b8605Smrg struct llvmpipe_screen *screen = llvmpipe_screen(_screen); 594848b8605Smrg struct sw_winsys *winsys = screen->winsys; 595848b8605Smrg 596848b8605Smrg if (screen->rast) 597848b8605Smrg lp_rast_destroy(screen->rast); 598848b8605Smrg 599848b8605Smrg lp_jit_screen_cleanup(screen); 600848b8605Smrg 601848b8605Smrg if(winsys->destroy) 602848b8605Smrg winsys->destroy(winsys); 603848b8605Smrg 604b8e80941Smrg mtx_destroy(&screen->rast_mutex); 605848b8605Smrg 606848b8605Smrg FREE(screen); 607848b8605Smrg} 608848b8605Smrg 609848b8605Smrg 610848b8605Smrg 611848b8605Smrg 612848b8605Smrg/** 613848b8605Smrg * Fence reference counting. 614848b8605Smrg */ 615848b8605Smrgstatic void 616848b8605Smrgllvmpipe_fence_reference(struct pipe_screen *screen, 617848b8605Smrg struct pipe_fence_handle **ptr, 618848b8605Smrg struct pipe_fence_handle *fence) 619848b8605Smrg{ 620848b8605Smrg struct lp_fence **old = (struct lp_fence **) ptr; 621848b8605Smrg struct lp_fence *f = (struct lp_fence *) fence; 622848b8605Smrg 623848b8605Smrg lp_fence_reference(old, f); 624848b8605Smrg} 625848b8605Smrg 626848b8605Smrg 627848b8605Smrg/** 628848b8605Smrg * Wait for the fence to finish. 629848b8605Smrg */ 630848b8605Smrgstatic boolean 631848b8605Smrgllvmpipe_fence_finish(struct pipe_screen *screen, 632b8e80941Smrg struct pipe_context *ctx, 633848b8605Smrg struct pipe_fence_handle *fence_handle, 634848b8605Smrg uint64_t timeout) 635848b8605Smrg{ 636848b8605Smrg struct lp_fence *f = (struct lp_fence *) fence_handle; 637848b8605Smrg 638b8e80941Smrg if (!timeout) 639b8e80941Smrg return lp_fence_signalled(f); 640b8e80941Smrg 641b8e80941Smrg if (!lp_fence_signalled(f)) { 642b8e80941Smrg if (timeout != PIPE_TIMEOUT_INFINITE) 643b8e80941Smrg return lp_fence_timedwait(f, timeout); 644b8e80941Smrg 645b8e80941Smrg lp_fence_wait(f); 646b8e80941Smrg } 647848b8605Smrg return TRUE; 648848b8605Smrg} 649848b8605Smrg 650848b8605Smrgstatic uint64_t 651848b8605Smrgllvmpipe_get_timestamp(struct pipe_screen *_screen) 652848b8605Smrg{ 653848b8605Smrg return os_time_get_nano(); 654848b8605Smrg} 655848b8605Smrg 656848b8605Smrg/** 657848b8605Smrg * Create a new pipe_screen object 658848b8605Smrg * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen). 659848b8605Smrg */ 660848b8605Smrgstruct pipe_screen * 661848b8605Smrgllvmpipe_create_screen(struct sw_winsys *winsys) 662848b8605Smrg{ 663848b8605Smrg struct llvmpipe_screen *screen; 664848b8605Smrg 665848b8605Smrg util_cpu_detect(); 666848b8605Smrg 667848b8605Smrg#ifdef DEBUG 668848b8605Smrg LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 ); 669848b8605Smrg#endif 670848b8605Smrg 671848b8605Smrg LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 ); 672848b8605Smrg 673848b8605Smrg screen = CALLOC_STRUCT(llvmpipe_screen); 674848b8605Smrg if (!screen) 675848b8605Smrg return NULL; 676848b8605Smrg 677b8e80941Smrg if (!lp_jit_screen_init(screen)) { 678b8e80941Smrg FREE(screen); 679b8e80941Smrg return NULL; 680b8e80941Smrg } 681b8e80941Smrg 682848b8605Smrg screen->winsys = winsys; 683848b8605Smrg 684848b8605Smrg screen->base.destroy = llvmpipe_destroy_screen; 685848b8605Smrg 686848b8605Smrg screen->base.get_name = llvmpipe_get_name; 687848b8605Smrg screen->base.get_vendor = llvmpipe_get_vendor; 688b8e80941Smrg screen->base.get_device_vendor = llvmpipe_get_vendor; // TODO should be the CPU vendor 689848b8605Smrg screen->base.get_param = llvmpipe_get_param; 690848b8605Smrg screen->base.get_shader_param = llvmpipe_get_shader_param; 691848b8605Smrg screen->base.get_paramf = llvmpipe_get_paramf; 692848b8605Smrg screen->base.is_format_supported = llvmpipe_is_format_supported; 693848b8605Smrg 694848b8605Smrg screen->base.context_create = llvmpipe_create_context; 695848b8605Smrg screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; 696848b8605Smrg screen->base.fence_reference = llvmpipe_fence_reference; 697848b8605Smrg screen->base.fence_finish = llvmpipe_fence_finish; 698848b8605Smrg 699848b8605Smrg screen->base.get_timestamp = llvmpipe_get_timestamp; 700848b8605Smrg 701848b8605Smrg llvmpipe_init_screen_resource_funcs(&screen->base); 702848b8605Smrg 703848b8605Smrg screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0; 704848b8605Smrg#ifdef PIPE_SUBSYSTEM_EMBEDDED 705848b8605Smrg screen->num_threads = 0; 706848b8605Smrg#endif 707848b8605Smrg screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads); 708848b8605Smrg screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS); 709848b8605Smrg 710848b8605Smrg screen->rast = lp_rast_create(screen->num_threads); 711848b8605Smrg if (!screen->rast) { 712848b8605Smrg lp_jit_screen_cleanup(screen); 713848b8605Smrg FREE(screen); 714848b8605Smrg return NULL; 715848b8605Smrg } 716b8e80941Smrg (void) mtx_init(&screen->rast_mutex, mtx_plain); 717848b8605Smrg 718848b8605Smrg return &screen->base; 719848b8605Smrg} 720