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 { __DRI_IMAGE_FOURCC_AYUV
, __DRI_IMAGE_COMPONENTS_AYUV
, 1,
290 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
292 /* For YUYV and UYVY buffers, we set up two overlapping DRI images
293 * and treat them as planar buffers in the compositors.
294 * Plane 0 is GR88 and samples YU or YV pairs and places Y into
295 * the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
296 * clusters and places pairs and places U into the G component and
297 * V into A. This lets the texture sampler interpolate the Y
298 * components correctly when sampling from plane 0, and interpolate
299 * U and V correctly when sampling from plane 1. */
300 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
301 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
302 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
303 { __DRI_IMAGE_FOURCC_UYVY
, __DRI_IMAGE_COMPONENTS_Y_UXVX
, 2,
304 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
305 { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } }
308 static const struct {
311 } supported_modifiers
[] = {
312 { .modifier
= DRM_FORMAT_MOD_LINEAR
, .since_gen
= 1 },
313 { .modifier
= I915_FORMAT_MOD_X_TILED
, .since_gen
= 1 },
314 { .modifier
= I915_FORMAT_MOD_Y_TILED
, .since_gen
= 6 },
315 { .modifier
= I915_FORMAT_MOD_Y_TILED_CCS
, .since_gen
= 9 },
319 modifier_is_supported(const struct gen_device_info
*devinfo
,
320 const struct intel_image_format
*fmt
, int dri_format
,
323 const struct isl_drm_modifier_info
*modinfo
=
324 isl_drm_modifier_get_info(modifier
);
327 /* ISL had better know about the modifier */
331 if (modinfo
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
332 /* If INTEL_DEBUG=norbc is set, don't support any CCS_E modifiers */
333 if (unlikely(INTEL_DEBUG
& DEBUG_NO_RBC
))
336 /* CCS_E is not supported for planar images */
337 if (fmt
&& fmt
->nplanes
> 1)
341 assert(dri_format
== 0);
342 dri_format
= fmt
->planes
[0].dri_format
;
345 mesa_format format
= driImageFormatToGLFormat(dri_format
);
346 /* Whether or not we support compression is based on the RGBA non-sRGB
347 * version of the format.
349 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
350 format
= _mesa_get_srgb_format_linear(format
);
351 if (!isl_format_supports_ccs_e(devinfo
,
352 brw_isl_format_for_mesa_format(format
)))
356 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
357 if (supported_modifiers
[i
].modifier
!= modifier
)
360 return supported_modifiers
[i
].since_gen
<= devinfo
->gen
;
367 tiling_to_modifier(uint32_t tiling
)
369 static const uint64_t map
[] = {
370 [I915_TILING_NONE
] = DRM_FORMAT_MOD_LINEAR
,
371 [I915_TILING_X
] = I915_FORMAT_MOD_X_TILED
,
372 [I915_TILING_Y
] = I915_FORMAT_MOD_Y_TILED
,
375 assert(tiling
< ARRAY_SIZE(map
));
381 intel_image_warn_if_unaligned(__DRIimage
*image
, const char *func
)
383 uint32_t tiling
, swizzle
;
384 brw_bo_get_tiling(image
->bo
, &tiling
, &swizzle
);
386 if (tiling
!= I915_TILING_NONE
&& (image
->offset
& 0xfff)) {
387 _mesa_warning(NULL
, "%s: offset 0x%08x not on tile boundary",
388 func
, image
->offset
);
392 static const struct intel_image_format
*
393 intel_image_format_lookup(int fourcc
)
395 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
396 if (intel_image_formats
[i
].fourcc
== fourcc
)
397 return &intel_image_formats
[i
];
404 intel_image_get_fourcc(__DRIimage
*image
, int *fourcc
)
406 if (image
->planar_format
) {
407 *fourcc
= image
->planar_format
->fourcc
;
411 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
412 if (intel_image_formats
[i
].planes
[0].dri_format
== image
->dri_format
) {
413 *fourcc
= intel_image_formats
[i
].fourcc
;
421 intel_allocate_image(struct intel_screen
*screen
, int dri_format
,
426 image
= calloc(1, sizeof *image
);
430 image
->screen
= screen
;
431 image
->dri_format
= dri_format
;
434 image
->format
= driImageFormatToGLFormat(dri_format
);
435 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
436 image
->format
== MESA_FORMAT_NONE
) {
441 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
442 image
->data
= loaderPrivate
;
448 * Sets up a DRIImage structure to point to a slice out of a miptree.
451 intel_setup_image_from_mipmap_tree(struct brw_context
*brw
, __DRIimage
*image
,
452 struct intel_mipmap_tree
*mt
, GLuint level
,
455 intel_miptree_make_shareable(brw
, mt
);
457 intel_miptree_check_level_layer(mt
, level
, zoffset
);
459 image
->width
= minify(mt
->surf
.phys_level0_sa
.width
,
460 level
- mt
->first_level
);
461 image
->height
= minify(mt
->surf
.phys_level0_sa
.height
,
462 level
- mt
->first_level
);
463 image
->pitch
= mt
->surf
.row_pitch_B
;
465 image
->offset
= intel_miptree_get_tile_offsets(mt
, level
, zoffset
,
469 brw_bo_unreference(image
->bo
);
471 brw_bo_reference(mt
->bo
);
475 intel_create_image_from_name(__DRIscreen
*dri_screen
,
476 int width
, int height
, int format
,
477 int name
, int pitch
, void *loaderPrivate
)
479 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
483 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
487 if (image
->format
== MESA_FORMAT_NONE
)
490 cpp
= _mesa_get_format_bytes(image
->format
);
492 image
->width
= width
;
493 image
->height
= height
;
494 image
->pitch
= pitch
* cpp
;
495 image
->bo
= brw_bo_gem_create_from_name(screen
->bufmgr
, "image",
501 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
507 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
508 int renderbuffer
, void *loaderPrivate
)
511 struct brw_context
*brw
= context
->driverPrivate
;
512 struct gl_context
*ctx
= &brw
->ctx
;
513 struct gl_renderbuffer
*rb
;
514 struct intel_renderbuffer
*irb
;
516 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
518 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
522 irb
= intel_renderbuffer(rb
);
523 intel_miptree_make_shareable(brw
, irb
->mt
);
524 image
= calloc(1, sizeof *image
);
528 image
->internal_format
= rb
->InternalFormat
;
529 image
->format
= rb
->Format
;
530 image
->modifier
= tiling_to_modifier(
531 isl_tiling_to_i915_tiling(irb
->mt
->surf
.tiling
));
533 image
->data
= loaderPrivate
;
534 brw_bo_unreference(image
->bo
);
535 image
->bo
= irb
->mt
->bo
;
536 brw_bo_reference(irb
->mt
->bo
);
537 image
->width
= rb
->Width
;
538 image
->height
= rb
->Height
;
539 image
->pitch
= irb
->mt
->surf
.row_pitch_B
;
540 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
541 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
543 rb
->NeedsFinishRenderTexture
= true;
548 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
549 unsigned texture
, int zoffset
,
555 struct brw_context
*brw
= context
->driverPrivate
;
556 struct gl_texture_object
*obj
;
557 struct intel_texture_object
*iobj
;
560 obj
= _mesa_lookup_texture(&brw
->ctx
, texture
);
561 if (!obj
|| obj
->Target
!= target
) {
562 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
566 if (target
== GL_TEXTURE_CUBE_MAP
)
569 _mesa_test_texobj_completeness(&brw
->ctx
, obj
);
570 iobj
= intel_texture_object(obj
);
571 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
572 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
576 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
577 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
581 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
582 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
585 image
= calloc(1, sizeof *image
);
587 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
591 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
592 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
593 image
->modifier
= tiling_to_modifier(
594 isl_tiling_to_i915_tiling(iobj
->mt
->surf
.tiling
));
595 image
->data
= loaderPrivate
;
596 intel_setup_image_from_mipmap_tree(brw
, image
, iobj
->mt
, level
, zoffset
);
597 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
598 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
599 image
->planar_format
= iobj
->planar_format
;
600 if (image
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
601 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
606 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
611 intel_destroy_image(__DRIimage
*image
)
613 brw_bo_unreference(image
->bo
);
617 enum modifier_priority
{
618 MODIFIER_PRIORITY_INVALID
= 0,
619 MODIFIER_PRIORITY_LINEAR
,
622 MODIFIER_PRIORITY_Y_CCS
,
625 const uint64_t priority_to_modifier
[] = {
626 [MODIFIER_PRIORITY_INVALID
] = DRM_FORMAT_MOD_INVALID
,
627 [MODIFIER_PRIORITY_LINEAR
] = DRM_FORMAT_MOD_LINEAR
,
628 [MODIFIER_PRIORITY_X
] = I915_FORMAT_MOD_X_TILED
,
629 [MODIFIER_PRIORITY_Y
] = I915_FORMAT_MOD_Y_TILED
,
630 [MODIFIER_PRIORITY_Y_CCS
] = I915_FORMAT_MOD_Y_TILED_CCS
,
634 select_best_modifier(struct gen_device_info
*devinfo
,
636 const uint64_t *modifiers
,
637 const unsigned count
)
639 enum modifier_priority prio
= MODIFIER_PRIORITY_INVALID
;
641 for (int i
= 0; i
< count
; i
++) {
642 if (!modifier_is_supported(devinfo
, NULL
, dri_format
, modifiers
[i
]))
645 switch (modifiers
[i
]) {
646 case I915_FORMAT_MOD_Y_TILED_CCS
:
647 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y_CCS
);
649 case I915_FORMAT_MOD_Y_TILED
:
650 prio
= MAX2(prio
, MODIFIER_PRIORITY_Y
);
652 case I915_FORMAT_MOD_X_TILED
:
653 prio
= MAX2(prio
, MODIFIER_PRIORITY_X
);
655 case DRM_FORMAT_MOD_LINEAR
:
656 prio
= MAX2(prio
, MODIFIER_PRIORITY_LINEAR
);
658 case DRM_FORMAT_MOD_INVALID
:
664 return priority_to_modifier
[prio
];
668 intel_create_image_common(__DRIscreen
*dri_screen
,
669 int width
, int height
, int format
,
671 const uint64_t *modifiers
,
676 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
677 uint64_t modifier
= DRM_FORMAT_MOD_INVALID
;
680 /* Callers of this may specify a modifier, or a dri usage, but not both. The
681 * newer modifier interface deprecates the older usage flags newer modifier
682 * interface deprecates the older usage flags.
684 assert(!(use
&& count
));
686 if (use
& __DRI_IMAGE_USE_CURSOR
) {
687 if (width
!= 64 || height
!= 64)
689 modifier
= DRM_FORMAT_MOD_LINEAR
;
692 if (use
& __DRI_IMAGE_USE_LINEAR
)
693 modifier
= DRM_FORMAT_MOD_LINEAR
;
695 if (modifier
== DRM_FORMAT_MOD_INVALID
) {
697 /* User requested specific modifiers */
698 modifier
= select_best_modifier(&screen
->devinfo
, format
,
700 if (modifier
== DRM_FORMAT_MOD_INVALID
)
703 /* Historically, X-tiled was the default, and so lack of modifier means
706 modifier
= I915_FORMAT_MOD_X_TILED
;
710 image
= intel_allocate_image(screen
, format
, loaderPrivate
);
714 const struct isl_drm_modifier_info
*mod_info
=
715 isl_drm_modifier_get_info(modifier
);
717 struct isl_surf surf
;
718 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
719 .dim
= ISL_SURF_DIM_2D
,
720 .format
= brw_isl_format_for_mesa_format(image
->format
),
727 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
728 ISL_SURF_USAGE_TEXTURE_BIT
|
729 ISL_SURF_USAGE_STORAGE_BIT
,
730 .tiling_flags
= (1 << mod_info
->tiling
));
737 struct isl_surf aux_surf
;
738 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
739 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
, 0);
745 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
749 /* We request that the bufmgr zero the buffer for us for two reasons:
751 * 1) If a buffer gets re-used from the pool, we don't want to leak random
752 * garbage from our process to some other.
754 * 2) For images with CCS_E, we want to ensure that the CCS starts off in
755 * a valid state. A CCS value of 0 indicates that the given block is
756 * in the pass-through state which is what we want.
758 image
->bo
= brw_bo_alloc_tiled(screen
->bufmgr
, "image",
759 surf
.size_B
+ aux_surf
.size_B
,
761 isl_tiling_to_i915_tiling(mod_info
->tiling
),
762 surf
.row_pitch_B
, BO_ALLOC_ZEROED
);
763 if (image
->bo
== NULL
) {
767 image
->width
= width
;
768 image
->height
= height
;
769 image
->pitch
= surf
.row_pitch_B
;
770 image
->modifier
= modifier
;
772 if (aux_surf
.size_B
) {
773 image
->aux_offset
= surf
.size_B
;
774 image
->aux_pitch
= aux_surf
.row_pitch_B
;
775 image
->aux_size
= aux_surf
.size_B
;
782 intel_create_image(__DRIscreen
*dri_screen
,
783 int width
, int height
, int format
,
787 return intel_create_image_common(dri_screen
, width
, height
, format
, use
, NULL
, 0,
792 intel_map_image(__DRIcontext
*context
, __DRIimage
*image
,
793 int x0
, int y0
, int width
, int height
,
794 unsigned int flags
, int *stride
, void **map_info
)
796 struct brw_context
*brw
= NULL
;
797 struct brw_bo
*bo
= NULL
;
798 void *raw_data
= NULL
;
803 if (!context
|| !image
|| !stride
|| !map_info
|| *map_info
)
806 if (x0
< 0 || x0
>= image
->width
|| width
> image
->width
- x0
)
809 if (y0
< 0 || y0
>= image
->height
|| height
> image
->height
- y0
)
812 if (flags
& MAP_INTERNAL_MASK
)
815 brw
= context
->driverPrivate
;
821 /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */
822 raw_data
= brw_bo_map(brw
, bo
, flags
);
826 _mesa_get_format_block_size(image
->format
, &pix_w
, &pix_h
);
827 pix_bytes
= _mesa_get_format_bytes(image
->format
);
831 assert(pix_bytes
> 0);
833 raw_data
+= (x0
/ pix_w
) * pix_bytes
+ (y0
/ pix_h
) * image
->pitch
;
835 brw_bo_reference(bo
);
837 *stride
= image
->pitch
;
844 intel_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *map_info
)
846 struct brw_bo
*bo
= map_info
;
849 brw_bo_unreference(bo
);
853 intel_create_image_with_modifiers(__DRIscreen
*dri_screen
,
854 int width
, int height
, int format
,
855 const uint64_t *modifiers
,
856 const unsigned count
,
859 return intel_create_image_common(dri_screen
, width
, height
, format
, 0,
860 modifiers
, count
, loaderPrivate
);
864 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
867 case __DRI_IMAGE_ATTRIB_STRIDE
:
868 *value
= image
->pitch
;
870 case __DRI_IMAGE_ATTRIB_HANDLE
:
871 *value
= brw_bo_export_gem_handle(image
->bo
);
873 case __DRI_IMAGE_ATTRIB_NAME
:
874 return !brw_bo_flink(image
->bo
, (uint32_t *) value
);
875 case __DRI_IMAGE_ATTRIB_FORMAT
:
876 *value
= image
->dri_format
;
878 case __DRI_IMAGE_ATTRIB_WIDTH
:
879 *value
= image
->width
;
881 case __DRI_IMAGE_ATTRIB_HEIGHT
:
882 *value
= image
->height
;
884 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
885 if (image
->planar_format
== NULL
)
887 *value
= image
->planar_format
->components
;
889 case __DRI_IMAGE_ATTRIB_FD
:
890 return !brw_bo_gem_export_to_prime(image
->bo
, value
);
891 case __DRI_IMAGE_ATTRIB_FOURCC
:
892 return intel_image_get_fourcc(image
, value
);
893 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
894 if (isl_drm_modifier_has_aux(image
->modifier
)) {
895 assert(!image
->planar_format
|| image
->planar_format
->nplanes
== 1);
897 } else if (image
->planar_format
) {
898 *value
= image
->planar_format
->nplanes
;
903 case __DRI_IMAGE_ATTRIB_OFFSET
:
904 *value
= image
->offset
;
906 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
907 *value
= (image
->modifier
& 0xffffffff);
909 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
910 *value
= ((image
->modifier
>> 32) & 0xffffffff);
919 intel_query_format_modifier_attribs(__DRIscreen
*dri_screen
,
920 uint32_t fourcc
, uint64_t modifier
,
921 int attrib
, uint64_t *value
)
923 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
924 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
926 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
930 case __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT
:
931 *value
= isl_drm_modifier_has_aux(modifier
) ? 2 : f
->nplanes
;
940 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
944 image
= calloc(1, sizeof *image
);
948 brw_bo_reference(orig_image
->bo
);
949 image
->bo
= orig_image
->bo
;
950 image
->internal_format
= orig_image
->internal_format
;
951 image
->planar_format
= orig_image
->planar_format
;
952 image
->dri_format
= orig_image
->dri_format
;
953 image
->format
= orig_image
->format
;
954 image
->modifier
= orig_image
->modifier
;
955 image
->offset
= orig_image
->offset
;
956 image
->width
= orig_image
->width
;
957 image
->height
= orig_image
->height
;
958 image
->pitch
= orig_image
->pitch
;
959 image
->tile_x
= orig_image
->tile_x
;
960 image
->tile_y
= orig_image
->tile_y
;
961 image
->has_depthstencil
= orig_image
->has_depthstencil
;
962 image
->data
= loaderPrivate
;
963 image
->aux_offset
= orig_image
->aux_offset
;
964 image
->aux_pitch
= orig_image
->aux_pitch
;
966 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
967 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
973 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
975 if (use
& __DRI_IMAGE_USE_CURSOR
) {
976 if (image
->width
!= 64 || image
->height
!= 64)
984 intel_create_image_from_names(__DRIscreen
*dri_screen
,
985 int width
, int height
, int fourcc
,
986 int *names
, int num_names
,
987 int *strides
, int *offsets
,
990 const struct intel_image_format
*f
= NULL
;
994 if (dri_screen
== NULL
|| names
== NULL
|| num_names
!= 1)
997 f
= intel_image_format_lookup(fourcc
);
1001 image
= intel_create_image_from_name(dri_screen
, width
, height
,
1002 __DRI_IMAGE_FORMAT_NONE
,
1003 names
[0], strides
[0],
1009 image
->planar_format
= f
;
1010 for (i
= 0; i
< f
->nplanes
; i
++) {
1011 index
= f
->planes
[i
].buffer_index
;
1012 image
->offsets
[index
] = offsets
[index
];
1013 image
->strides
[index
] = strides
[index
];
1020 intel_create_image_from_fds_common(__DRIscreen
*dri_screen
,
1021 int width
, int height
, int fourcc
,
1022 uint64_t modifier
, int *fds
, int num_fds
,
1023 int *strides
, int *offsets
,
1024 void *loaderPrivate
)
1026 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1027 const struct intel_image_format
*f
;
1032 if (fds
== NULL
|| num_fds
< 1)
1035 f
= intel_image_format_lookup(fourcc
);
1039 if (modifier
!= DRM_FORMAT_MOD_INVALID
&&
1040 !modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1043 if (f
->nplanes
== 1)
1044 image
= intel_allocate_image(screen
, f
->planes
[0].dri_format
,
1047 image
= intel_allocate_image(screen
, __DRI_IMAGE_FORMAT_NONE
,
1053 image
->width
= width
;
1054 image
->height
= height
;
1055 image
->pitch
= strides
[0];
1057 image
->planar_format
= f
;
1059 if (modifier
!= DRM_FORMAT_MOD_INVALID
) {
1060 const struct isl_drm_modifier_info
*mod_info
=
1061 isl_drm_modifier_get_info(modifier
);
1062 uint32_t tiling
= isl_tiling_to_i915_tiling(mod_info
->tiling
);
1063 image
->bo
= brw_bo_gem_create_from_prime_tiled(screen
->bufmgr
, fds
[0],
1064 tiling
, strides
[0]);
1066 image
->bo
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[0]);
1069 if (image
->bo
== NULL
) {
1074 /* We only support all planes from the same bo.
1075 * brw_bo_gem_create_from_prime() should return the same pointer for all
1076 * fds received here */
1077 for (i
= 1; i
< num_fds
; i
++) {
1078 struct brw_bo
*aux
= brw_bo_gem_create_from_prime(screen
->bufmgr
, fds
[i
]);
1079 brw_bo_unreference(aux
);
1080 if (aux
!= image
->bo
) {
1081 brw_bo_unreference(image
->bo
);
1087 if (modifier
!= DRM_FORMAT_MOD_INVALID
)
1088 image
->modifier
= modifier
;
1090 image
->modifier
= tiling_to_modifier(image
->bo
->tiling_mode
);
1092 const struct isl_drm_modifier_info
*mod_info
=
1093 isl_drm_modifier_get_info(image
->modifier
);
1096 struct isl_surf surf
;
1097 for (i
= 0; i
< f
->nplanes
; i
++) {
1098 index
= f
->planes
[i
].buffer_index
;
1099 image
->offsets
[index
] = offsets
[index
];
1100 image
->strides
[index
] = strides
[index
];
1102 mesa_format format
= driImageFormatToGLFormat(f
->planes
[i
].dri_format
);
1103 /* The images we will create are actually based on the RGBA non-sRGB
1104 * version of the format.
1106 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1107 format
= _mesa_get_srgb_format_linear(format
);
1109 ok
= isl_surf_init(&screen
->isl_dev
, &surf
,
1110 .dim
= ISL_SURF_DIM_2D
,
1111 .format
= brw_isl_format_for_mesa_format(format
),
1112 .width
= image
->width
>> f
->planes
[i
].width_shift
,
1113 .height
= image
->height
>> f
->planes
[i
].height_shift
,
1118 .row_pitch_B
= strides
[index
],
1119 .usage
= ISL_SURF_USAGE_RENDER_TARGET_BIT
|
1120 ISL_SURF_USAGE_TEXTURE_BIT
|
1121 ISL_SURF_USAGE_STORAGE_BIT
,
1122 .tiling_flags
= (1 << mod_info
->tiling
));
1124 brw_bo_unreference(image
->bo
);
1129 const int end
= offsets
[index
] + surf
.size_B
;
1134 if (mod_info
->aux_usage
== ISL_AUX_USAGE_CCS_E
) {
1135 /* Even though we initialize surf in the loop above, we know that
1136 * anything with CCS_E will have exactly one plane so surf is properly
1137 * initialized when we get here.
1139 assert(f
->nplanes
== 1);
1141 image
->aux_offset
= offsets
[1];
1142 image
->aux_pitch
= strides
[1];
1144 /* Scanout hardware requires that the CCS be placed after the main
1145 * surface in memory. We consider any CCS that is placed any earlier in
1146 * memory to be invalid and reject it.
1148 * At some point in the future, this restriction may be relaxed if the
1149 * hardware becomes less strict but we may need a new modifier for that.
1152 if (image
->aux_offset
< size
) {
1153 brw_bo_unreference(image
->bo
);
1158 struct isl_surf aux_surf
;
1159 ok
= isl_surf_get_ccs_surf(&screen
->isl_dev
, &surf
, &aux_surf
,
1162 brw_bo_unreference(image
->bo
);
1167 image
->aux_size
= aux_surf
.size_B
;
1169 const int end
= image
->aux_offset
+ aux_surf
.size_B
;
1173 assert(mod_info
->aux_usage
== ISL_AUX_USAGE_NONE
);
1176 /* Check that the requested image actually fits within the BO. 'size'
1177 * is already relative to the offsets, so we don't need to add that. */
1178 if (image
->bo
->size
== 0) {
1179 image
->bo
->size
= size
;
1180 } else if (size
> image
->bo
->size
) {
1181 brw_bo_unreference(image
->bo
);
1186 if (f
->nplanes
== 1) {
1187 image
->offset
= image
->offsets
[0];
1188 intel_image_warn_if_unaligned(image
, __func__
);
1195 intel_create_image_from_fds(__DRIscreen
*dri_screen
,
1196 int width
, int height
, int fourcc
,
1197 int *fds
, int num_fds
, int *strides
, int *offsets
,
1198 void *loaderPrivate
)
1200 return intel_create_image_from_fds_common(dri_screen
, width
, height
, fourcc
,
1201 DRM_FORMAT_MOD_INVALID
,
1202 fds
, num_fds
, strides
, offsets
,
1207 intel_create_image_from_dma_bufs2(__DRIscreen
*dri_screen
,
1208 int width
, int height
,
1209 int fourcc
, uint64_t modifier
,
1210 int *fds
, int num_fds
,
1211 int *strides
, int *offsets
,
1212 enum __DRIYUVColorSpace yuv_color_space
,
1213 enum __DRISampleRange sample_range
,
1214 enum __DRIChromaSiting horizontal_siting
,
1215 enum __DRIChromaSiting vertical_siting
,
1217 void *loaderPrivate
)
1220 const struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
1223 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1227 image
= intel_create_image_from_fds_common(dri_screen
, width
, height
,
1229 fds
, num_fds
, strides
, offsets
,
1233 * Invalid parameters and any inconsistencies between are assumed to be
1234 * checked by the caller. Therefore besides unsupported formats one can fail
1235 * only in allocation.
1238 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1242 image
->yuv_color_space
= yuv_color_space
;
1243 image
->sample_range
= sample_range
;
1244 image
->horizontal_siting
= horizontal_siting
;
1245 image
->vertical_siting
= vertical_siting
;
1247 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1252 intel_create_image_from_dma_bufs(__DRIscreen
*dri_screen
,
1253 int width
, int height
, int fourcc
,
1254 int *fds
, int num_fds
,
1255 int *strides
, int *offsets
,
1256 enum __DRIYUVColorSpace yuv_color_space
,
1257 enum __DRISampleRange sample_range
,
1258 enum __DRIChromaSiting horizontal_siting
,
1259 enum __DRIChromaSiting vertical_siting
,
1261 void *loaderPrivate
)
1263 return intel_create_image_from_dma_bufs2(dri_screen
, width
, height
,
1264 fourcc
, DRM_FORMAT_MOD_INVALID
,
1265 fds
, num_fds
, strides
, offsets
,
1275 intel_image_format_is_supported(const struct gen_device_info
*devinfo
,
1276 const struct intel_image_format
*fmt
)
1278 /* Currently, all formats with an intel_image_format are available on all
1279 * platforms so there's really nothing to check there.
1283 if (fmt
->nplanes
== 1) {
1284 mesa_format format
= driImageFormatToGLFormat(fmt
->planes
[0].dri_format
);
1285 /* The images we will create are actually based on the RGBA non-sRGB
1286 * version of the format.
1288 format
= _mesa_format_fallback_rgbx_to_rgba(format
);
1289 format
= _mesa_get_srgb_format_linear(format
);
1290 enum isl_format isl_format
= brw_isl_format_for_mesa_format(format
);
1291 assert(isl_format_supports_rendering(devinfo
, isl_format
));
1299 intel_query_dma_buf_formats(__DRIscreen
*_screen
, int max
,
1300 int *formats
, int *count
)
1302 struct intel_screen
*screen
= _screen
->driverPrivate
;
1303 int num_formats
= 0, i
;
1305 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
1306 /* These two formats are valid DRI formats but do not exist in
1307 * drm_fourcc.h in the Linux kernel. We don't want to accidentally
1308 * advertise them through the EGL layer.
1310 if (intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SARGB8888
||
1311 intel_image_formats
[i
].fourcc
== __DRI_IMAGE_FOURCC_SABGR8888
)
1314 if (!intel_image_format_is_supported(&screen
->devinfo
,
1315 &intel_image_formats
[i
]))
1322 formats
[num_formats
- 1] = intel_image_formats
[i
].fourcc
;
1323 if (num_formats
>= max
)
1327 *count
= num_formats
;
1332 intel_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1333 uint64_t *modifiers
,
1334 unsigned int *external_only
,
1337 struct intel_screen
*screen
= _screen
->driverPrivate
;
1338 const struct intel_image_format
*f
;
1339 int num_mods
= 0, i
;
1341 f
= intel_image_format_lookup(fourcc
);
1345 if (!intel_image_format_is_supported(&screen
->devinfo
, f
))
1348 for (i
= 0; i
< ARRAY_SIZE(supported_modifiers
); i
++) {
1349 uint64_t modifier
= supported_modifiers
[i
].modifier
;
1350 if (!modifier_is_supported(&screen
->devinfo
, f
, 0, modifier
))
1357 modifiers
[num_mods
- 1] = modifier
;
1358 if (num_mods
>= max
)
1362 if (external_only
!= NULL
) {
1363 for (i
= 0; i
< num_mods
&& i
< max
; i
++) {
1364 if (f
->components
== __DRI_IMAGE_COMPONENTS_Y_U_V
||
1365 f
->components
== __DRI_IMAGE_COMPONENTS_Y_UV
||
1366 f
->components
== __DRI_IMAGE_COMPONENTS_Y_XUXV
) {
1367 external_only
[i
] = GL_TRUE
;
1370 external_only
[i
] = GL_FALSE
;
1380 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
1382 int width
, height
, offset
, stride
, size
, dri_format
;
1388 width
= parent
->width
;
1389 height
= parent
->height
;
1391 const struct intel_image_format
*f
= parent
->planar_format
;
1393 if (f
&& plane
< f
->nplanes
) {
1394 /* Use the planar format definition. */
1395 width
>>= f
->planes
[plane
].width_shift
;
1396 height
>>= f
->planes
[plane
].height_shift
;
1397 dri_format
= f
->planes
[plane
].dri_format
;
1398 int index
= f
->planes
[plane
].buffer_index
;
1399 offset
= parent
->offsets
[index
];
1400 stride
= parent
->strides
[index
];
1401 size
= height
* stride
;
1402 } else if (plane
== 0) {
1403 /* The only plane of a non-planar image: copy the parent definition
1405 dri_format
= parent
->dri_format
;
1406 offset
= parent
->offset
;
1407 stride
= parent
->pitch
;
1408 size
= height
* stride
;
1409 } else if (plane
== 1 && parent
->modifier
!= DRM_FORMAT_MOD_INVALID
&&
1410 isl_drm_modifier_has_aux(parent
->modifier
)) {
1411 /* Auxiliary plane */
1412 dri_format
= parent
->dri_format
;
1413 offset
= parent
->aux_offset
;
1414 stride
= parent
->aux_pitch
;
1415 size
= parent
->aux_size
;
1420 if (offset
+ size
> parent
->bo
->size
) {
1421 _mesa_warning(NULL
, "intel_from_planar: subimage out of bounds");
1425 image
= intel_allocate_image(parent
->screen
, dri_format
, loaderPrivate
);
1429 image
->bo
= parent
->bo
;
1430 brw_bo_reference(parent
->bo
);
1431 image
->modifier
= parent
->modifier
;
1433 image
->width
= width
;
1434 image
->height
= height
;
1435 image
->pitch
= stride
;
1436 image
->offset
= offset
;
1438 intel_image_warn_if_unaligned(image
, __func__
);
1443 static const __DRIimageExtension intelImageExtension
= {
1444 .base
= { __DRI_IMAGE
, 16 },
1446 .createImageFromName
= intel_create_image_from_name
,
1447 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
1448 .destroyImage
= intel_destroy_image
,
1449 .createImage
= intel_create_image
,
1450 .queryImage
= intel_query_image
,
1451 .dupImage
= intel_dup_image
,
1452 .validateUsage
= intel_validate_usage
,
1453 .createImageFromNames
= intel_create_image_from_names
,
1454 .fromPlanar
= intel_from_planar
,
1455 .createImageFromTexture
= intel_create_image_from_texture
,
1456 .createImageFromFds
= intel_create_image_from_fds
,
1457 .createImageFromDmaBufs
= intel_create_image_from_dma_bufs
,
1459 .getCapabilities
= NULL
,
1460 .mapImage
= intel_map_image
,
1461 .unmapImage
= intel_unmap_image
,
1462 .createImageWithModifiers
= intel_create_image_with_modifiers
,
1463 .createImageFromDmaBufs2
= intel_create_image_from_dma_bufs2
,
1464 .queryDmaBufFormats
= intel_query_dma_buf_formats
,
1465 .queryDmaBufModifiers
= intel_query_dma_buf_modifiers
,
1466 .queryDmaBufFormatModifierAttribs
= intel_query_format_modifier_attribs
,
1470 get_aperture_size(int fd
)
1472 struct drm_i915_gem_get_aperture aperture
;
1474 if (drmIoctl(fd
, DRM_IOCTL_I915_GEM_GET_APERTURE
, &aperture
) != 0)
1477 return aperture
.aper_size
;
1481 brw_query_renderer_integer(__DRIscreen
*dri_screen
,
1482 int param
, unsigned int *value
)
1484 const struct intel_screen
*const screen
=
1485 (struct intel_screen
*) dri_screen
->driverPrivate
;
1488 case __DRI2_RENDERER_VENDOR_ID
:
1491 case __DRI2_RENDERER_DEVICE_ID
:
1492 value
[0] = screen
->deviceID
;
1494 case __DRI2_RENDERER_ACCELERATED
:
1497 case __DRI2_RENDERER_VIDEO_MEMORY
: {
1498 /* Once a batch uses more than 75% of the maximum mappable size, we
1499 * assume that there's some fragmentation, and we start doing extra
1500 * flushing, etc. That's the big cliff apps will care about.
1502 const unsigned gpu_mappable_megabytes
=
1503 screen
->aperture_threshold
/ (1024 * 1024);
1505 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
1506 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
1508 if (system_memory_pages
<= 0 || system_page_size
<= 0)
1511 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
1512 * (uint64_t) system_page_size
;
1514 const unsigned system_memory_megabytes
=
1515 (unsigned) (system_memory_bytes
/ (1024 * 1024));
1517 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
1520 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
1523 case __DRI2_RENDERER_HAS_TEXTURE_3D
:
1526 case __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
:
1528 if (brw_hw_context_set_priority(screen
->bufmgr
,
1529 0, GEN_CONTEXT_HIGH_PRIORITY
) == 0)
1530 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH
;
1531 if (brw_hw_context_set_priority(screen
->bufmgr
,
1532 0, GEN_CONTEXT_LOW_PRIORITY
) == 0)
1533 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW
;
1534 /* reset to default last, just in case */
1535 if (brw_hw_context_set_priority(screen
->bufmgr
,
1536 0, GEN_CONTEXT_MEDIUM_PRIORITY
) == 0)
1537 value
[0] |= __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM
;
1539 case __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
:
1543 return driQueryRendererIntegerCommon(dri_screen
, param
, value
);
1550 brw_query_renderer_string(__DRIscreen
*dri_screen
,
1551 int param
, const char **value
)
1553 const struct intel_screen
*screen
=
1554 (struct intel_screen
*) dri_screen
->driverPrivate
;
1557 case __DRI2_RENDERER_VENDOR_ID
:
1558 value
[0] = brw_vendor_string
;
1560 case __DRI2_RENDERER_DEVICE_ID
:
1561 value
[0] = brw_get_renderer_string(screen
);
1571 brw_set_cache_funcs(__DRIscreen
*dri_screen
,
1572 __DRIblobCacheSet set
, __DRIblobCacheGet get
)
1574 const struct intel_screen
*const screen
=
1575 (struct intel_screen
*) dri_screen
->driverPrivate
;
1577 if (!screen
->disk_cache
)
1580 disk_cache_set_callbacks(screen
->disk_cache
, set
, get
);
1583 static const __DRI2rendererQueryExtension intelRendererQueryExtension
= {
1584 .base
= { __DRI2_RENDERER_QUERY
, 1 },
1586 .queryInteger
= brw_query_renderer_integer
,
1587 .queryString
= brw_query_renderer_string
1590 static const __DRIrobustnessExtension dri2Robustness
= {
1591 .base
= { __DRI2_ROBUSTNESS
, 1 }
1594 static const __DRI2blobExtension intelBlobExtension
= {
1595 .base
= { __DRI2_BLOB
, 1 },
1596 .set_cache_funcs
= brw_set_cache_funcs
1599 static const __DRImutableRenderBufferDriverExtension intelMutableRenderBufferExtension
= {
1600 .base
= { __DRI_MUTABLE_RENDER_BUFFER_DRIVER
, 1 },
1603 static const __DRIextension
*screenExtensions
[] = {
1604 &intelTexBufferExtension
.base
,
1605 &intelFenceExtension
.base
,
1606 &intelFlushExtension
.base
,
1607 &intelImageExtension
.base
,
1608 &intelRendererQueryExtension
.base
,
1609 &intelMutableRenderBufferExtension
.base
,
1610 &dri2ConfigQueryExtension
.base
,
1611 &dri2NoErrorExtension
.base
,
1612 &intelBlobExtension
.base
,
1616 static const __DRIextension
*intelRobustScreenExtensions
[] = {
1617 &intelTexBufferExtension
.base
,
1618 &intelFenceExtension
.base
,
1619 &intelFlushExtension
.base
,
1620 &intelImageExtension
.base
,
1621 &intelRendererQueryExtension
.base
,
1622 &intelMutableRenderBufferExtension
.base
,
1623 &dri2ConfigQueryExtension
.base
,
1624 &dri2Robustness
.base
,
1625 &dri2NoErrorExtension
.base
,
1626 &intelBlobExtension
.base
,
1631 intel_get_param(struct intel_screen
*screen
, int param
, int *value
)
1634 struct drm_i915_getparam gp
;
1636 memset(&gp
, 0, sizeof(gp
));
1640 if (drmIoctl(screen
->driScrnPriv
->fd
, DRM_IOCTL_I915_GETPARAM
, &gp
) == -1) {
1643 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
1650 intel_get_boolean(struct intel_screen
*screen
, int param
)
1653 return (intel_get_param(screen
, param
, &value
) == 0) && value
;
1657 intel_get_integer(struct intel_screen
*screen
, int param
)
1661 if (intel_get_param(screen
, param
, &value
) == 0)
1668 intelDestroyScreen(__DRIscreen
* sPriv
)
1670 struct intel_screen
*screen
= sPriv
->driverPrivate
;
1672 brw_bufmgr_destroy(screen
->bufmgr
);
1673 driDestroyOptionInfo(&screen
->optionCache
);
1675 disk_cache_destroy(screen
->disk_cache
);
1677 ralloc_free(screen
);
1678 sPriv
->driverPrivate
= NULL
;
1683 * Create a gl_framebuffer and attach it to __DRIdrawable::driverPrivate.
1685 *_This implements driDriverAPI::createNewDrawable, which the DRI layer calls
1686 * when creating a EGLSurface, GLXDrawable, or GLXPixmap. Despite the name,
1687 * this does not allocate GPU memory.
1690 intelCreateBuffer(__DRIscreen
*dri_screen
,
1691 __DRIdrawable
* driDrawPriv
,
1692 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
1694 struct intel_renderbuffer
*rb
;
1695 struct intel_screen
*screen
= (struct intel_screen
*)
1696 dri_screen
->driverPrivate
;
1697 mesa_format rgbFormat
;
1698 unsigned num_samples
=
1699 intel_quantize_num_samples(screen
, mesaVis
->samples
);
1704 struct gl_framebuffer
*fb
= CALLOC_STRUCT(gl_framebuffer
);
1708 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
1710 if (screen
->winsys_msaa_samples_override
!= -1) {
1711 num_samples
= screen
->winsys_msaa_samples_override
;
1712 fb
->Visual
.samples
= num_samples
;
1715 if (mesaVis
->redBits
== 10 && mesaVis
->alphaBits
> 0) {
1716 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10A2_UNORM
1717 : MESA_FORMAT_R10G10B10A2_UNORM
;
1718 } else if (mesaVis
->redBits
== 10) {
1719 rgbFormat
= mesaVis
->redMask
== 0x3ff00000 ? MESA_FORMAT_B10G10R10X2_UNORM
1720 : MESA_FORMAT_R10G10B10X2_UNORM
;
1721 } else if (mesaVis
->redBits
== 5) {
1722 rgbFormat
= mesaVis
->redMask
== 0x1f ? MESA_FORMAT_R5G6B5_UNORM
1723 : MESA_FORMAT_B5G6R5_UNORM
;
1724 } else if (mesaVis
->sRGBCapable
) {
1725 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1726 : MESA_FORMAT_B8G8R8A8_SRGB
;
1727 } else if (mesaVis
->alphaBits
== 0) {
1728 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8X8_UNORM
1729 : MESA_FORMAT_B8G8R8X8_UNORM
;
1731 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1732 : MESA_FORMAT_B8G8R8A8_SRGB
;
1733 fb
->Visual
.sRGBCapable
= true;
1736 /* mesaVis->sRGBCapable was set, user is asking for sRGB */
1737 bool srgb_cap_set
= mesaVis
->redBits
>= 8 && mesaVis
->sRGBCapable
;
1739 /* setup the hardware-based renderbuffers */
1740 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1741 _mesa_attach_and_own_rb(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
1742 rb
->need_srgb
= srgb_cap_set
;
1744 if (mesaVis
->doubleBufferMode
) {
1745 rb
= intel_create_winsys_renderbuffer(screen
, rgbFormat
, num_samples
);
1746 _mesa_attach_and_own_rb(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
1747 rb
->need_srgb
= srgb_cap_set
;
1751 * Assert here that the gl_config has an expected depth/stencil bit
1752 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
1753 * which constructs the advertised configs.)
1755 if (mesaVis
->depthBits
== 24) {
1756 assert(mesaVis
->stencilBits
== 8);
1758 if (screen
->devinfo
.has_hiz_and_separate_stencil
) {
1759 rb
= intel_create_private_renderbuffer(screen
,
1760 MESA_FORMAT_Z24_UNORM_X8_UINT
,
1762 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1763 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_S_UINT8
,
1765 _mesa_attach_and_own_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1768 * Use combined depth/stencil. Note that the renderbuffer is
1769 * attached to two attachment points.
1771 rb
= intel_create_private_renderbuffer(screen
,
1772 MESA_FORMAT_Z24_UNORM_S8_UINT
,
1774 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1775 _mesa_attach_and_reference_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1778 else if (mesaVis
->depthBits
== 16) {
1779 assert(mesaVis
->stencilBits
== 0);
1780 rb
= intel_create_private_renderbuffer(screen
, MESA_FORMAT_Z_UNORM16
,
1782 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1785 assert(mesaVis
->depthBits
== 0);
1786 assert(mesaVis
->stencilBits
== 0);
1789 /* now add any/all software-based renderbuffers we may need */
1790 _swrast_add_soft_renderbuffers(fb
,
1791 false, /* never sw color */
1792 false, /* never sw depth */
1793 false, /* never sw stencil */
1794 mesaVis
->accumRedBits
> 0,
1795 false, /* never sw alpha */
1796 false /* never sw aux */ );
1797 driDrawPriv
->driverPrivate
= fb
;
1803 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
1805 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
1807 _mesa_reference_framebuffer(&fb
, NULL
);
1811 intel_cs_timestamp_frequency(struct intel_screen
*screen
)
1813 /* We shouldn't need to update gen_device_info.timestamp_frequency prior to
1814 * gen10, PCI-id is enough to figure it out.
1816 assert(screen
->devinfo
.gen
>= 10);
1820 ret
= intel_get_param(screen
, I915_PARAM_CS_TIMESTAMP_FREQUENCY
,
1824 "Kernel 4.15 required to read the CS timestamp frequency.\n");
1828 screen
->devinfo
.timestamp_frequency
= freq
;
1832 intel_detect_sseu(struct intel_screen
*screen
)
1834 assert(screen
->devinfo
.gen
>= 8);
1837 screen
->subslice_total
= -1;
1838 screen
->eu_total
= -1;
1840 ret
= intel_get_param(screen
, I915_PARAM_SUBSLICE_TOTAL
,
1841 &screen
->subslice_total
);
1842 if (ret
< 0 && ret
!= -EINVAL
)
1845 ret
= intel_get_param(screen
,
1846 I915_PARAM_EU_TOTAL
, &screen
->eu_total
);
1847 if (ret
< 0 && ret
!= -EINVAL
)
1850 /* Without this information, we cannot get the right Braswell brandstrings,
1851 * and we have to use conservative numbers for GPGPU on many platforms, but
1852 * otherwise, things will just work.
1854 if (screen
->subslice_total
< 1 || screen
->eu_total
< 1)
1856 "Kernel 4.1 required to properly query GPU properties.\n");
1861 screen
->subslice_total
= -1;
1862 screen
->eu_total
= -1;
1863 _mesa_warning(NULL
, "Failed to query GPU properties (%s).\n", strerror(-ret
));
1867 intel_init_bufmgr(struct intel_screen
*screen
)
1869 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
1871 if (getenv("INTEL_NO_HW") != NULL
)
1872 screen
->no_hw
= true;
1874 screen
->bufmgr
= brw_bufmgr_init(&screen
->devinfo
, dri_screen
->fd
);
1875 if (screen
->bufmgr
== NULL
) {
1876 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1877 __func__
, __LINE__
);
1881 if (!intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_NO_RELOC
)) {
1882 fprintf(stderr
, "[%s: %u] Kernel 3.9 required.\n", __func__
, __LINE__
);
1890 intel_detect_swizzling(struct intel_screen
*screen
)
1892 uint32_t tiling
= I915_TILING_X
;
1893 uint32_t swizzle_mode
= 0;
1894 struct brw_bo
*buffer
=
1895 brw_bo_alloc_tiled(screen
->bufmgr
, "swizzle test", 32768,
1896 BRW_MEMZONE_OTHER
, tiling
, 512, 0);
1900 brw_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1901 brw_bo_unreference(buffer
);
1903 return swizzle_mode
!= I915_BIT_6_SWIZZLE_NONE
;
1907 intel_detect_timestamp(struct intel_screen
*screen
)
1909 uint64_t dummy
= 0, last
= 0;
1910 int upper
, lower
, loops
;
1912 /* On 64bit systems, some old kernels trigger a hw bug resulting in the
1913 * TIMESTAMP register being shifted and the low 32bits always zero.
1915 * More recent kernels offer an interface to read the full 36bits
1918 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
| 1, &dummy
) == 0)
1921 /* Determine if we have a 32bit or 64bit kernel by inspecting the
1922 * upper 32bits for a rapidly changing timestamp.
1924 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &last
))
1928 for (loops
= 0; loops
< 10; loops
++) {
1929 /* The TIMESTAMP should change every 80ns, so several round trips
1930 * through the kernel should be enough to advance it.
1932 if (brw_reg_read(screen
->bufmgr
, TIMESTAMP
, &dummy
))
1935 upper
+= (dummy
>> 32) != (last
>> 32);
1936 if (upper
> 1) /* beware 32bit counter overflow */
1937 return 2; /* upper dword holds the low 32bits of the timestamp */
1939 lower
+= (dummy
& 0xffffffff) != (last
& 0xffffffff);
1941 return 1; /* timestamp is unshifted */
1946 /* No advancement? No timestamp! */
1951 * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer.
1953 * Some combinations of hardware and kernel versions allow this feature,
1954 * while others don't. Instead of trying to enumerate every case, just
1955 * try and write a register and see if works.
1958 intel_detect_pipelined_register(struct intel_screen
*screen
,
1959 int reg
, uint32_t expected_value
, bool reset
)
1964 struct brw_bo
*results
, *bo
;
1966 uint32_t offset
= 0;
1968 bool success
= false;
1970 /* Create a zero'ed temporary buffer for reading our results */
1971 results
= brw_bo_alloc(screen
->bufmgr
, "registers", 4096, BRW_MEMZONE_OTHER
);
1972 if (results
== NULL
)
1975 bo
= brw_bo_alloc(screen
->bufmgr
, "batchbuffer", 4096, BRW_MEMZONE_OTHER
);
1979 map
= brw_bo_map(NULL
, bo
, MAP_WRITE
);
1985 /* Write the register. */
1986 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
1988 *batch
++ = expected_value
;
1990 /* Save the register's value back to the buffer. */
1991 *batch
++ = MI_STORE_REGISTER_MEM
| (3 - 2);
1993 struct drm_i915_gem_relocation_entry reloc
= {
1994 .offset
= (char *) batch
- (char *) map
,
1995 .delta
= offset
* sizeof(uint32_t),
1996 .target_handle
= results
->gem_handle
,
1997 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
1998 .write_domain
= I915_GEM_DOMAIN_INSTRUCTION
,
2000 *batch
++ = reloc
.presumed_offset
+ reloc
.delta
;
2002 /* And afterwards clear the register */
2004 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
2009 *batch
++ = MI_BATCH_BUFFER_END
;
2011 struct drm_i915_gem_exec_object2 exec_objects
[2] = {
2013 .handle
= results
->gem_handle
,
2016 .handle
= bo
->gem_handle
,
2017 .relocation_count
= 1,
2018 .relocs_ptr
= (uintptr_t) &reloc
,
2022 struct drm_i915_gem_execbuffer2 execbuf
= {
2023 .buffers_ptr
= (uintptr_t) exec_objects
,
2025 .batch_len
= ALIGN((char *) batch
- (char *) map
, 8),
2026 .flags
= I915_EXEC_RENDER
,
2029 /* Don't bother with error checking - if the execbuf fails, the
2030 * value won't be written and we'll just report that there's no access.
2032 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2033 drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GEM_EXECBUFFER2
, &execbuf
);
2035 /* Check whether the value got written. */
2036 void *results_map
= brw_bo_map(NULL
, results
, MAP_READ
);
2038 success
= *((uint32_t *)results_map
+ offset
) == expected_value
;
2039 brw_bo_unmap(results
);
2043 brw_bo_unreference(bo
);
2045 brw_bo_unreference(results
);
2051 intel_detect_pipelined_so(struct intel_screen
*screen
)
2053 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2055 /* Supposedly, Broadwell just works. */
2056 if (devinfo
->gen
>= 8)
2059 if (devinfo
->gen
<= 6)
2062 /* See the big explanation about command parser versions below */
2063 if (screen
->cmd_parser_version
>= (devinfo
->is_haswell
? 7 : 2))
2066 /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the
2067 * statistics registers), and we already reset it to zero before using it.
2069 return intel_detect_pipelined_register(screen
,
2070 GEN7_SO_WRITE_OFFSET(0),
2076 * Return array of MSAA modes supported by the hardware. The array is
2077 * zero-terminated and sorted in decreasing order.
2080 intel_supported_msaa_modes(const struct intel_screen
*screen
)
2082 static const int gen9_modes
[] = {16, 8, 4, 2, 0, -1};
2083 static const int gen8_modes
[] = {8, 4, 2, 0, -1};
2084 static const int gen7_modes
[] = {8, 4, 0, -1};
2085 static const int gen6_modes
[] = {4, 0, -1};
2086 static const int gen4_modes
[] = {0, -1};
2088 if (screen
->devinfo
.gen
>= 9) {
2090 } else if (screen
->devinfo
.gen
>= 8) {
2092 } else if (screen
->devinfo
.gen
>= 7) {
2094 } else if (screen
->devinfo
.gen
== 6) {
2102 intel_loader_get_cap(const __DRIscreen
*dri_screen
, enum dri_loader_cap cap
)
2104 if (dri_screen
->dri2
.loader
&& dri_screen
->dri2
.loader
->base
.version
>= 4 &&
2105 dri_screen
->dri2
.loader
->getCapability
)
2106 return dri_screen
->dri2
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2108 if (dri_screen
->image
.loader
&& dri_screen
->image
.loader
->base
.version
>= 2 &&
2109 dri_screen
->image
.loader
->getCapability
)
2110 return dri_screen
->image
.loader
->getCapability(dri_screen
->loaderPrivate
, cap
);
2115 static __DRIconfig
**
2116 intel_screen_make_configs(__DRIscreen
*dri_screen
)
2118 static const mesa_format formats
[] = {
2119 MESA_FORMAT_B5G6R5_UNORM
,
2120 MESA_FORMAT_B8G8R8A8_UNORM
,
2121 MESA_FORMAT_B8G8R8X8_UNORM
,
2123 MESA_FORMAT_B8G8R8A8_SRGB
,
2125 /* For 10 bpc, 30 bit depth framebuffers. */
2126 MESA_FORMAT_B10G10R10A2_UNORM
,
2127 MESA_FORMAT_B10G10R10X2_UNORM
,
2129 /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
2130 * Likewise for RGBX and BGRX. Otherwise, the GLX client and the GLX
2131 * server may disagree on which format the GLXFBConfig represents,
2132 * resulting in swapped color channels.
2134 * The problem, as of 2017-05-30:
2135 * When matching a GLXFBConfig to a __DRIconfig, GLX ignores the channel
2136 * order and chooses the first __DRIconfig with the expected channel
2137 * sizes. Specifically, GLX compares the GLXFBConfig's and __DRIconfig's
2138 * __DRI_ATTRIB_{CHANNEL}_SIZE but ignores __DRI_ATTRIB_{CHANNEL}_MASK.
2140 * EGL does not suffer from this problem. It correctly compares the
2141 * channel masks when matching EGLConfig to __DRIconfig.
2144 /* Required by Android, for HAL_PIXEL_FORMAT_RGBA_8888. */
2145 MESA_FORMAT_R8G8B8A8_UNORM
,
2147 /* Required by Android, for HAL_PIXEL_FORMAT_RGBX_8888. */
2148 MESA_FORMAT_R8G8B8X8_UNORM
,
2150 MESA_FORMAT_R8G8B8A8_SRGB
,
2153 /* __DRI_ATTRIB_SWAP_COPY is not supported due to page flipping. */
2154 static const GLenum back_buffer_modes
[] = {
2155 __DRI_ATTRIB_SWAP_UNDEFINED
, __DRI_ATTRIB_SWAP_NONE
2158 static const uint8_t singlesample_samples
[1] = {0};
2160 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2161 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2162 uint8_t depth_bits
[4], stencil_bits
[4];
2163 __DRIconfig
**configs
= NULL
;
2165 /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
2166 unsigned num_formats
;
2167 if (intel_loader_get_cap(dri_screen
, DRI_LOADER_CAP_RGBA_ORDERING
))
2168 num_formats
= ARRAY_SIZE(formats
);
2170 num_formats
= ARRAY_SIZE(formats
) - 3; /* all - RGBA_ORDERING formats */
2172 /* Shall we expose 10 bpc formats? */
2173 bool allow_rgb10_configs
= driQueryOptionb(&screen
->optionCache
,
2174 "allow_rgb10_configs");
2176 /* Generate singlesample configs, each without accumulation buffer
2177 * and with EGL_MUTABLE_RENDER_BUFFER_BIT_KHR.
2179 for (unsigned i
= 0; i
< num_formats
; i
++) {
2180 __DRIconfig
**new_configs
;
2181 int num_depth_stencil_bits
= 2;
2183 if (!allow_rgb10_configs
&&
2184 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2185 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2188 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
2189 * buffer that has a different number of bits per pixel than the color
2190 * buffer, gen >= 6 supports this.
2193 stencil_bits
[0] = 0;
2195 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2197 stencil_bits
[1] = 0;
2198 if (devinfo
->gen
>= 6) {
2200 stencil_bits
[2] = 8;
2201 num_depth_stencil_bits
= 3;
2205 stencil_bits
[1] = 8;
2208 new_configs
= driCreateConfigs(formats
[i
],
2211 num_depth_stencil_bits
,
2212 back_buffer_modes
, 2,
2213 singlesample_samples
, 1,
2215 /*mutable_render_buffer*/ true);
2216 configs
= driConcatConfigs(configs
, new_configs
);
2219 /* Generate the minimum possible set of configs that include an
2220 * accumulation buffer.
2222 for (unsigned i
= 0; i
< num_formats
; i
++) {
2223 __DRIconfig
**new_configs
;
2225 if (!allow_rgb10_configs
&&
2226 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2227 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2230 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2232 stencil_bits
[0] = 0;
2235 stencil_bits
[0] = 8;
2238 new_configs
= driCreateConfigs(formats
[i
],
2239 depth_bits
, stencil_bits
, 1,
2240 back_buffer_modes
, 1,
2241 singlesample_samples
, 1,
2242 true, false, false);
2243 configs
= driConcatConfigs(configs
, new_configs
);
2246 /* Generate multisample configs.
2248 * This loop breaks early, and hence is a no-op, on gen < 6.
2250 * Multisample configs must follow the singlesample configs in order to
2251 * work around an X server bug present in 1.12. The X server chooses to
2252 * associate the first listed RGBA888-Z24S8 config, regardless of its
2253 * sample count, with the 32-bit depth visual used for compositing.
2255 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
2256 * supported. Singlebuffer configs are not supported because no one wants
2259 for (unsigned i
= 0; i
< num_formats
; i
++) {
2260 if (devinfo
->gen
< 6)
2263 if (!allow_rgb10_configs
&&
2264 (formats
[i
] == MESA_FORMAT_B10G10R10A2_UNORM
||
2265 formats
[i
] == MESA_FORMAT_B10G10R10X2_UNORM
))
2268 __DRIconfig
**new_configs
;
2269 const int num_depth_stencil_bits
= 2;
2270 int num_msaa_modes
= 0;
2271 const uint8_t *multisample_samples
= NULL
;
2274 stencil_bits
[0] = 0;
2276 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
2278 stencil_bits
[1] = 0;
2281 stencil_bits
[1] = 8;
2284 if (devinfo
->gen
>= 9) {
2285 static const uint8_t multisample_samples_gen9
[] = {2, 4, 8, 16};
2286 multisample_samples
= multisample_samples_gen9
;
2287 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen9
);
2288 } else if (devinfo
->gen
== 8) {
2289 static const uint8_t multisample_samples_gen8
[] = {2, 4, 8};
2290 multisample_samples
= multisample_samples_gen8
;
2291 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen8
);
2292 } else if (devinfo
->gen
== 7) {
2293 static const uint8_t multisample_samples_gen7
[] = {4, 8};
2294 multisample_samples
= multisample_samples_gen7
;
2295 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen7
);
2296 } else if (devinfo
->gen
== 6) {
2297 static const uint8_t multisample_samples_gen6
[] = {4};
2298 multisample_samples
= multisample_samples_gen6
;
2299 num_msaa_modes
= ARRAY_SIZE(multisample_samples_gen6
);
2302 new_configs
= driCreateConfigs(formats
[i
],
2305 num_depth_stencil_bits
,
2306 back_buffer_modes
, 1,
2307 multisample_samples
,
2309 false, false, false);
2310 configs
= driConcatConfigs(configs
, new_configs
);
2313 if (configs
== NULL
) {
2314 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
2323 set_max_gl_versions(struct intel_screen
*screen
)
2325 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
2326 const bool has_astc
= screen
->devinfo
.gen
>= 9;
2328 switch (screen
->devinfo
.gen
) {
2333 dri_screen
->max_gl_core_version
= 45;
2334 dri_screen
->max_gl_compat_version
= 30;
2335 dri_screen
->max_gl_es1_version
= 11;
2336 dri_screen
->max_gl_es2_version
= has_astc
? 32 : 31;
2339 dri_screen
->max_gl_core_version
= 33;
2340 if (can_do_pipelined_register_writes(screen
)) {
2341 dri_screen
->max_gl_core_version
= 42;
2342 if (screen
->devinfo
.is_haswell
&& can_do_compute_dispatch(screen
))
2343 dri_screen
->max_gl_core_version
= 43;
2344 if (screen
->devinfo
.is_haswell
&& can_do_mi_math_and_lrr(screen
))
2345 dri_screen
->max_gl_core_version
= 45;
2347 dri_screen
->max_gl_compat_version
= 30;
2348 dri_screen
->max_gl_es1_version
= 11;
2349 dri_screen
->max_gl_es2_version
= screen
->devinfo
.is_haswell
? 31 : 30;
2352 dri_screen
->max_gl_core_version
= 33;
2353 dri_screen
->max_gl_compat_version
= 30;
2354 dri_screen
->max_gl_es1_version
= 11;
2355 dri_screen
->max_gl_es2_version
= 30;
2359 dri_screen
->max_gl_core_version
= 0;
2360 dri_screen
->max_gl_compat_version
= 21;
2361 dri_screen
->max_gl_es1_version
= 11;
2362 dri_screen
->max_gl_es2_version
= 20;
2365 unreachable("unrecognized intel_screen::gen");
2370 * Return the revision (generally the revid field of the PCI header) of the
2374 intel_device_get_revision(int fd
)
2376 struct drm_i915_getparam gp
;
2380 memset(&gp
, 0, sizeof(gp
));
2381 gp
.param
= I915_PARAM_REVISION
;
2382 gp
.value
= &revision
;
2384 ret
= drmCommandWriteRead(fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
2392 shader_debug_log_mesa(void *data
, const char *fmt
, ...)
2394 struct brw_context
*brw
= (struct brw_context
*)data
;
2397 va_start(args
, fmt
);
2399 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
2400 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2401 MESA_DEBUG_TYPE_OTHER
,
2402 MESA_DEBUG_SEVERITY_NOTIFICATION
, fmt
, args
);
2407 shader_perf_log_mesa(void *data
, const char *fmt
, ...)
2409 struct brw_context
*brw
= (struct brw_context
*)data
;
2412 va_start(args
, fmt
);
2414 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
)) {
2416 va_copy(args_copy
, args
);
2417 vfprintf(stderr
, fmt
, args_copy
);
2421 if (brw
->perf_debug
) {
2423 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
2424 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
2425 MESA_DEBUG_TYPE_PERFORMANCE
,
2426 MESA_DEBUG_SEVERITY_MEDIUM
, fmt
, args
);
2432 * This is the driver specific part of the createNewScreen entry point.
2433 * Called when using DRI2.
2435 * \return the struct gl_config supported by this driver
2438 __DRIconfig
**intelInitScreen2(__DRIscreen
*dri_screen
)
2440 struct intel_screen
*screen
;
2442 if (dri_screen
->image
.loader
) {
2443 } else if (dri_screen
->dri2
.loader
->base
.version
<= 2 ||
2444 dri_screen
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
2446 "\nERROR! DRI2 loader with getBuffersWithFormat() "
2447 "support required\n");
2451 /* Allocate the private area */
2452 screen
= rzalloc(NULL
, struct intel_screen
);
2454 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
2457 /* parse information in __driConfigOptions */
2458 driOptionCache options
;
2459 memset(&options
, 0, sizeof(options
));
2461 driParseOptionInfo(&options
, brw_config_options
.xml
);
2462 driParseConfigFiles(&screen
->optionCache
, &options
, dri_screen
->myNum
,
2464 driDestroyOptionCache(&options
);
2466 screen
->driScrnPriv
= dri_screen
;
2467 dri_screen
->driverPrivate
= (void *) screen
;
2469 screen
->deviceID
= gen_get_pci_device_id_override();
2470 if (screen
->deviceID
< 0)
2471 screen
->deviceID
= intel_get_integer(screen
, I915_PARAM_CHIPSET_ID
);
2473 screen
->no_hw
= true;
2475 if (!gen_get_device_info(screen
->deviceID
, &screen
->devinfo
))
2478 if (!intel_init_bufmgr(screen
))
2481 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
2483 brw_process_intel_debug_variable();
2485 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && devinfo
->gen
< 7) {
2487 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
2488 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
2491 if (intel_get_integer(screen
, I915_PARAM_MMAP_GTT_VERSION
) >= 1) {
2492 /* Theorectically unlimited! At least for individual objects...
2494 * Currently the entire (global) address space for all GTT maps is
2495 * limited to 64bits. That is all objects on the system that are
2496 * setup for GTT mmapping must fit within 64bits. An attempt to use
2497 * one that exceeds the limit with fail in brw_bo_map_gtt().
2499 * Long before we hit that limit, we will be practically limited by
2500 * that any single object must fit in physical memory (RAM). The upper
2501 * limit on the CPU's address space is currently 48bits (Skylake), of
2502 * which only 39bits can be physical memory. (The GPU itself also has
2503 * a 48bit addressable virtual space.) We can fit over 32 million
2504 * objects of the current maximum allocable size before running out
2507 screen
->max_gtt_map_object_size
= UINT64_MAX
;
2509 /* Estimate the size of the mappable aperture into the GTT. There's an
2510 * ioctl to get the whole GTT size, but not one to get the mappable subset.
2511 * It turns out it's basically always 256MB, though some ancient hardware
2514 uint32_t gtt_size
= 256 * 1024 * 1024;
2516 /* We don't want to map two objects such that a memcpy between them would
2517 * just fault one mapping in and then the other over and over forever. So
2518 * we would need to divide the GTT size by 2. Additionally, some GTT is
2519 * taken up by things like the framebuffer and the ringbuffer and such, so
2520 * be more conservative.
2522 screen
->max_gtt_map_object_size
= gtt_size
/ 4;
2525 screen
->aperture_threshold
= get_aperture_size(dri_screen
->fd
) * 3 / 4;
2527 screen
->hw_has_swizzling
= intel_detect_swizzling(screen
);
2528 screen
->hw_has_timestamp
= intel_detect_timestamp(screen
);
2530 isl_device_init(&screen
->isl_dev
, &screen
->devinfo
,
2531 screen
->hw_has_swizzling
);
2533 if (devinfo
->gen
>= 10)
2534 intel_cs_timestamp_frequency(screen
);
2536 /* GENs prior to 8 do not support EU/Subslice info */
2537 if (devinfo
->gen
>= 8) {
2538 intel_detect_sseu(screen
);
2539 } else if (devinfo
->gen
== 7) {
2540 screen
->subslice_total
= 1 << (devinfo
->gt
- 1);
2543 /* Gen7-7.5 kernel requirements / command parser saga:
2546 * Haswell and Baytrail cannot use any privileged batchbuffer features.
2548 * Ivybridge has aliasing PPGTT on by default, which accidentally marks
2549 * all batches secure, allowing them to use any feature with no checking.
2550 * This is effectively equivalent to a command parser version of
2551 * \infinity - everything is possible.
2553 * The command parser does not exist, and querying the version will
2557 * The kernel enables the command parser by default, for systems with
2558 * aliasing PPGTT enabled (Ivybridge and Haswell). However, the
2559 * hardware checker is still enabled, so Haswell and Baytrail cannot
2562 * Ivybridge goes from "everything is possible" to "only what the
2563 * command parser allows" (if the user boots with i915.cmd_parser=0,
2564 * then everything is possible again). We can only safely use features
2565 * allowed by the supported command parser version.
2567 * Annoyingly, I915_PARAM_CMD_PARSER_VERSION reports the static version
2568 * implemented by the kernel, even if it's turned off. So, checking
2569 * for version > 0 does not mean that you can write registers. We have
2570 * to try it and see. The version does, however, indicate the age of
2573 * Instead of matching the hardware checker's behavior of converting
2574 * privileged commands to MI_NOOP, it makes execbuf2 start returning
2575 * -EINVAL, making it dangerous to try and use privileged features.
2577 * Effective command parser versions:
2578 * - Haswell: 0 (reporting 1, writes don't work)
2579 * - Baytrail: 0 (reporting 1, writes don't work)
2580 * - Ivybridge: 1 (enabled) or infinite (disabled)
2583 * Baytrail aliasing PPGTT is enabled, making it like Ivybridge:
2584 * effectively version 1 (enabled) or infinite (disabled).
2586 * - v3.19: f1f55cc0556031c8ee3fe99dae7251e78b9b653b
2587 * Command parser v2 supports predicate writes.
2589 * - Haswell: 0 (reporting 1, writes don't work)
2590 * - Baytrail: 2 (enabled) or infinite (disabled)
2591 * - Ivybridge: 2 (enabled) or infinite (disabled)
2593 * So version >= 2 is enough to know that Ivybridge and Baytrail
2594 * will work. Haswell still can't do anything.
2596 * - v4.0: Version 3 happened. Largely not relevant.
2598 * - v4.1: 6702cf16e0ba8b0129f5aa1b6609d4e9c70bc13b
2599 * L3 config registers are properly saved and restored as part
2600 * of the hardware context. We can approximately detect this point
2601 * in time by checking if I915_PARAM_REVISION is recognized - it
2602 * landed in a later commit, but in the same release cycle.
2604 * - v4.2: 245054a1fe33c06ad233e0d58a27ec7b64db9284
2605 * Command parser finally gains secure batch promotion. On Haswell,
2606 * the hardware checker gets disabled, which finally allows it to do
2607 * privileged commands.
2609 * I915_PARAM_CMD_PARSER_VERSION reports 3. Effective versions:
2610 * - Haswell: 3 (enabled) or 0 (disabled)
2611 * - Baytrail: 3 (enabled) or infinite (disabled)
2612 * - Ivybridge: 3 (enabled) or infinite (disabled)
2614 * Unfortunately, detecting this point in time is tricky, because
2615 * no version bump happened when this important change occurred.
2616 * On Haswell, if we can write any register, then the kernel is at
2617 * least this new, and we can start trusting the version number.
2619 * - v4.4: 2bbe6bbb0dc94fd4ce287bdac9e1bd184e23057b and
2620 * Command parser reaches version 4, allowing access to Haswell
2621 * atomic scratch and chicken3 registers. If version >= 4, we know
2622 * the kernel is new enough to support privileged features on all
2623 * hardware. However, the user might have disabled it...and the
2624 * kernel will still report version 4. So we still have to guess
2627 * - v4.4: 7b9748cb513a6bef4af87b79f0da3ff7e8b56cd8
2628 * Command parser v5 whitelists indirect compute shader dispatch
2629 * registers, needed for OpenGL 4.3 and later.
2632 * Command parser v7 lets us use MI_MATH on Haswell.
2634 * Additionally, the kernel begins reporting version 0 when
2635 * the command parser is disabled, allowing us to skip the
2636 * guess-and-check step on Haswell. Unfortunately, this also
2637 * means that we can no longer use it as an indicator of the
2638 * age of the kernel.
2640 if (intel_get_param(screen
, I915_PARAM_CMD_PARSER_VERSION
,
2641 &screen
->cmd_parser_version
) < 0) {
2642 /* Command parser does not exist - getparam is unrecognized */
2643 screen
->cmd_parser_version
= 0;
2646 /* Kernel 4.13 retuired for exec object capture */
2647 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_CAPTURE
)) {
2648 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_CAPTURE
;
2651 if (intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_BATCH_FIRST
)) {
2652 screen
->kernel_features
|= KERNEL_ALLOWS_EXEC_BATCH_FIRST
;
2655 if (!intel_detect_pipelined_so(screen
)) {
2656 /* We can't do anything, so the effective version is 0. */
2657 screen
->cmd_parser_version
= 0;
2659 screen
->kernel_features
|= KERNEL_ALLOWS_SOL_OFFSET_WRITES
;
2662 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 2)
2663 screen
->kernel_features
|= KERNEL_ALLOWS_PREDICATE_WRITES
;
2665 /* Haswell requires command parser version 4 in order to have L3
2666 * atomic scratch1 and chicken3 bits
2668 if (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 4) {
2669 screen
->kernel_features
|=
2670 KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3
;
2673 /* Haswell requires command parser version 6 in order to write to the
2674 * MI_MATH GPR registers, and version 7 in order to use
2675 * MI_LOAD_REGISTER_REG (which all users of MI_MATH use).
2677 if (devinfo
->gen
>= 8 ||
2678 (devinfo
->is_haswell
&& screen
->cmd_parser_version
>= 7)) {
2679 screen
->kernel_features
|= KERNEL_ALLOWS_MI_MATH_AND_LRR
;
2682 /* Gen7 needs at least command parser version 5 to support compute */
2683 if (devinfo
->gen
>= 8 || screen
->cmd_parser_version
>= 5)
2684 screen
->kernel_features
|= KERNEL_ALLOWS_COMPUTE_DISPATCH
;
2686 if (intel_get_boolean(screen
, I915_PARAM_HAS_CONTEXT_ISOLATION
))
2687 screen
->kernel_features
|= KERNEL_ALLOWS_CONTEXT_ISOLATION
;
2689 const char *force_msaa
= getenv("INTEL_FORCE_MSAA");
2691 screen
->winsys_msaa_samples_override
=
2692 intel_quantize_num_samples(screen
, atoi(force_msaa
));
2693 printf("Forcing winsys sample count to %d\n",
2694 screen
->winsys_msaa_samples_override
);
2696 screen
->winsys_msaa_samples_override
= -1;
2699 set_max_gl_versions(screen
);
2701 /* Notification of GPU resets requires hardware contexts and a kernel new
2702 * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is
2703 * supported, calling it with a context of 0 will either generate EPERM or
2704 * no error. If the ioctl is not supported, it always generate EINVAL.
2705 * Use this to determine whether to advertise the __DRI2_ROBUSTNESS
2706 * extension to the loader.
2708 * Don't even try on pre-Gen6, since we don't attempt to use contexts there.
2710 if (devinfo
->gen
>= 6) {
2711 struct drm_i915_reset_stats stats
;
2712 memset(&stats
, 0, sizeof(stats
));
2714 const int ret
= drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GET_RESET_STATS
, &stats
);
2716 screen
->has_context_reset_notification
=
2717 (ret
!= -1 || errno
!= EINVAL
);
2720 dri_screen
->extensions
= !screen
->has_context_reset_notification
2721 ? screenExtensions
: intelRobustScreenExtensions
;
2723 screen
->compiler
= brw_compiler_create(screen
, devinfo
);
2724 screen
->compiler
->shader_debug_log
= shader_debug_log_mesa
;
2725 screen
->compiler
->shader_perf_log
= shader_perf_log_mesa
;
2727 /* Changing the meaning of constant buffer pointers from a dynamic state
2728 * offset to an absolute address is only safe if the kernel isolates other
2729 * contexts from our changes.
2731 screen
->compiler
->constant_buffer_0_is_relative
= devinfo
->gen
< 8 ||
2732 !(screen
->kernel_features
& KERNEL_ALLOWS_CONTEXT_ISOLATION
);
2734 screen
->compiler
->supports_pull_constants
= true;
2736 screen
->has_exec_fence
=
2737 intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_FENCE
);
2739 intel_screen_init_surface_formats(screen
);
2741 if (INTEL_DEBUG
& (DEBUG_BATCH
| DEBUG_SUBMIT
)) {
2742 unsigned int caps
= intel_get_integer(screen
, I915_PARAM_HAS_SCHEDULER
);
2744 fprintf(stderr
, "Kernel scheduler detected: %08x\n", caps
);
2745 if (caps
& I915_SCHEDULER_CAP_PRIORITY
)
2746 fprintf(stderr
, " - User priority sorting enabled\n");
2747 if (caps
& I915_SCHEDULER_CAP_PREEMPTION
)
2748 fprintf(stderr
, " - Preemption enabled\n");
2752 brw_disk_cache_init(screen
);
2754 return (const __DRIconfig
**) intel_screen_make_configs(dri_screen
);
2757 struct intel_buffer
{
2762 static __DRIbuffer
*
2763 intelAllocateBuffer(__DRIscreen
*dri_screen
,
2764 unsigned attachment
, unsigned format
,
2765 int width
, int height
)
2767 struct intel_buffer
*intelBuffer
;
2768 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
2770 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
2771 attachment
== __DRI_BUFFER_BACK_LEFT
);
2773 intelBuffer
= calloc(1, sizeof *intelBuffer
);
2774 if (intelBuffer
== NULL
)
2777 /* The front and back buffers are color buffers, which are X tiled. GEN9+
2778 * supports Y tiled and compressed buffers, but there is no way to plumb that
2779 * through to here. */
2781 int cpp
= format
/ 8;
2782 intelBuffer
->bo
= brw_bo_alloc_tiled_2d(screen
->bufmgr
,
2783 "intelAllocateBuffer",
2788 I915_TILING_X
, &pitch
,
2791 if (intelBuffer
->bo
== NULL
) {
2796 brw_bo_flink(intelBuffer
->bo
, &intelBuffer
->base
.name
);
2798 intelBuffer
->base
.attachment
= attachment
;
2799 intelBuffer
->base
.cpp
= cpp
;
2800 intelBuffer
->base
.pitch
= pitch
;
2802 return &intelBuffer
->base
;
2806 intelReleaseBuffer(__DRIscreen
*dri_screen
, __DRIbuffer
*buffer
)
2808 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
2810 brw_bo_unreference(intelBuffer
->bo
);
2814 static const struct __DriverAPIRec brw_driver_api
= {
2815 .InitScreen
= intelInitScreen2
,
2816 .DestroyScreen
= intelDestroyScreen
,
2817 .CreateContext
= brwCreateContext
,
2818 .DestroyContext
= intelDestroyContext
,
2819 .CreateBuffer
= intelCreateBuffer
,
2820 .DestroyBuffer
= intelDestroyBuffer
,
2821 .MakeCurrent
= intelMakeCurrent
,
2822 .UnbindContext
= intelUnbindContext
,
2823 .AllocateBuffer
= intelAllocateBuffer
,
2824 .ReleaseBuffer
= intelReleaseBuffer
2827 static const struct __DRIDriverVtableExtensionRec brw_vtable
= {
2828 .base
= { __DRI_DRIVER_VTABLE
, 1 },
2829 .vtable
= &brw_driver_api
,
2832 static const __DRIextension
*brw_driver_extensions
[] = {
2833 &driCoreExtension
.base
,
2834 &driImageDriverExtension
.base
,
2835 &driDRI2Extension
.base
,
2837 &brw_config_options
.base
,
2841 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
2843 globalDriverAPI
= &brw_driver_api
;
2845 return brw_driver_extensions
;