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_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 "swrast/s_renderbuffer.h"
38 #include "util/ralloc.h"
39 #include "util/disk_cache.h"
40 #include "brw_defines.h"
41 #include "brw_state.h"
42 #include "compiler/nir/nir.h"
45 #include "util/disk_cache.h"
46 #include "util/xmlpool.h"
48 #include "common/gen_defines.h"
50 static const __DRIconfigOptionsExtension brw_config_options
= {
51 .base
= { __DRI_CONFIG_OPTIONS
, 1 },
54 DRI_CONF_SECTION_PERFORMANCE
55 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
56 * DRI_CONF_BO_REUSE_ALL
58 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
59 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
60 DRI_CONF_ENUM(0, "Disable buffer object reuse")
61 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
64 DRI_CONF_MESA_NO_ERROR("false")
67 DRI_CONF_SECTION_QUALITY
68 DRI_CONF_PRECISE_TRIG("false")
70 DRI_CONF_OPT_BEGIN(clamp_max_samples
, int, -1)
71 DRI_CONF_DESC(en
, "Clamp the value of GL_MAX_SAMPLES to the "
72 "given integer. If negative, then do not clamp.")
76 DRI_CONF_SECTION_DEBUG
77 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
78 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
79 DRI_CONF_DISABLE_THROTTLING("false")
80 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
81 DRI_CONF_FORCE_GLSL_VERSION(0)
82 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
83 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
84 DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false")
85 DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false")
86 DRI_CONF_ALLOW_GLSL_BUILTIN_VARIABLE_REDECLARATION("false")
87 DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH("false")
88 DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
89 DRI_CONF_FORCE_GLSL_ABS_SQRT("false")
91 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
92 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
96 DRI_CONF_SECTION_MISCELLANEOUS
97 DRI_CONF_GLSL_ZERO_INIT("false")
98 DRI_CONF_ALLOW_RGB10_CONFIGS("false")
103 #include "intel_batchbuffer.h"
104 #include "intel_buffers.h"
105 #include "brw_bufmgr.h"
106 #include "intel_fbo.h"
107 #include "intel_mipmap_tree.h"
108 #include "intel_screen.h"
109 #include "intel_tex.h"
110 #include "intel_image.h"
112 #include "brw_context.h"
114 #include "i915_drm.h"
117 * For debugging purposes, this returns a time in seconds.
124 clock_gettime(CLOCK_MONOTONIC
, &tp
);
126 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
129 static const __DRItexBufferExtension intelTexBufferExtension
= {
130 .base
= { __DRI_TEX_BUFFER
, 3 },
132 .setTexBuffer
= intelSetTexBuffer
,
133 .setTexBuffer2
= intelSetTexBuffer2
,
134 .releaseTexBuffer
= intelReleaseTexBuffer
,
138 intel_dri2_flush_with_flags(__DRIcontext
*cPriv
,
139 __DRIdrawable
*dPriv
,
141 enum __DRI2throttleReason reason
)
143 struct brw_context
*brw
= cPriv
->driverPrivate
;
148 struct gl_context
*ctx
= &brw
->ctx
;
150 FLUSH_VERTICES(ctx
, 0);
152 if (flags
& __DRI2_FLUSH_DRAWABLE
)
153 intel_resolve_for_dri2_flush(brw
, dPriv
);
155 if (reason
== __DRI2_THROTTLE_SWAPBUFFER
)
156 brw
->need_swap_throttle
= true;
157 if (reason
== __DRI2_THROTTLE_FLUSHFRONT
)
158 brw
->need_flush_throttle
= true;
160 intel_batchbuffer_flush(brw
);
164 * Provides compatibility with loaders that only support the older (version
165 * 1-3) flush interface.
167 * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13.
170 intel_dri2_flush(__DRIdrawable
*drawable
)
172 intel_dri2_flush_with_flags(drawable
->driContextPriv
, drawable
,
173 __DRI2_FLUSH_DRAWABLE
,
174 __DRI2_THROTTLE_SWAPBUFFER
);
177 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
178 .base
= { __DRI2_FLUSH
, 4 },
180 .flush
= intel_dri2_flush
,
181 .invalidate
= dri2InvalidateDrawable
,
182 .flush_with_flags
= intel_dri2_flush_with_flags
,
185 static const struct intel_image_format intel_image_formats
[] = {
186 { __DRI_IMAGE_FOURCC_ARGB2101010
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
187 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB2101010
, 4 } } },
189 { __DRI_IMAGE_FOURCC_XRGB2101010
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
190 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB2101010
, 4 } } },
192 { __DRI_IMAGE_FOURCC_ABGR2101010
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
193 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR2101010
, 4 } } },
195 { __DRI_IMAGE_FOURCC_XBGR2101010
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
196 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR2101010
, 4 } } },
198 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
199 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
201 { __DRI_IMAGE_FOURCC_ABGR8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
202 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
204 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
205 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8
, 4 } } },
207 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
208 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
210 { __DRI_IMAGE_FOURCC_XBGR8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
211 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 }, } },
213 { __DRI_IMAGE_FOURCC_ARGB1555
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
214 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555
, 2 } } },
216 { __DRI_IMAGE_FOURCC_RGB565
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
217 { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565
, 2 } } },
219 { __DRI_IMAGE_FOURCC_R8
, __DRI_IMAGE_COMPONENTS_R
, 1,
220 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 }, } },
222 { __DRI_IMAGE_FOURCC_R16
, __DRI_IMAGE_COMPONENTS_R
, 1,
223 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 1 }, } },
225 { __DRI_IMAGE_FOURCC_GR88
, __DRI_IMAGE_COMPONENTS_RG
, 1,
226 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 }, } },
228 { __DRI_IMAGE_FOURCC_GR1616
, __DRI_IMAGE_COMPONENTS_RG
, 1,
229 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616
, 2 }, } },
231 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
232 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
233 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
234 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
236 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
237 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
238 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
239 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
241 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
242 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
243 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
244 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
246 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
247 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
248 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
249 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
251 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
252 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
253 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
254 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
256 { __DRI_IMAGE_FOURCC_YVU410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
257 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
258 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
259 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
261 { __DRI_IMAGE_FOURCC_YVU411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
262 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
263 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
264 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
266 { __DRI_IMAGE_FOURCC_YVU420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
267 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
268 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
269 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
271 { __DRI_IMAGE_FOURCC_YVU422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
272 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
273 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
274 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
276 { __DRI_IMAGE_FOURCC_YVU444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
277 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
278 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
279 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
281 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
282 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
283 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
285 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
286 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
287 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
289 /* For YUYV and UYVY buffers, we set up two overlapping DRI images
290 * and treat them as planar buffers in the compositors.
291 * Plane 0 is GR88 and samples YU or YV pairs and places Y into
292 * the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
293 * clusters and places pairs and places U into the G component and
294 * V into A. This lets the texture sampler interpolate the Y
295 * components correctly when sampling from plane 0, and interpolate
296 * U and V correctly when sampling from plane 1. */
297 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
298 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
299 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
300 { __DRI_IMAGE_FOURCC_UYVY
, __DRI_IMAGE_COMPONENTS_Y_UXVX
, 2,
301 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
302 { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } }
305 static const struct {
308 } supported_modifiers
[] = {
309 { .modifier
= DRM_FORMAT_MOD_LINEAR
, .since_gen
= 1 },
310 { .modifier
= I915_FORMAT_MOD_X_TILED
, .since_gen
= 1 },
311 { .modifier
= I915_FORMAT_MOD_Y_TILED
, .since_gen
= 6 },
312 { .modifier
= I915_FORMAT_MOD_Y_TILED_CCS
, .since_gen
= 9 },
316 modifier_is_supported(const struct gen_device_info
*devinfo
,
317 const struct intel_image_format
*fmt
, int dri_format
,
320 const struct isl_drm_modifier_info
*modinfo
=
321 isl_drm_modifier_get_info(modifier
);
324 /* ISL had better know about the modifier */
328 if (modinfo
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
329 /* If INTEL_DEBUG=norbc is set, don't support any CCS_E modifiers */
330 if (unlikely(INTEL_DEBUG
& DEBUG_NO_RBC
))
333 /* CCS_E is not supported for planar images */
334 if (fmt
&& fmt
->nplanes
> 1)
338 assert(dri_format
== 0);
339 dri_format
= fmt
->planes
[0].dri_format
;
342 mesa_format format
= driImageFormatToGLFormat(dri_format
);
343 /* Whether or not we support compression is based on the RGBA non-sRGB
344 * version of the format.
346 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
347 format
= _mesa_get_srgb_format_linear(format
);
348 if (!isl_format_supports_ccs_e(devinfo
,
349 brw_isl_format_for_mesa_format(format
)))
353 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
354 if (supported_modifiers
[i
].modifier
!= modifier
)
357 return supported_modifiers
[i
].since_gen
<= devinfo
->gen
;
364 tiling_to_modifier(uint32_t tiling
)
366 static const uint64_t map
[] = {
367 [I915_TILING_NONE
] = DRM_FORMAT_MOD_LINEAR
,
368 [I915_TILING_X
] = I915_FORMAT_MOD_X_TILED
,
369 [I915_TILING_Y
] = I915_FORMAT_MOD_Y_TILED
,
372 assert(tiling
< ARRAY_SIZE(map
));
378 intel_image_warn_if_unaligned(__DRIimage
*image
, const char *func
)
380 uint32_t tiling
, swizzle
;
381 brw_bo_get_tiling(image
->bo
, &tiling
, &swizzle
);
383 if (tiling
!= I915_TILING_NONE
&& (image
->offset
& 0xfff)) {
384 _mesa_warning(NULL
, "%s: offset 0x%08x not on tile boundary",
385 func
, image
->offset
);
389 static const struct intel_image_format
*
390 intel_image_format_lookup(int fourcc
)
392 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
393 if (intel_image_formats
[i
].fourcc
== fourcc
)
394 return &intel_image_formats
[i
];
401 intel_image_get_fourcc(__DRIimage
*image
, int *fourcc
)
403 if (image
->planar_format
) {
404 *fourcc
= image
->planar_format
->fourcc
;
408 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
409 if (intel_image_formats
[i
].planes
[0].dri_format
== image
->dri_format
) {
410 *fourcc
= intel_image_formats
[i
].fourcc
;
418 intel_allocate_image(struct intel_screen
*screen
, int dri_format
,
423 image
= calloc(1, sizeof *image
);
427 image
->screen
= screen
;
428 image
->dri_format
= dri_format
;
431 image
->format
= driImageFormatToGLFormat(dri_format
);
432 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
433 image
->format
== MESA_FORMAT_NONE
) {
438 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
439 image
->data
= loaderPrivate
;
445 * Sets up a DRIImage structure to point to a slice out of a miptree.
448 intel_setup_image_from_mipmap_tree(struct brw_context
*brw
, __DRIimage
*image
,
449 struct intel_mipmap_tree
*mt
, GLuint level
,
452 intel_miptree_make_shareable(brw
, mt
);
454 intel_miptree_check_level_layer(mt
, level
, zoffset
);
456 image
->width
= minify(mt
->surf
.phys_level0_sa
.width
,
457 level
- mt
->first_level
);
458 image
->height
= minify(mt
->surf
.phys_level0_sa
.height
,
459 level
- mt
->first_level
);
460 image
->pitch
= mt
->surf
.row_pitch
;
462 image
->offset
= intel_miptree_get_tile_offsets(mt
, level
, zoffset
,
466 brw_bo_unreference(image
->bo
);
468 brw_bo_reference(mt
->bo
);
472 intel_create_image_from_name(__DRIscreen
*dri_screen
,
473 int width
, int height
, int format
,
474 int name
, int pitch
, void *loaderPrivate
)
476 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
480 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
484 if (image
->format
== MESA_FORMAT_NONE
)
487 cpp
= _mesa_get_format_bytes(image
->format
);
489 image
->width
= width
;
490 image
->height
= height
;
491 image
->pitch
= pitch
* cpp
;
492 image
->bo
= brw_bo_gem_create_from_name(screen
->bufmgr
, "image",
498 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
504 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
505 int renderbuffer
, void *loaderPrivate
)
508 struct brw_context
*brw
= context
->driverPrivate
;
509 struct gl_context
*ctx
= &brw
->ctx
;
510 struct gl_renderbuffer
*rb
;
511 struct intel_renderbuffer
*irb
;
513 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
515 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
519 irb
= intel_renderbuffer(rb
);
520 intel_miptree_make_shareable(brw
, irb
->mt
);
521 image
= calloc(1, sizeof *image
);
525 image
->internal_format
= rb
->InternalFormat
;
526 image
->format
= rb
->Format
;
527 image
->modifier
= tiling_to_modifier(
528 isl_tiling_to_i915_tiling(irb
->mt
->surf
.tiling
));
530 image
->data
= loaderPrivate
;
531 brw_bo_unreference(image
->bo
);
532 image
->bo
= irb
->mt
->bo
;
533 brw_bo_reference(irb
->mt
->bo
);
534 image
->width
= rb
->Width
;
535 image
->height
= rb
->Height
;
536 image
->pitch
= irb
->mt
->surf
.row_pitch
;
537 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
538 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
540 rb
->NeedsFinishRenderTexture
= true;
545 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
546 unsigned texture
, int zoffset
,
552 struct brw_context
*brw
= context
->driverPrivate
;
553 struct gl_texture_object
*obj
;
554 struct intel_texture_object
*iobj
;
557 obj
= _mesa_lookup_texture(&brw
->ctx
, texture
);
558 if (!obj
|| obj
->Target
!= target
) {
559 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
563 if (target
== GL_TEXTURE_CUBE_MAP
)
566 _mesa_test_texobj_completeness(&brw
->ctx
, obj
);
567 iobj
= intel_texture_object(obj
);
568 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
569 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
573 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
574 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
578 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
579 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
582 image
= calloc(1, sizeof *image
);
584 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
588 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
589 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
590 image
->modifier
= tiling_to_modifier(
591 isl_tiling_to_i915_tiling(iobj
->mt
->surf
.tiling
));
592 image
->data
= loaderPrivate
;
593 intel_setup_image_from_mipmap_tree(brw
, image
, iobj
->mt
, level
, zoffset
);
594 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
595 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
596 image
->planar_format
= iobj
->planar_format
;
597 if (image
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
598 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
603 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
608 intel_destroy_image(__DRIimage
*image
)
610 brw_bo_unreference(image
->bo
);
614 enum modifier_priority
{
615 MODIFIER_PRIORITY_INVALID
= 0,
616 MODIFIER_PRIORITY_LINEAR
,
619 MODIFIER_PRIORITY_Y_CCS
,
622 const uint64_t priority_to_modifier
[] = {
623 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
624 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
625 [MODIFIER_PRIORITY_X
] = I915_FORMAT_MOD_X_TILED
,
626 [MODIFIER_PRIORITY_Y
] = I915_FORMAT_MOD_Y_TILED
,
627 [MODIFIER_PRIORITY_Y_CCS
] = I915_FORMAT_MOD_Y_TILED_CCS
,
631 select_best_modifier(struct gen_device_info
*devinfo
,
633 const uint64_t *modifiers
,
634 const unsigned count
)
636 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
638 for (int i
= 0; i
< count
; i
++) {
639 if (!modifier_is_supported(devinfo
, NULL
, dri_format
, modifiers
[i
]))
642 switch (modifiers
[i
]) {
643 case I915_FORMAT_MOD_Y_TILED_CCS
:
644 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y_CCS
);
646 case I915_FORMAT_MOD_Y_TILED
:
647 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y
);
649 case I915_FORMAT_MOD_X_TILED
:
650 prio
= MAX2(prio
, MODIFIER_PRIORITY_X
);
652 case DRM_FORMAT_MOD_LINEAR
:
653 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
655 case DRM_FORMAT_MOD_INVALID
:
661 return priority_to_modifier
[prio
];
665 intel_create_image_common(__DRIscreen
*dri_screen
,
666 int width
, int height
, int format
,
668 const uint64_t *modifiers
,
673 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
674 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
677 /* Callers of this may specify a modifier, or a dri usage, but not both. The
678 * newer modifier interface deprecates the older usage flags newer modifier
679 * interface deprecates the older usage flags.
681 assert(!(use
&& count
));
683 if (use
& __DRI_IMAGE_USE_CURSOR
) {
684 if (width
!= 64 || height
!= 64)
686 modifier
= DRM_FORMAT_MOD_LINEAR
;
689 if (use
& __DRI_IMAGE_USE_LINEAR
)
690 modifier
= DRM_FORMAT_MOD_LINEAR
;
692 if (modifier
== DRM_FORMAT_MOD_INVALID
) {
694 /* User requested specific modifiers */
695 modifier
= select_best_modifier(&screen
->devinfo
, format
,
697 if (modifier
== DRM_FORMAT_MOD_INVALID
)
700 /* Historically, X-tiled was the default, and so lack of modifier means
703 modifier
= I915_FORMAT_MOD_X_TILED
;
707 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
711 const struct isl_drm_modifier_info
*mod_info
=
712 isl_drm_modifier_get_info(modifier
);
714 struct isl_surf surf
;
715 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
716 .dim
= ISL_SURF_DIM_2D
,
717 .format
= brw_isl_format_for_mesa_format(image
->format
),
724 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
725 ISL_SURF_USAGE_TEXTURE_BIT
|
726 ISL_SURF_USAGE_STORAGE_BIT
,
727 .tiling_flags
= (1 << mod_info
->tiling
));
734 struct isl_surf aux_surf
;
735 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
736 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
, 0);
742 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
746 /* We request that the bufmgr zero the buffer for us for two reasons:
748 * 1) If a buffer gets re-used from the pool, we don't want to leak random
749 * garbage from our process to some other.
751 * 2) For images with CCS_E, we want to ensure that the CCS starts off in
752 * a valid state. A CCS value of 0 indicates that the given block is
753 * in the pass-through state which is what we want.
755 image
->bo
= brw_bo_alloc_tiled(screen
->bufmgr
, "image",
756 surf
.size
+ aux_surf
.size
,
758 isl_tiling_to_i915_tiling(mod_info
->tiling
),
759 surf
.row_pitch
, BO_ALLOC_ZEROED
);
760 if (image
->bo
== NULL
) {
764 image
->width
= width
;
765 image
->height
= height
;
766 image
->pitch
= surf
.row_pitch
;
767 image
->modifier
= modifier
;
770 image
->aux_offset
= surf
.size
;
771 image
->aux_pitch
= aux_surf
.row_pitch
;
772 image
->aux_size
= aux_surf
.size
;
779 intel_create_image(__DRIscreen
*dri_screen
,
780 int width
, int height
, int format
,
784 return intel_create_image_common(dri_screen
, width
, height
, format
, use
, NULL
, 0,
789 intel_map_image(__DRIcontext
*context
, __DRIimage
*image
,
790 int x0
, int y0
, int width
, int height
,
791 unsigned int flags
, int *stride
, void **map_info
)
793 struct brw_context
*brw
= NULL
;
794 struct brw_bo
*bo
= NULL
;
795 void *raw_data
= NULL
;
800 if (!context
|| !image
|| !stride
|| !map_info
|| *map_info
)
803 if (x0
< 0 || x0
>= image
->width
|| width
> image
->width
- x0
)
806 if (y0
< 0 || y0
>= image
->height
|| height
> image
->height
- y0
)
809 if (flags
& MAP_INTERNAL_MASK
)
812 brw
= context
->driverPrivate
;
818 /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */
819 raw_data
= brw_bo_map(brw
, bo
, flags
);
823 _mesa_get_format_block_size(image
->format
, &pix_w
, &pix_h
);
824 pix_bytes
= _mesa_get_format_bytes(image
->format
);
828 assert(pix_bytes
> 0);
830 raw_data
+= (x0
/ pix_w
) * pix_bytes
+ (y0
/ pix_h
) * image
->pitch
;
832 brw_bo_reference(bo
);
834 *stride
= image
->pitch
;
841 intel_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *map_info
)
843 struct brw_bo
*bo
= map_info
;
846 brw_bo_unreference(bo
);
850 intel_create_image_with_modifiers(__DRIscreen
*dri_screen
,
851 int width
, int height
, int format
,
852 const uint64_t *modifiers
,
853 const unsigned count
,
856 return intel_create_image_common(dri_screen
, width
, height
, format
, 0,
857 modifiers
, count
, loaderPrivate
);
861 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
864 case __DRI_IMAGE_ATTRIB_STRIDE
:
865 *value
= image
->pitch
;
867 case __DRI_IMAGE_ATTRIB_HANDLE
:
868 *value
= brw_bo_export_gem_handle(image
->bo
);
870 case __DRI_IMAGE_ATTRIB_NAME
:
871 return !brw_bo_flink(image
->bo
, (uint32_t *) value
);
872 case __DRI_IMAGE_ATTRIB_FORMAT
:
873 *value
= image
->dri_format
;
875 case __DRI_IMAGE_ATTRIB_WIDTH
:
876 *value
= image
->width
;
878 case __DRI_IMAGE_ATTRIB_HEIGHT
:
879 *value
= image
->height
;
881 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
882 if (image
->planar_format
== NULL
)
884 *value
= image
->planar_format
->components
;
886 case __DRI_IMAGE_ATTRIB_FD
:
887 return !brw_bo_gem_export_to_prime(image
->bo
, value
);
888 case __DRI_IMAGE_ATTRIB_FOURCC
:
889 return intel_image_get_fourcc(image
, value
);
890 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
891 if (isl_drm_modifier_has_aux(image
->modifier
)) {
892 assert(!image
->planar_format
|| image
->planar_format
->nplanes
== 1);
894 } else if (image
->planar_format
) {
895 *value
= image
->planar_format
->nplanes
;
900 case __DRI_IMAGE_ATTRIB_OFFSET
:
901 *value
= image
->offset
;
903 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
904 *value
= (image
->modifier
& 0xffffffff);
906 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
907 *value
= ((image
->modifier
>> 32) & 0xffffffff);
916 intel_query_format_modifier_attribs(__DRIscreen
*dri_screen
,
917 uint32_t fourcc
, uint64_t modifier
,
918 int attrib
, uint64_t *value
)
920 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
921 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
923 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
927 case __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT
:
928 *value
= isl_drm_modifier_has_aux(modifier
) ? 2 : f
->nplanes
;
937 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
941 image
= calloc(1, sizeof *image
);
945 brw_bo_reference(orig_image
->bo
);
946 image
->bo
= orig_image
->bo
;
947 image
->internal_format
= orig_image
->internal_format
;
948 image
->planar_format
= orig_image
->planar_format
;
949 image
->dri_format
= orig_image
->dri_format
;
950 image
->format
= orig_image
->format
;
951 image
->modifier
= orig_image
->modifier
;
952 image
->offset
= orig_image
->offset
;
953 image
->width
= orig_image
->width
;
954 image
->height
= orig_image
->height
;
955 image
->pitch
= orig_image
->pitch
;
956 image
->tile_x
= orig_image
->tile_x
;
957 image
->tile_y
= orig_image
->tile_y
;
958 image
->has_depthstencil
= orig_image
->has_depthstencil
;
959 image
->data
= loaderPrivate
;
960 image
->dma_buf_imported
= orig_image
->dma_buf_imported
;
961 image
->aux_offset
= orig_image
->aux_offset
;
962 image
->aux_pitch
= orig_image
->aux_pitch
;
964 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
965 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
971 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
973 if (use
& __DRI_IMAGE_USE_CURSOR
) {
974 if (image
->width
!= 64 || image
->height
!= 64)
982 intel_create_image_from_names(__DRIscreen
*dri_screen
,
983 int width
, int height
, int fourcc
,
984 int *names
, int num_names
,
985 int *strides
, int *offsets
,
988 const struct intel_image_format
*f
= NULL
;
992 if (dri_screen
== NULL
|| names
== NULL
|| num_names
!= 1)
995 f
= intel_image_format_lookup(fourcc
);
999 image
= intel_create_image_from_name(dri_screen
, width
, height
,
1000 __DRI_IMAGE_FORMAT_NONE
,
1001 names
[0], strides
[0],
1007 image
->planar_format
= f
;
1008 for (i
= 0; i
< f
->nplanes
; i
++) {
1009 index
= f
->planes
[i
].buffer_index
;
1010 image
->offsets
[index
] = offsets
[index
];
1011 image
->strides
[index
] = strides
[index
];
1018 intel_create_image_from_fds_common(__DRIscreen
*dri_screen
,
1019 int width
, int height
, int fourcc
,
1020 uint64_t modifier
, int *fds
, int num_fds
,
1021 int *strides
, int *offsets
,
1022 void *loaderPrivate
)
1024 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1025 const struct intel_image_format
*f
;
1030 if (fds
== NULL
|| num_fds
< 1)
1033 f
= intel_image_format_lookup(fourcc
);
1037 if (modifier
!= DRM_FORMAT_MOD_INVALID
&&
1038 !modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1041 if (f
->nplanes
== 1)
1042 image
= intel_allocate_image(screen
, f
->planes
[0].dri_format
,
1045 image
= intel_allocate_image(screen
, __DRI_IMAGE_FORMAT_NONE
,
1051 image
->width
= width
;
1052 image
->height
= height
;
1053 image
->pitch
= strides
[0];
1055 image
->planar_format
= f
;
1057 if (modifier
!= DRM_FORMAT_MOD_INVALID
) {
1058 const struct isl_drm_modifier_info
*mod_info
=
1059 isl_drm_modifier_get_info(modifier
);
1060 uint32_t tiling
= isl_tiling_to_i915_tiling(mod_info
->tiling
);
1061 image
->bo
= brw_bo_gem_create_from_prime_tiled(screen
->bufmgr
, fds
[0],
1062 tiling
, strides
[0]);
1064 image
->bo
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[0]);
1067 if (image
->bo
== NULL
) {
1072 /* We only support all planes from the same bo.
1073 * brw_bo_gem_create_from_prime() should return the same pointer for all
1074 * fds received here */
1075 for (i
= 1; i
< num_fds
; i
++) {
1076 struct brw_bo
*aux
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[i
]);
1077 brw_bo_unreference(aux
);
1078 if (aux
!= image
->bo
) {
1079 brw_bo_unreference(image
->bo
);
1085 if (modifier
!= DRM_FORMAT_MOD_INVALID
)
1086 image
->modifier
= modifier
;
1088 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
1090 const struct isl_drm_modifier_info
*mod_info
=
1091 isl_drm_modifier_get_info(image
->modifier
);
1094 struct isl_surf surf
;
1095 for (i
= 0; i
< f
->nplanes
; i
++) {
1096 index
= f
->planes
[i
].buffer_index
;
1097 image
->offsets
[index
] = offsets
[index
];
1098 image
->strides
[index
] = strides
[index
];
1100 mesa_format format
= driImageFormatToGLFormat(f
->planes
[i
].dri_format
);
1101 /* The images we will create are actually based on the RGBA non-sRGB
1102 * version of the format.
1104 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1105 format
= _mesa_get_srgb_format_linear(format
);
1107 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
1108 .dim
= ISL_SURF_DIM_2D
,
1109 .format
= brw_isl_format_for_mesa_format(format
),
1110 .width
= image
->width
>> f
->planes
[i
].width_shift
,
1111 .height
= image
->height
>> f
->planes
[i
].height_shift
,
1116 .row_pitch
= strides
[index
],
1117 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
1118 ISL_SURF_USAGE_TEXTURE_BIT
|
1119 ISL_SURF_USAGE_STORAGE_BIT
,
1120 .tiling_flags
= (1 << mod_info
->tiling
));
1122 brw_bo_unreference(image
->bo
);
1127 const int end
= offsets
[index
] + surf
.size
;
1132 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
1133 /* Even though we initialize surf in the loop above, we know that
1134 * anything with CCS_E will have exactly one plane so surf is properly
1135 * initialized when we get here.
1137 assert(f
->nplanes
== 1);
1139 image
->aux_offset
= offsets
[1];
1140 image
->aux_pitch
= strides
[1];
1142 /* Scanout hardware requires that the CCS be placed after the main
1143 * surface in memory. We consider any CCS that is placed any earlier in
1144 * memory to be invalid and reject it.
1146 * At some point in the future, this restriction may be relaxed if the
1147 * hardware becomes less strict but we may need a new modifier for that.
1150 if (image
->aux_offset
< size
) {
1151 brw_bo_unreference(image
->bo
);
1156 struct isl_surf aux_surf
;
1157 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
,
1160 brw_bo_unreference(image
->bo
);
1165 image
->aux_size
= aux_surf
.size
;
1167 const int end
= image
->aux_offset
+ aux_surf
.size
;
1171 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
1174 /* Check that the requested image actually fits within the BO. 'size'
1175 * is already relative to the offsets, so we don't need to add that. */
1176 if (image
->bo
->size
== 0) {
1177 image
->bo
->size
= size
;
1178 } else if (size
> image
->bo
->size
) {
1179 brw_bo_unreference(image
->bo
);
1184 if (f
->nplanes
== 1) {
1185 image
->offset
= image
->offsets
[0];
1186 intel_image_warn_if_unaligned(image
, __func__
);
1193 intel_create_image_from_fds(__DRIscreen
*dri_screen
,
1194 int width
, int height
, int fourcc
,
1195 int *fds
, int num_fds
, int *strides
, int *offsets
,
1196 void *loaderPrivate
)
1198 return intel_create_image_from_fds_common(dri_screen
, width
, height
, fourcc
,
1199 DRM_FORMAT_MOD_INVALID
,
1200 fds
, num_fds
, strides
, offsets
,
1205 intel_create_image_from_dma_bufs2(__DRIscreen
*dri_screen
,
1206 int width
, int height
,
1207 int fourcc
, uint64_t modifier
,
1208 int *fds
, int num_fds
,
1209 int *strides
, int *offsets
,
1210 enum __DRIYUVColorSpace yuv_color_space
,
1211 enum __DRISampleRange sample_range
,
1212 enum __DRIChromaSiting horizontal_siting
,
1213 enum __DRIChromaSiting vertical_siting
,
1215 void *loaderPrivate
)
1218 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
1221 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1225 image
= intel_create_image_from_fds_common(dri_screen
, width
, height
,
1227 fds
, num_fds
, strides
, offsets
,
1231 * Invalid parameters and any inconsistencies between are assumed to be
1232 * checked by the caller. Therefore besides unsupported formats one can fail
1233 * only in allocation.
1236 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1240 image
->dma_buf_imported
= true;
1241 image
->yuv_color_space
= yuv_color_space
;
1242 image
->sample_range
= sample_range
;
1243 image
->horizontal_siting
= horizontal_siting
;
1244 image
->vertical_siting
= vertical_siting
;
1246 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1251 intel_create_image_from_dma_bufs(__DRIscreen
*dri_screen
,
1252 int width
, int height
, int fourcc
,
1253 int *fds
, int num_fds
,
1254 int *strides
, int *offsets
,
1255 enum __DRIYUVColorSpace yuv_color_space
,
1256 enum __DRISampleRange sample_range
,
1257 enum __DRIChromaSiting horizontal_siting
,
1258 enum __DRIChromaSiting vertical_siting
,
1260 void *loaderPrivate
)
1262 return intel_create_image_from_dma_bufs2(dri_screen
, width
, height
,
1263 fourcc
, DRM_FORMAT_MOD_INVALID
,
1264 fds
, num_fds
, strides
, offsets
,
1274 intel_image_format_is_supported(const struct gen_device_info
*devinfo
,
1275 const struct intel_image_format
*fmt
)
1277 /* Currently, all formats with an intel_image_format are available on all
1278 * platforms so there's really nothing to check there.
1282 if (fmt
->nplanes
== 1) {
1283 mesa_format format
= driImageFormatToGLFormat(fmt
->planes
[0].dri_format
);
1284 /* The images we will create are actually based on the RGBA non-sRGB
1285 * version of the format.
1287 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1288 format
= _mesa_get_srgb_format_linear(format
);
1289 enum isl_format isl_format
= brw_isl_format_for_mesa_format(format
);
1290 assert(isl_format_supports_rendering(devinfo
, isl_format
));
1298 intel_query_dma_buf_formats(__DRIscreen
*_screen
, int max
,
1299 int *formats
, int *count
)
1301 struct intel_screen
*screen
= _screen
->driverPrivate
;
1302 int num_formats
= 0, i
;
1304 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
1305 /* These two formats are valid DRI formats but do not exist in
1306 * drm_fourcc.h in the Linux kernel. We don't want to accidentally
1307 * advertise them through the EGL layer.
1309 if (intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SARGB8888
||
1310 intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SABGR8888
)
1313 if (!intel_image_format_is_supported(&screen
->devinfo
,
1314 &intel_image_formats
[i
]))
1321 formats
[num_formats
- 1] = intel_image_formats
[i
].fourcc
;
1322 if (num_formats
>= max
)
1326 *count
= num_formats
;
1331 intel_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1332 uint64_t *modifiers
,
1333 unsigned int *external_only
,
1336 struct intel_screen
*screen
= _screen
->driverPrivate
;
1337 const struct intel_image_format
*f
;
1338 int num_mods
= 0, i
;
1340 f
= intel_image_format_lookup(fourcc
);
1344 if (!intel_image_format_is_supported(&screen
->devinfo
, f
))
1347 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
1348 uint64_t modifier
= supported_modifiers
[i
].modifier
;
1349 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1356 modifiers
[num_mods
- 1] = modifier
;
1357 if (num_mods
>= max
)
1361 if (external_only
!= NULL
) {
1362 for (i
= 0; i
< num_mods
&& i
< max
; i
++) {
1363 if (f
->components
== __DRI_IMAGE_COMPONENTS_Y_U_V
||
1364 f
->components
== __DRI_IMAGE_COMPONENTS_Y_UV
||
1365 f
->components
== __DRI_IMAGE_COMPONENTS_Y_XUXV
) {
1366 external_only
[i
] = GL_TRUE
;
1369 external_only
[i
] = GL_FALSE
;
1379 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
1381 int width
, height
, offset
, stride
, size
, dri_format
;
1387 width
= parent
->width
;
1388 height
= parent
->height
;
1390 const struct intel_image_format
*f
= parent
->planar_format
;
1392 if (f
&& plane
< f
->nplanes
) {
1393 /* Use the planar format definition. */
1394 width
>>= f
->planes
[plane
].width_shift
;
1395 height
>>= f
->planes
[plane
].height_shift
;
1396 dri_format
= f
->planes
[plane
].dri_format
;
1397 int index
= f
->planes
[plane
].buffer_index
;
1398 offset
= parent
->offsets
[index
];
1399 stride
= parent
->strides
[index
];
1400 size
= height
* stride
;
1401 } else if (plane
== 0) {
1402 /* The only plane of a non-planar image: copy the parent definition
1404 dri_format
= parent
->dri_format
;
1405 offset
= parent
->offset
;
1406 stride
= parent
->pitch
;
1407 size
= height
* stride
;
1408 } else if (plane
== 1 && parent
->modifier
!= DRM_FORMAT_MOD_INVALID
&&
1409 isl_drm_modifier_has_aux(parent
->modifier
)) {
1410 /* Auxiliary plane */
1411 dri_format
= parent
->dri_format
;
1412 offset
= parent
->aux_offset
;
1413 stride
= parent
->aux_pitch
;
1414 size
= parent
->aux_size
;
1419 if (offset
+ size
> parent
->bo
->size
) {
1420 _mesa_warning(NULL
, "intel_from_planar: subimage out of bounds");
1424 image
= intel_allocate_image(parent
->screen
, dri_format
, loaderPrivate
);
1428 image
->bo
= parent
->bo
;
1429 brw_bo_reference(parent
->bo
);
1430 image
->modifier
= parent
->modifier
;
1432 image
->width
= width
;
1433 image
->height
= height
;
1434 image
->pitch
= stride
;
1435 image
->offset
= offset
;
1437 intel_image_warn_if_unaligned(image
, __func__
);
1442 static const __DRIimageExtension intelImageExtension
= {
1443 .base
= { __DRI_IMAGE
, 16 },
1445 .createImageFromName
= intel_create_image_from_name
,
1446 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
1447 .destroyImage
= intel_destroy_image
,
1448 .createImage
= intel_create_image
,
1449 .queryImage
= intel_query_image
,
1450 .dupImage
= intel_dup_image
,
1451 .validateUsage
= intel_validate_usage
,
1452 .createImageFromNames
= intel_create_image_from_names
,
1453 .fromPlanar
= intel_from_planar
,
1454 .createImageFromTexture
= intel_create_image_from_texture
,
1455 .createImageFromFds
= intel_create_image_from_fds
,
1456 .createImageFromDmaBufs
= intel_create_image_from_dma_bufs
,
1458 .getCapabilities
= NULL
,
1459 .mapImage
= intel_map_image
,
1460 .unmapImage
= intel_unmap_image
,
1461 .createImageWithModifiers
= intel_create_image_with_modifiers
,
1462 .createImageFromDmaBufs2
= intel_create_image_from_dma_bufs2
,
1463 .queryDmaBufFormats
= intel_query_dma_buf_formats
,
1464 .queryDmaBufModifiers
= intel_query_dma_buf_modifiers
,
1465 .queryDmaBufFormatModifierAttribs
= intel_query_format_modifier_attribs
,
1469 get_aperture_size(int fd
)
1471 struct drm_i915_gem_get_aperture aperture
;
1473 if (drmIoctl(fd
, DRM_IOCTL_I915_GEM_GET_APERTURE
, &aperture
) != 0)
1476 return aperture
.aper_size
;
1480 brw_query_renderer_integer(__DRIscreen
*dri_screen
,
1481 int param
, unsigned int *value
)
1483 const struct intel_screen
*const screen
=
1484 (struct intel_screen
*) dri_screen
->driverPrivate
;
1487 case __DRI2_RENDERER_VENDOR_ID
:
1490 case __DRI2_RENDERER_DEVICE_ID
:
1491 value
[0] = screen
->deviceID
;
1493 case __DRI2_RENDERER_ACCELERATED
:
1496 case __DRI2_RENDERER_VIDEO_MEMORY
: {
1497 /* Once a batch uses more than 75% of the maximum mappable size, we
1498 * assume that there's some fragmentation, and we start doing extra
1499 * flushing, etc. That's the big cliff apps will care about.
1501 const unsigned gpu_mappable_megabytes
=
1502 screen
->aperture_threshold
/ (1024 * 1024);
1504 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
1505 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
1507 if (system_memory_pages
<= 0 || system_page_size
<= 0)
1510 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
1511 * (uint64_t) system_page_size
;
1513 const unsigned system_memory_megabytes
=
1514 (unsigned) (system_memory_bytes
/ (1024 * 1024));
1516 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
1519 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
1522 case __DRI2_RENDERER_HAS_TEXTURE_3D
:
1525 case __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
:
1527 if (brw_hw_context_set_priority(screen
->bufmgr
,
1528 0, GEN_CONTEXT_HIGH_PRIORITY
) == 0)
1529 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH
;
1530 if (brw_hw_context_set_priority(screen
->bufmgr
,
1531 0, GEN_CONTEXT_LOW_PRIORITY
) == 0)
1532 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW
;
1533 /* reset to default last, just in case */
1534 if (brw_hw_context_set_priority(screen
->bufmgr
,
1535 0, GEN_CONTEXT_MEDIUM_PRIORITY
) == 0)
1536 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM
;
1538 case __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
:
1542 return driQueryRendererIntegerCommon(dri_screen
, param
, value
);
1549 brw_query_renderer_string(__DRIscreen
*dri_screen
,
1550 int param
, const char **value
)
1552 const struct intel_screen
*screen
=
1553 (struct intel_screen
*) dri_screen
->driverPrivate
;
1556 case __DRI2_RENDERER_VENDOR_ID
:
1557 value
[0] = brw_vendor_string
;
1559 case __DRI2_RENDERER_DEVICE_ID
:
1560 value
[0] = brw_get_renderer_string(screen
);
1570 brw_set_cache_funcs(__DRIscreen
*dri_screen
,
1571 __DRIblobCacheSet set
, __DRIblobCacheGet get
)
1573 const struct intel_screen
*const screen
=
1574 (struct intel_screen
*) dri_screen
->driverPrivate
;
1576 if (!screen
->disk_cache
)
1579 disk_cache_set_callbacks(screen
->disk_cache
, set
, get
);
1582 static const __DRI2rendererQueryExtension intelRendererQueryExtension
= {
1583 .base
= { __DRI2_RENDERER_QUERY
, 1 },
1585 .queryInteger
= brw_query_renderer_integer
,
1586 .queryString
= brw_query_renderer_string
1589 static const __DRIrobustnessExtension dri2Robustness
= {
1590 .base
= { __DRI2_ROBUSTNESS
, 1 }
1593 static const __DRI2blobExtension intelBlobExtension
= {
1594 .base
= { __DRI2_BLOB
, 1 },
1595 .set_cache_funcs
= brw_set_cache_funcs
1598 static const __DRImutableRenderBufferDriverExtension intelMutableRenderBufferExtension
= {
1599 .base
= { __DRI_MUTABLE_RENDER_BUFFER_DRIVER
, 1 },
1602 static const __DRIextension
*screenExtensions
[] = {
1603 &intelTexBufferExtension
.base
,
1604 &intelFenceExtension
.base
,
1605 &intelFlushExtension
.base
,
1606 &intelImageExtension
.base
,
1607 &intelRendererQueryExtension
.base
,
1608 &intelMutableRenderBufferExtension
.base
,
1609 &dri2ConfigQueryExtension
.base
,
1610 &dri2NoErrorExtension
.base
,
1611 &intelBlobExtension
.base
,
1615 static const __DRIextension
*intelRobustScreenExtensions
[] = {
1616 &intelTexBufferExtension
.base
,
1617 &intelFenceExtension
.base
,
1618 &intelFlushExtension
.base
,
1619 &intelImageExtension
.base
,
1620 &intelRendererQueryExtension
.base
,
1621 &intelMutableRenderBufferExtension
.base
,
1622 &dri2ConfigQueryExtension
.base
,
1623 &dri2Robustness
.base
,
1624 &dri2NoErrorExtension
.base
,
1625 &intelBlobExtension
.base
,
1630 intel_get_param(struct intel_screen
*screen
, int param
, int *value
)
1633 struct drm_i915_getparam gp
;
1635 memset(&gp
, 0, sizeof(gp
));
1639 if (drmIoctl(screen
->driScrnPriv
->fd
, DRM_IOCTL_I915_GETPARAM
, &gp
) == -1) {
1642 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
1649 intel_get_boolean(struct intel_screen
*screen
, int param
)
1652 return (intel_get_param(screen
, param
, &value
) == 0) && value
;
1656 intel_get_integer(struct intel_screen
*screen
, int param
)
1660 if (intel_get_param(screen
, param
, &value
) == 0)
1667 intelDestroyScreen(__DRIscreen
* sPriv
)
1669 struct intel_screen
*screen
= sPriv
->driverPrivate
;
1671 brw_bufmgr_destroy(screen
->bufmgr
);
1672 driDestroyOptionInfo(&screen
->optionCache
);
1674 disk_cache_destroy(screen
->disk_cache
);
1676 ralloc_free(screen
);
1677 sPriv
->driverPrivate
= NULL
;
1682 * Create a gl_framebuffer and attach it to __DRIdrawable::driverPrivate.
1684 *_This implements driDriverAPI::createNewDrawable, which the DRI layer calls
1685 * when creating a EGLSurface, GLXDrawable, or GLXPixmap. Despite the name,
1686 * this does not allocate GPU memory.
1689 intelCreateBuffer(__DRIscreen
*dri_screen
,
1690 __DRIdrawable
* driDrawPriv
,
1691 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
1693 struct intel_renderbuffer
*rb
;
1694 struct intel_screen
*screen
= (struct intel_screen
*)
1695 dri_screen
->driverPrivate
;
1696 mesa_format rgbFormat
;
1697 unsigned num_samples
=
1698 intel_quantize_num_samples(screen
, mesaVis
->samples
);
1703 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
1707 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
1709 if (screen
->winsys_msaa_samples_override
!= -1) {
1710 num_samples
= screen
->winsys_msaa_samples_override
;
1711 fb
->Visual
.samples
= num_samples
;
1714 if (mesaVis
->redBits
== 10 && mesaVis
->alphaBits
> 0) {
1715 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10A2_UNORM
1716 : MESA_FORMAT_R10G10B10A2_UNORM
;
1717 } else if (mesaVis
->redBits
== 10) {
1718 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10X2_UNORM
1719 : MESA_FORMAT_R10G10B10X2_UNORM
;
1720 } else if (mesaVis
->redBits
== 5) {
1721 rgbFormat
= mesaVis
->redMask
== 0x1f ? MESA_FORMAT_R5G6B5_UNORM
1722 : MESA_FORMAT_B5G6R5_UNORM
;
1723 } else if (mesaVis
->sRGBCapable
) {
1724 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1725 : MESA_FORMAT_B8G8R8A8_SRGB
;
1726 } else if (mesaVis
->alphaBits
== 0) {
1727 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8X8_UNORM
1728 : MESA_FORMAT_B8G8R8X8_UNORM
;
1730 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1731 : MESA_FORMAT_B8G8R8A8_SRGB
;
1732 fb
->Visual
.sRGBCapable
= true;
1735 /* mesaVis->sRGBCapable was set, user is asking for sRGB */
1736 bool srgb_cap_set
= mesaVis
->redBits
>= 8 && mesaVis
->sRGBCapable
;
1738 /* setup the hardware-based renderbuffers */
1739 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1740 _mesa_attach_and_own_rb(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
1741 rb
->need_srgb
= srgb_cap_set
;
1743 if (mesaVis
->doubleBufferMode
) {
1744 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1745 _mesa_attach_and_own_rb(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
1746 rb
->need_srgb
= srgb_cap_set
;
1750 * Assert here that the gl_config has an expected depth/stencil bit
1751 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
1752 * which constructs the advertised configs.)
1754 if (mesaVis
->depthBits
== 24) {
1755 assert(mesaVis
->stencilBits
== 8);
1757 if (screen
->devinfo
.has_hiz_and_separate_stencil
) {
1758 rb
= intel_create_private_renderbuffer(screen
,
1759 MESA_FORMAT_Z24_UNORM_X8_UINT
,
1761 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1762 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_S_UINT8
,
1764 _mesa_attach_and_own_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1767 * Use combined depth/stencil. Note that the renderbuffer is
1768 * attached to two attachment points.
1770 rb
= intel_create_private_renderbuffer(screen
,
1771 MESA_FORMAT_Z24_UNORM_S8_UINT
,
1773 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1774 _mesa_attach_and_reference_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1777 else if (mesaVis
->depthBits
== 16) {
1778 assert(mesaVis
->stencilBits
== 0);
1779 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_Z_UNORM16
,
1781 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1784 assert(mesaVis
->depthBits
== 0);
1785 assert(mesaVis
->stencilBits
== 0);
1788 /* now add any/all software-based renderbuffers we may need */
1789 _swrast_add_soft_renderbuffers(fb
,
1790 false, /* never sw color */
1791 false, /* never sw depth */
1792 false, /* never sw stencil */
1793 mesaVis
->accumRedBits
> 0,
1794 false, /* never sw alpha */
1795 false /* never sw aux */ );
1796 driDrawPriv
->driverPrivate
= fb
;
1802 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
1804 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
1806 _mesa_reference_framebuffer(&fb
, NULL
);
1810 intel_cs_timestamp_frequency(struct intel_screen
*screen
)
1812 /* We shouldn't need to update gen_device_info.timestamp_frequency prior to
1813 * gen10, PCI-id is enough to figure it out.
1815 assert(screen
->devinfo
.gen
>= 10);
1819 ret
= intel_get_param(screen
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
,
1823 "Kernel 4.15 required to read the CS timestamp frequency.\n");
1827 screen
->devinfo
.timestamp_frequency
= freq
;
1831 intel_detect_sseu(struct intel_screen
*screen
)
1833 assert(screen
->devinfo
.gen
>= 8);
1836 screen
->subslice_total
= -1;
1837 screen
->eu_total
= -1;
1839 ret
= intel_get_param(screen
, I915_PARAM_SUBSLICE_TOTAL
,
1840 &screen
->subslice_total
);
1841 if (ret
< 0 && ret
!= -EINVAL
)
1844 ret
= intel_get_param(screen
,
1845 I915_PARAM_EU_TOTAL
, &screen
->eu_total
);
1846 if (ret
< 0 && ret
!= -EINVAL
)
1849 /* Without this information, we cannot get the right Braswell brandstrings,
1850 * and we have to use conservative numbers for GPGPU on many platforms, but
1851 * otherwise, things will just work.
1853 if (screen
->subslice_total
< 1 || screen
->eu_total
< 1)
1855 "Kernel 4.1 required to properly query GPU properties.\n");
1860 screen
->subslice_total
= -1;
1861 screen
->eu_total
= -1;
1862 _mesa_warning(NULL
, "Failed to query GPU properties (%s).\n", strerror(-ret
));
1866 intel_init_bufmgr(struct intel_screen
*screen
)
1868 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
1870 if (getenv("INTEL_NO_HW") != NULL
)
1871 screen
->no_hw
= true;
1873 screen
->bufmgr
= brw_bufmgr_init(&screen
->devinfo
, dri_screen
->fd
);
1874 if (screen
->bufmgr
== NULL
) {
1875 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1876 __func__
, __LINE__
);
1880 if (!intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_NO_RELOC
)) {
1881 fprintf(stderr
, "[%s: %u] Kernel 3.9 required.\n", __func__
, __LINE__
);
1889 intel_detect_swizzling(struct intel_screen
*screen
)
1891 uint32_t tiling
= I915_TILING_X
;
1892 uint32_t swizzle_mode
= 0;
1893 struct brw_bo
*buffer
=
1894 brw_bo_alloc_tiled(screen
->bufmgr
, "swizzle test", 32768,
1895 BRW_MEMZONE_OTHER
, tiling
, 512, 0);
1899 brw_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1900 brw_bo_unreference(buffer
);
1902 return swizzle_mode
!= I915_BIT_6_SWIZZLE_NONE
;
1906 intel_detect_timestamp(struct intel_screen
*screen
)
1908 uint64_t dummy
= 0, last
= 0;
1909 int upper
, lower
, loops
;
1911 /* On 64bit systems, some old kernels trigger a hw bug resulting in the
1912 * TIMESTAMP register being shifted and the low 32bits always zero.
1914 * More recent kernels offer an interface to read the full 36bits
1917 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
| 1, &dummy
) == 0)
1920 /* Determine if we have a 32bit or 64bit kernel by inspecting the
1921 * upper 32bits for a rapidly changing timestamp.
1923 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &last
))
1927 for (loops
= 0; loops
< 10; loops
++) {
1928 /* The TIMESTAMP should change every 80ns, so several round trips
1929 * through the kernel should be enough to advance it.
1931 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &dummy
))
1934 upper
+= (dummy
>> 32) != (last
>> 32);
1935 if (upper
> 1) /* beware 32bit counter overflow */
1936 return 2; /* upper dword holds the low 32bits of the timestamp */
1938 lower
+= (dummy
& 0xffffffff) != (last
& 0xffffffff);
1940 return 1; /* timestamp is unshifted */
1945 /* No advancement? No timestamp! */
1950 * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer.
1952 * Some combinations of hardware and kernel versions allow this feature,
1953 * while others don't. Instead of trying to enumerate every case, just
1954 * try and write a register and see if works.
1957 intel_detect_pipelined_register(struct intel_screen
*screen
,
1958 int reg
, uint32_t expected_value
, bool reset
)
1963 struct brw_bo
*results
, *bo
;
1965 uint32_t offset
= 0;
1967 bool success
= false;
1969 /* Create a zero'ed temporary buffer for reading our results */
1970 results
= brw_bo_alloc(screen
->bufmgr
, "registers", 4096, BRW_MEMZONE_OTHER
);
1971 if (results
== NULL
)
1974 bo
= brw_bo_alloc(screen
->bufmgr
, "batchbuffer", 4096, BRW_MEMZONE_OTHER
);
1978 map
= brw_bo_map(NULL
, bo
, MAP_WRITE
);
1984 /* Write the register. */
1985 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
1987 *batch
++ = expected_value
;
1989 /* Save the register's value back to the buffer. */
1990 *batch
++ = MI_STORE_REGISTER_MEM
| (3 - 2);
1992 struct drm_i915_gem_relocation_entry reloc
= {
1993 .offset
= (char *) batch
- (char *) map
,
1994 .delta
= offset
* sizeof(uint32_t),
1995 .target_handle
= results
->gem_handle
,
1996 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
1997 .write_domain
= I915_GEM_DOMAIN_INSTRUCTION
,
1999 *batch
++ = reloc
.presumed_offset
+ reloc
.delta
;
2001 /* And afterwards clear the register */
2003 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
2008 *batch
++ = MI_BATCH_BUFFER_END
;
2010 struct drm_i915_gem_exec_object2 exec_objects
[2] = {
2012 .handle
= results
->gem_handle
,
2015 .handle
= bo
->gem_handle
,
2016 .relocation_count
= 1,
2017 .relocs_ptr
= (uintptr_t) &reloc
,
2021 struct drm_i915_gem_execbuffer2 execbuf
= {
2022 .buffers_ptr
= (uintptr_t) exec_objects
,
2024 .batch_len
= ALIGN((char *) batch
- (char *) map
, 8),
2025 .flags
= I915_EXEC_RENDER
,
2028 /* Don't bother with error checking - if the execbuf fails, the
2029 * value won't be written and we'll just report that there's no access.
2031 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2032 drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GEM_EXECBUFFER2
, &execbuf
);
2034 /* Check whether the value got written. */
2035 void *results_map
= brw_bo_map(NULL
, results
, MAP_READ
);
2037 success
= *((uint32_t *)results_map
+ offset
) == expected_value
;
2038 brw_bo_unmap(results
);
2042 brw_bo_unreference(bo
);
2044 brw_bo_unreference(results
);
2050 intel_detect_pipelined_so(struct intel_screen
*screen
)
2052 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2054 /* Supposedly, Broadwell just works. */
2055 if (devinfo
->gen
>= 8)
2058 if (devinfo
->gen
<= 6)
2061 /* See the big explanation about command parser versions below */
2062 if (screen
->cmd_parser_version
>= (devinfo
->is_haswell
? 7 : 2))
2065 /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the
2066 * statistics registers), and we already reset it to zero before using it.
2068 return intel_detect_pipelined_register(screen
,
2069 GEN7_SO_WRITE_OFFSET(0),
2075 * Return array of MSAA modes supported by the hardware. The array is
2076 * zero-terminated and sorted in decreasing order.
2079 intel_supported_msaa_modes(const struct intel_screen
*screen
)
2081 static const int gen9_modes
[] = {16, 8, 4, 2, 0, -1};
2082 static const int gen8_modes
[] = {8, 4, 2, 0, -1};
2083 static const int gen7_modes
[] = {8, 4, 0, -1};
2084 static const int gen6_modes
[] = {4, 0, -1};
2085 static const int gen4_modes
[] = {0, -1};
2087 if (screen
->devinfo
.gen
>= 9) {
2089 } else if (screen
->devinfo
.gen
>= 8) {
2091 } else if (screen
->devinfo
.gen
>= 7) {
2093 } else if (screen
->devinfo
.gen
== 6) {
2101 intel_loader_get_cap(const __DRIscreen
*dri_screen
, enum dri_loader_cap cap
)
2103 if (dri_screen
->dri2
.loader
&& dri_screen
->dri2
.loader
->base
.version
>= 4 &&
2104 dri_screen
->dri2
.loader
->getCapability
)
2105 return dri_screen
->dri2
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2107 if (dri_screen
->image
.loader
&& dri_screen
->image
.loader
->base
.version
>= 2 &&
2108 dri_screen
->image
.loader
->getCapability
)
2109 return dri_screen
->image
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2114 static __DRIconfig
**
2115 intel_screen_make_configs(__DRIscreen
*dri_screen
)
2117 static const mesa_format formats
[] = {
2118 MESA_FORMAT_B5G6R5_UNORM
,
2119 MESA_FORMAT_B8G8R8A8_UNORM
,
2120 MESA_FORMAT_B8G8R8X8_UNORM
,
2122 MESA_FORMAT_B8G8R8A8_SRGB
,
2124 /* For 10 bpc, 30 bit depth framebuffers. */
2125 MESA_FORMAT_B10G10R10A2_UNORM
,
2126 MESA_FORMAT_B10G10R10X2_UNORM
,
2128 /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
2129 * Likewise for RGBX and BGRX. Otherwise, the GLX client and the GLX
2130 * server may disagree on which format the GLXFBConfig represents,
2131 * resulting in swapped color channels.
2133 * The problem, as of 2017-05-30:
2134 * When matching a GLXFBConfig to a __DRIconfig, GLX ignores the channel
2135 * order and chooses the first __DRIconfig with the expected channel
2136 * sizes. Specifically, GLX compares the GLXFBConfig's and __DRIconfig's
2137 * __DRI_ATTRIB_{CHANNEL}_SIZE but ignores __DRI_ATTRIB_{CHANNEL}_MASK.
2139 * EGL does not suffer from this problem. It correctly compares the
2140 * channel masks when matching EGLConfig to __DRIconfig.
2143 /* Required by Android, for HAL_PIXEL_FORMAT_RGBA_8888. */
2144 MESA_FORMAT_R8G8B8A8_UNORM
,
2146 /* Required by Android, for HAL_PIXEL_FORMAT_RGBX_8888. */
2147 MESA_FORMAT_R8G8B8X8_UNORM
,
2149 MESA_FORMAT_R8G8B8A8_SRGB
,
2152 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
2153 static const GLenum back_buffer_modes
[] = {
2154 __DRI_ATTRIB_SWAP_UNDEFINED
, __DRI_ATTRIB_SWAP_NONE
2157 static const uint8_t singlesample_samples
[1] = {0};
2159 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2160 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2161 uint8_t depth_bits
[4], stencil_bits
[4];
2162 __DRIconfig
**configs
= NULL
;
2164 /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
2165 unsigned num_formats
;
2166 if (intel_loader_get_cap(dri_screen
, DRI_LOADER_CAP_RGBA_ORDERING
))
2167 num_formats
= ARRAY_SIZE(formats
);
2169 num_formats
= ARRAY_SIZE(formats
) - 3; /* all - RGBA_ORDERING formats */
2171 /* Shall we expose 10 bpc formats? */
2172 bool allow_rgb10_configs
= driQueryOptionb(&screen
->optionCache
,
2173 "allow_rgb10_configs");
2175 /* Generate singlesample configs, each without accumulation buffer
2176 * and with EGL_MUTABLE_RENDER_BUFFER_BIT_KHR.
2178 for (unsigned i
= 0; i
< num_formats
; i
++) {
2179 __DRIconfig
**new_configs
;
2180 int num_depth_stencil_bits
= 2;
2182 if (!allow_rgb10_configs
&&
2183 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2184 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2187 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
2188 * buffer that has a different number of bits per pixel than the color
2189 * buffer, gen >= 6 supports this.
2192 stencil_bits
[0] = 0;
2194 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2196 stencil_bits
[1] = 0;
2197 if (devinfo
->gen
>= 6) {
2199 stencil_bits
[2] = 8;
2200 num_depth_stencil_bits
= 3;
2204 stencil_bits
[1] = 8;
2207 new_configs
= driCreateConfigs(formats
[i
],
2210 num_depth_stencil_bits
,
2211 back_buffer_modes
, 2,
2212 singlesample_samples
, 1,
2214 /*mutable_render_buffer*/ true);
2215 configs
= driConcatConfigs(configs
, new_configs
);
2218 /* Generate the minimum possible set of configs that include an
2219 * accumulation buffer.
2221 for (unsigned i
= 0; i
< num_formats
; i
++) {
2222 __DRIconfig
**new_configs
;
2224 if (!allow_rgb10_configs
&&
2225 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2226 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2229 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2231 stencil_bits
[0] = 0;
2234 stencil_bits
[0] = 8;
2237 new_configs
= driCreateConfigs(formats
[i
],
2238 depth_bits
, stencil_bits
, 1,
2239 back_buffer_modes
, 1,
2240 singlesample_samples
, 1,
2241 true, false, false);
2242 configs
= driConcatConfigs(configs
, new_configs
);
2245 /* Generate multisample configs.
2247 * This loop breaks early, and hence is a no-op, on gen < 6.
2249 * Multisample configs must follow the singlesample configs in order to
2250 * work around an X server bug present in 1.12. The X server chooses to
2251 * associate the first listed RGBA888-Z24S8 config, regardless of its
2252 * sample count, with the 32-bit depth visual used for compositing.
2254 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
2255 * supported. Singlebuffer configs are not supported because no one wants
2258 for (unsigned i
= 0; i
< num_formats
; i
++) {
2259 if (devinfo
->gen
< 6)
2262 if (!allow_rgb10_configs
&&
2263 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2264 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2267 __DRIconfig
**new_configs
;
2268 const int num_depth_stencil_bits
= 2;
2269 int num_msaa_modes
= 0;
2270 const uint8_t *multisample_samples
= NULL
;
2273 stencil_bits
[0] = 0;
2275 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2277 stencil_bits
[1] = 0;
2280 stencil_bits
[1] = 8;
2283 if (devinfo
->gen
>= 9) {
2284 static const uint8_t multisample_samples_gen9
[] = {2, 4, 8, 16};
2285 multisample_samples
= multisample_samples_gen9
;
2286 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen9
);
2287 } else if (devinfo
->gen
== 8) {
2288 static const uint8_t multisample_samples_gen8
[] = {2, 4, 8};
2289 multisample_samples
= multisample_samples_gen8
;
2290 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen8
);
2291 } else if (devinfo
->gen
== 7) {
2292 static const uint8_t multisample_samples_gen7
[] = {4, 8};
2293 multisample_samples
= multisample_samples_gen7
;
2294 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen7
);
2295 } else if (devinfo
->gen
== 6) {
2296 static const uint8_t multisample_samples_gen6
[] = {4};
2297 multisample_samples
= multisample_samples_gen6
;
2298 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen6
);
2301 new_configs
= driCreateConfigs(formats
[i
],
2304 num_depth_stencil_bits
,
2305 back_buffer_modes
, 1,
2306 multisample_samples
,
2308 false, false, false);
2309 configs
= driConcatConfigs(configs
, new_configs
);
2312 if (configs
== NULL
) {
2313 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
2322 set_max_gl_versions(struct intel_screen
*screen
)
2324 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2325 const bool has_astc
= screen
->devinfo
.gen
>= 9;
2327 switch (screen
->devinfo
.gen
) {
2332 dri_screen
->max_gl_core_version
= 45;
2333 dri_screen
->max_gl_compat_version
= 30;
2334 dri_screen
->max_gl_es1_version
= 11;
2335 dri_screen
->max_gl_es2_version
= has_astc
? 32 : 31;
2338 dri_screen
->max_gl_core_version
= 33;
2339 if (can_do_pipelined_register_writes(screen
)) {
2340 dri_screen
->max_gl_core_version
= 42;
2341 if (screen
->devinfo
.is_haswell
&& can_do_compute_dispatch(screen
))
2342 dri_screen
->max_gl_core_version
= 43;
2343 if (screen
->devinfo
.is_haswell
&& can_do_mi_math_and_lrr(screen
))
2344 dri_screen
->max_gl_core_version
= 45;
2346 dri_screen
->max_gl_compat_version
= 30;
2347 dri_screen
->max_gl_es1_version
= 11;
2348 dri_screen
->max_gl_es2_version
= screen
->devinfo
.is_haswell
? 31 : 30;
2351 dri_screen
->max_gl_core_version
= 33;
2352 dri_screen
->max_gl_compat_version
= 30;
2353 dri_screen
->max_gl_es1_version
= 11;
2354 dri_screen
->max_gl_es2_version
= 30;
2358 dri_screen
->max_gl_core_version
= 0;
2359 dri_screen
->max_gl_compat_version
= 21;
2360 dri_screen
->max_gl_es1_version
= 11;
2361 dri_screen
->max_gl_es2_version
= 20;
2364 unreachable("unrecognized intel_screen::gen");
2369 * Return the revision (generally the revid field of the PCI header) of the
2373 intel_device_get_revision(int fd
)
2375 struct drm_i915_getparam gp
;
2379 memset(&gp
, 0, sizeof(gp
));
2380 gp
.param
= I915_PARAM_REVISION
;
2381 gp
.value
= &revision
;
2383 ret
= drmCommandWriteRead(fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
2391 shader_debug_log_mesa(void *data
, const char *fmt
, ...)
2393 struct brw_context
*brw
= (struct brw_context
*)data
;
2396 va_start(args
, fmt
);
2398 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
2399 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2400 MESA_DEBUG_TYPE_OTHER
,
2401 MESA_DEBUG_SEVERITY_NOTIFICATION
, fmt
, args
);
2406 shader_perf_log_mesa(void *data
, const char *fmt
, ...)
2408 struct brw_context
*brw
= (struct brw_context
*)data
;
2411 va_start(args
, fmt
);
2413 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
)) {
2415 va_copy(args_copy
, args
);
2416 vfprintf(stderr
, fmt
, args_copy
);
2420 if (brw
->perf_debug
) {
2422 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
2423 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2424 MESA_DEBUG_TYPE_PERFORMANCE
,
2425 MESA_DEBUG_SEVERITY_MEDIUM
, fmt
, args
);
2431 * This is the driver specific part of the createNewScreen entry point.
2432 * Called when using DRI2.
2434 * \return the struct gl_config supported by this driver
2437 __DRIconfig
**intelInitScreen2(__DRIscreen
*dri_screen
)
2439 struct intel_screen
*screen
;
2441 if (dri_screen
->image
.loader
) {
2442 } else if (dri_screen
->dri2
.loader
->base
.version
<= 2 ||
2443 dri_screen
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
2445 "\nERROR! DRI2 loader with getBuffersWithFormat() "
2446 "support required\n");
2450 /* Allocate the private area */
2451 screen
= rzalloc(NULL
, struct intel_screen
);
2453 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
2456 /* parse information in __driConfigOptions */
2457 driOptionCache options
;
2458 memset(&options
, 0, sizeof(options
));
2460 driParseOptionInfo(&options
, brw_config_options
.xml
);
2461 driParseConfigFiles(&screen
->optionCache
, &options
, dri_screen
->myNum
,
2463 driDestroyOptionCache(&options
);
2465 screen
->driScrnPriv
= dri_screen
;
2466 dri_screen
->driverPrivate
= (void *) screen
;
2468 screen
->deviceID
= gen_get_pci_device_id_override();
2469 if (screen
->deviceID
< 0)
2470 screen
->deviceID
= intel_get_integer(screen
, I915_PARAM_CHIPSET_ID
);
2472 screen
->no_hw
= true;
2474 if (!gen_get_device_info(screen
->deviceID
, &screen
->devinfo
))
2477 if (!intel_init_bufmgr(screen
))
2480 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2482 brw_process_intel_debug_variable();
2484 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && devinfo
->gen
< 7) {
2486 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
2487 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
2490 if (intel_get_integer(screen
, I915_PARAM_MMAP_GTT_VERSION
) >= 1) {
2491 /* Theorectically unlimited! At least for individual objects...
2493 * Currently the entire (global) address space for all GTT maps is
2494 * limited to 64bits. That is all objects on the system that are
2495 * setup for GTT mmapping must fit within 64bits. An attempt to use
2496 * one that exceeds the limit with fail in brw_bo_map_gtt().
2498 * Long before we hit that limit, we will be practically limited by
2499 * that any single object must fit in physical memory (RAM). The upper
2500 * limit on the CPU's address space is currently 48bits (Skylake), of
2501 * which only 39bits can be physical memory. (The GPU itself also has
2502 * a 48bit addressable virtual space.) We can fit over 32 million
2503 * objects of the current maximum allocable size before running out
2506 screen
->max_gtt_map_object_size
= UINT64_MAX
;
2508 /* Estimate the size of the mappable aperture into the GTT. There's an
2509 * ioctl to get the whole GTT size, but not one to get the mappable subset.
2510 * It turns out it's basically always 256MB, though some ancient hardware
2513 uint32_t gtt_size
= 256 * 1024 * 1024;
2515 /* We don't want to map two objects such that a memcpy between them would
2516 * just fault one mapping in and then the other over and over forever. So
2517 * we would need to divide the GTT size by 2. Additionally, some GTT is
2518 * taken up by things like the framebuffer and the ringbuffer and such, so
2519 * be more conservative.
2521 screen
->max_gtt_map_object_size
= gtt_size
/ 4;
2524 screen
->aperture_threshold
= get_aperture_size(dri_screen
->fd
) * 3 / 4;
2526 screen
->hw_has_swizzling
= intel_detect_swizzling(screen
);
2527 screen
->hw_has_timestamp
= intel_detect_timestamp(screen
);
2529 isl_device_init(&screen
->isl_dev
, &screen
->devinfo
,
2530 screen
->hw_has_swizzling
);
2532 if (devinfo
->gen
>= 10)
2533 intel_cs_timestamp_frequency(screen
);
2535 /* GENs prior to 8 do not support EU/Subslice info */
2536 if (devinfo
->gen
>= 8) {
2537 intel_detect_sseu(screen
);
2538 } else if (devinfo
->gen
== 7) {
2539 screen
->subslice_total
= 1 << (devinfo
->gt
- 1);
2542 /* Gen7-7.5 kernel requirements / command parser saga:
2545 * Haswell and Baytrail cannot use any privileged batchbuffer features.
2547 * Ivybridge has aliasing PPGTT on by default, which accidentally marks
2548 * all batches secure, allowing them to use any feature with no checking.
2549 * This is effectively equivalent to a command parser version of
2550 * \infinity - everything is possible.
2552 * The command parser does not exist, and querying the version will
2556 * The kernel enables the command parser by default, for systems with
2557 * aliasing PPGTT enabled (Ivybridge and Haswell). However, the
2558 * hardware checker is still enabled, so Haswell and Baytrail cannot
2561 * Ivybridge goes from "everything is possible" to "only what the
2562 * command parser allows" (if the user boots with i915.cmd_parser=0,
2563 * then everything is possible again). We can only safely use features
2564 * allowed by the supported command parser version.
2566 * Annoyingly, I915_PARAM_CMD_PARSER_VERSION reports the static version
2567 * implemented by the kernel, even if it's turned off. So, checking
2568 * for version > 0 does not mean that you can write registers. We have
2569 * to try it and see. The version does, however, indicate the age of
2572 * Instead of matching the hardware checker's behavior of converting
2573 * privileged commands to MI_NOOP, it makes execbuf2 start returning
2574 * -EINVAL, making it dangerous to try and use privileged features.
2576 * Effective command parser versions:
2577 * - Haswell: 0 (reporting 1, writes don't work)
2578 * - Baytrail: 0 (reporting 1, writes don't work)
2579 * - Ivybridge: 1 (enabled) or infinite (disabled)
2582 * Baytrail aliasing PPGTT is enabled, making it like Ivybridge:
2583 * effectively version 1 (enabled) or infinite (disabled).
2585 * - v3.19: f1f55cc0556031c8ee3fe99dae7251e78b9b653b
2586 * Command parser v2 supports predicate writes.
2588 * - Haswell: 0 (reporting 1, writes don't work)
2589 * - Baytrail: 2 (enabled) or infinite (disabled)
2590 * - Ivybridge: 2 (enabled) or infinite (disabled)
2592 * So version >= 2 is enough to know that Ivybridge and Baytrail
2593 * will work. Haswell still can't do anything.
2595 * - v4.0: Version 3 happened. Largely not relevant.
2597 * - v4.1: 6702cf16e0ba8b0129f5aa1b6609d4e9c70bc13b
2598 * L3 config registers are properly saved and restored as part
2599 * of the hardware context. We can approximately detect this point
2600 * in time by checking if I915_PARAM_REVISION is recognized - it
2601 * landed in a later commit, but in the same release cycle.
2603 * - v4.2: 245054a1fe33c06ad233e0d58a27ec7b64db9284
2604 * Command parser finally gains secure batch promotion. On Haswell,
2605 * the hardware checker gets disabled, which finally allows it to do
2606 * privileged commands.
2608 * I915_PARAM_CMD_PARSER_VERSION reports 3. Effective versions:
2609 * - Haswell: 3 (enabled) or 0 (disabled)
2610 * - Baytrail: 3 (enabled) or infinite (disabled)
2611 * - Ivybridge: 3 (enabled) or infinite (disabled)
2613 * Unfortunately, detecting this point in time is tricky, because
2614 * no version bump happened when this important change occurred.
2615 * On Haswell, if we can write any register, then the kernel is at
2616 * least this new, and we can start trusting the version number.
2618 * - v4.4: 2bbe6bbb0dc94fd4ce287bdac9e1bd184e23057b and
2619 * Command parser reaches version 4, allowing access to Haswell
2620 * atomic scratch and chicken3 registers. If version >= 4, we know
2621 * the kernel is new enough to support privileged features on all
2622 * hardware. However, the user might have disabled it...and the
2623 * kernel will still report version 4. So we still have to guess
2626 * - v4.4: 7b9748cb513a6bef4af87b79f0da3ff7e8b56cd8
2627 * Command parser v5 whitelists indirect compute shader dispatch
2628 * registers, needed for OpenGL 4.3 and later.
2631 * Command parser v7 lets us use MI_MATH on Haswell.
2633 * Additionally, the kernel begins reporting version 0 when
2634 * the command parser is disabled, allowing us to skip the
2635 * guess-and-check step on Haswell. Unfortunately, this also
2636 * means that we can no longer use it as an indicator of the
2637 * age of the kernel.
2639 if (intel_get_param(screen
, I915_PARAM_CMD_PARSER_VERSION
,
2640 &screen
->cmd_parser_version
) < 0) {
2641 /* Command parser does not exist - getparam is unrecognized */
2642 screen
->cmd_parser_version
= 0;
2645 /* Kernel 4.13 retuired for exec object capture */
2646 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_CAPTURE
)) {
2647 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_CAPTURE
;
2650 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_BATCH_FIRST
)) {
2651 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_BATCH_FIRST
;
2654 if (!intel_detect_pipelined_so(screen
)) {
2655 /* We can't do anything, so the effective version is 0. */
2656 screen
->cmd_parser_version
= 0;
2658 screen
->kernel_features
|= KERNEL_ALLOWS_SOL_OFFSET_WRITES
;
2661 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 2)
2662 screen
->kernel_features
|= KERNEL_ALLOWS_PREDICATE_WRITES
;
2664 /* Haswell requires command parser version 4 in order to have L3
2665 * atomic scratch1 and chicken3 bits
2667 if (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 4) {
2668 screen
->kernel_features
|=
2669 KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3
;
2672 /* Haswell requires command parser version 6 in order to write to the
2673 * MI_MATH GPR registers, and version 7 in order to use
2674 * MI_LOAD_REGISTER_REG (which all users of MI_MATH use).
2676 if (devinfo
->gen
>= 8 ||
2677 (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 7)) {
2678 screen
->kernel_features
|= KERNEL_ALLOWS_MI_MATH_AND_LRR
;
2681 /* Gen7 needs at least command parser version 5 to support compute */
2682 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 5)
2683 screen
->kernel_features
|= KERNEL_ALLOWS_COMPUTE_DISPATCH
;
2685 if (intel_get_boolean(screen
, I915_PARAM_HAS_CONTEXT_ISOLATION
))
2686 screen
->kernel_features
|= KERNEL_ALLOWS_CONTEXT_ISOLATION
;
2688 const char *force_msaa
= getenv("INTEL_FORCE_MSAA");
2690 screen
->winsys_msaa_samples_override
=
2691 intel_quantize_num_samples(screen
, atoi(force_msaa
));
2692 printf("Forcing winsys sample count to %d\n",
2693 screen
->winsys_msaa_samples_override
);
2695 screen
->winsys_msaa_samples_override
= -1;
2698 set_max_gl_versions(screen
);
2700 /* Notification of GPU resets requires hardware contexts and a kernel new
2701 * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is
2702 * supported, calling it with a context of 0 will either generate EPERM or
2703 * no error. If the ioctl is not supported, it always generate EINVAL.
2704 * Use this to determine whether to advertise the __DRI2_ROBUSTNESS
2705 * extension to the loader.
2707 * Don't even try on pre-Gen6, since we don't attempt to use contexts there.
2709 if (devinfo
->gen
>= 6) {
2710 struct drm_i915_reset_stats stats
;
2711 memset(&stats
, 0, sizeof(stats
));
2713 const int ret
= drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GET_RESET_STATS
, &stats
);
2715 screen
->has_context_reset_notification
=
2716 (ret
!= -1 || errno
!= EINVAL
);
2719 dri_screen
->extensions
= !screen
->has_context_reset_notification
2720 ? screenExtensions
: intelRobustScreenExtensions
;
2722 screen
->compiler
= brw_compiler_create(screen
, devinfo
);
2723 screen
->compiler
->shader_debug_log
= shader_debug_log_mesa
;
2724 screen
->compiler
->shader_perf_log
= shader_perf_log_mesa
;
2726 /* Changing the meaning of constant buffer pointers from a dynamic state
2727 * offset to an absolute address is only safe if the kernel isolates other
2728 * contexts from our changes.
2730 screen
->compiler
->constant_buffer_0_is_relative
= devinfo
->gen
< 8 ||
2731 !(screen
->kernel_features
& KERNEL_ALLOWS_CONTEXT_ISOLATION
);
2733 screen
->compiler
->supports_pull_constants
= true;
2735 screen
->has_exec_fence
=
2736 intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_FENCE
);
2738 intel_screen_init_surface_formats(screen
);
2740 if (INTEL_DEBUG
& (DEBUG_BATCH
| DEBUG_SUBMIT
)) {
2741 unsigned int caps
= intel_get_integer(screen
, I915_PARAM_HAS_SCHEDULER
);
2743 fprintf(stderr
, "Kernel scheduler detected: %08x\n", caps
);
2744 if (caps
& I915_SCHEDULER_CAP_PRIORITY
)
2745 fprintf(stderr
, " - User priority sorting enabled\n");
2746 if (caps
& I915_SCHEDULER_CAP_PREEMPTION
)
2747 fprintf(stderr
, " - Preemption enabled\n");
2751 brw_disk_cache_init(screen
);
2753 return (const __DRIconfig
**) intel_screen_make_configs(dri_screen
);
2756 struct intel_buffer
{
2761 static __DRIbuffer
*
2762 intelAllocateBuffer(__DRIscreen
*dri_screen
,
2763 unsigned attachment
, unsigned format
,
2764 int width
, int height
)
2766 struct intel_buffer
*intelBuffer
;
2767 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2769 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
2770 attachment
== __DRI_BUFFER_BACK_LEFT
);
2772 intelBuffer
= calloc(1, sizeof *intelBuffer
);
2773 if (intelBuffer
== NULL
)
2776 /* The front and back buffers are color buffers, which are X tiled. GEN9+
2777 * supports Y tiled and compressed buffers, but there is no way to plumb that
2778 * through to here. */
2780 int cpp
= format
/ 8;
2781 intelBuffer
->bo
= brw_bo_alloc_tiled_2d(screen
->bufmgr
,
2782 "intelAllocateBuffer",
2787 I915_TILING_X
, &pitch
,
2790 if (intelBuffer
->bo
== NULL
) {
2795 brw_bo_flink(intelBuffer
->bo
, &intelBuffer
->base
.name
);
2797 intelBuffer
->base
.attachment
= attachment
;
2798 intelBuffer
->base
.cpp
= cpp
;
2799 intelBuffer
->base
.pitch
= pitch
;
2801 return &intelBuffer
->base
;
2805 intelReleaseBuffer(__DRIscreen
*dri_screen
, __DRIbuffer
*buffer
)
2807 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
2809 brw_bo_unreference(intelBuffer
->bo
);
2813 static const struct __DriverAPIRec brw_driver_api
= {
2814 .InitScreen
= intelInitScreen2
,
2815 .DestroyScreen
= intelDestroyScreen
,
2816 .CreateContext
= brwCreateContext
,
2817 .DestroyContext
= intelDestroyContext
,
2818 .CreateBuffer
= intelCreateBuffer
,
2819 .DestroyBuffer
= intelDestroyBuffer
,
2820 .MakeCurrent
= intelMakeCurrent
,
2821 .UnbindContext
= intelUnbindContext
,
2822 .AllocateBuffer
= intelAllocateBuffer
,
2823 .ReleaseBuffer
= intelReleaseBuffer
2826 static const struct __DRIDriverVtableExtensionRec brw_vtable
= {
2827 .base
= { __DRI_DRIVER_VTABLE
, 1 },
2828 .vtable
= &brw_driver_api
,
2831 static const __DRIextension
*brw_driver_extensions
[] = {
2832 &driCoreExtension
.base
,
2833 &driImageDriverExtension
.base
,
2834 &driDRI2Extension
.base
,
2836 &brw_config_options
.base
,
2840 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
2842 globalDriverAPI
= &brw_driver_api
;
2844 return brw_driver_extensions
;