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 static const __DRIconfigOptionsExtension i915_config_options
= {
44 .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(early_z
, "false")
61 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
65 DRI_CONF_SECTION_QUALITY
66 DRI_CONF_FORCE_S3TC_ENABLE("false")
68 DRI_CONF_SECTION_DEBUG
69 DRI_CONF_NO_RAST("false")
70 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
71 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
72 DRI_CONF_DISABLE_THROTTLING("false")
73 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
74 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
75 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
77 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
78 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
84 #include "intel_batchbuffer.h"
85 #include "intel_buffers.h"
86 #include "intel_bufmgr.h"
87 #include "intel_chipset.h"
88 #include "intel_fbo.h"
89 #include "intel_mipmap_tree.h"
90 #include "intel_screen.h"
91 #include "intel_tex.h"
92 #include "intel_regions.h"
96 #ifdef USE_NEW_INTERFACE
97 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
98 #endif /*USE_NEW_INTERFACE */
101 * For debugging purposes, this returns a time in seconds.
108 clock_gettime(CLOCK_MONOTONIC
, &tp
);
110 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
114 aub_dump_bmp(struct gl_context
*ctx
)
116 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
118 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
119 struct intel_renderbuffer
*irb
=
120 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
122 if (irb
&& irb
->mt
) {
123 enum aub_dump_bmp_format format
;
125 switch (irb
->Base
.Base
.Format
) {
126 case MESA_FORMAT_ARGB8888
:
127 case MESA_FORMAT_XRGB8888
:
128 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
134 assert(irb
->mt
->region
->pitch
% irb
->mt
->region
->cpp
== 0);
135 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
138 irb
->Base
.Base
.Width
,
139 irb
->Base
.Base
.Height
,
141 irb
->mt
->region
->pitch
,
147 static const __DRItexBufferExtension intelTexBufferExtension
= {
148 .base
= { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
150 .setTexBuffer
= intelSetTexBuffer
,
151 .setTexBuffer2
= intelSetTexBuffer2
,
152 .releaseTexBuffer
= NULL
,
156 intelDRI2Flush(__DRIdrawable
*drawable
)
158 GET_CURRENT_CONTEXT(ctx
);
159 struct intel_context
*intel
= intel_context(ctx
);
163 INTEL_FIREVERTICES(intel
);
165 intel
->need_throttle
= true;
167 if (intel
->batch
.used
)
168 intel_batchbuffer_flush(intel
);
170 if (INTEL_DEBUG
& DEBUG_AUB
) {
175 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
176 .base
= { __DRI2_FLUSH
, 3 },
178 .flush
= intelDRI2Flush
,
179 .invalidate
= dri2InvalidateDrawable
,
182 static struct intel_image_format intel_image_formats
[] = {
183 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
184 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
186 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
187 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
189 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
190 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
191 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
192 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
194 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
195 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
196 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
197 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
199 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
200 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
201 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
202 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
204 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
205 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
206 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
207 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
209 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
210 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
211 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
212 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
214 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
215 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
216 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
218 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
219 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
220 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
222 /* For YUYV buffers, we set up two overlapping DRI images and treat
223 * them as planar buffers in the compositors. Plane 0 is GR88 and
224 * samples YU or YV pairs and places Y into the R component, while
225 * plane 1 is ARGB and samples YUYV clusters and places pairs and
226 * places U into the G component and V into A. This lets the
227 * texture sampler interpolate the Y components correctly when
228 * sampling from plane 0, and interpolate U and V correctly when
229 * sampling from plane 1. */
230 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
231 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
232 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
236 intel_allocate_image(int dri_format
, void *loaderPrivate
)
240 image
= calloc(1, sizeof *image
);
244 image
->dri_format
= dri_format
;
247 switch (dri_format
) {
248 case __DRI_IMAGE_FORMAT_RGB565
:
249 image
->format
= MESA_FORMAT_RGB565
;
251 case __DRI_IMAGE_FORMAT_XRGB8888
:
252 image
->format
= MESA_FORMAT_XRGB8888
;
254 case __DRI_IMAGE_FORMAT_ARGB8888
:
255 image
->format
= MESA_FORMAT_ARGB8888
;
257 case __DRI_IMAGE_FORMAT_ABGR8888
:
258 image
->format
= MESA_FORMAT_RGBA8888_REV
;
260 case __DRI_IMAGE_FORMAT_XBGR8888
:
261 image
->format
= MESA_FORMAT_RGBX8888_REV
;
263 case __DRI_IMAGE_FORMAT_R8
:
264 image
->format
= MESA_FORMAT_R8
;
266 case __DRI_IMAGE_FORMAT_GR88
:
267 image
->format
= MESA_FORMAT_GR88
;
269 case __DRI_IMAGE_FORMAT_NONE
:
270 image
->format
= MESA_FORMAT_NONE
;
277 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
278 image
->data
= loaderPrivate
;
284 * Sets up a DRIImage structure to point to our shared image in a region
287 intel_setup_image_from_mipmap_tree(struct intel_context
*intel
, __DRIimage
*image
,
288 struct intel_mipmap_tree
*mt
, GLuint level
,
291 unsigned int draw_x
, draw_y
;
292 uint32_t mask_x
, mask_y
;
294 intel_miptree_check_level_layer(mt
, level
, zoffset
);
296 intel_region_get_tile_masks(mt
->region
, &mask_x
, &mask_y
, false);
297 intel_miptree_get_image_offset(mt
, level
, zoffset
, &draw_x
, &draw_y
);
299 image
->width
= mt
->level
[level
].width
;
300 image
->height
= mt
->level
[level
].height
;
301 image
->tile_x
= draw_x
& mask_x
;
302 image
->tile_y
= draw_y
& mask_y
;
304 image
->offset
= intel_region_get_aligned_offset(mt
->region
,
309 intel_region_reference(&image
->region
, mt
->region
);
313 intel_setup_image_from_dimensions(__DRIimage
*image
)
315 image
->width
= image
->region
->width
;
316 image
->height
= image
->region
->height
;
321 static inline uint32_t
322 intel_dri_format(GLuint format
)
325 case MESA_FORMAT_RGB565
:
326 return __DRI_IMAGE_FORMAT_RGB565
;
327 case MESA_FORMAT_XRGB8888
:
328 return __DRI_IMAGE_FORMAT_XRGB8888
;
329 case MESA_FORMAT_ARGB8888
:
330 return __DRI_IMAGE_FORMAT_ARGB8888
;
331 case MESA_FORMAT_RGBA8888_REV
:
332 return __DRI_IMAGE_FORMAT_ABGR8888
;
334 return __DRI_IMAGE_FORMAT_R8
;
335 case MESA_FORMAT_RG88
:
336 return __DRI_IMAGE_FORMAT_GR88
;
339 return MESA_FORMAT_NONE
;
343 intel_create_image_from_name(__DRIscreen
*screen
,
344 int width
, int height
, int format
,
345 int name
, int pitch
, void *loaderPrivate
)
347 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
351 image
= intel_allocate_image(format
, loaderPrivate
);
355 if (image
->format
== MESA_FORMAT_NONE
)
358 cpp
= _mesa_get_format_bytes(image
->format
);
359 image
->region
= intel_region_alloc_for_handle(intelScreen
,
361 pitch
* cpp
, name
, "image");
362 if (image
->region
== NULL
) {
367 intel_setup_image_from_dimensions(image
);
373 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
374 int renderbuffer
, void *loaderPrivate
)
377 struct intel_context
*intel
= context
->driverPrivate
;
378 struct gl_renderbuffer
*rb
;
379 struct intel_renderbuffer
*irb
;
381 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
383 _mesa_error(&intel
->ctx
,
384 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
388 irb
= intel_renderbuffer(rb
);
389 image
= calloc(1, sizeof *image
);
393 image
->internal_format
= rb
->InternalFormat
;
394 image
->format
= rb
->Format
;
396 image
->data
= loaderPrivate
;
397 intel_region_reference(&image
->region
, irb
->mt
->region
);
398 intel_setup_image_from_dimensions(image
);
399 image
->dri_format
= intel_dri_format(image
->format
);
401 rb
->NeedsFinishRenderTexture
= true;
406 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
407 unsigned texture
, int zoffset
,
413 struct intel_context
*intel
= context
->driverPrivate
;
414 struct gl_texture_object
*obj
;
415 struct intel_texture_object
*iobj
;
418 obj
= _mesa_lookup_texture(&intel
->ctx
, texture
);
419 if (!obj
|| obj
->Target
!= target
) {
420 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
424 if (target
== GL_TEXTURE_CUBE_MAP
)
427 _mesa_test_texobj_completeness(&intel
->ctx
, obj
);
428 iobj
= intel_texture_object(obj
);
429 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
430 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
434 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
435 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
439 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
440 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
443 image
= calloc(1, sizeof *image
);
445 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
449 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
450 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
451 image
->data
= loaderPrivate
;
452 intel_setup_image_from_mipmap_tree(intel
, image
, iobj
->mt
, level
, zoffset
);
453 image
->dri_format
= intel_dri_format(image
->format
);
454 if (image
->dri_format
== MESA_FORMAT_NONE
) {
455 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
460 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
465 intel_destroy_image(__DRIimage
*image
)
467 intel_region_release(&image
->region
);
472 intel_create_image(__DRIscreen
*screen
,
473 int width
, int height
, int format
,
478 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
482 tiling
= I915_TILING_X
;
483 if (use
& __DRI_IMAGE_USE_CURSOR
) {
484 if (width
!= 64 || height
!= 64)
486 tiling
= I915_TILING_NONE
;
489 if (use
& __DRI_IMAGE_USE_LINEAR
)
490 tiling
= I915_TILING_NONE
;
492 image
= intel_allocate_image(format
, loaderPrivate
);
496 cpp
= _mesa_get_format_bytes(image
->format
);
498 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
499 if (image
->region
== NULL
) {
504 intel_setup_image_from_dimensions(image
);
510 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
513 case __DRI_IMAGE_ATTRIB_STRIDE
:
514 *value
= image
->region
->pitch
;
516 case __DRI_IMAGE_ATTRIB_HANDLE
:
517 *value
= image
->region
->bo
->handle
;
519 case __DRI_IMAGE_ATTRIB_NAME
:
520 return intel_region_flink(image
->region
, (uint32_t *) value
);
521 case __DRI_IMAGE_ATTRIB_FORMAT
:
522 *value
= image
->dri_format
;
524 case __DRI_IMAGE_ATTRIB_WIDTH
:
525 *value
= image
->region
->width
;
527 case __DRI_IMAGE_ATTRIB_HEIGHT
:
528 *value
= image
->region
->height
;
530 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
531 if (image
->planar_format
== NULL
)
533 *value
= image
->planar_format
->components
;
535 case __DRI_IMAGE_ATTRIB_FD
:
536 if (drm_intel_bo_gem_export_to_prime(image
->region
->bo
, value
) == 0)
545 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
549 image
= calloc(1, sizeof *image
);
553 intel_region_reference(&image
->region
, orig_image
->region
);
554 if (image
->region
== NULL
) {
559 image
->internal_format
= orig_image
->internal_format
;
560 image
->planar_format
= orig_image
->planar_format
;
561 image
->dri_format
= orig_image
->dri_format
;
562 image
->format
= orig_image
->format
;
563 image
->offset
= orig_image
->offset
;
564 image
->width
= orig_image
->width
;
565 image
->height
= orig_image
->height
;
566 image
->tile_x
= orig_image
->tile_x
;
567 image
->tile_y
= orig_image
->tile_y
;
568 image
->data
= loaderPrivate
;
570 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
571 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
577 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
579 if (use
& __DRI_IMAGE_USE_CURSOR
) {
580 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
588 intel_create_image_from_names(__DRIscreen
*screen
,
589 int width
, int height
, int fourcc
,
590 int *names
, int num_names
,
591 int *strides
, int *offsets
,
594 struct intel_image_format
*f
= NULL
;
598 if (screen
== NULL
|| names
== NULL
|| num_names
!= 1)
601 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
602 if (intel_image_formats
[i
].fourcc
== fourcc
) {
603 f
= &intel_image_formats
[i
];
610 image
= intel_create_image_from_name(screen
, width
, height
,
611 __DRI_IMAGE_FORMAT_NONE
,
612 names
[0], strides
[0],
618 image
->planar_format
= f
;
619 for (i
= 0; i
< f
->nplanes
; i
++) {
620 index
= f
->planes
[i
].buffer_index
;
621 image
->offsets
[index
] = offsets
[index
];
622 image
->strides
[index
] = strides
[index
];
629 intel_create_image_from_fds(__DRIscreen
*screen
,
630 int width
, int height
, int fourcc
,
631 int *fds
, int num_fds
, int *strides
, int *offsets
,
634 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
635 struct intel_image_format
*f
= NULL
;
639 if (fds
== NULL
|| num_fds
!= 1)
642 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
643 if (intel_image_formats
[i
].fourcc
== fourcc
) {
644 f
= &intel_image_formats
[i
];
651 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
655 image
->region
= intel_region_alloc_for_fd(intelScreen
,
657 strides
[0], fds
[0], "image");
658 if (image
->region
== NULL
) {
663 image
->planar_format
= f
;
664 for (i
= 0; i
< f
->nplanes
; i
++) {
665 index
= f
->planes
[i
].buffer_index
;
666 image
->offsets
[index
] = offsets
[index
];
667 image
->strides
[index
] = strides
[index
];
675 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
677 int width
, height
, offset
, stride
, dri_format
, index
;
678 struct intel_image_format
*f
;
679 uint32_t mask_x
, mask_y
;
682 if (parent
== NULL
|| parent
->planar_format
== NULL
)
685 f
= parent
->planar_format
;
687 if (plane
>= f
->nplanes
)
690 width
= parent
->region
->width
>> f
->planes
[plane
].width_shift
;
691 height
= parent
->region
->height
>> f
->planes
[plane
].height_shift
;
692 dri_format
= f
->planes
[plane
].dri_format
;
693 index
= f
->planes
[plane
].buffer_index
;
694 offset
= parent
->offsets
[index
];
695 stride
= parent
->strides
[index
];
697 image
= intel_allocate_image(dri_format
, loaderPrivate
);
701 if (offset
+ height
* stride
> parent
->region
->bo
->size
) {
702 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
707 image
->region
= calloc(sizeof(*image
->region
), 1);
708 if (image
->region
== NULL
) {
713 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
714 image
->region
->width
= width
;
715 image
->region
->height
= height
;
716 image
->region
->pitch
= stride
;
717 image
->region
->refcount
= 1;
718 image
->region
->bo
= parent
->region
->bo
;
719 drm_intel_bo_reference(image
->region
->bo
);
720 image
->region
->tiling
= parent
->region
->tiling
;
721 image
->offset
= offset
;
722 intel_setup_image_from_dimensions(image
);
724 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
, false);
727 "intel_create_sub_image: offset not on tile boundary");
732 static struct __DRIimageExtensionRec intelImageExtension
= {
733 .base
= { __DRI_IMAGE
, 7 },
735 .createImageFromName
= intel_create_image_from_name
,
736 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
737 .destroyImage
= intel_destroy_image
,
738 .createImage
= intel_create_image
,
739 .queryImage
= intel_query_image
,
740 .dupImage
= intel_dup_image
,
741 .validateUsage
= intel_validate_usage
,
742 .createImageFromNames
= intel_create_image_from_names
,
743 .fromPlanar
= intel_from_planar
,
744 .createImageFromTexture
= intel_create_image_from_texture
,
745 .createImageFromFds
= intel_create_image_from_fds
748 static const __DRIextension
*intelScreenExtensions
[] = {
749 &intelTexBufferExtension
.base
,
750 &intelFlushExtension
.base
,
751 &intelImageExtension
.base
,
752 &dri2ConfigQueryExtension
.base
,
757 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
760 struct drm_i915_getparam gp
;
762 memset(&gp
, 0, sizeof(gp
));
766 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
769 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
777 intel_get_boolean(__DRIscreen
*psp
, int param
)
780 return intel_get_param(psp
, param
, &value
) && value
;
784 intelDestroyScreen(__DRIscreen
* sPriv
)
786 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
788 dri_bufmgr_destroy(intelScreen
->bufmgr
);
789 driDestroyOptionInfo(&intelScreen
->optionCache
);
792 sPriv
->driverPrivate
= NULL
;
797 * This is called when we need to set up GL rendering to a new X window.
800 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
801 __DRIdrawable
* driDrawPriv
,
802 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
804 struct intel_renderbuffer
*rb
;
806 struct gl_framebuffer
*fb
;
811 fb
= CALLOC_STRUCT(gl_framebuffer
);
815 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
817 if (mesaVis
->redBits
== 5)
818 rgbFormat
= MESA_FORMAT_RGB565
;
819 else if (mesaVis
->sRGBCapable
)
820 rgbFormat
= MESA_FORMAT_SARGB8
;
821 else if (mesaVis
->alphaBits
== 0)
822 rgbFormat
= MESA_FORMAT_XRGB8888
;
824 rgbFormat
= MESA_FORMAT_ARGB8888
;
826 /* setup the hardware-based renderbuffers */
827 rb
= intel_create_renderbuffer(rgbFormat
);
828 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
830 if (mesaVis
->doubleBufferMode
) {
831 rb
= intel_create_renderbuffer(rgbFormat
);
832 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
836 * Assert here that the gl_config has an expected depth/stencil bit
837 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
838 * which constructs the advertised configs.)
840 if (mesaVis
->depthBits
== 24) {
841 assert(mesaVis
->stencilBits
== 8);
844 * Use combined depth/stencil. Note that the renderbuffer is
845 * attached to two attachment points.
847 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
);
848 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
849 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
851 else if (mesaVis
->depthBits
== 16) {
852 assert(mesaVis
->stencilBits
== 0);
853 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
);
854 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
857 assert(mesaVis
->depthBits
== 0);
858 assert(mesaVis
->stencilBits
== 0);
861 /* now add any/all software-based renderbuffers we may need */
862 _swrast_add_soft_renderbuffers(fb
,
863 false, /* never sw color */
864 false, /* never sw depth */
865 false, /* never sw stencil */
866 mesaVis
->accumRedBits
> 0,
867 false, /* never sw alpha */
868 false /* never sw aux */ );
869 driDrawPriv
->driverPrivate
= fb
;
875 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
877 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
879 _mesa_reference_framebuffer(&fb
, NULL
);
882 /* There are probably better ways to do this, such as an
883 * init-designated function to register chipids and createcontext
887 i830CreateContext(int api
,
888 const struct gl_config
*mesaVis
,
889 __DRIcontext
*driContextPriv
,
890 unsigned major_version
,
891 unsigned minor_version
,
893 void *sharedContextPrivate
);
896 i915CreateContext(int api
,
897 const struct gl_config
*mesaVis
,
898 __DRIcontext
*driContextPriv
,
899 unsigned major_version
,
900 unsigned minor_version
,
902 void *sharedContextPrivate
);
905 intelCreateContext(gl_api api
,
906 const struct gl_config
* mesaVis
,
907 __DRIcontext
* driContextPriv
,
908 unsigned major_version
,
909 unsigned minor_version
,
913 void *sharedContextPrivate
)
915 bool success
= false;
917 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
918 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
920 if (flags
& ~__DRI_CTX_FLAG_DEBUG
) {
921 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
926 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
930 if (IS_9XX(intelScreen
->deviceID
)) {
931 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
932 major_version
, minor_version
, error
,
933 sharedContextPrivate
);
935 intelScreen
->no_vbo
= true;
936 success
= i830CreateContext(api
, mesaVis
, driContextPriv
,
937 major_version
, minor_version
, error
,
938 sharedContextPrivate
);
944 if (driContextPriv
->driverPrivate
!= NULL
)
945 intelDestroyContext(driContextPriv
);
951 intel_init_bufmgr(struct intel_screen
*intelScreen
)
953 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
955 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
957 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
958 if (intelScreen
->bufmgr
== NULL
) {
959 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
964 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
966 if (!intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
)) {
967 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
975 intel_detect_swizzling(struct intel_screen
*screen
)
977 drm_intel_bo
*buffer
;
978 unsigned long flags
= 0;
979 unsigned long aligned_pitch
;
980 uint32_t tiling
= I915_TILING_X
;
981 uint32_t swizzle_mode
= 0;
983 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
985 &tiling
, &aligned_pitch
, flags
);
989 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
990 drm_intel_bo_unreference(buffer
);
992 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
999 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1001 static const gl_format formats
[] = {
1003 MESA_FORMAT_ARGB8888
1006 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1007 static const GLenum back_buffer_modes
[] = {
1008 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1011 static const uint8_t singlesample_samples
[1] = {0};
1013 uint8_t depth_bits
[4], stencil_bits
[4];
1014 __DRIconfig
**configs
= NULL
;
1016 /* Generate singlesample configs without accumulation buffer. */
1017 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1018 __DRIconfig
**new_configs
;
1019 int num_depth_stencil_bits
= 2;
1021 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1022 * buffer that has a different number of bits per pixel than the color
1026 stencil_bits
[0] = 0;
1028 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1030 stencil_bits
[1] = 0;
1033 stencil_bits
[1] = 8;
1036 new_configs
= driCreateConfigs(formats
[i
],
1039 num_depth_stencil_bits
,
1040 back_buffer_modes
, 2,
1041 singlesample_samples
, 1,
1043 configs
= driConcatConfigs(configs
, new_configs
);
1046 /* Generate the minimum possible set of configs that include an
1047 * accumulation buffer.
1049 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1050 __DRIconfig
**new_configs
;
1052 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1054 stencil_bits
[0] = 0;
1057 stencil_bits
[0] = 8;
1060 new_configs
= driCreateConfigs(formats
[i
],
1061 depth_bits
, stencil_bits
, 1,
1062 back_buffer_modes
, 1,
1063 singlesample_samples
, 1,
1065 configs
= driConcatConfigs(configs
, new_configs
);
1068 if (configs
== NULL
) {
1069 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1078 set_max_gl_versions(struct intel_screen
*screen
)
1080 __DRIscreen
*psp
= screen
->driScrnPriv
;
1082 switch (screen
->gen
) {
1084 psp
->max_gl_core_version
= 0;
1085 psp
->max_gl_es1_version
= 11;
1086 psp
->max_gl_compat_version
= 21;
1087 psp
->max_gl_es2_version
= 20;
1090 psp
->max_gl_core_version
= 0;
1091 psp
->max_gl_compat_version
= 13;
1092 psp
->max_gl_es1_version
= 11;
1093 psp
->max_gl_es2_version
= 0;
1096 assert(!"unrecognized intel_screen::gen");
1102 * This is the driver specific part of the createNewScreen entry point.
1103 * Called when using DRI2.
1105 * \return the struct gl_config supported by this driver
1108 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
1110 struct intel_screen
*intelScreen
;
1112 if (psp
->dri2
.loader
->base
.version
<= 2 ||
1113 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1115 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1116 "support required\n");
1120 /* Allocate the private area */
1121 intelScreen
= calloc(1, sizeof *intelScreen
);
1123 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1126 /* parse information in __driConfigOptions */
1127 driParseOptionInfo(&intelScreen
->optionCache
, i915_config_options
.xml
);
1129 intelScreen
->driScrnPriv
= psp
;
1130 psp
->driverPrivate
= (void *) intelScreen
;
1132 if (!intel_init_bufmgr(intelScreen
))
1135 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1137 if (IS_9XX(intelScreen
->deviceID
)) {
1138 intelScreen
->gen
= 3;
1140 intelScreen
->gen
= 2;
1143 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1145 set_max_gl_versions(intelScreen
);
1147 psp
->extensions
= intelScreenExtensions
;
1149 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1152 struct intel_buffer
{
1154 struct intel_region
*region
;
1157 static __DRIbuffer
*
1158 intelAllocateBuffer(__DRIscreen
*screen
,
1159 unsigned attachment
, unsigned format
,
1160 int width
, int height
)
1162 struct intel_buffer
*intelBuffer
;
1163 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1165 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1166 attachment
== __DRI_BUFFER_BACK_LEFT
);
1168 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1169 if (intelBuffer
== NULL
)
1172 /* The front and back buffers are color buffers, which are X tiled. */
1173 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1180 if (intelBuffer
->region
== NULL
) {
1185 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1187 intelBuffer
->base
.attachment
= attachment
;
1188 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1189 intelBuffer
->base
.pitch
= intelBuffer
->region
->pitch
;
1191 return &intelBuffer
->base
;
1195 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1197 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1199 intel_region_release(&intelBuffer
->region
);
1204 static const struct __DriverAPIRec i915_driver_api
= {
1205 .InitScreen
= intelInitScreen2
,
1206 .DestroyScreen
= intelDestroyScreen
,
1207 .CreateContext
= intelCreateContext
,
1208 .DestroyContext
= intelDestroyContext
,
1209 .CreateBuffer
= intelCreateBuffer
,
1210 .DestroyBuffer
= intelDestroyBuffer
,
1211 .MakeCurrent
= intelMakeCurrent
,
1212 .UnbindContext
= intelUnbindContext
,
1213 .AllocateBuffer
= intelAllocateBuffer
,
1214 .ReleaseBuffer
= intelReleaseBuffer
1217 static const struct __DRIDriverVtableExtensionRec i915_vtable
= {
1218 .base
= { __DRI_DRIVER_VTABLE
, 1 },
1219 .vtable
= &i915_driver_api
,
1222 /* This is the table of extensions that the loader will dlsym() for. */
1223 static const __DRIextension
*i915_driver_extensions
[] = {
1224 &driCoreExtension
.base
,
1225 &driDRI2Extension
.base
,
1227 &i915_config_options
.base
,
1231 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i915(void)
1233 globalDriverAPI
= &i915_driver_api
;
1235 return i915_driver_extensions
;