1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2017 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
12bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci/**
24bf215546Sopenharmony_ci * @file iris_screen.c
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci * Screen related driver hooks and capability lists.
27bf215546Sopenharmony_ci *
28bf215546Sopenharmony_ci * A program may use multiple rendering contexts (iris_context), but
29bf215546Sopenharmony_ci * they all share a common screen (iris_screen).  Global driver state
30bf215546Sopenharmony_ci * can be stored in the screen; it may be accessed by multiple threads.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include <stdio.h>
34bf215546Sopenharmony_ci#include <errno.h>
35bf215546Sopenharmony_ci#include <sys/ioctl.h>
36bf215546Sopenharmony_ci#include "pipe/p_defines.h"
37bf215546Sopenharmony_ci#include "pipe/p_state.h"
38bf215546Sopenharmony_ci#include "pipe/p_context.h"
39bf215546Sopenharmony_ci#include "pipe/p_screen.h"
40bf215546Sopenharmony_ci#include "util/debug.h"
41bf215546Sopenharmony_ci#include "util/os_file.h"
42bf215546Sopenharmony_ci#include "util/u_cpu_detect.h"
43bf215546Sopenharmony_ci#include "util/u_inlines.h"
44bf215546Sopenharmony_ci#include "util/format/u_format.h"
45bf215546Sopenharmony_ci#include "util/u_transfer_helper.h"
46bf215546Sopenharmony_ci#include "util/u_upload_mgr.h"
47bf215546Sopenharmony_ci#include "util/ralloc.h"
48bf215546Sopenharmony_ci#include "util/xmlconfig.h"
49bf215546Sopenharmony_ci#include "drm-uapi/i915_drm.h"
50bf215546Sopenharmony_ci#include "iris_context.h"
51bf215546Sopenharmony_ci#include "iris_defines.h"
52bf215546Sopenharmony_ci#include "iris_fence.h"
53bf215546Sopenharmony_ci#include "iris_pipe.h"
54bf215546Sopenharmony_ci#include "iris_resource.h"
55bf215546Sopenharmony_ci#include "iris_screen.h"
56bf215546Sopenharmony_ci#include "compiler/glsl_types.h"
57bf215546Sopenharmony_ci#include "intel/compiler/brw_compiler.h"
58bf215546Sopenharmony_ci#include "intel/common/intel_gem.h"
59bf215546Sopenharmony_ci#include "intel/common/intel_l3_config.h"
60bf215546Sopenharmony_ci#include "intel/common/intel_uuid.h"
61bf215546Sopenharmony_ci#include "iris_monitor.h"
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci#define genX_call(devinfo, func, ...)             \
64bf215546Sopenharmony_ci   switch ((devinfo)->verx10) {                   \
65bf215546Sopenharmony_ci   case 125:                                      \
66bf215546Sopenharmony_ci      gfx125_##func(__VA_ARGS__);                 \
67bf215546Sopenharmony_ci      break;                                      \
68bf215546Sopenharmony_ci   case 120:                                      \
69bf215546Sopenharmony_ci      gfx12_##func(__VA_ARGS__);                  \
70bf215546Sopenharmony_ci      break;                                      \
71bf215546Sopenharmony_ci   case 110:                                      \
72bf215546Sopenharmony_ci      gfx11_##func(__VA_ARGS__);                  \
73bf215546Sopenharmony_ci      break;                                      \
74bf215546Sopenharmony_ci   case 90:                                       \
75bf215546Sopenharmony_ci      gfx9_##func(__VA_ARGS__);                   \
76bf215546Sopenharmony_ci      break;                                      \
77bf215546Sopenharmony_ci   case 80:                                       \
78bf215546Sopenharmony_ci      gfx8_##func(__VA_ARGS__);                   \
79bf215546Sopenharmony_ci      break;                                      \
80bf215546Sopenharmony_ci   default:                                       \
81bf215546Sopenharmony_ci      unreachable("Unknown hardware generation"); \
82bf215546Sopenharmony_ci   }
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic const char *
85bf215546Sopenharmony_ciiris_get_vendor(struct pipe_screen *pscreen)
86bf215546Sopenharmony_ci{
87bf215546Sopenharmony_ci   return "Intel";
88bf215546Sopenharmony_ci}
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_cistatic const char *
91bf215546Sopenharmony_ciiris_get_device_vendor(struct pipe_screen *pscreen)
92bf215546Sopenharmony_ci{
93bf215546Sopenharmony_ci   return "Intel";
94bf215546Sopenharmony_ci}
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_cistatic void
97bf215546Sopenharmony_ciiris_get_device_uuid(struct pipe_screen *pscreen, char *uuid)
98bf215546Sopenharmony_ci{
99bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)pscreen;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   intel_uuid_compute_device_id((uint8_t *)uuid, &screen->devinfo, PIPE_UUID_SIZE);
102bf215546Sopenharmony_ci}
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cistatic void
105bf215546Sopenharmony_ciiris_get_driver_uuid(struct pipe_screen *pscreen, char *uuid)
106bf215546Sopenharmony_ci{
107bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)pscreen;
108bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   intel_uuid_compute_driver_id((uint8_t *)uuid, devinfo, PIPE_UUID_SIZE);
111bf215546Sopenharmony_ci}
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_cistatic bool
114bf215546Sopenharmony_ciiris_enable_clover()
115bf215546Sopenharmony_ci{
116bf215546Sopenharmony_ci   static int enable = -1;
117bf215546Sopenharmony_ci   if (enable < 0)
118bf215546Sopenharmony_ci      enable = env_var_as_boolean("IRIS_ENABLE_CLOVER", false);
119bf215546Sopenharmony_ci   return enable;
120bf215546Sopenharmony_ci}
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_cistatic void
123bf215546Sopenharmony_ciiris_warn_clover()
124bf215546Sopenharmony_ci{
125bf215546Sopenharmony_ci   static bool warned = false;
126bf215546Sopenharmony_ci   if (warned)
127bf215546Sopenharmony_ci      return;
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   warned = true;
130bf215546Sopenharmony_ci   fprintf(stderr, "WARNING: OpenCL support via iris+clover is incomplete.\n"
131bf215546Sopenharmony_ci                   "For a complete and conformant OpenCL implementation, use\n"
132bf215546Sopenharmony_ci                   "https://github.com/intel/compute-runtime instead\n");
133bf215546Sopenharmony_ci}
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_cistatic const char *
136bf215546Sopenharmony_ciiris_get_name(struct pipe_screen *pscreen)
137bf215546Sopenharmony_ci{
138bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)pscreen;
139bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
140bf215546Sopenharmony_ci   static char buf[128];
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   snprintf(buf, sizeof(buf), "Mesa %s", devinfo->name);
143bf215546Sopenharmony_ci   return buf;
144bf215546Sopenharmony_ci}
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_cistatic int
147bf215546Sopenharmony_ciiris_get_video_memory(struct iris_screen *screen)
148bf215546Sopenharmony_ci{
149bf215546Sopenharmony_ci   uint64_t vram = iris_bufmgr_vram_size(screen->bufmgr);
150bf215546Sopenharmony_ci   uint64_t sram = iris_bufmgr_sram_size(screen->bufmgr);
151bf215546Sopenharmony_ci   if (vram) {
152bf215546Sopenharmony_ci      return vram / (1024 * 1024);
153bf215546Sopenharmony_ci   } else if (sram) {
154bf215546Sopenharmony_ci      return sram / (1024 * 1024);
155bf215546Sopenharmony_ci   } else {
156bf215546Sopenharmony_ci      /* This is the old code path, it get the GGTT size from the kernel
157bf215546Sopenharmony_ci       * (which should always be 4Gb on Gfx8+).
158bf215546Sopenharmony_ci       *
159bf215546Sopenharmony_ci       * We should probably never end up here. This is just a fallback to get
160bf215546Sopenharmony_ci       * some kind of value in case os_get_available_system_memory fails.
161bf215546Sopenharmony_ci       */
162bf215546Sopenharmony_ci      const struct intel_device_info *devinfo = &screen->devinfo;
163bf215546Sopenharmony_ci      /* Once a batch uses more than 75% of the maximum mappable size, we
164bf215546Sopenharmony_ci       * assume that there's some fragmentation, and we start doing extra
165bf215546Sopenharmony_ci       * flushing, etc.  That's the big cliff apps will care about.
166bf215546Sopenharmony_ci       */
167bf215546Sopenharmony_ci      const unsigned gpu_mappable_megabytes =
168bf215546Sopenharmony_ci         (devinfo->aperture_bytes * 3 / 4) / (1024 * 1024);
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci      const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
171bf215546Sopenharmony_ci      const long system_page_size = sysconf(_SC_PAGE_SIZE);
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci      if (system_memory_pages <= 0 || system_page_size <= 0)
174bf215546Sopenharmony_ci         return -1;
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci      const uint64_t system_memory_bytes =
177bf215546Sopenharmony_ci         (uint64_t) system_memory_pages * (uint64_t) system_page_size;
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci      const unsigned system_memory_megabytes =
180bf215546Sopenharmony_ci         (unsigned) (system_memory_bytes / (1024 * 1024));
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci      return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
183bf215546Sopenharmony_ci   }
184bf215546Sopenharmony_ci}
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_cistatic int
187bf215546Sopenharmony_ciiris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
188bf215546Sopenharmony_ci{
189bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)pscreen;
190bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   switch (param) {
193bf215546Sopenharmony_ci   case PIPE_CAP_NPOT_TEXTURES:
194bf215546Sopenharmony_ci   case PIPE_CAP_ANISOTROPIC_FILTER:
195bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SPRITE:
196bf215546Sopenharmony_ci   case PIPE_CAP_OCCLUSION_QUERY:
197bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIME_ELAPSED:
198bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SWIZZLE:
199bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
200bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
201bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
202bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
203bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART:
204bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
205bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_ENABLE:
206bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_FUNC:
207bf215546Sopenharmony_ci   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
208bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
209bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
210bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE:
211bf215546Sopenharmony_ci   case PIPE_CAP_VS_INSTANCEID:
212bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
213bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
214bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP:
215bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
216bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER:
217bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BARRIER:
218bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
219bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
220bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE:
221bf215546Sopenharmony_ci   case PIPE_CAP_START_INSTANCE:
222bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIMESTAMP:
223bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MULTISAMPLE:
224bf215546Sopenharmony_ci   case PIPE_CAP_CUBE_MAP_ARRAY:
225bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
226bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
227bf215546Sopenharmony_ci   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
228bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_LOD:
229bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLE_SHADING:
230bf215546Sopenharmony_ci   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
231bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_INDIRECT:
232bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT:
233bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
234bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
235bf215546Sopenharmony_ci   case PIPE_CAP_VS_LAYER_VIEWPORT:
236bf215546Sopenharmony_ci   case PIPE_CAP_TES_LAYER_VIEWPORT:
237bf215546Sopenharmony_ci   case PIPE_CAP_FS_FINE_DERIVATIVE:
238bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_PACK_HALF_FLOAT:
239bf215546Sopenharmony_ci   case PIPE_CAP_ACCELERATED:
240bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
241bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_HALFZ:
242bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEXCOORD:
243bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
244bf215546Sopenharmony_ci   case PIPE_CAP_DOUBLES:
245bf215546Sopenharmony_ci   case PIPE_CAP_INT64:
246bf215546Sopenharmony_ci   case PIPE_CAP_INT64_DIVMOD:
247bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_VIEW_TARGET:
248bf215546Sopenharmony_ci   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
249bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
250bf215546Sopenharmony_ci   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
251bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
252bf215546Sopenharmony_ci   case PIPE_CAP_CULL_DISTANCE:
253bf215546Sopenharmony_ci   case PIPE_CAP_PACKED_UNIFORMS:
254bf215546Sopenharmony_ci   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
255bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
256bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
257bf215546Sopenharmony_ci   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
258bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_SO_OVERFLOW:
259bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_BUFFER_OBJECT:
260bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEX_TXF_LZ:
261bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_SAMPLES:
262bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_CLOCK:
263bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BALLOT:
264bf215546Sopenharmony_ci   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
265bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_TEXTURE:
266bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_SCISSORED:
267bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_GROUP_VOTE:
268bf215546Sopenharmony_ci   case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
269bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_GATHER_SM5:
270bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
271bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
272bf215546Sopenharmony_ci   case PIPE_CAP_LOAD_CONSTBUF:
273bf215546Sopenharmony_ci   case PIPE_CAP_NIR_COMPACT_ARRAYS:
274bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_PARAMETERS:
275bf215546Sopenharmony_ci   case PIPE_CAP_FS_POSITION_IS_SYSVAL:
276bf215546Sopenharmony_ci   case PIPE_CAP_FS_FACE_IS_INTEGER_SYSVAL:
277bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
278bf215546Sopenharmony_ci   case PIPE_CAP_INVALIDATE_BUFFER:
279bf215546Sopenharmony_ci   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
280bf215546Sopenharmony_ci   case PIPE_CAP_CS_DERIVED_SYSTEM_VALUES_SUPPORTED:
281bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SHADOW_LOD:
282bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_SAMPLES_IDENTICAL:
283bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV:
284bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS:
285bf215546Sopenharmony_ci   case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION:
286bf215546Sopenharmony_ci   case PIPE_CAP_NATIVE_FENCE_FD:
287bf215546Sopenharmony_ci   case PIPE_CAP_MEMOBJ:
288bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
289bf215546Sopenharmony_ci   case PIPE_CAP_FENCE_SIGNAL:
290bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_STORE_FORMATTED:
291bf215546Sopenharmony_ci   case PIPE_CAP_LEGACY_MATH_RULES:
292bf215546Sopenharmony_ci      return true;
293bf215546Sopenharmony_ci   case PIPE_CAP_UMA:
294bf215546Sopenharmony_ci      return iris_bufmgr_vram_size(screen->bufmgr) == 0;
295bf215546Sopenharmony_ci   case PIPE_CAP_PREFER_BACK_BUFFER_REUSE:
296bf215546Sopenharmony_ci      return false;
297bf215546Sopenharmony_ci   case PIPE_CAP_FBFETCH:
298bf215546Sopenharmony_ci      return BRW_MAX_DRAW_BUFFERS;
299bf215546Sopenharmony_ci   case PIPE_CAP_FBFETCH_COHERENT:
300bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_INNER_COVERAGE:
301bf215546Sopenharmony_ci   case PIPE_CAP_POST_DEPTH_COVERAGE:
302bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_STENCIL_EXPORT:
303bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
304bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_INTERLOCK:
305bf215546Sopenharmony_ci   case PIPE_CAP_ATOMIC_FLOAT_MINMAX:
306bf215546Sopenharmony_ci      return devinfo->ver >= 9;
307bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_BOUNDS_TEST:
308bf215546Sopenharmony_ci      return devinfo->ver >= 12;
309bf215546Sopenharmony_ci   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
310bf215546Sopenharmony_ci      return 1;
311bf215546Sopenharmony_ci   case PIPE_CAP_MAX_RENDER_TARGETS:
312bf215546Sopenharmony_ci      return BRW_MAX_DRAW_BUFFERS;
313bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
314bf215546Sopenharmony_ci      return 16384;
315bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
316bf215546Sopenharmony_ci      return IRIS_MAX_MIPLEVELS; /* 16384x16384 */
317bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
318bf215546Sopenharmony_ci      return 12; /* 2048x2048 */
319bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
320bf215546Sopenharmony_ci      return 4;
321bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
322bf215546Sopenharmony_ci      return 2048;
323bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
324bf215546Sopenharmony_ci      return BRW_MAX_SOL_BINDINGS / IRIS_MAX_SOL_BUFFERS;
325bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
326bf215546Sopenharmony_ci      return BRW_MAX_SOL_BINDINGS;
327bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL:
328bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
329bf215546Sopenharmony_ci      return 460;
330bf215546Sopenharmony_ci   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
331bf215546Sopenharmony_ci      /* 3DSTATE_CONSTANT_XS requires the start of UBOs to be 32B aligned */
332bf215546Sopenharmony_ci      return 32;
333bf215546Sopenharmony_ci   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
334bf215546Sopenharmony_ci      return IRIS_MAP_BUFFER_ALIGNMENT;
335bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
336bf215546Sopenharmony_ci      return 4;
337bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
338bf215546Sopenharmony_ci      return 1 << 27;
339bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
340bf215546Sopenharmony_ci      return 16; // XXX: u_screen says 256 is the minimum value...
341bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_TRANSFER_MODES:
342bf215546Sopenharmony_ci      return PIPE_TEXTURE_TRANSFER_BLIT;
343bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
344bf215546Sopenharmony_ci      return IRIS_MAX_TEXTURE_BUFFER_SIZE;
345bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VIEWPORTS:
346bf215546Sopenharmony_ci      return 16;
347bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
348bf215546Sopenharmony_ci      return 256;
349bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
350bf215546Sopenharmony_ci      return 1024;
351bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GS_INVOCATIONS:
352bf215546Sopenharmony_ci      return 32;
353bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
354bf215546Sopenharmony_ci      return 4;
355bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
356bf215546Sopenharmony_ci      return -32;
357bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
358bf215546Sopenharmony_ci      return 31;
359bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_STREAMS:
360bf215546Sopenharmony_ci      return 4;
361bf215546Sopenharmony_ci   case PIPE_CAP_VENDOR_ID:
362bf215546Sopenharmony_ci      return 0x8086;
363bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_ID:
364bf215546Sopenharmony_ci      return screen->pci_id;
365bf215546Sopenharmony_ci   case PIPE_CAP_VIDEO_MEMORY:
366bf215546Sopenharmony_ci      return iris_get_video_memory(screen);
367bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
368bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VARYINGS:
369bf215546Sopenharmony_ci      return 32;
370bf215546Sopenharmony_ci   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
371bf215546Sopenharmony_ci      /* AMD_pinned_memory assumes the flexibility of using client memory
372bf215546Sopenharmony_ci       * for any buffer (incl. vertex buffers) which rules out the prospect
373bf215546Sopenharmony_ci       * of using snooped buffers, as using snooped buffers without
374bf215546Sopenharmony_ci       * cogniscience is likely to be detrimental to performance and require
375bf215546Sopenharmony_ci       * extensive checking in the driver for correctness, e.g. to prevent
376bf215546Sopenharmony_ci       * illegal snoop <-> snoop transfers.
377bf215546Sopenharmony_ci       */
378bf215546Sopenharmony_ci      return devinfo->has_llc;
379bf215546Sopenharmony_ci   case PIPE_CAP_THROTTLE:
380bf215546Sopenharmony_ci      return screen->driconf.disable_throttling ? 0 : 1;
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
383bf215546Sopenharmony_ci      return PIPE_CONTEXT_PRIORITY_LOW |
384bf215546Sopenharmony_ci             PIPE_CONTEXT_PRIORITY_MEDIUM |
385bf215546Sopenharmony_ci             PIPE_CONTEXT_PRIORITY_HIGH;
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   case PIPE_CAP_FRONTEND_NOOP:
388bf215546Sopenharmony_ci      return true;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci   // XXX: don't hardcode 00:00:02.0 PCI here
391bf215546Sopenharmony_ci   case PIPE_CAP_PCI_GROUP:
392bf215546Sopenharmony_ci      return 0;
393bf215546Sopenharmony_ci   case PIPE_CAP_PCI_BUS:
394bf215546Sopenharmony_ci      return 0;
395bf215546Sopenharmony_ci   case PIPE_CAP_PCI_DEVICE:
396bf215546Sopenharmony_ci      return 2;
397bf215546Sopenharmony_ci   case PIPE_CAP_PCI_FUNCTION:
398bf215546Sopenharmony_ci      return 0;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   case PIPE_CAP_OPENCL_INTEGER_FUNCTIONS:
401bf215546Sopenharmony_ci   case PIPE_CAP_INTEGER_MULTIPLY_32X16:
402bf215546Sopenharmony_ci      return true;
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci   case PIPE_CAP_ALLOW_DYNAMIC_VAO_FASTPATH:
405bf215546Sopenharmony_ci      /* Internal details of VF cache make this optimization harmful on GFX
406bf215546Sopenharmony_ci       * version 8 and 9, because generated VERTEX_BUFFER_STATEs are cached
407bf215546Sopenharmony_ci       * separately.
408bf215546Sopenharmony_ci       */
409bf215546Sopenharmony_ci      return devinfo->ver >= 11;
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_ci   default:
412bf215546Sopenharmony_ci      return u_pipe_screen_get_param_defaults(pscreen, param);
413bf215546Sopenharmony_ci   }
414bf215546Sopenharmony_ci   return 0;
415bf215546Sopenharmony_ci}
416bf215546Sopenharmony_ci
417bf215546Sopenharmony_cistatic float
418bf215546Sopenharmony_ciiris_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
419bf215546Sopenharmony_ci{
420bf215546Sopenharmony_ci   switch (param) {
421bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH:
422bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH_AA:
423bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE:
424bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE_AA:
425bf215546Sopenharmony_ci      return 1;
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci   case PIPE_CAPF_POINT_SIZE_GRANULARITY:
428bf215546Sopenharmony_ci   case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
429bf215546Sopenharmony_ci      return 0.1;
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH:
432bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
433bf215546Sopenharmony_ci      return 7.375f;
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE:
436bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE_AA:
437bf215546Sopenharmony_ci      return 255.0f;
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
440bf215546Sopenharmony_ci      return 16.0f;
441bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
442bf215546Sopenharmony_ci      return 15.0f;
443bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
444bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
445bf215546Sopenharmony_ci   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
446bf215546Sopenharmony_ci      return 0.0f;
447bf215546Sopenharmony_ci   default:
448bf215546Sopenharmony_ci      unreachable("unknown param");
449bf215546Sopenharmony_ci   }
450bf215546Sopenharmony_ci}
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_cistatic int
453bf215546Sopenharmony_ciiris_get_shader_param(struct pipe_screen *pscreen,
454bf215546Sopenharmony_ci                      enum pipe_shader_type p_stage,
455bf215546Sopenharmony_ci                      enum pipe_shader_cap param)
456bf215546Sopenharmony_ci{
457bf215546Sopenharmony_ci   gl_shader_stage stage = stage_from_pipe(p_stage);
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci   /* this is probably not totally correct.. but it's a start: */
460bf215546Sopenharmony_ci   switch (param) {
461bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
462bf215546Sopenharmony_ci      return stage == MESA_SHADER_FRAGMENT ? 1024 : 16384;
463bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
464bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
465bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
466bf215546Sopenharmony_ci      return stage == MESA_SHADER_FRAGMENT ? 1024 : 0;
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
469bf215546Sopenharmony_ci      return UINT_MAX;
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INPUTS:
472bf215546Sopenharmony_ci      return stage == MESA_SHADER_VERTEX ? 16 : 32;
473bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_OUTPUTS:
474bf215546Sopenharmony_ci      return 32;
475bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
476bf215546Sopenharmony_ci      return 16 * 1024 * sizeof(float);
477bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
478bf215546Sopenharmony_ci      return 16;
479bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEMPS:
480bf215546Sopenharmony_ci      return 256; /* GL_MAX_PROGRAM_TEMPORARIES_ARB */
481bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_CONT_SUPPORTED:
482bf215546Sopenharmony_ci      return 0;
483bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
484bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
485bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
486bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
487bf215546Sopenharmony_ci      /* Lie about these to avoid st/mesa's GLSL IR lowering of indirects,
488bf215546Sopenharmony_ci       * which we don't want.  Our compiler backend will check brw_compiler's
489bf215546Sopenharmony_ci       * options and call nir_lower_indirect_derefs appropriately anyway.
490bf215546Sopenharmony_ci       */
491bf215546Sopenharmony_ci      return true;
492bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUBROUTINES:
493bf215546Sopenharmony_ci      return 0;
494bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INTEGERS:
495bf215546Sopenharmony_ci      return 1;
496bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT64_ATOMICS:
497bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16:
498bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_DERIVATIVES:
499bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
500bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT16:
501bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
502bf215546Sopenharmony_ci      return 0;
503bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
504bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
505bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
506bf215546Sopenharmony_ci      return IRIS_MAX_TEXTURE_SAMPLERS;
507bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
508bf215546Sopenharmony_ci      return IRIS_MAX_ABOS + IRIS_MAX_SSBOS;
509bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
510bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
511bf215546Sopenharmony_ci      return 0;
512bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_PREFERRED_IR:
513bf215546Sopenharmony_ci      return PIPE_SHADER_IR_NIR;
514bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUPPORTED_IRS: {
515bf215546Sopenharmony_ci      int irs = 1 << PIPE_SHADER_IR_NIR;
516bf215546Sopenharmony_ci      if (iris_enable_clover())
517bf215546Sopenharmony_ci         irs |= 1 << PIPE_SHADER_IR_NIR_SERIALIZED;
518bf215546Sopenharmony_ci      return irs;
519bf215546Sopenharmony_ci   }
520bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DROUND_SUPPORTED:
521bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
522bf215546Sopenharmony_ci      return 1;
523bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
524bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
525bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
526bf215546Sopenharmony_ci      return 0;
527bf215546Sopenharmony_ci   default:
528bf215546Sopenharmony_ci      unreachable("unknown shader param");
529bf215546Sopenharmony_ci   }
530bf215546Sopenharmony_ci}
531bf215546Sopenharmony_ci
532bf215546Sopenharmony_cistatic int
533bf215546Sopenharmony_ciiris_get_compute_param(struct pipe_screen *pscreen,
534bf215546Sopenharmony_ci                       enum pipe_shader_ir ir_type,
535bf215546Sopenharmony_ci                       enum pipe_compute_cap param,
536bf215546Sopenharmony_ci                       void *ret)
537bf215546Sopenharmony_ci{
538bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)pscreen;
539bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
540bf215546Sopenharmony_ci
541bf215546Sopenharmony_ci   const uint32_t max_invocations =
542bf215546Sopenharmony_ci      MIN2(1024, 32 * devinfo->max_cs_workgroup_threads);
543bf215546Sopenharmony_ci
544bf215546Sopenharmony_ci#define RET(x) do {                  \
545bf215546Sopenharmony_ci   if (ret)                          \
546bf215546Sopenharmony_ci      memcpy(ret, x, sizeof(x));     \
547bf215546Sopenharmony_ci   return sizeof(x);                 \
548bf215546Sopenharmony_ci} while (0)
549bf215546Sopenharmony_ci
550bf215546Sopenharmony_ci   switch (param) {
551bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
552bf215546Sopenharmony_ci      /* This gets queried on clover device init and is never queried by the
553bf215546Sopenharmony_ci       * OpenGL state tracker.
554bf215546Sopenharmony_ci       */
555bf215546Sopenharmony_ci      iris_warn_clover();
556bf215546Sopenharmony_ci      RET((uint32_t []){ 64 });
557bf215546Sopenharmony_ci
558bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IR_TARGET:
559bf215546Sopenharmony_ci      if (ret)
560bf215546Sopenharmony_ci         strcpy(ret, "gen");
561bf215546Sopenharmony_ci      return 4;
562bf215546Sopenharmony_ci
563bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
564bf215546Sopenharmony_ci      RET((uint64_t []) { 3 });
565bf215546Sopenharmony_ci
566bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
567bf215546Sopenharmony_ci      RET(((uint64_t []) { 65535, 65535, 65535 }));
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
570bf215546Sopenharmony_ci      /* MaxComputeWorkGroupSize[0..2] */
571bf215546Sopenharmony_ci      RET(((uint64_t []) {max_invocations, max_invocations, max_invocations}));
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
574bf215546Sopenharmony_ci      /* MaxComputeWorkGroupInvocations */
575bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
576bf215546Sopenharmony_ci      /* MaxComputeVariableGroupInvocations */
577bf215546Sopenharmony_ci      RET((uint64_t []) { max_invocations });
578bf215546Sopenharmony_ci
579bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
580bf215546Sopenharmony_ci      /* MaxComputeSharedMemorySize */
581bf215546Sopenharmony_ci      RET((uint64_t []) { 64 * 1024 });
582bf215546Sopenharmony_ci
583bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
584bf215546Sopenharmony_ci      RET((uint32_t []) { 1 });
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
587bf215546Sopenharmony_ci      RET((uint32_t []) { BRW_SUBGROUP_SIZE });
588bf215546Sopenharmony_ci
589bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
590bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
591bf215546Sopenharmony_ci      RET((uint64_t []) { 1 << 30 }); /* TODO */
592bf215546Sopenharmony_ci
593bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
594bf215546Sopenharmony_ci      RET((uint32_t []) { 400 }); /* TODO */
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS: {
597bf215546Sopenharmony_ci      RET((uint32_t []) { intel_device_info_subslice_total(devinfo) });
598bf215546Sopenharmony_ci   }
599bf215546Sopenharmony_ci
600bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
601bf215546Sopenharmony_ci      /* MaxComputeSharedMemorySize */
602bf215546Sopenharmony_ci      RET((uint64_t []) { 64 * 1024 });
603bf215546Sopenharmony_ci
604bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
605bf215546Sopenharmony_ci      /* We could probably allow more; this is the OpenCL minimum */
606bf215546Sopenharmony_ci      RET((uint64_t []) { 1024 });
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_ci   default:
609bf215546Sopenharmony_ci      unreachable("unknown compute param");
610bf215546Sopenharmony_ci   }
611bf215546Sopenharmony_ci}
612bf215546Sopenharmony_ci
613bf215546Sopenharmony_cistatic uint64_t
614bf215546Sopenharmony_ciiris_get_timestamp(struct pipe_screen *pscreen)
615bf215546Sopenharmony_ci{
616bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *) pscreen;
617bf215546Sopenharmony_ci   const unsigned TIMESTAMP = 0x2358;
618bf215546Sopenharmony_ci   uint64_t result;
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci   iris_reg_read(screen->bufmgr, TIMESTAMP | 1, &result);
621bf215546Sopenharmony_ci
622bf215546Sopenharmony_ci   result = intel_device_info_timebase_scale(&screen->devinfo, result);
623bf215546Sopenharmony_ci   result &= (1ull << TIMESTAMP_BITS) - 1;
624bf215546Sopenharmony_ci
625bf215546Sopenharmony_ci   return result;
626bf215546Sopenharmony_ci}
627bf215546Sopenharmony_ci
628bf215546Sopenharmony_civoid
629bf215546Sopenharmony_ciiris_screen_destroy(struct iris_screen *screen)
630bf215546Sopenharmony_ci{
631bf215546Sopenharmony_ci   iris_destroy_screen_measure(screen);
632bf215546Sopenharmony_ci   util_queue_destroy(&screen->shader_compiler_queue);
633bf215546Sopenharmony_ci   glsl_type_singleton_decref();
634bf215546Sopenharmony_ci   iris_bo_unreference(screen->workaround_bo);
635bf215546Sopenharmony_ci   u_transfer_helper_destroy(screen->base.transfer_helper);
636bf215546Sopenharmony_ci   iris_bufmgr_unref(screen->bufmgr);
637bf215546Sopenharmony_ci   disk_cache_destroy(screen->disk_cache);
638bf215546Sopenharmony_ci   close(screen->winsys_fd);
639bf215546Sopenharmony_ci   ralloc_free(screen);
640bf215546Sopenharmony_ci}
641bf215546Sopenharmony_ci
642bf215546Sopenharmony_cistatic void
643bf215546Sopenharmony_ciiris_screen_unref(struct pipe_screen *pscreen)
644bf215546Sopenharmony_ci{
645bf215546Sopenharmony_ci   iris_pscreen_unref(pscreen);
646bf215546Sopenharmony_ci}
647bf215546Sopenharmony_ci
648bf215546Sopenharmony_cistatic void
649bf215546Sopenharmony_ciiris_query_memory_info(struct pipe_screen *pscreen,
650bf215546Sopenharmony_ci                       struct pipe_memory_info *info)
651bf215546Sopenharmony_ci{
652bf215546Sopenharmony_ci}
653bf215546Sopenharmony_ci
654bf215546Sopenharmony_cistatic const void *
655bf215546Sopenharmony_ciiris_get_compiler_options(struct pipe_screen *pscreen,
656bf215546Sopenharmony_ci                          enum pipe_shader_ir ir,
657bf215546Sopenharmony_ci                          enum pipe_shader_type pstage)
658bf215546Sopenharmony_ci{
659bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *) pscreen;
660bf215546Sopenharmony_ci   gl_shader_stage stage = stage_from_pipe(pstage);
661bf215546Sopenharmony_ci   assert(ir == PIPE_SHADER_IR_NIR);
662bf215546Sopenharmony_ci
663bf215546Sopenharmony_ci   return screen->compiler->nir_options[stage];
664bf215546Sopenharmony_ci}
665bf215546Sopenharmony_ci
666bf215546Sopenharmony_cistatic struct disk_cache *
667bf215546Sopenharmony_ciiris_get_disk_shader_cache(struct pipe_screen *pscreen)
668bf215546Sopenharmony_ci{
669bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *) pscreen;
670bf215546Sopenharmony_ci   return screen->disk_cache;
671bf215546Sopenharmony_ci}
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_cistatic int
674bf215546Sopenharmony_ciiris_getparam(int fd, int param, int *value)
675bf215546Sopenharmony_ci{
676bf215546Sopenharmony_ci   struct drm_i915_getparam gp = { .param = param, .value = value };
677bf215546Sopenharmony_ci
678bf215546Sopenharmony_ci   if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) == -1)
679bf215546Sopenharmony_ci      return -errno;
680bf215546Sopenharmony_ci
681bf215546Sopenharmony_ci   return 0;
682bf215546Sopenharmony_ci}
683bf215546Sopenharmony_ci
684bf215546Sopenharmony_cistatic int
685bf215546Sopenharmony_ciiris_getparam_integer(int fd, int param)
686bf215546Sopenharmony_ci{
687bf215546Sopenharmony_ci   int value = -1;
688bf215546Sopenharmony_ci
689bf215546Sopenharmony_ci   if (iris_getparam(fd, param, &value) == 0)
690bf215546Sopenharmony_ci      return value;
691bf215546Sopenharmony_ci
692bf215546Sopenharmony_ci   return -1;
693bf215546Sopenharmony_ci}
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_cistatic const struct intel_l3_config *
696bf215546Sopenharmony_ciiris_get_default_l3_config(const struct intel_device_info *devinfo,
697bf215546Sopenharmony_ci                           bool compute)
698bf215546Sopenharmony_ci{
699bf215546Sopenharmony_ci   bool wants_dc_cache = true;
700bf215546Sopenharmony_ci   bool has_slm = compute;
701bf215546Sopenharmony_ci   const struct intel_l3_weights w =
702bf215546Sopenharmony_ci      intel_get_default_l3_weights(devinfo, wants_dc_cache, has_slm);
703bf215546Sopenharmony_ci   return intel_get_l3_config(devinfo, w);
704bf215546Sopenharmony_ci}
705bf215546Sopenharmony_ci
706bf215546Sopenharmony_cistatic void
707bf215546Sopenharmony_ciiris_shader_debug_log(void *data, unsigned *id, const char *fmt, ...)
708bf215546Sopenharmony_ci{
709bf215546Sopenharmony_ci   struct util_debug_callback *dbg = data;
710bf215546Sopenharmony_ci   va_list args;
711bf215546Sopenharmony_ci
712bf215546Sopenharmony_ci   if (!dbg->debug_message)
713bf215546Sopenharmony_ci      return;
714bf215546Sopenharmony_ci
715bf215546Sopenharmony_ci   va_start(args, fmt);
716bf215546Sopenharmony_ci   dbg->debug_message(dbg->data, id, UTIL_DEBUG_TYPE_SHADER_INFO, fmt, args);
717bf215546Sopenharmony_ci   va_end(args);
718bf215546Sopenharmony_ci}
719bf215546Sopenharmony_ci
720bf215546Sopenharmony_cistatic void
721bf215546Sopenharmony_ciiris_shader_perf_log(void *data, unsigned *id, const char *fmt, ...)
722bf215546Sopenharmony_ci{
723bf215546Sopenharmony_ci   struct util_debug_callback *dbg = data;
724bf215546Sopenharmony_ci   va_list args;
725bf215546Sopenharmony_ci   va_start(args, fmt);
726bf215546Sopenharmony_ci
727bf215546Sopenharmony_ci   if (INTEL_DEBUG(DEBUG_PERF)) {
728bf215546Sopenharmony_ci      va_list args_copy;
729bf215546Sopenharmony_ci      va_copy(args_copy, args);
730bf215546Sopenharmony_ci      vfprintf(stderr, fmt, args_copy);
731bf215546Sopenharmony_ci      va_end(args_copy);
732bf215546Sopenharmony_ci   }
733bf215546Sopenharmony_ci
734bf215546Sopenharmony_ci   if (dbg->debug_message) {
735bf215546Sopenharmony_ci      dbg->debug_message(dbg->data, id, UTIL_DEBUG_TYPE_PERF_INFO, fmt, args);
736bf215546Sopenharmony_ci   }
737bf215546Sopenharmony_ci
738bf215546Sopenharmony_ci   va_end(args);
739bf215546Sopenharmony_ci}
740bf215546Sopenharmony_ci
741bf215546Sopenharmony_cistatic void
742bf215546Sopenharmony_ciiris_detect_kernel_features(struct iris_screen *screen)
743bf215546Sopenharmony_ci{
744bf215546Sopenharmony_ci   /* Kernel 5.2+ */
745bf215546Sopenharmony_ci   if (intel_gem_supports_syncobj_wait(screen->fd))
746bf215546Sopenharmony_ci      screen->kernel_features |= KERNEL_HAS_WAIT_FOR_SUBMIT;
747bf215546Sopenharmony_ci}
748bf215546Sopenharmony_ci
749bf215546Sopenharmony_cistatic bool
750bf215546Sopenharmony_ciiris_init_identifier_bo(struct iris_screen *screen)
751bf215546Sopenharmony_ci{
752bf215546Sopenharmony_ci   void *bo_map;
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci   bo_map = iris_bo_map(NULL, screen->workaround_bo, MAP_READ | MAP_WRITE);
755bf215546Sopenharmony_ci   if (!bo_map)
756bf215546Sopenharmony_ci      return false;
757bf215546Sopenharmony_ci
758bf215546Sopenharmony_ci   assert(iris_bo_is_real(screen->workaround_bo));
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_ci   screen->workaround_bo->real.kflags |=
761bf215546Sopenharmony_ci      EXEC_OBJECT_CAPTURE | EXEC_OBJECT_ASYNC;
762bf215546Sopenharmony_ci   screen->workaround_address = (struct iris_address) {
763bf215546Sopenharmony_ci      .bo = screen->workaround_bo,
764bf215546Sopenharmony_ci      .offset = ALIGN(
765bf215546Sopenharmony_ci         intel_debug_write_identifiers(bo_map, 4096, "Iris") + 8, 8),
766bf215546Sopenharmony_ci   };
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci   iris_bo_unmap(screen->workaround_bo);
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci   return true;
771bf215546Sopenharmony_ci}
772bf215546Sopenharmony_ci
773bf215546Sopenharmony_cistruct pipe_screen *
774bf215546Sopenharmony_ciiris_screen_create(int fd, const struct pipe_screen_config *config)
775bf215546Sopenharmony_ci{
776bf215546Sopenharmony_ci   struct iris_screen *screen = rzalloc(NULL, struct iris_screen);
777bf215546Sopenharmony_ci   if (!screen)
778bf215546Sopenharmony_ci      return NULL;
779bf215546Sopenharmony_ci
780bf215546Sopenharmony_ci   if (!intel_get_device_info_from_fd(fd, &screen->devinfo))
781bf215546Sopenharmony_ci      return NULL;
782bf215546Sopenharmony_ci   screen->pci_id = screen->devinfo.pci_device_id;
783bf215546Sopenharmony_ci
784bf215546Sopenharmony_ci   p_atomic_set(&screen->refcount, 1);
785bf215546Sopenharmony_ci
786bf215546Sopenharmony_ci   if (screen->devinfo.ver < 8 || screen->devinfo.platform == INTEL_PLATFORM_CHV)
787bf215546Sopenharmony_ci      return NULL;
788bf215546Sopenharmony_ci
789bf215546Sopenharmony_ci   /* Here are the i915 features we need for Iris (in chronological order) :
790bf215546Sopenharmony_ci    *    - I915_PARAM_HAS_EXEC_NO_RELOC     (3.10)
791bf215546Sopenharmony_ci    *    - I915_PARAM_HAS_EXEC_HANDLE_LUT   (3.10)
792bf215546Sopenharmony_ci    *    - I915_PARAM_HAS_EXEC_BATCH_FIRST  (4.13)
793bf215546Sopenharmony_ci    *    - I915_PARAM_HAS_EXEC_FENCE_ARRAY  (4.14)
794bf215546Sopenharmony_ci    *    - I915_PARAM_HAS_CONTEXT_ISOLATION (4.16)
795bf215546Sopenharmony_ci    *
796bf215546Sopenharmony_ci    * Checking the last feature availability will include all previous ones.
797bf215546Sopenharmony_ci    */
798bf215546Sopenharmony_ci   if (iris_getparam_integer(fd, I915_PARAM_HAS_CONTEXT_ISOLATION) <= 0) {
799bf215546Sopenharmony_ci      debug_error("Kernel is too old for Iris. Consider upgrading to kernel v4.16.\n");
800bf215546Sopenharmony_ci      return NULL;
801bf215546Sopenharmony_ci   }
802bf215546Sopenharmony_ci
803bf215546Sopenharmony_ci   driParseConfigFiles(config->options, config->options_info, 0, "iris",
804bf215546Sopenharmony_ci                       NULL, NULL, NULL, 0, NULL, 0);
805bf215546Sopenharmony_ci
806bf215546Sopenharmony_ci   bool bo_reuse = false;
807bf215546Sopenharmony_ci   int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse");
808bf215546Sopenharmony_ci   switch (bo_reuse_mode) {
809bf215546Sopenharmony_ci   case DRI_CONF_BO_REUSE_DISABLED:
810bf215546Sopenharmony_ci      break;
811bf215546Sopenharmony_ci   case DRI_CONF_BO_REUSE_ALL:
812bf215546Sopenharmony_ci      bo_reuse = true;
813bf215546Sopenharmony_ci      break;
814bf215546Sopenharmony_ci   }
815bf215546Sopenharmony_ci
816bf215546Sopenharmony_ci   brw_process_intel_debug_variable();
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_ci   screen->bufmgr = iris_bufmgr_get_for_fd(&screen->devinfo, fd, bo_reuse);
819bf215546Sopenharmony_ci   if (!screen->bufmgr)
820bf215546Sopenharmony_ci      return NULL;
821bf215546Sopenharmony_ci
822bf215546Sopenharmony_ci   screen->fd = iris_bufmgr_get_fd(screen->bufmgr);
823bf215546Sopenharmony_ci   screen->winsys_fd = os_dupfd_cloexec(fd);
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci   screen->id = iris_bufmgr_create_screen_id(screen->bufmgr);
826bf215546Sopenharmony_ci
827bf215546Sopenharmony_ci   screen->workaround_bo =
828bf215546Sopenharmony_ci      iris_bo_alloc(screen->bufmgr, "workaround", 4096, 4096,
829bf215546Sopenharmony_ci                    IRIS_MEMZONE_OTHER, BO_ALLOC_NO_SUBALLOC);
830bf215546Sopenharmony_ci   if (!screen->workaround_bo)
831bf215546Sopenharmony_ci      return NULL;
832bf215546Sopenharmony_ci
833bf215546Sopenharmony_ci   if (!iris_init_identifier_bo(screen))
834bf215546Sopenharmony_ci      return NULL;
835bf215546Sopenharmony_ci
836bf215546Sopenharmony_ci   screen->driconf.dual_color_blend_by_location =
837bf215546Sopenharmony_ci      driQueryOptionb(config->options, "dual_color_blend_by_location");
838bf215546Sopenharmony_ci   screen->driconf.disable_throttling =
839bf215546Sopenharmony_ci      driQueryOptionb(config->options, "disable_throttling");
840bf215546Sopenharmony_ci   screen->driconf.always_flush_cache =
841bf215546Sopenharmony_ci      driQueryOptionb(config->options, "always_flush_cache");
842bf215546Sopenharmony_ci   screen->driconf.sync_compile =
843bf215546Sopenharmony_ci      driQueryOptionb(config->options, "sync_compile");
844bf215546Sopenharmony_ci   screen->driconf.limit_trig_input_range =
845bf215546Sopenharmony_ci      driQueryOptionb(config->options, "limit_trig_input_range");
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci   screen->precompile = env_var_as_boolean("shader_precompile", true);
848bf215546Sopenharmony_ci
849bf215546Sopenharmony_ci   isl_device_init(&screen->isl_dev, &screen->devinfo);
850bf215546Sopenharmony_ci
851bf215546Sopenharmony_ci   screen->compiler = brw_compiler_create(screen, &screen->devinfo);
852bf215546Sopenharmony_ci   screen->compiler->shader_debug_log = iris_shader_debug_log;
853bf215546Sopenharmony_ci   screen->compiler->shader_perf_log = iris_shader_perf_log;
854bf215546Sopenharmony_ci   screen->compiler->supports_shader_constants = true;
855bf215546Sopenharmony_ci   screen->compiler->indirect_ubos_use_sampler = screen->devinfo.ver < 12;
856bf215546Sopenharmony_ci
857bf215546Sopenharmony_ci   screen->l3_config_3d = iris_get_default_l3_config(&screen->devinfo, false);
858bf215546Sopenharmony_ci   screen->l3_config_cs = iris_get_default_l3_config(&screen->devinfo, true);
859bf215546Sopenharmony_ci
860bf215546Sopenharmony_ci   iris_disk_cache_init(screen);
861bf215546Sopenharmony_ci
862bf215546Sopenharmony_ci   slab_create_parent(&screen->transfer_pool,
863bf215546Sopenharmony_ci                      sizeof(struct iris_transfer), 64);
864bf215546Sopenharmony_ci
865bf215546Sopenharmony_ci   iris_detect_kernel_features(screen);
866bf215546Sopenharmony_ci
867bf215546Sopenharmony_ci   struct pipe_screen *pscreen = &screen->base;
868bf215546Sopenharmony_ci
869bf215546Sopenharmony_ci   iris_init_screen_fence_functions(pscreen);
870bf215546Sopenharmony_ci   iris_init_screen_resource_functions(pscreen);
871bf215546Sopenharmony_ci   iris_init_screen_measure(screen);
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_ci   pscreen->destroy = iris_screen_unref;
874bf215546Sopenharmony_ci   pscreen->get_name = iris_get_name;
875bf215546Sopenharmony_ci   pscreen->get_vendor = iris_get_vendor;
876bf215546Sopenharmony_ci   pscreen->get_device_vendor = iris_get_device_vendor;
877bf215546Sopenharmony_ci   pscreen->get_param = iris_get_param;
878bf215546Sopenharmony_ci   pscreen->get_shader_param = iris_get_shader_param;
879bf215546Sopenharmony_ci   pscreen->get_compute_param = iris_get_compute_param;
880bf215546Sopenharmony_ci   pscreen->get_paramf = iris_get_paramf;
881bf215546Sopenharmony_ci   pscreen->get_compiler_options = iris_get_compiler_options;
882bf215546Sopenharmony_ci   pscreen->get_device_uuid = iris_get_device_uuid;
883bf215546Sopenharmony_ci   pscreen->get_driver_uuid = iris_get_driver_uuid;
884bf215546Sopenharmony_ci   pscreen->get_disk_shader_cache = iris_get_disk_shader_cache;
885bf215546Sopenharmony_ci   pscreen->is_format_supported = iris_is_format_supported;
886bf215546Sopenharmony_ci   pscreen->context_create = iris_create_context;
887bf215546Sopenharmony_ci   pscreen->get_timestamp = iris_get_timestamp;
888bf215546Sopenharmony_ci   pscreen->query_memory_info = iris_query_memory_info;
889bf215546Sopenharmony_ci   pscreen->get_driver_query_group_info = iris_get_monitor_group_info;
890bf215546Sopenharmony_ci   pscreen->get_driver_query_info = iris_get_monitor_info;
891bf215546Sopenharmony_ci   iris_init_screen_program_functions(pscreen);
892bf215546Sopenharmony_ci
893bf215546Sopenharmony_ci   genX_call(&screen->devinfo, init_screen_state, screen);
894bf215546Sopenharmony_ci
895bf215546Sopenharmony_ci   glsl_type_singleton_init_or_ref();
896bf215546Sopenharmony_ci
897bf215546Sopenharmony_ci   intel_driver_ds_init();
898bf215546Sopenharmony_ci
899bf215546Sopenharmony_ci   /* FINISHME: Big core vs little core (for CPUs that have both kinds of
900bf215546Sopenharmony_ci    * cores) and, possibly, thread vs core should be considered here too.
901bf215546Sopenharmony_ci    */
902bf215546Sopenharmony_ci   unsigned compiler_threads = 1;
903bf215546Sopenharmony_ci   const struct util_cpu_caps_t *caps = util_get_cpu_caps();
904bf215546Sopenharmony_ci   unsigned hw_threads = caps->nr_cpus;
905bf215546Sopenharmony_ci
906bf215546Sopenharmony_ci   if (hw_threads >= 12) {
907bf215546Sopenharmony_ci      compiler_threads = hw_threads * 3 / 4;
908bf215546Sopenharmony_ci   } else if (hw_threads >= 6) {
909bf215546Sopenharmony_ci      compiler_threads = hw_threads - 2;
910bf215546Sopenharmony_ci   } else if (hw_threads >= 2) {
911bf215546Sopenharmony_ci      compiler_threads = hw_threads - 1;
912bf215546Sopenharmony_ci   }
913bf215546Sopenharmony_ci
914bf215546Sopenharmony_ci   if (!util_queue_init(&screen->shader_compiler_queue,
915bf215546Sopenharmony_ci                        "sh", 64, compiler_threads,
916bf215546Sopenharmony_ci                        UTIL_QUEUE_INIT_RESIZE_IF_FULL |
917bf215546Sopenharmony_ci                        UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY,
918bf215546Sopenharmony_ci                        NULL)) {
919bf215546Sopenharmony_ci      iris_screen_destroy(screen);
920bf215546Sopenharmony_ci      return NULL;
921bf215546Sopenharmony_ci   }
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci   return pscreen;
924bf215546Sopenharmony_ci}
925