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).")
66 DRI_CONF_SECTION_QUALITY
67 DRI_CONF_FORCE_S3TC_ENABLE("false")
69 DRI_CONF_SECTION_DEBUG
70 DRI_CONF_NO_RAST("false")
71 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
72 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
73 DRI_CONF_DISABLE_THROTTLING("false")
74 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
75 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
76 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
78 DRI_CONF_OPT_BEGIN_B(shader_precompile
, "true")
79 DRI_CONF_DESC(en
, "Perform code generation at shader link time.")
85 #include "intel_batchbuffer.h"
86 #include "intel_buffers.h"
87 #include "intel_bufmgr.h"
88 #include "intel_chipset.h"
89 #include "intel_fbo.h"
90 #include "intel_mipmap_tree.h"
91 #include "intel_screen.h"
92 #include "intel_tex.h"
93 #include "intel_regions.h"
97 #ifdef USE_NEW_INTERFACE
98 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
99 #endif /*USE_NEW_INTERFACE */
102 * For debugging purposes, this returns a time in seconds.
109 clock_gettime(CLOCK_MONOTONIC
, &tp
);
111 return tp
.tv_sec
+ tp
.tv_nsec
/ 1000000000.0;
115 aub_dump_bmp(struct gl_context
*ctx
)
117 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
119 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
120 struct intel_renderbuffer
*irb
=
121 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
123 if (irb
&& irb
->mt
) {
124 enum aub_dump_bmp_format format
;
126 switch (irb
->Base
.Base
.Format
) {
127 case MESA_FORMAT_ARGB8888
:
128 case MESA_FORMAT_XRGB8888
:
129 format
= AUB_DUMP_BMP_FORMAT_ARGB_8888
;
135 assert(irb
->mt
->region
->pitch
% irb
->mt
->region
->cpp
== 0);
136 drm_intel_gem_bo_aub_dump_bmp(irb
->mt
->region
->bo
,
139 irb
->Base
.Base
.Width
,
140 irb
->Base
.Base
.Height
,
142 irb
->mt
->region
->pitch
,
148 static const __DRItexBufferExtension intelTexBufferExtension
= {
149 .base
= { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
151 .setTexBuffer
= intelSetTexBuffer
,
152 .setTexBuffer2
= intelSetTexBuffer2
,
153 .releaseTexBuffer
= NULL
,
157 intelDRI2Flush(__DRIdrawable
*drawable
)
159 GET_CURRENT_CONTEXT(ctx
);
160 struct intel_context
*intel
= intel_context(ctx
);
164 INTEL_FIREVERTICES(intel
);
166 intel
->need_throttle
= true;
168 if (intel
->batch
.used
)
169 intel_batchbuffer_flush(intel
);
171 if (INTEL_DEBUG
& DEBUG_AUB
) {
176 static const struct __DRI2flushExtensionRec intelFlushExtension
= {
177 .base
= { __DRI2_FLUSH
, 3 },
179 .flush
= intelDRI2Flush
,
180 .invalidate
= dri2InvalidateDrawable
,
183 static struct intel_image_format intel_image_formats
[] = {
184 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_COMPONENTS_RGBA
, 1,
185 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
187 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_COMPONENTS_RGB
, 1,
188 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
190 { __DRI_IMAGE_FOURCC_YUV410
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
191 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
192 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
193 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
195 { __DRI_IMAGE_FOURCC_YUV411
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
196 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
197 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
198 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
200 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
201 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
202 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
203 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
205 { __DRI_IMAGE_FOURCC_YUV422
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
206 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
207 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
208 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
210 { __DRI_IMAGE_FOURCC_YUV444
, __DRI_IMAGE_COMPONENTS_Y_U_V
, 3,
211 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
212 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
213 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
215 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
216 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
217 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
219 { __DRI_IMAGE_FOURCC_NV16
, __DRI_IMAGE_COMPONENTS_Y_UV
, 2,
220 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
221 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
223 /* For YUYV buffers, we set up two overlapping DRI images and treat
224 * them as planar buffers in the compositors. Plane 0 is GR88 and
225 * samples YU or YV pairs and places Y into the R component, while
226 * plane 1 is ARGB and samples YUYV clusters and places pairs and
227 * places U into the G component and V into A. This lets the
228 * texture sampler interpolate the Y components correctly when
229 * sampling from plane 0, and interpolate U and V correctly when
230 * sampling from plane 1. */
231 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_COMPONENTS_Y_XUXV
, 2,
232 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
233 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } }
237 intel_allocate_image(int dri_format
, void *loaderPrivate
)
241 image
= calloc(1, sizeof *image
);
245 image
->dri_format
= dri_format
;
248 image
->format
= driImageFormatToGLFormat(dri_format
);
249 if (dri_format
!= __DRI_IMAGE_FORMAT_NONE
&&
250 image
->format
== MESA_FORMAT_NONE
) {
255 image
->internal_format
= _mesa_get_format_base_format(image
->format
);
256 image
->data
= loaderPrivate
;
262 * Sets up a DRIImage structure to point to our shared image in a region
265 intel_setup_image_from_mipmap_tree(struct intel_context
*intel
, __DRIimage
*image
,
266 struct intel_mipmap_tree
*mt
, GLuint level
,
269 unsigned int draw_x
, draw_y
;
270 uint32_t mask_x
, mask_y
;
272 intel_miptree_check_level_layer(mt
, level
, zoffset
);
274 intel_region_get_tile_masks(mt
->region
, &mask_x
, &mask_y
, false);
275 intel_miptree_get_image_offset(mt
, level
, zoffset
, &draw_x
, &draw_y
);
277 image
->width
= mt
->level
[level
].width
;
278 image
->height
= mt
->level
[level
].height
;
279 image
->tile_x
= draw_x
& mask_x
;
280 image
->tile_y
= draw_y
& mask_y
;
282 image
->offset
= intel_region_get_aligned_offset(mt
->region
,
287 intel_region_reference(&image
->region
, mt
->region
);
291 intel_setup_image_from_dimensions(__DRIimage
*image
)
293 image
->width
= image
->region
->width
;
294 image
->height
= image
->region
->height
;
300 intel_create_image_from_name(__DRIscreen
*screen
,
301 int width
, int height
, int format
,
302 int name
, int pitch
, void *loaderPrivate
)
304 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
308 image
= intel_allocate_image(format
, loaderPrivate
);
312 if (image
->format
== MESA_FORMAT_NONE
)
315 cpp
= _mesa_get_format_bytes(image
->format
);
316 image
->region
= intel_region_alloc_for_handle(intelScreen
,
318 pitch
* cpp
, name
, "image");
319 if (image
->region
== NULL
) {
324 intel_setup_image_from_dimensions(image
);
330 intel_create_image_from_renderbuffer(__DRIcontext
*context
,
331 int renderbuffer
, void *loaderPrivate
)
334 struct intel_context
*intel
= context
->driverPrivate
;
335 struct gl_renderbuffer
*rb
;
336 struct intel_renderbuffer
*irb
;
338 rb
= _mesa_lookup_renderbuffer(&intel
->ctx
, renderbuffer
);
340 _mesa_error(&intel
->ctx
,
341 GL_INVALID_OPERATION
, "glRenderbufferExternalMESA");
345 irb
= intel_renderbuffer(rb
);
346 image
= calloc(1, sizeof *image
);
350 image
->internal_format
= rb
->InternalFormat
;
351 image
->format
= rb
->Format
;
353 image
->data
= loaderPrivate
;
354 intel_region_reference(&image
->region
, irb
->mt
->region
);
355 intel_setup_image_from_dimensions(image
);
356 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
358 rb
->NeedsFinishRenderTexture
= true;
363 intel_create_image_from_texture(__DRIcontext
*context
, int target
,
364 unsigned texture
, int zoffset
,
370 struct intel_context
*intel
= context
->driverPrivate
;
371 struct gl_texture_object
*obj
;
372 struct intel_texture_object
*iobj
;
375 obj
= _mesa_lookup_texture(&intel
->ctx
, texture
);
376 if (!obj
|| obj
->Target
!= target
) {
377 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
381 if (target
== GL_TEXTURE_CUBE_MAP
)
384 _mesa_test_texobj_completeness(&intel
->ctx
, obj
);
385 iobj
= intel_texture_object(obj
);
386 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
387 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
391 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
392 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
396 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< zoffset
) {
397 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
400 image
= calloc(1, sizeof *image
);
402 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
406 image
->internal_format
= obj
->Image
[face
][level
]->InternalFormat
;
407 image
->format
= obj
->Image
[face
][level
]->TexFormat
;
408 image
->data
= loaderPrivate
;
409 intel_setup_image_from_mipmap_tree(intel
, image
, iobj
->mt
, level
, zoffset
);
410 image
->dri_format
= driGLFormatToImageFormat(image
->format
);
411 if (image
->dri_format
== MESA_FORMAT_NONE
) {
412 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
417 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
422 intel_destroy_image(__DRIimage
*image
)
424 intel_region_release(&image
->region
);
429 intel_create_image(__DRIscreen
*screen
,
430 int width
, int height
, int format
,
435 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
439 tiling
= I915_TILING_X
;
440 if (use
& __DRI_IMAGE_USE_CURSOR
) {
441 if (width
!= 64 || height
!= 64)
443 tiling
= I915_TILING_NONE
;
446 if (use
& __DRI_IMAGE_USE_LINEAR
)
447 tiling
= I915_TILING_NONE
;
449 image
= intel_allocate_image(format
, loaderPrivate
);
453 cpp
= _mesa_get_format_bytes(image
->format
);
455 intel_region_alloc(intelScreen
, tiling
, cpp
, width
, height
, true);
456 if (image
->region
== NULL
) {
461 intel_setup_image_from_dimensions(image
);
467 intel_query_image(__DRIimage
*image
, int attrib
, int *value
)
470 case __DRI_IMAGE_ATTRIB_STRIDE
:
471 *value
= image
->region
->pitch
;
473 case __DRI_IMAGE_ATTRIB_HANDLE
:
474 *value
= image
->region
->bo
->handle
;
476 case __DRI_IMAGE_ATTRIB_NAME
:
477 return intel_region_flink(image
->region
, (uint32_t *) value
);
478 case __DRI_IMAGE_ATTRIB_FORMAT
:
479 *value
= image
->dri_format
;
481 case __DRI_IMAGE_ATTRIB_WIDTH
:
482 *value
= image
->region
->width
;
484 case __DRI_IMAGE_ATTRIB_HEIGHT
:
485 *value
= image
->region
->height
;
487 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
488 if (image
->planar_format
== NULL
)
490 *value
= image
->planar_format
->components
;
492 case __DRI_IMAGE_ATTRIB_FD
:
493 if (drm_intel_bo_gem_export_to_prime(image
->region
->bo
, value
) == 0)
502 intel_dup_image(__DRIimage
*orig_image
, void *loaderPrivate
)
506 image
= calloc(1, sizeof *image
);
510 intel_region_reference(&image
->region
, orig_image
->region
);
511 if (image
->region
== NULL
) {
516 image
->internal_format
= orig_image
->internal_format
;
517 image
->planar_format
= orig_image
->planar_format
;
518 image
->dri_format
= orig_image
->dri_format
;
519 image
->format
= orig_image
->format
;
520 image
->offset
= orig_image
->offset
;
521 image
->width
= orig_image
->width
;
522 image
->height
= orig_image
->height
;
523 image
->tile_x
= orig_image
->tile_x
;
524 image
->tile_y
= orig_image
->tile_y
;
525 image
->data
= loaderPrivate
;
527 memcpy(image
->strides
, orig_image
->strides
, sizeof(image
->strides
));
528 memcpy(image
->offsets
, orig_image
->offsets
, sizeof(image
->offsets
));
534 intel_validate_usage(__DRIimage
*image
, unsigned int use
)
536 if (use
& __DRI_IMAGE_USE_CURSOR
) {
537 if (image
->region
->width
!= 64 || image
->region
->height
!= 64)
545 intel_create_image_from_names(__DRIscreen
*screen
,
546 int width
, int height
, int fourcc
,
547 int *names
, int num_names
,
548 int *strides
, int *offsets
,
551 struct intel_image_format
*f
= NULL
;
555 if (screen
== NULL
|| names
== NULL
|| num_names
!= 1)
558 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
559 if (intel_image_formats
[i
].fourcc
== fourcc
) {
560 f
= &intel_image_formats
[i
];
567 image
= intel_create_image_from_name(screen
, width
, height
,
568 __DRI_IMAGE_FORMAT_NONE
,
569 names
[0], strides
[0],
575 image
->planar_format
= f
;
576 for (i
= 0; i
< f
->nplanes
; i
++) {
577 index
= f
->planes
[i
].buffer_index
;
578 image
->offsets
[index
] = offsets
[index
];
579 image
->strides
[index
] = strides
[index
];
586 intel_create_image_from_fds(__DRIscreen
*screen
,
587 int width
, int height
, int fourcc
,
588 int *fds
, int num_fds
, int *strides
, int *offsets
,
591 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
592 struct intel_image_format
*f
= NULL
;
596 if (fds
== NULL
|| num_fds
!= 1)
599 for (i
= 0; i
< ARRAY_SIZE(intel_image_formats
); i
++) {
600 if (intel_image_formats
[i
].fourcc
== fourcc
) {
601 f
= &intel_image_formats
[i
];
608 image
= intel_allocate_image(__DRI_IMAGE_FORMAT_NONE
, loaderPrivate
);
612 image
->region
= intel_region_alloc_for_fd(intelScreen
,
613 f
->planes
[0].cpp
, width
, height
, strides
[0],
614 height
* strides
[0], fds
[0], "image");
615 if (image
->region
== NULL
) {
620 image
->planar_format
= f
;
621 for (i
= 0; i
< f
->nplanes
; i
++) {
622 index
= f
->planes
[i
].buffer_index
;
623 image
->offsets
[index
] = offsets
[index
];
624 image
->strides
[index
] = strides
[index
];
632 intel_from_planar(__DRIimage
*parent
, int plane
, void *loaderPrivate
)
634 int width
, height
, offset
, stride
, dri_format
, index
;
635 struct intel_image_format
*f
;
636 uint32_t mask_x
, mask_y
;
639 if (parent
== NULL
|| parent
->planar_format
== NULL
)
642 f
= parent
->planar_format
;
644 if (plane
>= f
->nplanes
)
647 width
= parent
->region
->width
>> f
->planes
[plane
].width_shift
;
648 height
= parent
->region
->height
>> f
->planes
[plane
].height_shift
;
649 dri_format
= f
->planes
[plane
].dri_format
;
650 index
= f
->planes
[plane
].buffer_index
;
651 offset
= parent
->offsets
[index
];
652 stride
= parent
->strides
[index
];
654 image
= intel_allocate_image(dri_format
, loaderPrivate
);
658 if (offset
+ height
* stride
> parent
->region
->bo
->size
) {
659 _mesa_warning(NULL
, "intel_create_sub_image: subimage out of bounds");
664 image
->region
= calloc(sizeof(*image
->region
), 1);
665 if (image
->region
== NULL
) {
670 image
->region
->cpp
= _mesa_get_format_bytes(image
->format
);
671 image
->region
->width
= width
;
672 image
->region
->height
= height
;
673 image
->region
->pitch
= stride
;
674 image
->region
->refcount
= 1;
675 image
->region
->bo
= parent
->region
->bo
;
676 drm_intel_bo_reference(image
->region
->bo
);
677 image
->region
->tiling
= parent
->region
->tiling
;
678 image
->offset
= offset
;
679 intel_setup_image_from_dimensions(image
);
681 intel_region_get_tile_masks(image
->region
, &mask_x
, &mask_y
, false);
684 "intel_create_sub_image: offset not on tile boundary");
689 static struct __DRIimageExtensionRec intelImageExtension
= {
690 .base
= { __DRI_IMAGE
, 7 },
692 .createImageFromName
= intel_create_image_from_name
,
693 .createImageFromRenderbuffer
= intel_create_image_from_renderbuffer
,
694 .destroyImage
= intel_destroy_image
,
695 .createImage
= intel_create_image
,
696 .queryImage
= intel_query_image
,
697 .dupImage
= intel_dup_image
,
698 .validateUsage
= intel_validate_usage
,
699 .createImageFromNames
= intel_create_image_from_names
,
700 .fromPlanar
= intel_from_planar
,
701 .createImageFromTexture
= intel_create_image_from_texture
,
702 .createImageFromFds
= intel_create_image_from_fds
706 i915_query_renderer_integer(__DRIscreen
*psp
, int param
, unsigned int *value
)
708 const struct intel_screen
*const intelScreen
=
709 (struct intel_screen
*) psp
->driverPrivate
;
712 case __DRI2_RENDERER_VENDOR_ID
:
715 case __DRI2_RENDERER_DEVICE_ID
:
716 value
[0] = intelScreen
->deviceID
;
718 case __DRI2_RENDERER_ACCELERATED
:
721 case __DRI2_RENDERER_VIDEO_MEMORY
: {
722 /* Once a batch uses more than 75% of the maximum mappable size, we
723 * assume that there's some fragmentation, and we start doing extra
724 * flushing, etc. That's the big cliff apps will care about.
727 size_t mappable_size
;
729 drm_intel_get_aperture_sizes(psp
->fd
, &mappable_size
, &aper_size
);
731 const unsigned gpu_mappable_megabytes
=
732 (aper_size
/ (1024 * 1024)) * 3 / 4;
734 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
735 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
737 if (system_memory_pages
<= 0 || system_page_size
<= 0)
740 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
741 * (uint64_t) system_page_size
;
743 const unsigned system_memory_megabytes
=
744 (unsigned) (system_memory_bytes
/ 1024);
746 value
[0] = MIN2(system_memory_megabytes
, gpu_mappable_megabytes
);
749 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
752 case __DRI2_RENDERER_PREFERRED_PROFILE
:
753 value
[0] = (1U << __DRI_API_OPENGL
);
756 return driQueryRendererIntegerCommon(psp
, param
, value
);
763 i915_query_renderer_string(__DRIscreen
*psp
, int param
, const char **value
)
765 const struct intel_screen
*intelScreen
=
766 (struct intel_screen
*) psp
->driverPrivate
;
769 case __DRI2_RENDERER_VENDOR_ID
:
770 value
[0] = i915_vendor_string
;
772 case __DRI2_RENDERER_DEVICE_ID
:
773 value
[0] = i915_get_renderer_string(intelScreen
->deviceID
);
782 static struct __DRI2rendererQueryExtensionRec intelRendererQueryExtension
= {
783 .base
= { __DRI2_RENDERER_QUERY
, 1 },
785 .queryInteger
= i915_query_renderer_integer
,
786 .queryString
= i915_query_renderer_string
789 static const __DRIextension
*intelScreenExtensions
[] = {
790 &intelTexBufferExtension
.base
,
791 &intelFlushExtension
.base
,
792 &intelImageExtension
.base
,
793 &intelRendererQueryExtension
.base
,
794 &dri2ConfigQueryExtension
.base
,
799 intel_get_param(__DRIscreen
*psp
, int param
, int *value
)
802 struct drm_i915_getparam gp
;
804 memset(&gp
, 0, sizeof(gp
));
808 ret
= drmCommandWriteRead(psp
->fd
, DRM_I915_GETPARAM
, &gp
, sizeof(gp
));
811 _mesa_warning(NULL
, "drm_i915_getparam: %d", ret
);
819 intel_get_boolean(__DRIscreen
*psp
, int param
)
822 return intel_get_param(psp
, param
, &value
) && value
;
826 intelDestroyScreen(__DRIscreen
* sPriv
)
828 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
830 dri_bufmgr_destroy(intelScreen
->bufmgr
);
831 driDestroyOptionInfo(&intelScreen
->optionCache
);
834 sPriv
->driverPrivate
= NULL
;
839 * This is called when we need to set up GL rendering to a new X window.
842 intelCreateBuffer(__DRIscreen
* driScrnPriv
,
843 __DRIdrawable
* driDrawPriv
,
844 const struct gl_config
* mesaVis
, GLboolean isPixmap
)
846 struct intel_renderbuffer
*rb
;
848 struct gl_framebuffer
*fb
;
853 fb
= CALLOC_STRUCT(gl_framebuffer
);
857 _mesa_initialize_window_framebuffer(fb
, mesaVis
);
859 if (mesaVis
->redBits
== 5)
860 rgbFormat
= MESA_FORMAT_RGB565
;
861 else if (mesaVis
->sRGBCapable
)
862 rgbFormat
= MESA_FORMAT_SARGB8
;
863 else if (mesaVis
->alphaBits
== 0)
864 rgbFormat
= MESA_FORMAT_XRGB8888
;
866 rgbFormat
= MESA_FORMAT_ARGB8888
;
868 /* setup the hardware-based renderbuffers */
869 rb
= intel_create_renderbuffer(rgbFormat
);
870 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &rb
->Base
.Base
);
872 if (mesaVis
->doubleBufferMode
) {
873 rb
= intel_create_renderbuffer(rgbFormat
);
874 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &rb
->Base
.Base
);
878 * Assert here that the gl_config has an expected depth/stencil bit
879 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
880 * which constructs the advertised configs.)
882 if (mesaVis
->depthBits
== 24) {
883 assert(mesaVis
->stencilBits
== 8);
886 * Use combined depth/stencil. Note that the renderbuffer is
887 * attached to two attachment points.
889 rb
= intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24
);
890 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
891 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &rb
->Base
.Base
);
893 else if (mesaVis
->depthBits
== 16) {
894 assert(mesaVis
->stencilBits
== 0);
895 rb
= intel_create_private_renderbuffer(MESA_FORMAT_Z16
);
896 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &rb
->Base
.Base
);
899 assert(mesaVis
->depthBits
== 0);
900 assert(mesaVis
->stencilBits
== 0);
903 /* now add any/all software-based renderbuffers we may need */
904 _swrast_add_soft_renderbuffers(fb
,
905 false, /* never sw color */
906 false, /* never sw depth */
907 false, /* never sw stencil */
908 mesaVis
->accumRedBits
> 0,
909 false, /* never sw alpha */
910 false /* never sw aux */ );
911 driDrawPriv
->driverPrivate
= fb
;
917 intelDestroyBuffer(__DRIdrawable
* driDrawPriv
)
919 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
921 _mesa_reference_framebuffer(&fb
, NULL
);
924 /* There are probably better ways to do this, such as an
925 * init-designated function to register chipids and createcontext
929 i830CreateContext(int api
,
930 const struct gl_config
*mesaVis
,
931 __DRIcontext
*driContextPriv
,
932 unsigned major_version
,
933 unsigned minor_version
,
936 void *sharedContextPrivate
);
939 i915CreateContext(int api
,
940 const struct gl_config
*mesaVis
,
941 __DRIcontext
*driContextPriv
,
942 unsigned major_version
,
943 unsigned minor_version
,
946 void *sharedContextPrivate
);
949 intelCreateContext(gl_api api
,
950 const struct gl_config
* mesaVis
,
951 __DRIcontext
* driContextPriv
,
952 unsigned major_version
,
953 unsigned minor_version
,
957 void *sharedContextPrivate
)
959 bool success
= false;
961 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
962 struct intel_screen
*intelScreen
= sPriv
->driverPrivate
;
964 if (flags
& ~__DRI_CTX_FLAG_DEBUG
) {
965 *error
= __DRI_CTX_ERROR_UNKNOWN_FLAG
;
970 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
974 if (IS_9XX(intelScreen
->deviceID
)) {
975 success
= i915CreateContext(api
, mesaVis
, driContextPriv
,
976 major_version
, minor_version
, flags
,
977 error
, sharedContextPrivate
);
979 intelScreen
->no_vbo
= true;
980 success
= i830CreateContext(api
, mesaVis
, driContextPriv
,
981 major_version
, minor_version
, flags
,
982 error
, sharedContextPrivate
);
988 if (driContextPriv
->driverPrivate
!= NULL
)
989 intelDestroyContext(driContextPriv
);
995 intel_init_bufmgr(struct intel_screen
*intelScreen
)
997 __DRIscreen
*spriv
= intelScreen
->driScrnPriv
;
999 intelScreen
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
1001 intelScreen
->bufmgr
= intel_bufmgr_gem_init(spriv
->fd
, BATCH_SZ
);
1002 if (intelScreen
->bufmgr
== NULL
) {
1003 fprintf(stderr
, "[%s:%u] Error initializing buffer manager.\n",
1004 __func__
, __LINE__
);
1008 drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen
->bufmgr
);
1010 if (!intel_get_boolean(spriv
, I915_PARAM_HAS_RELAXED_DELTA
)) {
1011 fprintf(stderr
, "[%s: %u] Kernel 2.6.39 required.\n", __func__
, __LINE__
);
1019 intel_detect_swizzling(struct intel_screen
*screen
)
1021 drm_intel_bo
*buffer
;
1022 unsigned long flags
= 0;
1023 unsigned long aligned_pitch
;
1024 uint32_t tiling
= I915_TILING_X
;
1025 uint32_t swizzle_mode
= 0;
1027 buffer
= drm_intel_bo_alloc_tiled(screen
->bufmgr
, "swizzle test",
1029 &tiling
, &aligned_pitch
, flags
);
1033 drm_intel_bo_get_tiling(buffer
, &tiling
, &swizzle_mode
);
1034 drm_intel_bo_unreference(buffer
);
1036 if (swizzle_mode
== I915_BIT_6_SWIZZLE_NONE
)
1042 static __DRIconfig
**
1043 intel_screen_make_configs(__DRIscreen
*dri_screen
)
1045 static const gl_format formats
[] = {
1047 MESA_FORMAT_ARGB8888
1050 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1051 static const GLenum back_buffer_modes
[] = {
1052 GLX_SWAP_UNDEFINED_OML
, GLX_NONE
,
1055 static const uint8_t singlesample_samples
[1] = {0};
1057 uint8_t depth_bits
[4], stencil_bits
[4];
1058 __DRIconfig
**configs
= NULL
;
1060 /* Generate singlesample configs without accumulation buffer. */
1061 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1062 __DRIconfig
**new_configs
;
1063 int num_depth_stencil_bits
= 2;
1065 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1066 * buffer that has a different number of bits per pixel than the color
1070 stencil_bits
[0] = 0;
1072 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1074 stencil_bits
[1] = 0;
1077 stencil_bits
[1] = 8;
1080 new_configs
= driCreateConfigs(formats
[i
],
1083 num_depth_stencil_bits
,
1084 back_buffer_modes
, 2,
1085 singlesample_samples
, 1,
1087 configs
= driConcatConfigs(configs
, new_configs
);
1090 /* Generate the minimum possible set of configs that include an
1091 * accumulation buffer.
1093 for (int i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
1094 __DRIconfig
**new_configs
;
1096 if (formats
[i
] == MESA_FORMAT_RGB565
) {
1098 stencil_bits
[0] = 0;
1101 stencil_bits
[0] = 8;
1104 new_configs
= driCreateConfigs(formats
[i
],
1105 depth_bits
, stencil_bits
, 1,
1106 back_buffer_modes
, 1,
1107 singlesample_samples
, 1,
1109 configs
= driConcatConfigs(configs
, new_configs
);
1112 if (configs
== NULL
) {
1113 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
1122 set_max_gl_versions(struct intel_screen
*screen
)
1124 __DRIscreen
*psp
= screen
->driScrnPriv
;
1126 switch (screen
->gen
) {
1128 psp
->max_gl_core_version
= 0;
1129 psp
->max_gl_es1_version
= 11;
1130 psp
->max_gl_compat_version
= 21;
1131 psp
->max_gl_es2_version
= 20;
1134 psp
->max_gl_core_version
= 0;
1135 psp
->max_gl_compat_version
= 13;
1136 psp
->max_gl_es1_version
= 11;
1137 psp
->max_gl_es2_version
= 0;
1140 assert(!"unrecognized intel_screen::gen");
1146 * This is the driver specific part of the createNewScreen entry point.
1147 * Called when using DRI2.
1149 * \return the struct gl_config supported by this driver
1152 __DRIconfig
**intelInitScreen2(__DRIscreen
*psp
)
1154 struct intel_screen
*intelScreen
;
1156 if (psp
->dri2
.loader
->base
.version
<= 2 ||
1157 psp
->dri2
.loader
->getBuffersWithFormat
== NULL
) {
1159 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1160 "support required\n");
1164 /* Allocate the private area */
1165 intelScreen
= calloc(1, sizeof *intelScreen
);
1167 fprintf(stderr
, "\nERROR! Allocating private area failed\n");
1170 /* parse information in __driConfigOptions */
1171 driParseOptionInfo(&intelScreen
->optionCache
, i915_config_options
.xml
);
1173 intelScreen
->driScrnPriv
= psp
;
1174 psp
->driverPrivate
= (void *) intelScreen
;
1176 if (!intel_init_bufmgr(intelScreen
))
1179 intelScreen
->deviceID
= drm_intel_bufmgr_gem_get_devid(intelScreen
->bufmgr
);
1181 if (IS_9XX(intelScreen
->deviceID
)) {
1182 intelScreen
->gen
= 3;
1184 intelScreen
->gen
= 2;
1187 intelScreen
->hw_has_swizzling
= intel_detect_swizzling(intelScreen
);
1189 set_max_gl_versions(intelScreen
);
1191 psp
->extensions
= intelScreenExtensions
;
1193 return (const __DRIconfig
**) intel_screen_make_configs(psp
);
1196 struct intel_buffer
{
1198 struct intel_region
*region
;
1201 static __DRIbuffer
*
1202 intelAllocateBuffer(__DRIscreen
*screen
,
1203 unsigned attachment
, unsigned format
,
1204 int width
, int height
)
1206 struct intel_buffer
*intelBuffer
;
1207 struct intel_screen
*intelScreen
= screen
->driverPrivate
;
1209 assert(attachment
== __DRI_BUFFER_FRONT_LEFT
||
1210 attachment
== __DRI_BUFFER_BACK_LEFT
);
1212 intelBuffer
= calloc(1, sizeof *intelBuffer
);
1213 if (intelBuffer
== NULL
)
1216 /* The front and back buffers are color buffers, which are X tiled. */
1217 intelBuffer
->region
= intel_region_alloc(intelScreen
,
1224 if (intelBuffer
->region
== NULL
) {
1229 intel_region_flink(intelBuffer
->region
, &intelBuffer
->base
.name
);
1231 intelBuffer
->base
.attachment
= attachment
;
1232 intelBuffer
->base
.cpp
= intelBuffer
->region
->cpp
;
1233 intelBuffer
->base
.pitch
= intelBuffer
->region
->pitch
;
1235 return &intelBuffer
->base
;
1239 intelReleaseBuffer(__DRIscreen
*screen
, __DRIbuffer
*buffer
)
1241 struct intel_buffer
*intelBuffer
= (struct intel_buffer
*) buffer
;
1243 intel_region_release(&intelBuffer
->region
);
1248 static const struct __DriverAPIRec i915_driver_api
= {
1249 .InitScreen
= intelInitScreen2
,
1250 .DestroyScreen
= intelDestroyScreen
,
1251 .CreateContext
= intelCreateContext
,
1252 .DestroyContext
= intelDestroyContext
,
1253 .CreateBuffer
= intelCreateBuffer
,
1254 .DestroyBuffer
= intelDestroyBuffer
,
1255 .MakeCurrent
= intelMakeCurrent
,
1256 .UnbindContext
= intelUnbindContext
,
1257 .AllocateBuffer
= intelAllocateBuffer
,
1258 .ReleaseBuffer
= intelReleaseBuffer
1261 static const struct __DRIDriverVtableExtensionRec i915_vtable
= {
1262 .base
= { __DRI_DRIVER_VTABLE
, 1 },
1263 .vtable
= &i915_driver_api
,
1266 /* This is the table of extensions that the loader will dlsym() for. */
1267 static const __DRIextension
*i915_driver_extensions
[] = {
1268 &driCoreExtension
.base
,
1269 &driImageDriverExtension
.base
,
1270 &driDRI2Extension
.base
,
1272 &i915_config_options
.base
,
1276 PUBLIC
const __DRIextension
**__driDriverGetExtensions_i915(void)
1278 globalDriverAPI
= &i915_driver_api
;
1280 return i915_driver_extensions
;