1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "main/glheader.h"
31 #include "main/context.h"
32 #include "main/framebuffer.h"
33 #include "main/renderbuffer.h"
34 #include "main/texobj.h"
35 #include "main/hash.h"
36 #include "main/fbobject.h"
37 #include "main/version.h"
38 #include "swrast/s_renderbuffer.h"
43 PUBLIC
const char __driConfigOptions
[] =
45 DRI_CONF_SECTION_PERFORMANCE
46 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
47 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
48 * DRI_CONF_BO_REUSE_ALL
50 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
51 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
52 DRI_CONF_ENUM(0, "Disable buffer object reuse")
53 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
57 DRI_CONF_OPT_BEGIN_B(hiz
, "true")
58 DRI_CONF_DESC(en
, "Enable Hierarchical Z on gen6+")
62 DRI_CONF_SECTION_QUALITY
63 DRI_CONF_FORCE_S3TC_ENABLE("false")
65 DRI_CONF_SECTION_DEBUG
66 DRI_CONF_NO_RAST("false")
67 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
68 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
69 DRI_CONF_DISABLE_THROTTLING("false")
70 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
71 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
72 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
74 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
75 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
80 #include "intel_batchbuffer.h"
81 #include "intel_buffers.h"
82 #include "intel_bufmgr.h"
83 #include "intel_chipset.h"
84 #include "intel_fbo.h"
85 #include "intel_mipmap_tree.h"
86 #include "intel_screen.h"
87 #include "intel_tex.h"
88 #include "intel_regions.h"
90 #include "brw_context.h"
94 #ifdef USE_NEW_INTERFACE
95 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
96 #endif /*USE_NEW_INTERFACE */
99 * For debugging purposes, this returns a time in seconds.
106 clock_gettime(CLOCK_MONOTONIC
, &tp
);
108 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
112 aub_dump_bmp(struct gl_context
*ctx
)
114 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
116 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
117 struct intel_renderbuffer
*irb
=
118 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
120 if (irb
&& irb
->mt
) {
121 enum aub_dump_bmp_format format
;
123 switch (irb
->Base
.Base
.Format
) {
124 case MESA_FORMAT_ARGB8888
:
125 case MESA_FORMAT_XRGB8888
:
126 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
132 assert(irb
->mt
->region
->pitch
% irb
->mt
->region
->cpp
== 0);
133 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
136 irb
->Base
.Base
.Width
,
137 irb
->Base
.Base
.Height
,
139 irb
->mt
->region
->pitch
,
145 static const __DRItexBufferExtension intelTexBufferExtension
= {
146 .base
= { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
148 .setTexBuffer
= intelSetTexBuffer
,
149 .setTexBuffer2
= intelSetTexBuffer2
,
150 .releaseTexBuffer
= NULL
,
154 intel_dri2_flush_with_flags(__DRIcontext
*cPriv
,
155 __DRIdrawable
*dPriv
,
157 enum __DRI2throttleReason reason
)
159 struct brw_context
*brw
= cPriv
->driverPrivate
;
164 struct gl_context
*ctx
= &brw
->ctx
;
166 FLUSH_VERTICES(ctx
, 0);
168 if (flags
& __DRI2_FLUSH_DRAWABLE
)
169 intel_resolve_for_dri2_flush(brw
, dPriv
);
171 if (reason
== __DRI2_THROTTLE_SWAPBUFFER
||
172 reason
== __DRI2_THROTTLE_FLUSHFRONT
) {
173 brw
->need_throttle
= true;
176 intel_batchbuffer_flush(brw
);
178 if (INTEL_DEBUG
& DEBUG_AUB
) {
184 * Provides compatibility with loaders that only support the older (version
185 * 1-3) flush interface.
187 * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13.
190 intel_dri2_flush(__DRIdrawable
*drawable
)
192 intel_dri2_flush_with_flags(drawable
->driContextPriv
, drawable
,
193 __DRI2_FLUSH_DRAWABLE
,
194 __DRI2_THROTTLE_SWAPBUFFER
);
197 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
198 .base
= { __DRI2_FLUSH
, 4 },
200 .flush
= intel_dri2_flush
,
201 .invalidate
= dri2InvalidateDrawable
,
202 .flush_with_flags
= intel_dri2_flush_with_flags
,
205 static struct intel_image_format intel_image_formats
[] = {
206 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
207 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
209 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
210 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
212 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
213 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
214 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
215 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
217 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
218 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
219 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
220 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
222 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
223 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
224 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
225 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
227 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
228 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
229 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
230 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
232 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
233 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
234 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
235 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
237 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
238 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
239 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
241 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
242 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
243 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
245 /* For YUYV buffers, we set up two overlapping DRI images and treat
246 * them as planar buffers in the compositors. Plane 0 is GR88 and
247 * samples YU or YV pairs and places Y into the R component, while
248 * plane 1 is ARGB and samples YUYV clusters and places pairs and
249 * places U into the G component and V into A. This lets the
250 * texture sampler interpolate the Y components correctly when
251 * sampling from plane 0, and interpolate U and V correctly when
252 * sampling from plane 1. */
253 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
254 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
255 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
258 static struct intel_image_format
*
259 intel_image_format_lookup(int fourcc
)
261 struct intel_image_format
*f
= NULL
;
263 for (unsigned i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
264 if (intel_image_formats
[i
].fourcc
== fourcc
) {
265 f
= &intel_image_formats
[i
];
274 intel_allocate_image(int dri_format
, void *loaderPrivate
)
278 image
= calloc(1, sizeof *image
);
282 image
->dri_format
= dri_format
;
285 switch (dri_format
) {
286 case __DRI_IMAGE_FORMAT_RGB565
:
287 image
->format
= MESA_FORMAT_RGB565
;
289 case __DRI_IMAGE_FORMAT_XRGB8888
:
290 image
->format
= MESA_FORMAT_XRGB8888
;
292 case __DRI_IMAGE_FORMAT_ARGB8888
:
293 image
->format
= MESA_FORMAT_ARGB8888
;
295 case __DRI_IMAGE_FORMAT_ABGR8888
:
296 image
->format
= MESA_FORMAT_RGBA8888_REV
;
298 case __DRI_IMAGE_FORMAT_XBGR8888
:
299 image
->format
= MESA_FORMAT_RGBX8888_REV
;
301 case __DRI_IMAGE_FORMAT_R8
:
302 image
->format
= MESA_FORMAT_R8
;
304 case __DRI_IMAGE_FORMAT_GR88
:
305 image
->format
= MESA_FORMAT_GR88
;
307 case __DRI_IMAGE_FORMAT_NONE
:
308 image
->format
= MESA_FORMAT_NONE
;
315 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
316 image
->data
= loaderPrivate
;
322 * Sets up a DRIImage structure to point to our shared image in a region
325 intel_setup_image_from_mipmap_tree(struct brw_context
*brw
, __DRIimage
*image
,
326 struct intel_mipmap_tree
*mt
, GLuint level
,
329 unsigned int draw_x
, draw_y
;
330 uint32_t mask_x
, mask_y
;
332 intel_miptree_make_shareable(brw
, mt
);
334 intel_miptree_check_level_layer(mt
, level
, zoffset
);
336 intel_region_get_tile_masks(mt
->region
, &mask_x
, &mask_y
, false);
337 intel_miptree_get_image_offset(mt
, level
, zoffset
, &draw_x
, &draw_y
);
339 image
->width
= mt
->level
[level
].width
;
340 image
->height
= mt
->level
[level
].height
;
341 image
->tile_x
= draw_x
& mask_x
;
342 image
->tile_y
= draw_y
& mask_y
;
344 image
->offset
= intel_region_get_aligned_offset(mt
->region
,
349 intel_region_reference(&image
->region
, mt
->region
);
353 intel_setup_image_from_dimensions(__DRIimage
*image
)
355 image
->width
= image
->region
->width
;
356 image
->height
= image
->region
->height
;
359 image
->has_depthstencil
= false;
362 static inline uint32_t
363 intel_dri_format(GLuint format
)
366 case MESA_FORMAT_RGB565
:
367 return __DRI_IMAGE_FORMAT_RGB565
;
368 case MESA_FORMAT_XRGB8888
:
369 return __DRI_IMAGE_FORMAT_XRGB8888
;
370 case MESA_FORMAT_ARGB8888
:
371 return __DRI_IMAGE_FORMAT_ARGB8888
;
372 case MESA_FORMAT_RGBA8888_REV
:
373 return __DRI_IMAGE_FORMAT_ABGR8888
;
375 return __DRI_IMAGE_FORMAT_R8
;
376 case MESA_FORMAT_RG88
:
377 return __DRI_IMAGE_FORMAT_GR88
;
380 return MESA_FORMAT_NONE
;
384 intel_create_image_from_name(__DRIscreen
*screen
,
385 int width
, int height
, int format
,
386 int name
, int pitch
, void *loaderPrivate
)
388 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
392 image
= intel_allocate_image(format
, loaderPrivate
);
396 if (image
->format
== MESA_FORMAT_NONE
)
399 cpp
= _mesa_get_format_bytes(image
->format
);
400 image
->region
= intel_region_alloc_for_handle(intelScreen
,
402 pitch
* cpp
, name
, "image");
403 if (image
->region
== NULL
) {
408 intel_setup_image_from_dimensions(image
);
414 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
415 int renderbuffer
, void *loaderPrivate
)
418 struct brw_context
*brw
= context
->driverPrivate
;
419 struct gl_context
*ctx
= &brw
->ctx
;
420 struct gl_renderbuffer
*rb
;
421 struct intel_renderbuffer
*irb
;
423 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
425 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
429 irb
= intel_renderbuffer(rb
);
430 intel_miptree_make_shareable(brw
, irb
->mt
);
431 image
= calloc(1, sizeof *image
);
435 image
->internal_format
= rb
->InternalFormat
;
436 image
->format
= rb
->Format
;
438 image
->data
= loaderPrivate
;
439 intel_region_reference(&image
->region
, irb
->mt
->region
);
440 intel_setup_image_from_dimensions(image
);
441 image
->dri_format
= intel_dri_format(image
->format
);
442 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
444 rb
->NeedsFinishRenderTexture
= true;
449 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
450 unsigned texture
, int zoffset
,
456 struct brw_context
*brw
= context
->driverPrivate
;
457 struct gl_texture_object
*obj
;
458 struct intel_texture_object
*iobj
;
461 obj
= _mesa_lookup_texture(&brw
->ctx
, texture
);
462 if (!obj
|| obj
->Target
!= target
) {
463 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
467 if (target
== GL_TEXTURE_CUBE_MAP
)
470 _mesa_test_texobj_completeness(&brw
->ctx
, obj
);
471 iobj
= intel_texture_object(obj
);
472 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
473 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
477 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
478 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
482 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
483 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
486 image
= calloc(1, sizeof *image
);
488 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
492 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
493 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
494 image
->data
= loaderPrivate
;
495 intel_setup_image_from_mipmap_tree(brw
, image
, iobj
->mt
, level
, zoffset
);
496 image
->dri_format
= intel_dri_format(image
->format
);
497 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
498 if (image
->dri_format
== MESA_FORMAT_NONE
) {
499 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
504 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
509 intel_destroy_image(__DRIimage
*image
)
511 intel_region_release(&image
->region
);
516 intel_create_image(__DRIscreen
*screen
,
517 int width
, int height
, int format
,
522 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
526 tiling
= I915_TILING_X
;
527 if (use
& __DRI_IMAGE_USE_CURSOR
) {
528 if (width
!= 64 || height
!= 64)
530 tiling
= I915_TILING_NONE
;
533 if (use
& __DRI_IMAGE_USE_LINEAR
)
534 tiling
= I915_TILING_NONE
;
536 image
= intel_allocate_image(format
, loaderPrivate
);
540 cpp
= _mesa_get_format_bytes(image
->format
);
542 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
543 if (image
->region
== NULL
) {
548 intel_setup_image_from_dimensions(image
);
554 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
557 case __DRI_IMAGE_ATTRIB_STRIDE
:
558 *value
= image
->region
->pitch
;
560 case __DRI_IMAGE_ATTRIB_HANDLE
:
561 *value
= image
->region
->bo
->handle
;
563 case __DRI_IMAGE_ATTRIB_NAME
:
564 return intel_region_flink(image
->region
, (uint32_t *) value
);
565 case __DRI_IMAGE_ATTRIB_FORMAT
:
566 *value
= image
->dri_format
;
568 case __DRI_IMAGE_ATTRIB_WIDTH
:
569 *value
= image
->region
->width
;
571 case __DRI_IMAGE_ATTRIB_HEIGHT
:
572 *value
= image
->region
->height
;
574 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
575 if (image
->planar_format
== NULL
)
577 *value
= image
->planar_format
->components
;
579 case __DRI_IMAGE_ATTRIB_FD
:
580 if (drm_intel_bo_gem_export_to_prime(image
->region
->bo
, value
) == 0)
589 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
593 image
= calloc(1, sizeof *image
);
597 intel_region_reference(&image
->region
, orig_image
->region
);
598 if (image
->region
== NULL
) {
603 image
->internal_format
= orig_image
->internal_format
;
604 image
->planar_format
= orig_image
->planar_format
;
605 image
->dri_format
= orig_image
->dri_format
;
606 image
->format
= orig_image
->format
;
607 image
->offset
= orig_image
->offset
;
608 image
->width
= orig_image
->width
;
609 image
->height
= orig_image
->height
;
610 image
->tile_x
= orig_image
->tile_x
;
611 image
->tile_y
= orig_image
->tile_y
;
612 image
->has_depthstencil
= orig_image
->has_depthstencil
;
613 image
->data
= loaderPrivate
;
615 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
616 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
622 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
624 if (use
& __DRI_IMAGE_USE_CURSOR
) {
625 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
633 intel_create_image_from_names(__DRIscreen
*screen
,
634 int width
, int height
, int fourcc
,
635 int *names
, int num_names
,
636 int *strides
, int *offsets
,
639 struct intel_image_format
*f
= NULL
;
643 if (screen
== NULL
|| names
== NULL
|| num_names
!= 1)
646 f
= intel_image_format_lookup(fourcc
);
650 image
= intel_create_image_from_name(screen
, width
, height
,
651 __DRI_IMAGE_FORMAT_NONE
,
652 names
[0], strides
[0],
658 image
->planar_format
= f
;
659 for (i
= 0; i
< f
->nplanes
; i
++) {
660 index
= f
->planes
[i
].buffer_index
;
661 image
->offsets
[index
] = offsets
[index
];
662 image
->strides
[index
] = strides
[index
];
669 intel_create_image_from_fds(__DRIscreen
*screen
,
670 int width
, int height
, int fourcc
,
671 int *fds
, int num_fds
, int *strides
, int *offsets
,
674 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
675 struct intel_image_format
*f
;
679 if (fds
== NULL
|| num_fds
!= 1)
682 f
= intel_image_format_lookup(fourcc
);
687 image
= intel_allocate_image(f
->planes
[0].dri_format
, loaderPrivate
);
689 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
694 image
->region
= intel_region_alloc_for_fd(intelScreen
,
696 strides
[0], fds
[0], "image");
697 if (image
->region
== NULL
) {
702 image
->planar_format
= f
;
703 for (i
= 0; i
< f
->nplanes
; i
++) {
704 index
= f
->planes
[i
].buffer_index
;
705 image
->offsets
[index
] = offsets
[index
];
706 image
->strides
[index
] = strides
[index
];
709 intel_setup_image_from_dimensions(image
);
715 intel_create_image_from_dma_bufs(__DRIscreen
*screen
,
716 int width
, int height
, int fourcc
,
717 int *fds
, int num_fds
,
718 int *strides
, int *offsets
,
719 enum __DRIYUVColorSpace yuv_color_space
,
720 enum __DRISampleRange sample_range
,
721 enum __DRIChromaSiting horizontal_siting
,
722 enum __DRIChromaSiting vertical_siting
,
727 struct intel_image_format
*f
= intel_image_format_lookup(fourcc
);
729 /* For now only packed formats that have native sampling are supported. */
730 if (!f
|| f
->nplanes
!= 1) {
731 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
735 image
= intel_create_image_from_fds(screen
, width
, height
, fourcc
, fds
,
736 num_fds
, strides
, offsets
,
740 * Invalid parameters and any inconsistencies between are assumed to be
741 * checked by the caller. Therefore besides unsupported formats one can fail
742 * only in allocation.
745 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
749 image
->dma_buf_imported
= true;
750 image
->yuv_color_space
= yuv_color_space
;
751 image
->sample_range
= sample_range
;
752 image
->horizontal_siting
= horizontal_siting
;
753 image
->vertical_siting
= vertical_siting
;
755 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
760 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
762 int width
, height
, offset
, stride
, dri_format
, index
;
763 struct intel_image_format
*f
;
764 uint32_t mask_x
, mask_y
;
767 if (parent
== NULL
|| parent
->planar_format
== NULL
)
770 f
= parent
->planar_format
;
772 if (plane
>= f
->nplanes
)
775 width
= parent
->region
->width
>> f
->planes
[plane
].width_shift
;
776 height
= parent
->region
->height
>> f
->planes
[plane
].height_shift
;
777 dri_format
= f
->planes
[plane
].dri_format
;
778 index
= f
->planes
[plane
].buffer_index
;
779 offset
= parent
->offsets
[index
];
780 stride
= parent
->strides
[index
];
782 image
= intel_allocate_image(dri_format
, loaderPrivate
);
786 if (offset
+ height
* stride
> parent
->region
->bo
->size
) {
787 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
792 image
->region
= calloc(sizeof(*image
->region
), 1);
793 if (image
->region
== NULL
) {
798 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
799 image
->region
->width
= width
;
800 image
->region
->height
= height
;
801 image
->region
->pitch
= stride
;
802 image
->region
->refcount
= 1;
803 image
->region
->bo
= parent
->region
->bo
;
804 drm_intel_bo_reference(image
->region
->bo
);
805 image
->region
->tiling
= parent
->region
->tiling
;
806 image
->offset
= offset
;
807 intel_setup_image_from_dimensions(image
);
809 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
, false);
812 "intel_create_sub_image: offset not on tile boundary");
817 static struct __DRIimageExtensionRec intelImageExtension
= {
818 .base
= { __DRI_IMAGE
, 8 },
820 .createImageFromName
= intel_create_image_from_name
,
821 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
822 .destroyImage
= intel_destroy_image
,
823 .createImage
= intel_create_image
,
824 .queryImage
= intel_query_image
,
825 .dupImage
= intel_dup_image
,
826 .validateUsage
= intel_validate_usage
,
827 .createImageFromNames
= intel_create_image_from_names
,
828 .fromPlanar
= intel_from_planar
,
829 .createImageFromTexture
= intel_create_image_from_texture
,
830 .createImageFromFds
= intel_create_image_from_fds
,
831 .createImageFromDmaBufs
= intel_create_image_from_dma_bufs
834 static const __DRIextension
*intelScreenExtensions
[] = {
835 &intelTexBufferExtension
.base
,
836 &intelFlushExtension
.base
,
837 &intelImageExtension
.base
,
838 &dri2ConfigQueryExtension
.base
,
843 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
846 struct drm_i915_getparam gp
;
848 memset(&gp
, 0, sizeof(gp
));
852 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
855 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
863 intel_get_boolean(__DRIscreen
*psp
, int param
)
866 return intel_get_param(psp
, param
, &value
) && value
;
870 intelDestroyScreen(__DRIscreen
* sPriv
)
872 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
874 dri_bufmgr_destroy(intelScreen
->bufmgr
);
875 driDestroyOptionInfo(&intelScreen
->optionCache
);
878 sPriv
->driverPrivate
= NULL
;
883 * This is called when we need to set up GL rendering to a new X window.
886 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
887 __DRIdrawable
* driDrawPriv
,
888 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
890 struct intel_renderbuffer
*rb
;
891 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
893 unsigned num_samples
= intel_quantize_num_samples(screen
, mesaVis
->samples
);
894 struct gl_framebuffer
*fb
;
899 fb
= CALLOC_STRUCT(gl_framebuffer
);
903 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
905 if (mesaVis
->redBits
== 5)
906 rgbFormat
= MESA_FORMAT_RGB565
;
907 else if (mesaVis
->sRGBCapable
)
908 rgbFormat
= MESA_FORMAT_SARGB8
;
909 else if (mesaVis
->alphaBits
== 0)
910 rgbFormat
= MESA_FORMAT_XRGB8888
;
912 rgbFormat
= MESA_FORMAT_SARGB8
;
913 fb
->Visual
.sRGBCapable
= true;
916 /* setup the hardware-based renderbuffers */
917 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
918 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
920 if (mesaVis
->doubleBufferMode
) {
921 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
922 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
926 * Assert here that the gl_config has an expected depth/stencil bit
927 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
928 * which constructs the advertised configs.)
930 if (mesaVis
->depthBits
== 24) {
931 assert(mesaVis
->stencilBits
== 8);
933 if (screen
->hw_has_separate_stencil
) {
934 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
,
936 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
937 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
,
939 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
942 * Use combined depth/stencil. Note that the renderbuffer is
943 * attached to two attachment points.
945 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
,
947 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
948 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
951 else if (mesaVis
->depthBits
== 16) {
952 assert(mesaVis
->stencilBits
== 0);
953 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
,
955 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
958 assert(mesaVis
->depthBits
== 0);
959 assert(mesaVis
->stencilBits
== 0);
962 /* now add any/all software-based renderbuffers we may need */
963 _swrast_add_soft_renderbuffers(fb
,
964 false, /* never sw color */
965 false, /* never sw depth */
966 false, /* never sw stencil */
967 mesaVis
->accumRedBits
> 0,
968 false, /* never sw alpha */
969 false /* never sw aux */ );
970 driDrawPriv
->driverPrivate
= fb
;
976 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
978 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
980 _mesa_reference_framebuffer(&fb
, NULL
);
984 intelCreateContext(gl_api api
,
985 const struct gl_config
* mesaVis
,
986 __DRIcontext
* driContextPriv
,
987 unsigned major_version
,
988 unsigned minor_version
,
991 void *sharedContextPrivate
)
993 bool success
= false;
995 success
= brwCreateContext(api
, mesaVis
,
997 major_version
, minor_version
, flags
,
998 error
, sharedContextPrivate
);
1003 if (driContextPriv
->driverPrivate
!= NULL
)
1004 intelDestroyContext(driContextPriv
);
1010 intel_init_bufmgr(struct intel_screen
*intelScreen
)
1012 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
1014 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
1016 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
1017 if (intelScreen
->bufmgr
== NULL
) {
1018 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1019 __func__
, __LINE__
);
1023 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
1025 if (!intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
)) {
1026 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
1034 * Override intel_screen.hw_has_separate_stencil with environment variable
1035 * INTEL_SEPARATE_STENCIL.
1037 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
1038 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
1042 intel_override_separate_stencil(struct intel_screen
*screen
)
1044 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
1047 } else if (!strncmp("0", s
, 2)) {
1048 screen
->hw_has_separate_stencil
= false;
1049 } else if (!strncmp("1", s
, 2)) {
1050 screen
->hw_has_separate_stencil
= true;
1053 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
1054 "invalid value and is ignored", s
);
1059 intel_detect_swizzling(struct intel_screen
*screen
)
1061 drm_intel_bo
*buffer
;
1062 unsigned long flags
= 0;
1063 unsigned long aligned_pitch
;
1064 uint32_t tiling
= I915_TILING_X
;
1065 uint32_t swizzle_mode
= 0;
1067 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
1069 &tiling
, &aligned_pitch
, flags
);
1073 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1074 drm_intel_bo_unreference(buffer
);
1076 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
1082 static __DRIconfig
**
1083 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1085 static const gl_format formats
[] = {
1087 MESA_FORMAT_ARGB8888
1090 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1091 static const GLenum back_buffer_modes
[] = {
1092 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1095 static const uint8_t singlesample_samples
[1] = {0};
1096 static const uint8_t multisample_samples
[2] = {4, 8};
1098 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1099 uint8_t depth_bits
[4], stencil_bits
[4];
1100 __DRIconfig
**configs
= NULL
;
1102 /* Generate singlesample configs without accumulation buffer. */
1103 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1104 __DRIconfig
**new_configs
;
1105 int num_depth_stencil_bits
= 2;
1107 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1108 * buffer that has a different number of bits per pixel than the color
1109 * buffer, gen >= 6 supports this.
1112 stencil_bits
[0] = 0;
1114 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1116 stencil_bits
[1] = 0;
1117 if (screen
->gen
>= 6) {
1119 stencil_bits
[2] = 8;
1120 num_depth_stencil_bits
= 3;
1124 stencil_bits
[1] = 8;
1127 new_configs
= driCreateConfigs(formats
[i
],
1130 num_depth_stencil_bits
,
1131 back_buffer_modes
, 2,
1132 singlesample_samples
, 1,
1134 configs
= driConcatConfigs(configs
, new_configs
);
1137 /* Generate the minimum possible set of configs that include an
1138 * accumulation buffer.
1140 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1141 __DRIconfig
**new_configs
;
1143 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1145 stencil_bits
[0] = 0;
1148 stencil_bits
[0] = 8;
1151 new_configs
= driCreateConfigs(formats
[i
],
1152 depth_bits
, stencil_bits
, 1,
1153 back_buffer_modes
, 1,
1154 singlesample_samples
, 1,
1156 configs
= driConcatConfigs(configs
, new_configs
);
1159 /* Generate multisample configs.
1161 * This loop breaks early, and hence is a no-op, on gen < 6.
1163 * Multisample configs must follow the singlesample configs in order to
1164 * work around an X server bug present in 1.12. The X server chooses to
1165 * associate the first listed RGBA888-Z24S8 config, regardless of its
1166 * sample count, with the 32-bit depth visual used for compositing.
1168 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
1169 * supported. Singlebuffer configs are not supported because no one wants
1172 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1173 if (screen
->gen
< 6)
1176 __DRIconfig
**new_configs
;
1177 const int num_depth_stencil_bits
= 2;
1178 int num_msaa_modes
= 0;
1181 stencil_bits
[0] = 0;
1183 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1185 stencil_bits
[1] = 0;
1188 stencil_bits
[1] = 8;
1191 if (screen
->gen
>= 7)
1193 else if (screen
->gen
== 6)
1196 new_configs
= driCreateConfigs(formats
[i
],
1199 num_depth_stencil_bits
,
1200 back_buffer_modes
, 1,
1201 multisample_samples
,
1204 configs
= driConcatConfigs(configs
, new_configs
);
1207 if (configs
== NULL
) {
1208 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1217 set_max_gl_versions(struct intel_screen
*screen
)
1219 int gl_version_override
= _mesa_get_gl_version_override();
1221 switch (screen
->gen
) {
1223 screen
->max_gl_core_version
= 31;
1224 screen
->max_gl_compat_version
= 30;
1225 screen
->max_gl_es1_version
= 11;
1226 screen
->max_gl_es2_version
= 30;
1229 screen
->max_gl_core_version
= 31;
1230 screen
->max_gl_compat_version
= 30;
1231 screen
->max_gl_es1_version
= 11;
1232 screen
->max_gl_es2_version
= 30;
1236 screen
->max_gl_core_version
= 0;
1237 screen
->max_gl_compat_version
= 21;
1238 screen
->max_gl_es1_version
= 11;
1239 screen
->max_gl_es2_version
= 20;
1242 assert(!"unrecognized intel_screen::gen");
1246 if (gl_version_override
>= 31) {
1247 screen
->max_gl_core_version
= MAX2(screen
->max_gl_core_version
,
1248 gl_version_override
);
1250 screen
->max_gl_compat_version
= MAX2(screen
->max_gl_compat_version
,
1251 gl_version_override
);
1256 * This is the driver specific part of the createNewScreen entry point.
1257 * Called when using DRI2.
1259 * \return the struct gl_config supported by this driver
1262 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
1264 struct intel_screen
*intelScreen
;
1266 if (psp
->dri2
.loader
->base
.version
<= 2 ||
1267 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1269 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1270 "support required\n");
1274 /* Allocate the private area */
1275 intelScreen
= calloc(1, sizeof *intelScreen
);
1277 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1280 /* parse information in __driConfigOptions */
1281 driParseOptionInfo(&intelScreen
->optionCache
, __driConfigOptions
);
1283 intelScreen
->driScrnPriv
= psp
;
1284 psp
->driverPrivate
= (void *) intelScreen
;
1286 if (!intel_init_bufmgr(intelScreen
))
1289 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1291 if (IS_GEN7(intelScreen
->deviceID
)) {
1292 intelScreen
->gen
= 7;
1293 } else if (IS_GEN6(intelScreen
->deviceID
)) {
1294 intelScreen
->gen
= 6;
1295 } else if (IS_GEN5(intelScreen
->deviceID
)) {
1296 intelScreen
->gen
= 5;
1298 intelScreen
->gen
= 4;
1301 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
1302 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
1305 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
1307 if (success
&& has_llc
)
1308 intelScreen
->hw_has_llc
= true;
1309 else if (!success
&& intelScreen
->gen
>= 6)
1310 intelScreen
->hw_has_llc
= true;
1312 intel_override_separate_stencil(intelScreen
);
1314 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1316 set_max_gl_versions(intelScreen
);
1318 psp
->api_mask
= (1 << __DRI_API_OPENGL
);
1319 if (intelScreen
->max_gl_core_version
> 0)
1320 psp
->api_mask
|= (1 << __DRI_API_OPENGL_CORE
);
1321 if (intelScreen
->max_gl_es1_version
> 0)
1322 psp
->api_mask
|= (1 << __DRI_API_GLES
);
1323 if (intelScreen
->max_gl_es2_version
> 0)
1324 psp
->api_mask
|= (1 << __DRI_API_GLES2
);
1325 if (intelScreen
->max_gl_es2_version
>= 30)
1326 psp
->api_mask
|= (1 << __DRI_API_GLES3
);
1328 psp
->extensions
= intelScreenExtensions
;
1330 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1333 struct intel_buffer
{
1335 struct intel_region
*region
;
1338 static __DRIbuffer
*
1339 intelAllocateBuffer(__DRIscreen
*screen
,
1340 unsigned attachment
, unsigned format
,
1341 int width
, int height
)
1343 struct intel_buffer
*intelBuffer
;
1344 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1346 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1347 attachment
== __DRI_BUFFER_BACK_LEFT
);
1349 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1350 if (intelBuffer
== NULL
)
1353 /* The front and back buffers are color buffers, which are X tiled. */
1354 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1361 if (intelBuffer
->region
== NULL
) {
1366 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1368 intelBuffer
->base
.attachment
= attachment
;
1369 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1370 intelBuffer
->base
.pitch
= intelBuffer
->region
->pitch
;
1372 return &intelBuffer
->base
;
1376 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1378 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1380 intel_region_release(&intelBuffer
->region
);
1385 const struct __DriverAPIRec driDriverAPI
= {
1386 .InitScreen
= intelInitScreen2
,
1387 .DestroyScreen
= intelDestroyScreen
,
1388 .CreateContext
= intelCreateContext
,
1389 .DestroyContext
= intelDestroyContext
,
1390 .CreateBuffer
= intelCreateBuffer
,
1391 .DestroyBuffer
= intelDestroyBuffer
,
1392 .MakeCurrent
= intelMakeCurrent
,
1393 .UnbindContext
= intelUnbindContext
,
1394 .AllocateBuffer
= intelAllocateBuffer
,
1395 .ReleaseBuffer
= intelReleaseBuffer
1398 /* This is the table of extensions that the loader will dlsym() for. */
1399 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1400 &driCoreExtension
.base
,
1401 &driDRI2Extension
.base
,