2 * Copyright 2003 VMware, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "drm-uapi/drm_fourcc.h"
30 #include "main/context.h"
31 #include "main/framebuffer.h"
32 #include "main/renderbuffer.h"
33 #include "main/texobj.h"
34 #include "main/hash.h"
35 #include "main/fbobject.h"
36 #include "main/version.h"
37 #include "main/glthread.h"
38 #include "swrast/s_renderbuffer.h"
39 #include "util/ralloc.h"
40 #include "util/disk_cache.h"
41 #include "brw_defines.h"
42 #include "brw_state.h"
43 #include "compiler/nir/nir.h"
46 #include "util/disk_cache.h"
47 #include "util/xmlpool.h"
49 #include "common/gen_defines.h"
51 static const __DRIconfigOptionsExtension brw_config_options
= {
52 .base
= { __DRI_CONFIG_OPTIONS
, 1 },
55 DRI_CONF_SECTION_PERFORMANCE
56 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
57 * DRI_CONF_BO_REUSE_ALL
59 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
60 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
61 DRI_CONF_ENUM(0, "Disable buffer object reuse")
62 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
65 DRI_CONF_MESA_NO_ERROR("false")
66 DRI_CONF_MESA_GLTHREAD("false")
69 DRI_CONF_SECTION_QUALITY
70 DRI_CONF_PRECISE_TRIG("false")
72 DRI_CONF_OPT_BEGIN(clamp_max_samples
, int, -1)
73 DRI_CONF_DESC(en
, "Clamp the value of GL_MAX_SAMPLES to the "
74 "given integer. If negative, then do not clamp.")
78 DRI_CONF_SECTION_DEBUG
79 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
80 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
81 DRI_CONF_DISABLE_THROTTLING("false")
82 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
83 DRI_CONF_FORCE_GLSL_VERSION(0)
84 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
85 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
86 DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false")
87 DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false")
88 DRI_CONF_ALLOW_GLSL_BUILTIN_VARIABLE_REDECLARATION("false")
89 DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH("false")
90 DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
91 DRI_CONF_FORCE_COMPAT_PROFILE("false")
92 DRI_CONF_FORCE_GLSL_ABS_SQRT("false")
94 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
95 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
99 DRI_CONF_SECTION_MISCELLANEOUS
100 DRI_CONF_GLSL_ZERO_INIT("false")
101 DRI_CONF_ALLOW_RGB10_CONFIGS("false")
102 DRI_CONF_ALLOW_RGB565_CONFIGS("true")
103 DRI_CONF_ALLOW_FP16_CONFIGS("false")
108 #include "intel_batchbuffer.h"
109 #include "intel_buffers.h"
110 #include "brw_bufmgr.h"
111 #include "intel_fbo.h"
112 #include "intel_mipmap_tree.h"
113 #include "intel_screen.h"
114 #include "intel_tex.h"
115 #include "intel_image.h"
117 #include "brw_context.h"
119 #include "drm-uapi/i915_drm.h"
122 * For debugging purposes, this returns a time in seconds.
129 clock_gettime(CLOCK_MONOTONIC
, &tp
);
131 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
134 static const __DRItexBufferExtension intelTexBufferExtension
= {
135 .base
= { __DRI_TEX_BUFFER
, 3 },
137 .setTexBuffer
= intelSetTexBuffer
,
138 .setTexBuffer2
= intelSetTexBuffer2
,
139 .releaseTexBuffer
= intelReleaseTexBuffer
,
143 intel_dri2_flush_with_flags(__DRIcontext
*cPriv
,
144 __DRIdrawable
*dPriv
,
146 enum __DRI2throttleReason reason
)
148 struct brw_context
*brw
= cPriv
->driverPrivate
;
153 struct gl_context
*ctx
= &brw
->ctx
;
155 _mesa_glthread_finish(ctx
);
157 FLUSH_VERTICES(ctx
, 0);
159 if (flags
& __DRI2_FLUSH_DRAWABLE
)
160 intel_resolve_for_dri2_flush(brw
, dPriv
);
162 if (reason
== __DRI2_THROTTLE_SWAPBUFFER
)
163 brw
->need_swap_throttle
= true;
164 if (reason
== __DRI2_THROTTLE_FLUSHFRONT
)
165 brw
->need_flush_throttle
= true;
167 intel_batchbuffer_flush(brw
);
171 * Provides compatibility with loaders that only support the older (version
172 * 1-3) flush interface.
174 * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13.
177 intel_dri2_flush(__DRIdrawable
*drawable
)
179 intel_dri2_flush_with_flags(drawable
->driContextPriv
, drawable
,
180 __DRI2_FLUSH_DRAWABLE
,
181 __DRI2_THROTTLE_SWAPBUFFER
);
184 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
185 .base
= { __DRI2_FLUSH
, 4 },
187 .flush
= intel_dri2_flush
,
188 .invalidate
= dri2InvalidateDrawable
,
189 .flush_with_flags
= intel_dri2_flush_with_flags
,
192 static const struct intel_image_format intel_image_formats
[] = {
193 { __DRI_IMAGE_FOURCC_ABGR16161616F
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
194 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR16161616F
, 8 } } },
196 { __DRI_IMAGE_FOURCC_XBGR16161616F
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
197 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR16161616F
, 8 } } },
199 { __DRI_IMAGE_FOURCC_ARGB2101010
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
200 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB2101010
, 4 } } },
202 { __DRI_IMAGE_FOURCC_XRGB2101010
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
203 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB2101010
, 4 } } },
205 { __DRI_IMAGE_FOURCC_ABGR2101010
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
206 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR2101010
, 4 } } },
208 { __DRI_IMAGE_FOURCC_XBGR2101010
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
209 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR2101010
, 4 } } },
211 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
212 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
214 { __DRI_IMAGE_FOURCC_ABGR8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
215 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
217 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
218 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8
, 4 } } },
220 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
221 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
223 { __DRI_IMAGE_FOURCC_XBGR8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
224 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 }, } },
226 { __DRI_IMAGE_FOURCC_ARGB1555
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
227 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555
, 2 } } },
229 { __DRI_IMAGE_FOURCC_RGB565
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
230 { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565
, 2 } } },
232 { __DRI_IMAGE_FOURCC_R8
, __DRI_IMAGE_COMPONENTS_R
, 1,
233 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 }, } },
235 { __DRI_IMAGE_FOURCC_R16
, __DRI_IMAGE_COMPONENTS_R
, 1,
236 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 1 }, } },
238 { __DRI_IMAGE_FOURCC_GR88
, __DRI_IMAGE_COMPONENTS_RG
, 1,
239 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 }, } },
241 { __DRI_IMAGE_FOURCC_GR1616
, __DRI_IMAGE_COMPONENTS_RG
, 1,
242 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616
, 2 }, } },
244 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
245 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
246 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
247 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
249 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
250 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
251 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
252 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
254 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
255 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
256 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
257 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
259 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
260 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
261 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
262 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
264 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
265 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
266 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
267 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
269 { __DRI_IMAGE_FOURCC_YVU410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
270 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
271 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
272 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
274 { __DRI_IMAGE_FOURCC_YVU411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
275 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
276 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
277 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
279 { __DRI_IMAGE_FOURCC_YVU420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
280 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
281 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
282 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
284 { __DRI_IMAGE_FOURCC_YVU422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
285 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
286 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
287 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
289 { __DRI_IMAGE_FOURCC_YVU444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
290 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
291 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
292 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
294 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
295 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
296 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
298 { __DRI_IMAGE_FOURCC_P010
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
299 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
300 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
302 { __DRI_IMAGE_FOURCC_P012
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
303 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
304 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
306 { __DRI_IMAGE_FOURCC_P016
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
307 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
308 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
310 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
311 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
312 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
314 { __DRI_IMAGE_FOURCC_AYUV
, __DRI_IMAGE_COMPONENTS_AYUV
, 1,
315 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
317 { __DRI_IMAGE_FOURCC_XYUV8888
, __DRI_IMAGE_COMPONENTS_XYUV
, 1,
318 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 } } },
320 /* For YUYV and UYVY buffers, we set up two overlapping DRI images
321 * and treat them as planar buffers in the compositors.
322 * Plane 0 is GR88 and samples YU or YV pairs and places Y into
323 * the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
324 * clusters and places pairs and places U into the G component and
325 * V into A. This lets the texture sampler interpolate the Y
326 * components correctly when sampling from plane 0, and interpolate
327 * U and V correctly when sampling from plane 1. */
328 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
329 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
330 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
331 { __DRI_IMAGE_FOURCC_UYVY
, __DRI_IMAGE_COMPONENTS_Y_UXVX
, 2,
332 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
333 { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } }
336 static const struct {
339 } supported_modifiers
[] = {
340 { .modifier
= DRM_FORMAT_MOD_LINEAR
, .since_gen
= 1 },
341 { .modifier
= I915_FORMAT_MOD_X_TILED
, .since_gen
= 1 },
342 { .modifier
= I915_FORMAT_MOD_Y_TILED
, .since_gen
= 6 },
343 { .modifier
= I915_FORMAT_MOD_Y_TILED_CCS
, .since_gen
= 9 },
347 modifier_is_supported(const struct gen_device_info
*devinfo
,
348 const struct intel_image_format
*fmt
, int dri_format
,
351 const struct isl_drm_modifier_info
*modinfo
=
352 isl_drm_modifier_get_info(modifier
);
355 /* ISL had better know about the modifier */
359 if (modinfo
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
360 /* If INTEL_DEBUG=norbc is set, don't support any CCS_E modifiers */
361 if (unlikely(INTEL_DEBUG
& DEBUG_NO_RBC
))
364 /* CCS_E is not supported for planar images */
365 if (fmt
&& fmt
->nplanes
> 1)
369 assert(dri_format
== 0);
370 dri_format
= fmt
->planes
[0].dri_format
;
373 mesa_format format
= driImageFormatToGLFormat(dri_format
);
374 /* Whether or not we support compression is based on the RGBA non-sRGB
375 * version of the format.
377 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
378 format
= _mesa_get_srgb_format_linear(format
);
379 if (!isl_format_supports_ccs_e(devinfo
,
380 brw_isl_format_for_mesa_format(format
)))
384 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
385 if (supported_modifiers
[i
].modifier
!= modifier
)
388 return supported_modifiers
[i
].since_gen
<= devinfo
->gen
;
395 tiling_to_modifier(uint32_t tiling
)
397 static const uint64_t map
[] = {
398 [I915_TILING_NONE
] = DRM_FORMAT_MOD_LINEAR
,
399 [I915_TILING_X
] = I915_FORMAT_MOD_X_TILED
,
400 [I915_TILING_Y
] = I915_FORMAT_MOD_Y_TILED
,
403 assert(tiling
< ARRAY_SIZE(map
));
409 intel_image_warn_if_unaligned(__DRIimage
*image
, const char *func
)
411 uint32_t tiling
, swizzle
;
412 brw_bo_get_tiling(image
->bo
, &tiling
, &swizzle
);
414 if (tiling
!= I915_TILING_NONE
&& (image
->offset
& 0xfff)) {
415 _mesa_warning(NULL
, "%s: offset 0x%08x not on tile boundary",
416 func
, image
->offset
);
420 static const struct intel_image_format
*
421 intel_image_format_lookup(int fourcc
)
423 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
424 if (intel_image_formats
[i
].fourcc
== fourcc
)
425 return &intel_image_formats
[i
];
432 intel_image_get_fourcc(__DRIimage
*image
, int *fourcc
)
434 if (image
->planar_format
) {
435 *fourcc
= image
->planar_format
->fourcc
;
439 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
440 if (intel_image_formats
[i
].planes
[0].dri_format
== image
->dri_format
) {
441 *fourcc
= intel_image_formats
[i
].fourcc
;
449 intel_allocate_image(struct intel_screen
*screen
, int dri_format
,
454 image
= calloc(1, sizeof *image
);
458 image
->screen
= screen
;
459 image
->dri_format
= dri_format
;
462 image
->format
= driImageFormatToGLFormat(dri_format
);
463 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
464 image
->format
== MESA_FORMAT_NONE
) {
469 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
470 image
->data
= loaderPrivate
;
476 * Sets up a DRIImage structure to point to a slice out of a miptree.
479 intel_setup_image_from_mipmap_tree(struct brw_context
*brw
, __DRIimage
*image
,
480 struct intel_mipmap_tree
*mt
, GLuint level
,
483 intel_miptree_make_shareable(brw
, mt
);
485 intel_miptree_check_level_layer(mt
, level
, zoffset
);
487 image
->width
= minify(mt
->surf
.phys_level0_sa
.width
,
488 level
- mt
->first_level
);
489 image
->height
= minify(mt
->surf
.phys_level0_sa
.height
,
490 level
- mt
->first_level
);
491 image
->pitch
= mt
->surf
.row_pitch_B
;
493 image
->offset
= intel_miptree_get_tile_offsets(mt
, level
, zoffset
,
497 brw_bo_unreference(image
->bo
);
499 brw_bo_reference(mt
->bo
);
503 intel_create_image_from_name(__DRIscreen
*dri_screen
,
504 int width
, int height
, int format
,
505 int name
, int pitch
, void *loaderPrivate
)
507 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
511 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
515 if (image
->format
== MESA_FORMAT_NONE
)
518 cpp
= _mesa_get_format_bytes(image
->format
);
520 image
->width
= width
;
521 image
->height
= height
;
522 image
->pitch
= pitch
* cpp
;
523 image
->bo
= brw_bo_gem_create_from_name(screen
->bufmgr
, "image",
529 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
535 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
536 int renderbuffer
, void *loaderPrivate
)
539 struct brw_context
*brw
= context
->driverPrivate
;
540 struct gl_context
*ctx
= &brw
->ctx
;
541 struct gl_renderbuffer
*rb
;
542 struct intel_renderbuffer
*irb
;
544 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
546 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
550 irb
= intel_renderbuffer(rb
);
551 intel_miptree_make_shareable(brw
, irb
->mt
);
552 image
= calloc(1, sizeof *image
);
556 image
->internal_format
= rb
->InternalFormat
;
557 image
->format
= rb
->Format
;
558 image
->modifier
= tiling_to_modifier(
559 isl_tiling_to_i915_tiling(irb
->mt
->surf
.tiling
));
561 image
->data
= loaderPrivate
;
562 brw_bo_unreference(image
->bo
);
563 image
->bo
= irb
->mt
->bo
;
564 brw_bo_reference(irb
->mt
->bo
);
565 image
->width
= rb
->Width
;
566 image
->height
= rb
->Height
;
567 image
->pitch
= irb
->mt
->surf
.row_pitch_B
;
568 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
569 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
571 rb
->NeedsFinishRenderTexture
= true;
576 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
577 unsigned texture
, int zoffset
,
583 struct brw_context
*brw
= context
->driverPrivate
;
584 struct gl_texture_object
*obj
;
585 struct intel_texture_object
*iobj
;
588 obj
= _mesa_lookup_texture(&brw
->ctx
, texture
);
589 if (!obj
|| obj
->Target
!= target
) {
590 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
594 if (target
== GL_TEXTURE_CUBE_MAP
)
597 _mesa_test_texobj_completeness(&brw
->ctx
, obj
);
598 iobj
= intel_texture_object(obj
);
599 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
600 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
604 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
605 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
609 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
610 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
613 image
= calloc(1, sizeof *image
);
615 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
619 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
620 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
621 image
->modifier
= tiling_to_modifier(
622 isl_tiling_to_i915_tiling(iobj
->mt
->surf
.tiling
));
623 image
->data
= loaderPrivate
;
624 intel_setup_image_from_mipmap_tree(brw
, image
, iobj
->mt
, level
, zoffset
);
625 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
626 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
627 image
->planar_format
= iobj
->planar_format
;
628 if (image
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
629 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
634 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
639 intel_destroy_image(__DRIimage
*image
)
641 brw_bo_unreference(image
->bo
);
645 enum modifier_priority
{
646 MODIFIER_PRIORITY_INVALID
= 0,
647 MODIFIER_PRIORITY_LINEAR
,
650 MODIFIER_PRIORITY_Y_CCS
,
653 const uint64_t priority_to_modifier
[] = {
654 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
655 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
656 [MODIFIER_PRIORITY_X
] = I915_FORMAT_MOD_X_TILED
,
657 [MODIFIER_PRIORITY_Y
] = I915_FORMAT_MOD_Y_TILED
,
658 [MODIFIER_PRIORITY_Y_CCS
] = I915_FORMAT_MOD_Y_TILED_CCS
,
662 select_best_modifier(struct gen_device_info
*devinfo
,
664 const uint64_t *modifiers
,
665 const unsigned count
)
667 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
669 for (int i
= 0; i
< count
; i
++) {
670 if (!modifier_is_supported(devinfo
, NULL
, dri_format
, modifiers
[i
]))
673 switch (modifiers
[i
]) {
674 case I915_FORMAT_MOD_Y_TILED_CCS
:
675 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y_CCS
);
677 case I915_FORMAT_MOD_Y_TILED
:
678 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y
);
680 case I915_FORMAT_MOD_X_TILED
:
681 prio
= MAX2(prio
, MODIFIER_PRIORITY_X
);
683 case DRM_FORMAT_MOD_LINEAR
:
684 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
686 case DRM_FORMAT_MOD_INVALID
:
692 return priority_to_modifier
[prio
];
696 intel_create_image_common(__DRIscreen
*dri_screen
,
697 int width
, int height
, int format
,
699 const uint64_t *modifiers
,
704 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
705 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
708 /* Callers of this may specify a modifier, or a dri usage, but not both. The
709 * newer modifier interface deprecates the older usage flags newer modifier
710 * interface deprecates the older usage flags.
712 assert(!(use
&& count
));
714 if (use
& __DRI_IMAGE_USE_CURSOR
) {
715 if (width
!= 64 || height
!= 64)
717 modifier
= DRM_FORMAT_MOD_LINEAR
;
720 if (use
& __DRI_IMAGE_USE_LINEAR
)
721 modifier
= DRM_FORMAT_MOD_LINEAR
;
723 if (modifier
== DRM_FORMAT_MOD_INVALID
) {
725 /* User requested specific modifiers */
726 modifier
= select_best_modifier(&screen
->devinfo
, format
,
728 if (modifier
== DRM_FORMAT_MOD_INVALID
)
731 /* Historically, X-tiled was the default, and so lack of modifier means
734 modifier
= I915_FORMAT_MOD_X_TILED
;
738 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
742 const struct isl_drm_modifier_info
*mod_info
=
743 isl_drm_modifier_get_info(modifier
);
745 struct isl_surf surf
;
746 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
747 .dim
= ISL_SURF_DIM_2D
,
748 .format
= brw_isl_format_for_mesa_format(image
->format
),
755 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
756 ISL_SURF_USAGE_TEXTURE_BIT
|
757 ISL_SURF_USAGE_STORAGE_BIT
,
758 .tiling_flags
= (1 << mod_info
->tiling
));
765 struct isl_surf aux_surf
;
766 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
767 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
, 0);
773 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
777 /* We request that the bufmgr zero the buffer for us for two reasons:
779 * 1) If a buffer gets re-used from the pool, we don't want to leak random
780 * garbage from our process to some other.
782 * 2) For images with CCS_E, we want to ensure that the CCS starts off in
783 * a valid state. A CCS value of 0 indicates that the given block is
784 * in the pass-through state which is what we want.
786 image
->bo
= brw_bo_alloc_tiled(screen
->bufmgr
, "image",
787 surf
.size_B
+ aux_surf
.size_B
,
789 isl_tiling_to_i915_tiling(mod_info
->tiling
),
790 surf
.row_pitch_B
, BO_ALLOC_ZEROED
);
791 if (image
->bo
== NULL
) {
795 image
->width
= width
;
796 image
->height
= height
;
797 image
->pitch
= surf
.row_pitch_B
;
798 image
->modifier
= modifier
;
800 if (aux_surf
.size_B
) {
801 image
->aux_offset
= surf
.size_B
;
802 image
->aux_pitch
= aux_surf
.row_pitch_B
;
803 image
->aux_size
= aux_surf
.size_B
;
810 intel_create_image(__DRIscreen
*dri_screen
,
811 int width
, int height
, int format
,
815 return intel_create_image_common(dri_screen
, width
, height
, format
, use
, NULL
, 0,
820 intel_map_image(__DRIcontext
*context
, __DRIimage
*image
,
821 int x0
, int y0
, int width
, int height
,
822 unsigned int flags
, int *stride
, void **map_info
)
824 struct brw_context
*brw
= NULL
;
825 struct brw_bo
*bo
= NULL
;
826 void *raw_data
= NULL
;
831 if (!context
|| !image
|| !stride
|| !map_info
|| *map_info
)
834 if (x0
< 0 || x0
>= image
->width
|| width
> image
->width
- x0
)
837 if (y0
< 0 || y0
>= image
->height
|| height
> image
->height
- y0
)
840 if (flags
& MAP_INTERNAL_MASK
)
843 brw
= context
->driverPrivate
;
849 /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */
850 raw_data
= brw_bo_map(brw
, bo
, flags
);
854 _mesa_get_format_block_size(image
->format
, &pix_w
, &pix_h
);
855 pix_bytes
= _mesa_get_format_bytes(image
->format
);
859 assert(pix_bytes
> 0);
861 raw_data
+= (x0
/ pix_w
) * pix_bytes
+ (y0
/ pix_h
) * image
->pitch
;
863 brw_bo_reference(bo
);
865 *stride
= image
->pitch
;
872 intel_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *map_info
)
874 struct brw_bo
*bo
= map_info
;
877 brw_bo_unreference(bo
);
881 intel_create_image_with_modifiers(__DRIscreen
*dri_screen
,
882 int width
, int height
, int format
,
883 const uint64_t *modifiers
,
884 const unsigned count
,
887 return intel_create_image_common(dri_screen
, width
, height
, format
, 0,
888 modifiers
, count
, loaderPrivate
);
892 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
895 case __DRI_IMAGE_ATTRIB_STRIDE
:
896 *value
= image
->pitch
;
898 case __DRI_IMAGE_ATTRIB_HANDLE
:
899 *value
= brw_bo_export_gem_handle(image
->bo
);
901 case __DRI_IMAGE_ATTRIB_NAME
:
902 return !brw_bo_flink(image
->bo
, (uint32_t *) value
);
903 case __DRI_IMAGE_ATTRIB_FORMAT
:
904 *value
= image
->dri_format
;
906 case __DRI_IMAGE_ATTRIB_WIDTH
:
907 *value
= image
->width
;
909 case __DRI_IMAGE_ATTRIB_HEIGHT
:
910 *value
= image
->height
;
912 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
913 if (image
->planar_format
== NULL
)
915 *value
= image
->planar_format
->components
;
917 case __DRI_IMAGE_ATTRIB_FD
:
918 return !brw_bo_gem_export_to_prime(image
->bo
, value
);
919 case __DRI_IMAGE_ATTRIB_FOURCC
:
920 return intel_image_get_fourcc(image
, value
);
921 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
922 if (isl_drm_modifier_has_aux(image
->modifier
)) {
923 assert(!image
->planar_format
|| image
->planar_format
->nplanes
== 1);
925 } else if (image
->planar_format
) {
926 *value
= image
->planar_format
->nplanes
;
931 case __DRI_IMAGE_ATTRIB_OFFSET
:
932 *value
= image
->offset
;
934 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
935 *value
= (image
->modifier
& 0xffffffff);
937 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
938 *value
= ((image
->modifier
>> 32) & 0xffffffff);
947 intel_query_format_modifier_attribs(__DRIscreen
*dri_screen
,
948 uint32_t fourcc
, uint64_t modifier
,
949 int attrib
, uint64_t *value
)
951 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
952 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
954 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
958 case __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT
:
959 *value
= isl_drm_modifier_has_aux(modifier
) ? 2 : f
->nplanes
;
968 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
972 image
= calloc(1, sizeof *image
);
976 brw_bo_reference(orig_image
->bo
);
977 image
->bo
= orig_image
->bo
;
978 image
->internal_format
= orig_image
->internal_format
;
979 image
->planar_format
= orig_image
->planar_format
;
980 image
->dri_format
= orig_image
->dri_format
;
981 image
->format
= orig_image
->format
;
982 image
->modifier
= orig_image
->modifier
;
983 image
->offset
= orig_image
->offset
;
984 image
->width
= orig_image
->width
;
985 image
->height
= orig_image
->height
;
986 image
->pitch
= orig_image
->pitch
;
987 image
->tile_x
= orig_image
->tile_x
;
988 image
->tile_y
= orig_image
->tile_y
;
989 image
->has_depthstencil
= orig_image
->has_depthstencil
;
990 image
->data
= loaderPrivate
;
991 image
->aux_offset
= orig_image
->aux_offset
;
992 image
->aux_pitch
= orig_image
->aux_pitch
;
994 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
995 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
1001 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
1003 if (use
& __DRI_IMAGE_USE_CURSOR
) {
1004 if (image
->width
!= 64 || image
->height
!= 64)
1012 intel_create_image_from_names(__DRIscreen
*dri_screen
,
1013 int width
, int height
, int fourcc
,
1014 int *names
, int num_names
,
1015 int *strides
, int *offsets
,
1016 void *loaderPrivate
)
1018 const struct intel_image_format
*f
= NULL
;
1022 if (dri_screen
== NULL
|| names
== NULL
|| num_names
!= 1)
1025 f
= intel_image_format_lookup(fourcc
);
1029 image
= intel_create_image_from_name(dri_screen
, width
, height
,
1030 __DRI_IMAGE_FORMAT_NONE
,
1031 names
[0], strides
[0],
1037 image
->planar_format
= f
;
1038 for (i
= 0; i
< f
->nplanes
; i
++) {
1039 index
= f
->planes
[i
].buffer_index
;
1040 image
->offsets
[index
] = offsets
[index
];
1041 image
->strides
[index
] = strides
[index
];
1048 intel_create_image_from_fds_common(__DRIscreen
*dri_screen
,
1049 int width
, int height
, int fourcc
,
1050 uint64_t modifier
, int *fds
, int num_fds
,
1051 int *strides
, int *offsets
,
1052 void *loaderPrivate
)
1054 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1055 const struct intel_image_format
*f
;
1060 if (fds
== NULL
|| num_fds
< 1)
1063 f
= intel_image_format_lookup(fourcc
);
1067 if (modifier
!= DRM_FORMAT_MOD_INVALID
&&
1068 !modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1071 if (f
->nplanes
== 1)
1072 image
= intel_allocate_image(screen
, f
->planes
[0].dri_format
,
1075 image
= intel_allocate_image(screen
, __DRI_IMAGE_FORMAT_NONE
,
1081 image
->width
= width
;
1082 image
->height
= height
;
1083 image
->pitch
= strides
[0];
1085 image
->planar_format
= f
;
1087 if (modifier
!= DRM_FORMAT_MOD_INVALID
) {
1088 const struct isl_drm_modifier_info
*mod_info
=
1089 isl_drm_modifier_get_info(modifier
);
1090 uint32_t tiling
= isl_tiling_to_i915_tiling(mod_info
->tiling
);
1091 image
->bo
= brw_bo_gem_create_from_prime_tiled(screen
->bufmgr
, fds
[0],
1092 tiling
, strides
[0]);
1094 image
->bo
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[0]);
1097 if (image
->bo
== NULL
) {
1102 /* We only support all planes from the same bo.
1103 * brw_bo_gem_create_from_prime() should return the same pointer for all
1104 * fds received here */
1105 for (i
= 1; i
< num_fds
; i
++) {
1106 struct brw_bo
*aux
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[i
]);
1107 brw_bo_unreference(aux
);
1108 if (aux
!= image
->bo
) {
1109 brw_bo_unreference(image
->bo
);
1115 if (modifier
!= DRM_FORMAT_MOD_INVALID
)
1116 image
->modifier
= modifier
;
1118 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
1120 const struct isl_drm_modifier_info
*mod_info
=
1121 isl_drm_modifier_get_info(image
->modifier
);
1124 struct isl_surf surf
;
1125 for (i
= 0; i
< f
->nplanes
; i
++) {
1126 index
= f
->planes
[i
].buffer_index
;
1127 image
->offsets
[index
] = offsets
[index
];
1128 image
->strides
[index
] = strides
[index
];
1130 mesa_format format
= driImageFormatToGLFormat(f
->planes
[i
].dri_format
);
1131 /* The images we will create are actually based on the RGBA non-sRGB
1132 * version of the format.
1134 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1135 format
= _mesa_get_srgb_format_linear(format
);
1137 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
1138 .dim
= ISL_SURF_DIM_2D
,
1139 .format
= brw_isl_format_for_mesa_format(format
),
1140 .width
= image
->width
>> f
->planes
[i
].width_shift
,
1141 .height
= image
->height
>> f
->planes
[i
].height_shift
,
1146 .row_pitch_B
= strides
[index
],
1147 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
1148 ISL_SURF_USAGE_TEXTURE_BIT
|
1149 ISL_SURF_USAGE_STORAGE_BIT
,
1150 .tiling_flags
= (1 << mod_info
->tiling
));
1152 brw_bo_unreference(image
->bo
);
1157 const int end
= offsets
[index
] + surf
.size_B
;
1162 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
1163 /* Even though we initialize surf in the loop above, we know that
1164 * anything with CCS_E will have exactly one plane so surf is properly
1165 * initialized when we get here.
1167 assert(f
->nplanes
== 1);
1169 image
->aux_offset
= offsets
[1];
1170 image
->aux_pitch
= strides
[1];
1172 /* Scanout hardware requires that the CCS be placed after the main
1173 * surface in memory. We consider any CCS that is placed any earlier in
1174 * memory to be invalid and reject it.
1176 * At some point in the future, this restriction may be relaxed if the
1177 * hardware becomes less strict but we may need a new modifier for that.
1180 if (image
->aux_offset
< size
) {
1181 brw_bo_unreference(image
->bo
);
1186 struct isl_surf aux_surf
;
1187 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
,
1190 brw_bo_unreference(image
->bo
);
1195 image
->aux_size
= aux_surf
.size_B
;
1197 const int end
= image
->aux_offset
+ aux_surf
.size_B
;
1201 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
1204 /* Check that the requested image actually fits within the BO. 'size'
1205 * is already relative to the offsets, so we don't need to add that. */
1206 if (image
->bo
->size
== 0) {
1207 image
->bo
->size
= size
;
1208 } else if (size
> image
->bo
->size
) {
1209 brw_bo_unreference(image
->bo
);
1214 if (f
->nplanes
== 1) {
1215 image
->offset
= image
->offsets
[0];
1216 intel_image_warn_if_unaligned(image
, __func__
);
1223 intel_create_image_from_fds(__DRIscreen
*dri_screen
,
1224 int width
, int height
, int fourcc
,
1225 int *fds
, int num_fds
, int *strides
, int *offsets
,
1226 void *loaderPrivate
)
1228 return intel_create_image_from_fds_common(dri_screen
, width
, height
, fourcc
,
1229 DRM_FORMAT_MOD_INVALID
,
1230 fds
, num_fds
, strides
, offsets
,
1235 intel_create_image_from_dma_bufs2(__DRIscreen
*dri_screen
,
1236 int width
, int height
,
1237 int fourcc
, uint64_t modifier
,
1238 int *fds
, int num_fds
,
1239 int *strides
, int *offsets
,
1240 enum __DRIYUVColorSpace yuv_color_space
,
1241 enum __DRISampleRange sample_range
,
1242 enum __DRIChromaSiting horizontal_siting
,
1243 enum __DRIChromaSiting vertical_siting
,
1245 void *loaderPrivate
)
1248 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
1251 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1255 image
= intel_create_image_from_fds_common(dri_screen
, width
, height
,
1257 fds
, num_fds
, strides
, offsets
,
1261 * Invalid parameters and any inconsistencies between are assumed to be
1262 * checked by the caller. Therefore besides unsupported formats one can fail
1263 * only in allocation.
1266 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1270 image
->yuv_color_space
= yuv_color_space
;
1271 image
->sample_range
= sample_range
;
1272 image
->horizontal_siting
= horizontal_siting
;
1273 image
->vertical_siting
= vertical_siting
;
1275 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1280 intel_create_image_from_dma_bufs(__DRIscreen
*dri_screen
,
1281 int width
, int height
, int fourcc
,
1282 int *fds
, int num_fds
,
1283 int *strides
, int *offsets
,
1284 enum __DRIYUVColorSpace yuv_color_space
,
1285 enum __DRISampleRange sample_range
,
1286 enum __DRIChromaSiting horizontal_siting
,
1287 enum __DRIChromaSiting vertical_siting
,
1289 void *loaderPrivate
)
1291 return intel_create_image_from_dma_bufs2(dri_screen
, width
, height
,
1292 fourcc
, DRM_FORMAT_MOD_INVALID
,
1293 fds
, num_fds
, strides
, offsets
,
1303 intel_image_format_is_supported(const struct gen_device_info
*devinfo
,
1304 const struct intel_image_format
*fmt
)
1306 /* Currently, all formats with an intel_image_format are available on all
1307 * platforms so there's really nothing to check there.
1311 if (fmt
->nplanes
== 1) {
1312 mesa_format format
= driImageFormatToGLFormat(fmt
->planes
[0].dri_format
);
1313 /* The images we will create are actually based on the RGBA non-sRGB
1314 * version of the format.
1316 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1317 format
= _mesa_get_srgb_format_linear(format
);
1318 enum isl_format isl_format
= brw_isl_format_for_mesa_format(format
);
1319 assert(isl_format_supports_rendering(devinfo
, isl_format
));
1327 intel_query_dma_buf_formats(__DRIscreen
*_screen
, int max
,
1328 int *formats
, int *count
)
1330 struct intel_screen
*screen
= _screen
->driverPrivate
;
1331 int num_formats
= 0, i
;
1333 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
1334 /* These two formats are valid DRI formats but do not exist in
1335 * drm_fourcc.h in the Linux kernel. We don't want to accidentally
1336 * advertise them through the EGL layer.
1338 if (intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SARGB8888
||
1339 intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SABGR8888
)
1342 if (!intel_image_format_is_supported(&screen
->devinfo
,
1343 &intel_image_formats
[i
]))
1350 formats
[num_formats
- 1] = intel_image_formats
[i
].fourcc
;
1351 if (num_formats
>= max
)
1355 *count
= num_formats
;
1360 intel_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1361 uint64_t *modifiers
,
1362 unsigned int *external_only
,
1365 struct intel_screen
*screen
= _screen
->driverPrivate
;
1366 const struct intel_image_format
*f
;
1367 int num_mods
= 0, i
;
1369 f
= intel_image_format_lookup(fourcc
);
1373 if (!intel_image_format_is_supported(&screen
->devinfo
, f
))
1376 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
1377 uint64_t modifier
= supported_modifiers
[i
].modifier
;
1378 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1385 modifiers
[num_mods
- 1] = modifier
;
1386 if (num_mods
>= max
)
1390 if (external_only
!= NULL
) {
1391 for (i
= 0; i
< num_mods
&& i
< max
; i
++) {
1392 if (f
->components
== __DRI_IMAGE_COMPONENTS_Y_U_V
||
1393 f
->components
== __DRI_IMAGE_COMPONENTS_Y_UV
||
1394 f
->components
== __DRI_IMAGE_COMPONENTS_Y_XUXV
||
1395 f
->components
== __DRI_IMAGE_COMPONENTS_Y_UXVX
) {
1396 external_only
[i
] = GL_TRUE
;
1399 external_only
[i
] = GL_FALSE
;
1409 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
1411 int width
, height
, offset
, stride
, size
, dri_format
;
1417 width
= parent
->width
;
1418 height
= parent
->height
;
1420 const struct intel_image_format
*f
= parent
->planar_format
;
1422 if (f
&& plane
< f
->nplanes
) {
1423 /* Use the planar format definition. */
1424 width
>>= f
->planes
[plane
].width_shift
;
1425 height
>>= f
->planes
[plane
].height_shift
;
1426 dri_format
= f
->planes
[plane
].dri_format
;
1427 int index
= f
->planes
[plane
].buffer_index
;
1428 offset
= parent
->offsets
[index
];
1429 stride
= parent
->strides
[index
];
1430 size
= height
* stride
;
1431 } else if (plane
== 0) {
1432 /* The only plane of a non-planar image: copy the parent definition
1434 dri_format
= parent
->dri_format
;
1435 offset
= parent
->offset
;
1436 stride
= parent
->pitch
;
1437 size
= height
* stride
;
1438 } else if (plane
== 1 && parent
->modifier
!= DRM_FORMAT_MOD_INVALID
&&
1439 isl_drm_modifier_has_aux(parent
->modifier
)) {
1440 /* Auxiliary plane */
1441 dri_format
= parent
->dri_format
;
1442 offset
= parent
->aux_offset
;
1443 stride
= parent
->aux_pitch
;
1444 size
= parent
->aux_size
;
1449 if (offset
+ size
> parent
->bo
->size
) {
1450 _mesa_warning(NULL
, "intel_from_planar: subimage out of bounds");
1454 image
= intel_allocate_image(parent
->screen
, dri_format
, loaderPrivate
);
1458 image
->bo
= parent
->bo
;
1459 brw_bo_reference(parent
->bo
);
1460 image
->modifier
= parent
->modifier
;
1462 image
->width
= width
;
1463 image
->height
= height
;
1464 image
->pitch
= stride
;
1465 image
->offset
= offset
;
1467 intel_image_warn_if_unaligned(image
, __func__
);
1472 static const __DRIimageExtension intelImageExtension
= {
1473 .base
= { __DRI_IMAGE
, 16 },
1475 .createImageFromName
= intel_create_image_from_name
,
1476 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
1477 .destroyImage
= intel_destroy_image
,
1478 .createImage
= intel_create_image
,
1479 .queryImage
= intel_query_image
,
1480 .dupImage
= intel_dup_image
,
1481 .validateUsage
= intel_validate_usage
,
1482 .createImageFromNames
= intel_create_image_from_names
,
1483 .fromPlanar
= intel_from_planar
,
1484 .createImageFromTexture
= intel_create_image_from_texture
,
1485 .createImageFromFds
= intel_create_image_from_fds
,
1486 .createImageFromDmaBufs
= intel_create_image_from_dma_bufs
,
1488 .getCapabilities
= NULL
,
1489 .mapImage
= intel_map_image
,
1490 .unmapImage
= intel_unmap_image
,
1491 .createImageWithModifiers
= intel_create_image_with_modifiers
,
1492 .createImageFromDmaBufs2
= intel_create_image_from_dma_bufs2
,
1493 .queryDmaBufFormats
= intel_query_dma_buf_formats
,
1494 .queryDmaBufModifiers
= intel_query_dma_buf_modifiers
,
1495 .queryDmaBufFormatModifierAttribs
= intel_query_format_modifier_attribs
,
1499 get_aperture_size(int fd
)
1501 struct drm_i915_gem_get_aperture aperture
;
1503 if (drmIoctl(fd
, DRM_IOCTL_I915_GEM_GET_APERTURE
, &aperture
) != 0)
1506 return aperture
.aper_size
;
1510 brw_query_renderer_integer(__DRIscreen
*dri_screen
,
1511 int param
, unsigned int *value
)
1513 const struct intel_screen
*const screen
=
1514 (struct intel_screen
*) dri_screen
->driverPrivate
;
1517 case __DRI2_RENDERER_VENDOR_ID
:
1520 case __DRI2_RENDERER_DEVICE_ID
:
1521 value
[0] = screen
->deviceID
;
1523 case __DRI2_RENDERER_ACCELERATED
:
1526 case __DRI2_RENDERER_VIDEO_MEMORY
: {
1527 /* Once a batch uses more than 75% of the maximum mappable size, we
1528 * assume that there's some fragmentation, and we start doing extra
1529 * flushing, etc. That's the big cliff apps will care about.
1531 const unsigned gpu_mappable_megabytes
=
1532 screen
->aperture_threshold
/ (1024 * 1024);
1534 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
1535 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
1537 if (system_memory_pages
<= 0 || system_page_size
<= 0)
1540 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
1541 * (uint64_t) system_page_size
;
1543 const unsigned system_memory_megabytes
=
1544 (unsigned) (system_memory_bytes
/ (1024 * 1024));
1546 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
1549 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
1552 case __DRI2_RENDERER_HAS_TEXTURE_3D
:
1555 case __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
:
1557 if (brw_hw_context_set_priority(screen
->bufmgr
,
1558 0, GEN_CONTEXT_HIGH_PRIORITY
) == 0)
1559 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH
;
1560 if (brw_hw_context_set_priority(screen
->bufmgr
,
1561 0, GEN_CONTEXT_LOW_PRIORITY
) == 0)
1562 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW
;
1563 /* reset to default last, just in case */
1564 if (brw_hw_context_set_priority(screen
->bufmgr
,
1565 0, GEN_CONTEXT_MEDIUM_PRIORITY
) == 0)
1566 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM
;
1568 case __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
:
1572 return driQueryRendererIntegerCommon(dri_screen
, param
, value
);
1579 brw_query_renderer_string(__DRIscreen
*dri_screen
,
1580 int param
, const char **value
)
1582 const struct intel_screen
*screen
=
1583 (struct intel_screen
*) dri_screen
->driverPrivate
;
1586 case __DRI2_RENDERER_VENDOR_ID
:
1587 value
[0] = brw_vendor_string
;
1589 case __DRI2_RENDERER_DEVICE_ID
:
1590 value
[0] = brw_get_renderer_string(screen
);
1600 brw_set_cache_funcs(__DRIscreen
*dri_screen
,
1601 __DRIblobCacheSet set
, __DRIblobCacheGet get
)
1603 const struct intel_screen
*const screen
=
1604 (struct intel_screen
*) dri_screen
->driverPrivate
;
1606 if (!screen
->disk_cache
)
1609 disk_cache_set_callbacks(screen
->disk_cache
, set
, get
);
1612 static const __DRI2rendererQueryExtension intelRendererQueryExtension
= {
1613 .base
= { __DRI2_RENDERER_QUERY
, 1 },
1615 .queryInteger
= brw_query_renderer_integer
,
1616 .queryString
= brw_query_renderer_string
1619 static const __DRIrobustnessExtension dri2Robustness
= {
1620 .base
= { __DRI2_ROBUSTNESS
, 1 }
1623 static const __DRI2blobExtension intelBlobExtension
= {
1624 .base
= { __DRI2_BLOB
, 1 },
1625 .set_cache_funcs
= brw_set_cache_funcs
1628 static const __DRImutableRenderBufferDriverExtension intelMutableRenderBufferExtension
= {
1629 .base
= { __DRI_MUTABLE_RENDER_BUFFER_DRIVER
, 1 },
1632 static const __DRIextension
*screenExtensions
[] = {
1633 &intelTexBufferExtension
.base
,
1634 &intelFenceExtension
.base
,
1635 &intelFlushExtension
.base
,
1636 &intelImageExtension
.base
,
1637 &intelRendererQueryExtension
.base
,
1638 &intelMutableRenderBufferExtension
.base
,
1639 &dri2ConfigQueryExtension
.base
,
1640 &dri2NoErrorExtension
.base
,
1641 &intelBlobExtension
.base
,
1645 static const __DRIextension
*intelRobustScreenExtensions
[] = {
1646 &intelTexBufferExtension
.base
,
1647 &intelFenceExtension
.base
,
1648 &intelFlushExtension
.base
,
1649 &intelImageExtension
.base
,
1650 &intelRendererQueryExtension
.base
,
1651 &intelMutableRenderBufferExtension
.base
,
1652 &dri2ConfigQueryExtension
.base
,
1653 &dri2Robustness
.base
,
1654 &dri2NoErrorExtension
.base
,
1655 &intelBlobExtension
.base
,
1660 intel_get_param(struct intel_screen
*screen
, int param
, int *value
)
1663 struct drm_i915_getparam gp
;
1665 memset(&gp
, 0, sizeof(gp
));
1669 if (drmIoctl(screen
->driScrnPriv
->fd
, DRM_IOCTL_I915_GETPARAM
, &gp
) == -1) {
1672 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
1679 intel_get_boolean(struct intel_screen
*screen
, int param
)
1682 return (intel_get_param(screen
, param
, &value
) == 0) && value
;
1686 intel_get_integer(struct intel_screen
*screen
, int param
)
1690 if (intel_get_param(screen
, param
, &value
) == 0)
1697 intelDestroyScreen(__DRIscreen
* sPriv
)
1699 struct intel_screen
*screen
= sPriv
->driverPrivate
;
1701 brw_bufmgr_destroy(screen
->bufmgr
);
1702 driDestroyOptionInfo(&screen
->optionCache
);
1704 disk_cache_destroy(screen
->disk_cache
);
1706 ralloc_free(screen
);
1707 sPriv
->driverPrivate
= NULL
;
1712 * Create a gl_framebuffer and attach it to __DRIdrawable::driverPrivate.
1714 *_This implements driDriverAPI::createNewDrawable, which the DRI layer calls
1715 * when creating a EGLSurface, GLXDrawable, or GLXPixmap. Despite the name,
1716 * this does not allocate GPU memory.
1719 intelCreateBuffer(__DRIscreen
*dri_screen
,
1720 __DRIdrawable
* driDrawPriv
,
1721 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
1723 struct intel_renderbuffer
*rb
;
1724 struct intel_screen
*screen
= (struct intel_screen
*)
1725 dri_screen
->driverPrivate
;
1726 mesa_format rgbFormat
;
1727 unsigned num_samples
=
1728 intel_quantize_num_samples(screen
, mesaVis
->samples
);
1733 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
1737 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
1739 if (screen
->winsys_msaa_samples_override
!= -1) {
1740 num_samples
= screen
->winsys_msaa_samples_override
;
1741 fb
->Visual
.samples
= num_samples
;
1744 if (mesaVis
->redBits
== 16 && mesaVis
->alphaBits
> 0 && mesaVis
->floatMode
) {
1745 rgbFormat
= MESA_FORMAT_RGBA_FLOAT16
;
1746 } else if (mesaVis
->redBits
== 16 && mesaVis
->floatMode
) {
1747 rgbFormat
= MESA_FORMAT_RGBX_FLOAT16
;
1748 } else if (mesaVis
->redBits
== 10 && mesaVis
->alphaBits
> 0) {
1749 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10A2_UNORM
1750 : MESA_FORMAT_R10G10B10A2_UNORM
;
1751 } else if (mesaVis
->redBits
== 10) {
1752 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10X2_UNORM
1753 : MESA_FORMAT_R10G10B10X2_UNORM
;
1754 } else if (mesaVis
->redBits
== 5) {
1755 rgbFormat
= mesaVis
->redMask
== 0x1f ? MESA_FORMAT_R5G6B5_UNORM
1756 : MESA_FORMAT_B5G6R5_UNORM
;
1757 } else if (mesaVis
->sRGBCapable
) {
1758 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1759 : MESA_FORMAT_B8G8R8A8_SRGB
;
1760 } else if (mesaVis
->alphaBits
== 0) {
1761 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8X8_UNORM
1762 : MESA_FORMAT_B8G8R8X8_UNORM
;
1764 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1765 : MESA_FORMAT_B8G8R8A8_SRGB
;
1766 fb
->Visual
.sRGBCapable
= true;
1769 /* mesaVis->sRGBCapable was set, user is asking for sRGB */
1770 bool srgb_cap_set
= mesaVis
->redBits
>= 8 && mesaVis
->sRGBCapable
;
1772 /* setup the hardware-based renderbuffers */
1773 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1774 _mesa_attach_and_own_rb(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
1775 rb
->need_srgb
= srgb_cap_set
;
1777 if (mesaVis
->doubleBufferMode
) {
1778 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1779 _mesa_attach_and_own_rb(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
1780 rb
->need_srgb
= srgb_cap_set
;
1784 * Assert here that the gl_config has an expected depth/stencil bit
1785 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
1786 * which constructs the advertised configs.)
1788 if (mesaVis
->depthBits
== 24) {
1789 assert(mesaVis
->stencilBits
== 8);
1791 if (screen
->devinfo
.has_hiz_and_separate_stencil
) {
1792 rb
= intel_create_private_renderbuffer(screen
,
1793 MESA_FORMAT_Z24_UNORM_X8_UINT
,
1795 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1796 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_S_UINT8
,
1798 _mesa_attach_and_own_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1801 * Use combined depth/stencil. Note that the renderbuffer is
1802 * attached to two attachment points.
1804 rb
= intel_create_private_renderbuffer(screen
,
1805 MESA_FORMAT_Z24_UNORM_S8_UINT
,
1807 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1808 _mesa_attach_and_reference_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1811 else if (mesaVis
->depthBits
== 16) {
1812 assert(mesaVis
->stencilBits
== 0);
1813 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_Z_UNORM16
,
1815 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1818 assert(mesaVis
->depthBits
== 0);
1819 assert(mesaVis
->stencilBits
== 0);
1822 /* now add any/all software-based renderbuffers we may need */
1823 _swrast_add_soft_renderbuffers(fb
,
1824 false, /* never sw color */
1825 false, /* never sw depth */
1826 false, /* never sw stencil */
1827 mesaVis
->accumRedBits
> 0,
1828 false, /* never sw alpha */
1829 false /* never sw aux */ );
1830 driDrawPriv
->driverPrivate
= fb
;
1836 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
1838 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
1840 _mesa_reference_framebuffer(&fb
, NULL
);
1844 intel_cs_timestamp_frequency(struct intel_screen
*screen
)
1846 /* We shouldn't need to update gen_device_info.timestamp_frequency prior to
1847 * gen10, PCI-id is enough to figure it out.
1849 assert(screen
->devinfo
.gen
>= 10);
1853 ret
= intel_get_param(screen
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
,
1857 "Kernel 4.15 required to read the CS timestamp frequency.\n");
1861 screen
->devinfo
.timestamp_frequency
= freq
;
1865 intel_detect_sseu(struct intel_screen
*screen
)
1867 assert(screen
->devinfo
.gen
>= 8);
1870 screen
->subslice_total
= -1;
1871 screen
->eu_total
= -1;
1873 ret
= intel_get_param(screen
, I915_PARAM_SUBSLICE_TOTAL
,
1874 &screen
->subslice_total
);
1875 if (ret
< 0 && ret
!= -EINVAL
)
1878 ret
= intel_get_param(screen
,
1879 I915_PARAM_EU_TOTAL
, &screen
->eu_total
);
1880 if (ret
< 0 && ret
!= -EINVAL
)
1883 /* Without this information, we cannot get the right Braswell brandstrings,
1884 * and we have to use conservative numbers for GPGPU on many platforms, but
1885 * otherwise, things will just work.
1887 if (screen
->subslice_total
< 1 || screen
->eu_total
< 1)
1889 "Kernel 4.1 required to properly query GPU properties.\n");
1894 screen
->subslice_total
= -1;
1895 screen
->eu_total
= -1;
1896 _mesa_warning(NULL
, "Failed to query GPU properties (%s).\n", strerror(-ret
));
1900 intel_init_bufmgr(struct intel_screen
*screen
)
1902 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
1904 if (getenv("INTEL_NO_HW") != NULL
)
1905 screen
->no_hw
= true;
1907 screen
->bufmgr
= brw_bufmgr_init(&screen
->devinfo
, dri_screen
->fd
);
1908 if (screen
->bufmgr
== NULL
) {
1909 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1910 __func__
, __LINE__
);
1914 if (!intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_NO_RELOC
)) {
1915 fprintf(stderr
, "[%s: %u] Kernel 3.9 required.\n", __func__
, __LINE__
);
1923 intel_detect_swizzling(struct intel_screen
*screen
)
1925 /* Broadwell PRM says:
1927 * "Before Gen8, there was a historical configuration control field to
1928 * swizzle address bit[6] for in X/Y tiling modes. This was set in three
1929 * different places: TILECTL[1:0], ARB_MODE[5:4], and
1930 * DISP_ARB_CTL[14:13].
1932 * For Gen8 and subsequent generations, the swizzle fields are all
1933 * reserved, and the CPU's memory controller performs all address
1934 * swizzling modifications."
1936 if (screen
->devinfo
.gen
>= 8)
1939 uint32_t tiling
= I915_TILING_X
;
1940 uint32_t swizzle_mode
= 0;
1941 struct brw_bo
*buffer
=
1942 brw_bo_alloc_tiled(screen
->bufmgr
, "swizzle test", 32768,
1943 BRW_MEMZONE_OTHER
, tiling
, 512, 0);
1947 brw_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1948 brw_bo_unreference(buffer
);
1950 return swizzle_mode
!= I915_BIT_6_SWIZZLE_NONE
;
1954 intel_detect_timestamp(struct intel_screen
*screen
)
1956 uint64_t dummy
= 0, last
= 0;
1957 int upper
, lower
, loops
;
1959 /* On 64bit systems, some old kernels trigger a hw bug resulting in the
1960 * TIMESTAMP register being shifted and the low 32bits always zero.
1962 * More recent kernels offer an interface to read the full 36bits
1965 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
| 1, &dummy
) == 0)
1968 /* Determine if we have a 32bit or 64bit kernel by inspecting the
1969 * upper 32bits for a rapidly changing timestamp.
1971 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &last
))
1975 for (loops
= 0; loops
< 10; loops
++) {
1976 /* The TIMESTAMP should change every 80ns, so several round trips
1977 * through the kernel should be enough to advance it.
1979 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &dummy
))
1982 upper
+= (dummy
>> 32) != (last
>> 32);
1983 if (upper
> 1) /* beware 32bit counter overflow */
1984 return 2; /* upper dword holds the low 32bits of the timestamp */
1986 lower
+= (dummy
& 0xffffffff) != (last
& 0xffffffff);
1988 return 1; /* timestamp is unshifted */
1993 /* No advancement? No timestamp! */
1998 * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer.
2000 * Some combinations of hardware and kernel versions allow this feature,
2001 * while others don't. Instead of trying to enumerate every case, just
2002 * try and write a register and see if works.
2005 intel_detect_pipelined_register(struct intel_screen
*screen
,
2006 int reg
, uint32_t expected_value
, bool reset
)
2011 struct brw_bo
*results
, *bo
;
2013 uint32_t offset
= 0;
2015 bool success
= false;
2017 /* Create a zero'ed temporary buffer for reading our results */
2018 results
= brw_bo_alloc(screen
->bufmgr
, "registers", 4096, BRW_MEMZONE_OTHER
);
2019 if (results
== NULL
)
2022 bo
= brw_bo_alloc(screen
->bufmgr
, "batchbuffer", 4096, BRW_MEMZONE_OTHER
);
2026 map
= brw_bo_map(NULL
, bo
, MAP_WRITE
);
2032 /* Write the register. */
2033 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
2035 *batch
++ = expected_value
;
2037 /* Save the register's value back to the buffer. */
2038 *batch
++ = MI_STORE_REGISTER_MEM
| (3 - 2);
2040 struct drm_i915_gem_relocation_entry reloc
= {
2041 .offset
= (char *) batch
- (char *) map
,
2042 .delta
= offset
* sizeof(uint32_t),
2043 .target_handle
= results
->gem_handle
,
2044 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
2045 .write_domain
= I915_GEM_DOMAIN_INSTRUCTION
,
2047 *batch
++ = reloc
.presumed_offset
+ reloc
.delta
;
2049 /* And afterwards clear the register */
2051 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
2056 *batch
++ = MI_BATCH_BUFFER_END
;
2058 struct drm_i915_gem_exec_object2 exec_objects
[2] = {
2060 .handle
= results
->gem_handle
,
2063 .handle
= bo
->gem_handle
,
2064 .relocation_count
= 1,
2065 .relocs_ptr
= (uintptr_t) &reloc
,
2069 struct drm_i915_gem_execbuffer2 execbuf
= {
2070 .buffers_ptr
= (uintptr_t) exec_objects
,
2072 .batch_len
= ALIGN((char *) batch
- (char *) map
, 8),
2073 .flags
= I915_EXEC_RENDER
,
2076 /* Don't bother with error checking - if the execbuf fails, the
2077 * value won't be written and we'll just report that there's no access.
2079 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2080 drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GEM_EXECBUFFER2
, &execbuf
);
2082 /* Check whether the value got written. */
2083 void *results_map
= brw_bo_map(NULL
, results
, MAP_READ
);
2085 success
= *((uint32_t *)results_map
+ offset
) == expected_value
;
2086 brw_bo_unmap(results
);
2090 brw_bo_unreference(bo
);
2092 brw_bo_unreference(results
);
2098 intel_detect_pipelined_so(struct intel_screen
*screen
)
2100 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2102 /* Supposedly, Broadwell just works. */
2103 if (devinfo
->gen
>= 8)
2106 if (devinfo
->gen
<= 6)
2109 /* See the big explanation about command parser versions below */
2110 if (screen
->cmd_parser_version
>= (devinfo
->is_haswell
? 7 : 2))
2113 /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the
2114 * statistics registers), and we already reset it to zero before using it.
2116 return intel_detect_pipelined_register(screen
,
2117 GEN7_SO_WRITE_OFFSET(0),
2123 * Return array of MSAA modes supported by the hardware. The array is
2124 * zero-terminated and sorted in decreasing order.
2127 intel_supported_msaa_modes(const struct intel_screen
*screen
)
2129 static const int gen9_modes
[] = {16, 8, 4, 2, 0, -1};
2130 static const int gen8_modes
[] = {8, 4, 2, 0, -1};
2131 static const int gen7_modes
[] = {8, 4, 0, -1};
2132 static const int gen6_modes
[] = {4, 0, -1};
2133 static const int gen4_modes
[] = {0, -1};
2135 if (screen
->devinfo
.gen
>= 9) {
2137 } else if (screen
->devinfo
.gen
>= 8) {
2139 } else if (screen
->devinfo
.gen
>= 7) {
2141 } else if (screen
->devinfo
.gen
== 6) {
2149 intel_loader_get_cap(const __DRIscreen
*dri_screen
, enum dri_loader_cap cap
)
2151 if (dri_screen
->dri2
.loader
&& dri_screen
->dri2
.loader
->base
.version
>= 4 &&
2152 dri_screen
->dri2
.loader
->getCapability
)
2153 return dri_screen
->dri2
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2155 if (dri_screen
->image
.loader
&& dri_screen
->image
.loader
->base
.version
>= 2 &&
2156 dri_screen
->image
.loader
->getCapability
)
2157 return dri_screen
->image
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2163 intel_allowed_format(__DRIscreen
*dri_screen
, mesa_format format
)
2165 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2167 /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
2168 bool allow_rgba_ordering
= intel_loader_get_cap(dri_screen
, DRI_LOADER_CAP_RGBA_ORDERING
);
2169 if (!allow_rgba_ordering
&&
2170 (format
== MESA_FORMAT_R8G8B8A8_UNORM
||
2171 format
== MESA_FORMAT_R8G8B8X8_UNORM
||
2172 format
== MESA_FORMAT_R8G8B8A8_SRGB
))
2175 /* Shall we expose 10 bpc formats? */
2176 bool allow_rgb10_configs
= driQueryOptionb(&screen
->optionCache
,
2177 "allow_rgb10_configs");
2178 if (!allow_rgb10_configs
&&
2179 (format
== MESA_FORMAT_B10G10R10A2_UNORM
||
2180 format
== MESA_FORMAT_B10G10R10X2_UNORM
))
2183 /* Shall we expose 565 formats? */
2184 bool allow_rgb565_configs
= driQueryOptionb(&screen
->optionCache
,
2185 "allow_rgb565_configs");
2186 if (!allow_rgb565_configs
&& format
== MESA_FORMAT_B5G6R5_UNORM
)
2189 /* Shall we expose fp16 formats? */
2190 bool allow_fp16_configs
= driQueryOptionb(&screen
->optionCache
,
2191 "allow_fp16_configs");
2192 allow_fp16_configs
&= intel_loader_get_cap(dri_screen
, DRI_LOADER_CAP_FP16
);
2193 if (!allow_fp16_configs
&&
2194 (format
== MESA_FORMAT_RGBA_FLOAT16
||
2195 format
== MESA_FORMAT_RGBX_FLOAT16
))
2201 static __DRIconfig
**
2202 intel_screen_make_configs(__DRIscreen
*dri_screen
)
2204 static const mesa_format formats
[] = {
2205 MESA_FORMAT_B5G6R5_UNORM
,
2206 MESA_FORMAT_B8G8R8A8_UNORM
,
2207 MESA_FORMAT_B8G8R8X8_UNORM
,
2209 MESA_FORMAT_B8G8R8A8_SRGB
,
2211 /* For 10 bpc, 30 bit depth framebuffers. */
2212 MESA_FORMAT_B10G10R10A2_UNORM
,
2213 MESA_FORMAT_B10G10R10X2_UNORM
,
2215 MESA_FORMAT_RGBA_FLOAT16
,
2216 MESA_FORMAT_RGBX_FLOAT16
,
2218 /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
2219 * Likewise for RGBX and BGRX. Otherwise, the GLX client and the GLX
2220 * server may disagree on which format the GLXFBConfig represents,
2221 * resulting in swapped color channels.
2223 * The problem, as of 2017-05-30:
2224 * When matching a GLXFBConfig to a __DRIconfig, GLX ignores the channel
2225 * order and chooses the first __DRIconfig with the expected channel
2226 * sizes. Specifically, GLX compares the GLXFBConfig's and __DRIconfig's
2227 * __DRI_ATTRIB_{CHANNEL}_SIZE but ignores __DRI_ATTRIB_{CHANNEL}_MASK.
2229 * EGL does not suffer from this problem. It correctly compares the
2230 * channel masks when matching EGLConfig to __DRIconfig.
2233 /* Required by Android, for HAL_PIXEL_FORMAT_RGBA_8888. */
2234 MESA_FORMAT_R8G8B8A8_UNORM
,
2236 /* Required by Android, for HAL_PIXEL_FORMAT_RGBX_8888. */
2237 MESA_FORMAT_R8G8B8X8_UNORM
,
2239 MESA_FORMAT_R8G8B8A8_SRGB
,
2242 /* __DRI_ATTRIB_SWAP_COPY is not supported due to page flipping. */
2243 static const GLenum back_buffer_modes
[] = {
2244 __DRI_ATTRIB_SWAP_UNDEFINED
, __DRI_ATTRIB_SWAP_NONE
2247 static const uint8_t singlesample_samples
[1] = {0};
2249 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2250 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2251 uint8_t depth_bits
[4], stencil_bits
[4];
2252 __DRIconfig
**configs
= NULL
;
2254 unsigned num_formats
= ARRAY_SIZE(formats
);
2256 /* Generate singlesample configs, each without accumulation buffer
2257 * and with EGL_MUTABLE_RENDER_BUFFER_BIT_KHR.
2259 for (unsigned i
= 0; i
< num_formats
; i
++) {
2260 __DRIconfig
**new_configs
;
2261 int num_depth_stencil_bits
= 2;
2263 if (!intel_allowed_format(dri_screen
, formats
[i
]))
2266 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
2267 * buffer that has a different number of bits per pixel than the color
2268 * buffer, gen >= 6 supports this.
2271 stencil_bits
[0] = 0;
2273 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2275 stencil_bits
[1] = 0;
2276 if (devinfo
->gen
>= 6) {
2278 stencil_bits
[2] = 8;
2279 num_depth_stencil_bits
= 3;
2283 stencil_bits
[1] = 8;
2286 new_configs
= driCreateConfigs(formats
[i
],
2289 num_depth_stencil_bits
,
2290 back_buffer_modes
, 2,
2291 singlesample_samples
, 1,
2293 /*mutable_render_buffer*/ true);
2294 configs
= driConcatConfigs(configs
, new_configs
);
2297 /* Generate the minimum possible set of configs that include an
2298 * accumulation buffer.
2300 for (unsigned i
= 0; i
< num_formats
; i
++) {
2301 __DRIconfig
**new_configs
;
2303 if (!intel_allowed_format(dri_screen
, formats
[i
]))
2306 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2308 stencil_bits
[0] = 0;
2311 stencil_bits
[0] = 8;
2314 new_configs
= driCreateConfigs(formats
[i
],
2315 depth_bits
, stencil_bits
, 1,
2316 back_buffer_modes
, 1,
2317 singlesample_samples
, 1,
2318 true, false, false);
2319 configs
= driConcatConfigs(configs
, new_configs
);
2322 /* Generate multisample configs.
2324 * This loop breaks early, and hence is a no-op, on gen < 6.
2326 * Multisample configs must follow the singlesample configs in order to
2327 * work around an X server bug present in 1.12. The X server chooses to
2328 * associate the first listed RGBA888-Z24S8 config, regardless of its
2329 * sample count, with the 32-bit depth visual used for compositing.
2331 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
2332 * supported. Singlebuffer configs are not supported because no one wants
2335 for (unsigned i
= 0; i
< num_formats
; i
++) {
2336 if (devinfo
->gen
< 6)
2339 if (!intel_allowed_format(dri_screen
, formats
[i
]))
2342 __DRIconfig
**new_configs
;
2343 const int num_depth_stencil_bits
= 2;
2344 int num_msaa_modes
= 0;
2345 const uint8_t *multisample_samples
= NULL
;
2348 stencil_bits
[0] = 0;
2350 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2352 stencil_bits
[1] = 0;
2355 stencil_bits
[1] = 8;
2358 if (devinfo
->gen
>= 9) {
2359 static const uint8_t multisample_samples_gen9
[] = {2, 4, 8, 16};
2360 multisample_samples
= multisample_samples_gen9
;
2361 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen9
);
2362 } else if (devinfo
->gen
== 8) {
2363 static const uint8_t multisample_samples_gen8
[] = {2, 4, 8};
2364 multisample_samples
= multisample_samples_gen8
;
2365 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen8
);
2366 } else if (devinfo
->gen
== 7) {
2367 static const uint8_t multisample_samples_gen7
[] = {4, 8};
2368 multisample_samples
= multisample_samples_gen7
;
2369 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen7
);
2370 } else if (devinfo
->gen
== 6) {
2371 static const uint8_t multisample_samples_gen6
[] = {4};
2372 multisample_samples
= multisample_samples_gen6
;
2373 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen6
);
2376 new_configs
= driCreateConfigs(formats
[i
],
2379 num_depth_stencil_bits
,
2380 back_buffer_modes
, 1,
2381 multisample_samples
,
2383 false, false, false);
2384 configs
= driConcatConfigs(configs
, new_configs
);
2387 if (configs
== NULL
) {
2388 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
2397 set_max_gl_versions(struct intel_screen
*screen
)
2399 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2400 const bool has_astc
= screen
->devinfo
.gen
>= 9;
2402 switch (screen
->devinfo
.gen
) {
2407 dri_screen
->max_gl_core_version
= 46;
2408 dri_screen
->max_gl_compat_version
= 30;
2409 dri_screen
->max_gl_es1_version
= 11;
2410 dri_screen
->max_gl_es2_version
= has_astc
? 32 : 31;
2413 dri_screen
->max_gl_core_version
= 33;
2414 if (can_do_pipelined_register_writes(screen
)) {
2415 dri_screen
->max_gl_core_version
= 42;
2416 if (screen
->devinfo
.is_haswell
&& can_do_compute_dispatch(screen
))
2417 dri_screen
->max_gl_core_version
= 43;
2418 if (screen
->devinfo
.is_haswell
&& can_do_mi_math_and_lrr(screen
))
2419 dri_screen
->max_gl_core_version
= 45;
2421 dri_screen
->max_gl_compat_version
= 30;
2422 dri_screen
->max_gl_es1_version
= 11;
2423 dri_screen
->max_gl_es2_version
= screen
->devinfo
.is_haswell
? 31 : 30;
2426 dri_screen
->max_gl_core_version
= 33;
2427 dri_screen
->max_gl_compat_version
= 30;
2428 dri_screen
->max_gl_es1_version
= 11;
2429 dri_screen
->max_gl_es2_version
= 30;
2433 dri_screen
->max_gl_core_version
= 0;
2434 dri_screen
->max_gl_compat_version
= 21;
2435 dri_screen
->max_gl_es1_version
= 11;
2436 dri_screen
->max_gl_es2_version
= 20;
2439 unreachable("unrecognized intel_screen::gen");
2444 shader_debug_log_mesa(void *data
, const char *fmt
, ...)
2446 struct brw_context
*brw
= (struct brw_context
*)data
;
2449 va_start(args
, fmt
);
2451 _mesa_gl_vdebugf(&brw
->ctx
, &msg_id
,
2452 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2453 MESA_DEBUG_TYPE_OTHER
,
2454 MESA_DEBUG_SEVERITY_NOTIFICATION
, fmt
, args
);
2459 shader_perf_log_mesa(void *data
, const char *fmt
, ...)
2461 struct brw_context
*brw
= (struct brw_context
*)data
;
2464 va_start(args
, fmt
);
2466 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
)) {
2468 va_copy(args_copy
, args
);
2469 vfprintf(stderr
, fmt
, args_copy
);
2473 if (brw
->perf_debug
) {
2475 _mesa_gl_vdebugf(&brw
->ctx
, &msg_id
,
2476 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2477 MESA_DEBUG_TYPE_PERFORMANCE
,
2478 MESA_DEBUG_SEVERITY_MEDIUM
, fmt
, args
);
2484 * This is the driver specific part of the createNewScreen entry point.
2485 * Called when using DRI2.
2487 * \return the struct gl_config supported by this driver
2490 __DRIconfig
**intelInitScreen2(__DRIscreen
*dri_screen
)
2492 struct intel_screen
*screen
;
2494 if (dri_screen
->image
.loader
) {
2495 } else if (dri_screen
->dri2
.loader
->base
.version
<= 2 ||
2496 dri_screen
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
2498 "\nERROR! DRI2 loader with getBuffersWithFormat() "
2499 "support required\n");
2503 /* Allocate the private area */
2504 screen
= rzalloc(NULL
, struct intel_screen
);
2506 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
2509 /* parse information in __driConfigOptions */
2510 driOptionCache options
;
2511 memset(&options
, 0, sizeof(options
));
2513 driParseOptionInfo(&options
, brw_config_options
.xml
);
2514 driParseConfigFiles(&screen
->optionCache
, &options
, dri_screen
->myNum
,
2516 driDestroyOptionCache(&options
);
2518 screen
->driScrnPriv
= dri_screen
;
2519 dri_screen
->driverPrivate
= (void *) screen
;
2521 if (!gen_get_device_info_from_fd(dri_screen
->fd
, &screen
->devinfo
))
2524 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2525 screen
->deviceID
= devinfo
->chipset_id
;
2526 screen
->no_hw
= devinfo
->no_hw
;
2528 if (!intel_init_bufmgr(screen
))
2531 brw_process_intel_debug_variable();
2533 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && devinfo
->gen
< 7) {
2535 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
2536 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
2539 if (intel_get_integer(screen
, I915_PARAM_MMAP_GTT_VERSION
) >= 1) {
2540 /* Theorectically unlimited! At least for individual objects...
2542 * Currently the entire (global) address space for all GTT maps is
2543 * limited to 64bits. That is all objects on the system that are
2544 * setup for GTT mmapping must fit within 64bits. An attempt to use
2545 * one that exceeds the limit with fail in brw_bo_map_gtt().
2547 * Long before we hit that limit, we will be practically limited by
2548 * that any single object must fit in physical memory (RAM). The upper
2549 * limit on the CPU's address space is currently 48bits (Skylake), of
2550 * which only 39bits can be physical memory. (The GPU itself also has
2551 * a 48bit addressable virtual space.) We can fit over 32 million
2552 * objects of the current maximum allocable size before running out
2555 screen
->max_gtt_map_object_size
= UINT64_MAX
;
2557 /* Estimate the size of the mappable aperture into the GTT. There's an
2558 * ioctl to get the whole GTT size, but not one to get the mappable subset.
2559 * It turns out it's basically always 256MB, though some ancient hardware
2562 uint32_t gtt_size
= 256 * 1024 * 1024;
2564 /* We don't want to map two objects such that a memcpy between them would
2565 * just fault one mapping in and then the other over and over forever. So
2566 * we would need to divide the GTT size by 2. Additionally, some GTT is
2567 * taken up by things like the framebuffer and the ringbuffer and such, so
2568 * be more conservative.
2570 screen
->max_gtt_map_object_size
= gtt_size
/ 4;
2573 screen
->aperture_threshold
= get_aperture_size(dri_screen
->fd
) * 3 / 4;
2575 screen
->hw_has_swizzling
= intel_detect_swizzling(screen
);
2576 screen
->hw_has_timestamp
= intel_detect_timestamp(screen
);
2578 isl_device_init(&screen
->isl_dev
, &screen
->devinfo
,
2579 screen
->hw_has_swizzling
);
2581 if (devinfo
->gen
>= 10)
2582 intel_cs_timestamp_frequency(screen
);
2584 /* GENs prior to 8 do not support EU/Subslice info */
2585 if (devinfo
->gen
>= 8) {
2586 intel_detect_sseu(screen
);
2587 } else if (devinfo
->gen
== 7) {
2588 screen
->subslice_total
= 1 << (devinfo
->gt
- 1);
2591 /* Gen7-7.5 kernel requirements / command parser saga:
2594 * Haswell and Baytrail cannot use any privileged batchbuffer features.
2596 * Ivybridge has aliasing PPGTT on by default, which accidentally marks
2597 * all batches secure, allowing them to use any feature with no checking.
2598 * This is effectively equivalent to a command parser version of
2599 * \infinity - everything is possible.
2601 * The command parser does not exist, and querying the version will
2605 * The kernel enables the command parser by default, for systems with
2606 * aliasing PPGTT enabled (Ivybridge and Haswell). However, the
2607 * hardware checker is still enabled, so Haswell and Baytrail cannot
2610 * Ivybridge goes from "everything is possible" to "only what the
2611 * command parser allows" (if the user boots with i915.cmd_parser=0,
2612 * then everything is possible again). We can only safely use features
2613 * allowed by the supported command parser version.
2615 * Annoyingly, I915_PARAM_CMD_PARSER_VERSION reports the static version
2616 * implemented by the kernel, even if it's turned off. So, checking
2617 * for version > 0 does not mean that you can write registers. We have
2618 * to try it and see. The version does, however, indicate the age of
2621 * Instead of matching the hardware checker's behavior of converting
2622 * privileged commands to MI_NOOP, it makes execbuf2 start returning
2623 * -EINVAL, making it dangerous to try and use privileged features.
2625 * Effective command parser versions:
2626 * - Haswell: 0 (reporting 1, writes don't work)
2627 * - Baytrail: 0 (reporting 1, writes don't work)
2628 * - Ivybridge: 1 (enabled) or infinite (disabled)
2631 * Baytrail aliasing PPGTT is enabled, making it like Ivybridge:
2632 * effectively version 1 (enabled) or infinite (disabled).
2634 * - v3.19: f1f55cc0556031c8ee3fe99dae7251e78b9b653b
2635 * Command parser v2 supports predicate writes.
2637 * - Haswell: 0 (reporting 1, writes don't work)
2638 * - Baytrail: 2 (enabled) or infinite (disabled)
2639 * - Ivybridge: 2 (enabled) or infinite (disabled)
2641 * So version >= 2 is enough to know that Ivybridge and Baytrail
2642 * will work. Haswell still can't do anything.
2644 * - v4.0: Version 3 happened. Largely not relevant.
2646 * - v4.1: 6702cf16e0ba8b0129f5aa1b6609d4e9c70bc13b
2647 * L3 config registers are properly saved and restored as part
2648 * of the hardware context. We can approximately detect this point
2649 * in time by checking if I915_PARAM_REVISION is recognized - it
2650 * landed in a later commit, but in the same release cycle.
2652 * - v4.2: 245054a1fe33c06ad233e0d58a27ec7b64db9284
2653 * Command parser finally gains secure batch promotion. On Haswell,
2654 * the hardware checker gets disabled, which finally allows it to do
2655 * privileged commands.
2657 * I915_PARAM_CMD_PARSER_VERSION reports 3. Effective versions:
2658 * - Haswell: 3 (enabled) or 0 (disabled)
2659 * - Baytrail: 3 (enabled) or infinite (disabled)
2660 * - Ivybridge: 3 (enabled) or infinite (disabled)
2662 * Unfortunately, detecting this point in time is tricky, because
2663 * no version bump happened when this important change occurred.
2664 * On Haswell, if we can write any register, then the kernel is at
2665 * least this new, and we can start trusting the version number.
2667 * - v4.4: 2bbe6bbb0dc94fd4ce287bdac9e1bd184e23057b and
2668 * Command parser reaches version 4, allowing access to Haswell
2669 * atomic scratch and chicken3 registers. If version >= 4, we know
2670 * the kernel is new enough to support privileged features on all
2671 * hardware. However, the user might have disabled it...and the
2672 * kernel will still report version 4. So we still have to guess
2675 * - v4.4: 7b9748cb513a6bef4af87b79f0da3ff7e8b56cd8
2676 * Command parser v5 whitelists indirect compute shader dispatch
2677 * registers, needed for OpenGL 4.3 and later.
2680 * Command parser v7 lets us use MI_MATH on Haswell.
2682 * Additionally, the kernel begins reporting version 0 when
2683 * the command parser is disabled, allowing us to skip the
2684 * guess-and-check step on Haswell. Unfortunately, this also
2685 * means that we can no longer use it as an indicator of the
2686 * age of the kernel.
2688 if (intel_get_param(screen
, I915_PARAM_CMD_PARSER_VERSION
,
2689 &screen
->cmd_parser_version
) < 0) {
2690 /* Command parser does not exist - getparam is unrecognized */
2691 screen
->cmd_parser_version
= 0;
2694 /* Kernel 4.13 retuired for exec object capture */
2695 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_CAPTURE
)) {
2696 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_CAPTURE
;
2699 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_BATCH_FIRST
)) {
2700 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_BATCH_FIRST
;
2703 if (!intel_detect_pipelined_so(screen
)) {
2704 /* We can't do anything, so the effective version is 0. */
2705 screen
->cmd_parser_version
= 0;
2707 screen
->kernel_features
|= KERNEL_ALLOWS_SOL_OFFSET_WRITES
;
2710 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 2)
2711 screen
->kernel_features
|= KERNEL_ALLOWS_PREDICATE_WRITES
;
2713 /* Haswell requires command parser version 4 in order to have L3
2714 * atomic scratch1 and chicken3 bits
2716 if (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 4) {
2717 screen
->kernel_features
|=
2718 KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3
;
2721 /* Haswell requires command parser version 6 in order to write to the
2722 * MI_MATH GPR registers, and version 7 in order to use
2723 * MI_LOAD_REGISTER_REG (which all users of MI_MATH use).
2725 if (devinfo
->gen
>= 8 ||
2726 (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 7)) {
2727 screen
->kernel_features
|= KERNEL_ALLOWS_MI_MATH_AND_LRR
;
2730 /* Gen7 needs at least command parser version 5 to support compute */
2731 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 5)
2732 screen
->kernel_features
|= KERNEL_ALLOWS_COMPUTE_DISPATCH
;
2734 if (intel_get_boolean(screen
, I915_PARAM_HAS_CONTEXT_ISOLATION
))
2735 screen
->kernel_features
|= KERNEL_ALLOWS_CONTEXT_ISOLATION
;
2737 const char *force_msaa
= getenv("INTEL_FORCE_MSAA");
2739 screen
->winsys_msaa_samples_override
=
2740 intel_quantize_num_samples(screen
, atoi(force_msaa
));
2741 printf("Forcing winsys sample count to %d\n",
2742 screen
->winsys_msaa_samples_override
);
2744 screen
->winsys_msaa_samples_override
= -1;
2747 set_max_gl_versions(screen
);
2749 /* Notification of GPU resets requires hardware contexts and a kernel new
2750 * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is
2751 * supported, calling it with a context of 0 will either generate EPERM or
2752 * no error. If the ioctl is not supported, it always generate EINVAL.
2753 * Use this to determine whether to advertise the __DRI2_ROBUSTNESS
2754 * extension to the loader.
2756 * Don't even try on pre-Gen6, since we don't attempt to use contexts there.
2758 if (devinfo
->gen
>= 6) {
2759 struct drm_i915_reset_stats stats
;
2760 memset(&stats
, 0, sizeof(stats
));
2762 const int ret
= drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GET_RESET_STATS
, &stats
);
2764 screen
->has_context_reset_notification
=
2765 (ret
!= -1 || errno
!= EINVAL
);
2768 dri_screen
->extensions
= !screen
->has_context_reset_notification
2769 ? screenExtensions
: intelRobustScreenExtensions
;
2771 screen
->compiler
= brw_compiler_create(screen
, devinfo
);
2772 screen
->compiler
->shader_debug_log
= shader_debug_log_mesa
;
2773 screen
->compiler
->shader_perf_log
= shader_perf_log_mesa
;
2775 /* Changing the meaning of constant buffer pointers from a dynamic state
2776 * offset to an absolute address is only safe if the kernel isolates other
2777 * contexts from our changes.
2779 screen
->compiler
->constant_buffer_0_is_relative
= devinfo
->gen
< 8 ||
2780 !(screen
->kernel_features
& KERNEL_ALLOWS_CONTEXT_ISOLATION
);
2782 screen
->compiler
->supports_pull_constants
= true;
2784 screen
->has_exec_fence
=
2785 intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_FENCE
);
2787 intel_screen_init_surface_formats(screen
);
2789 if (INTEL_DEBUG
& (DEBUG_BATCH
| DEBUG_SUBMIT
)) {
2790 unsigned int caps
= intel_get_integer(screen
, I915_PARAM_HAS_SCHEDULER
);
2792 fprintf(stderr
, "Kernel scheduler detected: %08x\n", caps
);
2793 if (caps
& I915_SCHEDULER_CAP_PRIORITY
)
2794 fprintf(stderr
, " - User priority sorting enabled\n");
2795 if (caps
& I915_SCHEDULER_CAP_PREEMPTION
)
2796 fprintf(stderr
, " - Preemption enabled\n");
2800 brw_disk_cache_init(screen
);
2802 return (const __DRIconfig
**) intel_screen_make_configs(dri_screen
);
2805 struct intel_buffer
{
2810 static __DRIbuffer
*
2811 intelAllocateBuffer(__DRIscreen
*dri_screen
,
2812 unsigned attachment
, unsigned format
,
2813 int width
, int height
)
2815 struct intel_buffer
*intelBuffer
;
2816 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2818 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
2819 attachment
== __DRI_BUFFER_BACK_LEFT
);
2821 intelBuffer
= calloc(1, sizeof *intelBuffer
);
2822 if (intelBuffer
== NULL
)
2825 /* The front and back buffers are color buffers, which are X tiled. GEN9+
2826 * supports Y tiled and compressed buffers, but there is no way to plumb that
2827 * through to here. */
2829 int cpp
= format
/ 8;
2830 intelBuffer
->bo
= brw_bo_alloc_tiled_2d(screen
->bufmgr
,
2831 "intelAllocateBuffer",
2836 I915_TILING_X
, &pitch
,
2839 if (intelBuffer
->bo
== NULL
) {
2844 brw_bo_flink(intelBuffer
->bo
, &intelBuffer
->base
.name
);
2846 intelBuffer
->base
.attachment
= attachment
;
2847 intelBuffer
->base
.cpp
= cpp
;
2848 intelBuffer
->base
.pitch
= pitch
;
2850 return &intelBuffer
->base
;
2854 intelReleaseBuffer(__DRIscreen
*dri_screen
, __DRIbuffer
*buffer
)
2856 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
2858 brw_bo_unreference(intelBuffer
->bo
);
2862 static const struct __DriverAPIRec brw_driver_api
= {
2863 .InitScreen
= intelInitScreen2
,
2864 .DestroyScreen
= intelDestroyScreen
,
2865 .CreateContext
= brwCreateContext
,
2866 .DestroyContext
= intelDestroyContext
,
2867 .CreateBuffer
= intelCreateBuffer
,
2868 .DestroyBuffer
= intelDestroyBuffer
,
2869 .MakeCurrent
= intelMakeCurrent
,
2870 .UnbindContext
= intelUnbindContext
,
2871 .AllocateBuffer
= intelAllocateBuffer
,
2872 .ReleaseBuffer
= intelReleaseBuffer
2875 static const struct __DRIDriverVtableExtensionRec brw_vtable
= {
2876 .base
= { __DRI_DRIVER_VTABLE
, 1 },
2877 .vtable
= &brw_driver_api
,
2880 static const __DRIextension
*brw_driver_extensions
[] = {
2881 &driCoreExtension
.base
,
2882 &driImageDriverExtension
.base
,
2883 &driDRI2Extension
.base
,
2885 &brw_config_options
.base
,
2889 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
2891 globalDriverAPI
= &brw_driver_api
;
2893 return brw_driver_extensions
;