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 crocus_screen.c
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci * Screen related driver hooks and capability lists.
27bf215546Sopenharmony_ci *
28bf215546Sopenharmony_ci * A program may use multiple rendering contexts (crocus_context), but
29bf215546Sopenharmony_ci * they all share a common screen (crocus_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/u_inlines.h"
42bf215546Sopenharmony_ci#include "util/format/u_format.h"
43bf215546Sopenharmony_ci#include "util/u_transfer_helper.h"
44bf215546Sopenharmony_ci#include "util/u_upload_mgr.h"
45bf215546Sopenharmony_ci#include "util/ralloc.h"
46bf215546Sopenharmony_ci#include "util/xmlconfig.h"
47bf215546Sopenharmony_ci#include "drm-uapi/i915_drm.h"
48bf215546Sopenharmony_ci#include "crocus_context.h"
49bf215546Sopenharmony_ci#include "crocus_defines.h"
50bf215546Sopenharmony_ci#include "crocus_fence.h"
51bf215546Sopenharmony_ci#include "crocus_pipe.h"
52bf215546Sopenharmony_ci#include "crocus_resource.h"
53bf215546Sopenharmony_ci#include "crocus_screen.h"
54bf215546Sopenharmony_ci#include "intel/compiler/brw_compiler.h"
55bf215546Sopenharmony_ci#include "intel/common/intel_gem.h"
56bf215546Sopenharmony_ci#include "intel/common/intel_l3_config.h"
57bf215546Sopenharmony_ci#include "intel/common/intel_uuid.h"
58bf215546Sopenharmony_ci#include "crocus_monitor.h"
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci#define genX_call(devinfo, func, ...)                   \
61bf215546Sopenharmony_ci   switch ((devinfo)->verx10) {                         \
62bf215546Sopenharmony_ci   case 80:                                             \
63bf215546Sopenharmony_ci      gfx8_##func(__VA_ARGS__);                         \
64bf215546Sopenharmony_ci      break;                                            \
65bf215546Sopenharmony_ci   case 75:                                             \
66bf215546Sopenharmony_ci      gfx75_##func(__VA_ARGS__);                        \
67bf215546Sopenharmony_ci      break;                                            \
68bf215546Sopenharmony_ci   case 70:                                             \
69bf215546Sopenharmony_ci      gfx7_##func(__VA_ARGS__);                         \
70bf215546Sopenharmony_ci      break;                                            \
71bf215546Sopenharmony_ci   case 60:                                             \
72bf215546Sopenharmony_ci      gfx6_##func(__VA_ARGS__);                         \
73bf215546Sopenharmony_ci      break;                                            \
74bf215546Sopenharmony_ci   case 50:                                             \
75bf215546Sopenharmony_ci      gfx5_##func(__VA_ARGS__);                         \
76bf215546Sopenharmony_ci      break;                                            \
77bf215546Sopenharmony_ci   case 45:                                             \
78bf215546Sopenharmony_ci      gfx45_##func(__VA_ARGS__);                        \
79bf215546Sopenharmony_ci      break;                                            \
80bf215546Sopenharmony_ci   case 40:                                             \
81bf215546Sopenharmony_ci      gfx4_##func(__VA_ARGS__);                         \
82bf215546Sopenharmony_ci      break;                                            \
83bf215546Sopenharmony_ci   default:                                             \
84bf215546Sopenharmony_ci      unreachable("Unknown hardware generation");       \
85bf215546Sopenharmony_ci   }
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cistatic const char *
88bf215546Sopenharmony_cicrocus_get_vendor(struct pipe_screen *pscreen)
89bf215546Sopenharmony_ci{
90bf215546Sopenharmony_ci   return "Intel";
91bf215546Sopenharmony_ci}
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_cistatic const char *
94bf215546Sopenharmony_cicrocus_get_device_vendor(struct pipe_screen *pscreen)
95bf215546Sopenharmony_ci{
96bf215546Sopenharmony_ci   return "Intel";
97bf215546Sopenharmony_ci}
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_cistatic void
100bf215546Sopenharmony_cicrocus_get_device_uuid(struct pipe_screen *pscreen, char *uuid)
101bf215546Sopenharmony_ci{
102bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   intel_uuid_compute_device_id((uint8_t *)uuid, &screen->devinfo, PIPE_UUID_SIZE);
105bf215546Sopenharmony_ci}
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cistatic void
108bf215546Sopenharmony_cicrocus_get_driver_uuid(struct pipe_screen *pscreen, char *uuid)
109bf215546Sopenharmony_ci{
110bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
111bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   intel_uuid_compute_driver_id((uint8_t *)uuid, devinfo, PIPE_UUID_SIZE);
114bf215546Sopenharmony_ci}
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_cistatic const char *
117bf215546Sopenharmony_cicrocus_get_name(struct pipe_screen *pscreen)
118bf215546Sopenharmony_ci{
119bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
120bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
121bf215546Sopenharmony_ci   static char buf[128];
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   snprintf(buf, sizeof(buf), "Mesa %s", devinfo->name);
124bf215546Sopenharmony_ci   return buf;
125bf215546Sopenharmony_ci}
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_cistatic uint64_t
128bf215546Sopenharmony_ciget_aperture_size(int fd)
129bf215546Sopenharmony_ci{
130bf215546Sopenharmony_ci   struct drm_i915_gem_get_aperture aperture = {};
131bf215546Sopenharmony_ci   intel_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
132bf215546Sopenharmony_ci   return aperture.aper_size;
133bf215546Sopenharmony_ci}
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_cistatic int
136bf215546Sopenharmony_cicrocus_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
137bf215546Sopenharmony_ci{
138bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
139bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci   switch (param) {
142bf215546Sopenharmony_ci   case PIPE_CAP_NPOT_TEXTURES:
143bf215546Sopenharmony_ci   case PIPE_CAP_ANISOTROPIC_FILTER:
144bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SPRITE:
145bf215546Sopenharmony_ci   case PIPE_CAP_OCCLUSION_QUERY:
146bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SWIZZLE:
147bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
148bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
149bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
150bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
151bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART:
152bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
153bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_ENABLE:
154bf215546Sopenharmony_ci   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
155bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
156bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
157bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE:
158bf215546Sopenharmony_ci   case PIPE_CAP_VS_INSTANCEID:
159bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
160bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
161bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP:
162bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
163bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER:
164bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BARRIER:
165bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
166bf215546Sopenharmony_ci   case PIPE_CAP_START_INSTANCE:
167bf215546Sopenharmony_ci   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
168bf215546Sopenharmony_ci   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
169bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
170bf215546Sopenharmony_ci   case PIPE_CAP_VS_LAYER_VIEWPORT:
171bf215546Sopenharmony_ci   case PIPE_CAP_TES_LAYER_VIEWPORT:
172bf215546Sopenharmony_ci   case PIPE_CAP_ACCELERATED:
173bf215546Sopenharmony_ci   case PIPE_CAP_UMA:
174bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_HALFZ:
175bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEXCOORD:
176bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
177bf215546Sopenharmony_ci   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
178bf215546Sopenharmony_ci   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
179bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
180bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
181bf215546Sopenharmony_ci   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
182bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEX_TXF_LZ:
183bf215546Sopenharmony_ci   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
184bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_TEXTURE:
185bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_GROUP_VOTE:
186bf215546Sopenharmony_ci   case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
187bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_GATHER_SM5:
188bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
189bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
190bf215546Sopenharmony_ci   case PIPE_CAP_NIR_COMPACT_ARRAYS:
191bf215546Sopenharmony_ci   case PIPE_CAP_FS_POSITION_IS_SYSVAL:
192bf215546Sopenharmony_ci   case PIPE_CAP_FS_FACE_IS_INTEGER_SYSVAL:
193bf215546Sopenharmony_ci   case PIPE_CAP_INVALIDATE_BUFFER:
194bf215546Sopenharmony_ci   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
195bf215546Sopenharmony_ci   case PIPE_CAP_CS_DERIVED_SYSTEM_VALUES_SUPPORTED:
196bf215546Sopenharmony_ci   case PIPE_CAP_FENCE_SIGNAL:
197bf215546Sopenharmony_ci   case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION:
198bf215546Sopenharmony_ci   case PIPE_CAP_GL_CLAMP:
199bf215546Sopenharmony_ci   case PIPE_CAP_LEGACY_MATH_RULES:
200bf215546Sopenharmony_ci      return true;
201bf215546Sopenharmony_ci   case PIPE_CAP_INT64:
202bf215546Sopenharmony_ci   case PIPE_CAP_INT64_DIVMOD:
203bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BALLOT:
204bf215546Sopenharmony_ci   case PIPE_CAP_PACKED_UNIFORMS:
205bf215546Sopenharmony_ci      return devinfo->ver == 8;
206bf215546Sopenharmony_ci   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
207bf215546Sopenharmony_ci      return devinfo->ver <= 5;
208bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_LOD:
209bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIME_ELAPSED:
210bf215546Sopenharmony_ci      return devinfo->ver >= 5;
211bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_INDIRECT:
212bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT:
213bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
214bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
215bf215546Sopenharmony_ci   case PIPE_CAP_FS_FINE_DERIVATIVE:
216bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
217bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_CLOCK:
218bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_SAMPLES:
219bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE:
220bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_VIEW_TARGET:
221bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_SAMPLES_IDENTICAL:
222bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_PACK_HALF_FLOAT:
223bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV:
224bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS:
225bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
226bf215546Sopenharmony_ci   case PIPE_CAP_DOUBLES:
227bf215546Sopenharmony_ci   case PIPE_CAP_MEMOBJ:
228bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_STORE_FORMATTED:
229bf215546Sopenharmony_ci      return devinfo->ver >= 7;
230bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_BUFFER_OBJECT:
231bf215546Sopenharmony_ci   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
232bf215546Sopenharmony_ci      return devinfo->verx10 >= 75;
233bf215546Sopenharmony_ci   case PIPE_CAP_CULL_DISTANCE:
234bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
235bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
236bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLE_SHADING:
237bf215546Sopenharmony_ci   case PIPE_CAP_CUBE_MAP_ARRAY:
238bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_SO_OVERFLOW:
239bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MULTISAMPLE:
240bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
241bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIMESTAMP:
242bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
243bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_FUNC:
244bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SHADOW_LOD:
245bf215546Sopenharmony_ci   case PIPE_CAP_LOAD_CONSTBUF:
246bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_PARAMETERS:
247bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_SCISSORED:
248bf215546Sopenharmony_ci      return devinfo->ver >= 6;
249bf215546Sopenharmony_ci   case PIPE_CAP_FBFETCH:
250bf215546Sopenharmony_ci      return devinfo->verx10 >= 45 ? BRW_MAX_DRAW_BUFFERS : 0;
251bf215546Sopenharmony_ci   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
252bf215546Sopenharmony_ci      /* in theory CL (965gm) can do this */
253bf215546Sopenharmony_ci      return devinfo->verx10 >= 45 ? 1 : 0;
254bf215546Sopenharmony_ci   case PIPE_CAP_MAX_RENDER_TARGETS:
255bf215546Sopenharmony_ci      return BRW_MAX_DRAW_BUFFERS;
256bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
257bf215546Sopenharmony_ci      if (devinfo->ver >= 7)
258bf215546Sopenharmony_ci         return 16384;
259bf215546Sopenharmony_ci      else
260bf215546Sopenharmony_ci         return 8192;
261bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
262bf215546Sopenharmony_ci      if (devinfo->ver >= 7)
263bf215546Sopenharmony_ci         return CROCUS_MAX_MIPLEVELS; /* 16384x16384 */
264bf215546Sopenharmony_ci      else
265bf215546Sopenharmony_ci         return CROCUS_MAX_MIPLEVELS - 1; /* 8192x8192 */
266bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
267bf215546Sopenharmony_ci      return 12; /* 2048x2048 */
268bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
269bf215546Sopenharmony_ci      return (devinfo->ver >= 6) ? 4 : 0;
270bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
271bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? 2048 : 512;
272bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
273bf215546Sopenharmony_ci      return BRW_MAX_SOL_BINDINGS / CROCUS_MAX_SOL_BUFFERS;
274bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
275bf215546Sopenharmony_ci      return BRW_MAX_SOL_BINDINGS;
276bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
277bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL: {
278bf215546Sopenharmony_ci      if (devinfo->verx10 >= 75)
279bf215546Sopenharmony_ci         return 460;
280bf215546Sopenharmony_ci      else if (devinfo->ver >= 7)
281bf215546Sopenharmony_ci         return 420;
282bf215546Sopenharmony_ci      else if (devinfo->ver >= 6)
283bf215546Sopenharmony_ci         return 330;
284bf215546Sopenharmony_ci      return 140;
285bf215546Sopenharmony_ci   }
286bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_PLANES:
287bf215546Sopenharmony_ci      if (devinfo->verx10 < 45)
288bf215546Sopenharmony_ci         return 6;
289bf215546Sopenharmony_ci      else
290bf215546Sopenharmony_ci         return 1; // defaults to MAX (8)
291bf215546Sopenharmony_ci   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
292bf215546Sopenharmony_ci      /* 3DSTATE_CONSTANT_XS requires the start of UBOs to be 32B aligned */
293bf215546Sopenharmony_ci      return 32;
294bf215546Sopenharmony_ci   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
295bf215546Sopenharmony_ci      return CROCUS_MAP_BUFFER_ALIGNMENT;
296bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
297bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? 4 : 0;
298bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
299bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? (1 << 27) : 0;
300bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
301bf215546Sopenharmony_ci      return 16; // XXX: u_screen says 256 is the minimum value...
302bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_TRANSFER_MODES:
303bf215546Sopenharmony_ci      return PIPE_TEXTURE_TRANSFER_BLIT;
304bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
305bf215546Sopenharmony_ci      return CROCUS_MAX_TEXTURE_BUFFER_SIZE;
306bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VIEWPORTS:
307bf215546Sopenharmony_ci      return devinfo->ver >= 6 ? 16 : 1;
308bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
309bf215546Sopenharmony_ci      return devinfo->ver >= 6 ? 256 : 0;
310bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
311bf215546Sopenharmony_ci      return devinfo->ver >= 6 ? 1024 : 0;
312bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GS_INVOCATIONS:
313bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? 32 : 1;
314bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
315bf215546Sopenharmony_ci      if (devinfo->ver >= 7)
316bf215546Sopenharmony_ci         return 4;
317bf215546Sopenharmony_ci      else if (devinfo->ver == 6)
318bf215546Sopenharmony_ci         return 1;
319bf215546Sopenharmony_ci      else
320bf215546Sopenharmony_ci         return 0;
321bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
322bf215546Sopenharmony_ci      if (devinfo->ver >= 7)
323bf215546Sopenharmony_ci         return -32;
324bf215546Sopenharmony_ci      else if (devinfo->ver == 6)
325bf215546Sopenharmony_ci         return -8;
326bf215546Sopenharmony_ci      else
327bf215546Sopenharmony_ci         return 0;
328bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
329bf215546Sopenharmony_ci      if (devinfo->ver >= 7)
330bf215546Sopenharmony_ci         return 31;
331bf215546Sopenharmony_ci      else if (devinfo->ver == 6)
332bf215546Sopenharmony_ci         return 7;
333bf215546Sopenharmony_ci      else
334bf215546Sopenharmony_ci         return 0;
335bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_STREAMS:
336bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? 4 : 1;
337bf215546Sopenharmony_ci   case PIPE_CAP_VENDOR_ID:
338bf215546Sopenharmony_ci      return 0x8086;
339bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_ID:
340bf215546Sopenharmony_ci      return screen->pci_id;
341bf215546Sopenharmony_ci   case PIPE_CAP_VIDEO_MEMORY: {
342bf215546Sopenharmony_ci      /* Once a batch uses more than 75% of the maximum mappable size, we
343bf215546Sopenharmony_ci       * assume that there's some fragmentation, and we start doing extra
344bf215546Sopenharmony_ci       * flushing, etc.  That's the big cliff apps will care about.
345bf215546Sopenharmony_ci       */
346bf215546Sopenharmony_ci      const unsigned gpu_mappable_megabytes =
347bf215546Sopenharmony_ci         (screen->aperture_threshold) / (1024 * 1024);
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci      const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
350bf215546Sopenharmony_ci      const long system_page_size = sysconf(_SC_PAGE_SIZE);
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci      if (system_memory_pages <= 0 || system_page_size <= 0)
353bf215546Sopenharmony_ci         return -1;
354bf215546Sopenharmony_ci
355bf215546Sopenharmony_ci      const uint64_t system_memory_bytes =
356bf215546Sopenharmony_ci         (uint64_t) system_memory_pages * (uint64_t) system_page_size;
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci      const unsigned system_memory_megabytes =
359bf215546Sopenharmony_ci         (unsigned) (system_memory_bytes / (1024 * 1024));
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci      return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
362bf215546Sopenharmony_ci   }
363bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
364bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VARYINGS:
365bf215546Sopenharmony_ci      return (screen->devinfo.ver >= 6) ? 32 : 16;
366bf215546Sopenharmony_ci   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
367bf215546Sopenharmony_ci      /* AMD_pinned_memory assumes the flexibility of using client memory
368bf215546Sopenharmony_ci       * for any buffer (incl. vertex buffers) which rules out the prospect
369bf215546Sopenharmony_ci       * of using snooped buffers, as using snooped buffers without
370bf215546Sopenharmony_ci       * cogniscience is likely to be detrimental to performance and require
371bf215546Sopenharmony_ci       * extensive checking in the driver for correctness, e.g. to prevent
372bf215546Sopenharmony_ci       * illegal snoop <-> snoop transfers.
373bf215546Sopenharmony_ci       */
374bf215546Sopenharmony_ci      return devinfo->has_llc;
375bf215546Sopenharmony_ci   case PIPE_CAP_THROTTLE:
376bf215546Sopenharmony_ci      return screen->driconf.disable_throttling ? 0 : 1;
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_ci   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
379bf215546Sopenharmony_ci      return PIPE_CONTEXT_PRIORITY_LOW |
380bf215546Sopenharmony_ci             PIPE_CONTEXT_PRIORITY_MEDIUM |
381bf215546Sopenharmony_ci             PIPE_CONTEXT_PRIORITY_HIGH;
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_ci   case PIPE_CAP_FRONTEND_NOOP:
384bf215546Sopenharmony_ci      return true;
385bf215546Sopenharmony_ci      // XXX: don't hardcode 00:00:02.0 PCI here
386bf215546Sopenharmony_ci   case PIPE_CAP_PCI_GROUP:
387bf215546Sopenharmony_ci      return 0;
388bf215546Sopenharmony_ci   case PIPE_CAP_PCI_BUS:
389bf215546Sopenharmony_ci      return 0;
390bf215546Sopenharmony_ci   case PIPE_CAP_PCI_DEVICE:
391bf215546Sopenharmony_ci      return 2;
392bf215546Sopenharmony_ci   case PIPE_CAP_PCI_FUNCTION:
393bf215546Sopenharmony_ci      return 0;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci   case PIPE_CAP_HARDWARE_GL_SELECT:
396bf215546Sopenharmony_ci      return 0;
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci   default:
399bf215546Sopenharmony_ci      return u_pipe_screen_get_param_defaults(pscreen, param);
400bf215546Sopenharmony_ci   }
401bf215546Sopenharmony_ci   return 0;
402bf215546Sopenharmony_ci}
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_cistatic float
405bf215546Sopenharmony_cicrocus_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
406bf215546Sopenharmony_ci{
407bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
408bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_ci   switch (param) {
411bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH:
412bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH_AA:
413bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE:
414bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE_AA:
415bf215546Sopenharmony_ci      return 1;
416bf215546Sopenharmony_ci
417bf215546Sopenharmony_ci   case PIPE_CAPF_POINT_SIZE_GRANULARITY:
418bf215546Sopenharmony_ci   case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
419bf215546Sopenharmony_ci      return 0.1;
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH:
422bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
423bf215546Sopenharmony_ci      if (devinfo->ver >= 6)
424bf215546Sopenharmony_ci         return 7.375f;
425bf215546Sopenharmony_ci      else
426bf215546Sopenharmony_ci         return 7.0f;
427bf215546Sopenharmony_ci
428bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE:
429bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE_AA:
430bf215546Sopenharmony_ci      return 255.0f;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
433bf215546Sopenharmony_ci      return 16.0f;
434bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
435bf215546Sopenharmony_ci      return 15.0f;
436bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
437bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
438bf215546Sopenharmony_ci   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
439bf215546Sopenharmony_ci      return 0.0f;
440bf215546Sopenharmony_ci   default:
441bf215546Sopenharmony_ci      unreachable("unknown param");
442bf215546Sopenharmony_ci   }
443bf215546Sopenharmony_ci}
444bf215546Sopenharmony_ci
445bf215546Sopenharmony_cistatic int
446bf215546Sopenharmony_cicrocus_get_shader_param(struct pipe_screen *pscreen,
447bf215546Sopenharmony_ci                        enum pipe_shader_type p_stage,
448bf215546Sopenharmony_ci                        enum pipe_shader_cap param)
449bf215546Sopenharmony_ci{
450bf215546Sopenharmony_ci   gl_shader_stage stage = stage_from_pipe(p_stage);
451bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
452bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_ci   if (devinfo->ver < 6 &&
455bf215546Sopenharmony_ci       p_stage != PIPE_SHADER_VERTEX &&
456bf215546Sopenharmony_ci       p_stage != PIPE_SHADER_FRAGMENT)
457bf215546Sopenharmony_ci      return 0;
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci   if (devinfo->ver == 6 &&
460bf215546Sopenharmony_ci       p_stage != PIPE_SHADER_VERTEX &&
461bf215546Sopenharmony_ci       p_stage != PIPE_SHADER_FRAGMENT &&
462bf215546Sopenharmony_ci       p_stage != PIPE_SHADER_GEOMETRY)
463bf215546Sopenharmony_ci      return 0;
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   /* this is probably not totally correct.. but it's a start: */
466bf215546Sopenharmony_ci   switch (param) {
467bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
468bf215546Sopenharmony_ci      return stage == MESA_SHADER_FRAGMENT ? 1024 : 16384;
469bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
470bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
471bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
472bf215546Sopenharmony_ci      return stage == MESA_SHADER_FRAGMENT ? 1024 : 0;
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
475bf215546Sopenharmony_ci      return UINT_MAX;
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INPUTS:
478bf215546Sopenharmony_ci      if (stage == MESA_SHADER_VERTEX ||
479bf215546Sopenharmony_ci          stage == MESA_SHADER_GEOMETRY)
480bf215546Sopenharmony_ci         return 16; /* Gen7 vec4 geom backend */
481bf215546Sopenharmony_ci      return 32;
482bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_OUTPUTS:
483bf215546Sopenharmony_ci      return 32;
484bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
485bf215546Sopenharmony_ci      return 16 * 1024 * sizeof(float);
486bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
487bf215546Sopenharmony_ci      return devinfo->ver >= 6 ? 16 : 1;
488bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEMPS:
489bf215546Sopenharmony_ci      return 256; /* GL_MAX_PROGRAM_TEMPORARIES_ARB */
490bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_CONT_SUPPORTED:
491bf215546Sopenharmony_ci      return 0;
492bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
493bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
494bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
495bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
496bf215546Sopenharmony_ci      /* Lie about these to avoid st/mesa's GLSL IR lowering of indirects,
497bf215546Sopenharmony_ci       * which we don't want.  Our compiler backend will check brw_compiler's
498bf215546Sopenharmony_ci       * options and call nir_lower_indirect_derefs appropriately anyway.
499bf215546Sopenharmony_ci       */
500bf215546Sopenharmony_ci      return true;
501bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUBROUTINES:
502bf215546Sopenharmony_ci      return 0;
503bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INTEGERS:
504bf215546Sopenharmony_ci      return 1;
505bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT64_ATOMICS:
506bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16:
507bf215546Sopenharmony_ci      return 0;
508bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
509bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
510bf215546Sopenharmony_ci      return (devinfo->verx10 >= 75) ? CROCUS_MAX_TEXTURE_SAMPLERS : 16;
511bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
512bf215546Sopenharmony_ci      if (devinfo->ver >= 7 &&
513bf215546Sopenharmony_ci          (p_stage == PIPE_SHADER_FRAGMENT ||
514bf215546Sopenharmony_ci           p_stage == PIPE_SHADER_COMPUTE))
515bf215546Sopenharmony_ci         return CROCUS_MAX_TEXTURE_SAMPLERS;
516bf215546Sopenharmony_ci      return 0;
517bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
518bf215546Sopenharmony_ci      return devinfo->ver >= 7 ? (CROCUS_MAX_ABOS + CROCUS_MAX_SSBOS) : 0;
519bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
520bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
521bf215546Sopenharmony_ci      return 0;
522bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_PREFERRED_IR:
523bf215546Sopenharmony_ci      return PIPE_SHADER_IR_NIR;
524bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUPPORTED_IRS:
525bf215546Sopenharmony_ci      return 1 << PIPE_SHADER_IR_NIR;
526bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DROUND_SUPPORTED:
527bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
528bf215546Sopenharmony_ci      return 1;
529bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
530bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
531bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
532bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_DERIVATIVES:
533bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT16:
534bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
535bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
536bf215546Sopenharmony_ci      return 0;
537bf215546Sopenharmony_ci   default:
538bf215546Sopenharmony_ci      unreachable("unknown shader param");
539bf215546Sopenharmony_ci   }
540bf215546Sopenharmony_ci}
541bf215546Sopenharmony_ci
542bf215546Sopenharmony_cistatic int
543bf215546Sopenharmony_cicrocus_get_compute_param(struct pipe_screen *pscreen,
544bf215546Sopenharmony_ci                         enum pipe_shader_ir ir_type,
545bf215546Sopenharmony_ci                         enum pipe_compute_cap param,
546bf215546Sopenharmony_ci                         void *ret)
547bf215546Sopenharmony_ci{
548bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *)pscreen;
549bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = &screen->devinfo;
550bf215546Sopenharmony_ci
551bf215546Sopenharmony_ci   const uint32_t max_invocations = 32 * devinfo->max_cs_workgroup_threads;
552bf215546Sopenharmony_ci
553bf215546Sopenharmony_ci   if (devinfo->ver < 7)
554bf215546Sopenharmony_ci      return 0;
555bf215546Sopenharmony_ci#define RET(x) do {                  \
556bf215546Sopenharmony_ci   if (ret)                          \
557bf215546Sopenharmony_ci      memcpy(ret, x, sizeof(x));     \
558bf215546Sopenharmony_ci   return sizeof(x);                 \
559bf215546Sopenharmony_ci} while (0)
560bf215546Sopenharmony_ci
561bf215546Sopenharmony_ci   switch (param) {
562bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
563bf215546Sopenharmony_ci      RET((uint32_t []){ 32 });
564bf215546Sopenharmony_ci
565bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IR_TARGET:
566bf215546Sopenharmony_ci      if (ret)
567bf215546Sopenharmony_ci         strcpy(ret, "gen");
568bf215546Sopenharmony_ci      return 4;
569bf215546Sopenharmony_ci
570bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
571bf215546Sopenharmony_ci      RET((uint64_t []) { 3 });
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
574bf215546Sopenharmony_ci      RET(((uint64_t []) { 65535, 65535, 65535 }));
575bf215546Sopenharmony_ci
576bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
577bf215546Sopenharmony_ci      /* MaxComputeWorkGroupSize[0..2] */
578bf215546Sopenharmony_ci      RET(((uint64_t []) {max_invocations, max_invocations, max_invocations}));
579bf215546Sopenharmony_ci
580bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
581bf215546Sopenharmony_ci      /* MaxComputeWorkGroupInvocations */
582bf215546Sopenharmony_ci      RET((uint64_t []) { max_invocations });
583bf215546Sopenharmony_ci
584bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
585bf215546Sopenharmony_ci      /* MaxComputeSharedMemorySize */
586bf215546Sopenharmony_ci      RET((uint64_t []) { 64 * 1024 });
587bf215546Sopenharmony_ci
588bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
589bf215546Sopenharmony_ci      RET((uint32_t []) { 1 });
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
592bf215546Sopenharmony_ci      RET((uint32_t []) { BRW_SUBGROUP_SIZE });
593bf215546Sopenharmony_ci
594bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
595bf215546Sopenharmony_ci      RET((uint64_t []) { max_invocations });
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
598bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
599bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
600bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
601bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
602bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
603bf215546Sopenharmony_ci
604bf215546Sopenharmony_ci      // XXX: I think these are for Clover...
605bf215546Sopenharmony_ci      return 0;
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_ci   default:
608bf215546Sopenharmony_ci      unreachable("unknown compute param");
609bf215546Sopenharmony_ci   }
610bf215546Sopenharmony_ci}
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_cistatic uint64_t
613bf215546Sopenharmony_cicrocus_get_timestamp(struct pipe_screen *pscreen)
614bf215546Sopenharmony_ci{
615bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *) pscreen;
616bf215546Sopenharmony_ci   const unsigned TIMESTAMP = 0x2358;
617bf215546Sopenharmony_ci   uint64_t result;
618bf215546Sopenharmony_ci
619bf215546Sopenharmony_ci   crocus_reg_read(screen->bufmgr, TIMESTAMP | 1, &result);
620bf215546Sopenharmony_ci
621bf215546Sopenharmony_ci   result = intel_device_info_timebase_scale(&screen->devinfo, result);
622bf215546Sopenharmony_ci   result &= (1ull << TIMESTAMP_BITS) - 1;
623bf215546Sopenharmony_ci
624bf215546Sopenharmony_ci   return result;
625bf215546Sopenharmony_ci}
626bf215546Sopenharmony_ci
627bf215546Sopenharmony_civoid
628bf215546Sopenharmony_cicrocus_screen_destroy(struct crocus_screen *screen)
629bf215546Sopenharmony_ci{
630bf215546Sopenharmony_ci   u_transfer_helper_destroy(screen->base.transfer_helper);
631bf215546Sopenharmony_ci   crocus_bufmgr_unref(screen->bufmgr);
632bf215546Sopenharmony_ci   disk_cache_destroy(screen->disk_cache);
633bf215546Sopenharmony_ci   close(screen->winsys_fd);
634bf215546Sopenharmony_ci   ralloc_free(screen);
635bf215546Sopenharmony_ci}
636bf215546Sopenharmony_ci
637bf215546Sopenharmony_cistatic void
638bf215546Sopenharmony_cicrocus_screen_unref(struct pipe_screen *pscreen)
639bf215546Sopenharmony_ci{
640bf215546Sopenharmony_ci   crocus_pscreen_unref(pscreen);
641bf215546Sopenharmony_ci}
642bf215546Sopenharmony_ci
643bf215546Sopenharmony_cistatic void
644bf215546Sopenharmony_cicrocus_query_memory_info(struct pipe_screen *pscreen,
645bf215546Sopenharmony_ci                         struct pipe_memory_info *info)
646bf215546Sopenharmony_ci{
647bf215546Sopenharmony_ci}
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_cistatic const void *
650bf215546Sopenharmony_cicrocus_get_compiler_options(struct pipe_screen *pscreen,
651bf215546Sopenharmony_ci                            enum pipe_shader_ir ir,
652bf215546Sopenharmony_ci                            enum pipe_shader_type pstage)
653bf215546Sopenharmony_ci{
654bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *) pscreen;
655bf215546Sopenharmony_ci   gl_shader_stage stage = stage_from_pipe(pstage);
656bf215546Sopenharmony_ci   assert(ir == PIPE_SHADER_IR_NIR);
657bf215546Sopenharmony_ci
658bf215546Sopenharmony_ci   return screen->compiler->nir_options[stage];
659bf215546Sopenharmony_ci}
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_cistatic struct disk_cache *
662bf215546Sopenharmony_cicrocus_get_disk_shader_cache(struct pipe_screen *pscreen)
663bf215546Sopenharmony_ci{
664bf215546Sopenharmony_ci   struct crocus_screen *screen = (struct crocus_screen *) pscreen;
665bf215546Sopenharmony_ci   return screen->disk_cache;
666bf215546Sopenharmony_ci}
667bf215546Sopenharmony_ci
668bf215546Sopenharmony_cistatic const struct intel_l3_config *
669bf215546Sopenharmony_cicrocus_get_default_l3_config(const struct intel_device_info *devinfo,
670bf215546Sopenharmony_ci                             bool compute)
671bf215546Sopenharmony_ci{
672bf215546Sopenharmony_ci   bool wants_dc_cache = true;
673bf215546Sopenharmony_ci   bool has_slm = compute;
674bf215546Sopenharmony_ci   const struct intel_l3_weights w =
675bf215546Sopenharmony_ci      intel_get_default_l3_weights(devinfo, wants_dc_cache, has_slm);
676bf215546Sopenharmony_ci   return intel_get_l3_config(devinfo, w);
677bf215546Sopenharmony_ci}
678bf215546Sopenharmony_ci
679bf215546Sopenharmony_cistatic void
680bf215546Sopenharmony_cicrocus_shader_debug_log(void *data, unsigned *id, const char *fmt, ...)
681bf215546Sopenharmony_ci{
682bf215546Sopenharmony_ci   struct util_debug_callback *dbg = data;
683bf215546Sopenharmony_ci   va_list args;
684bf215546Sopenharmony_ci
685bf215546Sopenharmony_ci   if (!dbg->debug_message)
686bf215546Sopenharmony_ci      return;
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci   va_start(args, fmt);
689bf215546Sopenharmony_ci   dbg->debug_message(dbg->data, id, UTIL_DEBUG_TYPE_SHADER_INFO, fmt, args);
690bf215546Sopenharmony_ci   va_end(args);
691bf215546Sopenharmony_ci}
692bf215546Sopenharmony_ci
693bf215546Sopenharmony_cistatic void
694bf215546Sopenharmony_cicrocus_shader_perf_log(void *data, unsigned *id, const char *fmt, ...)
695bf215546Sopenharmony_ci{
696bf215546Sopenharmony_ci   struct util_debug_callback *dbg = data;
697bf215546Sopenharmony_ci   va_list args;
698bf215546Sopenharmony_ci   va_start(args, fmt);
699bf215546Sopenharmony_ci
700bf215546Sopenharmony_ci   if (INTEL_DEBUG(DEBUG_PERF)) {
701bf215546Sopenharmony_ci      va_list args_copy;
702bf215546Sopenharmony_ci      va_copy(args_copy, args);
703bf215546Sopenharmony_ci      vfprintf(stderr, fmt, args_copy);
704bf215546Sopenharmony_ci      va_end(args_copy);
705bf215546Sopenharmony_ci   }
706bf215546Sopenharmony_ci
707bf215546Sopenharmony_ci   if (dbg->debug_message) {
708bf215546Sopenharmony_ci      dbg->debug_message(dbg->data, id, UTIL_DEBUG_TYPE_PERF_INFO, fmt, args);
709bf215546Sopenharmony_ci   }
710bf215546Sopenharmony_ci
711bf215546Sopenharmony_ci   va_end(args);
712bf215546Sopenharmony_ci}
713bf215546Sopenharmony_ci
714bf215546Sopenharmony_cistruct pipe_screen *
715bf215546Sopenharmony_cicrocus_screen_create(int fd, const struct pipe_screen_config *config)
716bf215546Sopenharmony_ci{
717bf215546Sopenharmony_ci   struct crocus_screen *screen = rzalloc(NULL, struct crocus_screen);
718bf215546Sopenharmony_ci   if (!screen)
719bf215546Sopenharmony_ci      return NULL;
720bf215546Sopenharmony_ci
721bf215546Sopenharmony_ci   if (!intel_get_device_info_from_fd(fd, &screen->devinfo))
722bf215546Sopenharmony_ci      return NULL;
723bf215546Sopenharmony_ci   screen->pci_id = screen->devinfo.pci_device_id;
724bf215546Sopenharmony_ci
725bf215546Sopenharmony_ci   if (screen->devinfo.ver > 8)
726bf215546Sopenharmony_ci      return NULL;
727bf215546Sopenharmony_ci
728bf215546Sopenharmony_ci   if (screen->devinfo.ver == 8) {
729bf215546Sopenharmony_ci      /* bind to cherryview or bdw if forced */
730bf215546Sopenharmony_ci      if (screen->devinfo.platform != INTEL_PLATFORM_CHV &&
731bf215546Sopenharmony_ci          !getenv("CROCUS_GEN8"))
732bf215546Sopenharmony_ci         return NULL;
733bf215546Sopenharmony_ci   }
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_ci   p_atomic_set(&screen->refcount, 1);
736bf215546Sopenharmony_ci
737bf215546Sopenharmony_ci   screen->aperture_bytes = get_aperture_size(fd);
738bf215546Sopenharmony_ci   screen->aperture_threshold = screen->aperture_bytes * 3 / 4;
739bf215546Sopenharmony_ci
740bf215546Sopenharmony_ci   driParseConfigFiles(config->options, config->options_info, 0, "crocus",
741bf215546Sopenharmony_ci                       NULL, NULL, NULL, 0, NULL, 0);
742bf215546Sopenharmony_ci
743bf215546Sopenharmony_ci   bool bo_reuse = false;
744bf215546Sopenharmony_ci   int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse");
745bf215546Sopenharmony_ci   switch (bo_reuse_mode) {
746bf215546Sopenharmony_ci   case DRI_CONF_BO_REUSE_DISABLED:
747bf215546Sopenharmony_ci      break;
748bf215546Sopenharmony_ci   case DRI_CONF_BO_REUSE_ALL:
749bf215546Sopenharmony_ci      bo_reuse = true;
750bf215546Sopenharmony_ci      break;
751bf215546Sopenharmony_ci   }
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_ci   screen->bufmgr = crocus_bufmgr_get_for_fd(&screen->devinfo, fd, bo_reuse);
754bf215546Sopenharmony_ci   if (!screen->bufmgr)
755bf215546Sopenharmony_ci      return NULL;
756bf215546Sopenharmony_ci   screen->fd = crocus_bufmgr_get_fd(screen->bufmgr);
757bf215546Sopenharmony_ci   screen->winsys_fd = fd;
758bf215546Sopenharmony_ci
759bf215546Sopenharmony_ci   brw_process_intel_debug_variable();
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_ci   screen->driconf.dual_color_blend_by_location =
762bf215546Sopenharmony_ci      driQueryOptionb(config->options, "dual_color_blend_by_location");
763bf215546Sopenharmony_ci   screen->driconf.disable_throttling =
764bf215546Sopenharmony_ci      driQueryOptionb(config->options, "disable_throttling");
765bf215546Sopenharmony_ci   screen->driconf.always_flush_cache =
766bf215546Sopenharmony_ci      driQueryOptionb(config->options, "always_flush_cache");
767bf215546Sopenharmony_ci   screen->driconf.limit_trig_input_range =
768bf215546Sopenharmony_ci      driQueryOptionb(config->options, "limit_trig_input_range");
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci   screen->precompile = env_var_as_boolean("shader_precompile", true);
771bf215546Sopenharmony_ci
772bf215546Sopenharmony_ci   isl_device_init(&screen->isl_dev, &screen->devinfo);
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_ci   screen->compiler = brw_compiler_create(screen, &screen->devinfo);
775bf215546Sopenharmony_ci   screen->compiler->shader_debug_log = crocus_shader_debug_log;
776bf215546Sopenharmony_ci   screen->compiler->shader_perf_log = crocus_shader_perf_log;
777bf215546Sopenharmony_ci   screen->compiler->supports_shader_constants = false;
778bf215546Sopenharmony_ci   screen->compiler->constant_buffer_0_is_relative = true;
779bf215546Sopenharmony_ci
780bf215546Sopenharmony_ci   if (screen->devinfo.ver >= 7) {
781bf215546Sopenharmony_ci      screen->l3_config_3d = crocus_get_default_l3_config(&screen->devinfo, false);
782bf215546Sopenharmony_ci      screen->l3_config_cs = crocus_get_default_l3_config(&screen->devinfo, true);
783bf215546Sopenharmony_ci   }
784bf215546Sopenharmony_ci
785bf215546Sopenharmony_ci   crocus_disk_cache_init(screen);
786bf215546Sopenharmony_ci
787bf215546Sopenharmony_ci   slab_create_parent(&screen->transfer_pool,
788bf215546Sopenharmony_ci                      sizeof(struct crocus_transfer), 64);
789bf215546Sopenharmony_ci
790bf215546Sopenharmony_ci   struct pipe_screen *pscreen = &screen->base;
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_ci   crocus_init_screen_fence_functions(pscreen);
793bf215546Sopenharmony_ci   crocus_init_screen_resource_functions(pscreen);
794bf215546Sopenharmony_ci
795bf215546Sopenharmony_ci   pscreen->destroy = crocus_screen_unref;
796bf215546Sopenharmony_ci   pscreen->get_name = crocus_get_name;
797bf215546Sopenharmony_ci   pscreen->get_vendor = crocus_get_vendor;
798bf215546Sopenharmony_ci   pscreen->get_device_vendor = crocus_get_device_vendor;
799bf215546Sopenharmony_ci   pscreen->get_param = crocus_get_param;
800bf215546Sopenharmony_ci   pscreen->get_shader_param = crocus_get_shader_param;
801bf215546Sopenharmony_ci   pscreen->get_compute_param = crocus_get_compute_param;
802bf215546Sopenharmony_ci   pscreen->get_paramf = crocus_get_paramf;
803bf215546Sopenharmony_ci   pscreen->get_compiler_options = crocus_get_compiler_options;
804bf215546Sopenharmony_ci   pscreen->get_device_uuid = crocus_get_device_uuid;
805bf215546Sopenharmony_ci   pscreen->get_driver_uuid = crocus_get_driver_uuid;
806bf215546Sopenharmony_ci   pscreen->get_disk_shader_cache = crocus_get_disk_shader_cache;
807bf215546Sopenharmony_ci   pscreen->is_format_supported = crocus_is_format_supported;
808bf215546Sopenharmony_ci   pscreen->context_create = crocus_create_context;
809bf215546Sopenharmony_ci   pscreen->get_timestamp = crocus_get_timestamp;
810bf215546Sopenharmony_ci   pscreen->query_memory_info = crocus_query_memory_info;
811bf215546Sopenharmony_ci   pscreen->get_driver_query_group_info = crocus_get_monitor_group_info;
812bf215546Sopenharmony_ci   pscreen->get_driver_query_info = crocus_get_monitor_info;
813bf215546Sopenharmony_ci
814bf215546Sopenharmony_ci   genX_call(&screen->devinfo, crocus_init_screen_state, screen);
815bf215546Sopenharmony_ci   genX_call(&screen->devinfo, crocus_init_screen_query, screen);
816bf215546Sopenharmony_ci   return pscreen;
817bf215546Sopenharmony_ci}
818