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