2 * Mesa 3-D graphics library
4 * Copyright 2009, VMware, Inc.
6 * Copyright (C) 2010 LunarG Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
27 * Keith Whitwell <keithw@vmware.com> Jakob Bornecrantz
28 * <wallbraker@gmail.com> Chia-I Wu <olv@lunarg.com>
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"
48 #include "dri_helpers.h"
49 #include "dri_drawable.h"
50 #include "dri_query_renderer.h"
51 #include "dri2_buffer.h"
53 #ifndef DRM_FORMAT_MOD_INVALID
54 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
57 static const int fourcc_formats
[] = {
58 __DRI_IMAGE_FOURCC_ARGB8888
,
59 __DRI_IMAGE_FOURCC_ABGR8888
,
60 __DRI_IMAGE_FOURCC_SARGB8888
,
61 __DRI_IMAGE_FOURCC_XRGB8888
,
62 __DRI_IMAGE_FOURCC_XBGR8888
,
63 __DRI_IMAGE_FOURCC_ARGB1555
,
64 __DRI_IMAGE_FOURCC_RGB565
,
65 __DRI_IMAGE_FOURCC_R8
,
66 __DRI_IMAGE_FOURCC_R16
,
67 __DRI_IMAGE_FOURCC_GR88
,
68 __DRI_IMAGE_FOURCC_GR1616
,
69 __DRI_IMAGE_FOURCC_YUV410
,
70 __DRI_IMAGE_FOURCC_YUV411
,
71 __DRI_IMAGE_FOURCC_YUV420
,
72 __DRI_IMAGE_FOURCC_YUV422
,
73 __DRI_IMAGE_FOURCC_YUV444
,
74 __DRI_IMAGE_FOURCC_YVU410
,
75 __DRI_IMAGE_FOURCC_YVU411
,
76 __DRI_IMAGE_FOURCC_YVU420
,
77 __DRI_IMAGE_FOURCC_YVU422
,
78 __DRI_IMAGE_FOURCC_YVU444
,
79 __DRI_IMAGE_FOURCC_NV12
,
80 __DRI_IMAGE_FOURCC_NV16
,
81 __DRI_IMAGE_FOURCC_YUYV
84 static int convert_fourcc(int format
, int *dri_components_p
)
88 case __DRI_IMAGE_FOURCC_RGB565
:
89 format
= __DRI_IMAGE_FORMAT_RGB565
;
90 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
92 case __DRI_IMAGE_FOURCC_ARGB8888
:
93 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
94 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
96 case __DRI_IMAGE_FOURCC_XRGB8888
:
97 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
98 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
100 case __DRI_IMAGE_FOURCC_ABGR8888
:
101 format
= __DRI_IMAGE_FORMAT_ABGR8888
;
102 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
104 case __DRI_IMAGE_FOURCC_XBGR8888
:
105 format
= __DRI_IMAGE_FORMAT_XBGR8888
;
106 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
108 case __DRI_IMAGE_FOURCC_R8
:
109 format
= __DRI_IMAGE_FORMAT_R8
;
110 dri_components
= __DRI_IMAGE_COMPONENTS_R
;
112 case __DRI_IMAGE_FOURCC_GR88
:
113 format
= __DRI_IMAGE_FORMAT_GR88
;
114 dri_components
= __DRI_IMAGE_COMPONENTS_RG
;
117 * For multi-planar YUV formats, we return the format of the first
118 * plane only. Since there is only one caller which supports multi-
119 * planar YUV it gets to figure out the remaining planes on it's
122 case __DRI_IMAGE_FOURCC_YUV420
:
123 case __DRI_IMAGE_FOURCC_YVU420
:
124 format
= __DRI_IMAGE_FORMAT_R8
;
125 dri_components
= __DRI_IMAGE_COMPONENTS_Y_U_V
;
127 case __DRI_IMAGE_FOURCC_NV12
:
128 format
= __DRI_IMAGE_FORMAT_R8
;
129 dri_components
= __DRI_IMAGE_COMPONENTS_Y_UV
;
134 *dri_components_p
= dri_components
;
138 /* NOTE this probably isn't going to do the right thing for YUV images
139 * (but I think the same can be said for intel_query_image()). I think
140 * only needed for exporting dmabuf's, so I think I won't loose much
143 static int convert_to_fourcc(int format
)
146 case __DRI_IMAGE_FORMAT_RGB565
:
147 format
= __DRI_IMAGE_FOURCC_RGB565
;
149 case __DRI_IMAGE_FORMAT_ARGB8888
:
150 format
= __DRI_IMAGE_FOURCC_ARGB8888
;
152 case __DRI_IMAGE_FORMAT_XRGB8888
:
153 format
= __DRI_IMAGE_FOURCC_XRGB8888
;
155 case __DRI_IMAGE_FORMAT_ABGR8888
:
156 format
= __DRI_IMAGE_FOURCC_ABGR8888
;
158 case __DRI_IMAGE_FORMAT_XBGR8888
:
159 format
= __DRI_IMAGE_FOURCC_XBGR8888
;
161 case __DRI_IMAGE_FORMAT_R8
:
162 format
= __DRI_IMAGE_FOURCC_R8
;
164 case __DRI_IMAGE_FORMAT_GR88
:
165 format
= __DRI_IMAGE_FOURCC_GR88
;
173 static enum pipe_format
dri2_format_to_pipe_format (int format
)
178 case __DRI_IMAGE_FORMAT_RGB565
:
179 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
181 case __DRI_IMAGE_FORMAT_XRGB8888
:
182 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
184 case __DRI_IMAGE_FORMAT_ARGB8888
:
185 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
187 case __DRI_IMAGE_FORMAT_XBGR8888
:
188 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
190 case __DRI_IMAGE_FORMAT_ABGR8888
:
191 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
193 case __DRI_IMAGE_FORMAT_R8
:
194 pf
= PIPE_FORMAT_R8_UNORM
;
196 case __DRI_IMAGE_FORMAT_GR88
:
197 pf
= PIPE_FORMAT_RG88_UNORM
;
200 pf
= PIPE_FORMAT_NONE
;
207 static enum pipe_format
fourcc_to_pipe_format(int fourcc
)
212 case __DRI_IMAGE_FOURCC_R8
:
213 pf
= PIPE_FORMAT_R8_UNORM
;
215 case __DRI_IMAGE_FOURCC_GR88
:
216 pf
= PIPE_FORMAT_RG88_UNORM
;
218 case __DRI_IMAGE_FOURCC_ARGB1555
:
219 pf
= PIPE_FORMAT_B5G5R5A1_UNORM
;
221 case __DRI_IMAGE_FOURCC_R16
:
222 pf
= PIPE_FORMAT_R16_UNORM
;
224 case __DRI_IMAGE_FOURCC_GR1616
:
225 pf
= PIPE_FORMAT_RG1616_UNORM
;
227 case __DRI_IMAGE_FOURCC_RGB565
:
228 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
230 case __DRI_IMAGE_FOURCC_ARGB8888
:
231 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
233 case __DRI_IMAGE_FOURCC_XRGB8888
:
234 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
236 case __DRI_IMAGE_FOURCC_ABGR8888
:
237 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
239 case __DRI_IMAGE_FOURCC_XBGR8888
:
240 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
243 case __DRI_IMAGE_FOURCC_NV12
:
244 pf
= PIPE_FORMAT_NV12
;
246 case __DRI_IMAGE_FOURCC_YUYV
:
247 pf
= PIPE_FORMAT_YUYV
;
249 case __DRI_IMAGE_FOURCC_YUV420
:
250 case __DRI_IMAGE_FOURCC_YVU420
:
251 pf
= PIPE_FORMAT_YV12
;
254 case __DRI_IMAGE_FOURCC_SARGB8888
:
255 case __DRI_IMAGE_FOURCC_YUV410
:
256 case __DRI_IMAGE_FOURCC_YUV411
:
257 case __DRI_IMAGE_FOURCC_YUV422
:
258 case __DRI_IMAGE_FOURCC_YUV444
:
259 case __DRI_IMAGE_FOURCC_NV16
:
260 case __DRI_IMAGE_FOURCC_YVU410
:
261 case __DRI_IMAGE_FOURCC_YVU411
:
262 case __DRI_IMAGE_FOURCC_YVU422
:
263 case __DRI_IMAGE_FOURCC_YVU444
:
265 pf
= PIPE_FORMAT_NONE
;
272 * DRI2 flush extension.
275 dri2_flush_drawable(__DRIdrawable
*dPriv
)
277 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
281 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
283 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
285 dri2InvalidateDrawable(dPriv
);
286 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
287 drawable
->texture_mask
= 0;
289 p_atomic_inc(&drawable
->base
.stamp
);
292 static const __DRI2flushExtension dri2FlushExtension
= {
293 .base
= { __DRI2_FLUSH
, 4 },
295 .flush
= dri2_flush_drawable
,
296 .invalidate
= dri2_invalidate_drawable
,
297 .flush_with_flags
= dri_flush
,
301 * Retrieve __DRIbuffer from the DRI loader.
304 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
305 const enum st_attachment_type
*atts
,
308 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
309 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
311 __DRIbuffer
*buffers
;
313 unsigned attachments
[10];
314 unsigned num_attachments
, i
;
317 with_format
= dri_with_format(drawable
->sPriv
);
321 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
323 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
325 for (i
= 0; i
< *count
; i
++) {
326 enum pipe_format format
;
330 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
331 if (format
== PIPE_FORMAT_NONE
)
335 case ST_ATTACHMENT_FRONT_LEFT
:
339 att
= __DRI_BUFFER_FRONT_LEFT
;
341 case ST_ATTACHMENT_BACK_LEFT
:
342 att
= __DRI_BUFFER_BACK_LEFT
;
344 case ST_ATTACHMENT_FRONT_RIGHT
:
345 att
= __DRI_BUFFER_FRONT_RIGHT
;
347 case ST_ATTACHMENT_BACK_RIGHT
:
348 att
= __DRI_BUFFER_BACK_RIGHT
;
355 * In this switch statement we must support all formats that
356 * may occur as the stvis->color_format.
359 case PIPE_FORMAT_BGRA8888_UNORM
:
360 case PIPE_FORMAT_RGBA8888_UNORM
:
363 case PIPE_FORMAT_BGRX8888_UNORM
:
364 case PIPE_FORMAT_RGBX8888_UNORM
:
367 case PIPE_FORMAT_B5G6R5_UNORM
:
371 depth
= util_format_get_blocksizebits(format
);
372 assert(!"Unexpected format in dri2_drawable_get_buffers()");
375 attachments
[num_attachments
++] = att
;
377 attachments
[num_attachments
++] = depth
;
382 num_attachments
/= 2;
383 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
384 &dri_drawable
->w
, &dri_drawable
->h
,
385 attachments
, num_attachments
,
386 &num_buffers
, dri_drawable
->loaderPrivate
);
389 buffers
= loader
->getBuffers(dri_drawable
,
390 &dri_drawable
->w
, &dri_drawable
->h
,
391 attachments
, num_attachments
,
392 &num_buffers
, dri_drawable
->loaderPrivate
);
396 *count
= num_buffers
;
402 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
403 struct __DRIimageList
*images
,
404 const enum st_attachment_type
*statts
,
405 unsigned statts_count
)
407 __DRIdrawable
*dPriv
= drawable
->dPriv
;
408 __DRIscreen
*sPriv
= drawable
->sPriv
;
409 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
411 uint32_t buffer_mask
= 0;
414 for (i
= 0; i
< statts_count
; i
++) {
415 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
416 if (pf
== PIPE_FORMAT_NONE
)
420 case ST_ATTACHMENT_FRONT_LEFT
:
421 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
423 case ST_ATTACHMENT_BACK_LEFT
:
424 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
431 case PIPE_FORMAT_B5G6R5_UNORM
:
432 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
434 case PIPE_FORMAT_BGRX8888_UNORM
:
435 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
437 case PIPE_FORMAT_BGRA8888_UNORM
:
438 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
440 case PIPE_FORMAT_RGBX8888_UNORM
:
441 image_format
= __DRI_IMAGE_FORMAT_XBGR8888
;
443 case PIPE_FORMAT_RGBA8888_UNORM
:
444 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
447 image_format
= __DRI_IMAGE_FORMAT_NONE
;
452 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
453 (uint32_t *) &drawable
->base
.stamp
,
454 dPriv
->loaderPrivate
, buffer_mask
,
459 dri2_allocate_buffer(__DRIscreen
*sPriv
,
460 unsigned attachment
, unsigned format
,
461 int width
, int height
)
463 struct dri_screen
*screen
= dri_screen(sPriv
);
464 struct dri2_buffer
*buffer
;
465 struct pipe_resource templ
;
468 struct winsys_handle whandle
;
470 switch (attachment
) {
471 case __DRI_BUFFER_FRONT_LEFT
:
472 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
473 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
475 case __DRI_BUFFER_BACK_LEFT
:
476 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
478 case __DRI_BUFFER_DEPTH
:
479 case __DRI_BUFFER_DEPTH_STENCIL
:
480 case __DRI_BUFFER_STENCIL
:
481 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
485 /* because we get the handle and stride */
486 bind
|= PIPE_BIND_SHARED
;
490 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
493 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
496 pf
= PIPE_FORMAT_Z16_UNORM
;
502 buffer
= CALLOC_STRUCT(dri2_buffer
);
506 memset(&templ
, 0, sizeof(templ
));
509 templ
.target
= PIPE_TEXTURE_2D
;
510 templ
.last_level
= 0;
511 templ
.width0
= width
;
512 templ
.height0
= height
;
514 templ
.array_size
= 1;
517 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
518 if (!buffer
->resource
) {
523 memset(&whandle
, 0, sizeof(whandle
));
524 if (screen
->can_share_buffer
)
525 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
527 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
529 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
, NULL
,
530 buffer
->resource
, &whandle
,
531 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
533 buffer
->base
.attachment
= attachment
;
534 buffer
->base
.name
= whandle
.handle
;
535 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
536 buffer
->base
.pitch
= whandle
.stride
;
538 return &buffer
->base
;
542 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
544 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
546 pipe_resource_reference(&buffer
->resource
, NULL
);
551 * Backend functions for st_framebuffer interface.
555 dri2_allocate_textures(struct dri_context
*ctx
,
556 struct dri_drawable
*drawable
,
557 const enum st_attachment_type
*statts
,
558 unsigned statts_count
)
560 __DRIscreen
*sPriv
= drawable
->sPriv
;
561 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
562 struct dri_screen
*screen
= dri_screen(sPriv
);
563 struct pipe_resource templ
;
564 boolean alloc_depthstencil
= FALSE
;
566 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
567 /* Image specific variables */
568 struct __DRIimageList images
;
569 /* Dri2 specific variables */
570 __DRIbuffer
*buffers
= NULL
;
571 struct winsys_handle whandle
;
572 unsigned num_buffers
= statts_count
;
574 /* First get the buffers from the loader */
576 if (!dri_image_drawable_get_buffers(drawable
, &images
,
577 statts
, statts_count
))
581 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
582 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
583 drawable
->old_w
== dri_drawable
->w
&&
584 drawable
->old_h
== dri_drawable
->h
&&
585 memcmp(drawable
->old
, buffers
,
586 sizeof(__DRIbuffer
) * num_buffers
) == 0))
590 /* Second clean useless resources*/
592 /* See if we need a depth-stencil buffer. */
593 for (i
= 0; i
< statts_count
; i
++) {
594 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
595 alloc_depthstencil
= TRUE
;
600 /* Delete the resources we won't need. */
601 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
602 /* Don't delete the depth-stencil buffer, we can reuse it. */
603 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
606 /* Flush the texture before unreferencing, so that other clients can
607 * see what the driver has rendered.
609 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
610 struct pipe_context
*pipe
= ctx
->st
->pipe
;
611 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
614 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
617 if (drawable
->stvis
.samples
> 1) {
618 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
621 /* Don't delete MSAA resources for the attachments which are enabled,
622 * we can reuse them. */
623 for (j
= 0; j
< statts_count
; j
++) {
624 if (i
== statts
[j
]) {
631 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
636 /* Third use the buffers retrieved to fill the drawable info */
638 memset(&templ
, 0, sizeof(templ
));
639 templ
.target
= screen
->target
;
640 templ
.last_level
= 0;
642 templ
.array_size
= 1;
645 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
646 struct pipe_resource
**buf
=
647 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
648 struct pipe_resource
*texture
= images
.front
->texture
;
650 dri_drawable
->w
= texture
->width0
;
651 dri_drawable
->h
= texture
->height0
;
653 pipe_resource_reference(buf
, texture
);
656 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
657 struct pipe_resource
**buf
=
658 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
659 struct pipe_resource
*texture
= images
.back
->texture
;
661 dri_drawable
->w
= texture
->width0
;
662 dri_drawable
->h
= texture
->height0
;
664 pipe_resource_reference(buf
, texture
);
667 /* Note: if there is both a back and a front buffer,
668 * then they have the same size.
670 templ
.width0
= dri_drawable
->w
;
671 templ
.height0
= dri_drawable
->h
;
674 memset(&whandle
, 0, sizeof(whandle
));
676 /* Process DRI-provided buffers and get pipe_resources. */
677 for (i
= 0; i
< num_buffers
; i
++) {
678 __DRIbuffer
*buf
= &buffers
[i
];
679 enum st_attachment_type statt
;
680 enum pipe_format format
;
682 switch (buf
->attachment
) {
683 case __DRI_BUFFER_FRONT_LEFT
:
684 if (!screen
->auto_fake_front
) {
685 continue; /* invalid attachment */
688 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
689 statt
= ST_ATTACHMENT_FRONT_LEFT
;
691 case __DRI_BUFFER_BACK_LEFT
:
692 statt
= ST_ATTACHMENT_BACK_LEFT
;
695 continue; /* invalid attachment */
698 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
699 if (format
== PIPE_FORMAT_NONE
)
702 /* dri2_drawable_get_buffers has already filled dri_drawable->w
703 * and dri_drawable->h */
704 templ
.width0
= dri_drawable
->w
;
705 templ
.height0
= dri_drawable
->h
;
706 templ
.format
= format
;
708 whandle
.handle
= buf
->name
;
709 whandle
.stride
= buf
->pitch
;
711 if (screen
->can_share_buffer
)
712 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
714 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
715 drawable
->textures
[statt
] =
716 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
718 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
719 assert(drawable
->textures
[statt
]);
723 /* Allocate private MSAA colorbuffers. */
724 if (drawable
->stvis
.samples
> 1) {
725 for (i
= 0; i
< statts_count
; i
++) {
726 enum st_attachment_type statt
= statts
[i
];
728 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
731 if (drawable
->textures
[statt
]) {
732 templ
.format
= drawable
->textures
[statt
]->format
;
733 templ
.bind
= drawable
->textures
[statt
]->bind
&
734 ~(PIPE_BIND_SCANOUT
| PIPE_BIND_SHARED
);
735 templ
.nr_samples
= drawable
->stvis
.samples
;
737 /* Try to reuse the resource.
738 * (the other resource parameters should be constant)
740 if (!drawable
->msaa_textures
[statt
] ||
741 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
742 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
743 /* Allocate a new one. */
744 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
746 drawable
->msaa_textures
[statt
] =
747 screen
->base
.screen
->resource_create(screen
->base
.screen
,
749 assert(drawable
->msaa_textures
[statt
]);
751 /* If there are any MSAA resources, we should initialize them
752 * such that they contain the same data as the single-sample
753 * resources we just got from the X server.
755 * The reason for this is that the state tracker (and
756 * therefore the app) can access the MSAA resources only.
757 * The single-sample resources are not exposed
758 * to the state tracker.
761 dri_pipe_blit(ctx
->st
->pipe
,
762 drawable
->msaa_textures
[statt
],
763 drawable
->textures
[statt
]);
767 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
772 /* Allocate a private depth-stencil buffer. */
773 if (alloc_depthstencil
) {
774 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
775 struct pipe_resource
**zsbuf
;
776 enum pipe_format format
;
779 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
782 templ
.format
= format
;
783 templ
.bind
= bind
& ~PIPE_BIND_SHARED
;
785 if (drawable
->stvis
.samples
> 1) {
786 templ
.nr_samples
= drawable
->stvis
.samples
;
787 zsbuf
= &drawable
->msaa_textures
[statt
];
790 templ
.nr_samples
= 0;
791 zsbuf
= &drawable
->textures
[statt
];
794 /* Try to reuse the resource.
795 * (the other resource parameters should be constant)
798 (*zsbuf
)->width0
!= templ
.width0
||
799 (*zsbuf
)->height0
!= templ
.height0
) {
800 /* Allocate a new one. */
801 pipe_resource_reference(zsbuf
, NULL
);
802 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
808 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
809 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
813 /* For DRI2, we may get the same buffers again from the server.
814 * To prevent useless imports of gem names, drawable->old* is used
815 * to bypass the import if we get the same buffers. This doesn't apply
816 * to DRI3/Wayland, users of image.loader, since the buffer is managed
817 * by the client (no import), and the back buffer is going to change
821 drawable
->old_num
= num_buffers
;
822 drawable
->old_w
= dri_drawable
->w
;
823 drawable
->old_h
= dri_drawable
->h
;
824 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
829 dri2_flush_frontbuffer(struct dri_context
*ctx
,
830 struct dri_drawable
*drawable
,
831 enum st_attachment_type statt
)
833 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
834 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
835 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
836 struct pipe_context
*pipe
= ctx
->st
->pipe
;
838 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
841 if (drawable
->stvis
.samples
> 1) {
842 /* Resolve the front buffer. */
843 dri_pipe_blit(ctx
->st
->pipe
,
844 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
845 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
848 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
849 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
852 pipe
->flush(pipe
, NULL
, 0);
855 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
857 else if (loader
->flushFrontBuffer
) {
858 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
863 * The struct dri_drawable flush_swapbuffers callback
866 dri2_flush_swapbuffers(struct dri_context
*ctx
,
867 struct dri_drawable
*drawable
)
869 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
870 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
872 if (image
&& image
->base
.version
>= 3 && image
->flushSwapBuffers
) {
873 image
->flushSwapBuffers(dri_drawable
, dri_drawable
->loaderPrivate
);
878 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
879 struct dri_context
*ctx
,
880 struct pipe_resource
*res
)
886 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
887 int width
, int height
, int format
,
888 int num_handles
, struct winsys_handle
*whandle
,
891 struct dri_screen
*screen
= dri_screen(_screen
);
892 struct pipe_screen
*pscreen
= screen
->base
.screen
;
894 struct pipe_resource templ
;
899 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
901 pf
= dri2_format_to_pipe_format (format
);
902 if (pf
== PIPE_FORMAT_NONE
)
905 img
= CALLOC_STRUCT(__DRIimageRec
);
909 memset(&templ
, 0, sizeof(templ
));
910 templ
.bind
= tex_usage
;
911 templ
.target
= screen
->target
;
912 templ
.last_level
= 0;
914 templ
.array_size
= 1;
916 for (i
= num_handles
- 1; i
>= 0; i
--) {
917 struct pipe_resource
*tex
;
919 /* TODO: something a lot less ugly */
922 templ
.width0
= width
;
923 templ
.height0
= height
;
927 templ
.width0
= width
/ 2;
928 templ
.height0
= height
/ 2;
929 templ
.format
= (num_handles
== 2) ?
930 PIPE_FORMAT_RG88_UNORM
: /* NV12, etc */
931 PIPE_FORMAT_R8_UNORM
; /* I420, etc */
934 templ
.width0
= width
/ 2;
935 templ
.height0
= height
/ 2;
936 templ
.format
= PIPE_FORMAT_R8_UNORM
;
939 unreachable("too many planes!");
942 tex
= pscreen
->resource_from_handle(pscreen
,
943 &templ
, &whandle
[i
], PIPE_HANDLE_USAGE_READ_WRITE
);
945 pipe_resource_reference(&img
->texture
, NULL
);
950 tex
->next
= img
->texture
;
956 img
->dri_format
= format
;
958 img
->loader_private
= loaderPrivate
;
964 dri2_create_image_from_name(__DRIscreen
*_screen
,
965 int width
, int height
, int format
,
966 int name
, int pitch
, void *loaderPrivate
)
968 struct winsys_handle whandle
;
971 memset(&whandle
, 0, sizeof(whandle
));
972 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
973 whandle
.handle
= name
;
974 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
976 pf
= dri2_format_to_pipe_format (format
);
977 if (pf
== PIPE_FORMAT_NONE
)
980 whandle
.stride
= pitch
* util_format_get_blocksize(pf
);
982 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
983 1, &whandle
, loaderPrivate
);
987 dri2_create_image_from_fd(__DRIscreen
*_screen
,
988 int width
, int height
, int fourcc
,
989 uint64_t modifier
, int *fds
, int num_fds
,
990 int *strides
, int *offsets
, unsigned *error
,
991 int *dri_components
, void *loaderPrivate
)
993 struct winsys_handle whandles
[3];
995 __DRIimage
*img
= NULL
;
996 unsigned err
= __DRI_IMAGE_ERROR_SUCCESS
;
997 int expected_num_fds
, i
;
1000 case __DRI_IMAGE_FOURCC_YUV420
:
1001 case __DRI_IMAGE_FOURCC_YVU420
:
1002 expected_num_fds
= 3;
1004 case __DRI_IMAGE_FOURCC_NV12
:
1005 expected_num_fds
= 2;
1008 expected_num_fds
= 1;
1012 if (num_fds
!= expected_num_fds
) {
1013 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1017 format
= convert_fourcc(fourcc
, dri_components
);
1019 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1023 memset(whandles
, 0, sizeof(whandles
));
1025 for (i
= 0; i
< num_fds
; i
++) {
1027 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1031 whandles
[i
].type
= DRM_API_HANDLE_TYPE_FD
;
1032 whandles
[i
].handle
= (unsigned)fds
[i
];
1033 whandles
[i
].stride
= (unsigned)strides
[i
];
1034 whandles
[i
].offset
= (unsigned)offsets
[i
];
1035 whandles
[i
].modifier
= modifier
;
1038 if (fourcc
== __DRI_IMAGE_FOURCC_YVU420
) {
1039 /* convert to YUV420 by swapping 2nd and 3rd planes: */
1040 struct winsys_handle tmp
= whandles
[1];
1041 whandles
[1] = whandles
[2];
1043 fourcc
= __DRI_IMAGE_FOURCC_YUV420
;
1046 img
= dri2_create_image_from_winsys(_screen
, width
, height
, format
,
1047 num_fds
, whandles
, loaderPrivate
);
1049 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1059 dri2_create_image_common(__DRIscreen
*_screen
,
1060 int width
, int height
,
1061 int format
, unsigned int use
,
1062 const uint64_t *modifiers
,
1063 const unsigned count
,
1064 void *loaderPrivate
)
1066 struct dri_screen
*screen
= dri_screen(_screen
);
1068 struct pipe_resource templ
;
1070 enum pipe_format pf
;
1072 /* createImageWithModifiers doesn't supply usage, and we should not get
1073 * here with both modifiers and a usage flag.
1075 assert(!(use
&& (modifiers
!= NULL
)));
1077 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1079 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1080 tex_usage
|= PIPE_BIND_SCANOUT
;
1081 if (use
& __DRI_IMAGE_USE_SHARE
)
1082 tex_usage
|= PIPE_BIND_SHARED
;
1083 if (use
& __DRI_IMAGE_USE_LINEAR
)
1084 tex_usage
|= PIPE_BIND_LINEAR
;
1085 if (use
& __DRI_IMAGE_USE_CURSOR
) {
1086 if (width
!= 64 || height
!= 64)
1088 tex_usage
|= PIPE_BIND_CURSOR
;
1091 pf
= dri2_format_to_pipe_format (format
);
1092 if (pf
== PIPE_FORMAT_NONE
)
1095 img
= CALLOC_STRUCT(__DRIimageRec
);
1099 memset(&templ
, 0, sizeof(templ
));
1100 templ
.bind
= tex_usage
;
1102 templ
.target
= PIPE_TEXTURE_2D
;
1103 templ
.last_level
= 0;
1104 templ
.width0
= width
;
1105 templ
.height0
= height
;
1107 templ
.array_size
= 1;
1112 ->resource_create_with_modifiers(screen
->base
.screen
,
1118 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
1119 if (!img
->texture
) {
1126 img
->dri_format
= format
;
1127 img
->dri_components
= 0;
1130 img
->loader_private
= loaderPrivate
;
1135 dri2_create_image(__DRIscreen
*_screen
,
1136 int width
, int height
, int format
,
1137 unsigned int use
, void *loaderPrivate
)
1139 return dri2_create_image_common(_screen
, width
, height
, format
, use
,
1140 NULL
/* modifiers */, 0 /* count */,
1145 dri2_create_image_with_modifiers(__DRIscreen
*dri_screen
,
1146 int width
, int height
, int format
,
1147 const uint64_t *modifiers
,
1148 const unsigned count
,
1149 void *loaderPrivate
)
1151 return dri2_create_image_common(dri_screen
, width
, height
, format
,
1152 0 /* use */, modifiers
, count
,
1157 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
1159 struct winsys_handle whandle
;
1162 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1163 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
;
1165 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1167 memset(&whandle
, 0, sizeof(whandle
));
1170 case __DRI_IMAGE_ATTRIB_STRIDE
:
1171 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1172 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1173 NULL
, image
->texture
, &whandle
, usage
))
1175 *value
= whandle
.stride
;
1177 case __DRI_IMAGE_ATTRIB_OFFSET
:
1178 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1179 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1180 NULL
, image
->texture
, &whandle
, usage
))
1182 *value
= whandle
.offset
;
1184 case __DRI_IMAGE_ATTRIB_HANDLE
:
1185 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1186 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1187 NULL
, image
->texture
, &whandle
, usage
))
1189 *value
= whandle
.handle
;
1191 case __DRI_IMAGE_ATTRIB_NAME
:
1192 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
1193 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1194 NULL
, image
->texture
, &whandle
, usage
))
1196 *value
= whandle
.handle
;
1198 case __DRI_IMAGE_ATTRIB_FD
:
1199 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1200 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1201 NULL
, image
->texture
, &whandle
, usage
))
1204 *value
= whandle
.handle
;
1206 case __DRI_IMAGE_ATTRIB_FORMAT
:
1207 *value
= image
->dri_format
;
1209 case __DRI_IMAGE_ATTRIB_WIDTH
:
1210 *value
= image
->texture
->width0
;
1212 case __DRI_IMAGE_ATTRIB_HEIGHT
:
1213 *value
= image
->texture
->height0
;
1215 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
1216 if (image
->dri_components
== 0)
1218 *value
= image
->dri_components
;
1220 case __DRI_IMAGE_ATTRIB_FOURCC
:
1221 *value
= convert_to_fourcc(image
->dri_format
);
1223 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1226 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1227 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1228 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1229 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1230 NULL
, image
->texture
, &whandle
, usage
))
1232 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1234 *value
= (whandle
.modifier
>> 32) & 0xffffffff;
1236 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1237 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1238 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1239 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1240 NULL
, image
->texture
, &whandle
, usage
))
1242 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1244 *value
= whandle
.modifier
& 0xffffffff;
1252 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
1256 img
= CALLOC_STRUCT(__DRIimageRec
);
1260 img
->texture
= NULL
;
1261 pipe_resource_reference(&img
->texture
, image
->texture
);
1262 img
->level
= image
->level
;
1263 img
->layer
= image
->layer
;
1264 img
->dri_format
= image
->dri_format
;
1265 /* This should be 0 for sub images, but dup is also used for base images. */
1266 img
->dri_components
= image
->dri_components
;
1267 img
->loader_private
= loaderPrivate
;
1273 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
1276 * Gallium drivers are bad at adding usages to the resources
1277 * once opened again in another process, which is the main use
1278 * case for this, so we have to lie.
1287 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
1288 int *names
, int num_names
, int *strides
, int *offsets
,
1289 void *loaderPrivate
)
1293 struct winsys_handle whandle
;
1298 format
= convert_fourcc(format
, &dri_components
);
1302 memset(&whandle
, 0, sizeof(whandle
));
1303 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
1304 whandle
.handle
= names
[0];
1305 whandle
.stride
= strides
[0];
1306 whandle
.offset
= offsets
[0];
1307 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1309 img
= dri2_create_image_from_winsys(screen
, width
, height
, format
,
1310 1, &whandle
, loaderPrivate
);
1314 img
->dri_components
= dri_components
;
1319 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1326 if (image
->dri_components
== 0)
1329 img
= dri2_dup_image(image
, loaderPrivate
);
1333 if (img
->texture
->screen
->resource_changed
)
1334 img
->texture
->screen
->resource_changed(img
->texture
->screen
,
1337 /* set this to 0 for sub images. */
1338 img
->dri_components
= 0;
1343 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1344 int *fds
, int num_fds
, int *strides
, int *offsets
,
1345 void *loaderPrivate
)
1350 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1351 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1352 strides
, offsets
, NULL
,
1353 &dri_components
, loaderPrivate
);
1357 img
->dri_components
= dri_components
;
1362 dri2_query_dma_buf_formats(__DRIscreen
*_screen
, int max
, int *formats
,
1365 struct dri_screen
*screen
= dri_screen(_screen
);
1366 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1367 const unsigned bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1370 for (i
= 0, j
= 0; (i
< ARRAY_SIZE(fourcc_formats
)) &&
1371 (j
< max
|| max
== 0); i
++) {
1372 if (pscreen
->is_format_supported(pscreen
,
1373 fourcc_to_pipe_format(
1378 formats
[j
] = fourcc_formats
[i
];
1387 dri2_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1388 uint64_t *modifiers
, unsigned int *external_only
,
1391 struct dri_screen
*screen
= dri_screen(_screen
);
1392 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1393 enum pipe_format format
= fourcc_to_pipe_format(fourcc
);
1394 const unsigned usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1396 if (pscreen
->query_dmabuf_modifiers
!= NULL
&&
1397 pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, usage
)) {
1398 pscreen
->query_dmabuf_modifiers(pscreen
, format
, max
, modifiers
,
1399 external_only
, count
);
1406 dri2_from_dma_bufs(__DRIscreen
*screen
,
1407 int width
, int height
, int fourcc
,
1408 int *fds
, int num_fds
,
1409 int *strides
, int *offsets
,
1410 enum __DRIYUVColorSpace yuv_color_space
,
1411 enum __DRISampleRange sample_range
,
1412 enum __DRIChromaSiting horizontal_siting
,
1413 enum __DRIChromaSiting vertical_siting
,
1415 void *loaderPrivate
)
1420 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1421 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1422 strides
, offsets
, error
,
1423 &dri_components
, loaderPrivate
);
1427 img
->yuv_color_space
= yuv_color_space
;
1428 img
->sample_range
= sample_range
;
1429 img
->horizontal_siting
= horizontal_siting
;
1430 img
->vertical_siting
= vertical_siting
;
1431 img
->dri_components
= dri_components
;
1433 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1438 dri2_from_dma_bufs2(__DRIscreen
*screen
,
1439 int width
, int height
, int fourcc
,
1440 uint64_t modifier
, int *fds
, int num_fds
,
1441 int *strides
, int *offsets
,
1442 enum __DRIYUVColorSpace yuv_color_space
,
1443 enum __DRISampleRange sample_range
,
1444 enum __DRIChromaSiting horizontal_siting
,
1445 enum __DRIChromaSiting vertical_siting
,
1447 void *loaderPrivate
)
1452 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1453 modifier
, fds
, num_fds
, strides
, offsets
,
1454 error
, &dri_components
, loaderPrivate
);
1458 img
->yuv_color_space
= yuv_color_space
;
1459 img
->sample_range
= sample_range
;
1460 img
->horizontal_siting
= horizontal_siting
;
1461 img
->vertical_siting
= vertical_siting
;
1462 img
->dri_components
= dri_components
;
1464 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1469 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1470 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1471 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1474 struct dri_context
*ctx
= dri_context(context
);
1475 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1476 struct pipe_screen
*screen
;
1477 struct pipe_fence_handle
*fence
;
1478 struct pipe_blit_info blit
;
1483 memset(&blit
, 0, sizeof(blit
));
1484 blit
.dst
.resource
= dst
->texture
;
1485 blit
.dst
.box
.x
= dstx0
;
1486 blit
.dst
.box
.y
= dsty0
;
1487 blit
.dst
.box
.width
= dstwidth
;
1488 blit
.dst
.box
.height
= dstheight
;
1489 blit
.dst
.box
.depth
= 1;
1490 blit
.dst
.format
= dst
->texture
->format
;
1491 blit
.src
.resource
= src
->texture
;
1492 blit
.src
.box
.x
= srcx0
;
1493 blit
.src
.box
.y
= srcy0
;
1494 blit
.src
.box
.width
= srcwidth
;
1495 blit
.src
.box
.height
= srcheight
;
1496 blit
.src
.box
.depth
= 1;
1497 blit
.src
.format
= src
->texture
->format
;
1498 blit
.mask
= PIPE_MASK_RGBA
;
1499 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1501 pipe
->blit(pipe
, &blit
);
1503 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1504 pipe
->flush_resource(pipe
, dst
->texture
);
1505 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1506 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1507 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1508 pipe
->flush_resource(pipe
, dst
->texture
);
1509 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1510 (void) screen
->fence_finish(screen
, NULL
, fence
, PIPE_TIMEOUT_INFINITE
);
1511 screen
->fence_reference(screen
, &fence
, NULL
);
1516 dri2_map_image(__DRIcontext
*context
, __DRIimage
*image
,
1517 int x0
, int y0
, int width
, int height
,
1518 unsigned int flags
, int *stride
, void **data
)
1520 struct dri_context
*ctx
= dri_context(context
);
1521 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1522 enum pipe_transfer_usage pipe_access
= 0;
1523 struct pipe_transfer
*trans
;
1526 if (!image
|| !data
|| *data
)
1529 if (flags
& __DRI_IMAGE_TRANSFER_READ
)
1530 pipe_access
|= PIPE_TRANSFER_READ
;
1531 if (flags
& __DRI_IMAGE_TRANSFER_WRITE
)
1532 pipe_access
|= PIPE_TRANSFER_WRITE
;
1534 map
= pipe_transfer_map(pipe
, image
->texture
,
1535 0, 0, pipe_access
, x0
, y0
, width
, height
,
1539 *stride
= trans
->stride
;
1546 dri2_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *data
)
1548 struct dri_context
*ctx
= dri_context(context
);
1549 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1551 pipe_transfer_unmap(pipe
, (struct pipe_transfer
*)data
);
1555 dri2_get_capabilities(__DRIscreen
*_screen
)
1557 struct dri_screen
*screen
= dri_screen(_screen
);
1559 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1562 /* The extension is modified during runtime if DRI_PRIME is detected */
1563 static __DRIimageExtension dri2ImageExtension
= {
1564 .base
= { __DRI_IMAGE
, 15 },
1566 .createImageFromName
= dri2_create_image_from_name
,
1567 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1568 .destroyImage
= dri2_destroy_image
,
1569 .createImage
= dri2_create_image
,
1570 .queryImage
= dri2_query_image
,
1571 .dupImage
= dri2_dup_image
,
1572 .validateUsage
= dri2_validate_usage
,
1573 .createImageFromNames
= dri2_from_names
,
1574 .fromPlanar
= dri2_from_planar
,
1575 .createImageFromTexture
= dri2_create_from_texture
,
1576 .createImageFromFds
= NULL
,
1577 .createImageFromDmaBufs
= NULL
,
1578 .blitImage
= dri2_blit_image
,
1579 .getCapabilities
= dri2_get_capabilities
,
1580 .mapImage
= dri2_map_image
,
1581 .unmapImage
= dri2_unmap_image
,
1584 static const __DRIrobustnessExtension dri2Robustness
= {
1585 .base
= { __DRI2_ROBUSTNESS
, 1 }
1589 dri2_interop_query_device_info(__DRIcontext
*_ctx
,
1590 struct mesa_glinterop_device_info
*out
)
1592 struct pipe_screen
*screen
= dri_context(_ctx
)->st
->pipe
->screen
;
1594 /* There is no version 0, thus we do not support it */
1595 if (out
->version
== 0)
1596 return MESA_GLINTEROP_INVALID_VERSION
;
1598 out
->pci_segment_group
= screen
->get_param(screen
, PIPE_CAP_PCI_GROUP
);
1599 out
->pci_bus
= screen
->get_param(screen
, PIPE_CAP_PCI_BUS
);
1600 out
->pci_device
= screen
->get_param(screen
, PIPE_CAP_PCI_DEVICE
);
1601 out
->pci_function
= screen
->get_param(screen
, PIPE_CAP_PCI_FUNCTION
);
1603 out
->vendor_id
= screen
->get_param(screen
, PIPE_CAP_VENDOR_ID
);
1604 out
->device_id
= screen
->get_param(screen
, PIPE_CAP_DEVICE_ID
);
1606 /* Instruct the caller that we support up-to version one of the interface */
1609 return MESA_GLINTEROP_SUCCESS
;
1613 dri2_interop_export_object(__DRIcontext
*_ctx
,
1614 struct mesa_glinterop_export_in
*in
,
1615 struct mesa_glinterop_export_out
*out
)
1617 struct st_context_iface
*st
= dri_context(_ctx
)->st
;
1618 struct pipe_screen
*screen
= st
->pipe
->screen
;
1619 struct gl_context
*ctx
= ((struct st_context
*)st
)->ctx
;
1620 struct pipe_resource
*res
= NULL
;
1621 struct winsys_handle whandle
;
1622 unsigned target
, usage
;
1625 /* There is no version 0, thus we do not support it */
1626 if (in
->version
== 0 || out
->version
== 0)
1627 return MESA_GLINTEROP_INVALID_VERSION
;
1629 /* Validate the target. */
1630 switch (in
->target
) {
1631 case GL_TEXTURE_BUFFER
:
1635 case GL_TEXTURE_RECTANGLE
:
1636 case GL_TEXTURE_1D_ARRAY
:
1637 case GL_TEXTURE_2D_ARRAY
:
1638 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1639 case GL_TEXTURE_CUBE_MAP
:
1640 case GL_TEXTURE_2D_MULTISAMPLE
:
1641 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1642 case GL_TEXTURE_EXTERNAL_OES
:
1643 case GL_RENDERBUFFER
:
1644 case GL_ARRAY_BUFFER
:
1645 target
= in
->target
;
1647 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1648 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1649 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1650 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1651 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1652 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1653 target
= GL_TEXTURE_CUBE_MAP
;
1656 return MESA_GLINTEROP_INVALID_TARGET
;
1659 /* Validate the simple case of miplevel. */
1660 if ((target
== GL_RENDERBUFFER
|| target
== GL_ARRAY_BUFFER
) &&
1662 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1664 /* Validate the OpenGL object and get pipe_resource. */
1665 mtx_lock(&ctx
->Shared
->Mutex
);
1667 if (target
== GL_ARRAY_BUFFER
) {
1670 * The error checking is based on the documentation of
1671 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1673 struct gl_buffer_object
*buf
= _mesa_lookup_bufferobj(ctx
, in
->obj
);
1675 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1676 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1677 * a GL buffer object but does not have an existing data store or
1678 * the size of the buffer is 0."
1680 if (!buf
|| buf
->Size
== 0) {
1681 mtx_unlock(&ctx
->Shared
->Mutex
);
1682 return MESA_GLINTEROP_INVALID_OBJECT
;
1685 res
= st_buffer_object(buf
)->buffer
;
1687 /* this shouldn't happen */
1688 mtx_unlock(&ctx
->Shared
->Mutex
);
1689 return MESA_GLINTEROP_INVALID_OBJECT
;
1692 out
->buf_offset
= 0;
1693 out
->buf_size
= buf
->Size
;
1695 buf
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1696 } else if (target
== GL_RENDERBUFFER
) {
1699 * The error checking is based on the documentation of
1700 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1702 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, in
->obj
);
1704 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1705 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1706 * object or if the width or height of renderbuffer is zero."
1708 if (!rb
|| rb
->Width
== 0 || rb
->Height
== 0) {
1709 mtx_unlock(&ctx
->Shared
->Mutex
);
1710 return MESA_GLINTEROP_INVALID_OBJECT
;
1713 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1714 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1715 * renderbuffer object."
1717 if (rb
->NumSamples
> 1) {
1718 mtx_unlock(&ctx
->Shared
->Mutex
);
1719 return MESA_GLINTEROP_INVALID_OPERATION
;
1722 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1723 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1724 * required by the OpenCL implementation on the device."
1726 res
= st_renderbuffer(rb
)->texture
;
1728 mtx_unlock(&ctx
->Shared
->Mutex
);
1729 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1732 out
->internal_format
= rb
->InternalFormat
;
1733 out
->view_minlevel
= 0;
1734 out
->view_numlevels
= 1;
1735 out
->view_minlayer
= 0;
1736 out
->view_numlayers
= 1;
1740 * The error checking is based on the documentation of
1741 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1743 struct gl_texture_object
*obj
= _mesa_lookup_texture(ctx
, in
->obj
);
1746 _mesa_test_texobj_completeness(ctx
, obj
);
1748 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1749 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1750 * type matches texture_target, if the specified miplevel of texture
1751 * is not defined, or if the width or height of the specified
1752 * miplevel is zero or if the GL texture object is incomplete."
1755 obj
->Target
!= target
||
1756 !obj
->_BaseComplete
||
1757 (in
->miplevel
> 0 && !obj
->_MipmapComplete
)) {
1758 mtx_unlock(&ctx
->Shared
->Mutex
);
1759 return MESA_GLINTEROP_INVALID_OBJECT
;
1762 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1763 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1764 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1765 * implementations); or greater than the value of q (for both OpenGL
1766 * and OpenGL ES). levelbase and q are defined for the texture in
1767 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1768 * specification and section 3.7.10 of the OpenGL ES 2.0."
1770 if (in
->miplevel
< obj
->BaseLevel
|| in
->miplevel
> obj
->_MaxLevel
) {
1771 mtx_unlock(&ctx
->Shared
->Mutex
);
1772 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1775 if (!st_finalize_texture(ctx
, st
->pipe
, obj
, 0)) {
1776 mtx_unlock(&ctx
->Shared
->Mutex
);
1777 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1780 res
= st_get_texobj_resource(obj
);
1782 /* Incomplete texture buffer object? This shouldn't really occur. */
1783 mtx_unlock(&ctx
->Shared
->Mutex
);
1784 return MESA_GLINTEROP_INVALID_OBJECT
;
1787 if (target
== GL_TEXTURE_BUFFER
) {
1788 out
->internal_format
= obj
->BufferObjectFormat
;
1789 out
->buf_offset
= obj
->BufferOffset
;
1790 out
->buf_size
= obj
->BufferSize
== -1 ? obj
->BufferObject
->Size
:
1793 obj
->BufferObject
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1795 out
->internal_format
= obj
->Image
[0][0]->InternalFormat
;
1796 out
->view_minlevel
= obj
->MinLevel
;
1797 out
->view_numlevels
= obj
->NumLevels
;
1798 out
->view_minlayer
= obj
->MinLayer
;
1799 out
->view_numlayers
= obj
->NumLayers
;
1803 /* Get the handle. */
1804 switch (in
->access
) {
1805 case MESA_GLINTEROP_ACCESS_READ_WRITE
:
1806 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1808 case MESA_GLINTEROP_ACCESS_READ_ONLY
:
1809 usage
= PIPE_HANDLE_USAGE_READ
;
1811 case MESA_GLINTEROP_ACCESS_WRITE_ONLY
:
1812 usage
= PIPE_HANDLE_USAGE_WRITE
;
1818 memset(&whandle
, 0, sizeof(whandle
));
1819 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1821 success
= screen
->resource_get_handle(screen
, st
->pipe
, res
, &whandle
,
1823 mtx_unlock(&ctx
->Shared
->Mutex
);
1826 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY
;
1828 out
->dmabuf_fd
= whandle
.handle
;
1829 out
->out_driver_data_written
= 0;
1831 if (res
->target
== PIPE_BUFFER
)
1832 out
->buf_offset
+= whandle
.offset
;
1834 /* Instruct the caller that we support up-to version one of the interface */
1838 return MESA_GLINTEROP_SUCCESS
;
1841 static const __DRI2interopExtension dri2InteropExtension
= {
1842 .base
= { __DRI2_INTEROP
, 1 },
1843 .query_device_info
= dri2_interop_query_device_info
,
1844 .export_object
= dri2_interop_export_object
1848 * \brief the DRI2ConfigQueryExtension configQueryb method
1851 dri2GalliumConfigQueryb(__DRIscreen
*sPriv
, const char *var
,
1854 struct dri_screen
*screen
= dri_screen(sPriv
);
1856 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_BOOL
))
1857 return dri2ConfigQueryExtension
.configQueryb(sPriv
, var
, val
);
1859 *val
= driQueryOptionb(&screen
->dev
->option_cache
, var
);
1865 * \brief the DRI2ConfigQueryExtension configQueryi method
1868 dri2GalliumConfigQueryi(__DRIscreen
*sPriv
, const char *var
, int *val
)
1870 struct dri_screen
*screen
= dri_screen(sPriv
);
1872 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_INT
) &&
1873 !driCheckOption(&screen
->dev
->option_cache
, var
, DRI_ENUM
))
1874 return dri2ConfigQueryExtension
.configQueryi(sPriv
, var
, val
);
1876 *val
= driQueryOptioni(&screen
->dev
->option_cache
, var
);
1882 * \brief the DRI2ConfigQueryExtension configQueryf method
1885 dri2GalliumConfigQueryf(__DRIscreen
*sPriv
, const char *var
, float *val
)
1887 struct dri_screen
*screen
= dri_screen(sPriv
);
1889 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_FLOAT
))
1890 return dri2ConfigQueryExtension
.configQueryf(sPriv
, var
, val
);
1892 *val
= driQueryOptionf(&screen
->dev
->option_cache
, var
);
1898 * \brief the DRI2ConfigQueryExtension struct.
1900 * We first query the driver option cache. Then the dri2 option cache.
1902 static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension
= {
1903 .base
= { __DRI2_CONFIG_QUERY
, 1 },
1905 .configQueryb
= dri2GalliumConfigQueryb
,
1906 .configQueryi
= dri2GalliumConfigQueryi
,
1907 .configQueryf
= dri2GalliumConfigQueryf
,
1911 * Backend function init_screen.
1914 static const __DRIextension
*dri_screen_extensions
[] = {
1915 &driTexBufferExtension
.base
,
1916 &dri2FlushExtension
.base
,
1917 &dri2ImageExtension
.base
,
1918 &dri2RendererQueryExtension
.base
,
1919 &dri2GalliumConfigQueryExtension
.base
,
1920 &dri2ThrottleExtension
.base
,
1921 &dri2FenceExtension
.base
,
1922 &dri2InteropExtension
.base
,
1923 &dri2NoErrorExtension
.base
,
1927 static const __DRIextension
*dri_robust_screen_extensions
[] = {
1928 &driTexBufferExtension
.base
,
1929 &dri2FlushExtension
.base
,
1930 &dri2ImageExtension
.base
,
1931 &dri2RendererQueryExtension
.base
,
1932 &dri2GalliumConfigQueryExtension
.base
,
1933 &dri2ThrottleExtension
.base
,
1934 &dri2FenceExtension
.base
,
1935 &dri2InteropExtension
.base
,
1936 &dri2Robustness
.base
,
1937 &dri2NoErrorExtension
.base
,
1942 * This is the driver specific part of the createNewScreen entry point.
1944 * Returns the struct gl_config supported by this driver.
1946 static const __DRIconfig
**
1947 dri2_init_screen(__DRIscreen
* sPriv
)
1949 const __DRIconfig
**configs
;
1950 struct dri_screen
*screen
;
1951 struct pipe_screen
*pscreen
= NULL
;
1952 const struct drm_conf_ret
*throttle_ret
;
1953 const struct drm_conf_ret
*dmabuf_ret
;
1956 screen
= CALLOC_STRUCT(dri_screen
);
1960 screen
->sPriv
= sPriv
;
1961 screen
->fd
= sPriv
->fd
;
1962 (void) mtx_init(&screen
->opencl_func_mutex
, mtx_plain
);
1964 sPriv
->driverPrivate
= (void *)screen
;
1966 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
1970 if (pipe_loader_drm_probe_fd(&screen
->dev
, fd
)) {
1971 dri_init_options(screen
);
1973 pscreen
= pipe_loader_create_screen(screen
->dev
);
1979 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
1980 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
1982 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
1983 screen
->throttling_enabled
= TRUE
;
1984 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
1987 if (pscreen
->resource_create_with_modifiers
)
1988 dri2ImageExtension
.createImageWithModifiers
=
1989 dri2_create_image_with_modifiers
;
1991 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
1994 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1995 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1996 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1997 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1998 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
1999 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2000 dri2ImageExtension
.queryDmaBufModifiers
=
2001 dri2_query_dma_buf_modifiers
;
2005 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
2006 sPriv
->extensions
= dri_robust_screen_extensions
;
2007 screen
->has_reset_status_query
= true;
2010 sPriv
->extensions
= dri_screen_extensions
;
2012 configs
= dri_init_screen_helper(screen
, pscreen
);
2014 goto destroy_screen
;
2016 screen
->can_share_buffer
= true;
2017 screen
->auto_fake_front
= dri_with_format(sPriv
);
2018 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2019 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2024 dri_destroy_screen_helper(screen
);
2028 pipe_loader_release(&screen
->dev
, 1);
2038 * This is the driver specific part of the createNewScreen entry point.
2040 * Returns the struct gl_config supported by this driver.
2042 static const __DRIconfig
**
2043 dri_kms_init_screen(__DRIscreen
* sPriv
)
2045 #if defined(GALLIUM_SOFTPIPE)
2046 const __DRIconfig
**configs
;
2047 struct dri_screen
*screen
;
2048 struct pipe_screen
*pscreen
= NULL
;
2052 screen
= CALLOC_STRUCT(dri_screen
);
2056 screen
->sPriv
= sPriv
;
2057 screen
->fd
= sPriv
->fd
;
2059 sPriv
->driverPrivate
= (void *)screen
;
2061 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
2064 if (pipe_loader_sw_probe_kms(&screen
->dev
, fd
)) {
2065 dri_init_options(screen
);
2066 pscreen
= pipe_loader_create_screen(screen
->dev
);
2072 if (pscreen
->resource_create_with_modifiers
)
2073 dri2ImageExtension
.createImageWithModifiers
=
2074 dri2_create_image_with_modifiers
;
2076 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2077 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2078 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2079 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2080 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2081 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2082 dri2ImageExtension
.queryDmaBufModifiers
= dri2_query_dma_buf_modifiers
;
2085 sPriv
->extensions
= dri_screen_extensions
;
2087 configs
= dri_init_screen_helper(screen
, pscreen
);
2089 goto destroy_screen
;
2091 screen
->can_share_buffer
= false;
2092 screen
->auto_fake_front
= dri_with_format(sPriv
);
2093 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2094 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2099 dri_destroy_screen_helper(screen
);
2103 pipe_loader_release(&screen
->dev
, 1);
2109 #endif // GALLIUM_SOFTPIPE
2114 dri2_create_buffer(__DRIscreen
* sPriv
,
2115 __DRIdrawable
* dPriv
,
2116 const struct gl_config
* visual
, boolean isPixmap
)
2118 struct dri_drawable
*drawable
= NULL
;
2120 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
2123 drawable
= dPriv
->driverPrivate
;
2125 drawable
->allocate_textures
= dri2_allocate_textures
;
2126 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
2127 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
2128 drawable
->flush_swapbuffers
= dri2_flush_swapbuffers
;
2134 * DRI driver virtual function table.
2136 * DRI versions differ in their implementation of init_screen and swap_buffers.
2138 const struct __DriverAPIRec galliumdrm_driver_api
= {
2139 .InitScreen
= dri2_init_screen
,
2140 .DestroyScreen
= dri_destroy_screen
,
2141 .CreateContext
= dri_create_context
,
2142 .DestroyContext
= dri_destroy_context
,
2143 .CreateBuffer
= dri2_create_buffer
,
2144 .DestroyBuffer
= dri_destroy_buffer
,
2145 .MakeCurrent
= dri_make_current
,
2146 .UnbindContext
= dri_unbind_context
,
2148 .AllocateBuffer
= dri2_allocate_buffer
,
2149 .ReleaseBuffer
= dri2_release_buffer
,
2153 * DRI driver virtual function table.
2155 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
2156 * hook. The latter is used to explicitly initialise the kms_swrast driver
2157 * rather than selecting the approapriate driver as suggested by the loader.
2159 const struct __DriverAPIRec dri_kms_driver_api
= {
2160 .InitScreen
= dri_kms_init_screen
,
2161 .DestroyScreen
= dri_destroy_screen
,
2162 .CreateContext
= dri_create_context
,
2163 .DestroyContext
= dri_destroy_context
,
2164 .CreateBuffer
= dri2_create_buffer
,
2165 .DestroyBuffer
= dri_destroy_buffer
,
2166 .MakeCurrent
= dri_make_current
,
2167 .UnbindContext
= dri_unbind_context
,
2169 .AllocateBuffer
= dri2_allocate_buffer
,
2170 .ReleaseBuffer
= dri2_release_buffer
,
2173 /* This is the table of extensions that the loader will dlsym() for. */
2174 const __DRIextension
*galliumdrm_driver_extensions
[] = {
2175 &driCoreExtension
.base
,
2176 &driImageDriverExtension
.base
,
2177 &driDRI2Extension
.base
,
2178 &gallium_config_options
.base
,
2182 /* vim: set sw=3 ts=8 sts=3 expandtab: */