gallium: push offset down to driver
[mesa.git] / src / gallium / state_trackers / dri / dri2.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright 2009, VMware, Inc.
5 * All Rights Reserved.
6 * Copyright (C) 2010 LunarG Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@vmware.com> Jakob Bornecrantz
28 * <wallbraker@gmail.com> Chia-I Wu <olv@lunarg.com>
29 */
30
31 #include <xf86drm.h>
32 #include <dlfcn.h>
33 #include "GL/mesa_glinterop.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "util/u_format.h"
37 #include "util/u_debug.h"
38 #include "state_tracker/drm_driver.h"
39 #include "state_tracker/st_cb_bufferobjects.h"
40 #include "state_tracker/st_cb_fbo.h"
41 #include "state_tracker/st_cb_texture.h"
42 #include "state_tracker/st_texture.h"
43 #include "state_tracker/st_context.h"
44 #include "pipe-loader/pipe_loader.h"
45 #include "main/bufferobj.h"
46 #include "main/texobj.h"
47
48 #include "dri_screen.h"
49 #include "dri_context.h"
50 #include "dri_drawable.h"
51 #include "dri_query_renderer.h"
52 #include "dri2_buffer.h"
53
54 static int convert_fourcc(int format, int *dri_components_p)
55 {
56 int dri_components;
57 switch(format) {
58 case __DRI_IMAGE_FOURCC_RGB565:
59 format = __DRI_IMAGE_FORMAT_RGB565;
60 dri_components = __DRI_IMAGE_COMPONENTS_RGB;
61 break;
62 case __DRI_IMAGE_FOURCC_ARGB8888:
63 format = __DRI_IMAGE_FORMAT_ARGB8888;
64 dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
65 break;
66 case __DRI_IMAGE_FOURCC_XRGB8888:
67 format = __DRI_IMAGE_FORMAT_XRGB8888;
68 dri_components = __DRI_IMAGE_COMPONENTS_RGB;
69 break;
70 case __DRI_IMAGE_FOURCC_ABGR8888:
71 format = __DRI_IMAGE_FORMAT_ABGR8888;
72 dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
73 break;
74 case __DRI_IMAGE_FOURCC_XBGR8888:
75 format = __DRI_IMAGE_FORMAT_XBGR8888;
76 dri_components = __DRI_IMAGE_COMPONENTS_RGB;
77 break;
78 case __DRI_IMAGE_FOURCC_R8:
79 format = __DRI_IMAGE_FORMAT_R8;
80 dri_components = __DRI_IMAGE_COMPONENTS_R;
81 break;
82 case __DRI_IMAGE_FOURCC_GR88:
83 format = __DRI_IMAGE_FORMAT_GR88;
84 dri_components = __DRI_IMAGE_COMPONENTS_RG;
85 break;
86 default:
87 return -1;
88 }
89 *dri_components_p = dri_components;
90 return format;
91 }
92
93 static int convert_to_fourcc(int format)
94 {
95 switch(format) {
96 case __DRI_IMAGE_FORMAT_RGB565:
97 format = __DRI_IMAGE_FOURCC_RGB565;
98 break;
99 case __DRI_IMAGE_FORMAT_ARGB8888:
100 format = __DRI_IMAGE_FOURCC_ARGB8888;
101 break;
102 case __DRI_IMAGE_FORMAT_XRGB8888:
103 format = __DRI_IMAGE_FOURCC_XRGB8888;
104 break;
105 case __DRI_IMAGE_FORMAT_ABGR8888:
106 format = __DRI_IMAGE_FOURCC_ABGR8888;
107 break;
108 case __DRI_IMAGE_FORMAT_XBGR8888:
109 format = __DRI_IMAGE_FOURCC_XBGR8888;
110 break;
111 case __DRI_IMAGE_FORMAT_R8:
112 format = __DRI_IMAGE_FOURCC_R8;
113 break;
114 case __DRI_IMAGE_FORMAT_GR88:
115 format = __DRI_IMAGE_FOURCC_GR88;
116 break;
117 default:
118 return -1;
119 }
120 return format;
121 }
122
123 static enum pipe_format dri2_format_to_pipe_format (int format)
124 {
125 enum pipe_format pf;
126
127 switch (format) {
128 case __DRI_IMAGE_FORMAT_RGB565:
129 pf = PIPE_FORMAT_B5G6R5_UNORM;
130 break;
131 case __DRI_IMAGE_FORMAT_XRGB8888:
132 pf = PIPE_FORMAT_BGRX8888_UNORM;
133 break;
134 case __DRI_IMAGE_FORMAT_ARGB8888:
135 pf = PIPE_FORMAT_BGRA8888_UNORM;
136 break;
137 case __DRI_IMAGE_FORMAT_ABGR8888:
138 pf = PIPE_FORMAT_RGBA8888_UNORM;
139 break;
140 case __DRI_IMAGE_FORMAT_R8:
141 pf = PIPE_FORMAT_R8_UNORM;
142 break;
143 case __DRI_IMAGE_FORMAT_GR88:
144 pf = PIPE_FORMAT_RG88_UNORM;
145 break;
146 default:
147 pf = PIPE_FORMAT_NONE;
148 break;
149 }
150
151 return pf;
152 }
153
154 /**
155 * DRI2 flush extension.
156 */
157 static void
158 dri2_flush_drawable(__DRIdrawable *dPriv)
159 {
160 dri_flush(dPriv->driContextPriv, dPriv, __DRI2_FLUSH_DRAWABLE, -1);
161 }
162
163 static void
164 dri2_invalidate_drawable(__DRIdrawable *dPriv)
165 {
166 struct dri_drawable *drawable = dri_drawable(dPriv);
167
168 dri2InvalidateDrawable(dPriv);
169 drawable->dPriv->lastStamp = drawable->dPriv->dri2.stamp;
170
171 p_atomic_inc(&drawable->base.stamp);
172 }
173
174 static const __DRI2flushExtension dri2FlushExtension = {
175 .base = { __DRI2_FLUSH, 4 },
176
177 .flush = dri2_flush_drawable,
178 .invalidate = dri2_invalidate_drawable,
179 .flush_with_flags = dri_flush,
180 };
181
182 /**
183 * Retrieve __DRIbuffer from the DRI loader.
184 */
185 static __DRIbuffer *
186 dri2_drawable_get_buffers(struct dri_drawable *drawable,
187 const enum st_attachment_type *atts,
188 unsigned *count)
189 {
190 __DRIdrawable *dri_drawable = drawable->dPriv;
191 const __DRIdri2LoaderExtension *loader = drawable->sPriv->dri2.loader;
192 boolean with_format;
193 __DRIbuffer *buffers;
194 int num_buffers;
195 unsigned attachments[10];
196 unsigned num_attachments, i;
197
198 assert(loader);
199 with_format = dri_with_format(drawable->sPriv);
200
201 num_attachments = 0;
202
203 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
204 if (!with_format)
205 attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT;
206
207 for (i = 0; i < *count; i++) {
208 enum pipe_format format;
209 unsigned bind;
210 int att, depth;
211
212 dri_drawable_get_format(drawable, atts[i], &format, &bind);
213 if (format == PIPE_FORMAT_NONE)
214 continue;
215
216 switch (atts[i]) {
217 case ST_ATTACHMENT_FRONT_LEFT:
218 /* already added */
219 if (!with_format)
220 continue;
221 att = __DRI_BUFFER_FRONT_LEFT;
222 break;
223 case ST_ATTACHMENT_BACK_LEFT:
224 att = __DRI_BUFFER_BACK_LEFT;
225 break;
226 case ST_ATTACHMENT_FRONT_RIGHT:
227 att = __DRI_BUFFER_FRONT_RIGHT;
228 break;
229 case ST_ATTACHMENT_BACK_RIGHT:
230 att = __DRI_BUFFER_BACK_RIGHT;
231 break;
232 default:
233 continue;
234 }
235
236 /*
237 * In this switch statement we must support all formats that
238 * may occur as the stvis->color_format.
239 */
240 switch(format) {
241 case PIPE_FORMAT_BGRA8888_UNORM:
242 depth = 32;
243 break;
244 case PIPE_FORMAT_BGRX8888_UNORM:
245 depth = 24;
246 break;
247 case PIPE_FORMAT_B5G6R5_UNORM:
248 depth = 16;
249 break;
250 default:
251 depth = util_format_get_blocksizebits(format);
252 assert(!"Unexpected format in dri2_drawable_get_buffers()");
253 }
254
255 attachments[num_attachments++] = att;
256 if (with_format) {
257 attachments[num_attachments++] = depth;
258 }
259 }
260
261 if (with_format) {
262 num_attachments /= 2;
263 buffers = loader->getBuffersWithFormat(dri_drawable,
264 &dri_drawable->w, &dri_drawable->h,
265 attachments, num_attachments,
266 &num_buffers, dri_drawable->loaderPrivate);
267 }
268 else {
269 buffers = loader->getBuffers(dri_drawable,
270 &dri_drawable->w, &dri_drawable->h,
271 attachments, num_attachments,
272 &num_buffers, dri_drawable->loaderPrivate);
273 }
274
275 if (buffers)
276 *count = num_buffers;
277
278 return buffers;
279 }
280
281 static bool
282 dri_image_drawable_get_buffers(struct dri_drawable *drawable,
283 struct __DRIimageList *images,
284 const enum st_attachment_type *statts,
285 unsigned statts_count)
286 {
287 __DRIdrawable *dPriv = drawable->dPriv;
288 __DRIscreen *sPriv = drawable->sPriv;
289 unsigned int image_format = __DRI_IMAGE_FORMAT_NONE;
290 enum pipe_format pf;
291 uint32_t buffer_mask = 0;
292 unsigned i, bind;
293
294 for (i = 0; i < statts_count; i++) {
295 dri_drawable_get_format(drawable, statts[i], &pf, &bind);
296 if (pf == PIPE_FORMAT_NONE)
297 continue;
298
299 switch (statts[i]) {
300 case ST_ATTACHMENT_FRONT_LEFT:
301 buffer_mask |= __DRI_IMAGE_BUFFER_FRONT;
302 break;
303 case ST_ATTACHMENT_BACK_LEFT:
304 buffer_mask |= __DRI_IMAGE_BUFFER_BACK;
305 break;
306 default:
307 continue;
308 }
309
310 switch (pf) {
311 case PIPE_FORMAT_B5G6R5_UNORM:
312 image_format = __DRI_IMAGE_FORMAT_RGB565;
313 break;
314 case PIPE_FORMAT_BGRX8888_UNORM:
315 image_format = __DRI_IMAGE_FORMAT_XRGB8888;
316 break;
317 case PIPE_FORMAT_BGRA8888_UNORM:
318 image_format = __DRI_IMAGE_FORMAT_ARGB8888;
319 break;
320 case PIPE_FORMAT_RGBA8888_UNORM:
321 image_format = __DRI_IMAGE_FORMAT_ABGR8888;
322 break;
323 default:
324 image_format = __DRI_IMAGE_FORMAT_NONE;
325 break;
326 }
327 }
328
329 return (*sPriv->image.loader->getBuffers) (dPriv, image_format,
330 (uint32_t *) &drawable->base.stamp,
331 dPriv->loaderPrivate, buffer_mask,
332 images);
333 }
334
335 static __DRIbuffer *
336 dri2_allocate_buffer(__DRIscreen *sPriv,
337 unsigned attachment, unsigned format,
338 int width, int height)
339 {
340 struct dri_screen *screen = dri_screen(sPriv);
341 struct dri2_buffer *buffer;
342 struct pipe_resource templ;
343 enum pipe_format pf;
344 unsigned bind = 0;
345 struct winsys_handle whandle;
346
347 switch (attachment) {
348 case __DRI_BUFFER_FRONT_LEFT:
349 case __DRI_BUFFER_FAKE_FRONT_LEFT:
350 bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
351 break;
352 case __DRI_BUFFER_BACK_LEFT:
353 bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
354 break;
355 case __DRI_BUFFER_DEPTH:
356 case __DRI_BUFFER_DEPTH_STENCIL:
357 case __DRI_BUFFER_STENCIL:
358 bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
359 break;
360 }
361
362 /* because we get the handle and stride */
363 bind |= PIPE_BIND_SHARED;
364
365 switch (format) {
366 case 32:
367 pf = PIPE_FORMAT_BGRA8888_UNORM;
368 break;
369 case 24:
370 pf = PIPE_FORMAT_BGRX8888_UNORM;
371 break;
372 case 16:
373 pf = PIPE_FORMAT_Z16_UNORM;
374 break;
375 default:
376 return NULL;
377 }
378
379 buffer = CALLOC_STRUCT(dri2_buffer);
380 if (!buffer)
381 return NULL;
382
383 memset(&templ, 0, sizeof(templ));
384 templ.bind = bind;
385 templ.format = pf;
386 templ.target = PIPE_TEXTURE_2D;
387 templ.last_level = 0;
388 templ.width0 = width;
389 templ.height0 = height;
390 templ.depth0 = 1;
391 templ.array_size = 1;
392
393 buffer->resource =
394 screen->base.screen->resource_create(screen->base.screen, &templ);
395 if (!buffer->resource) {
396 FREE(buffer);
397 return NULL;
398 }
399
400 memset(&whandle, 0, sizeof(whandle));
401 if (screen->can_share_buffer)
402 whandle.type = DRM_API_HANDLE_TYPE_SHARED;
403 else
404 whandle.type = DRM_API_HANDLE_TYPE_KMS;
405
406 screen->base.screen->resource_get_handle(screen->base.screen,
407 buffer->resource, &whandle,
408 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
409
410 buffer->base.attachment = attachment;
411 buffer->base.name = whandle.handle;
412 buffer->base.cpp = util_format_get_blocksize(pf);
413 buffer->base.pitch = whandle.stride;
414
415 return &buffer->base;
416 }
417
418 static void
419 dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv)
420 {
421 struct dri2_buffer *buffer = dri2_buffer(bPriv);
422
423 pipe_resource_reference(&buffer->resource, NULL);
424 FREE(buffer);
425 }
426
427 /*
428 * Backend functions for st_framebuffer interface.
429 */
430
431 static void
432 dri2_allocate_textures(struct dri_context *ctx,
433 struct dri_drawable *drawable,
434 const enum st_attachment_type *statts,
435 unsigned statts_count)
436 {
437 __DRIscreen *sPriv = drawable->sPriv;
438 __DRIdrawable *dri_drawable = drawable->dPriv;
439 struct dri_screen *screen = dri_screen(sPriv);
440 struct pipe_resource templ;
441 boolean alloc_depthstencil = FALSE;
442 unsigned i, j, bind;
443 const __DRIimageLoaderExtension *image = sPriv->image.loader;
444 /* Image specific variables */
445 struct __DRIimageList images;
446 /* Dri2 specific variables */
447 __DRIbuffer *buffers = NULL;
448 struct winsys_handle whandle;
449 unsigned num_buffers = statts_count;
450
451 /* First get the buffers from the loader */
452 if (image) {
453 if (!dri_image_drawable_get_buffers(drawable, &images,
454 statts, statts_count))
455 return;
456 }
457 else {
458 buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
459 if (!buffers || (drawable->old_num == num_buffers &&
460 drawable->old_w == dri_drawable->w &&
461 drawable->old_h == dri_drawable->h &&
462 memcmp(drawable->old, buffers,
463 sizeof(__DRIbuffer) * num_buffers) == 0))
464 return;
465 }
466
467 /* Second clean useless resources*/
468
469 /* See if we need a depth-stencil buffer. */
470 for (i = 0; i < statts_count; i++) {
471 if (statts[i] == ST_ATTACHMENT_DEPTH_STENCIL) {
472 alloc_depthstencil = TRUE;
473 break;
474 }
475 }
476
477 /* Delete the resources we won't need. */
478 for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
479 /* Don't delete the depth-stencil buffer, we can reuse it. */
480 if (i == ST_ATTACHMENT_DEPTH_STENCIL && alloc_depthstencil)
481 continue;
482
483 /* Flush the texture before unreferencing, so that other clients can
484 * see what the driver has rendered.
485 */
486 if (i != ST_ATTACHMENT_DEPTH_STENCIL && drawable->textures[i]) {
487 struct pipe_context *pipe = ctx->st->pipe;
488 pipe->flush_resource(pipe, drawable->textures[i]);
489 }
490
491 pipe_resource_reference(&drawable->textures[i], NULL);
492 }
493
494 if (drawable->stvis.samples > 1) {
495 for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
496 boolean del = TRUE;
497
498 /* Don't delete MSAA resources for the attachments which are enabled,
499 * we can reuse them. */
500 for (j = 0; j < statts_count; j++) {
501 if (i == statts[j]) {
502 del = FALSE;
503 break;
504 }
505 }
506
507 if (del) {
508 pipe_resource_reference(&drawable->msaa_textures[i], NULL);
509 }
510 }
511 }
512
513 /* Third use the buffers retrieved to fill the drawable info */
514
515 memset(&templ, 0, sizeof(templ));
516 templ.target = screen->target;
517 templ.last_level = 0;
518 templ.depth0 = 1;
519 templ.array_size = 1;
520
521 if (image) {
522 if (images.image_mask & __DRI_IMAGE_BUFFER_FRONT) {
523 struct pipe_resource **buf =
524 &drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
525 struct pipe_resource *texture = images.front->texture;
526
527 dri_drawable->w = texture->width0;
528 dri_drawable->h = texture->height0;
529
530 pipe_resource_reference(buf, texture);
531 }
532
533 if (images.image_mask & __DRI_IMAGE_BUFFER_BACK) {
534 struct pipe_resource **buf =
535 &drawable->textures[ST_ATTACHMENT_BACK_LEFT];
536 struct pipe_resource *texture = images.back->texture;
537
538 dri_drawable->w = texture->width0;
539 dri_drawable->h = texture->height0;
540
541 pipe_resource_reference(buf, texture);
542 }
543
544 /* Note: if there is both a back and a front buffer,
545 * then they have the same size.
546 */
547 templ.width0 = dri_drawable->w;
548 templ.height0 = dri_drawable->h;
549 }
550 else {
551 memset(&whandle, 0, sizeof(whandle));
552
553 /* Process DRI-provided buffers and get pipe_resources. */
554 for (i = 0; i < num_buffers; i++) {
555 __DRIbuffer *buf = &buffers[i];
556 enum st_attachment_type statt;
557 enum pipe_format format;
558
559 switch (buf->attachment) {
560 case __DRI_BUFFER_FRONT_LEFT:
561 if (!screen->auto_fake_front) {
562 continue; /* invalid attachment */
563 }
564 /* fallthrough */
565 case __DRI_BUFFER_FAKE_FRONT_LEFT:
566 statt = ST_ATTACHMENT_FRONT_LEFT;
567 break;
568 case __DRI_BUFFER_BACK_LEFT:
569 statt = ST_ATTACHMENT_BACK_LEFT;
570 break;
571 default:
572 continue; /* invalid attachment */
573 }
574
575 dri_drawable_get_format(drawable, statt, &format, &bind);
576 if (format == PIPE_FORMAT_NONE)
577 continue;
578
579 /* dri2_drawable_get_buffers has already filled dri_drawable->w
580 * and dri_drawable->h */
581 templ.width0 = dri_drawable->w;
582 templ.height0 = dri_drawable->h;
583 templ.format = format;
584 templ.bind = bind;
585 whandle.handle = buf->name;
586 whandle.stride = buf->pitch;
587 whandle.offset = 0;
588 if (screen->can_share_buffer)
589 whandle.type = DRM_API_HANDLE_TYPE_SHARED;
590 else
591 whandle.type = DRM_API_HANDLE_TYPE_KMS;
592 drawable->textures[statt] =
593 screen->base.screen->resource_from_handle(screen->base.screen,
594 &templ, &whandle,
595 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
596 assert(drawable->textures[statt]);
597 }
598 }
599
600 /* Allocate private MSAA colorbuffers. */
601 if (drawable->stvis.samples > 1) {
602 for (i = 0; i < statts_count; i++) {
603 enum st_attachment_type statt = statts[i];
604
605 if (statt == ST_ATTACHMENT_DEPTH_STENCIL)
606 continue;
607
608 if (drawable->textures[statt]) {
609 templ.format = drawable->textures[statt]->format;
610 templ.bind = drawable->textures[statt]->bind & ~PIPE_BIND_SCANOUT;
611 templ.nr_samples = drawable->stvis.samples;
612
613 /* Try to reuse the resource.
614 * (the other resource parameters should be constant)
615 */
616 if (!drawable->msaa_textures[statt] ||
617 drawable->msaa_textures[statt]->width0 != templ.width0 ||
618 drawable->msaa_textures[statt]->height0 != templ.height0) {
619 /* Allocate a new one. */
620 pipe_resource_reference(&drawable->msaa_textures[statt], NULL);
621
622 drawable->msaa_textures[statt] =
623 screen->base.screen->resource_create(screen->base.screen,
624 &templ);
625 assert(drawable->msaa_textures[statt]);
626
627 /* If there are any MSAA resources, we should initialize them
628 * such that they contain the same data as the single-sample
629 * resources we just got from the X server.
630 *
631 * The reason for this is that the state tracker (and
632 * therefore the app) can access the MSAA resources only.
633 * The single-sample resources are not exposed
634 * to the state tracker.
635 *
636 */
637 dri_pipe_blit(ctx->st->pipe,
638 drawable->msaa_textures[statt],
639 drawable->textures[statt]);
640 }
641 }
642 else {
643 pipe_resource_reference(&drawable->msaa_textures[statt], NULL);
644 }
645 }
646 }
647
648 /* Allocate a private depth-stencil buffer. */
649 if (alloc_depthstencil) {
650 enum st_attachment_type statt = ST_ATTACHMENT_DEPTH_STENCIL;
651 struct pipe_resource **zsbuf;
652 enum pipe_format format;
653 unsigned bind;
654
655 dri_drawable_get_format(drawable, statt, &format, &bind);
656
657 if (format) {
658 templ.format = format;
659 templ.bind = bind;
660
661 if (drawable->stvis.samples > 1) {
662 templ.nr_samples = drawable->stvis.samples;
663 zsbuf = &drawable->msaa_textures[statt];
664 }
665 else {
666 templ.nr_samples = 0;
667 zsbuf = &drawable->textures[statt];
668 }
669
670 /* Try to reuse the resource.
671 * (the other resource parameters should be constant)
672 */
673 if (!*zsbuf ||
674 (*zsbuf)->width0 != templ.width0 ||
675 (*zsbuf)->height0 != templ.height0) {
676 /* Allocate a new one. */
677 pipe_resource_reference(zsbuf, NULL);
678 *zsbuf = screen->base.screen->resource_create(screen->base.screen,
679 &templ);
680 assert(*zsbuf);
681 }
682 }
683 else {
684 pipe_resource_reference(&drawable->msaa_textures[statt], NULL);
685 pipe_resource_reference(&drawable->textures[statt], NULL);
686 }
687 }
688
689 /* For DRI2, we may get the same buffers again from the server.
690 * To prevent useless imports of gem names, drawable->old* is used
691 * to bypass the import if we get the same buffers. This doesn't apply
692 * to DRI3/Wayland, users of image.loader, since the buffer is managed
693 * by the client (no import), and the back buffer is going to change
694 * at every redraw.
695 */
696 if (!image) {
697 drawable->old_num = num_buffers;
698 drawable->old_w = dri_drawable->w;
699 drawable->old_h = dri_drawable->h;
700 memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * num_buffers);
701 }
702 }
703
704 static void
705 dri2_flush_frontbuffer(struct dri_context *ctx,
706 struct dri_drawable *drawable,
707 enum st_attachment_type statt)
708 {
709 __DRIdrawable *dri_drawable = drawable->dPriv;
710 const __DRIimageLoaderExtension *image = drawable->sPriv->image.loader;
711 const __DRIdri2LoaderExtension *loader = drawable->sPriv->dri2.loader;
712 struct pipe_context *pipe = ctx->st->pipe;
713
714 if (statt != ST_ATTACHMENT_FRONT_LEFT)
715 return;
716
717 if (drawable->stvis.samples > 1) {
718 /* Resolve the front buffer. */
719 dri_pipe_blit(ctx->st->pipe,
720 drawable->textures[ST_ATTACHMENT_FRONT_LEFT],
721 drawable->msaa_textures[ST_ATTACHMENT_FRONT_LEFT]);
722 }
723
724 if (drawable->textures[ST_ATTACHMENT_FRONT_LEFT]) {
725 pipe->flush_resource(pipe, drawable->textures[ST_ATTACHMENT_FRONT_LEFT]);
726 }
727
728 pipe->flush(pipe, NULL, 0);
729
730 if (image) {
731 image->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate);
732 }
733 else if (loader->flushFrontBuffer) {
734 loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate);
735 }
736 }
737
738 static void
739 dri2_update_tex_buffer(struct dri_drawable *drawable,
740 struct dri_context *ctx,
741 struct pipe_resource *res)
742 {
743 /* no-op */
744 }
745
746 static __DRIimage *
747 dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
748 {
749 const __DRIimageLookupExtension *loader = screen->sPriv->dri2.image;
750 __DRIimage *img;
751
752 if (!loader->lookupEGLImage)
753 return NULL;
754
755 img = loader->lookupEGLImage(screen->sPriv,
756 handle, screen->sPriv->loaderPrivate);
757
758 return img;
759 }
760
761 static __DRIimage *
762 dri2_create_image_from_winsys(__DRIscreen *_screen,
763 int width, int height, int format,
764 struct winsys_handle *whandle,
765 void *loaderPrivate)
766 {
767 struct dri_screen *screen = dri_screen(_screen);
768 __DRIimage *img;
769 struct pipe_resource templ;
770 unsigned tex_usage;
771 enum pipe_format pf;
772
773 tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
774
775 pf = dri2_format_to_pipe_format (format);
776 if (pf == PIPE_FORMAT_NONE)
777 return NULL;
778
779 img = CALLOC_STRUCT(__DRIimageRec);
780 if (!img)
781 return NULL;
782
783 memset(&templ, 0, sizeof(templ));
784 templ.bind = tex_usage;
785 templ.format = pf;
786 templ.target = screen->target;
787 templ.last_level = 0;
788 templ.width0 = width;
789 templ.height0 = height;
790 templ.depth0 = 1;
791 templ.array_size = 1;
792
793 img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
794 &templ, whandle, PIPE_HANDLE_USAGE_READ_WRITE);
795 if (!img->texture) {
796 FREE(img);
797 return NULL;
798 }
799
800 img->level = 0;
801 img->layer = 0;
802 img->dri_format = format;
803 img->use = 0;
804 img->loader_private = loaderPrivate;
805
806 return img;
807 }
808
809 static __DRIimage *
810 dri2_create_image_from_name(__DRIscreen *_screen,
811 int width, int height, int format,
812 int name, int pitch, void *loaderPrivate)
813 {
814 struct winsys_handle whandle;
815 enum pipe_format pf;
816
817 memset(&whandle, 0, sizeof(whandle));
818 whandle.type = DRM_API_HANDLE_TYPE_SHARED;
819 whandle.handle = name;
820
821 pf = dri2_format_to_pipe_format (format);
822 if (pf == PIPE_FORMAT_NONE)
823 return NULL;
824
825 whandle.stride = pitch * util_format_get_blocksize(pf);
826
827 return dri2_create_image_from_winsys(_screen, width, height, format,
828 &whandle, loaderPrivate);
829 }
830
831 static __DRIimage *
832 dri2_create_image_from_fd(__DRIscreen *_screen,
833 int width, int height, int fourcc,
834 int *fds, int num_fds, int *strides,
835 int *offsets, unsigned *error,
836 int *dri_components, void *loaderPrivate)
837 {
838 struct winsys_handle whandle;
839 int format;
840 __DRIimage *img = NULL;
841 unsigned err = __DRI_IMAGE_ERROR_SUCCESS;
842
843 if (num_fds != 1) {
844 err = __DRI_IMAGE_ERROR_BAD_MATCH;
845 goto exit;
846 }
847
848 format = convert_fourcc(fourcc, dri_components);
849 if (format == -1) {
850 err = __DRI_IMAGE_ERROR_BAD_MATCH;
851 goto exit;
852 }
853
854 if (fds[0] < 0) {
855 err = __DRI_IMAGE_ERROR_BAD_ALLOC;
856 goto exit;
857 }
858
859 memset(&whandle, 0, sizeof(whandle));
860 whandle.type = DRM_API_HANDLE_TYPE_FD;
861 whandle.handle = (unsigned)fds[0];
862 whandle.stride = (unsigned)strides[0];
863 whandle.offset = (unsigned)offsets[0];
864
865 img = dri2_create_image_from_winsys(_screen, width, height, format,
866 &whandle, loaderPrivate);
867 if(img == NULL)
868 err = __DRI_IMAGE_ERROR_BAD_ALLOC;
869
870 exit:
871 if (error)
872 *error = err;
873
874 return img;
875 }
876
877 static __DRIimage *
878 dri2_create_image_from_renderbuffer(__DRIcontext *context,
879 int renderbuffer, void *loaderPrivate)
880 {
881 struct dri_context *ctx = dri_context(context);
882
883 if (!ctx->st->get_resource_for_egl_image)
884 return NULL;
885
886 /* TODO */
887 return NULL;
888 }
889
890 static __DRIimage *
891 dri2_create_image(__DRIscreen *_screen,
892 int width, int height, int format,
893 unsigned int use, void *loaderPrivate)
894 {
895 struct dri_screen *screen = dri_screen(_screen);
896 __DRIimage *img;
897 struct pipe_resource templ;
898 unsigned tex_usage;
899 enum pipe_format pf;
900
901 tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
902 if (use & __DRI_IMAGE_USE_SCANOUT)
903 tex_usage |= PIPE_BIND_SCANOUT;
904 if (use & __DRI_IMAGE_USE_SHARE)
905 tex_usage |= PIPE_BIND_SHARED;
906 if (use & __DRI_IMAGE_USE_LINEAR)
907 tex_usage |= PIPE_BIND_LINEAR;
908 if (use & __DRI_IMAGE_USE_CURSOR) {
909 if (width != 64 || height != 64)
910 return NULL;
911 tex_usage |= PIPE_BIND_CURSOR;
912 }
913
914 pf = dri2_format_to_pipe_format (format);
915 if (pf == PIPE_FORMAT_NONE)
916 return NULL;
917
918 img = CALLOC_STRUCT(__DRIimageRec);
919 if (!img)
920 return NULL;
921
922 memset(&templ, 0, sizeof(templ));
923 templ.bind = tex_usage;
924 templ.format = pf;
925 templ.target = PIPE_TEXTURE_2D;
926 templ.last_level = 0;
927 templ.width0 = width;
928 templ.height0 = height;
929 templ.depth0 = 1;
930 templ.array_size = 1;
931
932 img->texture = screen->base.screen->resource_create(screen->base.screen, &templ);
933 if (!img->texture) {
934 FREE(img);
935 return NULL;
936 }
937
938 img->level = 0;
939 img->layer = 0;
940 img->dri_format = format;
941 img->dri_components = 0;
942 img->use = use;
943
944 img->loader_private = loaderPrivate;
945 return img;
946 }
947
948 static GLboolean
949 dri2_query_image(__DRIimage *image, int attrib, int *value)
950 {
951 struct winsys_handle whandle;
952 unsigned usage;
953
954 if (image->use & __DRI_IMAGE_USE_BACKBUFFER)
955 usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ;
956 else
957 usage = PIPE_HANDLE_USAGE_READ_WRITE;
958
959 memset(&whandle, 0, sizeof(whandle));
960
961 switch (attrib) {
962 case __DRI_IMAGE_ATTRIB_STRIDE:
963 whandle.type = DRM_API_HANDLE_TYPE_KMS;
964 image->texture->screen->resource_get_handle(image->texture->screen,
965 image->texture, &whandle, usage);
966 *value = whandle.stride;
967 return GL_TRUE;
968 case __DRI_IMAGE_ATTRIB_HANDLE:
969 whandle.type = DRM_API_HANDLE_TYPE_KMS;
970 image->texture->screen->resource_get_handle(image->texture->screen,
971 image->texture, &whandle, usage);
972 *value = whandle.handle;
973 return GL_TRUE;
974 case __DRI_IMAGE_ATTRIB_NAME:
975 whandle.type = DRM_API_HANDLE_TYPE_SHARED;
976 image->texture->screen->resource_get_handle(image->texture->screen,
977 image->texture, &whandle, usage);
978 *value = whandle.handle;
979 return GL_TRUE;
980 case __DRI_IMAGE_ATTRIB_FD:
981 whandle.type= DRM_API_HANDLE_TYPE_FD;
982 image->texture->screen->resource_get_handle(image->texture->screen,
983 image->texture, &whandle, usage);
984 *value = whandle.handle;
985 return GL_TRUE;
986 case __DRI_IMAGE_ATTRIB_FORMAT:
987 *value = image->dri_format;
988 return GL_TRUE;
989 case __DRI_IMAGE_ATTRIB_WIDTH:
990 *value = image->texture->width0;
991 return GL_TRUE;
992 case __DRI_IMAGE_ATTRIB_HEIGHT:
993 *value = image->texture->height0;
994 return GL_TRUE;
995 case __DRI_IMAGE_ATTRIB_COMPONENTS:
996 if (image->dri_components == 0)
997 return GL_FALSE;
998 *value = image->dri_components;
999 return GL_TRUE;
1000 case __DRI_IMAGE_ATTRIB_FOURCC:
1001 *value = convert_to_fourcc(image->dri_format);
1002 return GL_TRUE;
1003 case __DRI_IMAGE_ATTRIB_NUM_PLANES:
1004 *value = 1;
1005 return GL_TRUE;
1006 default:
1007 return GL_FALSE;
1008 }
1009 }
1010
1011 static __DRIimage *
1012 dri2_dup_image(__DRIimage *image, void *loaderPrivate)
1013 {
1014 __DRIimage *img;
1015
1016 img = CALLOC_STRUCT(__DRIimageRec);
1017 if (!img)
1018 return NULL;
1019
1020 img->texture = NULL;
1021 pipe_resource_reference(&img->texture, image->texture);
1022 img->level = image->level;
1023 img->layer = image->layer;
1024 img->dri_format = image->dri_format;
1025 /* This should be 0 for sub images, but dup is also used for base images. */
1026 img->dri_components = image->dri_components;
1027 img->loader_private = loaderPrivate;
1028
1029 return img;
1030 }
1031
1032 static GLboolean
1033 dri2_validate_usage(__DRIimage *image, unsigned int use)
1034 {
1035 /*
1036 * Gallium drivers are bad at adding usages to the resources
1037 * once opened again in another process, which is the main use
1038 * case for this, so we have to lie.
1039 */
1040 if (image != NULL)
1041 return GL_TRUE;
1042 else
1043 return GL_FALSE;
1044 }
1045
1046 static __DRIimage *
1047 dri2_from_names(__DRIscreen *screen, int width, int height, int format,
1048 int *names, int num_names, int *strides, int *offsets,
1049 void *loaderPrivate)
1050 {
1051 __DRIimage *img;
1052 int dri_components;
1053 struct winsys_handle whandle;
1054
1055 if (num_names != 1)
1056 return NULL;
1057
1058 format = convert_fourcc(format, &dri_components);
1059 if (format == -1)
1060 return NULL;
1061
1062 memset(&whandle, 0, sizeof(whandle));
1063 whandle.type = DRM_API_HANDLE_TYPE_SHARED;
1064 whandle.handle = names[0];
1065 whandle.stride = strides[0];
1066 whandle.offset = offsets[0];
1067
1068 img = dri2_create_image_from_winsys(screen, width, height, format,
1069 &whandle, loaderPrivate);
1070 if (img == NULL)
1071 return NULL;
1072
1073 img->dri_components = dri_components;
1074 return img;
1075 }
1076
1077 static __DRIimage *
1078 dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
1079 {
1080 __DRIimage *img;
1081
1082 if (plane != 0)
1083 return NULL;
1084
1085 if (image->dri_components == 0)
1086 return NULL;
1087
1088 img = dri2_dup_image(image, loaderPrivate);
1089 if (img == NULL)
1090 return NULL;
1091
1092 /* set this to 0 for sub images. */
1093 img->dri_components = 0;
1094 return img;
1095 }
1096
1097 static __DRIimage *
1098 dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
1099 int depth, int level, unsigned *error,
1100 void *loaderPrivate)
1101 {
1102 __DRIimage *img;
1103 struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx;
1104 struct gl_texture_object *obj;
1105 struct pipe_resource *tex;
1106 GLuint face = 0;
1107
1108 obj = _mesa_lookup_texture(ctx, texture);
1109 if (!obj || obj->Target != target) {
1110 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
1111 return NULL;
1112 }
1113
1114 tex = st_get_texobj_resource(obj);
1115 if (!tex) {
1116 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
1117 return NULL;
1118 }
1119
1120 if (target == GL_TEXTURE_CUBE_MAP)
1121 face = depth;
1122
1123 _mesa_test_texobj_completeness(ctx, obj);
1124 if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
1125 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
1126 return NULL;
1127 }
1128
1129 if (level < obj->BaseLevel || level > obj->_MaxLevel) {
1130 *error = __DRI_IMAGE_ERROR_BAD_MATCH;
1131 return NULL;
1132 }
1133
1134 if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < depth) {
1135 *error = __DRI_IMAGE_ERROR_BAD_MATCH;
1136 return NULL;
1137 }
1138
1139 img = CALLOC_STRUCT(__DRIimageRec);
1140 if (!img) {
1141 *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
1142 return NULL;
1143 }
1144
1145 img->level = level;
1146 img->layer = depth;
1147 img->dri_format = driGLFormatToImageFormat(obj->Image[face][level]->TexFormat);
1148
1149 img->loader_private = loaderPrivate;
1150
1151 if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
1152 *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
1153 free(img);
1154 return NULL;
1155 }
1156
1157 pipe_resource_reference(&img->texture, tex);
1158
1159 *error = __DRI_IMAGE_ERROR_SUCCESS;
1160 return img;
1161 }
1162
1163 static __DRIimage *
1164 dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
1165 int *fds, int num_fds, int *strides, int *offsets,
1166 void *loaderPrivate)
1167 {
1168 __DRIimage *img;
1169 int dri_components;
1170
1171 img = dri2_create_image_from_fd(screen, width, height, fourcc,
1172 fds, num_fds, strides, offsets, NULL,
1173 &dri_components, loaderPrivate);
1174 if (img == NULL)
1175 return NULL;
1176
1177 img->dri_components = dri_components;
1178 return img;
1179 }
1180
1181 static __DRIimage *
1182 dri2_from_dma_bufs(__DRIscreen *screen,
1183 int width, int height, int fourcc,
1184 int *fds, int num_fds,
1185 int *strides, int *offsets,
1186 enum __DRIYUVColorSpace yuv_color_space,
1187 enum __DRISampleRange sample_range,
1188 enum __DRIChromaSiting horizontal_siting,
1189 enum __DRIChromaSiting vertical_siting,
1190 unsigned *error,
1191 void *loaderPrivate)
1192 {
1193 __DRIimage *img;
1194 int dri_components;
1195
1196 img = dri2_create_image_from_fd(screen, width, height, fourcc,
1197 fds, num_fds, strides, offsets, error,
1198 &dri_components, loaderPrivate);
1199 if (img == NULL)
1200 return NULL;
1201
1202 img->yuv_color_space = yuv_color_space;
1203 img->sample_range = sample_range;
1204 img->horizontal_siting = horizontal_siting;
1205 img->vertical_siting = vertical_siting;
1206 img->dri_components = dri_components;
1207
1208 *error = __DRI_IMAGE_ERROR_SUCCESS;
1209 return img;
1210 }
1211
1212 static void
1213 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
1214 int dstx0, int dsty0, int dstwidth, int dstheight,
1215 int srcx0, int srcy0, int srcwidth, int srcheight,
1216 int flush_flag)
1217 {
1218 struct dri_context *ctx = dri_context(context);
1219 struct pipe_context *pipe = ctx->st->pipe;
1220 struct pipe_screen *screen;
1221 struct pipe_fence_handle *fence;
1222 struct pipe_blit_info blit;
1223
1224 if (!dst || !src)
1225 return;
1226
1227 memset(&blit, 0, sizeof(blit));
1228 blit.dst.resource = dst->texture;
1229 blit.dst.box.x = dstx0;
1230 blit.dst.box.y = dsty0;
1231 blit.dst.box.width = dstwidth;
1232 blit.dst.box.height = dstheight;
1233 blit.dst.box.depth = 1;
1234 blit.dst.format = dst->texture->format;
1235 blit.src.resource = src->texture;
1236 blit.src.box.x = srcx0;
1237 blit.src.box.y = srcy0;
1238 blit.src.box.width = srcwidth;
1239 blit.src.box.height = srcheight;
1240 blit.src.box.depth = 1;
1241 blit.src.format = src->texture->format;
1242 blit.mask = PIPE_MASK_RGBA;
1243 blit.filter = PIPE_TEX_FILTER_NEAREST;
1244
1245 pipe->blit(pipe, &blit);
1246
1247 if (flush_flag == __BLIT_FLAG_FLUSH) {
1248 pipe->flush_resource(pipe, dst->texture);
1249 ctx->st->flush(ctx->st, 0, NULL);
1250 } else if (flush_flag == __BLIT_FLAG_FINISH) {
1251 screen = dri_screen(ctx->sPriv)->base.screen;
1252 pipe->flush_resource(pipe, dst->texture);
1253 ctx->st->flush(ctx->st, 0, &fence);
1254 (void) screen->fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
1255 screen->fence_reference(screen, &fence, NULL);
1256 }
1257 }
1258
1259 static void *
1260 dri2_map_image(__DRIcontext *context, __DRIimage *image,
1261 int x0, int y0, int width, int height,
1262 unsigned int flags, int *stride, void **data)
1263 {
1264 struct dri_context *ctx = dri_context(context);
1265 struct pipe_context *pipe = ctx->st->pipe;
1266 enum pipe_transfer_usage pipe_access = 0;
1267 struct pipe_transfer *trans;
1268 void *map;
1269
1270 if (!image || !data || *data)
1271 return NULL;
1272
1273 if (flags & __DRI_IMAGE_TRANSFER_READ)
1274 pipe_access |= PIPE_TRANSFER_READ;
1275 if (flags & __DRI_IMAGE_TRANSFER_WRITE)
1276 pipe_access |= PIPE_TRANSFER_WRITE;
1277
1278 map = pipe_transfer_map(pipe, image->texture,
1279 0, 0, pipe_access, x0, y0, width, height,
1280 &trans);
1281 if (map) {
1282 *data = trans;
1283 *stride = trans->stride;
1284 }
1285
1286 return map;
1287 }
1288
1289 static void
1290 dri2_unmap_image(__DRIcontext *context, __DRIimage *image, void *data)
1291 {
1292 struct dri_context *ctx = dri_context(context);
1293 struct pipe_context *pipe = ctx->st->pipe;
1294
1295 pipe_transfer_unmap(pipe, (struct pipe_transfer *)data);
1296 }
1297
1298 static void
1299 dri2_destroy_image(__DRIimage *img)
1300 {
1301 pipe_resource_reference(&img->texture, NULL);
1302 FREE(img);
1303 }
1304
1305 static int
1306 dri2_get_capabilities(__DRIscreen *_screen)
1307 {
1308 struct dri_screen *screen = dri_screen(_screen);
1309
1310 return (screen->can_share_buffer ? __DRI_IMAGE_CAP_GLOBAL_NAMES : 0);
1311 }
1312
1313 /* The extension is modified during runtime if DRI_PRIME is detected */
1314 static __DRIimageExtension dri2ImageExtension = {
1315 .base = { __DRI_IMAGE, 12 },
1316
1317 .createImageFromName = dri2_create_image_from_name,
1318 .createImageFromRenderbuffer = dri2_create_image_from_renderbuffer,
1319 .destroyImage = dri2_destroy_image,
1320 .createImage = dri2_create_image,
1321 .queryImage = dri2_query_image,
1322 .dupImage = dri2_dup_image,
1323 .validateUsage = dri2_validate_usage,
1324 .createImageFromNames = dri2_from_names,
1325 .fromPlanar = dri2_from_planar,
1326 .createImageFromTexture = dri2_create_from_texture,
1327 .createImageFromFds = NULL,
1328 .createImageFromDmaBufs = NULL,
1329 .blitImage = dri2_blit_image,
1330 .getCapabilities = dri2_get_capabilities,
1331 .mapImage = dri2_map_image,
1332 .unmapImage = dri2_unmap_image,
1333 };
1334
1335
1336 static bool
1337 dri2_is_opencl_interop_loaded_locked(struct dri_screen *screen)
1338 {
1339 return screen->opencl_dri_event_add_ref &&
1340 screen->opencl_dri_event_release &&
1341 screen->opencl_dri_event_wait &&
1342 screen->opencl_dri_event_get_fence;
1343 }
1344
1345 static bool
1346 dri2_load_opencl_interop(struct dri_screen *screen)
1347 {
1348 #if defined(RTLD_DEFAULT)
1349 bool success;
1350
1351 pipe_mutex_lock(screen->opencl_func_mutex);
1352
1353 if (dri2_is_opencl_interop_loaded_locked(screen)) {
1354 pipe_mutex_unlock(screen->opencl_func_mutex);
1355 return true;
1356 }
1357
1358 screen->opencl_dri_event_add_ref =
1359 dlsym(RTLD_DEFAULT, "opencl_dri_event_add_ref");
1360 screen->opencl_dri_event_release =
1361 dlsym(RTLD_DEFAULT, "opencl_dri_event_release");
1362 screen->opencl_dri_event_wait =
1363 dlsym(RTLD_DEFAULT, "opencl_dri_event_wait");
1364 screen->opencl_dri_event_get_fence =
1365 dlsym(RTLD_DEFAULT, "opencl_dri_event_get_fence");
1366
1367 success = dri2_is_opencl_interop_loaded_locked(screen);
1368 pipe_mutex_unlock(screen->opencl_func_mutex);
1369 return success;
1370 #else
1371 return false;
1372 #endif
1373 }
1374
1375 struct dri2_fence {
1376 struct dri_screen *driscreen;
1377 struct pipe_fence_handle *pipe_fence;
1378 void *cl_event;
1379 };
1380
1381 static void *
1382 dri2_create_fence(__DRIcontext *_ctx)
1383 {
1384 struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
1385 struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
1386
1387 if (!fence)
1388 return NULL;
1389
1390 ctx->flush(ctx, &fence->pipe_fence, 0);
1391
1392 if (!fence->pipe_fence) {
1393 FREE(fence);
1394 return NULL;
1395 }
1396
1397 fence->driscreen = dri_screen(_ctx->driScreenPriv);
1398 return fence;
1399 }
1400
1401 static void *
1402 dri2_get_fence_from_cl_event(__DRIscreen *_screen, intptr_t cl_event)
1403 {
1404 struct dri_screen *driscreen = dri_screen(_screen);
1405 struct dri2_fence *fence;
1406
1407 if (!dri2_load_opencl_interop(driscreen))
1408 return NULL;
1409
1410 fence = CALLOC_STRUCT(dri2_fence);
1411 if (!fence)
1412 return NULL;
1413
1414 fence->cl_event = (void*)cl_event;
1415
1416 if (!driscreen->opencl_dri_event_add_ref(fence->cl_event)) {
1417 free(fence);
1418 return NULL;
1419 }
1420
1421 fence->driscreen = driscreen;
1422 return fence;
1423 }
1424
1425 static void
1426 dri2_destroy_fence(__DRIscreen *_screen, void *_fence)
1427 {
1428 struct dri_screen *driscreen = dri_screen(_screen);
1429 struct pipe_screen *screen = driscreen->base.screen;
1430 struct dri2_fence *fence = (struct dri2_fence*)_fence;
1431
1432 if (fence->pipe_fence)
1433 screen->fence_reference(screen, &fence->pipe_fence, NULL);
1434 else if (fence->cl_event)
1435 driscreen->opencl_dri_event_release(fence->cl_event);
1436 else
1437 assert(0);
1438
1439 FREE(fence);
1440 }
1441
1442 static GLboolean
1443 dri2_client_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags,
1444 uint64_t timeout)
1445 {
1446 struct dri2_fence *fence = (struct dri2_fence*)_fence;
1447 struct dri_screen *driscreen = fence->driscreen;
1448 struct pipe_screen *screen = driscreen->base.screen;
1449
1450 /* No need to flush. The context was flushed when the fence was created. */
1451
1452 if (fence->pipe_fence)
1453 return screen->fence_finish(screen, fence->pipe_fence, timeout);
1454 else if (fence->cl_event) {
1455 struct pipe_fence_handle *pipe_fence =
1456 driscreen->opencl_dri_event_get_fence(fence->cl_event);
1457
1458 if (pipe_fence)
1459 return screen->fence_finish(screen, pipe_fence, timeout);
1460 else
1461 return driscreen->opencl_dri_event_wait(fence->cl_event, timeout);
1462 }
1463 else {
1464 assert(0);
1465 return false;
1466 }
1467 }
1468
1469 static void
1470 dri2_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags)
1471 {
1472 /* AFAIK, no driver currently supports parallel context execution. */
1473 }
1474
1475 static __DRI2fenceExtension dri2FenceExtension = {
1476 .base = { __DRI2_FENCE, 1 },
1477
1478 .create_fence = dri2_create_fence,
1479 .get_fence_from_cl_event = dri2_get_fence_from_cl_event,
1480 .destroy_fence = dri2_destroy_fence,
1481 .client_wait_sync = dri2_client_wait_sync,
1482 .server_wait_sync = dri2_server_wait_sync
1483 };
1484
1485 static const __DRIrobustnessExtension dri2Robustness = {
1486 .base = { __DRI2_ROBUSTNESS, 1 }
1487 };
1488
1489 static int
1490 dri2_interop_query_device_info(__DRIcontext *_ctx,
1491 mesa_glinterop_device_info *out)
1492 {
1493 struct pipe_screen *screen = dri_context(_ctx)->st->pipe->screen;
1494
1495 /* There is no version 0, thus we do not support it */
1496 if (out->version == 0)
1497 return MESA_GLINTEROP_INVALID_VERSION;
1498
1499 out->pci_segment_group = screen->get_param(screen, PIPE_CAP_PCI_GROUP);
1500 out->pci_bus = screen->get_param(screen, PIPE_CAP_PCI_BUS);
1501 out->pci_device = screen->get_param(screen, PIPE_CAP_PCI_DEVICE);
1502 out->pci_function = screen->get_param(screen, PIPE_CAP_PCI_FUNCTION);
1503
1504 out->vendor_id = screen->get_param(screen, PIPE_CAP_VENDOR_ID);
1505 out->device_id = screen->get_param(screen, PIPE_CAP_DEVICE_ID);
1506
1507 /* Instruct the caller that we support up-to version one of the interface */
1508 out->version = 1;
1509
1510 return MESA_GLINTEROP_SUCCESS;
1511 }
1512
1513 static int
1514 dri2_interop_export_object(__DRIcontext *_ctx,
1515 mesa_glinterop_export_in *in,
1516 mesa_glinterop_export_out *out)
1517 {
1518 struct st_context_iface *st = dri_context(_ctx)->st;
1519 struct pipe_screen *screen = st->pipe->screen;
1520 struct gl_context *ctx = ((struct st_context *)st)->ctx;
1521 struct pipe_resource *res = NULL;
1522 struct winsys_handle whandle;
1523 unsigned target, usage;
1524 boolean success;
1525
1526 /* There is no version 0, thus we do not support it */
1527 if (in->version == 0 || out->version == 0)
1528 return MESA_GLINTEROP_INVALID_VERSION;
1529
1530 /* Validate the target. */
1531 switch (in->target) {
1532 case GL_TEXTURE_BUFFER:
1533 case GL_TEXTURE_1D:
1534 case GL_TEXTURE_2D:
1535 case GL_TEXTURE_3D:
1536 case GL_TEXTURE_RECTANGLE:
1537 case GL_TEXTURE_1D_ARRAY:
1538 case GL_TEXTURE_2D_ARRAY:
1539 case GL_TEXTURE_CUBE_MAP_ARRAY:
1540 case GL_TEXTURE_CUBE_MAP:
1541 case GL_TEXTURE_2D_MULTISAMPLE:
1542 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
1543 case GL_TEXTURE_EXTERNAL_OES:
1544 case GL_RENDERBUFFER:
1545 case GL_ARRAY_BUFFER:
1546 target = in->target;
1547 break;
1548 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1549 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1550 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1551 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1552 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1553 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1554 target = GL_TEXTURE_CUBE_MAP;
1555 break;
1556 default:
1557 return MESA_GLINTEROP_INVALID_TARGET;
1558 }
1559
1560 /* Validate the simple case of miplevel. */
1561 if ((target == GL_RENDERBUFFER || target == GL_ARRAY_BUFFER) &&
1562 in->miplevel != 0)
1563 return MESA_GLINTEROP_INVALID_MIP_LEVEL;
1564
1565 /* Validate the OpenGL object and get pipe_resource. */
1566 mtx_lock(&ctx->Shared->Mutex);
1567
1568 if (target == GL_ARRAY_BUFFER) {
1569 /* Buffer objects.
1570 *
1571 * The error checking is based on the documentation of
1572 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1573 */
1574 struct gl_buffer_object *buf = _mesa_lookup_bufferobj(ctx, in->obj);
1575
1576 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1577 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1578 * a GL buffer object but does not have an existing data store or
1579 * the size of the buffer is 0."
1580 */
1581 if (!buf || buf->Size == 0) {
1582 mtx_unlock(&ctx->Shared->Mutex);
1583 return MESA_GLINTEROP_INVALID_OBJECT;
1584 }
1585
1586 res = st_buffer_object(buf)->buffer;
1587 if (!res) {
1588 /* this shouldn't happen */
1589 mtx_unlock(&ctx->Shared->Mutex);
1590 return MESA_GLINTEROP_INVALID_OBJECT;
1591 }
1592
1593 out->buf_offset = 0;
1594 out->buf_size = buf->Size;
1595
1596 buf->UsageHistory |= USAGE_DISABLE_MINMAX_CACHE;
1597 } else if (target == GL_RENDERBUFFER) {
1598 /* Renderbuffers.
1599 *
1600 * The error checking is based on the documentation of
1601 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1602 */
1603 struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, in->obj);
1604
1605 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1606 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1607 * object or if the width or height of renderbuffer is zero."
1608 */
1609 if (!rb || rb->Width == 0 || rb->Height == 0) {
1610 mtx_unlock(&ctx->Shared->Mutex);
1611 return MESA_GLINTEROP_INVALID_OBJECT;
1612 }
1613
1614 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1615 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1616 * renderbuffer object."
1617 */
1618 if (rb->NumSamples > 1) {
1619 mtx_unlock(&ctx->Shared->Mutex);
1620 return MESA_GLINTEROP_INVALID_OPERATION;
1621 }
1622
1623 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1624 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1625 * required by the OpenCL implementation on the device."
1626 */
1627 res = st_renderbuffer(rb)->texture;
1628 if (!res) {
1629 mtx_unlock(&ctx->Shared->Mutex);
1630 return MESA_GLINTEROP_OUT_OF_RESOURCES;
1631 }
1632
1633 out->internal_format = rb->InternalFormat;
1634 out->view_minlevel = 0;
1635 out->view_numlevels = 1;
1636 out->view_minlayer = 0;
1637 out->view_numlayers = 1;
1638 } else {
1639 /* Texture objects.
1640 *
1641 * The error checking is based on the documentation of
1642 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1643 */
1644 struct gl_texture_object *obj = _mesa_lookup_texture(ctx, in->obj);
1645
1646 if (obj)
1647 _mesa_test_texobj_completeness(ctx, obj);
1648
1649 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1650 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1651 * type matches texture_target, if the specified miplevel of texture
1652 * is not defined, or if the width or height of the specified
1653 * miplevel is zero or if the GL texture object is incomplete."
1654 */
1655 if (!obj ||
1656 obj->Target != target ||
1657 !obj->_BaseComplete ||
1658 (in->miplevel > 0 && !obj->_MipmapComplete)) {
1659 mtx_unlock(&ctx->Shared->Mutex);
1660 return MESA_GLINTEROP_INVALID_OBJECT;
1661 }
1662
1663 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1664 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1665 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1666 * implementations); or greater than the value of q (for both OpenGL
1667 * and OpenGL ES). levelbase and q are defined for the texture in
1668 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1669 * specification and section 3.7.10 of the OpenGL ES 2.0."
1670 */
1671 if (in->miplevel < obj->BaseLevel || in->miplevel > obj->_MaxLevel) {
1672 mtx_unlock(&ctx->Shared->Mutex);
1673 return MESA_GLINTEROP_INVALID_MIP_LEVEL;
1674 }
1675
1676 if (!st_finalize_texture(ctx, st->pipe, obj)) {
1677 mtx_unlock(&ctx->Shared->Mutex);
1678 return MESA_GLINTEROP_OUT_OF_RESOURCES;
1679 }
1680
1681 res = st_get_texobj_resource(obj);
1682 if (!res) {
1683 /* Incomplete texture buffer object? This shouldn't really occur. */
1684 mtx_unlock(&ctx->Shared->Mutex);
1685 return MESA_GLINTEROP_INVALID_OBJECT;
1686 }
1687
1688 if (target == GL_TEXTURE_BUFFER) {
1689 out->internal_format = obj->BufferObjectFormat;
1690 out->buf_offset = obj->BufferOffset;
1691 out->buf_size = obj->BufferSize == -1 ? obj->BufferObject->Size :
1692 obj->BufferSize;
1693
1694 obj->BufferObject->UsageHistory |= USAGE_DISABLE_MINMAX_CACHE;
1695 } else {
1696 out->internal_format = obj->Image[0][0]->InternalFormat;
1697 out->view_minlevel = obj->MinLevel;
1698 out->view_numlevels = obj->NumLevels;
1699 out->view_minlayer = obj->MinLayer;
1700 out->view_numlayers = obj->NumLayers;
1701 }
1702 }
1703
1704 /* Get the handle. */
1705 switch (in->access) {
1706 case MESA_GLINTEROP_ACCESS_READ_WRITE:
1707 usage = PIPE_HANDLE_USAGE_READ_WRITE;
1708 break;
1709 case MESA_GLINTEROP_ACCESS_READ_ONLY:
1710 usage = PIPE_HANDLE_USAGE_READ;
1711 break;
1712 case MESA_GLINTEROP_ACCESS_WRITE_ONLY:
1713 usage = PIPE_HANDLE_USAGE_WRITE;
1714 break;
1715 default:
1716 usage = 0;
1717 }
1718
1719 memset(&whandle, 0, sizeof(whandle));
1720 whandle.type = DRM_API_HANDLE_TYPE_FD;
1721
1722 success = screen->resource_get_handle(screen, res, &whandle, usage);
1723 mtx_unlock(&ctx->Shared->Mutex);
1724
1725 if (!success)
1726 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY;
1727
1728 out->dmabuf_fd = whandle.handle;
1729 out->out_driver_data_written = 0;
1730
1731 if (res->target == PIPE_BUFFER)
1732 out->buf_offset += whandle.offset;
1733
1734 /* Instruct the caller that we support up-to version one of the interface */
1735 in->version = 1;
1736 out->version = 1;
1737
1738 return MESA_GLINTEROP_SUCCESS;
1739 }
1740
1741 static const __DRI2interopExtension dri2InteropExtension = {
1742 .base = { __DRI2_INTEROP, 1 },
1743 .query_device_info = dri2_interop_query_device_info,
1744 .export_object = dri2_interop_export_object
1745 };
1746
1747 /*
1748 * Backend function init_screen.
1749 */
1750
1751 static const __DRIextension *dri_screen_extensions[] = {
1752 &driTexBufferExtension.base,
1753 &dri2FlushExtension.base,
1754 &dri2ImageExtension.base,
1755 &dri2RendererQueryExtension.base,
1756 &dri2ConfigQueryExtension.base,
1757 &dri2ThrottleExtension.base,
1758 &dri2FenceExtension.base,
1759 &dri2InteropExtension.base,
1760 NULL
1761 };
1762
1763 static const __DRIextension *dri_robust_screen_extensions[] = {
1764 &driTexBufferExtension.base,
1765 &dri2FlushExtension.base,
1766 &dri2ImageExtension.base,
1767 &dri2RendererQueryExtension.base,
1768 &dri2ConfigQueryExtension.base,
1769 &dri2ThrottleExtension.base,
1770 &dri2FenceExtension.base,
1771 &dri2InteropExtension.base,
1772 &dri2Robustness.base,
1773 NULL
1774 };
1775
1776 /**
1777 * This is the driver specific part of the createNewScreen entry point.
1778 *
1779 * Returns the struct gl_config supported by this driver.
1780 */
1781 static const __DRIconfig **
1782 dri2_init_screen(__DRIscreen * sPriv)
1783 {
1784 const __DRIconfig **configs;
1785 struct dri_screen *screen;
1786 struct pipe_screen *pscreen = NULL;
1787 const struct drm_conf_ret *throttle_ret;
1788 const struct drm_conf_ret *dmabuf_ret;
1789 int fd;
1790
1791 screen = CALLOC_STRUCT(dri_screen);
1792 if (!screen)
1793 return NULL;
1794
1795 screen->sPriv = sPriv;
1796 screen->fd = sPriv->fd;
1797 pipe_mutex_init(screen->opencl_func_mutex);
1798
1799 sPriv->driverPrivate = (void *)screen;
1800
1801 if (screen->fd < 0 || (fd = dup(screen->fd)) < 0)
1802 goto free_screen;
1803
1804 if (pipe_loader_drm_probe_fd(&screen->dev, fd))
1805 pscreen = pipe_loader_create_screen(screen->dev);
1806
1807 if (!pscreen)
1808 goto release_pipe;
1809
1810 throttle_ret = pipe_loader_configuration(screen->dev, DRM_CONF_THROTTLE);
1811 dmabuf_ret = pipe_loader_configuration(screen->dev, DRM_CONF_SHARE_FD);
1812
1813 if (throttle_ret && throttle_ret->val.val_int != -1) {
1814 screen->throttling_enabled = TRUE;
1815 screen->default_throttle_frames = throttle_ret->val.val_int;
1816 }
1817
1818 if (dmabuf_ret && dmabuf_ret->val.val_bool) {
1819 uint64_t cap;
1820
1821 if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
1822 (cap & DRM_PRIME_CAP_IMPORT)) {
1823 dri2ImageExtension.createImageFromFds = dri2_from_fds;
1824 dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
1825 }
1826 }
1827
1828 if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
1829 sPriv->extensions = dri_robust_screen_extensions;
1830 screen->has_reset_status_query = true;
1831 }
1832 else
1833 sPriv->extensions = dri_screen_extensions;
1834
1835 configs = dri_init_screen_helper(screen, pscreen, screen->dev->driver_name);
1836 if (!configs)
1837 goto destroy_screen;
1838
1839 screen->can_share_buffer = true;
1840 screen->auto_fake_front = dri_with_format(sPriv);
1841 screen->broken_invalidate = !sPriv->dri2.useInvalidate;
1842 screen->lookup_egl_image = dri2_lookup_egl_image;
1843
1844 return configs;
1845
1846 destroy_screen:
1847 dri_destroy_screen_helper(screen);
1848
1849 release_pipe:
1850 if (screen->dev)
1851 pipe_loader_release(&screen->dev, 1);
1852 else
1853 close(fd);
1854
1855 free_screen:
1856 FREE(screen);
1857 return NULL;
1858 }
1859
1860 /**
1861 * This is the driver specific part of the createNewScreen entry point.
1862 *
1863 * Returns the struct gl_config supported by this driver.
1864 */
1865 static const __DRIconfig **
1866 dri_kms_init_screen(__DRIscreen * sPriv)
1867 {
1868 #if defined(GALLIUM_SOFTPIPE)
1869 const __DRIconfig **configs;
1870 struct dri_screen *screen;
1871 struct pipe_screen *pscreen = NULL;
1872 uint64_t cap;
1873 int fd;
1874
1875 screen = CALLOC_STRUCT(dri_screen);
1876 if (!screen)
1877 return NULL;
1878
1879 screen->sPriv = sPriv;
1880 screen->fd = sPriv->fd;
1881
1882 sPriv->driverPrivate = (void *)screen;
1883
1884 if (screen->fd < 0 || (fd = dup(screen->fd)) < 0)
1885 goto free_screen;
1886
1887 if (pipe_loader_sw_probe_kms(&screen->dev, fd))
1888 pscreen = pipe_loader_create_screen(screen->dev);
1889
1890 if (!pscreen)
1891 goto release_pipe;
1892
1893 if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
1894 (cap & DRM_PRIME_CAP_IMPORT)) {
1895 dri2ImageExtension.createImageFromFds = dri2_from_fds;
1896 dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
1897 }
1898
1899 sPriv->extensions = dri_screen_extensions;
1900
1901 configs = dri_init_screen_helper(screen, pscreen, "swrast");
1902 if (!configs)
1903 goto destroy_screen;
1904
1905 screen->can_share_buffer = false;
1906 screen->auto_fake_front = dri_with_format(sPriv);
1907 screen->broken_invalidate = !sPriv->dri2.useInvalidate;
1908 screen->lookup_egl_image = dri2_lookup_egl_image;
1909
1910 return configs;
1911
1912 destroy_screen:
1913 dri_destroy_screen_helper(screen);
1914
1915 release_pipe:
1916 if (screen->dev)
1917 pipe_loader_release(&screen->dev, 1);
1918 else
1919 close(fd);
1920
1921 free_screen:
1922 FREE(screen);
1923 #endif // GALLIUM_SOFTPIPE
1924 return NULL;
1925 }
1926
1927 static boolean
1928 dri2_create_buffer(__DRIscreen * sPriv,
1929 __DRIdrawable * dPriv,
1930 const struct gl_config * visual, boolean isPixmap)
1931 {
1932 struct dri_drawable *drawable = NULL;
1933
1934 if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap))
1935 return FALSE;
1936
1937 drawable = dPriv->driverPrivate;
1938
1939 drawable->allocate_textures = dri2_allocate_textures;
1940 drawable->flush_frontbuffer = dri2_flush_frontbuffer;
1941 drawable->update_tex_buffer = dri2_update_tex_buffer;
1942
1943 return TRUE;
1944 }
1945
1946 /**
1947 * DRI driver virtual function table.
1948 *
1949 * DRI versions differ in their implementation of init_screen and swap_buffers.
1950 */
1951 const struct __DriverAPIRec galliumdrm_driver_api = {
1952 .InitScreen = dri2_init_screen,
1953 .DestroyScreen = dri_destroy_screen,
1954 .CreateContext = dri_create_context,
1955 .DestroyContext = dri_destroy_context,
1956 .CreateBuffer = dri2_create_buffer,
1957 .DestroyBuffer = dri_destroy_buffer,
1958 .MakeCurrent = dri_make_current,
1959 .UnbindContext = dri_unbind_context,
1960
1961 .AllocateBuffer = dri2_allocate_buffer,
1962 .ReleaseBuffer = dri2_release_buffer,
1963 };
1964
1965 /**
1966 * DRI driver virtual function table.
1967 *
1968 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
1969 * hook. The latter is used to explicitly initialise the kms_swrast driver
1970 * rather than selecting the approapriate driver as suggested by the loader.
1971 */
1972 const struct __DriverAPIRec dri_kms_driver_api = {
1973 .InitScreen = dri_kms_init_screen,
1974 .DestroyScreen = dri_destroy_screen,
1975 .CreateContext = dri_create_context,
1976 .DestroyContext = dri_destroy_context,
1977 .CreateBuffer = dri2_create_buffer,
1978 .DestroyBuffer = dri_destroy_buffer,
1979 .MakeCurrent = dri_make_current,
1980 .UnbindContext = dri_unbind_context,
1981
1982 .AllocateBuffer = dri2_allocate_buffer,
1983 .ReleaseBuffer = dri2_release_buffer,
1984 };
1985
1986 /* This is the table of extensions that the loader will dlsym() for. */
1987 const __DRIextension *galliumdrm_driver_extensions[] = {
1988 &driCoreExtension.base,
1989 &driImageDriverExtension.base,
1990 &driDRI2Extension.base,
1991 &gallium_config_options.base,
1992 NULL
1993 };
1994
1995 /* vim: set sw=3 ts=8 sts=3 expandtab: */