1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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 **************************************************************************/
31 #include "main/glheader.h"
32 #include "main/context.h"
33 #include "main/framebuffer.h"
34 #include "main/renderbuffer.h"
35 #include "main/texobj.h"
36 #include "main/hash.h"
37 #include "main/fbobject.h"
38 #include "main/version.h"
39 #include "swrast/s_renderbuffer.h"
44 static const __DRIconfigOptionsExtension i915_config_options
= {
45 .base
= { __DRI_CONFIG_OPTIONS
, 1 },
49 DRI_CONF_SECTION_PERFORMANCE
50 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC
)
51 /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
52 * DRI_CONF_BO_REUSE_ALL
54 DRI_CONF_OPT_BEGIN_V(bo_reuse
, enum, 1, "0:1")
55 DRI_CONF_DESC_BEGIN(en
, "Buffer object reuse")
56 DRI_CONF_ENUM(0, "Disable buffer object reuse")
57 DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
61 DRI_CONF_OPT_BEGIN_B(early_z
, "false")
62 DRI_CONF_DESC(en
, "Enable early Z in classic mode (unstable, 945-only).")
65 DRI_CONF_OPT_BEGIN_B(fragment_shader
, "true")
66 DRI_CONF_DESC(en
, "Enable limited ARB_fragment_shader support on 915/945.")
70 DRI_CONF_SECTION_QUALITY
71 DRI_CONF_FORCE_S3TC_ENABLE("false")
73 DRI_CONF_SECTION_DEBUG
74 DRI_CONF_NO_RAST("false")
75 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
76 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
77 DRI_CONF_DISABLE_THROTTLING("false")
78 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
79 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
80 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
82 DRI_CONF_OPT_BEGIN_B(stub_occlusion_query
, "false")
83 DRI_CONF_DESC(en
, "Enable stub ARB_occlusion_query support on 915/945.")
86 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
87 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
93 #include "intel_batchbuffer.h"
94 #include "intel_buffers.h"
95 #include "intel_bufmgr.h"
96 #include "intel_chipset.h"
97 #include "intel_fbo.h"
98 #include "intel_mipmap_tree.h"
99 #include "intel_screen.h"
100 #include "intel_tex.h"
101 #include "intel_regions.h"
103 #include "i915_drm.h"
106 * For debugging purposes, this returns a time in seconds.
113 clock_gettime(CLOCK_MONOTONIC
, &tp
);
115 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
119 aub_dump_bmp(struct gl_context
*ctx
)
121 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
123 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
124 struct intel_renderbuffer
*irb
=
125 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
127 if (irb
&& irb
->mt
) {
128 enum aub_dump_bmp_format format
;
130 switch (irb
->Base
.Base
.Format
) {
131 case MESA_FORMAT_B8G8R8A8_UNORM
:
132 case MESA_FORMAT_B8G8R8X8_UNORM
:
133 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
139 assert(irb
->mt
->region
->pitch
% irb
->mt
->region
->cpp
== 0);
140 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
143 irb
->Base
.Base
.Width
,
144 irb
->Base
.Base
.Height
,
146 irb
->mt
->region
->pitch
,
152 static const __DRItexBufferExtension intelTexBufferExtension
= {
153 .base
= { __DRI_TEX_BUFFER
, 3 },
155 .setTexBuffer
= intelSetTexBuffer
,
156 .setTexBuffer2
= intelSetTexBuffer2
,
157 .releaseTexBuffer
= NULL
,
161 intelDRI2Flush(__DRIdrawable
*drawable
)
163 GET_CURRENT_CONTEXT(ctx
);
164 struct intel_context
*intel
= intel_context(ctx
);
168 INTEL_FIREVERTICES(intel
);
170 intel
->need_throttle
= true;
172 if (intel
->batch
.used
)
173 intel_batchbuffer_flush(intel
);
175 if (INTEL_DEBUG
& DEBUG_AUB
) {
180 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
181 .base
= { __DRI2_FLUSH
, 3 },
183 .flush
= intelDRI2Flush
,
184 .invalidate
= dri2InvalidateDrawable
,
187 static struct intel_image_format intel_image_formats
[] = {
188 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
189 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
191 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
192 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8
, 4 } } },
194 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
195 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
197 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
198 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
199 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
200 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
202 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
203 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
204 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
205 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
207 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
208 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
209 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
210 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
212 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
213 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
214 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
215 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
217 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
218 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
219 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
220 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
222 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
223 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
224 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
226 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
227 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
228 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
230 /* For YUYV buffers, we set up two overlapping DRI images and treat
231 * them as planar buffers in the compositors. Plane 0 is GR88 and
232 * samples YU or YV pairs and places Y into the R component, while
233 * plane 1 is ARGB and samples YUYV clusters and places pairs and
234 * places U into the G component and V into A. This lets the
235 * texture sampler interpolate the Y components correctly when
236 * sampling from plane 0, and interpolate U and V correctly when
237 * sampling from plane 1. */
238 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
239 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
240 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
244 intel_allocate_image(int dri_format
, void *loaderPrivate
)
248 image
= calloc(1, sizeof *image
);
252 image
->dri_format
= dri_format
;
255 image
->format
= driImageFormatToGLFormat(dri_format
);
256 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
257 image
->format
== MESA_FORMAT_NONE
) {
262 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
263 image
->data
= loaderPrivate
;
269 * Sets up a DRIImage structure to point to our shared image in a region
272 intel_setup_image_from_mipmap_tree(struct intel_context
*intel
, __DRIimage
*image
,
273 struct intel_mipmap_tree
*mt
, GLuint level
,
276 unsigned int draw_x
, draw_y
;
277 uint32_t mask_x
, mask_y
;
279 intel_miptree_check_level_layer(mt
, level
, zoffset
);
281 intel_region_get_tile_masks(mt
->region
, &mask_x
, &mask_y
, false);
282 intel_miptree_get_image_offset(mt
, level
, zoffset
, &draw_x
, &draw_y
);
284 image
->width
= mt
->level
[level
].width
;
285 image
->height
= mt
->level
[level
].height
;
286 image
->tile_x
= draw_x
& mask_x
;
287 image
->tile_y
= draw_y
& mask_y
;
289 image
->offset
= intel_region_get_aligned_offset(mt
->region
,
294 intel_region_reference(&image
->region
, mt
->region
);
298 intel_setup_image_from_dimensions(__DRIimage
*image
)
300 image
->width
= image
->region
->width
;
301 image
->height
= image
->region
->height
;
307 intel_create_image_from_name(__DRIscreen
*screen
,
308 int width
, int height
, int format
,
309 int name
, int pitch
, void *loaderPrivate
)
311 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
315 image
= intel_allocate_image(format
, loaderPrivate
);
319 if (image
->format
== MESA_FORMAT_NONE
)
322 cpp
= _mesa_get_format_bytes(image
->format
);
323 image
->region
= intel_region_alloc_for_handle(intelScreen
,
325 pitch
* cpp
, name
, "image");
326 if (image
->region
== NULL
) {
331 intel_setup_image_from_dimensions(image
);
337 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
338 int renderbuffer
, void *loaderPrivate
)
341 struct intel_context
*intel
= context
->driverPrivate
;
342 struct gl_renderbuffer
*rb
;
343 struct intel_renderbuffer
*irb
;
345 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
347 _mesa_error(&intel
->ctx
,
348 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
352 irb
= intel_renderbuffer(rb
);
353 image
= calloc(1, sizeof *image
);
357 image
->internal_format
= rb
->InternalFormat
;
358 image
->format
= rb
->Format
;
360 image
->data
= loaderPrivate
;
361 intel_region_reference(&image
->region
, irb
->mt
->region
);
362 intel_setup_image_from_dimensions(image
);
363 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
365 rb
->NeedsFinishRenderTexture
= true;
370 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
371 unsigned texture
, int zoffset
,
377 struct intel_context
*intel
= context
->driverPrivate
;
378 struct gl_texture_object
*obj
;
379 struct intel_texture_object
*iobj
;
382 obj
= _mesa_lookup_texture(&intel
->ctx
, texture
);
383 if (!obj
|| obj
->Target
!= target
) {
384 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
388 if (target
== GL_TEXTURE_CUBE_MAP
)
391 _mesa_test_texobj_completeness(&intel
->ctx
, obj
);
392 iobj
= intel_texture_object(obj
);
393 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
394 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
398 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
399 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
403 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
404 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
407 image
= calloc(1, sizeof *image
);
409 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
413 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
414 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
415 image
->data
= loaderPrivate
;
416 intel_setup_image_from_mipmap_tree(intel
, image
, iobj
->mt
, level
, zoffset
);
417 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
418 if (image
->dri_format
== MESA_FORMAT_NONE
) {
419 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
424 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
429 intel_destroy_image(__DRIimage
*image
)
431 intel_region_release(&image
->region
);
436 intel_create_image(__DRIscreen
*screen
,
437 int width
, int height
, int format
,
442 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
446 tiling
= I915_TILING_X
;
447 if (use
& __DRI_IMAGE_USE_CURSOR
) {
448 if (width
!= 64 || height
!= 64)
450 tiling
= I915_TILING_NONE
;
453 if (use
& __DRI_IMAGE_USE_LINEAR
)
454 tiling
= I915_TILING_NONE
;
456 image
= intel_allocate_image(format
, loaderPrivate
);
460 cpp
= _mesa_get_format_bytes(image
->format
);
462 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
463 if (image
->region
== NULL
) {
468 intel_setup_image_from_dimensions(image
);
474 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
477 case __DRI_IMAGE_ATTRIB_STRIDE
:
478 *value
= image
->region
->pitch
;
480 case __DRI_IMAGE_ATTRIB_HANDLE
:
481 *value
= image
->region
->bo
->handle
;
483 case __DRI_IMAGE_ATTRIB_NAME
:
484 return intel_region_flink(image
->region
, (uint32_t *) value
);
485 case __DRI_IMAGE_ATTRIB_FORMAT
:
486 *value
= image
->dri_format
;
488 case __DRI_IMAGE_ATTRIB_WIDTH
:
489 *value
= image
->region
->width
;
491 case __DRI_IMAGE_ATTRIB_HEIGHT
:
492 *value
= image
->region
->height
;
494 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
495 if (image
->planar_format
== NULL
)
497 *value
= image
->planar_format
->components
;
499 case __DRI_IMAGE_ATTRIB_FD
:
500 return !drm_intel_bo_gem_export_to_prime(image
->region
->bo
, value
);
507 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
511 image
= calloc(1, sizeof *image
);
515 intel_region_reference(&image
->region
, orig_image
->region
);
516 if (image
->region
== NULL
) {
521 image
->internal_format
= orig_image
->internal_format
;
522 image
->planar_format
= orig_image
->planar_format
;
523 image
->dri_format
= orig_image
->dri_format
;
524 image
->format
= orig_image
->format
;
525 image
->offset
= orig_image
->offset
;
526 image
->width
= orig_image
->width
;
527 image
->height
= orig_image
->height
;
528 image
->tile_x
= orig_image
->tile_x
;
529 image
->tile_y
= orig_image
->tile_y
;
530 image
->data
= loaderPrivate
;
532 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
533 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
539 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
541 if (use
& __DRI_IMAGE_USE_CURSOR
) {
542 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
550 intel_create_image_from_names(__DRIscreen
*screen
,
551 int width
, int height
, int fourcc
,
552 int *names
, int num_names
,
553 int *strides
, int *offsets
,
556 struct intel_image_format
*f
= NULL
;
560 if (screen
== NULL
|| names
== NULL
|| num_names
!= 1)
563 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
564 if (intel_image_formats
[i
].fourcc
== fourcc
) {
565 f
= &intel_image_formats
[i
];
572 image
= intel_create_image_from_name(screen
, width
, height
,
573 __DRI_IMAGE_FORMAT_NONE
,
574 names
[0], strides
[0],
580 image
->planar_format
= f
;
581 for (i
= 0; i
< f
->nplanes
; i
++) {
582 index
= f
->planes
[i
].buffer_index
;
583 image
->offsets
[index
] = offsets
[index
];
584 image
->strides
[index
] = strides
[index
];
591 intel_create_image_from_fds(__DRIscreen
*screen
,
592 int width
, int height
, int fourcc
,
593 int *fds
, int num_fds
, int *strides
, int *offsets
,
596 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
597 struct intel_image_format
*f
= NULL
;
601 if (fds
== NULL
|| num_fds
!= 1)
604 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
605 if (intel_image_formats
[i
].fourcc
== fourcc
) {
606 f
= &intel_image_formats
[i
];
613 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
617 image
->region
= intel_region_alloc_for_fd(intelScreen
,
618 f
->planes
[0].cpp
, width
, height
, strides
[0],
619 height
* strides
[0], fds
[0], "image");
620 if (image
->region
== NULL
) {
625 intel_setup_image_from_dimensions(image
);
627 image
->planar_format
= f
;
628 for (i
= 0; i
< f
->nplanes
; i
++) {
629 index
= f
->planes
[i
].buffer_index
;
630 image
->offsets
[index
] = offsets
[index
];
631 image
->strides
[index
] = strides
[index
];
639 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
641 int width
, height
, offset
, stride
, dri_format
, index
;
642 struct intel_image_format
*f
;
643 uint32_t mask_x
, mask_y
;
646 if (parent
== NULL
|| parent
->planar_format
== NULL
)
649 f
= parent
->planar_format
;
651 if (plane
>= f
->nplanes
)
654 width
= parent
->region
->width
>> f
->planes
[plane
].width_shift
;
655 height
= parent
->region
->height
>> f
->planes
[plane
].height_shift
;
656 dri_format
= f
->planes
[plane
].dri_format
;
657 index
= f
->planes
[plane
].buffer_index
;
658 offset
= parent
->offsets
[index
];
659 stride
= parent
->strides
[index
];
661 image
= intel_allocate_image(dri_format
, loaderPrivate
);
665 if (offset
+ height
* stride
> parent
->region
->bo
->size
) {
666 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
671 image
->region
= calloc(sizeof(*image
->region
), 1);
672 if (image
->region
== NULL
) {
677 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
678 image
->region
->width
= width
;
679 image
->region
->height
= height
;
680 image
->region
->pitch
= stride
;
681 image
->region
->refcount
= 1;
682 image
->region
->bo
= parent
->region
->bo
;
683 drm_intel_bo_reference(image
->region
->bo
);
684 image
->region
->tiling
= parent
->region
->tiling
;
685 image
->offset
= offset
;
686 intel_setup_image_from_dimensions(image
);
688 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
, false);
691 "intel_create_sub_image: offset not on tile boundary");
696 static const __DRIimageExtension intelImageExtension
= {
697 .base
= { __DRI_IMAGE
, 7 },
699 .createImageFromName
= intel_create_image_from_name
,
700 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
701 .destroyImage
= intel_destroy_image
,
702 .createImage
= intel_create_image
,
703 .queryImage
= intel_query_image
,
704 .dupImage
= intel_dup_image
,
705 .validateUsage
= intel_validate_usage
,
706 .createImageFromNames
= intel_create_image_from_names
,
707 .fromPlanar
= intel_from_planar
,
708 .createImageFromTexture
= intel_create_image_from_texture
,
709 .createImageFromFds
= intel_create_image_from_fds
713 i915_query_renderer_integer(__DRIscreen
*psp
, int param
, unsigned int *value
)
715 const struct intel_screen
*const intelScreen
=
716 (struct intel_screen
*) psp
->driverPrivate
;
719 case __DRI2_RENDERER_VENDOR_ID
:
722 case __DRI2_RENDERER_DEVICE_ID
:
723 value
[0] = intelScreen
->deviceID
;
725 case __DRI2_RENDERER_ACCELERATED
:
728 case __DRI2_RENDERER_VIDEO_MEMORY
: {
729 /* Once a batch uses more than 75% of the maximum mappable size, we
730 * assume that there's some fragmentation, and we start doing extra
731 * flushing, etc. That's the big cliff apps will care about.
734 size_t mappable_size
;
736 drm_intel_get_aperture_sizes(psp
->fd
, &mappable_size
, &aper_size
);
738 const unsigned gpu_mappable_megabytes
=
739 (aper_size
/ (1024 * 1024)) * 3 / 4;
741 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
742 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
744 if (system_memory_pages
<= 0 || system_page_size
<= 0)
747 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
748 * (uint64_t) system_page_size
;
750 const unsigned system_memory_megabytes
=
751 (unsigned) (system_memory_bytes
/ (1024 * 1024));
753 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
756 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
759 case __DRI2_RENDERER_HAS_TEXTURE_3D
:
763 return driQueryRendererIntegerCommon(psp
, param
, value
);
770 i915_query_renderer_string(__DRIscreen
*psp
, int param
, const char **value
)
772 const struct intel_screen
*intelScreen
=
773 (struct intel_screen
*) psp
->driverPrivate
;
776 case __DRI2_RENDERER_VENDOR_ID
:
777 value
[0] = i915_vendor_string
;
779 case __DRI2_RENDERER_DEVICE_ID
:
780 value
[0] = i915_get_renderer_string(intelScreen
->deviceID
);
789 static const __DRI2rendererQueryExtension intelRendererQueryExtension
= {
790 .base
= { __DRI2_RENDERER_QUERY
, 1 },
792 .queryInteger
= i915_query_renderer_integer
,
793 .queryString
= i915_query_renderer_string
796 static const __DRIextension
*intelScreenExtensions
[] = {
797 &intelTexBufferExtension
.base
,
798 &intelFenceExtension
.base
,
799 &intelFlushExtension
.base
,
800 &intelImageExtension
.base
,
801 &intelRendererQueryExtension
.base
,
802 &dri2ConfigQueryExtension
.base
,
807 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
810 struct drm_i915_getparam gp
;
812 memset(&gp
, 0, sizeof(gp
));
816 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
819 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
827 intel_get_boolean(__DRIscreen
*psp
, int param
)
830 return intel_get_param(psp
, param
, &value
) && value
;
834 intelDestroyScreen(__DRIscreen
* sPriv
)
836 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
838 dri_bufmgr_destroy(intelScreen
->bufmgr
);
839 driDestroyOptionInfo(&intelScreen
->optionCache
);
842 sPriv
->driverPrivate
= NULL
;
847 * This is called when we need to set up GL rendering to a new X window.
850 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
851 __DRIdrawable
* driDrawPriv
,
852 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
854 struct intel_renderbuffer
*rb
;
855 mesa_format rgbFormat
;
856 struct gl_framebuffer
*fb
;
861 fb
= CALLOC_STRUCT(gl_framebuffer
);
865 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
867 if (mesaVis
->redBits
== 5)
868 rgbFormat
= MESA_FORMAT_B5G6R5_UNORM
;
869 else if (mesaVis
->sRGBCapable
)
870 rgbFormat
= MESA_FORMAT_B8G8R8A8_SRGB
;
871 else if (mesaVis
->alphaBits
== 0)
872 rgbFormat
= MESA_FORMAT_B8G8R8X8_UNORM
;
874 rgbFormat
= MESA_FORMAT_B8G8R8A8_UNORM
;
876 /* setup the hardware-based renderbuffers */
877 rb
= intel_create_renderbuffer(rgbFormat
);
878 _mesa_attach_and_own_rb(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
880 if (mesaVis
->doubleBufferMode
) {
881 rb
= intel_create_renderbuffer(rgbFormat
);
882 _mesa_attach_and_own_rb(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
886 * Assert here that the gl_config has an expected depth/stencil bit
887 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
888 * which constructs the advertised configs.)
890 if (mesaVis
->depthBits
== 24) {
891 assert(mesaVis
->stencilBits
== 8);
894 * Use combined depth/stencil. Note that the renderbuffer is
895 * attached to two attachment points.
897 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_S8_UINT
);
898 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
899 _mesa_attach_and_reference_rb(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
901 else if (mesaVis
->depthBits
== 16) {
902 assert(mesaVis
->stencilBits
== 0);
903 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z_UNORM16
);
904 _mesa_attach_and_own_rb(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
907 assert(mesaVis
->depthBits
== 0);
908 assert(mesaVis
->stencilBits
== 0);
911 /* now add any/all software-based renderbuffers we may need */
912 _swrast_add_soft_renderbuffers(fb
,
913 false, /* never sw color */
914 false, /* never sw depth */
915 false, /* never sw stencil */
916 mesaVis
->accumRedBits
> 0,
917 false, /* never sw alpha */
918 false /* never sw aux */ );
919 driDrawPriv
->driverPrivate
= fb
;
925 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
927 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
929 _mesa_reference_framebuffer(&fb
, NULL
);
932 /* There are probably better ways to do this, such as an
933 * init-designated function to register chipids and createcontext
937 i830CreateContext(int api
,
938 const struct gl_config
*mesaVis
,
939 __DRIcontext
*driContextPriv
,
940 unsigned major_version
,
941 unsigned minor_version
,
944 void *sharedContextPrivate
);
947 i915CreateContext(int api
,
948 const struct gl_config
*mesaVis
,
949 __DRIcontext
*driContextPriv
,
950 unsigned major_version
,
951 unsigned minor_version
,
954 void *sharedContextPrivate
);
957 intelCreateContext(gl_api api
,
958 const struct gl_config
* mesaVis
,
959 __DRIcontext
* driContextPriv
,
960 unsigned major_version
,
961 unsigned minor_version
,
965 void *sharedContextPrivate
)
967 bool success
= false;
969 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
970 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
972 if (flags
& ~__DRI_CTX_FLAG_DEBUG
) {
973 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
978 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
982 if (IS_GEN3(intelScreen
->deviceID
)) {
983 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
984 major_version
, minor_version
, flags
,
985 error
, sharedContextPrivate
);
987 intelScreen
->no_vbo
= true;
988 success
= i830CreateContext(api
, mesaVis
, driContextPriv
,
989 major_version
, minor_version
, flags
,
990 error
, sharedContextPrivate
);
996 if (driContextPriv
->driverPrivate
!= NULL
)
997 intelDestroyContext(driContextPriv
);
1003 intel_init_bufmgr(struct intel_screen
*intelScreen
)
1005 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
1007 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
1009 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
1010 if (intelScreen
->bufmgr
== NULL
) {
1011 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1012 __func__
, __LINE__
);
1016 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
1018 if (!intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
)) {
1019 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
1027 intel_detect_swizzling(struct intel_screen
*screen
)
1029 drm_intel_bo
*buffer
;
1030 unsigned long flags
= 0;
1031 unsigned long aligned_pitch
;
1032 uint32_t tiling
= I915_TILING_X
;
1033 uint32_t swizzle_mode
= 0;
1035 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
1037 &tiling
, &aligned_pitch
, flags
);
1041 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1042 drm_intel_bo_unreference(buffer
);
1044 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
1050 static __DRIconfig
**
1051 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1053 static const mesa_format formats
[] = {
1054 MESA_FORMAT_B5G6R5_UNORM
,
1055 MESA_FORMAT_B8G8R8A8_UNORM
,
1056 MESA_FORMAT_B8G8R8X8_UNORM
1059 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1060 static const GLenum back_buffer_modes
[] = {
1061 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1064 static const uint8_t singlesample_samples
[1] = {0};
1066 uint8_t depth_bits
[4], stencil_bits
[4];
1067 __DRIconfig
**configs
= NULL
;
1069 /* Generate singlesample configs without accumulation buffer. */
1070 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1071 __DRIconfig
**new_configs
;
1072 int num_depth_stencil_bits
= 2;
1074 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1075 * buffer that has a different number of bits per pixel than the color
1079 stencil_bits
[0] = 0;
1081 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
1083 stencil_bits
[1] = 0;
1086 stencil_bits
[1] = 8;
1089 new_configs
= driCreateConfigs(formats
[i
],
1092 num_depth_stencil_bits
,
1093 back_buffer_modes
, 2,
1094 singlesample_samples
, 1,
1096 configs
= driConcatConfigs(configs
, new_configs
);
1099 /* Generate the minimum possible set of configs that include an
1100 * accumulation buffer.
1102 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1103 __DRIconfig
**new_configs
;
1105 if (formats
[i
] == MESA_FORMAT_B5G6R5_UNORM
) {
1107 stencil_bits
[0] = 0;
1110 stencil_bits
[0] = 8;
1113 new_configs
= driCreateConfigs(formats
[i
],
1114 depth_bits
, stencil_bits
, 1,
1115 back_buffer_modes
, 1,
1116 singlesample_samples
, 1,
1118 configs
= driConcatConfigs(configs
, new_configs
);
1121 if (configs
== NULL
) {
1122 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1131 set_max_gl_versions(struct intel_screen
*screen
)
1133 __DRIscreen
*psp
= screen
->driScrnPriv
;
1135 switch (screen
->gen
) {
1137 bool has_fragment_shader
= driQueryOptionb(&screen
->optionCache
, "fragment_shader");
1138 bool has_occlusion_query
= driQueryOptionb(&screen
->optionCache
, "stub_occlusion_query");
1140 psp
->max_gl_core_version
= 0;
1141 psp
->max_gl_es1_version
= 11;
1142 psp
->max_gl_es2_version
= 20;
1144 if (has_fragment_shader
&& has_occlusion_query
) {
1145 psp
->max_gl_compat_version
= 21;
1147 psp
->max_gl_compat_version
= 14;
1152 psp
->max_gl_core_version
= 0;
1153 psp
->max_gl_compat_version
= 13;
1154 psp
->max_gl_es1_version
= 11;
1155 psp
->max_gl_es2_version
= 0;
1158 assert(!"unrecognized intel_screen::gen");
1164 * This is the driver specific part of the createNewScreen entry point.
1165 * Called when using DRI2.
1167 * \return the struct gl_config supported by this driver
1170 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
1172 struct intel_screen
*intelScreen
;
1174 if (psp
->image
.loader
) {
1175 } else if (psp
->dri2
.loader
->base
.version
<= 2 ||
1176 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1178 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1179 "support required\n");
1183 /* Allocate the private area */
1184 intelScreen
= calloc(1, sizeof *intelScreen
);
1186 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1189 /* parse information in __driConfigOptions */
1190 driParseOptionInfo(&intelScreen
->optionCache
, i915_config_options
.xml
);
1192 intelScreen
->driScrnPriv
= psp
;
1193 psp
->driverPrivate
= (void *) intelScreen
;
1195 if (!intel_init_bufmgr(intelScreen
))
1198 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1200 if (IS_GEN3(intelScreen
->deviceID
)) {
1201 intelScreen
->gen
= 3;
1203 intelScreen
->gen
= 2;
1206 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1208 set_max_gl_versions(intelScreen
);
1210 psp
->extensions
= intelScreenExtensions
;
1212 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1215 struct intel_buffer
{
1217 struct intel_region
*region
;
1220 static __DRIbuffer
*
1221 intelAllocateBuffer(__DRIscreen
*screen
,
1222 unsigned attachment
, unsigned format
,
1223 int width
, int height
)
1225 struct intel_buffer
*intelBuffer
;
1226 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1228 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1229 attachment
== __DRI_BUFFER_BACK_LEFT
);
1231 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1232 if (intelBuffer
== NULL
)
1235 /* The front and back buffers are color buffers, which are X tiled. */
1236 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1243 if (intelBuffer
->region
== NULL
) {
1248 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1250 intelBuffer
->base
.attachment
= attachment
;
1251 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1252 intelBuffer
->base
.pitch
= intelBuffer
->region
->pitch
;
1254 return &intelBuffer
->base
;
1258 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1260 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1262 intel_region_release(&intelBuffer
->region
);
1267 static const struct __DriverAPIRec i915_driver_api
= {
1268 .InitScreen
= intelInitScreen2
,
1269 .DestroyScreen
= intelDestroyScreen
,
1270 .CreateContext
= intelCreateContext
,
1271 .DestroyContext
= intelDestroyContext
,
1272 .CreateBuffer
= intelCreateBuffer
,
1273 .DestroyBuffer
= intelDestroyBuffer
,
1274 .MakeCurrent
= intelMakeCurrent
,
1275 .UnbindContext
= intelUnbindContext
,
1276 .AllocateBuffer
= intelAllocateBuffer
,
1277 .ReleaseBuffer
= intelReleaseBuffer
1280 static const struct __DRIDriverVtableExtensionRec i915_vtable
= {
1281 .base
= { __DRI_DRIVER_VTABLE
, 1 },
1282 .vtable
= &i915_driver_api
,
1285 /* This is the table of extensions that the loader will dlsym() for. */
1286 static const __DRIextension
*i915_driver_extensions
[] = {
1287 &driCoreExtension
.base
,
1288 &driImageDriverExtension
.base
,
1289 &driDRI2Extension
.base
,
1291 &i915_config_options
.base
,
1295 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i915(void)
1297 globalDriverAPI
= &i915_driver_api
;
1299 return i915_driver_extensions
;