19f464c52Smaya/*
29f464c52Smaya * Copyright © 2017 Intel Corporation
39f464c52Smaya *
49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
59f464c52Smaya * copy of this software and associated documentation files (the "Software"),
69f464c52Smaya * to deal in the Software without restriction, including without limitation
79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the
99f464c52Smaya * Software is furnished to do so, subject to the following conditions:
109f464c52Smaya *
119f464c52Smaya * The above copyright notice and this permission notice shall be included
129f464c52Smaya * in all copies or substantial portions of the Software.
139f464c52Smaya *
149f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
159f464c52Smaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
179f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
189f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
199f464c52Smaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
209f464c52Smaya * DEALINGS IN THE SOFTWARE.
219f464c52Smaya */
229f464c52Smaya
239f464c52Smaya/**
249f464c52Smaya * @file iris_screen.c
259f464c52Smaya *
269f464c52Smaya * Screen related driver hooks and capability lists.
279f464c52Smaya *
289f464c52Smaya * A program may use multiple rendering contexts (iris_context), but
299f464c52Smaya * they all share a common screen (iris_screen).  Global driver state
309f464c52Smaya * can be stored in the screen; it may be accessed by multiple threads.
319f464c52Smaya */
329f464c52Smaya
339f464c52Smaya#include <stdio.h>
349f464c52Smaya#include <errno.h>
359f464c52Smaya#include <sys/ioctl.h>
369f464c52Smaya#include "pipe/p_defines.h"
379f464c52Smaya#include "pipe/p_state.h"
389f464c52Smaya#include "pipe/p_context.h"
399f464c52Smaya#include "pipe/p_screen.h"
409f464c52Smaya#include "util/debug.h"
417ec681f3Smrg#include "util/u_cpu_detect.h"
429f464c52Smaya#include "util/u_inlines.h"
437ec681f3Smrg#include "util/format/u_format.h"
449f464c52Smaya#include "util/u_transfer_helper.h"
459f464c52Smaya#include "util/u_upload_mgr.h"
469f464c52Smaya#include "util/ralloc.h"
479f464c52Smaya#include "util/xmlconfig.h"
489f464c52Smaya#include "drm-uapi/i915_drm.h"
499f464c52Smaya#include "iris_context.h"
509f464c52Smaya#include "iris_defines.h"
519f464c52Smaya#include "iris_fence.h"
529f464c52Smaya#include "iris_pipe.h"
539f464c52Smaya#include "iris_resource.h"
549f464c52Smaya#include "iris_screen.h"
557ec681f3Smrg#include "compiler/glsl_types.h"
569f464c52Smaya#include "intel/compiler/brw_compiler.h"
577ec681f3Smrg#include "intel/common/intel_gem.h"
587ec681f3Smrg#include "intel/common/intel_l3_config.h"
597ec681f3Smrg#include "intel/common/intel_uuid.h"
607ec681f3Smrg#include "iris_monitor.h"
617ec681f3Smrg
627ec681f3Smrg#define genX_call(devinfo, func, ...)             \
637ec681f3Smrg   switch ((devinfo)->verx10) {                   \
647ec681f3Smrg   case 125:                                      \
657ec681f3Smrg      gfx125_##func(__VA_ARGS__);                 \
667ec681f3Smrg      break;                                      \
677ec681f3Smrg   case 120:                                      \
687ec681f3Smrg      gfx12_##func(__VA_ARGS__);                  \
697ec681f3Smrg      break;                                      \
707ec681f3Smrg   case 110:                                      \
717ec681f3Smrg      gfx11_##func(__VA_ARGS__);                  \
727ec681f3Smrg      break;                                      \
737ec681f3Smrg   case 90:                                       \
747ec681f3Smrg      gfx9_##func(__VA_ARGS__);                   \
757ec681f3Smrg      break;                                      \
767ec681f3Smrg   case 80:                                       \
777ec681f3Smrg      gfx8_##func(__VA_ARGS__);                   \
787ec681f3Smrg      break;                                      \
797ec681f3Smrg   default:                                       \
807ec681f3Smrg      unreachable("Unknown hardware generation"); \
817ec681f3Smrg   }
829f464c52Smaya
839f464c52Smayastatic void
849f464c52Smayairis_flush_frontbuffer(struct pipe_screen *_screen,
857ec681f3Smrg                       struct pipe_context *_pipe,
869f464c52Smaya                       struct pipe_resource *resource,
879f464c52Smaya                       unsigned level, unsigned layer,
889f464c52Smaya                       void *context_private, struct pipe_box *box)
899f464c52Smaya{
909f464c52Smaya}
919f464c52Smaya
929f464c52Smayastatic const char *
939f464c52Smayairis_get_vendor(struct pipe_screen *pscreen)
949f464c52Smaya{
959f464c52Smaya   return "Intel";
969f464c52Smaya}
979f464c52Smaya
989f464c52Smayastatic const char *
999f464c52Smayairis_get_device_vendor(struct pipe_screen *pscreen)
1009f464c52Smaya{
1019f464c52Smaya   return "Intel";
1029f464c52Smaya}
1039f464c52Smaya
1047ec681f3Smrgstatic void
1057ec681f3Smrgiris_get_device_uuid(struct pipe_screen *pscreen, char *uuid)
1067ec681f3Smrg{
1077ec681f3Smrg   struct iris_screen *screen = (struct iris_screen *)pscreen;
1087ec681f3Smrg   const struct isl_device *isldev = &screen->isl_dev;
1097ec681f3Smrg
1107ec681f3Smrg   intel_uuid_compute_device_id((uint8_t *)uuid, isldev, PIPE_UUID_SIZE);
1117ec681f3Smrg}
1127ec681f3Smrg
1137ec681f3Smrgstatic void
1147ec681f3Smrgiris_get_driver_uuid(struct pipe_screen *pscreen, char *uuid)
1157ec681f3Smrg{
1167ec681f3Smrg   struct iris_screen *screen = (struct iris_screen *)pscreen;
1177ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
1187ec681f3Smrg
1197ec681f3Smrg   intel_uuid_compute_driver_id((uint8_t *)uuid, devinfo, PIPE_UUID_SIZE);
1207ec681f3Smrg}
1217ec681f3Smrg
1227ec681f3Smrgstatic bool
1237ec681f3Smrgiris_enable_clover()
1247ec681f3Smrg{
1257ec681f3Smrg   static int enable = -1;
1267ec681f3Smrg   if (enable < 0)
1277ec681f3Smrg      enable = env_var_as_boolean("IRIS_ENABLE_CLOVER", false);
1287ec681f3Smrg   return enable;
1297ec681f3Smrg}
1307ec681f3Smrg
1317ec681f3Smrgstatic void
1327ec681f3Smrgiris_warn_clover()
1337ec681f3Smrg{
1347ec681f3Smrg   static bool warned = false;
1357ec681f3Smrg   if (warned)
1367ec681f3Smrg      return;
1377ec681f3Smrg
1387ec681f3Smrg   warned = true;
1397ec681f3Smrg   fprintf(stderr, "WARNING: OpenCL support via iris+clover is incomplete.\n"
1407ec681f3Smrg                   "For a complete and conformant OpenCL implementation, use\n"
1417ec681f3Smrg                   "https://github.com/intel/compute-runtime instead\n");
1427ec681f3Smrg}
1437ec681f3Smrg
1449f464c52Smayastatic const char *
1459f464c52Smayairis_get_name(struct pipe_screen *pscreen)
1469f464c52Smaya{
1479f464c52Smaya   struct iris_screen *screen = (struct iris_screen *)pscreen;
1487ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
1499f464c52Smaya   static char buf[128];
1509f464c52Smaya
1517ec681f3Smrg   snprintf(buf, sizeof(buf), "Mesa %s", devinfo->name);
1529f464c52Smaya   return buf;
1539f464c52Smaya}
1549f464c52Smaya
1559f464c52Smayastatic int
1569f464c52Smayairis_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
1579f464c52Smaya{
1589f464c52Smaya   struct iris_screen *screen = (struct iris_screen *)pscreen;
1597ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
1609f464c52Smaya
1619f464c52Smaya   switch (param) {
1629f464c52Smaya   case PIPE_CAP_NPOT_TEXTURES:
1639f464c52Smaya   case PIPE_CAP_ANISOTROPIC_FILTER:
1649f464c52Smaya   case PIPE_CAP_POINT_SPRITE:
1659f464c52Smaya   case PIPE_CAP_OCCLUSION_QUERY:
1669f464c52Smaya   case PIPE_CAP_QUERY_TIME_ELAPSED:
1679f464c52Smaya   case PIPE_CAP_TEXTURE_SWIZZLE:
1689f464c52Smaya   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
1699f464c52Smaya   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
1707ec681f3Smrg   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
1717ec681f3Smrg   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
1727ec681f3Smrg   case PIPE_CAP_VERTEX_SHADER_SATURATE:
1739f464c52Smaya   case PIPE_CAP_PRIMITIVE_RESTART:
1747ec681f3Smrg   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
1759f464c52Smaya   case PIPE_CAP_INDEP_BLEND_ENABLE:
1769f464c52Smaya   case PIPE_CAP_INDEP_BLEND_FUNC:
1779f464c52Smaya   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
1789f464c52Smaya   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
1799f464c52Smaya   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
1809f464c52Smaya   case PIPE_CAP_DEPTH_CLIP_DISABLE:
1819f464c52Smaya   case PIPE_CAP_TGSI_INSTANCEID:
1829f464c52Smaya   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
1839f464c52Smaya   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
1849f464c52Smaya   case PIPE_CAP_SEAMLESS_CUBE_MAP:
1859f464c52Smaya   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
1869f464c52Smaya   case PIPE_CAP_CONDITIONAL_RENDER:
1879f464c52Smaya   case PIPE_CAP_TEXTURE_BARRIER:
1889f464c52Smaya   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
1899f464c52Smaya   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
1909f464c52Smaya   case PIPE_CAP_COMPUTE:
1919f464c52Smaya   case PIPE_CAP_START_INSTANCE:
1929f464c52Smaya   case PIPE_CAP_QUERY_TIMESTAMP:
1939f464c52Smaya   case PIPE_CAP_TEXTURE_MULTISAMPLE:
1949f464c52Smaya   case PIPE_CAP_CUBE_MAP_ARRAY:
1959f464c52Smaya   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
1969f464c52Smaya   case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
1979f464c52Smaya   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
1989f464c52Smaya   case PIPE_CAP_TEXTURE_QUERY_LOD:
1999f464c52Smaya   case PIPE_CAP_SAMPLE_SHADING:
2009f464c52Smaya   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
2019f464c52Smaya   case PIPE_CAP_DRAW_INDIRECT:
2027ec681f3Smrg   case PIPE_CAP_MULTI_DRAW_INDIRECT:
2037ec681f3Smrg   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
2049f464c52Smaya   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
2059f464c52Smaya   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
2069f464c52Smaya   case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
2079f464c52Smaya   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
2087ec681f3Smrg   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
2099f464c52Smaya   case PIPE_CAP_ACCELERATED:
2109f464c52Smaya   case PIPE_CAP_UMA:
2119f464c52Smaya   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
2129f464c52Smaya   case PIPE_CAP_CLIP_HALFZ:
2139f464c52Smaya   case PIPE_CAP_TGSI_TEXCOORD:
2149f464c52Smaya   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
2159f464c52Smaya   case PIPE_CAP_DOUBLES:
2169f464c52Smaya   case PIPE_CAP_INT64:
2179f464c52Smaya   case PIPE_CAP_INT64_DIVMOD:
2189f464c52Smaya   case PIPE_CAP_SAMPLER_VIEW_TARGET:
2199f464c52Smaya   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
2207ec681f3Smrg   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
2219f464c52Smaya   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
2229f464c52Smaya   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
2239f464c52Smaya   case PIPE_CAP_CULL_DISTANCE:
2249f464c52Smaya   case PIPE_CAP_PACKED_UNIFORMS:
2259f464c52Smaya   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
2269f464c52Smaya   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
2279f464c52Smaya   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
2289f464c52Smaya   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
2299f464c52Smaya   case PIPE_CAP_QUERY_SO_OVERFLOW:
2309f464c52Smaya   case PIPE_CAP_QUERY_BUFFER_OBJECT:
2319f464c52Smaya   case PIPE_CAP_TGSI_TEX_TXF_LZ:
2329f464c52Smaya   case PIPE_CAP_TGSI_TXQS:
2339f464c52Smaya   case PIPE_CAP_TGSI_CLOCK:
2349f464c52Smaya   case PIPE_CAP_TGSI_BALLOT:
2359f464c52Smaya   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
2369f464c52Smaya   case PIPE_CAP_CLEAR_TEXTURE:
2377ec681f3Smrg   case PIPE_CAP_CLEAR_SCISSORED:
2389f464c52Smaya   case PIPE_CAP_TGSI_VOTE:
2399f464c52Smaya   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
2409f464c52Smaya   case PIPE_CAP_TEXTURE_GATHER_SM5:
2419f464c52Smaya   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
2429f464c52Smaya   case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
2439f464c52Smaya   case PIPE_CAP_LOAD_CONSTBUF:
2449f464c52Smaya   case PIPE_CAP_NIR_COMPACT_ARRAYS:
2459f464c52Smaya   case PIPE_CAP_DRAW_PARAMETERS:
2467ec681f3Smrg   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
2479f464c52Smaya   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
2489f464c52Smaya   case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
2499f464c52Smaya   case PIPE_CAP_INVALIDATE_BUFFER:
2509f464c52Smaya   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
2517ec681f3Smrg   case PIPE_CAP_CS_DERIVED_SYSTEM_VALUES_SUPPORTED:
2527ec681f3Smrg   case PIPE_CAP_TEXTURE_SHADOW_LOD:
2537ec681f3Smrg   case PIPE_CAP_SHADER_SAMPLES_IDENTICAL:
2547ec681f3Smrg   case PIPE_CAP_GL_SPIRV:
2557ec681f3Smrg   case PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS:
2567ec681f3Smrg   case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION:
2577ec681f3Smrg   case PIPE_CAP_NATIVE_FENCE_FD:
2587ec681f3Smrg   case PIPE_CAP_MEMOBJ:
2597ec681f3Smrg   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
2607ec681f3Smrg   case PIPE_CAP_FENCE_SIGNAL:
2619f464c52Smaya      return true;
2627ec681f3Smrg   case PIPE_CAP_FBFETCH:
2637ec681f3Smrg      return BRW_MAX_DRAW_BUFFERS;
2647ec681f3Smrg   case PIPE_CAP_FBFETCH_COHERENT:
2659f464c52Smaya   case PIPE_CAP_CONSERVATIVE_RASTER_INNER_COVERAGE:
2669f464c52Smaya   case PIPE_CAP_POST_DEPTH_COVERAGE:
2679f464c52Smaya   case PIPE_CAP_SHADER_STENCIL_EXPORT:
2689f464c52Smaya   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
2697ec681f3Smrg   case PIPE_CAP_FRAGMENT_SHADER_INTERLOCK:
2707ec681f3Smrg   case PIPE_CAP_ATOMIC_FLOAT_MINMAX:
2717ec681f3Smrg      return devinfo->ver >= 9;
2727ec681f3Smrg   case PIPE_CAP_DEPTH_BOUNDS_TEST:
2737ec681f3Smrg      return devinfo->ver >= 12;
2749f464c52Smaya   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
2759f464c52Smaya      return 1;
2769f464c52Smaya   case PIPE_CAP_MAX_RENDER_TARGETS:
2779f464c52Smaya      return BRW_MAX_DRAW_BUFFERS;
2787ec681f3Smrg   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
2797ec681f3Smrg      return 16384;
2809f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
2819f464c52Smaya      return IRIS_MAX_MIPLEVELS; /* 16384x16384 */
2829f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
2839f464c52Smaya      return 12; /* 2048x2048 */
2849f464c52Smaya   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
2859f464c52Smaya      return 4;
2869f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
2879f464c52Smaya      return 2048;
2889f464c52Smaya   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
2899f464c52Smaya      return BRW_MAX_SOL_BINDINGS / IRIS_MAX_SOL_BUFFERS;
2909f464c52Smaya   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
2919f464c52Smaya      return BRW_MAX_SOL_BINDINGS;
2929f464c52Smaya   case PIPE_CAP_GLSL_FEATURE_LEVEL:
2939f464c52Smaya   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
2947ec681f3Smrg      return 460;
2959f464c52Smaya   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
2969f464c52Smaya      /* 3DSTATE_CONSTANT_XS requires the start of UBOs to be 32B aligned */
2979f464c52Smaya      return 32;
2989f464c52Smaya   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
2999f464c52Smaya      return IRIS_MAP_BUFFER_ALIGNMENT;
3009f464c52Smaya   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
3017ec681f3Smrg      return 4;
3029f464c52Smaya   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
3039f464c52Smaya      return 1 << 27;
3049f464c52Smaya   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
3059f464c52Smaya      return 16; // XXX: u_screen says 256 is the minimum value...
3069f464c52Smaya   case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
3077ec681f3Smrg      return true;
3089f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
3099f464c52Smaya      return IRIS_MAX_TEXTURE_BUFFER_SIZE;
3109f464c52Smaya   case PIPE_CAP_MAX_VIEWPORTS:
3119f464c52Smaya      return 16;
3129f464c52Smaya   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
3139f464c52Smaya      return 256;
3149f464c52Smaya   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
3159f464c52Smaya      return 1024;
3169f464c52Smaya   case PIPE_CAP_MAX_GS_INVOCATIONS:
3179f464c52Smaya      return 32;
3189f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
3199f464c52Smaya      return 4;
3209f464c52Smaya   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
3219f464c52Smaya      return -32;
3229f464c52Smaya   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
3239f464c52Smaya      return 31;
3249f464c52Smaya   case PIPE_CAP_MAX_VERTEX_STREAMS:
3259f464c52Smaya      return 4;
3269f464c52Smaya   case PIPE_CAP_VENDOR_ID:
3279f464c52Smaya      return 0x8086;
3289f464c52Smaya   case PIPE_CAP_DEVICE_ID:
3299f464c52Smaya      return screen->pci_id;
3307ec681f3Smrg   case PIPE_CAP_VIDEO_MEMORY: {
3317ec681f3Smrg      /* Once a batch uses more than 75% of the maximum mappable size, we
3327ec681f3Smrg       * assume that there's some fragmentation, and we start doing extra
3337ec681f3Smrg       * flushing, etc.  That's the big cliff apps will care about.
3347ec681f3Smrg       */
3357ec681f3Smrg      const unsigned gpu_mappable_megabytes =
3367ec681f3Smrg         (devinfo->aperture_bytes * 3 / 4) / (1024 * 1024);
3377ec681f3Smrg
3387ec681f3Smrg      const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
3397ec681f3Smrg      const long system_page_size = sysconf(_SC_PAGE_SIZE);
3407ec681f3Smrg
3417ec681f3Smrg      if (system_memory_pages <= 0 || system_page_size <= 0)
3427ec681f3Smrg         return -1;
3437ec681f3Smrg
3447ec681f3Smrg      const uint64_t system_memory_bytes =
3457ec681f3Smrg         (uint64_t) system_memory_pages * (uint64_t) system_page_size;
3467ec681f3Smrg
3477ec681f3Smrg      const unsigned system_memory_megabytes =
3487ec681f3Smrg         (unsigned) (system_memory_bytes / (1024 * 1024));
3497ec681f3Smrg
3507ec681f3Smrg      return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
3517ec681f3Smrg   }
3529f464c52Smaya   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
3539f464c52Smaya   case PIPE_CAP_MAX_VARYINGS:
3549f464c52Smaya      return 32;
3559f464c52Smaya   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
3569f464c52Smaya      /* AMD_pinned_memory assumes the flexibility of using client memory
3579f464c52Smaya       * for any buffer (incl. vertex buffers) which rules out the prospect
3589f464c52Smaya       * of using snooped buffers, as using snooped buffers without
3599f464c52Smaya       * cogniscience is likely to be detrimental to performance and require
3609f464c52Smaya       * extensive checking in the driver for correctness, e.g. to prevent
3619f464c52Smaya       * illegal snoop <-> snoop transfers.
3629f464c52Smaya       */
3639f464c52Smaya      return devinfo->has_llc;
3647ec681f3Smrg   case PIPE_CAP_THROTTLE:
3657ec681f3Smrg      return screen->driconf.disable_throttling ? 0 : 1;
3669f464c52Smaya
3679f464c52Smaya   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
3689f464c52Smaya      return PIPE_CONTEXT_PRIORITY_LOW |
3699f464c52Smaya             PIPE_CONTEXT_PRIORITY_MEDIUM |
3709f464c52Smaya             PIPE_CONTEXT_PRIORITY_HIGH;
3719f464c52Smaya
3727ec681f3Smrg   case PIPE_CAP_FRONTEND_NOOP:
3737ec681f3Smrg      return true;
3747ec681f3Smrg
3759f464c52Smaya   // XXX: don't hardcode 00:00:02.0 PCI here
3769f464c52Smaya   case PIPE_CAP_PCI_GROUP:
3779f464c52Smaya      return 0;
3789f464c52Smaya   case PIPE_CAP_PCI_BUS:
3799f464c52Smaya      return 0;
3809f464c52Smaya   case PIPE_CAP_PCI_DEVICE:
3819f464c52Smaya      return 2;
3829f464c52Smaya   case PIPE_CAP_PCI_FUNCTION:
3839f464c52Smaya      return 0;
3849f464c52Smaya
3857ec681f3Smrg   case PIPE_CAP_OPENCL_INTEGER_FUNCTIONS:
3867ec681f3Smrg   case PIPE_CAP_INTEGER_MULTIPLY_32X16:
3877ec681f3Smrg      return true;
3887ec681f3Smrg
3897ec681f3Smrg   case PIPE_CAP_ALLOW_DYNAMIC_VAO_FASTPATH:
3907ec681f3Smrg      /* Internal details of VF cache make this optimization harmful on GFX
3917ec681f3Smrg       * version 8 and 9, because generated VERTEX_BUFFER_STATEs are cached
3927ec681f3Smrg       * separately.
3937ec681f3Smrg       */
3947ec681f3Smrg      return devinfo->ver >= 11;
3957ec681f3Smrg
3969f464c52Smaya   default:
3979f464c52Smaya      return u_pipe_screen_get_param_defaults(pscreen, param);
3989f464c52Smaya   }
3999f464c52Smaya   return 0;
4009f464c52Smaya}
4019f464c52Smaya
4029f464c52Smayastatic float
4039f464c52Smayairis_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
4049f464c52Smaya{
4059f464c52Smaya   switch (param) {
4069f464c52Smaya   case PIPE_CAPF_MAX_LINE_WIDTH:
4079f464c52Smaya   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
4089f464c52Smaya      return 7.375f;
4099f464c52Smaya
4109f464c52Smaya   case PIPE_CAPF_MAX_POINT_WIDTH:
4119f464c52Smaya   case PIPE_CAPF_MAX_POINT_WIDTH_AA:
4129f464c52Smaya      return 255.0f;
4139f464c52Smaya
4149f464c52Smaya   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
4159f464c52Smaya      return 16.0f;
4169f464c52Smaya   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
4179f464c52Smaya      return 15.0f;
4189f464c52Smaya   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
4199f464c52Smaya   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
4209f464c52Smaya   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
4219f464c52Smaya      return 0.0f;
4229f464c52Smaya   default:
4239f464c52Smaya      unreachable("unknown param");
4249f464c52Smaya   }
4259f464c52Smaya}
4269f464c52Smaya
4279f464c52Smayastatic int
4289f464c52Smayairis_get_shader_param(struct pipe_screen *pscreen,
4299f464c52Smaya                      enum pipe_shader_type p_stage,
4309f464c52Smaya                      enum pipe_shader_cap param)
4319f464c52Smaya{
4329f464c52Smaya   gl_shader_stage stage = stage_from_pipe(p_stage);
4339f464c52Smaya
4349f464c52Smaya   /* this is probably not totally correct.. but it's a start: */
4359f464c52Smaya   switch (param) {
4369f464c52Smaya   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
4379f464c52Smaya      return stage == MESA_SHADER_FRAGMENT ? 1024 : 16384;
4389f464c52Smaya   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
4399f464c52Smaya   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
4409f464c52Smaya   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
4419f464c52Smaya      return stage == MESA_SHADER_FRAGMENT ? 1024 : 0;
4429f464c52Smaya
4439f464c52Smaya   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
4449f464c52Smaya      return UINT_MAX;
4459f464c52Smaya
4469f464c52Smaya   case PIPE_SHADER_CAP_MAX_INPUTS:
4479f464c52Smaya      return stage == MESA_SHADER_VERTEX ? 16 : 32;
4489f464c52Smaya   case PIPE_SHADER_CAP_MAX_OUTPUTS:
4499f464c52Smaya      return 32;
4509f464c52Smaya   case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
4519f464c52Smaya      return 16 * 1024 * sizeof(float);
4529f464c52Smaya   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
4539f464c52Smaya      return 16;
4549f464c52Smaya   case PIPE_SHADER_CAP_MAX_TEMPS:
4559f464c52Smaya      return 256; /* GL_MAX_PROGRAM_TEMPORARIES_ARB */
4569f464c52Smaya   case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
4579f464c52Smaya      return 0;
4589f464c52Smaya   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
4599f464c52Smaya   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
4609f464c52Smaya   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
4619f464c52Smaya   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
4629f464c52Smaya      /* Lie about these to avoid st/mesa's GLSL IR lowering of indirects,
4639f464c52Smaya       * which we don't want.  Our compiler backend will check brw_compiler's
4649f464c52Smaya       * options and call nir_lower_indirect_derefs appropriately anyway.
4659f464c52Smaya       */
4669f464c52Smaya      return true;
4679f464c52Smaya   case PIPE_SHADER_CAP_SUBROUTINES:
4689f464c52Smaya      return 0;
4699f464c52Smaya   case PIPE_SHADER_CAP_INTEGERS:
4709f464c52Smaya      return 1;
4719f464c52Smaya   case PIPE_SHADER_CAP_INT64_ATOMICS:
4729f464c52Smaya   case PIPE_SHADER_CAP_FP16:
4737ec681f3Smrg   case PIPE_SHADER_CAP_FP16_DERIVATIVES:
4747ec681f3Smrg   case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
4757ec681f3Smrg   case PIPE_SHADER_CAP_INT16:
4767ec681f3Smrg   case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
4779f464c52Smaya      return 0;
4789f464c52Smaya   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
4799f464c52Smaya   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
4809f464c52Smaya   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
4819f464c52Smaya      return IRIS_MAX_TEXTURE_SAMPLERS;
4829f464c52Smaya   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
4839f464c52Smaya      return IRIS_MAX_ABOS + IRIS_MAX_SSBOS;
4849f464c52Smaya   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
4859f464c52Smaya   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
4869f464c52Smaya      return 0;
4879f464c52Smaya   case PIPE_SHADER_CAP_PREFERRED_IR:
4889f464c52Smaya      return PIPE_SHADER_IR_NIR;
4897ec681f3Smrg   case PIPE_SHADER_CAP_SUPPORTED_IRS: {
4907ec681f3Smrg      int irs = 1 << PIPE_SHADER_IR_NIR;
4917ec681f3Smrg      if (iris_enable_clover())
4927ec681f3Smrg         irs |= 1 << PIPE_SHADER_IR_NIR_SERIALIZED;
4937ec681f3Smrg      return irs;
4947ec681f3Smrg   }
4957ec681f3Smrg   case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
4967ec681f3Smrg   case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
4977ec681f3Smrg      return 1;
4989f464c52Smaya   case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
4999f464c52Smaya   case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
5009f464c52Smaya   case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
5019f464c52Smaya   case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
5029f464c52Smaya   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
5039f464c52Smaya   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
5047ec681f3Smrg   case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
5059f464c52Smaya      return 0;
5069f464c52Smaya   default:
5079f464c52Smaya      unreachable("unknown shader param");
5089f464c52Smaya   }
5099f464c52Smaya}
5109f464c52Smaya
5119f464c52Smayastatic int
5129f464c52Smayairis_get_compute_param(struct pipe_screen *pscreen,
5139f464c52Smaya                       enum pipe_shader_ir ir_type,
5149f464c52Smaya                       enum pipe_compute_cap param,
5159f464c52Smaya                       void *ret)
5169f464c52Smaya{
5179f464c52Smaya   struct iris_screen *screen = (struct iris_screen *)pscreen;
5187ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
5199f464c52Smaya
5207ec681f3Smrg   const uint32_t max_invocations = 32 * devinfo->max_cs_workgroup_threads;
5219f464c52Smaya
5229f464c52Smaya#define RET(x) do {                  \
5239f464c52Smaya   if (ret)                          \
5249f464c52Smaya      memcpy(ret, x, sizeof(x));     \
5259f464c52Smaya   return sizeof(x);                 \
5269f464c52Smaya} while (0)
5279f464c52Smaya
5289f464c52Smaya   switch (param) {
5299f464c52Smaya   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
5307ec681f3Smrg      /* This gets queried on clover device init and is never queried by the
5317ec681f3Smrg       * OpenGL state tracker.
5327ec681f3Smrg       */
5337ec681f3Smrg      iris_warn_clover();
5347ec681f3Smrg      RET((uint32_t []){ 64 });
5359f464c52Smaya
5369f464c52Smaya   case PIPE_COMPUTE_CAP_IR_TARGET:
5379f464c52Smaya      if (ret)
5389f464c52Smaya         strcpy(ret, "gen");
5399f464c52Smaya      return 4;
5409f464c52Smaya
5419f464c52Smaya   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
5429f464c52Smaya      RET((uint64_t []) { 3 });
5439f464c52Smaya
5449f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
5459f464c52Smaya      RET(((uint64_t []) { 65535, 65535, 65535 }));
5469f464c52Smaya
5479f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
5489f464c52Smaya      /* MaxComputeWorkGroupSize[0..2] */
5499f464c52Smaya      RET(((uint64_t []) {max_invocations, max_invocations, max_invocations}));
5509f464c52Smaya
5519f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
5529f464c52Smaya      /* MaxComputeWorkGroupInvocations */
5537ec681f3Smrg   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
5547ec681f3Smrg      /* MaxComputeVariableGroupInvocations */
5559f464c52Smaya      RET((uint64_t []) { max_invocations });
5569f464c52Smaya
5579f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
5589f464c52Smaya      /* MaxComputeSharedMemorySize */
5599f464c52Smaya      RET((uint64_t []) { 64 * 1024 });
5609f464c52Smaya
5619f464c52Smaya   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
5629f464c52Smaya      RET((uint32_t []) { 1 });
5639f464c52Smaya
5649f464c52Smaya   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
5659f464c52Smaya      RET((uint32_t []) { BRW_SUBGROUP_SIZE });
5669f464c52Smaya
5679f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
5689f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
5697ec681f3Smrg      RET((uint64_t []) { 1 << 30 }); /* TODO */
5707ec681f3Smrg
5717ec681f3Smrg   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
5727ec681f3Smrg      RET((uint32_t []) { 400 }); /* TODO */
5737ec681f3Smrg
5747ec681f3Smrg   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS: {
5757ec681f3Smrg      RET((uint32_t []) { intel_device_info_subslice_total(devinfo) });
5767ec681f3Smrg   }
5777ec681f3Smrg
5789f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
5797ec681f3Smrg      /* MaxComputeSharedMemorySize */
5807ec681f3Smrg      RET((uint64_t []) { 64 * 1024 });
5817ec681f3Smrg
5829f464c52Smaya   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
5837ec681f3Smrg      /* We could probably allow more; this is the OpenCL minimum */
5847ec681f3Smrg      RET((uint64_t []) { 1024 });
5859f464c52Smaya
5869f464c52Smaya   default:
5879f464c52Smaya      unreachable("unknown compute param");
5889f464c52Smaya   }
5899f464c52Smaya}
5909f464c52Smaya
5919f464c52Smayastatic uint64_t
5929f464c52Smayairis_get_timestamp(struct pipe_screen *pscreen)
5939f464c52Smaya{
5949f464c52Smaya   struct iris_screen *screen = (struct iris_screen *) pscreen;
5959f464c52Smaya   const unsigned TIMESTAMP = 0x2358;
5969f464c52Smaya   uint64_t result;
5979f464c52Smaya
5989f464c52Smaya   iris_reg_read(screen->bufmgr, TIMESTAMP | 1, &result);
5999f464c52Smaya
6007ec681f3Smrg   result = intel_device_info_timebase_scale(&screen->devinfo, result);
6019f464c52Smaya   result &= (1ull << TIMESTAMP_BITS) - 1;
6029f464c52Smaya
6039f464c52Smaya   return result;
6049f464c52Smaya}
6059f464c52Smaya
6067ec681f3Smrgvoid
6077ec681f3Smrgiris_screen_destroy(struct iris_screen *screen)
6089f464c52Smaya{
6097ec681f3Smrg   iris_destroy_screen_measure(screen);
6107ec681f3Smrg   util_queue_destroy(&screen->shader_compiler_queue);
6117ec681f3Smrg   glsl_type_singleton_decref();
6129f464c52Smaya   iris_bo_unreference(screen->workaround_bo);
6137ec681f3Smrg   u_transfer_helper_destroy(screen->base.transfer_helper);
6147ec681f3Smrg   iris_bufmgr_unref(screen->bufmgr);
6157ec681f3Smrg   disk_cache_destroy(screen->disk_cache);
6167ec681f3Smrg   close(screen->winsys_fd);
6179f464c52Smaya   ralloc_free(screen);
6189f464c52Smaya}
6199f464c52Smaya
6207ec681f3Smrgstatic void
6217ec681f3Smrgiris_screen_unref(struct pipe_screen *pscreen)
6227ec681f3Smrg{
6237ec681f3Smrg   iris_pscreen_unref(pscreen);
6247ec681f3Smrg}
6257ec681f3Smrg
6269f464c52Smayastatic void
6279f464c52Smayairis_query_memory_info(struct pipe_screen *pscreen,
6289f464c52Smaya                       struct pipe_memory_info *info)
6299f464c52Smaya{
6309f464c52Smaya}
6319f464c52Smaya
6329f464c52Smayastatic const void *
6339f464c52Smayairis_get_compiler_options(struct pipe_screen *pscreen,
6349f464c52Smaya                          enum pipe_shader_ir ir,
6359f464c52Smaya                          enum pipe_shader_type pstage)
6369f464c52Smaya{
6379f464c52Smaya   struct iris_screen *screen = (struct iris_screen *) pscreen;
6389f464c52Smaya   gl_shader_stage stage = stage_from_pipe(pstage);
6399f464c52Smaya   assert(ir == PIPE_SHADER_IR_NIR);
6409f464c52Smaya
6419f464c52Smaya   return screen->compiler->glsl_compiler_options[stage].NirOptions;
6429f464c52Smaya}
6439f464c52Smaya
6447ec681f3Smrgstatic struct disk_cache *
6457ec681f3Smrgiris_get_disk_shader_cache(struct pipe_screen *pscreen)
6467ec681f3Smrg{
6477ec681f3Smrg   struct iris_screen *screen = (struct iris_screen *) pscreen;
6487ec681f3Smrg   return screen->disk_cache;
6497ec681f3Smrg}
6507ec681f3Smrg
6519f464c52Smayastatic int
6527ec681f3Smrgiris_getparam(int fd, int param, int *value)
6539f464c52Smaya{
6549f464c52Smaya   struct drm_i915_getparam gp = { .param = param, .value = value };
6559f464c52Smaya
6567ec681f3Smrg   if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) == -1)
6579f464c52Smaya      return -errno;
6589f464c52Smaya
6599f464c52Smaya   return 0;
6609f464c52Smaya}
6619f464c52Smaya
6629f464c52Smayastatic int
6637ec681f3Smrgiris_getparam_integer(int fd, int param)
6649f464c52Smaya{
6659f464c52Smaya   int value = -1;
6669f464c52Smaya
6677ec681f3Smrg   if (iris_getparam(fd, param, &value) == 0)
6689f464c52Smaya      return value;
6699f464c52Smaya
6709f464c52Smaya   return -1;
6719f464c52Smaya}
6729f464c52Smaya
6737ec681f3Smrgstatic const struct intel_l3_config *
6747ec681f3Smrgiris_get_default_l3_config(const struct intel_device_info *devinfo,
6757ec681f3Smrg                           bool compute)
6767ec681f3Smrg{
6777ec681f3Smrg   bool wants_dc_cache = true;
6787ec681f3Smrg   bool has_slm = compute;
6797ec681f3Smrg   const struct intel_l3_weights w =
6807ec681f3Smrg      intel_get_default_l3_weights(devinfo, wants_dc_cache, has_slm);
6817ec681f3Smrg   return intel_get_l3_config(devinfo, w);
6827ec681f3Smrg}
6837ec681f3Smrg
6849f464c52Smayastatic void
6857ec681f3Smrgiris_shader_debug_log(void *data, unsigned *id, const char *fmt, ...)
6869f464c52Smaya{
6879f464c52Smaya   struct pipe_debug_callback *dbg = data;
6889f464c52Smaya   va_list args;
6899f464c52Smaya
6909f464c52Smaya   if (!dbg->debug_message)
6919f464c52Smaya      return;
6929f464c52Smaya
6939f464c52Smaya   va_start(args, fmt);
6947ec681f3Smrg   dbg->debug_message(dbg->data, id, PIPE_DEBUG_TYPE_SHADER_INFO, fmt, args);
6959f464c52Smaya   va_end(args);
6969f464c52Smaya}
6979f464c52Smaya
6989f464c52Smayastatic void
6997ec681f3Smrgiris_shader_perf_log(void *data, unsigned *id, const char *fmt, ...)
7009f464c52Smaya{
7019f464c52Smaya   struct pipe_debug_callback *dbg = data;
7029f464c52Smaya   va_list args;
7039f464c52Smaya   va_start(args, fmt);
7049f464c52Smaya
7057ec681f3Smrg   if (INTEL_DEBUG(DEBUG_PERF)) {
7069f464c52Smaya      va_list args_copy;
7079f464c52Smaya      va_copy(args_copy, args);
7089f464c52Smaya      vfprintf(stderr, fmt, args_copy);
7099f464c52Smaya      va_end(args_copy);
7109f464c52Smaya   }
7119f464c52Smaya
7129f464c52Smaya   if (dbg->debug_message) {
7137ec681f3Smrg      dbg->debug_message(dbg->data, id, PIPE_DEBUG_TYPE_PERF_INFO, fmt, args);
7149f464c52Smaya   }
7159f464c52Smaya
7169f464c52Smaya   va_end(args);
7179f464c52Smaya}
7189f464c52Smaya
7197ec681f3Smrgstatic void
7207ec681f3Smrgiris_detect_kernel_features(struct iris_screen *screen)
7217ec681f3Smrg{
7227ec681f3Smrg   /* Kernel 5.2+ */
7237ec681f3Smrg   if (intel_gem_supports_syncobj_wait(screen->fd))
7247ec681f3Smrg      screen->kernel_features |= KERNEL_HAS_WAIT_FOR_SUBMIT;
7257ec681f3Smrg}
7267ec681f3Smrg
7277ec681f3Smrgstatic bool
7287ec681f3Smrgiris_init_identifier_bo(struct iris_screen *screen)
7297ec681f3Smrg{
7307ec681f3Smrg   void *bo_map;
7317ec681f3Smrg
7327ec681f3Smrg   bo_map = iris_bo_map(NULL, screen->workaround_bo, MAP_READ | MAP_WRITE);
7337ec681f3Smrg   if (!bo_map)
7347ec681f3Smrg      return false;
7357ec681f3Smrg
7367ec681f3Smrg   assert(iris_bo_is_real(screen->workaround_bo));
7377ec681f3Smrg
7387ec681f3Smrg   screen->workaround_bo->real.kflags |=
7397ec681f3Smrg      EXEC_OBJECT_CAPTURE | EXEC_OBJECT_ASYNC;
7407ec681f3Smrg   screen->workaround_address = (struct iris_address) {
7417ec681f3Smrg      .bo = screen->workaround_bo,
7427ec681f3Smrg      .offset = ALIGN(
7437ec681f3Smrg         intel_debug_write_identifiers(bo_map, 4096, "Iris") + 8, 8),
7447ec681f3Smrg   };
7457ec681f3Smrg
7467ec681f3Smrg   iris_bo_unmap(screen->workaround_bo);
7477ec681f3Smrg
7487ec681f3Smrg   return true;
7497ec681f3Smrg}
7507ec681f3Smrg
7519f464c52Smayastruct pipe_screen *
7529f464c52Smayairis_screen_create(int fd, const struct pipe_screen_config *config)
7539f464c52Smaya{
7547ec681f3Smrg   /* Here are the i915 features we need for Iris (in chronological order) :
7557ec681f3Smrg    *    - I915_PARAM_HAS_EXEC_NO_RELOC     (3.10)
7567ec681f3Smrg    *    - I915_PARAM_HAS_EXEC_HANDLE_LUT   (3.10)
7577ec681f3Smrg    *    - I915_PARAM_HAS_EXEC_BATCH_FIRST  (4.13)
7587ec681f3Smrg    *    - I915_PARAM_HAS_EXEC_FENCE_ARRAY  (4.14)
7597ec681f3Smrg    *    - I915_PARAM_HAS_CONTEXT_ISOLATION (4.16)
7607ec681f3Smrg    *
7617ec681f3Smrg    * Checking the last feature availability will include all previous ones.
7627ec681f3Smrg    */
7637ec681f3Smrg   if (iris_getparam_integer(fd, I915_PARAM_HAS_CONTEXT_ISOLATION) <= 0) {
7647ec681f3Smrg      debug_error("Kernel is too old for Iris. Consider upgrading to kernel v4.16.\n");
7657ec681f3Smrg      return NULL;
7667ec681f3Smrg   }
7677ec681f3Smrg
7689f464c52Smaya   struct iris_screen *screen = rzalloc(NULL, struct iris_screen);
7699f464c52Smaya   if (!screen)
7709f464c52Smaya      return NULL;
7719f464c52Smaya
7727ec681f3Smrg   if (!intel_get_device_info_from_fd(fd, &screen->devinfo))
7739f464c52Smaya      return NULL;
7747ec681f3Smrg   screen->pci_id = screen->devinfo.chipset_id;
7757ec681f3Smrg
7767ec681f3Smrg   p_atomic_set(&screen->refcount, 1);
7779f464c52Smaya
7787ec681f3Smrg   if (screen->devinfo.ver < 8 || screen->devinfo.is_cherryview)
7799f464c52Smaya      return NULL;
7809f464c52Smaya
7817ec681f3Smrg   driParseConfigFiles(config->options, config->options_info, 0, "iris",
7827ec681f3Smrg                       NULL, NULL, NULL, 0, NULL, 0);
7839f464c52Smaya
7847ec681f3Smrg   bool bo_reuse = false;
7857ec681f3Smrg   int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse");
7867ec681f3Smrg   switch (bo_reuse_mode) {
7877ec681f3Smrg   case DRI_CONF_BO_REUSE_DISABLED:
7887ec681f3Smrg      break;
7897ec681f3Smrg   case DRI_CONF_BO_REUSE_ALL:
7907ec681f3Smrg      bo_reuse = true;
7917ec681f3Smrg      break;
7927ec681f3Smrg   }
7939f464c52Smaya
7947ec681f3Smrg   screen->bufmgr = iris_bufmgr_get_for_fd(&screen->devinfo, fd, bo_reuse);
7959f464c52Smaya   if (!screen->bufmgr)
7969f464c52Smaya      return NULL;
7979f464c52Smaya
7987ec681f3Smrg   screen->fd = iris_bufmgr_get_fd(screen->bufmgr);
7997ec681f3Smrg   screen->winsys_fd = fd;
8007ec681f3Smrg
8017ec681f3Smrg   screen->id = iris_bufmgr_create_screen_id(screen->bufmgr);
8027ec681f3Smrg
8039f464c52Smaya   screen->workaround_bo =
8047ec681f3Smrg      iris_bo_alloc(screen->bufmgr, "workaround", 4096, 1,
8057ec681f3Smrg                    IRIS_MEMZONE_OTHER, BO_ALLOC_NO_SUBALLOC);
8069f464c52Smaya   if (!screen->workaround_bo)
8079f464c52Smaya      return NULL;
8089f464c52Smaya
8097ec681f3Smrg   if (!iris_init_identifier_bo(screen))
8107ec681f3Smrg      return NULL;
8117ec681f3Smrg
8129f464c52Smaya   brw_process_intel_debug_variable();
8139f464c52Smaya
8149f464c52Smaya   screen->driconf.dual_color_blend_by_location =
8159f464c52Smaya      driQueryOptionb(config->options, "dual_color_blend_by_location");
8167ec681f3Smrg   screen->driconf.disable_throttling =
8177ec681f3Smrg      driQueryOptionb(config->options, "disable_throttling");
8187ec681f3Smrg   screen->driconf.always_flush_cache =
8197ec681f3Smrg      driQueryOptionb(config->options, "always_flush_cache");
8207ec681f3Smrg   screen->driconf.sync_compile =
8217ec681f3Smrg      driQueryOptionb(config->options, "sync_compile");
8229f464c52Smaya
8239f464c52Smaya   screen->precompile = env_var_as_boolean("shader_precompile", true);
8249f464c52Smaya
8259f464c52Smaya   isl_device_init(&screen->isl_dev, &screen->devinfo, false);
8269f464c52Smaya
8279f464c52Smaya   screen->compiler = brw_compiler_create(screen, &screen->devinfo);
8289f464c52Smaya   screen->compiler->shader_debug_log = iris_shader_debug_log;
8299f464c52Smaya   screen->compiler->shader_perf_log = iris_shader_perf_log;
8309f464c52Smaya   screen->compiler->supports_pull_constants = false;
8317ec681f3Smrg   screen->compiler->supports_shader_constants = true;
8327ec681f3Smrg   screen->compiler->compact_params = false;
8337ec681f3Smrg   screen->compiler->indirect_ubos_use_sampler = screen->devinfo.ver < 12;
8347ec681f3Smrg
8357ec681f3Smrg   screen->l3_config_3d = iris_get_default_l3_config(&screen->devinfo, false);
8367ec681f3Smrg   screen->l3_config_cs = iris_get_default_l3_config(&screen->devinfo, true);
8377ec681f3Smrg
8387ec681f3Smrg   iris_disk_cache_init(screen);
8399f464c52Smaya
8409f464c52Smaya   slab_create_parent(&screen->transfer_pool,
8419f464c52Smaya                      sizeof(struct iris_transfer), 64);
8429f464c52Smaya
8437ec681f3Smrg   iris_detect_kernel_features(screen);
8449f464c52Smaya
8459f464c52Smaya   struct pipe_screen *pscreen = &screen->base;
8469f464c52Smaya
8479f464c52Smaya   iris_init_screen_fence_functions(pscreen);
8489f464c52Smaya   iris_init_screen_resource_functions(pscreen);
8497ec681f3Smrg   iris_init_screen_measure(screen);
8509f464c52Smaya
8517ec681f3Smrg   pscreen->destroy = iris_screen_unref;
8529f464c52Smaya   pscreen->get_name = iris_get_name;
8539f464c52Smaya   pscreen->get_vendor = iris_get_vendor;
8549f464c52Smaya   pscreen->get_device_vendor = iris_get_device_vendor;
8559f464c52Smaya   pscreen->get_param = iris_get_param;
8569f464c52Smaya   pscreen->get_shader_param = iris_get_shader_param;
8579f464c52Smaya   pscreen->get_compute_param = iris_get_compute_param;
8589f464c52Smaya   pscreen->get_paramf = iris_get_paramf;
8599f464c52Smaya   pscreen->get_compiler_options = iris_get_compiler_options;
8607ec681f3Smrg   pscreen->get_device_uuid = iris_get_device_uuid;
8617ec681f3Smrg   pscreen->get_driver_uuid = iris_get_driver_uuid;
8627ec681f3Smrg   pscreen->get_disk_shader_cache = iris_get_disk_shader_cache;
8639f464c52Smaya   pscreen->is_format_supported = iris_is_format_supported;
8649f464c52Smaya   pscreen->context_create = iris_create_context;
8659f464c52Smaya   pscreen->flush_frontbuffer = iris_flush_frontbuffer;
8669f464c52Smaya   pscreen->get_timestamp = iris_get_timestamp;
8679f464c52Smaya   pscreen->query_memory_info = iris_query_memory_info;
8687ec681f3Smrg   pscreen->get_driver_query_group_info = iris_get_monitor_group_info;
8697ec681f3Smrg   pscreen->get_driver_query_info = iris_get_monitor_info;
8707ec681f3Smrg   iris_init_screen_program_functions(pscreen);
8717ec681f3Smrg
8727ec681f3Smrg   genX_call(&screen->devinfo, init_screen_state, screen);
8737ec681f3Smrg
8747ec681f3Smrg   glsl_type_singleton_init_or_ref();
8757ec681f3Smrg
8767ec681f3Smrg   /* FINISHME: Big core vs little core (for CPUs that have both kinds of
8777ec681f3Smrg    * cores) and, possibly, thread vs core should be considered here too.
8787ec681f3Smrg    */
8797ec681f3Smrg   unsigned compiler_threads = 1;
8807ec681f3Smrg   const struct util_cpu_caps_t *caps = util_get_cpu_caps();
8817ec681f3Smrg   unsigned hw_threads = caps->nr_cpus;
8827ec681f3Smrg
8837ec681f3Smrg   if (hw_threads >= 12) {
8847ec681f3Smrg      compiler_threads = hw_threads * 3 / 4;
8857ec681f3Smrg   } else if (hw_threads >= 6) {
8867ec681f3Smrg      compiler_threads = hw_threads - 2;
8877ec681f3Smrg   } else if (hw_threads >= 2) {
8887ec681f3Smrg      compiler_threads = hw_threads - 1;
8897ec681f3Smrg   }
8907ec681f3Smrg
8917ec681f3Smrg   if (!util_queue_init(&screen->shader_compiler_queue,
8927ec681f3Smrg                        "sh", 64, compiler_threads,
8937ec681f3Smrg                        UTIL_QUEUE_INIT_RESIZE_IF_FULL |
8947ec681f3Smrg                        UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY,
8957ec681f3Smrg                        NULL)) {
8967ec681f3Smrg      iris_screen_destroy(screen);
8977ec681f3Smrg      return NULL;
8987ec681f3Smrg   }
8999f464c52Smaya
9009f464c52Smaya   return pscreen;
9019f464c52Smaya}
902