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.
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
32 #include "main/texobj.h"
33 #include "main/hash.h"
34 #include "main/fbobject.h"
35 #include "main/version.h"
36 #include "swrast/s_renderbuffer.h"
37 #include "util/ralloc.h"
38 #include "brw_defines.h"
39 #include "compiler/nir/nir.h"
44 static const __DRIconfigOptionsExtension brw_config_options
= {
45 .base
= { __DRI_CONFIG_OPTIONS
, 1 },
48 DRI_CONF_SECTION_PERFORMANCE
49 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
50 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
51 * DRI_CONF_BO_REUSE_ALL
53 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
54 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
55 DRI_CONF_ENUM(0, "Disable buffer object reuse")
56 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
60 DRI_CONF_OPT_BEGIN_B(hiz
, "true")
61 DRI_CONF_DESC(en
, "Enable Hierarchical Z on gen6+")
65 DRI_CONF_SECTION_QUALITY
66 DRI_CONF_FORCE_S3TC_ENABLE("false")
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_NO_RAST("false")
78 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
79 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
80 DRI_CONF_DISABLE_THROTTLING("false")
81 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
82 DRI_CONF_FORCE_GLSL_VERSION(0)
83 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
84 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
85 DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false")
86 DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false")
87 DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
89 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
90 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
94 DRI_CONF_SECTION_MISCELLANEOUS
95 DRI_CONF_GLSL_ZERO_INIT("false")
100 #include "intel_batchbuffer.h"
101 #include "intel_buffers.h"
102 #include "intel_bufmgr.h"
103 #include "intel_fbo.h"
104 #include "intel_mipmap_tree.h"
105 #include "intel_screen.h"
106 #include "intel_tex.h"
107 #include "intel_image.h"
109 #include "brw_context.h"
111 #include "i915_drm.h"
114 * For debugging purposes, this returns a time in seconds.
121 clock_gettime(CLOCK_MONOTONIC
, &tp
);
123 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
127 aub_dump_bmp(struct gl_context
*ctx
)
129 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
131 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
132 struct intel_renderbuffer
*irb
=
133 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
135 if (irb
&& irb
->mt
) {
136 enum aub_dump_bmp_format format
;
138 switch (irb
->Base
.Base
.Format
) {
139 case MESA_FORMAT_B8G8R8A8_UNORM
:
140 case MESA_FORMAT_B8G8R8X8_UNORM
:
141 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
147 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->bo
,
150 irb
->Base
.Base
.Width
,
151 irb
->Base
.Base
.Height
,
159 static const __DRItexBufferExtension intelTexBufferExtension
= {
160 .base
= { __DRI_TEX_BUFFER
, 3 },
162 .setTexBuffer
= intelSetTexBuffer
,
163 .setTexBuffer2
= intelSetTexBuffer2
,
164 .releaseTexBuffer
= NULL
,
168 intel_dri2_flush_with_flags(__DRIcontext
*cPriv
,
169 __DRIdrawable
*dPriv
,
171 enum __DRI2throttleReason reason
)
173 struct brw_context
*brw
= cPriv
->driverPrivate
;
178 struct gl_context
*ctx
= &brw
->ctx
;
180 FLUSH_VERTICES(ctx
, 0);
182 if (flags
& __DRI2_FLUSH_DRAWABLE
)
183 intel_resolve_for_dri2_flush(brw
, dPriv
);
185 if (reason
== __DRI2_THROTTLE_SWAPBUFFER
)
186 brw
->need_swap_throttle
= true;
187 if (reason
== __DRI2_THROTTLE_FLUSHFRONT
)
188 brw
->need_flush_throttle
= true;
190 intel_batchbuffer_flush(brw
);
192 if (INTEL_DEBUG
& DEBUG_AUB
) {
198 * Provides compatibility with loaders that only support the older (version
199 * 1-3) flush interface.
201 * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13.
204 intel_dri2_flush(__DRIdrawable
*drawable
)
206 intel_dri2_flush_with_flags(drawable
->driContextPriv
, drawable
,
207 __DRI2_FLUSH_DRAWABLE
,
208 __DRI2_THROTTLE_SWAPBUFFER
);
211 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
212 .base
= { __DRI2_FLUSH
, 4 },
214 .flush
= intel_dri2_flush
,
215 .invalidate
= dri2InvalidateDrawable
,
216 .flush_with_flags
= intel_dri2_flush_with_flags
,
219 static struct intel_image_format intel_image_formats
[] = {
220 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
221 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
223 { __DRI_IMAGE_FOURCC_ABGR8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
224 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
226 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
227 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8
, 4 } } },
229 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
230 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
232 { __DRI_IMAGE_FOURCC_XBGR8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
233 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 }, } },
235 { __DRI_IMAGE_FOURCC_ARGB1555
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
236 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555
, 2 } } },
238 { __DRI_IMAGE_FOURCC_RGB565
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
239 { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565
, 2 } } },
241 { __DRI_IMAGE_FOURCC_R8
, __DRI_IMAGE_COMPONENTS_R
, 1,
242 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 }, } },
244 { __DRI_IMAGE_FOURCC_R16
, __DRI_IMAGE_COMPONENTS_R
, 1,
245 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 1 }, } },
247 { __DRI_IMAGE_FOURCC_GR88
, __DRI_IMAGE_COMPONENTS_RG
, 1,
248 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 }, } },
250 { __DRI_IMAGE_FOURCC_GR1616
, __DRI_IMAGE_COMPONENTS_RG
, 1,
251 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616
, 2 }, } },
253 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
254 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
255 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
256 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
258 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
259 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
260 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
261 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
263 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
264 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
265 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
266 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
268 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
269 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
270 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
271 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
273 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
274 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
275 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
276 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
278 { __DRI_IMAGE_FOURCC_YVU410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
279 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
280 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
281 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
283 { __DRI_IMAGE_FOURCC_YVU411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
284 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
285 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
286 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
288 { __DRI_IMAGE_FOURCC_YVU420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
289 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
290 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
291 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
293 { __DRI_IMAGE_FOURCC_YVU422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
294 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
295 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
296 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
298 { __DRI_IMAGE_FOURCC_YVU444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
299 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
300 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
301 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
303 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
304 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
305 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
307 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
308 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
309 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
311 /* For YUYV buffers, we set up two overlapping DRI images and treat
312 * them as planar buffers in the compositors. Plane 0 is GR88 and
313 * samples YU or YV pairs and places Y into the R component, while
314 * plane 1 is ARGB and samples YUYV clusters and places pairs and
315 * places U into the G component and V into A. This lets the
316 * texture sampler interpolate the Y components correctly when
317 * sampling from plane 0, and interpolate U and V correctly when
318 * sampling from plane 1. */
319 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
320 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
321 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
325 intel_image_warn_if_unaligned(__DRIimage
*image
, const char *func
)
327 uint32_t tiling
, swizzle
;
328 drm_intel_bo_get_tiling(image
->bo
, &tiling
, &swizzle
);
330 if (tiling
!= I915_TILING_NONE
&& (image
->offset
& 0xfff)) {
331 _mesa_warning(NULL
, "%s: offset 0x%08x not on tile boundary",
332 func
, image
->offset
);
336 static struct intel_image_format
*
337 intel_image_format_lookup(int fourcc
)
339 struct intel_image_format
*f
= NULL
;
341 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
342 if (intel_image_formats
[i
].fourcc
== fourcc
) {
343 f
= &intel_image_formats
[i
];
351 static boolean
intel_lookup_fourcc(int dri_format
, int *fourcc
)
353 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
354 if (intel_image_formats
[i
].planes
[0].dri_format
== dri_format
) {
355 *fourcc
= intel_image_formats
[i
].fourcc
;
363 intel_allocate_image(int dri_format
, void *loaderPrivate
)
367 image
= calloc(1, sizeof *image
);
371 image
->dri_format
= dri_format
;
374 image
->format
= driImageFormatToGLFormat(dri_format
);
375 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
376 image
->format
== MESA_FORMAT_NONE
) {
381 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
382 image
->data
= loaderPrivate
;
388 * Sets up a DRIImage structure to point to a slice out of a miptree.
391 intel_setup_image_from_mipmap_tree(struct brw_context
*brw
, __DRIimage
*image
,
392 struct intel_mipmap_tree
*mt
, GLuint level
,
395 intel_miptree_make_shareable(brw
, mt
);
397 intel_miptree_check_level_layer(mt
, level
, zoffset
);
399 image
->width
= minify(mt
->physical_width0
, level
- mt
->first_level
);
400 image
->height
= minify(mt
->physical_height0
, level
- mt
->first_level
);
401 image
->pitch
= mt
->pitch
;
403 image
->offset
= intel_miptree_get_tile_offsets(mt
, level
, zoffset
,
407 drm_intel_bo_unreference(image
->bo
);
409 drm_intel_bo_reference(mt
->bo
);
413 intel_create_image_from_name(__DRIscreen
*dri_screen
,
414 int width
, int height
, int format
,
415 int name
, int pitch
, void *loaderPrivate
)
417 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
421 image
= intel_allocate_image(format
, loaderPrivate
);
425 if (image
->format
== MESA_FORMAT_NONE
)
428 cpp
= _mesa_get_format_bytes(image
->format
);
430 image
->width
= width
;
431 image
->height
= height
;
432 image
->pitch
= pitch
* cpp
;
433 image
->bo
= drm_intel_bo_gem_create_from_name(screen
->bufmgr
, "image",
444 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
445 int renderbuffer
, void *loaderPrivate
)
448 struct brw_context
*brw
= context
->driverPrivate
;
449 struct gl_context
*ctx
= &brw
->ctx
;
450 struct gl_renderbuffer
*rb
;
451 struct intel_renderbuffer
*irb
;
453 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
455 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
459 irb
= intel_renderbuffer(rb
);
460 intel_miptree_make_shareable(brw
, irb
->mt
);
461 image
= calloc(1, sizeof *image
);
465 image
->internal_format
= rb
->InternalFormat
;
466 image
->format
= rb
->Format
;
468 image
->data
= loaderPrivate
;
469 drm_intel_bo_unreference(image
->bo
);
470 image
->bo
= irb
->mt
->bo
;
471 drm_intel_bo_reference(irb
->mt
->bo
);
472 image
->width
= rb
->Width
;
473 image
->height
= rb
->Height
;
474 image
->pitch
= irb
->mt
->pitch
;
475 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
476 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
478 rb
->NeedsFinishRenderTexture
= true;
483 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
484 unsigned texture
, int zoffset
,
490 struct brw_context
*brw
= context
->driverPrivate
;
491 struct gl_texture_object
*obj
;
492 struct intel_texture_object
*iobj
;
495 obj
= _mesa_lookup_texture(&brw
->ctx
, texture
);
496 if (!obj
|| obj
->Target
!= target
) {
497 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
501 if (target
== GL_TEXTURE_CUBE_MAP
)
504 _mesa_test_texobj_completeness(&brw
->ctx
, obj
);
505 iobj
= intel_texture_object(obj
);
506 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
507 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
511 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
512 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
516 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
517 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
520 image
= calloc(1, sizeof *image
);
522 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
526 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
527 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
528 image
->data
= loaderPrivate
;
529 intel_setup_image_from_mipmap_tree(brw
, image
, iobj
->mt
, level
, zoffset
);
530 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
531 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
532 if (image
->dri_format
== MESA_FORMAT_NONE
) {
533 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
538 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
543 intel_destroy_image(__DRIimage
*image
)
545 drm_intel_bo_unreference(image
->bo
);
550 intel_create_image(__DRIscreen
*dri_screen
,
551 int width
, int height
, int format
,
556 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
561 tiling
= I915_TILING_X
;
562 if (use
& __DRI_IMAGE_USE_CURSOR
) {
563 if (width
!= 64 || height
!= 64)
565 tiling
= I915_TILING_NONE
;
568 if (use
& __DRI_IMAGE_USE_LINEAR
)
569 tiling
= I915_TILING_NONE
;
571 image
= intel_allocate_image(format
, loaderPrivate
);
575 cpp
= _mesa_get_format_bytes(image
->format
);
576 image
->bo
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "image",
577 width
, height
, cpp
, &tiling
,
579 if (image
->bo
== NULL
) {
583 image
->width
= width
;
584 image
->height
= height
;
585 image
->pitch
= pitch
;
591 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
594 case __DRI_IMAGE_ATTRIB_STRIDE
:
595 *value
= image
->pitch
;
597 case __DRI_IMAGE_ATTRIB_HANDLE
:
598 *value
= image
->bo
->handle
;
600 case __DRI_IMAGE_ATTRIB_NAME
:
601 return !drm_intel_bo_flink(image
->bo
, (uint32_t *) value
);
602 case __DRI_IMAGE_ATTRIB_FORMAT
:
603 *value
= image
->dri_format
;
605 case __DRI_IMAGE_ATTRIB_WIDTH
:
606 *value
= image
->width
;
608 case __DRI_IMAGE_ATTRIB_HEIGHT
:
609 *value
= image
->height
;
611 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
612 if (image
->planar_format
== NULL
)
614 *value
= image
->planar_format
->components
;
616 case __DRI_IMAGE_ATTRIB_FD
:
617 return !drm_intel_bo_gem_export_to_prime(image
->bo
, value
);
618 case __DRI_IMAGE_ATTRIB_FOURCC
:
619 return intel_lookup_fourcc(image
->dri_format
, value
);
620 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
623 case __DRI_IMAGE_ATTRIB_OFFSET
:
624 *value
= image
->offset
;
633 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
637 image
= calloc(1, sizeof *image
);
641 drm_intel_bo_reference(orig_image
->bo
);
642 image
->bo
= orig_image
->bo
;
643 image
->internal_format
= orig_image
->internal_format
;
644 image
->planar_format
= orig_image
->planar_format
;
645 image
->dri_format
= orig_image
->dri_format
;
646 image
->format
= orig_image
->format
;
647 image
->offset
= orig_image
->offset
;
648 image
->width
= orig_image
->width
;
649 image
->height
= orig_image
->height
;
650 image
->pitch
= orig_image
->pitch
;
651 image
->tile_x
= orig_image
->tile_x
;
652 image
->tile_y
= orig_image
->tile_y
;
653 image
->has_depthstencil
= orig_image
->has_depthstencil
;
654 image
->data
= loaderPrivate
;
656 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
657 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
663 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
665 if (use
& __DRI_IMAGE_USE_CURSOR
) {
666 if (image
->width
!= 64 || image
->height
!= 64)
674 intel_create_image_from_names(__DRIscreen
*dri_screen
,
675 int width
, int height
, int fourcc
,
676 int *names
, int num_names
,
677 int *strides
, int *offsets
,
680 struct intel_image_format
*f
= NULL
;
684 if (dri_screen
== NULL
|| names
== NULL
|| num_names
!= 1)
687 f
= intel_image_format_lookup(fourcc
);
691 image
= intel_create_image_from_name(dri_screen
, width
, height
,
692 __DRI_IMAGE_FORMAT_NONE
,
693 names
[0], strides
[0],
699 image
->planar_format
= f
;
700 for (i
= 0; i
< f
->nplanes
; i
++) {
701 index
= f
->planes
[i
].buffer_index
;
702 image
->offsets
[index
] = offsets
[index
];
703 image
->strides
[index
] = strides
[index
];
710 intel_create_image_from_fds(__DRIscreen
*dri_screen
,
711 int width
, int height
, int fourcc
,
712 int *fds
, int num_fds
, int *strides
, int *offsets
,
715 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
716 struct intel_image_format
*f
;
720 if (fds
== NULL
|| num_fds
< 1)
723 /* We only support all planes from the same bo */
724 for (i
= 0; i
< num_fds
; i
++)
725 if (fds
[0] != fds
[i
])
728 f
= intel_image_format_lookup(fourcc
);
733 image
= intel_allocate_image(f
->planes
[0].dri_format
, loaderPrivate
);
735 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
740 image
->width
= width
;
741 image
->height
= height
;
742 image
->pitch
= strides
[0];
744 image
->planar_format
= f
;
746 for (i
= 0; i
< f
->nplanes
; i
++) {
747 index
= f
->planes
[i
].buffer_index
;
748 image
->offsets
[index
] = offsets
[index
];
749 image
->strides
[index
] = strides
[index
];
751 const int plane_height
= height
>> f
->planes
[i
].height_shift
;
752 const int end
= offsets
[index
] + plane_height
* strides
[index
];
757 image
->bo
= drm_intel_bo_gem_create_from_prime(screen
->bufmgr
,
759 if (image
->bo
== NULL
) {
764 if (f
->nplanes
== 1) {
765 image
->offset
= image
->offsets
[0];
766 intel_image_warn_if_unaligned(image
, __func__
);
773 intel_create_image_from_dma_bufs(__DRIscreen
*dri_screen
,
774 int width
, int height
, int fourcc
,
775 int *fds
, int num_fds
,
776 int *strides
, int *offsets
,
777 enum __DRIYUVColorSpace yuv_color_space
,
778 enum __DRISampleRange sample_range
,
779 enum __DRIChromaSiting horizontal_siting
,
780 enum __DRIChromaSiting vertical_siting
,
785 struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
788 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
792 image
= intel_create_image_from_fds(dri_screen
, width
, height
, fourcc
, fds
,
793 num_fds
, strides
, offsets
,
797 * Invalid parameters and any inconsistencies between are assumed to be
798 * checked by the caller. Therefore besides unsupported formats one can fail
799 * only in allocation.
802 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
806 image
->dma_buf_imported
= true;
807 image
->yuv_color_space
= yuv_color_space
;
808 image
->sample_range
= sample_range
;
809 image
->horizontal_siting
= horizontal_siting
;
810 image
->vertical_siting
= vertical_siting
;
812 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
817 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
819 int width
, height
, offset
, stride
, dri_format
, index
;
820 struct intel_image_format
*f
;
823 if (parent
== NULL
|| parent
->planar_format
== NULL
)
826 f
= parent
->planar_format
;
828 if (plane
>= f
->nplanes
)
831 width
= parent
->width
>> f
->planes
[plane
].width_shift
;
832 height
= parent
->height
>> f
->planes
[plane
].height_shift
;
833 dri_format
= f
->planes
[plane
].dri_format
;
834 index
= f
->planes
[plane
].buffer_index
;
835 offset
= parent
->offsets
[index
];
836 stride
= parent
->strides
[index
];
838 image
= intel_allocate_image(dri_format
, loaderPrivate
);
842 if (offset
+ height
* stride
> parent
->bo
->size
) {
843 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
848 image
->bo
= parent
->bo
;
849 drm_intel_bo_reference(parent
->bo
);
851 image
->width
= width
;
852 image
->height
= height
;
853 image
->pitch
= stride
;
854 image
->offset
= offset
;
856 intel_image_warn_if_unaligned(image
, __func__
);
861 static const __DRIimageExtension intelImageExtension
= {
862 .base
= { __DRI_IMAGE
, 13 },
864 .createImageFromName
= intel_create_image_from_name
,
865 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
866 .destroyImage
= intel_destroy_image
,
867 .createImage
= intel_create_image
,
868 .queryImage
= intel_query_image
,
869 .dupImage
= intel_dup_image
,
870 .validateUsage
= intel_validate_usage
,
871 .createImageFromNames
= intel_create_image_from_names
,
872 .fromPlanar
= intel_from_planar
,
873 .createImageFromTexture
= intel_create_image_from_texture
,
874 .createImageFromFds
= intel_create_image_from_fds
,
875 .createImageFromDmaBufs
= intel_create_image_from_dma_bufs
,
877 .getCapabilities
= NULL
,
883 brw_query_renderer_integer(__DRIscreen
*dri_screen
,
884 int param
, unsigned int *value
)
886 const struct intel_screen
*const screen
=
887 (struct intel_screen
*) dri_screen
->driverPrivate
;
890 case __DRI2_RENDERER_VENDOR_ID
:
893 case __DRI2_RENDERER_DEVICE_ID
:
894 value
[0] = screen
->deviceID
;
896 case __DRI2_RENDERER_ACCELERATED
:
899 case __DRI2_RENDERER_VIDEO_MEMORY
: {
900 /* Once a batch uses more than 75% of the maximum mappable size, we
901 * assume that there's some fragmentation, and we start doing extra
902 * flushing, etc. That's the big cliff apps will care about.
905 size_t mappable_size
;
907 drm_intel_get_aperture_sizes(dri_screen
->fd
, &mappable_size
, &aper_size
);
909 const unsigned gpu_mappable_megabytes
=
910 (aper_size
/ (1024 * 1024)) * 3 / 4;
912 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
913 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
915 if (system_memory_pages
<= 0 || system_page_size
<= 0)
918 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
919 * (uint64_t) system_page_size
;
921 const unsigned system_memory_megabytes
=
922 (unsigned) (system_memory_bytes
/ (1024 * 1024));
924 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
927 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
930 case __DRI2_RENDERER_HAS_TEXTURE_3D
:
934 return driQueryRendererIntegerCommon(dri_screen
, param
, value
);
941 brw_query_renderer_string(__DRIscreen
*dri_screen
,
942 int param
, const char **value
)
944 const struct intel_screen
*screen
=
945 (struct intel_screen
*) dri_screen
->driverPrivate
;
948 case __DRI2_RENDERER_VENDOR_ID
:
949 value
[0] = brw_vendor_string
;
951 case __DRI2_RENDERER_DEVICE_ID
:
952 value
[0] = brw_get_renderer_string(screen
);
961 static const __DRI2rendererQueryExtension intelRendererQueryExtension
= {
962 .base
= { __DRI2_RENDERER_QUERY
, 1 },
964 .queryInteger
= brw_query_renderer_integer
,
965 .queryString
= brw_query_renderer_string
968 static const __DRIrobustnessExtension dri2Robustness
= {
969 .base
= { __DRI2_ROBUSTNESS
, 1 }
972 static const __DRIextension
*screenExtensions
[] = {
973 &intelTexBufferExtension
.base
,
974 &intelFenceExtension
.base
,
975 &intelFlushExtension
.base
,
976 &intelImageExtension
.base
,
977 &intelRendererQueryExtension
.base
,
978 &dri2ConfigQueryExtension
.base
,
982 static const __DRIextension
*intelRobustScreenExtensions
[] = {
983 &intelTexBufferExtension
.base
,
984 &intelFenceExtension
.base
,
985 &intelFlushExtension
.base
,
986 &intelImageExtension
.base
,
987 &intelRendererQueryExtension
.base
,
988 &dri2ConfigQueryExtension
.base
,
989 &dri2Robustness
.base
,
994 intel_get_param(struct intel_screen
*screen
, int param
, int *value
)
997 struct drm_i915_getparam gp
;
999 memset(&gp
, 0, sizeof(gp
));
1003 if (drmIoctl(screen
->driScrnPriv
->fd
, DRM_IOCTL_I915_GETPARAM
, &gp
) == -1) {
1006 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
1013 intel_get_boolean(struct intel_screen
*screen
, int param
)
1016 return (intel_get_param(screen
, param
, &value
) == 0) && value
;
1020 intel_get_integer(struct intel_screen
*screen
, int param
)
1024 if (intel_get_param(screen
, param
, &value
) == 0)
1031 intelDestroyScreen(__DRIscreen
* sPriv
)
1033 struct intel_screen
*screen
= sPriv
->driverPrivate
;
1035 dri_bufmgr_destroy(screen
->bufmgr
);
1036 driDestroyOptionInfo(&screen
->optionCache
);
1038 ralloc_free(screen
);
1039 sPriv
->driverPrivate
= NULL
;
1044 * This is called when we need to set up GL rendering to a new X window.
1047 intelCreateBuffer(__DRIscreen
*dri_screen
,
1048 __DRIdrawable
* driDrawPriv
,
1049 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
1051 struct intel_renderbuffer
*rb
;
1052 struct intel_screen
*screen
= (struct intel_screen
*)
1053 dri_screen
->driverPrivate
;
1054 mesa_format rgbFormat
;
1055 unsigned num_samples
=
1056 intel_quantize_num_samples(screen
, mesaVis
->samples
);
1057 struct gl_framebuffer
*fb
;
1062 fb
= CALLOC_STRUCT(gl_framebuffer
);
1066 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
1068 if (screen
->winsys_msaa_samples_override
!= -1) {
1069 num_samples
= screen
->winsys_msaa_samples_override
;
1070 fb
->Visual
.samples
= num_samples
;
1073 if (mesaVis
->redBits
== 5) {
1074 rgbFormat
= mesaVis
->redMask
== 0x1f ? MESA_FORMAT_R5G6B5_UNORM
1075 : MESA_FORMAT_B5G6R5_UNORM
;
1076 } else if (mesaVis
->sRGBCapable
) {
1077 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1078 : MESA_FORMAT_B8G8R8A8_SRGB
;
1079 } else if (mesaVis
->alphaBits
== 0) {
1080 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8X8_UNORM
1081 : MESA_FORMAT_B8G8R8X8_UNORM
;
1083 rgbFormat
= mesaVis
->redMask
== 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1084 : MESA_FORMAT_B8G8R8A8_SRGB
;
1085 fb
->Visual
.sRGBCapable
= true;
1088 /* setup the hardware-based renderbuffers */
1089 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
1090 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
1092 if (mesaVis
->doubleBufferMode
) {
1093 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
1094 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
1098 * Assert here that the gl_config has an expected depth/stencil bit
1099 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
1100 * which constructs the advertised configs.)
1102 if (mesaVis
->depthBits
== 24) {
1103 assert(mesaVis
->stencilBits
== 8);
1105 if (screen
->devinfo
.has_hiz_and_separate_stencil
) {
1106 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_X8_UINT
,
1108 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1109 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S_UINT8
,
1111 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1114 * Use combined depth/stencil. Note that the renderbuffer is
1115 * attached to two attachment points.
1117 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_S8_UINT
,
1119 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1120 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
1123 else if (mesaVis
->depthBits
== 16) {
1124 assert(mesaVis
->stencilBits
== 0);
1125 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z_UNORM16
,
1127 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
1130 assert(mesaVis
->depthBits
== 0);
1131 assert(mesaVis
->stencilBits
== 0);
1134 /* now add any/all software-based renderbuffers we may need */
1135 _swrast_add_soft_renderbuffers(fb
,
1136 false, /* never sw color */
1137 false, /* never sw depth */
1138 false, /* never sw stencil */
1139 mesaVis
->accumRedBits
> 0,
1140 false, /* never sw alpha */
1141 false /* never sw aux */ );
1142 driDrawPriv
->driverPrivate
= fb
;
1148 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
1150 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
1152 _mesa_reference_framebuffer(&fb
, NULL
);
1156 intel_detect_sseu(struct intel_screen
*screen
)
1158 assert(screen
->devinfo
.gen
>= 8);
1161 screen
->subslice_total
= -1;
1162 screen
->eu_total
= -1;
1164 ret
= intel_get_param(screen
, I915_PARAM_SUBSLICE_TOTAL
,
1165 &screen
->subslice_total
);
1166 if (ret
< 0 && ret
!= -EINVAL
)
1169 ret
= intel_get_param(screen
,
1170 I915_PARAM_EU_TOTAL
, &screen
->eu_total
);
1171 if (ret
< 0 && ret
!= -EINVAL
)
1174 /* Without this information, we cannot get the right Braswell brandstrings,
1175 * and we have to use conservative numbers for GPGPU on many platforms, but
1176 * otherwise, things will just work.
1178 if (screen
->subslice_total
< 1 || screen
->eu_total
< 1)
1180 "Kernel 4.1 required to properly query GPU properties.\n");
1185 screen
->subslice_total
= -1;
1186 screen
->eu_total
= -1;
1187 _mesa_warning(NULL
, "Failed to query GPU properties (%s).\n", strerror(-ret
));
1191 intel_init_bufmgr(struct intel_screen
*screen
)
1193 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
1195 screen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
1197 screen
->bufmgr
= intel_bufmgr_gem_init(dri_screen
->fd
, BATCH_SZ
);
1198 if (screen
->bufmgr
== NULL
) {
1199 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1200 __func__
, __LINE__
);
1204 drm_intel_bufmgr_gem_enable_fenced_relocs(screen
->bufmgr
);
1206 if (!intel_get_boolean(screen
, I915_PARAM_HAS_RELAXED_DELTA
)) {
1207 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
1215 intel_detect_swizzling(struct intel_screen
*screen
)
1217 drm_intel_bo
*buffer
;
1218 unsigned long flags
= 0;
1219 unsigned long aligned_pitch
;
1220 uint32_t tiling
= I915_TILING_X
;
1221 uint32_t swizzle_mode
= 0;
1223 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
1225 &tiling
, &aligned_pitch
, flags
);
1229 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1230 drm_intel_bo_unreference(buffer
);
1232 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
1239 intel_detect_timestamp(struct intel_screen
*screen
)
1241 uint64_t dummy
= 0, last
= 0;
1242 int upper
, lower
, loops
;
1244 /* On 64bit systems, some old kernels trigger a hw bug resulting in the
1245 * TIMESTAMP register being shifted and the low 32bits always zero.
1247 * More recent kernels offer an interface to read the full 36bits
1250 if (drm_intel_reg_read(screen
->bufmgr
, TIMESTAMP
| 1, &dummy
) == 0)
1253 /* Determine if we have a 32bit or 64bit kernel by inspecting the
1254 * upper 32bits for a rapidly changing timestamp.
1256 if (drm_intel_reg_read(screen
->bufmgr
, TIMESTAMP
, &last
))
1260 for (loops
= 0; loops
< 10; loops
++) {
1261 /* The TIMESTAMP should change every 80ns, so several round trips
1262 * through the kernel should be enough to advance it.
1264 if (drm_intel_reg_read(screen
->bufmgr
, TIMESTAMP
, &dummy
))
1267 upper
+= (dummy
>> 32) != (last
>> 32);
1268 if (upper
> 1) /* beware 32bit counter overflow */
1269 return 2; /* upper dword holds the low 32bits of the timestamp */
1271 lower
+= (dummy
& 0xffffffff) != (last
& 0xffffffff);
1273 return 1; /* timestamp is unshifted */
1278 /* No advancement? No timestamp! */
1283 * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer.
1285 * Some combinations of hardware and kernel versions allow this feature,
1286 * while others don't. Instead of trying to enumerate every case, just
1287 * try and write a register and see if works.
1290 intel_detect_pipelined_register(struct intel_screen
*screen
,
1291 int reg
, uint32_t expected_value
, bool reset
)
1293 drm_intel_bo
*results
, *bo
;
1295 uint32_t offset
= 0;
1296 bool success
= false;
1298 /* Create a zero'ed temporary buffer for reading our results */
1299 results
= drm_intel_bo_alloc(screen
->bufmgr
, "registers", 4096, 0);
1300 if (results
== NULL
)
1303 bo
= drm_intel_bo_alloc(screen
->bufmgr
, "batchbuffer", 4096, 0);
1307 if (drm_intel_bo_map(bo
, 1))
1310 batch
= bo
->virtual;
1312 /* Write the register. */
1313 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
1315 *batch
++ = expected_value
;
1317 /* Save the register's value back to the buffer. */
1318 *batch
++ = MI_STORE_REGISTER_MEM
| (3 - 2);
1320 drm_intel_bo_emit_reloc(bo
, (char *)batch
-(char *)bo
->virtual,
1321 results
, offset
*sizeof(uint32_t),
1322 I915_GEM_DOMAIN_INSTRUCTION
,
1323 I915_GEM_DOMAIN_INSTRUCTION
);
1324 *batch
++ = results
->offset
+ offset
*sizeof(uint32_t);
1326 /* And afterwards clear the register */
1328 *batch
++ = MI_LOAD_REGISTER_IMM
| (3 - 2);
1333 *batch
++ = MI_BATCH_BUFFER_END
;
1335 drm_intel_bo_mrb_exec(bo
, ALIGN((char *)batch
- (char *)bo
->virtual, 8),
1339 /* Check whether the value got written. */
1340 if (drm_intel_bo_map(results
, false) == 0) {
1341 success
= *((uint32_t *)results
->virtual + offset
) == expected_value
;
1342 drm_intel_bo_unmap(results
);
1346 drm_intel_bo_unreference(bo
);
1348 drm_intel_bo_unreference(results
);
1354 intel_detect_pipelined_so(struct intel_screen
*screen
)
1356 /* Supposedly, Broadwell just works. */
1357 if (screen
->devinfo
.gen
>= 8)
1360 if (screen
->devinfo
.gen
<= 6)
1363 /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the
1364 * statistics registers), and we already reset it to zero before using it.
1366 return intel_detect_pipelined_register(screen
,
1367 GEN7_SO_WRITE_OFFSET(0),
1373 * Return array of MSAA modes supported by the hardware. The array is
1374 * zero-terminated and sorted in decreasing order.
1377 intel_supported_msaa_modes(const struct intel_screen
*screen
)
1379 static const int gen9_modes
[] = {16, 8, 4, 2, 0, -1};
1380 static const int gen8_modes
[] = {8, 4, 2, 0, -1};
1381 static const int gen7_modes
[] = {8, 4, 0, -1};
1382 static const int gen6_modes
[] = {4, 0, -1};
1383 static const int gen4_modes
[] = {0, -1};
1385 if (screen
->devinfo
.gen
>= 9) {
1387 } else if (screen
->devinfo
.gen
>= 8) {
1389 } else if (screen
->devinfo
.gen
>= 7) {
1391 } else if (screen
->devinfo
.gen
== 6) {
1398 static __DRIconfig
**
1399 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1401 static const mesa_format formats
[] = {
1402 MESA_FORMAT_B5G6R5_UNORM
,
1403 MESA_FORMAT_B8G8R8A8_UNORM
,
1404 MESA_FORMAT_B8G8R8X8_UNORM
1407 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1408 static const GLenum back_buffer_modes
[] = {
1409 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1412 static const uint8_t singlesample_samples
[1] = {0};
1413 static const uint8_t multisample_samples
[2] = {4, 8};
1415 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1416 const struct gen_device_info
*devinfo
= &screen
->devinfo
;
1417 uint8_t depth_bits
[4], stencil_bits
[4];
1418 __DRIconfig
**configs
= NULL
;
1420 /* Generate singlesample configs without accumulation buffer. */
1421 for (unsigned i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1422 __DRIconfig
**new_configs
;
1423 int num_depth_stencil_bits
= 2;
1425 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1426 * buffer that has a different number of bits per pixel than the color
1427 * buffer, gen >= 6 supports this.
1430 stencil_bits
[0] = 0;
1432 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
1434 stencil_bits
[1] = 0;
1435 if (devinfo
->gen
>= 6) {
1437 stencil_bits
[2] = 8;
1438 num_depth_stencil_bits
= 3;
1442 stencil_bits
[1] = 8;
1445 new_configs
= driCreateConfigs(formats
[i
],
1448 num_depth_stencil_bits
,
1449 back_buffer_modes
, 2,
1450 singlesample_samples
, 1,
1452 configs
= driConcatConfigs(configs
, new_configs
);
1455 /* Generate the minimum possible set of configs that include an
1456 * accumulation buffer.
1458 for (unsigned i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1459 __DRIconfig
**new_configs
;
1461 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
1463 stencil_bits
[0] = 0;
1466 stencil_bits
[0] = 8;
1469 new_configs
= driCreateConfigs(formats
[i
],
1470 depth_bits
, stencil_bits
, 1,
1471 back_buffer_modes
, 1,
1472 singlesample_samples
, 1,
1474 configs
= driConcatConfigs(configs
, new_configs
);
1477 /* Generate multisample configs.
1479 * This loop breaks early, and hence is a no-op, on gen < 6.
1481 * Multisample configs must follow the singlesample configs in order to
1482 * work around an X server bug present in 1.12. The X server chooses to
1483 * associate the first listed RGBA888-Z24S8 config, regardless of its
1484 * sample count, with the 32-bit depth visual used for compositing.
1486 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
1487 * supported. Singlebuffer configs are not supported because no one wants
1490 for (unsigned i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1491 if (devinfo
->gen
< 6)
1494 __DRIconfig
**new_configs
;
1495 const int num_depth_stencil_bits
= 2;
1496 int num_msaa_modes
= 0;
1499 stencil_bits
[0] = 0;
1501 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
1503 stencil_bits
[1] = 0;
1506 stencil_bits
[1] = 8;
1509 if (devinfo
->gen
>= 7)
1511 else if (devinfo
->gen
== 6)
1514 new_configs
= driCreateConfigs(formats
[i
],
1517 num_depth_stencil_bits
,
1518 back_buffer_modes
, 1,
1519 multisample_samples
,
1522 configs
= driConcatConfigs(configs
, new_configs
);
1525 if (configs
== NULL
) {
1526 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1535 set_max_gl_versions(struct intel_screen
*screen
)
1537 __DRIscreen
*dri_screen
= screen
->driScrnPriv
;
1538 const bool has_astc
= screen
->devinfo
.gen
>= 9;
1540 switch (screen
->devinfo
.gen
) {
1543 dri_screen
->max_gl_core_version
= 45;
1544 dri_screen
->max_gl_compat_version
= 30;
1545 dri_screen
->max_gl_es1_version
= 11;
1546 dri_screen
->max_gl_es2_version
= has_astc
? 32 : 31;
1549 dri_screen
->max_gl_core_version
= screen
->devinfo
.is_haswell
&&
1550 can_do_pipelined_register_writes(screen
) ? 45 : 33;
1551 dri_screen
->max_gl_compat_version
= 30;
1552 dri_screen
->max_gl_es1_version
= 11;
1553 dri_screen
->max_gl_es2_version
= screen
->devinfo
.is_haswell
? 31 : 30;
1556 dri_screen
->max_gl_core_version
= 33;
1557 dri_screen
->max_gl_compat_version
= 30;
1558 dri_screen
->max_gl_es1_version
= 11;
1559 dri_screen
->max_gl_es2_version
= 30;
1563 dri_screen
->max_gl_core_version
= 0;
1564 dri_screen
->max_gl_compat_version
= 21;
1565 dri_screen
->max_gl_es1_version
= 11;
1566 dri_screen
->max_gl_es2_version
= 20;
1569 unreachable("unrecognized intel_screen::gen");
1574 * Return the revision (generally the revid field of the PCI header) of the
1577 * XXX: This function is useful to keep around even if it is not currently in
1578 * use. It is necessary for new platforms and revision specific workarounds or
1579 * features. Please don't remove it so that we know it at least continues to
1582 static __attribute__((__unused__
)) int
1583 brw_get_revision(int fd
)
1585 struct drm_i915_getparam gp
;
1589 memset(&gp
, 0, sizeof(gp
));
1590 gp
.param
= I915_PARAM_REVISION
;
1591 gp
.value
= &revision
;
1593 ret
= drmCommandWriteRead(fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
1600 /* Drop when RS headers get pulled to libdrm */
1601 #ifndef I915_PARAM_HAS_RESOURCE_STREAMER
1602 #define I915_PARAM_HAS_RESOURCE_STREAMER 36
1606 shader_debug_log_mesa(void *data
, const char *fmt
, ...)
1608 struct brw_context
*brw
= (struct brw_context
*)data
;
1611 va_start(args
, fmt
);
1613 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
1614 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
1615 MESA_DEBUG_TYPE_OTHER
,
1616 MESA_DEBUG_SEVERITY_NOTIFICATION
, fmt
, args
);
1621 shader_perf_log_mesa(void *data
, const char *fmt
, ...)
1623 struct brw_context
*brw
= (struct brw_context
*)data
;
1626 va_start(args
, fmt
);
1628 if (unlikely(INTEL_DEBUG
& DEBUG_PERF
)) {
1630 va_copy(args_copy
, args
);
1631 vfprintf(stderr
, fmt
, args_copy
);
1635 if (brw
->perf_debug
) {
1637 _mesa_gl_vdebug(&brw
->ctx
, &msg_id
,
1638 MESA_DEBUG_SOURCE_SHADER_COMPILER
,
1639 MESA_DEBUG_TYPE_PERFORMANCE
,
1640 MESA_DEBUG_SEVERITY_MEDIUM
, fmt
, args
);
1646 * This is the driver specific part of the createNewScreen entry point.
1647 * Called when using DRI2.
1649 * \return the struct gl_config supported by this driver
1652 __DRIconfig
**intelInitScreen2(__DRIscreen
*dri_screen
)
1654 struct intel_screen
*screen
;
1656 if (dri_screen
->image
.loader
) {
1657 } else if (dri_screen
->dri2
.loader
->base
.version
<= 2 ||
1658 dri_screen
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1660 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1661 "support required\n");
1665 /* Allocate the private area */
1666 screen
= rzalloc(NULL
, struct intel_screen
);
1668 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1671 /* parse information in __driConfigOptions */
1672 driParseOptionInfo(&screen
->optionCache
, brw_config_options
.xml
);
1674 screen
->driScrnPriv
= dri_screen
;
1675 dri_screen
->driverPrivate
= (void *) screen
;
1677 if (!intel_init_bufmgr(screen
))
1680 screen
->deviceID
= drm_intel_bufmgr_gem_get_devid(screen
->bufmgr
);
1681 if (!gen_get_device_info(screen
->deviceID
, &screen
->devinfo
))
1684 brw_process_intel_debug_variable();
1686 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1687 dri_bufmgr_set_debug(screen
->bufmgr
, true);
1689 if ((INTEL_DEBUG
& DEBUG_SHADER_TIME
) && screen
->devinfo
.gen
< 7) {
1691 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
1692 INTEL_DEBUG
&= ~DEBUG_SHADER_TIME
;
1695 if (INTEL_DEBUG
& DEBUG_AUB
)
1696 drm_intel_bufmgr_gem_set_aub_dump(screen
->bufmgr
, true);
1698 #ifndef I915_PARAM_MMAP_GTT_VERSION
1699 #define I915_PARAM_MMAP_GTT_VERSION 40 /* XXX delete me with new libdrm */
1701 if (intel_get_integer(screen
, I915_PARAM_MMAP_GTT_VERSION
) >= 1) {
1702 /* Theorectically unlimited! At least for individual objects...
1704 * Currently the entire (global) address space for all GTT maps is
1705 * limited to 64bits. That is all objects on the system that are
1706 * setup for GTT mmapping must fit within 64bits. An attempt to use
1707 * one that exceeds the limit with fail in drm_intel_bo_map_gtt().
1709 * Long before we hit that limit, we will be practically limited by
1710 * that any single object must fit in physical memory (RAM). The upper
1711 * limit on the CPU's address space is currently 48bits (Skylake), of
1712 * which only 39bits can be physical memory. (The GPU itself also has
1713 * a 48bit addressable virtual space.) We can fit over 32 million
1714 * objects of the current maximum allocable size before running out
1717 screen
->max_gtt_map_object_size
= UINT64_MAX
;
1719 /* Estimate the size of the mappable aperture into the GTT. There's an
1720 * ioctl to get the whole GTT size, but not one to get the mappable subset.
1721 * It turns out it's basically always 256MB, though some ancient hardware
1724 uint32_t gtt_size
= 256 * 1024 * 1024;
1726 /* We don't want to map two objects such that a memcpy between them would
1727 * just fault one mapping in and then the other over and over forever. So
1728 * we would need to divide the GTT size by 2. Additionally, some GTT is
1729 * taken up by things like the framebuffer and the ringbuffer and such, so
1730 * be more conservative.
1732 screen
->max_gtt_map_object_size
= gtt_size
/ 4;
1735 screen
->hw_has_swizzling
= intel_detect_swizzling(screen
);
1736 screen
->hw_has_timestamp
= intel_detect_timestamp(screen
);
1738 /* GENs prior to 8 do not support EU/Subslice info */
1739 if (screen
->devinfo
.gen
>= 8) {
1740 intel_detect_sseu(screen
);
1741 } else if (screen
->devinfo
.gen
== 7) {
1742 screen
->subslice_total
= 1 << (screen
->devinfo
.gt
- 1);
1745 if (intel_detect_pipelined_so(screen
))
1746 screen
->kernel_features
|= KERNEL_ALLOWS_SOL_OFFSET_WRITES
;
1748 const char *force_msaa
= getenv("INTEL_FORCE_MSAA");
1750 screen
->winsys_msaa_samples_override
=
1751 intel_quantize_num_samples(screen
, atoi(force_msaa
));
1752 printf("Forcing winsys sample count to %d\n",
1753 screen
->winsys_msaa_samples_override
);
1755 screen
->winsys_msaa_samples_override
= -1;
1758 set_max_gl_versions(screen
);
1760 /* Notification of GPU resets requires hardware contexts and a kernel new
1761 * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is
1762 * supported, calling it with a context of 0 will either generate EPERM or
1763 * no error. If the ioctl is not supported, it always generate EINVAL.
1764 * Use this to determine whether to advertise the __DRI2_ROBUSTNESS
1765 * extension to the loader.
1767 * Don't even try on pre-Gen6, since we don't attempt to use contexts there.
1769 if (screen
->devinfo
.gen
>= 6) {
1770 struct drm_i915_reset_stats stats
;
1771 memset(&stats
, 0, sizeof(stats
));
1773 const int ret
= drmIoctl(dri_screen
->fd
, DRM_IOCTL_I915_GET_RESET_STATS
, &stats
);
1775 screen
->has_context_reset_notification
=
1776 (ret
!= -1 || errno
!= EINVAL
);
1779 if (intel_get_param(screen
, I915_PARAM_CMD_PARSER_VERSION
,
1780 &screen
->cmd_parser_version
) < 0) {
1781 screen
->cmd_parser_version
= 0;
1784 if (screen
->devinfo
.gen
>= 8 || screen
->cmd_parser_version
>= 2)
1785 screen
->kernel_features
|= KERNEL_ALLOWS_PREDICATE_WRITES
;
1787 /* Haswell requires command parser version 4 in order to have L3
1788 * atomic scratch1 and chicken3 bits
1790 if (screen
->devinfo
.is_haswell
&& screen
->cmd_parser_version
>= 4) {
1791 screen
->kernel_features
|=
1792 KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3
;
1795 /* Haswell requires command parser version 6 in order to write to the
1796 * MI_MATH GPR registers, and version 7 in order to use
1797 * MI_LOAD_REGISTER_REG (which all users of MI_MATH use).
1799 if (screen
->devinfo
.gen
>= 8 ||
1800 (screen
->devinfo
.is_haswell
&& screen
->cmd_parser_version
>= 7)) {
1801 screen
->kernel_features
|= KERNEL_ALLOWS_MI_MATH_AND_LRR
;
1804 /* Gen7 needs at least command parser version 5 to support compute */
1805 if (screen
->devinfo
.gen
>= 8 || screen
->cmd_parser_version
>= 5)
1806 screen
->kernel_features
|= KERNEL_ALLOWS_COMPUTE_DISPATCH
;
1808 dri_screen
->extensions
= !screen
->has_context_reset_notification
1809 ? screenExtensions
: intelRobustScreenExtensions
;
1811 screen
->compiler
= brw_compiler_create(screen
,
1813 screen
->compiler
->shader_debug_log
= shader_debug_log_mesa
;
1814 screen
->compiler
->shader_perf_log
= shader_perf_log_mesa
;
1815 screen
->program_id
= 1;
1817 if (screen
->devinfo
.has_resource_streamer
) {
1818 screen
->has_resource_streamer
=
1819 intel_get_boolean(screen
, I915_PARAM_HAS_RESOURCE_STREAMER
);
1822 screen
->has_exec_fence
=
1823 intel_get_boolean(screen
, I915_PARAM_HAS_EXEC_FENCE
);
1825 return (const __DRIconfig
**) intel_screen_make_configs(dri_screen
);
1828 struct intel_buffer
{
1833 static __DRIbuffer
*
1834 intelAllocateBuffer(__DRIscreen
*dri_screen
,
1835 unsigned attachment
, unsigned format
,
1836 int width
, int height
)
1838 struct intel_buffer
*intelBuffer
;
1839 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1841 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1842 attachment
== __DRI_BUFFER_BACK_LEFT
);
1844 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1845 if (intelBuffer
== NULL
)
1848 /* The front and back buffers are color buffers, which are X tiled. */
1849 uint32_t tiling
= I915_TILING_X
;
1850 unsigned long pitch
;
1851 int cpp
= format
/ 8;
1852 intelBuffer
->bo
= drm_intel_bo_alloc_tiled(screen
->bufmgr
,
1853 "intelAllocateBuffer",
1858 BO_ALLOC_FOR_RENDER
);
1860 if (intelBuffer
->bo
== NULL
) {
1865 drm_intel_bo_flink(intelBuffer
->bo
, &intelBuffer
->base
.name
);
1867 intelBuffer
->base
.attachment
= attachment
;
1868 intelBuffer
->base
.cpp
= cpp
;
1869 intelBuffer
->base
.pitch
= pitch
;
1871 return &intelBuffer
->base
;
1875 intelReleaseBuffer(__DRIscreen
*dri_screen
, __DRIbuffer
*buffer
)
1877 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1879 drm_intel_bo_unreference(intelBuffer
->bo
);
1883 static const struct __DriverAPIRec brw_driver_api
= {
1884 .InitScreen
= intelInitScreen2
,
1885 .DestroyScreen
= intelDestroyScreen
,
1886 .CreateContext
= brwCreateContext
,
1887 .DestroyContext
= intelDestroyContext
,
1888 .CreateBuffer
= intelCreateBuffer
,
1889 .DestroyBuffer
= intelDestroyBuffer
,
1890 .MakeCurrent
= intelMakeCurrent
,
1891 .UnbindContext
= intelUnbindContext
,
1892 .AllocateBuffer
= intelAllocateBuffer
,
1893 .ReleaseBuffer
= intelReleaseBuffer
1896 static const struct __DRIDriverVtableExtensionRec brw_vtable
= {
1897 .base
= { __DRI_DRIVER_VTABLE
, 1 },
1898 .vtable
= &brw_driver_api
,
1901 static const __DRIextension
*brw_driver_extensions
[] = {
1902 &driCoreExtension
.base
,
1903 &driImageDriverExtension
.base
,
1904 &driDRI2Extension
.base
,
1906 &brw_config_options
.base
,
1910 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i965(void)
1912 globalDriverAPI
= &brw_driver_api
;
1914 return brw_driver_extensions
;