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+")
61 DRI_CONF_OPT_BEGIN_B(early_z
, "false")
62 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
66 DRI_CONF_SECTION_QUALITY
67 DRI_CONF_FORCE_S3TC_ENABLE("false")
68 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
70 DRI_CONF_SECTION_DEBUG
71 DRI_CONF_NO_RAST("false")
72 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
73 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
74 DRI_CONF_DISABLE_THROTTLING("false")
75 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
76 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
77 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
79 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
80 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
85 const GLuint __driNConfigOptions
= 14;
87 #include "intel_batchbuffer.h"
88 #include "intel_buffers.h"
89 #include "intel_bufmgr.h"
90 #include "intel_chipset.h"
91 #include "intel_fbo.h"
92 #include "intel_mipmap_tree.h"
93 #include "intel_screen.h"
94 #include "intel_tex.h"
95 #include "intel_regions.h"
98 #include "brw_context.h"
101 #include "i915_drm.h"
103 #ifdef USE_NEW_INTERFACE
104 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
105 #endif /*USE_NEW_INTERFACE */
108 * For debugging purposes, this returns a time in seconds.
115 clock_gettime(CLOCK_MONOTONIC
, &tp
);
117 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
121 aub_dump_bmp(struct gl_context
*ctx
)
123 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
125 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
126 struct intel_renderbuffer
*irb
=
127 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
129 if (irb
&& irb
->mt
) {
130 enum aub_dump_bmp_format format
;
132 switch (irb
->Base
.Base
.Format
) {
133 case MESA_FORMAT_ARGB8888
:
134 case MESA_FORMAT_XRGB8888
:
135 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
141 assert(irb
->mt
->region
->pitch
% irb
->mt
->region
->cpp
== 0);
142 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
145 irb
->Base
.Base
.Width
,
146 irb
->Base
.Base
.Height
,
148 irb
->mt
->region
->pitch
,
154 static const __DRItexBufferExtension intelTexBufferExtension
= {
155 .base
= { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
157 .setTexBuffer
= intelSetTexBuffer
,
158 .setTexBuffer2
= intelSetTexBuffer2
,
159 .releaseTexBuffer
= NULL
,
163 intelDRI2Flush(__DRIdrawable
*drawable
)
165 GET_CURRENT_CONTEXT(ctx
);
166 struct intel_context
*intel
= intel_context(ctx
);
170 intel_resolve_for_dri2_flush(intel
, drawable
);
171 intel
->need_throttle
= true;
173 if (intel
->batch
.used
)
174 intel_batchbuffer_flush(intel
);
176 if (INTEL_DEBUG
& DEBUG_AUB
) {
181 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
182 .base
= { __DRI2_FLUSH
, 3 },
184 .flush
= intelDRI2Flush
,
185 .invalidate
= dri2InvalidateDrawable
,
188 static struct intel_image_format intel_image_formats
[] = {
189 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
190 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
192 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
193 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
195 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
196 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
197 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
198 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
200 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
201 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
202 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
203 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
205 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
206 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
207 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
208 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
210 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
211 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
212 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
213 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
215 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
216 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
217 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
218 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
220 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
221 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
222 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
224 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
225 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
226 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
228 /* For YUYV buffers, we set up two overlapping DRI images and treat
229 * them as planar buffers in the compositors. Plane 0 is GR88 and
230 * samples YU or YV pairs and places Y into the R component, while
231 * plane 1 is ARGB and samples YUYV clusters and places pairs and
232 * places U into the G component and V into A. This lets the
233 * texture sampler interpolate the Y components correctly when
234 * sampling from plane 0, and interpolate U and V correctly when
235 * sampling from plane 1. */
236 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
237 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
238 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
242 intel_allocate_image(int dri_format
, void *loaderPrivate
)
246 image
= calloc(1, sizeof *image
);
250 image
->dri_format
= dri_format
;
253 switch (dri_format
) {
254 case __DRI_IMAGE_FORMAT_RGB565
:
255 image
->format
= MESA_FORMAT_RGB565
;
257 case __DRI_IMAGE_FORMAT_XRGB8888
:
258 image
->format
= MESA_FORMAT_XRGB8888
;
260 case __DRI_IMAGE_FORMAT_ARGB8888
:
261 image
->format
= MESA_FORMAT_ARGB8888
;
263 case __DRI_IMAGE_FORMAT_ABGR8888
:
264 image
->format
= MESA_FORMAT_RGBA8888_REV
;
266 case __DRI_IMAGE_FORMAT_XBGR8888
:
267 image
->format
= MESA_FORMAT_RGBX8888_REV
;
269 case __DRI_IMAGE_FORMAT_R8
:
270 image
->format
= MESA_FORMAT_R8
;
272 case __DRI_IMAGE_FORMAT_GR88
:
273 image
->format
= MESA_FORMAT_GR88
;
275 case __DRI_IMAGE_FORMAT_NONE
:
276 image
->format
= MESA_FORMAT_NONE
;
283 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
284 image
->data
= loaderPrivate
;
290 * Sets up a DRIImage structure to point to our shared image in a region
293 intel_setup_image_from_mipmap_tree(struct intel_context
*intel
, __DRIimage
*image
,
294 struct intel_mipmap_tree
*mt
, GLuint level
,
297 unsigned int draw_x
, draw_y
;
298 uint32_t mask_x
, mask_y
;
300 intel_miptree_make_shareable(intel
, mt
);
302 intel_miptree_check_level_layer(mt
, level
, zoffset
);
304 intel_region_get_tile_masks(mt
->region
, &mask_x
, &mask_y
, false);
305 intel_miptree_get_image_offset(mt
, level
, zoffset
, &draw_x
, &draw_y
);
307 image
->width
= mt
->level
[level
].width
;
308 image
->height
= mt
->level
[level
].height
;
309 image
->tile_x
= draw_x
& mask_x
;
310 image
->tile_y
= draw_y
& mask_y
;
312 image
->offset
= intel_region_get_aligned_offset(mt
->region
,
317 intel_region_reference(&image
->region
, mt
->region
);
321 intel_setup_image_from_dimensions(__DRIimage
*image
)
323 image
->width
= image
->region
->width
;
324 image
->height
= image
->region
->height
;
327 image
->has_depthstencil
= false;
330 static inline uint32_t
331 intel_dri_format(GLuint format
)
334 case MESA_FORMAT_RGB565
:
335 return __DRI_IMAGE_FORMAT_RGB565
;
336 case MESA_FORMAT_XRGB8888
:
337 return __DRI_IMAGE_FORMAT_XRGB8888
;
338 case MESA_FORMAT_ARGB8888
:
339 return __DRI_IMAGE_FORMAT_ARGB8888
;
340 case MESA_FORMAT_RGBA8888_REV
:
341 return __DRI_IMAGE_FORMAT_ABGR8888
;
343 return __DRI_IMAGE_FORMAT_R8
;
344 case MESA_FORMAT_RG88
:
345 return __DRI_IMAGE_FORMAT_GR88
;
348 return MESA_FORMAT_NONE
;
352 intel_create_image_from_name(__DRIscreen
*screen
,
353 int width
, int height
, int format
,
354 int name
, int pitch
, void *loaderPrivate
)
356 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
360 image
= intel_allocate_image(format
, loaderPrivate
);
364 if (image
->format
== MESA_FORMAT_NONE
)
367 cpp
= _mesa_get_format_bytes(image
->format
);
368 image
->region
= intel_region_alloc_for_handle(intelScreen
,
370 pitch
* cpp
, name
, "image");
371 if (image
->region
== NULL
) {
376 intel_setup_image_from_dimensions(image
);
382 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
383 int renderbuffer
, void *loaderPrivate
)
386 struct intel_context
*intel
= context
->driverPrivate
;
387 struct gl_renderbuffer
*rb
;
388 struct intel_renderbuffer
*irb
;
390 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
392 _mesa_error(&intel
->ctx
,
393 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
397 irb
= intel_renderbuffer(rb
);
398 intel_miptree_make_shareable(intel
, irb
->mt
);
399 image
= calloc(1, sizeof *image
);
403 image
->internal_format
= rb
->InternalFormat
;
404 image
->format
= rb
->Format
;
406 image
->data
= loaderPrivate
;
407 intel_region_reference(&image
->region
, irb
->mt
->region
);
408 intel_setup_image_from_dimensions(image
);
409 image
->dri_format
= intel_dri_format(image
->format
);
410 image
->has_depthstencil
= irb
->mt
->stencil_mt
? true : false;
412 rb
->NeedsFinishRenderTexture
= true;
417 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
418 unsigned texture
, int zoffset
,
424 struct intel_context
*intel
= context
->driverPrivate
;
425 struct gl_texture_object
*obj
;
426 struct intel_texture_object
*iobj
;
429 obj
= _mesa_lookup_texture(&intel
->ctx
, texture
);
430 if (!obj
|| obj
->Target
!= target
) {
431 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
435 if (target
== GL_TEXTURE_CUBE_MAP
)
438 _mesa_test_texobj_completeness(&intel
->ctx
, obj
);
439 iobj
= intel_texture_object(obj
);
440 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
441 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
445 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
446 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
450 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
451 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
454 image
= calloc(1, sizeof *image
);
456 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
460 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
461 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
462 image
->data
= loaderPrivate
;
463 intel_setup_image_from_mipmap_tree(intel
, image
, iobj
->mt
, level
, zoffset
);
464 image
->dri_format
= intel_dri_format(image
->format
);
465 image
->has_depthstencil
= iobj
->mt
->stencil_mt
? true : false;
466 if (image
->dri_format
== MESA_FORMAT_NONE
) {
467 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
472 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
477 intel_destroy_image(__DRIimage
*image
)
479 intel_region_release(&image
->region
);
484 intel_create_image(__DRIscreen
*screen
,
485 int width
, int height
, int format
,
490 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
494 tiling
= I915_TILING_X
;
495 if (use
& __DRI_IMAGE_USE_CURSOR
) {
496 if (width
!= 64 || height
!= 64)
498 tiling
= I915_TILING_NONE
;
501 image
= intel_allocate_image(format
, loaderPrivate
);
505 cpp
= _mesa_get_format_bytes(image
->format
);
507 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
508 if (image
->region
== NULL
) {
513 intel_setup_image_from_dimensions(image
);
519 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
522 case __DRI_IMAGE_ATTRIB_STRIDE
:
523 *value
= image
->region
->pitch
;
525 case __DRI_IMAGE_ATTRIB_HANDLE
:
526 *value
= image
->region
->bo
->handle
;
528 case __DRI_IMAGE_ATTRIB_NAME
:
529 return intel_region_flink(image
->region
, (uint32_t *) value
);
530 case __DRI_IMAGE_ATTRIB_FORMAT
:
531 *value
= image
->dri_format
;
533 case __DRI_IMAGE_ATTRIB_WIDTH
:
534 *value
= image
->region
->width
;
536 case __DRI_IMAGE_ATTRIB_HEIGHT
:
537 *value
= image
->region
->height
;
539 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
540 if (image
->planar_format
== NULL
)
542 *value
= image
->planar_format
->components
;
544 case __DRI_IMAGE_ATTRIB_FD
:
545 if (drm_intel_bo_gem_export_to_prime(image
->region
->bo
, value
) == 0)
554 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
558 image
= calloc(1, sizeof *image
);
562 intel_region_reference(&image
->region
, orig_image
->region
);
563 if (image
->region
== NULL
) {
568 image
->internal_format
= orig_image
->internal_format
;
569 image
->planar_format
= orig_image
->planar_format
;
570 image
->dri_format
= orig_image
->dri_format
;
571 image
->format
= orig_image
->format
;
572 image
->offset
= orig_image
->offset
;
573 image
->width
= orig_image
->width
;
574 image
->height
= orig_image
->height
;
575 image
->tile_x
= orig_image
->tile_x
;
576 image
->tile_y
= orig_image
->tile_y
;
577 image
->has_depthstencil
= orig_image
->has_depthstencil
;
578 image
->data
= loaderPrivate
;
580 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
581 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
587 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
589 if (use
& __DRI_IMAGE_USE_CURSOR
) {
590 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
598 intel_create_image_from_names(__DRIscreen
*screen
,
599 int width
, int height
, int fourcc
,
600 int *names
, int num_names
,
601 int *strides
, int *offsets
,
604 struct intel_image_format
*f
= NULL
;
608 if (screen
== NULL
|| names
== NULL
|| num_names
!= 1)
611 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
612 if (intel_image_formats
[i
].fourcc
== fourcc
) {
613 f
= &intel_image_formats
[i
];
620 image
= intel_create_image_from_name(screen
, width
, height
,
621 __DRI_IMAGE_FORMAT_NONE
,
622 names
[0], strides
[0],
628 image
->planar_format
= f
;
629 for (i
= 0; i
< f
->nplanes
; i
++) {
630 index
= f
->planes
[i
].buffer_index
;
631 image
->offsets
[index
] = offsets
[index
];
632 image
->strides
[index
] = strides
[index
];
639 intel_create_image_from_fds(__DRIscreen
*screen
,
640 int width
, int height
, int fourcc
,
641 int *fds
, int num_fds
, int *strides
, int *offsets
,
644 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
645 struct intel_image_format
*f
= NULL
;
649 if (fds
== NULL
|| num_fds
!= 1)
652 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
653 if (intel_image_formats
[i
].fourcc
== fourcc
) {
654 f
= &intel_image_formats
[i
];
661 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
665 image
->region
= intel_region_alloc_for_fd(intelScreen
,
667 strides
[0], fds
[0], "image");
668 if (image
->region
== NULL
) {
673 image
->planar_format
= f
;
674 for (i
= 0; i
< f
->nplanes
; i
++) {
675 index
= f
->planes
[i
].buffer_index
;
676 image
->offsets
[index
] = offsets
[index
];
677 image
->strides
[index
] = strides
[index
];
685 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
687 int width
, height
, offset
, stride
, dri_format
, index
;
688 struct intel_image_format
*f
;
689 uint32_t mask_x
, mask_y
;
692 if (parent
== NULL
|| parent
->planar_format
== NULL
)
695 f
= parent
->planar_format
;
697 if (plane
>= f
->nplanes
)
700 width
= parent
->region
->width
>> f
->planes
[plane
].width_shift
;
701 height
= parent
->region
->height
>> f
->planes
[plane
].height_shift
;
702 dri_format
= f
->planes
[plane
].dri_format
;
703 index
= f
->planes
[plane
].buffer_index
;
704 offset
= parent
->offsets
[index
];
705 stride
= parent
->strides
[index
];
707 image
= intel_allocate_image(dri_format
, loaderPrivate
);
711 if (offset
+ height
* stride
> parent
->region
->bo
->size
) {
712 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
717 image
->region
= calloc(sizeof(*image
->region
), 1);
718 if (image
->region
== NULL
) {
723 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
724 image
->region
->width
= width
;
725 image
->region
->height
= height
;
726 image
->region
->pitch
= stride
;
727 image
->region
->refcount
= 1;
728 image
->region
->bo
= parent
->region
->bo
;
729 drm_intel_bo_reference(image
->region
->bo
);
730 image
->region
->tiling
= parent
->region
->tiling
;
731 image
->offset
= offset
;
732 intel_setup_image_from_dimensions(image
);
734 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
, false);
737 "intel_create_sub_image: offset not on tile boundary");
742 static struct __DRIimageExtensionRec intelImageExtension
= {
743 .base
= { __DRI_IMAGE
, 7 },
745 .createImageFromName
= intel_create_image_from_name
,
746 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
747 .destroyImage
= intel_destroy_image
,
748 .createImage
= intel_create_image
,
749 .queryImage
= intel_query_image
,
750 .dupImage
= intel_dup_image
,
751 .validateUsage
= intel_validate_usage
,
752 .createImageFromNames
= intel_create_image_from_names
,
753 .fromPlanar
= intel_from_planar
,
754 .createImageFromTexture
= intel_create_image_from_texture
,
755 .createImageFromFds
= intel_create_image_from_fds
758 static const __DRIextension
*intelScreenExtensions
[] = {
759 &intelTexBufferExtension
.base
,
760 &intelFlushExtension
.base
,
761 &intelImageExtension
.base
,
762 &dri2ConfigQueryExtension
.base
,
767 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
770 struct drm_i915_getparam gp
;
772 memset(&gp
, 0, sizeof(gp
));
776 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
779 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
787 intel_get_boolean(__DRIscreen
*psp
, int param
)
790 return intel_get_param(psp
, param
, &value
) && value
;
794 intelDestroyScreen(__DRIscreen
* sPriv
)
796 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
798 dri_bufmgr_destroy(intelScreen
->bufmgr
);
799 driDestroyOptionInfo(&intelScreen
->optionCache
);
802 sPriv
->driverPrivate
= NULL
;
807 * This is called when we need to set up GL rendering to a new X window.
810 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
811 __DRIdrawable
* driDrawPriv
,
812 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
814 struct intel_renderbuffer
*rb
;
815 struct intel_screen
*screen
= (struct intel_screen
*) driScrnPriv
->driverPrivate
;
817 unsigned num_samples
= intel_quantize_num_samples(screen
, mesaVis
->samples
);
818 struct gl_framebuffer
*fb
;
823 fb
= CALLOC_STRUCT(gl_framebuffer
);
827 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
829 if (mesaVis
->redBits
== 5)
830 rgbFormat
= MESA_FORMAT_RGB565
;
831 else if (mesaVis
->sRGBCapable
)
832 rgbFormat
= MESA_FORMAT_SARGB8
;
833 else if (mesaVis
->alphaBits
== 0)
834 rgbFormat
= MESA_FORMAT_XRGB8888
;
836 rgbFormat
= MESA_FORMAT_SARGB8
;
837 fb
->Visual
.sRGBCapable
= true;
840 /* setup the hardware-based renderbuffers */
841 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
842 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
844 if (mesaVis
->doubleBufferMode
) {
845 rb
= intel_create_renderbuffer(rgbFormat
, num_samples
);
846 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
850 * Assert here that the gl_config has an expected depth/stencil bit
851 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
852 * which constructs the advertised configs.)
854 if (mesaVis
->depthBits
== 24) {
855 assert(mesaVis
->stencilBits
== 8);
857 if (screen
->hw_has_separate_stencil
) {
858 rb
= intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24
,
860 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
861 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8
,
863 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
866 * Use combined depth/stencil. Note that the renderbuffer is
867 * attached to two attachment points.
869 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
,
871 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
872 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
875 else if (mesaVis
->depthBits
== 16) {
876 assert(mesaVis
->stencilBits
== 0);
877 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
,
879 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
882 assert(mesaVis
->depthBits
== 0);
883 assert(mesaVis
->stencilBits
== 0);
886 /* now add any/all software-based renderbuffers we may need */
887 _swrast_add_soft_renderbuffers(fb
,
888 false, /* never sw color */
889 false, /* never sw depth */
890 false, /* never sw stencil */
891 mesaVis
->accumRedBits
> 0,
892 false, /* never sw alpha */
893 false /* never sw aux */ );
894 driDrawPriv
->driverPrivate
= fb
;
900 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
902 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
904 _mesa_reference_framebuffer(&fb
, NULL
);
907 /* There are probably better ways to do this, such as an
908 * init-designated function to register chipids and createcontext
912 i830CreateContext(int api
,
913 const struct gl_config
*mesaVis
,
914 __DRIcontext
*driContextPriv
,
915 unsigned major_version
,
916 unsigned minor_version
,
918 void *sharedContextPrivate
);
921 i915CreateContext(int api
,
922 const struct gl_config
*mesaVis
,
923 __DRIcontext
*driContextPriv
,
924 unsigned major_version
,
925 unsigned minor_version
,
927 void *sharedContextPrivate
);
929 brwCreateContext(int api
,
930 const struct gl_config
*mesaVis
,
931 __DRIcontext
*driContextPriv
,
932 unsigned major_version
,
933 unsigned minor_version
,
936 void *sharedContextPrivate
);
939 intelCreateContext(gl_api api
,
940 const struct gl_config
* mesaVis
,
941 __DRIcontext
* driContextPriv
,
942 unsigned major_version
,
943 unsigned minor_version
,
946 void *sharedContextPrivate
)
948 bool success
= false;
951 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
952 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
954 if (IS_9XX(intelScreen
->deviceID
)) {
955 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
956 major_version
, minor_version
, error
,
957 sharedContextPrivate
);
959 intelScreen
->no_vbo
= true;
960 success
= i830CreateContext(api
, mesaVis
, driContextPriv
,
961 major_version
, minor_version
, error
,
962 sharedContextPrivate
);
965 success
= brwCreateContext(api
, mesaVis
,
967 major_version
, minor_version
, flags
,
968 error
, sharedContextPrivate
);
974 if (driContextPriv
->driverPrivate
!= NULL
)
975 intelDestroyContext(driContextPriv
);
981 intel_init_bufmgr(struct intel_screen
*intelScreen
)
983 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
985 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
987 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
988 if (intelScreen
->bufmgr
== NULL
) {
989 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
994 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
996 if (!intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
)) {
997 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
1005 * Override intel_screen.hw_has_separate_stencil with environment variable
1006 * INTEL_SEPARATE_STENCIL.
1008 * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
1009 * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
1013 intel_override_separate_stencil(struct intel_screen
*screen
)
1015 const char *s
= getenv("INTEL_SEPARATE_STENCIL");
1018 } else if (!strncmp("0", s
, 2)) {
1019 screen
->hw_has_separate_stencil
= false;
1020 } else if (!strncmp("1", s
, 2)) {
1021 screen
->hw_has_separate_stencil
= true;
1024 "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
1025 "invalid value and is ignored", s
);
1030 intel_detect_swizzling(struct intel_screen
*screen
)
1032 drm_intel_bo
*buffer
;
1033 unsigned long flags
= 0;
1034 unsigned long aligned_pitch
;
1035 uint32_t tiling
= I915_TILING_X
;
1036 uint32_t swizzle_mode
= 0;
1038 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
1040 &tiling
, &aligned_pitch
, flags
);
1044 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1045 drm_intel_bo_unreference(buffer
);
1047 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
1053 static __DRIconfig
**
1054 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1056 static const gl_format formats
[] = {
1058 MESA_FORMAT_ARGB8888
1061 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1062 static const GLenum back_buffer_modes
[] = {
1063 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1066 static const uint8_t singlesample_samples
[1] = {0};
1067 static const uint8_t multisample_samples
[2] = {4, 8};
1069 struct intel_screen
*screen
= dri_screen
->driverPrivate
;
1070 uint8_t depth_bits
[4], stencil_bits
[4];
1071 __DRIconfig
**configs
= NULL
;
1073 /* Generate singlesample configs without accumulation buffer. */
1074 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1075 __DRIconfig
**new_configs
;
1076 int num_depth_stencil_bits
= 2;
1078 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1079 * buffer that has a different number of bits per pixel than the color
1080 * buffer, gen >= 6 supports this.
1083 stencil_bits
[0] = 0;
1085 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1087 stencil_bits
[1] = 0;
1088 if (screen
->gen
>= 6) {
1090 stencil_bits
[2] = 8;
1091 num_depth_stencil_bits
= 3;
1095 stencil_bits
[1] = 8;
1098 new_configs
= driCreateConfigs(formats
[i
],
1101 num_depth_stencil_bits
,
1102 back_buffer_modes
, 2,
1103 singlesample_samples
, 1,
1105 configs
= driConcatConfigs(configs
, new_configs
);
1108 /* Generate the minimum possible set of configs that include an
1109 * accumulation buffer.
1111 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1112 __DRIconfig
**new_configs
;
1114 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1116 stencil_bits
[0] = 0;
1119 stencil_bits
[0] = 8;
1122 new_configs
= driCreateConfigs(formats
[i
],
1123 depth_bits
, stencil_bits
, 1,
1124 back_buffer_modes
, 1,
1125 singlesample_samples
, 1,
1127 configs
= driConcatConfigs(configs
, new_configs
);
1130 /* Generate multisample configs.
1132 * This loop breaks early, and hence is a no-op, on gen < 6.
1134 * Multisample configs must follow the singlesample configs in order to
1135 * work around an X server bug present in 1.12. The X server chooses to
1136 * associate the first listed RGBA888-Z24S8 config, regardless of its
1137 * sample count, with the 32-bit depth visual used for compositing.
1139 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
1140 * supported. Singlebuffer configs are not supported because no one wants
1143 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1144 if (screen
->gen
< 6)
1147 __DRIconfig
**new_configs
;
1148 const int num_depth_stencil_bits
= 2;
1149 int num_msaa_modes
= 0;
1152 stencil_bits
[0] = 0;
1154 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1156 stencil_bits
[1] = 0;
1159 stencil_bits
[1] = 8;
1162 if (screen
->gen
>= 7)
1164 else if (screen
->gen
== 6)
1167 new_configs
= driCreateConfigs(formats
[i
],
1170 num_depth_stencil_bits
,
1171 back_buffer_modes
, 1,
1172 multisample_samples
,
1175 configs
= driConcatConfigs(configs
, new_configs
);
1178 if (configs
== NULL
) {
1179 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1188 set_max_gl_versions(struct intel_screen
*screen
)
1190 int gl_version_override
= _mesa_get_gl_version_override();
1192 switch (screen
->gen
) {
1194 screen
->max_gl_core_version
= 31;
1195 screen
->max_gl_compat_version
= 30;
1196 screen
->max_gl_es1_version
= 11;
1197 screen
->max_gl_es2_version
= 30;
1200 screen
->max_gl_core_version
= 31;
1201 screen
->max_gl_compat_version
= 30;
1202 screen
->max_gl_es1_version
= 11;
1203 screen
->max_gl_es2_version
= 30;
1207 screen
->max_gl_core_version
= 0;
1208 screen
->max_gl_compat_version
= 21;
1209 screen
->max_gl_es1_version
= 11;
1210 screen
->max_gl_es2_version
= 20;
1213 screen
->max_gl_core_version
= 0;
1214 screen
->max_gl_es1_version
= 11;
1215 screen
->max_gl_compat_version
= 21;
1216 screen
->max_gl_es2_version
= 20;
1221 screen
->max_gl_core_version
= 0;
1222 screen
->max_gl_compat_version
= 13;
1223 screen
->max_gl_es1_version
= 11;
1224 screen
->max_gl_es2_version
= 0;
1227 assert(!"unrecognized intel_screen::gen");
1231 if (gl_version_override
>= 31) {
1232 screen
->max_gl_core_version
= MAX2(screen
->max_gl_core_version
,
1233 gl_version_override
);
1235 screen
->max_gl_compat_version
= MAX2(screen
->max_gl_compat_version
,
1236 gl_version_override
);
1240 screen
->max_gl_es1_version
= 0;
1244 screen
->max_gl_es2_version
= 0;
1249 * This is the driver specific part of the createNewScreen entry point.
1250 * Called when using DRI2.
1252 * \return the struct gl_config supported by this driver
1255 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
1257 struct intel_screen
*intelScreen
;
1259 if (psp
->dri2
.loader
->base
.version
<= 2 ||
1260 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1262 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1263 "support required\n");
1267 /* Allocate the private area */
1268 intelScreen
= calloc(1, sizeof *intelScreen
);
1270 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1273 /* parse information in __driConfigOptions */
1274 driParseOptionInfo(&intelScreen
->optionCache
,
1275 __driConfigOptions
, __driNConfigOptions
);
1277 intelScreen
->driScrnPriv
= psp
;
1278 psp
->driverPrivate
= (void *) intelScreen
;
1280 if (!intel_init_bufmgr(intelScreen
))
1283 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1285 if (IS_GEN7(intelScreen
->deviceID
)) {
1286 intelScreen
->gen
= 7;
1287 } else if (IS_GEN6(intelScreen
->deviceID
)) {
1288 intelScreen
->gen
= 6;
1289 } else if (IS_GEN5(intelScreen
->deviceID
)) {
1290 intelScreen
->gen
= 5;
1291 } else if (IS_965(intelScreen
->deviceID
)) {
1292 intelScreen
->gen
= 4;
1293 } else if (IS_9XX(intelScreen
->deviceID
)) {
1294 intelScreen
->gen
= 3;
1296 intelScreen
->gen
= 2;
1299 intelScreen
->hw_has_separate_stencil
= intelScreen
->gen
>= 6;
1300 intelScreen
->hw_must_use_separate_stencil
= intelScreen
->gen
>= 7;
1303 bool success
= intel_get_param(intelScreen
->driScrnPriv
, I915_PARAM_HAS_LLC
,
1305 if (success
&& has_llc
)
1306 intelScreen
->hw_has_llc
= true;
1307 else if (!success
&& intelScreen
->gen
>= 6)
1308 intelScreen
->hw_has_llc
= true;
1310 intel_override_separate_stencil(intelScreen
);
1312 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1314 set_max_gl_versions(intelScreen
);
1316 psp
->api_mask
= (1 << __DRI_API_OPENGL
);
1317 if (intelScreen
->max_gl_core_version
> 0)
1318 psp
->api_mask
|= (1 << __DRI_API_OPENGL_CORE
);
1319 if (intelScreen
->max_gl_es1_version
> 0)
1320 psp
->api_mask
|= (1 << __DRI_API_GLES
);
1321 if (intelScreen
->max_gl_es2_version
> 0)
1322 psp
->api_mask
|= (1 << __DRI_API_GLES2
);
1323 if (intelScreen
->max_gl_es2_version
>= 30)
1324 psp
->api_mask
|= (1 << __DRI_API_GLES3
);
1326 psp
->extensions
= intelScreenExtensions
;
1328 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1331 struct intel_buffer
{
1333 struct intel_region
*region
;
1336 static __DRIbuffer
*
1337 intelAllocateBuffer(__DRIscreen
*screen
,
1338 unsigned attachment
, unsigned format
,
1339 int width
, int height
)
1341 struct intel_buffer
*intelBuffer
;
1342 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1344 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1345 attachment
== __DRI_BUFFER_BACK_LEFT
);
1347 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1348 if (intelBuffer
== NULL
)
1351 /* The front and back buffers are color buffers, which are X tiled. */
1352 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1359 if (intelBuffer
->region
== NULL
) {
1364 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1366 intelBuffer
->base
.attachment
= attachment
;
1367 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1368 intelBuffer
->base
.pitch
= intelBuffer
->region
->pitch
;
1370 return &intelBuffer
->base
;
1374 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1376 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1378 intel_region_release(&intelBuffer
->region
);
1383 const struct __DriverAPIRec driDriverAPI
= {
1384 .InitScreen
= intelInitScreen2
,
1385 .DestroyScreen
= intelDestroyScreen
,
1386 .CreateContext
= intelCreateContext
,
1387 .DestroyContext
= intelDestroyContext
,
1388 .CreateBuffer
= intelCreateBuffer
,
1389 .DestroyBuffer
= intelDestroyBuffer
,
1390 .MakeCurrent
= intelMakeCurrent
,
1391 .UnbindContext
= intelUnbindContext
,
1392 .AllocateBuffer
= intelAllocateBuffer
,
1393 .ReleaseBuffer
= intelReleaseBuffer
1396 /* This is the table of extensions that the loader will dlsym() for. */
1397 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1398 &driCoreExtension
.base
,
1399 &driDRI2Extension
.base
,