i965: Drop duplicate #defines now that we've bumped libdrm requirements.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_screen.c
1 /*
2 * Copyright 2003 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <errno.h>
27 #include <time.h>
28 #include <unistd.h>
29 #include "main/context.h"
30 #include "main/framebuffer.h"
31 #include "main/renderbuffer.h"
32 #include "main/texobj.h"
33 #include "main/hash.h"
34 #include "main/fbobject.h"
35 #include "main/version.h"
36 #include "swrast/s_renderbuffer.h"
37 #include "util/ralloc.h"
38 #include "brw_defines.h"
39 #include "compiler/nir/nir.h"
40
41 #include "utils.h"
42 #include "xmlpool.h"
43
44 static const __DRIconfigOptionsExtension brw_config_options = {
45 .base = { __DRI_CONFIG_OPTIONS, 1 },
46 .xml =
47 DRI_CONF_BEGIN
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
52 */
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")
57 DRI_CONF_DESC_END
58 DRI_CONF_OPT_END
59
60 DRI_CONF_OPT_BEGIN_B(hiz, "true")
61 DRI_CONF_DESC(en, "Enable Hierarchical Z on gen6+")
62 DRI_CONF_OPT_END
63 DRI_CONF_SECTION_END
64
65 DRI_CONF_SECTION_QUALITY
66 DRI_CONF_FORCE_S3TC_ENABLE("false")
67
68 DRI_CONF_PRECISE_TRIG("false")
69
70 DRI_CONF_OPT_BEGIN(clamp_max_samples, int, -1)
71 DRI_CONF_DESC(en, "Clamp the value of GL_MAX_SAMPLES to the "
72 "given integer. If negative, then do not clamp.")
73 DRI_CONF_OPT_END
74 DRI_CONF_SECTION_END
75
76 DRI_CONF_SECTION_DEBUG
77 DRI_CONF_NO_RAST("false")
78 DRI_CONF_ALWAYS_FLUSH_BATCH("false")
79 DRI_CONF_ALWAYS_FLUSH_CACHE("false")
80 DRI_CONF_DISABLE_THROTTLING("false")
81 DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
82 DRI_CONF_FORCE_GLSL_VERSION(0)
83 DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
84 DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
85 DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("false")
86 DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false")
87 DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
88
89 DRI_CONF_OPT_BEGIN_B(shader_precompile, "true")
90 DRI_CONF_DESC(en, "Perform code generation at shader link time.")
91 DRI_CONF_OPT_END
92 DRI_CONF_SECTION_END
93
94 DRI_CONF_SECTION_MISCELLANEOUS
95 DRI_CONF_GLSL_ZERO_INIT("false")
96 DRI_CONF_SECTION_END
97 DRI_CONF_END
98 };
99
100 #include "intel_batchbuffer.h"
101 #include "intel_buffers.h"
102 #include "intel_bufmgr.h"
103 #include "intel_fbo.h"
104 #include "intel_mipmap_tree.h"
105 #include "intel_screen.h"
106 #include "intel_tex.h"
107 #include "intel_image.h"
108
109 #include "brw_context.h"
110
111 #include "i915_drm.h"
112
113 /**
114 * For debugging purposes, this returns a time in seconds.
115 */
116 double
117 get_time(void)
118 {
119 struct timespec tp;
120
121 clock_gettime(CLOCK_MONOTONIC, &tp);
122
123 return tp.tv_sec + tp.tv_nsec / 1000000000.0;
124 }
125
126 void
127 aub_dump_bmp(struct gl_context *ctx)
128 {
129 struct gl_framebuffer *fb = ctx->DrawBuffer;
130
131 for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
132 struct intel_renderbuffer *irb =
133 intel_renderbuffer(fb->_ColorDrawBuffers[i]);
134
135 if (irb && irb->mt) {
136 enum aub_dump_bmp_format format;
137
138 switch (irb->Base.Base.Format) {
139 case MESA_FORMAT_B8G8R8A8_UNORM:
140 case MESA_FORMAT_B8G8R8X8_UNORM:
141 format = AUB_DUMP_BMP_FORMAT_ARGB_8888;
142 break;
143 default:
144 continue;
145 }
146
147 drm_intel_gem_bo_aub_dump_bmp(irb->mt->bo,
148 irb->draw_x,
149 irb->draw_y,
150 irb->Base.Base.Width,
151 irb->Base.Base.Height,
152 format,
153 irb->mt->pitch,
154 0);
155 }
156 }
157 }
158
159 static const __DRItexBufferExtension intelTexBufferExtension = {
160 .base = { __DRI_TEX_BUFFER, 3 },
161
162 .setTexBuffer = intelSetTexBuffer,
163 .setTexBuffer2 = intelSetTexBuffer2,
164 .releaseTexBuffer = NULL,
165 };
166
167 static void
168 intel_dri2_flush_with_flags(__DRIcontext *cPriv,
169 __DRIdrawable *dPriv,
170 unsigned flags,
171 enum __DRI2throttleReason reason)
172 {
173 struct brw_context *brw = cPriv->driverPrivate;
174
175 if (!brw)
176 return;
177
178 struct gl_context *ctx = &brw->ctx;
179
180 FLUSH_VERTICES(ctx, 0);
181
182 if (flags & __DRI2_FLUSH_DRAWABLE)
183 intel_resolve_for_dri2_flush(brw, dPriv);
184
185 if (reason == __DRI2_THROTTLE_SWAPBUFFER)
186 brw->need_swap_throttle = true;
187 if (reason == __DRI2_THROTTLE_FLUSHFRONT)
188 brw->need_flush_throttle = true;
189
190 intel_batchbuffer_flush(brw);
191
192 if (INTEL_DEBUG & DEBUG_AUB) {
193 aub_dump_bmp(ctx);
194 }
195 }
196
197 /**
198 * Provides compatibility with loaders that only support the older (version
199 * 1-3) flush interface.
200 *
201 * That includes libGL up to Mesa 9.0, and the X Server at least up to 1.13.
202 */
203 static void
204 intel_dri2_flush(__DRIdrawable *drawable)
205 {
206 intel_dri2_flush_with_flags(drawable->driContextPriv, drawable,
207 __DRI2_FLUSH_DRAWABLE,
208 __DRI2_THROTTLE_SWAPBUFFER);
209 }
210
211 static const struct __DRI2flushExtensionRec intelFlushExtension = {
212 .base = { __DRI2_FLUSH, 4 },
213
214 .flush = intel_dri2_flush,
215 .invalidate = dri2InvalidateDrawable,
216 .flush_with_flags = intel_dri2_flush_with_flags,
217 };
218
219 static struct intel_image_format intel_image_formats[] = {
220 { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1,
221 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } },
222
223 { __DRI_IMAGE_FOURCC_ABGR8888, __DRI_IMAGE_COMPONENTS_RGBA, 1,
224 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888, 4 } } },
225
226 { __DRI_IMAGE_FOURCC_SARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1,
227 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } },
228
229 { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1,
230 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } },
231
232 { __DRI_IMAGE_FOURCC_XBGR8888, __DRI_IMAGE_COMPONENTS_RGB, 1,
233 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888, 4 }, } },
234
235 { __DRI_IMAGE_FOURCC_ARGB1555, __DRI_IMAGE_COMPONENTS_RGBA, 1,
236 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } },
237
238 { __DRI_IMAGE_FOURCC_RGB565, __DRI_IMAGE_COMPONENTS_RGB, 1,
239 { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } },
240
241 { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1,
242 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } },
243
244 { __DRI_IMAGE_FOURCC_R16, __DRI_IMAGE_COMPONENTS_R, 1,
245 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 1 }, } },
246
247 { __DRI_IMAGE_FOURCC_GR88, __DRI_IMAGE_COMPONENTS_RG, 1,
248 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } },
249
250 { __DRI_IMAGE_FOURCC_GR1616, __DRI_IMAGE_COMPONENTS_RG, 1,
251 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616, 2 }, } },
252
253 { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
254 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
255 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
256 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
257
258 { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
259 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
260 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
261 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
262
263 { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
264 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
265 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
266 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
267
268 { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
269 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
270 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
271 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
272
273 { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
274 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
275 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
276 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
277
278 { __DRI_IMAGE_FOURCC_YVU410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
279 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
280 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
281 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
282
283 { __DRI_IMAGE_FOURCC_YVU411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
284 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
285 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
286 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
287
288 { __DRI_IMAGE_FOURCC_YVU420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
289 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
290 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
291 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
292
293 { __DRI_IMAGE_FOURCC_YVU422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
294 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
295 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
296 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
297
298 { __DRI_IMAGE_FOURCC_YVU444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
299 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
300 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
301 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
302
303 { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
304 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
305 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } },
306
307 { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
308 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
309 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
310
311 /* For YUYV buffers, we set up two overlapping DRI images and treat
312 * them as planar buffers in the compositors. Plane 0 is GR88 and
313 * samples YU or YV pairs and places Y into the R component, while
314 * plane 1 is ARGB and samples YUYV clusters and places pairs and
315 * places U into the G component and V into A. This lets the
316 * texture sampler interpolate the Y components correctly when
317 * sampling from plane 0, and interpolate U and V correctly when
318 * sampling from plane 1. */
319 { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
320 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
321 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
322 };
323
324 static void
325 intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
326 {
327 uint32_t tiling, swizzle;
328 drm_intel_bo_get_tiling(image->bo, &tiling, &swizzle);
329
330 if (tiling != I915_TILING_NONE && (image->offset & 0xfff)) {
331 _mesa_warning(NULL, "%s: offset 0x%08x not on tile boundary",
332 func, image->offset);
333 }
334 }
335
336 static struct intel_image_format *
337 intel_image_format_lookup(int fourcc)
338 {
339 struct intel_image_format *f = NULL;
340
341 for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
342 if (intel_image_formats[i].fourcc == fourcc) {
343 f = &intel_image_formats[i];
344 break;
345 }
346 }
347
348 return f;
349 }
350
351 static boolean intel_lookup_fourcc(int dri_format, int *fourcc)
352 {
353 for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
354 if (intel_image_formats[i].planes[0].dri_format == dri_format) {
355 *fourcc = intel_image_formats[i].fourcc;
356 return true;
357 }
358 }
359 return false;
360 }
361
362 static __DRIimage *
363 intel_allocate_image(int dri_format, void *loaderPrivate)
364 {
365 __DRIimage *image;
366
367 image = calloc(1, sizeof *image);
368 if (image == NULL)
369 return NULL;
370
371 image->dri_format = dri_format;
372 image->offset = 0;
373
374 image->format = driImageFormatToGLFormat(dri_format);
375 if (dri_format != __DRI_IMAGE_FORMAT_NONE &&
376 image->format == MESA_FORMAT_NONE) {
377 free(image);
378 return NULL;
379 }
380
381 image->internal_format = _mesa_get_format_base_format(image->format);
382 image->data = loaderPrivate;
383
384 return image;
385 }
386
387 /**
388 * Sets up a DRIImage structure to point to a slice out of a miptree.
389 */
390 static void
391 intel_setup_image_from_mipmap_tree(struct brw_context *brw, __DRIimage *image,
392 struct intel_mipmap_tree *mt, GLuint level,
393 GLuint zoffset)
394 {
395 intel_miptree_make_shareable(brw, mt);
396
397 intel_miptree_check_level_layer(mt, level, zoffset);
398
399 image->width = minify(mt->physical_width0, level - mt->first_level);
400 image->height = minify(mt->physical_height0, level - mt->first_level);
401 image->pitch = mt->pitch;
402
403 image->offset = intel_miptree_get_tile_offsets(mt, level, zoffset,
404 &image->tile_x,
405 &image->tile_y);
406
407 drm_intel_bo_unreference(image->bo);
408 image->bo = mt->bo;
409 drm_intel_bo_reference(mt->bo);
410 }
411
412 static __DRIimage *
413 intel_create_image_from_name(__DRIscreen *dri_screen,
414 int width, int height, int format,
415 int name, int pitch, void *loaderPrivate)
416 {
417 struct intel_screen *screen = dri_screen->driverPrivate;
418 __DRIimage *image;
419 int cpp;
420
421 image = intel_allocate_image(format, loaderPrivate);
422 if (image == NULL)
423 return NULL;
424
425 if (image->format == MESA_FORMAT_NONE)
426 cpp = 1;
427 else
428 cpp = _mesa_get_format_bytes(image->format);
429
430 image->width = width;
431 image->height = height;
432 image->pitch = pitch * cpp;
433 image->bo = drm_intel_bo_gem_create_from_name(screen->bufmgr, "image",
434 name);
435 if (!image->bo) {
436 free(image);
437 return NULL;
438 }
439
440 return image;
441 }
442
443 static __DRIimage *
444 intel_create_image_from_renderbuffer(__DRIcontext *context,
445 int renderbuffer, void *loaderPrivate)
446 {
447 __DRIimage *image;
448 struct brw_context *brw = context->driverPrivate;
449 struct gl_context *ctx = &brw->ctx;
450 struct gl_renderbuffer *rb;
451 struct intel_renderbuffer *irb;
452
453 rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
454 if (!rb) {
455 _mesa_error(ctx, GL_INVALID_OPERATION, "glRenderbufferExternalMESA");
456 return NULL;
457 }
458
459 irb = intel_renderbuffer(rb);
460 intel_miptree_make_shareable(brw, irb->mt);
461 image = calloc(1, sizeof *image);
462 if (image == NULL)
463 return NULL;
464
465 image->internal_format = rb->InternalFormat;
466 image->format = rb->Format;
467 image->offset = 0;
468 image->data = loaderPrivate;
469 drm_intel_bo_unreference(image->bo);
470 image->bo = irb->mt->bo;
471 drm_intel_bo_reference(irb->mt->bo);
472 image->width = rb->Width;
473 image->height = rb->Height;
474 image->pitch = irb->mt->pitch;
475 image->dri_format = driGLFormatToImageFormat(image->format);
476 image->has_depthstencil = irb->mt->stencil_mt? true : false;
477
478 rb->NeedsFinishRenderTexture = true;
479 return image;
480 }
481
482 static __DRIimage *
483 intel_create_image_from_texture(__DRIcontext *context, int target,
484 unsigned texture, int zoffset,
485 int level,
486 unsigned *error,
487 void *loaderPrivate)
488 {
489 __DRIimage *image;
490 struct brw_context *brw = context->driverPrivate;
491 struct gl_texture_object *obj;
492 struct intel_texture_object *iobj;
493 GLuint face = 0;
494
495 obj = _mesa_lookup_texture(&brw->ctx, texture);
496 if (!obj || obj->Target != target) {
497 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
498 return NULL;
499 }
500
501 if (target == GL_TEXTURE_CUBE_MAP)
502 face = zoffset;
503
504 _mesa_test_texobj_completeness(&brw->ctx, obj);
505 iobj = intel_texture_object(obj);
506 if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
507 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
508 return NULL;
509 }
510
511 if (level < obj->BaseLevel || level > obj->_MaxLevel) {
512 *error = __DRI_IMAGE_ERROR_BAD_MATCH;
513 return NULL;
514 }
515
516 if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < zoffset) {
517 *error = __DRI_IMAGE_ERROR_BAD_MATCH;
518 return NULL;
519 }
520 image = calloc(1, sizeof *image);
521 if (image == NULL) {
522 *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
523 return NULL;
524 }
525
526 image->internal_format = obj->Image[face][level]->InternalFormat;
527 image->format = obj->Image[face][level]->TexFormat;
528 image->data = loaderPrivate;
529 intel_setup_image_from_mipmap_tree(brw, image, iobj->mt, level, zoffset);
530 image->dri_format = driGLFormatToImageFormat(image->format);
531 image->has_depthstencil = iobj->mt->stencil_mt? true : false;
532 if (image->dri_format == MESA_FORMAT_NONE) {
533 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
534 free(image);
535 return NULL;
536 }
537
538 *error = __DRI_IMAGE_ERROR_SUCCESS;
539 return image;
540 }
541
542 static void
543 intel_destroy_image(__DRIimage *image)
544 {
545 drm_intel_bo_unreference(image->bo);
546 free(image);
547 }
548
549 static __DRIimage *
550 intel_create_image(__DRIscreen *dri_screen,
551 int width, int height, int format,
552 unsigned int use,
553 void *loaderPrivate)
554 {
555 __DRIimage *image;
556 struct intel_screen *screen = dri_screen->driverPrivate;
557 uint32_t tiling;
558 int cpp;
559 unsigned long pitch;
560
561 tiling = I915_TILING_X;
562 if (use & __DRI_IMAGE_USE_CURSOR) {
563 if (width != 64 || height != 64)
564 return NULL;
565 tiling = I915_TILING_NONE;
566 }
567
568 if (use & __DRI_IMAGE_USE_LINEAR)
569 tiling = I915_TILING_NONE;
570
571 image = intel_allocate_image(format, loaderPrivate);
572 if (image == NULL)
573 return NULL;
574
575 cpp = _mesa_get_format_bytes(image->format);
576 image->bo = drm_intel_bo_alloc_tiled(screen->bufmgr, "image",
577 width, height, cpp, &tiling,
578 &pitch, 0);
579 if (image->bo == NULL) {
580 free(image);
581 return NULL;
582 }
583 image->width = width;
584 image->height = height;
585 image->pitch = pitch;
586
587 return image;
588 }
589
590 static GLboolean
591 intel_query_image(__DRIimage *image, int attrib, int *value)
592 {
593 switch (attrib) {
594 case __DRI_IMAGE_ATTRIB_STRIDE:
595 *value = image->pitch;
596 return true;
597 case __DRI_IMAGE_ATTRIB_HANDLE:
598 *value = image->bo->handle;
599 return true;
600 case __DRI_IMAGE_ATTRIB_NAME:
601 return !drm_intel_bo_flink(image->bo, (uint32_t *) value);
602 case __DRI_IMAGE_ATTRIB_FORMAT:
603 *value = image->dri_format;
604 return true;
605 case __DRI_IMAGE_ATTRIB_WIDTH:
606 *value = image->width;
607 return true;
608 case __DRI_IMAGE_ATTRIB_HEIGHT:
609 *value = image->height;
610 return true;
611 case __DRI_IMAGE_ATTRIB_COMPONENTS:
612 if (image->planar_format == NULL)
613 return false;
614 *value = image->planar_format->components;
615 return true;
616 case __DRI_IMAGE_ATTRIB_FD:
617 return !drm_intel_bo_gem_export_to_prime(image->bo, value);
618 case __DRI_IMAGE_ATTRIB_FOURCC:
619 return intel_lookup_fourcc(image->dri_format, value);
620 case __DRI_IMAGE_ATTRIB_NUM_PLANES:
621 *value = 1;
622 return true;
623 case __DRI_IMAGE_ATTRIB_OFFSET:
624 *value = image->offset;
625 return true;
626
627 default:
628 return false;
629 }
630 }
631
632 static __DRIimage *
633 intel_dup_image(__DRIimage *orig_image, void *loaderPrivate)
634 {
635 __DRIimage *image;
636
637 image = calloc(1, sizeof *image);
638 if (image == NULL)
639 return NULL;
640
641 drm_intel_bo_reference(orig_image->bo);
642 image->bo = orig_image->bo;
643 image->internal_format = orig_image->internal_format;
644 image->planar_format = orig_image->planar_format;
645 image->dri_format = orig_image->dri_format;
646 image->format = orig_image->format;
647 image->offset = orig_image->offset;
648 image->width = orig_image->width;
649 image->height = orig_image->height;
650 image->pitch = orig_image->pitch;
651 image->tile_x = orig_image->tile_x;
652 image->tile_y = orig_image->tile_y;
653 image->has_depthstencil = orig_image->has_depthstencil;
654 image->data = loaderPrivate;
655
656 memcpy(image->strides, orig_image->strides, sizeof(image->strides));
657 memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets));
658
659 return image;
660 }
661
662 static GLboolean
663 intel_validate_usage(__DRIimage *image, unsigned int use)
664 {
665 if (use & __DRI_IMAGE_USE_CURSOR) {
666 if (image->width != 64 || image->height != 64)
667 return GL_FALSE;
668 }
669
670 return GL_TRUE;
671 }
672
673 static __DRIimage *
674 intel_create_image_from_names(__DRIscreen *dri_screen,
675 int width, int height, int fourcc,
676 int *names, int num_names,
677 int *strides, int *offsets,
678 void *loaderPrivate)
679 {
680 struct intel_image_format *f = NULL;
681 __DRIimage *image;
682 int i, index;
683
684 if (dri_screen == NULL || names == NULL || num_names != 1)
685 return NULL;
686
687 f = intel_image_format_lookup(fourcc);
688 if (f == NULL)
689 return NULL;
690
691 image = intel_create_image_from_name(dri_screen, width, height,
692 __DRI_IMAGE_FORMAT_NONE,
693 names[0], strides[0],
694 loaderPrivate);
695
696 if (image == NULL)
697 return NULL;
698
699 image->planar_format = f;
700 for (i = 0; i < f->nplanes; i++) {
701 index = f->planes[i].buffer_index;
702 image->offsets[index] = offsets[index];
703 image->strides[index] = strides[index];
704 }
705
706 return image;
707 }
708
709 static __DRIimage *
710 intel_create_image_from_fds(__DRIscreen *dri_screen,
711 int width, int height, int fourcc,
712 int *fds, int num_fds, int *strides, int *offsets,
713 void *loaderPrivate)
714 {
715 struct intel_screen *screen = dri_screen->driverPrivate;
716 struct intel_image_format *f;
717 __DRIimage *image;
718 int i, index;
719
720 if (fds == NULL || num_fds < 1)
721 return NULL;
722
723 /* We only support all planes from the same bo */
724 for (i = 0; i < num_fds; i++)
725 if (fds[0] != fds[i])
726 return NULL;
727
728 f = intel_image_format_lookup(fourcc);
729 if (f == NULL)
730 return NULL;
731
732 if (f->nplanes == 1)
733 image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate);
734 else
735 image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
736
737 if (image == NULL)
738 return NULL;
739
740 image->width = width;
741 image->height = height;
742 image->pitch = strides[0];
743
744 image->planar_format = f;
745 int size = 0;
746 for (i = 0; i < f->nplanes; i++) {
747 index = f->planes[i].buffer_index;
748 image->offsets[index] = offsets[index];
749 image->strides[index] = strides[index];
750
751 const int plane_height = height >> f->planes[i].height_shift;
752 const int end = offsets[index] + plane_height * strides[index];
753 if (size < end)
754 size = end;
755 }
756
757 image->bo = drm_intel_bo_gem_create_from_prime(screen->bufmgr,
758 fds[0], size);
759 if (image->bo == NULL) {
760 free(image);
761 return NULL;
762 }
763
764 if (f->nplanes == 1) {
765 image->offset = image->offsets[0];
766 intel_image_warn_if_unaligned(image, __func__);
767 }
768
769 return image;
770 }
771
772 static __DRIimage *
773 intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
774 int width, int height, int fourcc,
775 int *fds, int num_fds,
776 int *strides, int *offsets,
777 enum __DRIYUVColorSpace yuv_color_space,
778 enum __DRISampleRange sample_range,
779 enum __DRIChromaSiting horizontal_siting,
780 enum __DRIChromaSiting vertical_siting,
781 unsigned *error,
782 void *loaderPrivate)
783 {
784 __DRIimage *image;
785 struct intel_image_format *f = intel_image_format_lookup(fourcc);
786
787 if (!f) {
788 *error = __DRI_IMAGE_ERROR_BAD_MATCH;
789 return NULL;
790 }
791
792 image = intel_create_image_from_fds(dri_screen, width, height, fourcc, fds,
793 num_fds, strides, offsets,
794 loaderPrivate);
795
796 /*
797 * Invalid parameters and any inconsistencies between are assumed to be
798 * checked by the caller. Therefore besides unsupported formats one can fail
799 * only in allocation.
800 */
801 if (!image) {
802 *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
803 return NULL;
804 }
805
806 image->dma_buf_imported = true;
807 image->yuv_color_space = yuv_color_space;
808 image->sample_range = sample_range;
809 image->horizontal_siting = horizontal_siting;
810 image->vertical_siting = vertical_siting;
811
812 *error = __DRI_IMAGE_ERROR_SUCCESS;
813 return image;
814 }
815
816 static __DRIimage *
817 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
818 {
819 int width, height, offset, stride, dri_format, index;
820 struct intel_image_format *f;
821 __DRIimage *image;
822
823 if (parent == NULL || parent->planar_format == NULL)
824 return NULL;
825
826 f = parent->planar_format;
827
828 if (plane >= f->nplanes)
829 return NULL;
830
831 width = parent->width >> f->planes[plane].width_shift;
832 height = parent->height >> f->planes[plane].height_shift;
833 dri_format = f->planes[plane].dri_format;
834 index = f->planes[plane].buffer_index;
835 offset = parent->offsets[index];
836 stride = parent->strides[index];
837
838 image = intel_allocate_image(dri_format, loaderPrivate);
839 if (image == NULL)
840 return NULL;
841
842 if (offset + height * stride > parent->bo->size) {
843 _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds");
844 free(image);
845 return NULL;
846 }
847
848 image->bo = parent->bo;
849 drm_intel_bo_reference(parent->bo);
850
851 image->width = width;
852 image->height = height;
853 image->pitch = stride;
854 image->offset = offset;
855
856 intel_image_warn_if_unaligned(image, __func__);
857
858 return image;
859 }
860
861 static const __DRIimageExtension intelImageExtension = {
862 .base = { __DRI_IMAGE, 13 },
863
864 .createImageFromName = intel_create_image_from_name,
865 .createImageFromRenderbuffer = intel_create_image_from_renderbuffer,
866 .destroyImage = intel_destroy_image,
867 .createImage = intel_create_image,
868 .queryImage = intel_query_image,
869 .dupImage = intel_dup_image,
870 .validateUsage = intel_validate_usage,
871 .createImageFromNames = intel_create_image_from_names,
872 .fromPlanar = intel_from_planar,
873 .createImageFromTexture = intel_create_image_from_texture,
874 .createImageFromFds = intel_create_image_from_fds,
875 .createImageFromDmaBufs = intel_create_image_from_dma_bufs,
876 .blitImage = NULL,
877 .getCapabilities = NULL,
878 .mapImage = NULL,
879 .unmapImage = NULL,
880 };
881
882 static int
883 brw_query_renderer_integer(__DRIscreen *dri_screen,
884 int param, unsigned int *value)
885 {
886 const struct intel_screen *const screen =
887 (struct intel_screen *) dri_screen->driverPrivate;
888
889 switch (param) {
890 case __DRI2_RENDERER_VENDOR_ID:
891 value[0] = 0x8086;
892 return 0;
893 case __DRI2_RENDERER_DEVICE_ID:
894 value[0] = screen->deviceID;
895 return 0;
896 case __DRI2_RENDERER_ACCELERATED:
897 value[0] = 1;
898 return 0;
899 case __DRI2_RENDERER_VIDEO_MEMORY: {
900 /* Once a batch uses more than 75% of the maximum mappable size, we
901 * assume that there's some fragmentation, and we start doing extra
902 * flushing, etc. That's the big cliff apps will care about.
903 */
904 size_t aper_size;
905 size_t mappable_size;
906
907 drm_intel_get_aperture_sizes(dri_screen->fd, &mappable_size, &aper_size);
908
909 const unsigned gpu_mappable_megabytes =
910 (aper_size / (1024 * 1024)) * 3 / 4;
911
912 const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
913 const long system_page_size = sysconf(_SC_PAGE_SIZE);
914
915 if (system_memory_pages <= 0 || system_page_size <= 0)
916 return -1;
917
918 const uint64_t system_memory_bytes = (uint64_t) system_memory_pages
919 * (uint64_t) system_page_size;
920
921 const unsigned system_memory_megabytes =
922 (unsigned) (system_memory_bytes / (1024 * 1024));
923
924 value[0] = MIN2(system_memory_megabytes, gpu_mappable_megabytes);
925 return 0;
926 }
927 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
928 value[0] = 1;
929 return 0;
930 case __DRI2_RENDERER_HAS_TEXTURE_3D:
931 value[0] = 1;
932 return 0;
933 default:
934 return driQueryRendererIntegerCommon(dri_screen, param, value);
935 }
936
937 return -1;
938 }
939
940 static int
941 brw_query_renderer_string(__DRIscreen *dri_screen,
942 int param, const char **value)
943 {
944 const struct intel_screen *screen =
945 (struct intel_screen *) dri_screen->driverPrivate;
946
947 switch (param) {
948 case __DRI2_RENDERER_VENDOR_ID:
949 value[0] = brw_vendor_string;
950 return 0;
951 case __DRI2_RENDERER_DEVICE_ID:
952 value[0] = brw_get_renderer_string(screen);
953 return 0;
954 default:
955 break;
956 }
957
958 return -1;
959 }
960
961 static const __DRI2rendererQueryExtension intelRendererQueryExtension = {
962 .base = { __DRI2_RENDERER_QUERY, 1 },
963
964 .queryInteger = brw_query_renderer_integer,
965 .queryString = brw_query_renderer_string
966 };
967
968 static const __DRIrobustnessExtension dri2Robustness = {
969 .base = { __DRI2_ROBUSTNESS, 1 }
970 };
971
972 static const __DRIextension *screenExtensions[] = {
973 &intelTexBufferExtension.base,
974 &intelFenceExtension.base,
975 &intelFlushExtension.base,
976 &intelImageExtension.base,
977 &intelRendererQueryExtension.base,
978 &dri2ConfigQueryExtension.base,
979 NULL
980 };
981
982 static const __DRIextension *intelRobustScreenExtensions[] = {
983 &intelTexBufferExtension.base,
984 &intelFenceExtension.base,
985 &intelFlushExtension.base,
986 &intelImageExtension.base,
987 &intelRendererQueryExtension.base,
988 &dri2ConfigQueryExtension.base,
989 &dri2Robustness.base,
990 NULL
991 };
992
993 static int
994 intel_get_param(struct intel_screen *screen, int param, int *value)
995 {
996 int ret = 0;
997 struct drm_i915_getparam gp;
998
999 memset(&gp, 0, sizeof(gp));
1000 gp.param = param;
1001 gp.value = value;
1002
1003 if (drmIoctl(screen->driScrnPriv->fd, DRM_IOCTL_I915_GETPARAM, &gp) == -1) {
1004 ret = -errno;
1005 if (ret != -EINVAL)
1006 _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
1007 }
1008
1009 return ret;
1010 }
1011
1012 static bool
1013 intel_get_boolean(struct intel_screen *screen, int param)
1014 {
1015 int value = 0;
1016 return (intel_get_param(screen, param, &value) == 0) && value;
1017 }
1018
1019 static int
1020 intel_get_integer(struct intel_screen *screen, int param)
1021 {
1022 int value = -1;
1023
1024 if (intel_get_param(screen, param, &value) == 0)
1025 return value;
1026
1027 return -1;
1028 }
1029
1030 static void
1031 intelDestroyScreen(__DRIscreen * sPriv)
1032 {
1033 struct intel_screen *screen = sPriv->driverPrivate;
1034
1035 dri_bufmgr_destroy(screen->bufmgr);
1036 driDestroyOptionInfo(&screen->optionCache);
1037
1038 ralloc_free(screen);
1039 sPriv->driverPrivate = NULL;
1040 }
1041
1042
1043 /**
1044 * This is called when we need to set up GL rendering to a new X window.
1045 */
1046 static GLboolean
1047 intelCreateBuffer(__DRIscreen *dri_screen,
1048 __DRIdrawable * driDrawPriv,
1049 const struct gl_config * mesaVis, GLboolean isPixmap)
1050 {
1051 struct intel_renderbuffer *rb;
1052 struct intel_screen *screen = (struct intel_screen *)
1053 dri_screen->driverPrivate;
1054 mesa_format rgbFormat;
1055 unsigned num_samples =
1056 intel_quantize_num_samples(screen, mesaVis->samples);
1057 struct gl_framebuffer *fb;
1058
1059 if (isPixmap)
1060 return false;
1061
1062 fb = CALLOC_STRUCT(gl_framebuffer);
1063 if (!fb)
1064 return false;
1065
1066 _mesa_initialize_window_framebuffer(fb, mesaVis);
1067
1068 if (screen->winsys_msaa_samples_override != -1) {
1069 num_samples = screen->winsys_msaa_samples_override;
1070 fb->Visual.samples = num_samples;
1071 }
1072
1073 if (mesaVis->redBits == 5) {
1074 rgbFormat = mesaVis->redMask == 0x1f ? MESA_FORMAT_R5G6B5_UNORM
1075 : MESA_FORMAT_B5G6R5_UNORM;
1076 } else if (mesaVis->sRGBCapable) {
1077 rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1078 : MESA_FORMAT_B8G8R8A8_SRGB;
1079 } else if (mesaVis->alphaBits == 0) {
1080 rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8X8_UNORM
1081 : MESA_FORMAT_B8G8R8X8_UNORM;
1082 } else {
1083 rgbFormat = mesaVis->redMask == 0xff ? MESA_FORMAT_R8G8B8A8_SRGB
1084 : MESA_FORMAT_B8G8R8A8_SRGB;
1085 fb->Visual.sRGBCapable = true;
1086 }
1087
1088 /* setup the hardware-based renderbuffers */
1089 rb = intel_create_renderbuffer(rgbFormat, num_samples);
1090 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
1091
1092 if (mesaVis->doubleBufferMode) {
1093 rb = intel_create_renderbuffer(rgbFormat, num_samples);
1094 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
1095 }
1096
1097 /*
1098 * Assert here that the gl_config has an expected depth/stencil bit
1099 * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
1100 * which constructs the advertised configs.)
1101 */
1102 if (mesaVis->depthBits == 24) {
1103 assert(mesaVis->stencilBits == 8);
1104
1105 if (screen->devinfo.has_hiz_and_separate_stencil) {
1106 rb = intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_X8_UINT,
1107 num_samples);
1108 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
1109 rb = intel_create_private_renderbuffer(MESA_FORMAT_S_UINT8,
1110 num_samples);
1111 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
1112 } else {
1113 /*
1114 * Use combined depth/stencil. Note that the renderbuffer is
1115 * attached to two attachment points.
1116 */
1117 rb = intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_S8_UINT,
1118 num_samples);
1119 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
1120 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
1121 }
1122 }
1123 else if (mesaVis->depthBits == 16) {
1124 assert(mesaVis->stencilBits == 0);
1125 rb = intel_create_private_renderbuffer(MESA_FORMAT_Z_UNORM16,
1126 num_samples);
1127 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
1128 }
1129 else {
1130 assert(mesaVis->depthBits == 0);
1131 assert(mesaVis->stencilBits == 0);
1132 }
1133
1134 /* now add any/all software-based renderbuffers we may need */
1135 _swrast_add_soft_renderbuffers(fb,
1136 false, /* never sw color */
1137 false, /* never sw depth */
1138 false, /* never sw stencil */
1139 mesaVis->accumRedBits > 0,
1140 false, /* never sw alpha */
1141 false /* never sw aux */ );
1142 driDrawPriv->driverPrivate = fb;
1143
1144 return true;
1145 }
1146
1147 static void
1148 intelDestroyBuffer(__DRIdrawable * driDrawPriv)
1149 {
1150 struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
1151
1152 _mesa_reference_framebuffer(&fb, NULL);
1153 }
1154
1155 static void
1156 intel_detect_sseu(struct intel_screen *screen)
1157 {
1158 assert(screen->devinfo.gen >= 8);
1159 int ret;
1160
1161 screen->subslice_total = -1;
1162 screen->eu_total = -1;
1163
1164 ret = intel_get_param(screen, I915_PARAM_SUBSLICE_TOTAL,
1165 &screen->subslice_total);
1166 if (ret < 0 && ret != -EINVAL)
1167 goto err_out;
1168
1169 ret = intel_get_param(screen,
1170 I915_PARAM_EU_TOTAL, &screen->eu_total);
1171 if (ret < 0 && ret != -EINVAL)
1172 goto err_out;
1173
1174 /* Without this information, we cannot get the right Braswell brandstrings,
1175 * and we have to use conservative numbers for GPGPU on many platforms, but
1176 * otherwise, things will just work.
1177 */
1178 if (screen->subslice_total < 1 || screen->eu_total < 1)
1179 _mesa_warning(NULL,
1180 "Kernel 4.1 required to properly query GPU properties.\n");
1181
1182 return;
1183
1184 err_out:
1185 screen->subslice_total = -1;
1186 screen->eu_total = -1;
1187 _mesa_warning(NULL, "Failed to query GPU properties (%s).\n", strerror(-ret));
1188 }
1189
1190 static bool
1191 intel_init_bufmgr(struct intel_screen *screen)
1192 {
1193 __DRIscreen *dri_screen = screen->driScrnPriv;
1194
1195 screen->no_hw = getenv("INTEL_NO_HW") != NULL;
1196
1197 screen->bufmgr = intel_bufmgr_gem_init(dri_screen->fd, BATCH_SZ);
1198 if (screen->bufmgr == NULL) {
1199 fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
1200 __func__, __LINE__);
1201 return false;
1202 }
1203
1204 drm_intel_bufmgr_gem_enable_fenced_relocs(screen->bufmgr);
1205
1206 if (!intel_get_boolean(screen, I915_PARAM_HAS_RELAXED_DELTA)) {
1207 fprintf(stderr, "[%s: %u] Kernel 2.6.39 required.\n", __func__, __LINE__);
1208 return false;
1209 }
1210
1211 return true;
1212 }
1213
1214 static bool
1215 intel_detect_swizzling(struct intel_screen *screen)
1216 {
1217 drm_intel_bo *buffer;
1218 unsigned long flags = 0;
1219 unsigned long aligned_pitch;
1220 uint32_t tiling = I915_TILING_X;
1221 uint32_t swizzle_mode = 0;
1222
1223 buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test",
1224 64, 64, 4,
1225 &tiling, &aligned_pitch, flags);
1226 if (buffer == NULL)
1227 return false;
1228
1229 drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode);
1230 drm_intel_bo_unreference(buffer);
1231
1232 if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE)
1233 return false;
1234 else
1235 return true;
1236 }
1237
1238 static int
1239 intel_detect_timestamp(struct intel_screen *screen)
1240 {
1241 uint64_t dummy = 0, last = 0;
1242 int upper, lower, loops;
1243
1244 /* On 64bit systems, some old kernels trigger a hw bug resulting in the
1245 * TIMESTAMP register being shifted and the low 32bits always zero.
1246 *
1247 * More recent kernels offer an interface to read the full 36bits
1248 * everywhere.
1249 */
1250 if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP | 1, &dummy) == 0)
1251 return 3;
1252
1253 /* Determine if we have a 32bit or 64bit kernel by inspecting the
1254 * upper 32bits for a rapidly changing timestamp.
1255 */
1256 if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP, &last))
1257 return 0;
1258
1259 upper = lower = 0;
1260 for (loops = 0; loops < 10; loops++) {
1261 /* The TIMESTAMP should change every 80ns, so several round trips
1262 * through the kernel should be enough to advance it.
1263 */
1264 if (drm_intel_reg_read(screen->bufmgr, TIMESTAMP, &dummy))
1265 return 0;
1266
1267 upper += (dummy >> 32) != (last >> 32);
1268 if (upper > 1) /* beware 32bit counter overflow */
1269 return 2; /* upper dword holds the low 32bits of the timestamp */
1270
1271 lower += (dummy & 0xffffffff) != (last & 0xffffffff);
1272 if (lower > 1)
1273 return 1; /* timestamp is unshifted */
1274
1275 last = dummy;
1276 }
1277
1278 /* No advancement? No timestamp! */
1279 return 0;
1280 }
1281
1282 /**
1283 * Test if we can use MI_LOAD_REGISTER_MEM from an untrusted batchbuffer.
1284 *
1285 * Some combinations of hardware and kernel versions allow this feature,
1286 * while others don't. Instead of trying to enumerate every case, just
1287 * try and write a register and see if works.
1288 */
1289 static bool
1290 intel_detect_pipelined_register(struct intel_screen *screen,
1291 int reg, uint32_t expected_value, bool reset)
1292 {
1293 drm_intel_bo *results, *bo;
1294 uint32_t *batch;
1295 uint32_t offset = 0;
1296 bool success = false;
1297
1298 /* Create a zero'ed temporary buffer for reading our results */
1299 results = drm_intel_bo_alloc(screen->bufmgr, "registers", 4096, 0);
1300 if (results == NULL)
1301 goto err;
1302
1303 bo = drm_intel_bo_alloc(screen->bufmgr, "batchbuffer", 4096, 0);
1304 if (bo == NULL)
1305 goto err_results;
1306
1307 if (drm_intel_bo_map(bo, 1))
1308 goto err_batch;
1309
1310 batch = bo->virtual;
1311
1312 /* Write the register. */
1313 *batch++ = MI_LOAD_REGISTER_IMM | (3 - 2);
1314 *batch++ = reg;
1315 *batch++ = expected_value;
1316
1317 /* Save the register's value back to the buffer. */
1318 *batch++ = MI_STORE_REGISTER_MEM | (3 - 2);
1319 *batch++ = reg;
1320 drm_intel_bo_emit_reloc(bo, (char *)batch -(char *)bo->virtual,
1321 results, offset*sizeof(uint32_t),
1322 I915_GEM_DOMAIN_INSTRUCTION,
1323 I915_GEM_DOMAIN_INSTRUCTION);
1324 *batch++ = results->offset + offset*sizeof(uint32_t);
1325
1326 /* And afterwards clear the register */
1327 if (reset) {
1328 *batch++ = MI_LOAD_REGISTER_IMM | (3 - 2);
1329 *batch++ = reg;
1330 *batch++ = 0;
1331 }
1332
1333 *batch++ = MI_BATCH_BUFFER_END;
1334
1335 drm_intel_bo_mrb_exec(bo, ALIGN((char *)batch - (char *)bo->virtual, 8),
1336 NULL, 0, 0,
1337 I915_EXEC_RENDER);
1338
1339 /* Check whether the value got written. */
1340 if (drm_intel_bo_map(results, false) == 0) {
1341 success = *((uint32_t *)results->virtual + offset) == expected_value;
1342 drm_intel_bo_unmap(results);
1343 }
1344
1345 err_batch:
1346 drm_intel_bo_unreference(bo);
1347 err_results:
1348 drm_intel_bo_unreference(results);
1349 err:
1350 return success;
1351 }
1352
1353 static bool
1354 intel_detect_pipelined_so(struct intel_screen *screen)
1355 {
1356 /* Supposedly, Broadwell just works. */
1357 if (screen->devinfo.gen >= 8)
1358 return true;
1359
1360 if (screen->devinfo.gen <= 6)
1361 return false;
1362
1363 /* We use SO_WRITE_OFFSET0 since you're supposed to write it (unlike the
1364 * statistics registers), and we already reset it to zero before using it.
1365 */
1366 return intel_detect_pipelined_register(screen,
1367 GEN7_SO_WRITE_OFFSET(0),
1368 0x1337d0d0,
1369 false);
1370 }
1371
1372 /**
1373 * Return array of MSAA modes supported by the hardware. The array is
1374 * zero-terminated and sorted in decreasing order.
1375 */
1376 const int*
1377 intel_supported_msaa_modes(const struct intel_screen *screen)
1378 {
1379 static const int gen9_modes[] = {16, 8, 4, 2, 0, -1};
1380 static const int gen8_modes[] = {8, 4, 2, 0, -1};
1381 static const int gen7_modes[] = {8, 4, 0, -1};
1382 static const int gen6_modes[] = {4, 0, -1};
1383 static const int gen4_modes[] = {0, -1};
1384
1385 if (screen->devinfo.gen >= 9) {
1386 return gen9_modes;
1387 } else if (screen->devinfo.gen >= 8) {
1388 return gen8_modes;
1389 } else if (screen->devinfo.gen >= 7) {
1390 return gen7_modes;
1391 } else if (screen->devinfo.gen == 6) {
1392 return gen6_modes;
1393 } else {
1394 return gen4_modes;
1395 }
1396 }
1397
1398 static __DRIconfig**
1399 intel_screen_make_configs(__DRIscreen *dri_screen)
1400 {
1401 static const mesa_format formats[] = {
1402 MESA_FORMAT_B5G6R5_UNORM,
1403 MESA_FORMAT_B8G8R8A8_UNORM,
1404 MESA_FORMAT_B8G8R8X8_UNORM
1405 };
1406
1407 /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
1408 static const GLenum back_buffer_modes[] = {
1409 GLX_SWAP_UNDEFINED_OML, GLX_NONE,
1410 };
1411
1412 static const uint8_t singlesample_samples[1] = {0};
1413 static const uint8_t multisample_samples[2] = {4, 8};
1414
1415 struct intel_screen *screen = dri_screen->driverPrivate;
1416 const struct gen_device_info *devinfo = &screen->devinfo;
1417 uint8_t depth_bits[4], stencil_bits[4];
1418 __DRIconfig **configs = NULL;
1419
1420 /* Generate singlesample configs without accumulation buffer. */
1421 for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
1422 __DRIconfig **new_configs;
1423 int num_depth_stencil_bits = 2;
1424
1425 /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
1426 * buffer that has a different number of bits per pixel than the color
1427 * buffer, gen >= 6 supports this.
1428 */
1429 depth_bits[0] = 0;
1430 stencil_bits[0] = 0;
1431
1432 if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) {
1433 depth_bits[1] = 16;
1434 stencil_bits[1] = 0;
1435 if (devinfo->gen >= 6) {
1436 depth_bits[2] = 24;
1437 stencil_bits[2] = 8;
1438 num_depth_stencil_bits = 3;
1439 }
1440 } else {
1441 depth_bits[1] = 24;
1442 stencil_bits[1] = 8;
1443 }
1444
1445 new_configs = driCreateConfigs(formats[i],
1446 depth_bits,
1447 stencil_bits,
1448 num_depth_stencil_bits,
1449 back_buffer_modes, 2,
1450 singlesample_samples, 1,
1451 false, false);
1452 configs = driConcatConfigs(configs, new_configs);
1453 }
1454
1455 /* Generate the minimum possible set of configs that include an
1456 * accumulation buffer.
1457 */
1458 for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
1459 __DRIconfig **new_configs;
1460
1461 if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) {
1462 depth_bits[0] = 16;
1463 stencil_bits[0] = 0;
1464 } else {
1465 depth_bits[0] = 24;
1466 stencil_bits[0] = 8;
1467 }
1468
1469 new_configs = driCreateConfigs(formats[i],
1470 depth_bits, stencil_bits, 1,
1471 back_buffer_modes, 1,
1472 singlesample_samples, 1,
1473 true, false);
1474 configs = driConcatConfigs(configs, new_configs);
1475 }
1476
1477 /* Generate multisample configs.
1478 *
1479 * This loop breaks early, and hence is a no-op, on gen < 6.
1480 *
1481 * Multisample configs must follow the singlesample configs in order to
1482 * work around an X server bug present in 1.12. The X server chooses to
1483 * associate the first listed RGBA888-Z24S8 config, regardless of its
1484 * sample count, with the 32-bit depth visual used for compositing.
1485 *
1486 * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
1487 * supported. Singlebuffer configs are not supported because no one wants
1488 * them.
1489 */
1490 for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
1491 if (devinfo->gen < 6)
1492 break;
1493
1494 __DRIconfig **new_configs;
1495 const int num_depth_stencil_bits = 2;
1496 int num_msaa_modes = 0;
1497
1498 depth_bits[0] = 0;
1499 stencil_bits[0] = 0;
1500
1501 if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) {
1502 depth_bits[1] = 16;
1503 stencil_bits[1] = 0;
1504 } else {
1505 depth_bits[1] = 24;
1506 stencil_bits[1] = 8;
1507 }
1508
1509 if (devinfo->gen >= 7)
1510 num_msaa_modes = 2;
1511 else if (devinfo->gen == 6)
1512 num_msaa_modes = 1;
1513
1514 new_configs = driCreateConfigs(formats[i],
1515 depth_bits,
1516 stencil_bits,
1517 num_depth_stencil_bits,
1518 back_buffer_modes, 1,
1519 multisample_samples,
1520 num_msaa_modes,
1521 false, false);
1522 configs = driConcatConfigs(configs, new_configs);
1523 }
1524
1525 if (configs == NULL) {
1526 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
1527 __LINE__);
1528 return NULL;
1529 }
1530
1531 return configs;
1532 }
1533
1534 static void
1535 set_max_gl_versions(struct intel_screen *screen)
1536 {
1537 __DRIscreen *dri_screen = screen->driScrnPriv;
1538 const bool has_astc = screen->devinfo.gen >= 9;
1539
1540 switch (screen->devinfo.gen) {
1541 case 9:
1542 case 8:
1543 dri_screen->max_gl_core_version = 45;
1544 dri_screen->max_gl_compat_version = 30;
1545 dri_screen->max_gl_es1_version = 11;
1546 dri_screen->max_gl_es2_version = has_astc ? 32 : 31;
1547 break;
1548 case 7:
1549 dri_screen->max_gl_core_version = screen->devinfo.is_haswell &&
1550 can_do_pipelined_register_writes(screen) ? 45 : 33;
1551 dri_screen->max_gl_compat_version = 30;
1552 dri_screen->max_gl_es1_version = 11;
1553 dri_screen->max_gl_es2_version = screen->devinfo.is_haswell ? 31 : 30;
1554 break;
1555 case 6:
1556 dri_screen->max_gl_core_version = 33;
1557 dri_screen->max_gl_compat_version = 30;
1558 dri_screen->max_gl_es1_version = 11;
1559 dri_screen->max_gl_es2_version = 30;
1560 break;
1561 case 5:
1562 case 4:
1563 dri_screen->max_gl_core_version = 0;
1564 dri_screen->max_gl_compat_version = 21;
1565 dri_screen->max_gl_es1_version = 11;
1566 dri_screen->max_gl_es2_version = 20;
1567 break;
1568 default:
1569 unreachable("unrecognized intel_screen::gen");
1570 }
1571 }
1572
1573 /**
1574 * Return the revision (generally the revid field of the PCI header) of the
1575 * graphics device.
1576 *
1577 * XXX: This function is useful to keep around even if it is not currently in
1578 * use. It is necessary for new platforms and revision specific workarounds or
1579 * features. Please don't remove it so that we know it at least continues to
1580 * build.
1581 */
1582 static __attribute__((__unused__)) int
1583 brw_get_revision(int fd)
1584 {
1585 struct drm_i915_getparam gp;
1586 int revision;
1587 int ret;
1588
1589 memset(&gp, 0, sizeof(gp));
1590 gp.param = I915_PARAM_REVISION;
1591 gp.value = &revision;
1592
1593 ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
1594 if (ret)
1595 revision = -1;
1596
1597 return revision;
1598 }
1599
1600 static void
1601 shader_debug_log_mesa(void *data, const char *fmt, ...)
1602 {
1603 struct brw_context *brw = (struct brw_context *)data;
1604 va_list args;
1605
1606 va_start(args, fmt);
1607 GLuint msg_id = 0;
1608 _mesa_gl_vdebug(&brw->ctx, &msg_id,
1609 MESA_DEBUG_SOURCE_SHADER_COMPILER,
1610 MESA_DEBUG_TYPE_OTHER,
1611 MESA_DEBUG_SEVERITY_NOTIFICATION, fmt, args);
1612 va_end(args);
1613 }
1614
1615 static void
1616 shader_perf_log_mesa(void *data, const char *fmt, ...)
1617 {
1618 struct brw_context *brw = (struct brw_context *)data;
1619
1620 va_list args;
1621 va_start(args, fmt);
1622
1623 if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
1624 va_list args_copy;
1625 va_copy(args_copy, args);
1626 vfprintf(stderr, fmt, args_copy);
1627 va_end(args_copy);
1628 }
1629
1630 if (brw->perf_debug) {
1631 GLuint msg_id = 0;
1632 _mesa_gl_vdebug(&brw->ctx, &msg_id,
1633 MESA_DEBUG_SOURCE_SHADER_COMPILER,
1634 MESA_DEBUG_TYPE_PERFORMANCE,
1635 MESA_DEBUG_SEVERITY_MEDIUM, fmt, args);
1636 }
1637 va_end(args);
1638 }
1639
1640 /**
1641 * This is the driver specific part of the createNewScreen entry point.
1642 * Called when using DRI2.
1643 *
1644 * \return the struct gl_config supported by this driver
1645 */
1646 static const
1647 __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
1648 {
1649 struct intel_screen *screen;
1650
1651 if (dri_screen->image.loader) {
1652 } else if (dri_screen->dri2.loader->base.version <= 2 ||
1653 dri_screen->dri2.loader->getBuffersWithFormat == NULL) {
1654 fprintf(stderr,
1655 "\nERROR! DRI2 loader with getBuffersWithFormat() "
1656 "support required\n");
1657 return false;
1658 }
1659
1660 /* Allocate the private area */
1661 screen = rzalloc(NULL, struct intel_screen);
1662 if (!screen) {
1663 fprintf(stderr, "\nERROR! Allocating private area failed\n");
1664 return false;
1665 }
1666 /* parse information in __driConfigOptions */
1667 driParseOptionInfo(&screen->optionCache, brw_config_options.xml);
1668
1669 screen->driScrnPriv = dri_screen;
1670 dri_screen->driverPrivate = (void *) screen;
1671
1672 if (!intel_init_bufmgr(screen))
1673 return false;
1674
1675 screen->deviceID = drm_intel_bufmgr_gem_get_devid(screen->bufmgr);
1676 if (!gen_get_device_info(screen->deviceID, &screen->devinfo))
1677 return false;
1678
1679 brw_process_intel_debug_variable();
1680
1681 if (INTEL_DEBUG & DEBUG_BUFMGR)
1682 dri_bufmgr_set_debug(screen->bufmgr, true);
1683
1684 if ((INTEL_DEBUG & DEBUG_SHADER_TIME) && screen->devinfo.gen < 7) {
1685 fprintf(stderr,
1686 "shader_time debugging requires gen7 (Ivybridge) or better.\n");
1687 INTEL_DEBUG &= ~DEBUG_SHADER_TIME;
1688 }
1689
1690 if (INTEL_DEBUG & DEBUG_AUB)
1691 drm_intel_bufmgr_gem_set_aub_dump(screen->bufmgr, true);
1692
1693 if (intel_get_integer(screen, I915_PARAM_MMAP_GTT_VERSION) >= 1) {
1694 /* Theorectically unlimited! At least for individual objects...
1695 *
1696 * Currently the entire (global) address space for all GTT maps is
1697 * limited to 64bits. That is all objects on the system that are
1698 * setup for GTT mmapping must fit within 64bits. An attempt to use
1699 * one that exceeds the limit with fail in drm_intel_bo_map_gtt().
1700 *
1701 * Long before we hit that limit, we will be practically limited by
1702 * that any single object must fit in physical memory (RAM). The upper
1703 * limit on the CPU's address space is currently 48bits (Skylake), of
1704 * which only 39bits can be physical memory. (The GPU itself also has
1705 * a 48bit addressable virtual space.) We can fit over 32 million
1706 * objects of the current maximum allocable size before running out
1707 * of mmap space.
1708 */
1709 screen->max_gtt_map_object_size = UINT64_MAX;
1710 } else {
1711 /* Estimate the size of the mappable aperture into the GTT. There's an
1712 * ioctl to get the whole GTT size, but not one to get the mappable subset.
1713 * It turns out it's basically always 256MB, though some ancient hardware
1714 * was smaller.
1715 */
1716 uint32_t gtt_size = 256 * 1024 * 1024;
1717
1718 /* We don't want to map two objects such that a memcpy between them would
1719 * just fault one mapping in and then the other over and over forever. So
1720 * we would need to divide the GTT size by 2. Additionally, some GTT is
1721 * taken up by things like the framebuffer and the ringbuffer and such, so
1722 * be more conservative.
1723 */
1724 screen->max_gtt_map_object_size = gtt_size / 4;
1725 }
1726
1727 screen->hw_has_swizzling = intel_detect_swizzling(screen);
1728 screen->hw_has_timestamp = intel_detect_timestamp(screen);
1729
1730 /* GENs prior to 8 do not support EU/Subslice info */
1731 if (screen->devinfo.gen >= 8) {
1732 intel_detect_sseu(screen);
1733 } else if (screen->devinfo.gen == 7) {
1734 screen->subslice_total = 1 << (screen->devinfo.gt - 1);
1735 }
1736
1737 if (intel_detect_pipelined_so(screen))
1738 screen->kernel_features |= KERNEL_ALLOWS_SOL_OFFSET_WRITES;
1739
1740 const char *force_msaa = getenv("INTEL_FORCE_MSAA");
1741 if (force_msaa) {
1742 screen->winsys_msaa_samples_override =
1743 intel_quantize_num_samples(screen, atoi(force_msaa));
1744 printf("Forcing winsys sample count to %d\n",
1745 screen->winsys_msaa_samples_override);
1746 } else {
1747 screen->winsys_msaa_samples_override = -1;
1748 }
1749
1750 set_max_gl_versions(screen);
1751
1752 /* Notification of GPU resets requires hardware contexts and a kernel new
1753 * enough to support DRM_IOCTL_I915_GET_RESET_STATS. If the ioctl is
1754 * supported, calling it with a context of 0 will either generate EPERM or
1755 * no error. If the ioctl is not supported, it always generate EINVAL.
1756 * Use this to determine whether to advertise the __DRI2_ROBUSTNESS
1757 * extension to the loader.
1758 *
1759 * Don't even try on pre-Gen6, since we don't attempt to use contexts there.
1760 */
1761 if (screen->devinfo.gen >= 6) {
1762 struct drm_i915_reset_stats stats;
1763 memset(&stats, 0, sizeof(stats));
1764
1765 const int ret = drmIoctl(dri_screen->fd, DRM_IOCTL_I915_GET_RESET_STATS, &stats);
1766
1767 screen->has_context_reset_notification =
1768 (ret != -1 || errno != EINVAL);
1769 }
1770
1771 if (intel_get_param(screen, I915_PARAM_CMD_PARSER_VERSION,
1772 &screen->cmd_parser_version) < 0) {
1773 screen->cmd_parser_version = 0;
1774 }
1775
1776 if (screen->devinfo.gen >= 8 || screen->cmd_parser_version >= 2)
1777 screen->kernel_features |= KERNEL_ALLOWS_PREDICATE_WRITES;
1778
1779 /* Haswell requires command parser version 4 in order to have L3
1780 * atomic scratch1 and chicken3 bits
1781 */
1782 if (screen->devinfo.is_haswell && screen->cmd_parser_version >= 4) {
1783 screen->kernel_features |=
1784 KERNEL_ALLOWS_HSW_SCRATCH1_AND_ROW_CHICKEN3;
1785 }
1786
1787 /* Haswell requires command parser version 6 in order to write to the
1788 * MI_MATH GPR registers, and version 7 in order to use
1789 * MI_LOAD_REGISTER_REG (which all users of MI_MATH use).
1790 */
1791 if (screen->devinfo.gen >= 8 ||
1792 (screen->devinfo.is_haswell && screen->cmd_parser_version >= 7)) {
1793 screen->kernel_features |= KERNEL_ALLOWS_MI_MATH_AND_LRR;
1794 }
1795
1796 /* Gen7 needs at least command parser version 5 to support compute */
1797 if (screen->devinfo.gen >= 8 || screen->cmd_parser_version >= 5)
1798 screen->kernel_features |= KERNEL_ALLOWS_COMPUTE_DISPATCH;
1799
1800 dri_screen->extensions = !screen->has_context_reset_notification
1801 ? screenExtensions : intelRobustScreenExtensions;
1802
1803 screen->compiler = brw_compiler_create(screen,
1804 &screen->devinfo);
1805 screen->compiler->shader_debug_log = shader_debug_log_mesa;
1806 screen->compiler->shader_perf_log = shader_perf_log_mesa;
1807 screen->program_id = 1;
1808
1809 if (screen->devinfo.has_resource_streamer) {
1810 screen->has_resource_streamer =
1811 intel_get_boolean(screen, I915_PARAM_HAS_RESOURCE_STREAMER);
1812 }
1813
1814 screen->has_exec_fence =
1815 intel_get_boolean(screen, I915_PARAM_HAS_EXEC_FENCE);
1816
1817 return (const __DRIconfig**) intel_screen_make_configs(dri_screen);
1818 }
1819
1820 struct intel_buffer {
1821 __DRIbuffer base;
1822 drm_intel_bo *bo;
1823 };
1824
1825 static __DRIbuffer *
1826 intelAllocateBuffer(__DRIscreen *dri_screen,
1827 unsigned attachment, unsigned format,
1828 int width, int height)
1829 {
1830 struct intel_buffer *intelBuffer;
1831 struct intel_screen *screen = dri_screen->driverPrivate;
1832
1833 assert(attachment == __DRI_BUFFER_FRONT_LEFT ||
1834 attachment == __DRI_BUFFER_BACK_LEFT);
1835
1836 intelBuffer = calloc(1, sizeof *intelBuffer);
1837 if (intelBuffer == NULL)
1838 return NULL;
1839
1840 /* The front and back buffers are color buffers, which are X tiled. */
1841 uint32_t tiling = I915_TILING_X;
1842 unsigned long pitch;
1843 int cpp = format / 8;
1844 intelBuffer->bo = drm_intel_bo_alloc_tiled(screen->bufmgr,
1845 "intelAllocateBuffer",
1846 width,
1847 height,
1848 cpp,
1849 &tiling, &pitch,
1850 BO_ALLOC_FOR_RENDER);
1851
1852 if (intelBuffer->bo == NULL) {
1853 free(intelBuffer);
1854 return NULL;
1855 }
1856
1857 drm_intel_bo_flink(intelBuffer->bo, &intelBuffer->base.name);
1858
1859 intelBuffer->base.attachment = attachment;
1860 intelBuffer->base.cpp = cpp;
1861 intelBuffer->base.pitch = pitch;
1862
1863 return &intelBuffer->base;
1864 }
1865
1866 static void
1867 intelReleaseBuffer(__DRIscreen *dri_screen, __DRIbuffer *buffer)
1868 {
1869 struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
1870
1871 drm_intel_bo_unreference(intelBuffer->bo);
1872 free(intelBuffer);
1873 }
1874
1875 static const struct __DriverAPIRec brw_driver_api = {
1876 .InitScreen = intelInitScreen2,
1877 .DestroyScreen = intelDestroyScreen,
1878 .CreateContext = brwCreateContext,
1879 .DestroyContext = intelDestroyContext,
1880 .CreateBuffer = intelCreateBuffer,
1881 .DestroyBuffer = intelDestroyBuffer,
1882 .MakeCurrent = intelMakeCurrent,
1883 .UnbindContext = intelUnbindContext,
1884 .AllocateBuffer = intelAllocateBuffer,
1885 .ReleaseBuffer = intelReleaseBuffer
1886 };
1887
1888 static const struct __DRIDriverVtableExtensionRec brw_vtable = {
1889 .base = { __DRI_DRIVER_VTABLE, 1 },
1890 .vtable = &brw_driver_api,
1891 };
1892
1893 static const __DRIextension *brw_driver_extensions[] = {
1894 &driCoreExtension.base,
1895 &driImageDriverExtension.base,
1896 &driDRI2Extension.base,
1897 &brw_vtable.base,
1898 &brw_config_options.base,
1899 NULL
1900 };
1901
1902 PUBLIC const __DRIextension **__driDriverGetExtensions_i965(void)
1903 {
1904 globalDriverAPI = &brw_driver_api;
1905
1906 return brw_driver_extensions;
1907 }