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
;
116 case __DRI_IMAGE_FOURCC_R16
:
117 format
= __DRI_IMAGE_FORMAT_R16
;
118 dri_components
= __DRI_IMAGE_COMPONENTS_R
;
120 case __DRI_IMAGE_FOURCC_GR1616
:
121 format
= __DRI_IMAGE_FORMAT_GR1616
;
122 dri_components
= __DRI_IMAGE_COMPONENTS_RG
;
124 case __DRI_IMAGE_FOURCC_YUYV
:
125 format
= __DRI_IMAGE_FORMAT_YUYV
;
126 dri_components
= __DRI_IMAGE_COMPONENTS_Y_XUXV
;
129 * For multi-planar YUV formats, we return the format of the first
130 * plane only. Since there is only one caller which supports multi-
131 * planar YUV it gets to figure out the remaining planes on it's
134 case __DRI_IMAGE_FOURCC_YUV420
:
135 case __DRI_IMAGE_FOURCC_YVU420
:
136 format
= __DRI_IMAGE_FORMAT_R8
;
137 dri_components
= __DRI_IMAGE_COMPONENTS_Y_U_V
;
139 case __DRI_IMAGE_FOURCC_NV12
:
140 format
= __DRI_IMAGE_FORMAT_R8
;
141 dri_components
= __DRI_IMAGE_COMPONENTS_Y_UV
;
146 *dri_components_p
= dri_components
;
150 /* NOTE this probably isn't going to do the right thing for YUV images
151 * (but I think the same can be said for intel_query_image()). I think
152 * only needed for exporting dmabuf's, so I think I won't loose much
155 static int convert_to_fourcc(int format
)
158 case __DRI_IMAGE_FORMAT_RGB565
:
159 format
= __DRI_IMAGE_FOURCC_RGB565
;
161 case __DRI_IMAGE_FORMAT_ARGB8888
:
162 format
= __DRI_IMAGE_FOURCC_ARGB8888
;
164 case __DRI_IMAGE_FORMAT_XRGB8888
:
165 format
= __DRI_IMAGE_FOURCC_XRGB8888
;
167 case __DRI_IMAGE_FORMAT_ABGR8888
:
168 format
= __DRI_IMAGE_FOURCC_ABGR8888
;
170 case __DRI_IMAGE_FORMAT_XBGR8888
:
171 format
= __DRI_IMAGE_FOURCC_XBGR8888
;
173 case __DRI_IMAGE_FORMAT_R8
:
174 format
= __DRI_IMAGE_FOURCC_R8
;
176 case __DRI_IMAGE_FORMAT_GR88
:
177 format
= __DRI_IMAGE_FOURCC_GR88
;
185 static enum pipe_format
dri2_format_to_pipe_format (int format
)
190 case __DRI_IMAGE_FORMAT_RGB565
:
191 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
193 case __DRI_IMAGE_FORMAT_XRGB8888
:
194 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
196 case __DRI_IMAGE_FORMAT_ARGB8888
:
197 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
199 case __DRI_IMAGE_FORMAT_XBGR8888
:
200 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
202 case __DRI_IMAGE_FORMAT_ABGR8888
:
203 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
205 case __DRI_IMAGE_FORMAT_R8
:
206 pf
= PIPE_FORMAT_R8_UNORM
;
208 case __DRI_IMAGE_FORMAT_GR88
:
209 pf
= PIPE_FORMAT_RG88_UNORM
;
211 case __DRI_IMAGE_FORMAT_R16
:
212 pf
= PIPE_FORMAT_R16_UNORM
;
214 case __DRI_IMAGE_FORMAT_GR1616
:
215 pf
= PIPE_FORMAT_R16G16_UNORM
;
217 case __DRI_IMAGE_FORMAT_YUYV
:
218 pf
= PIPE_FORMAT_YUYV
;
221 pf
= PIPE_FORMAT_NONE
;
228 static enum pipe_format
fourcc_to_pipe_format(int fourcc
)
233 case __DRI_IMAGE_FOURCC_R8
:
234 pf
= PIPE_FORMAT_R8_UNORM
;
236 case __DRI_IMAGE_FOURCC_GR88
:
237 pf
= PIPE_FORMAT_RG88_UNORM
;
239 case __DRI_IMAGE_FOURCC_ARGB1555
:
240 pf
= PIPE_FORMAT_B5G5R5A1_UNORM
;
242 case __DRI_IMAGE_FOURCC_R16
:
243 pf
= PIPE_FORMAT_R16_UNORM
;
245 case __DRI_IMAGE_FOURCC_GR1616
:
246 pf
= PIPE_FORMAT_RG1616_UNORM
;
248 case __DRI_IMAGE_FOURCC_RGB565
:
249 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
251 case __DRI_IMAGE_FOURCC_ARGB8888
:
252 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
254 case __DRI_IMAGE_FOURCC_XRGB8888
:
255 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
257 case __DRI_IMAGE_FOURCC_ABGR8888
:
258 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
260 case __DRI_IMAGE_FOURCC_XBGR8888
:
261 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
264 case __DRI_IMAGE_FOURCC_NV12
:
265 pf
= PIPE_FORMAT_NV12
;
267 case __DRI_IMAGE_FOURCC_YUYV
:
268 pf
= PIPE_FORMAT_YUYV
;
270 case __DRI_IMAGE_FOURCC_YUV420
:
271 case __DRI_IMAGE_FOURCC_YVU420
:
272 pf
= PIPE_FORMAT_YV12
;
275 case __DRI_IMAGE_FOURCC_SARGB8888
:
276 case __DRI_IMAGE_FOURCC_YUV410
:
277 case __DRI_IMAGE_FOURCC_YUV411
:
278 case __DRI_IMAGE_FOURCC_YUV422
:
279 case __DRI_IMAGE_FOURCC_YUV444
:
280 case __DRI_IMAGE_FOURCC_NV16
:
281 case __DRI_IMAGE_FOURCC_YVU410
:
282 case __DRI_IMAGE_FOURCC_YVU411
:
283 case __DRI_IMAGE_FOURCC_YVU422
:
284 case __DRI_IMAGE_FOURCC_YVU444
:
286 pf
= PIPE_FORMAT_NONE
;
293 * DRI2 flush extension.
296 dri2_flush_drawable(__DRIdrawable
*dPriv
)
298 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
302 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
304 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
306 dri2InvalidateDrawable(dPriv
);
307 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
308 drawable
->texture_mask
= 0;
310 p_atomic_inc(&drawable
->base
.stamp
);
313 static const __DRI2flushExtension dri2FlushExtension
= {
314 .base
= { __DRI2_FLUSH
, 4 },
316 .flush
= dri2_flush_drawable
,
317 .invalidate
= dri2_invalidate_drawable
,
318 .flush_with_flags
= dri_flush
,
322 * Retrieve __DRIbuffer from the DRI loader.
325 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
326 const enum st_attachment_type
*atts
,
329 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
330 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
332 __DRIbuffer
*buffers
;
334 unsigned attachments
[10];
335 unsigned num_attachments
, i
;
338 with_format
= dri_with_format(drawable
->sPriv
);
342 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
344 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
346 for (i
= 0; i
< *count
; i
++) {
347 enum pipe_format format
;
351 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
352 if (format
== PIPE_FORMAT_NONE
)
356 case ST_ATTACHMENT_FRONT_LEFT
:
360 att
= __DRI_BUFFER_FRONT_LEFT
;
362 case ST_ATTACHMENT_BACK_LEFT
:
363 att
= __DRI_BUFFER_BACK_LEFT
;
365 case ST_ATTACHMENT_FRONT_RIGHT
:
366 att
= __DRI_BUFFER_FRONT_RIGHT
;
368 case ST_ATTACHMENT_BACK_RIGHT
:
369 att
= __DRI_BUFFER_BACK_RIGHT
;
376 * In this switch statement we must support all formats that
377 * may occur as the stvis->color_format.
380 case PIPE_FORMAT_BGRA8888_UNORM
:
381 case PIPE_FORMAT_RGBA8888_UNORM
:
384 case PIPE_FORMAT_BGRX8888_UNORM
:
385 case PIPE_FORMAT_RGBX8888_UNORM
:
388 case PIPE_FORMAT_B5G6R5_UNORM
:
392 depth
= util_format_get_blocksizebits(format
);
393 assert(!"Unexpected format in dri2_drawable_get_buffers()");
396 attachments
[num_attachments
++] = att
;
398 attachments
[num_attachments
++] = depth
;
403 num_attachments
/= 2;
404 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
405 &dri_drawable
->w
, &dri_drawable
->h
,
406 attachments
, num_attachments
,
407 &num_buffers
, dri_drawable
->loaderPrivate
);
410 buffers
= loader
->getBuffers(dri_drawable
,
411 &dri_drawable
->w
, &dri_drawable
->h
,
412 attachments
, num_attachments
,
413 &num_buffers
, dri_drawable
->loaderPrivate
);
417 *count
= num_buffers
;
423 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
424 struct __DRIimageList
*images
,
425 const enum st_attachment_type
*statts
,
426 unsigned statts_count
)
428 __DRIdrawable
*dPriv
= drawable
->dPriv
;
429 __DRIscreen
*sPriv
= drawable
->sPriv
;
430 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
432 uint32_t buffer_mask
= 0;
435 for (i
= 0; i
< statts_count
; i
++) {
436 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
437 if (pf
== PIPE_FORMAT_NONE
)
441 case ST_ATTACHMENT_FRONT_LEFT
:
442 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
444 case ST_ATTACHMENT_BACK_LEFT
:
445 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
452 case PIPE_FORMAT_B5G6R5_UNORM
:
453 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
455 case PIPE_FORMAT_BGRX8888_UNORM
:
456 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
458 case PIPE_FORMAT_BGRA8888_UNORM
:
459 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
461 case PIPE_FORMAT_RGBX8888_UNORM
:
462 image_format
= __DRI_IMAGE_FORMAT_XBGR8888
;
464 case PIPE_FORMAT_RGBA8888_UNORM
:
465 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
468 image_format
= __DRI_IMAGE_FORMAT_NONE
;
473 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
474 (uint32_t *) &drawable
->base
.stamp
,
475 dPriv
->loaderPrivate
, buffer_mask
,
480 dri2_allocate_buffer(__DRIscreen
*sPriv
,
481 unsigned attachment
, unsigned format
,
482 int width
, int height
)
484 struct dri_screen
*screen
= dri_screen(sPriv
);
485 struct dri2_buffer
*buffer
;
486 struct pipe_resource templ
;
489 struct winsys_handle whandle
;
491 switch (attachment
) {
492 case __DRI_BUFFER_FRONT_LEFT
:
493 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
494 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
496 case __DRI_BUFFER_BACK_LEFT
:
497 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
499 case __DRI_BUFFER_DEPTH
:
500 case __DRI_BUFFER_DEPTH_STENCIL
:
501 case __DRI_BUFFER_STENCIL
:
502 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
506 /* because we get the handle and stride */
507 bind
|= PIPE_BIND_SHARED
;
511 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
514 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
517 pf
= PIPE_FORMAT_Z16_UNORM
;
523 buffer
= CALLOC_STRUCT(dri2_buffer
);
527 memset(&templ
, 0, sizeof(templ
));
530 templ
.target
= PIPE_TEXTURE_2D
;
531 templ
.last_level
= 0;
532 templ
.width0
= width
;
533 templ
.height0
= height
;
535 templ
.array_size
= 1;
538 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
539 if (!buffer
->resource
) {
544 memset(&whandle
, 0, sizeof(whandle
));
545 if (screen
->can_share_buffer
)
546 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
548 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
550 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
, NULL
,
551 buffer
->resource
, &whandle
,
552 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
554 buffer
->base
.attachment
= attachment
;
555 buffer
->base
.name
= whandle
.handle
;
556 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
557 buffer
->base
.pitch
= whandle
.stride
;
559 return &buffer
->base
;
563 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
565 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
567 pipe_resource_reference(&buffer
->resource
, NULL
);
572 * Backend functions for st_framebuffer interface.
576 dri2_allocate_textures(struct dri_context
*ctx
,
577 struct dri_drawable
*drawable
,
578 const enum st_attachment_type
*statts
,
579 unsigned statts_count
)
581 __DRIscreen
*sPriv
= drawable
->sPriv
;
582 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
583 struct dri_screen
*screen
= dri_screen(sPriv
);
584 struct pipe_resource templ
;
585 boolean alloc_depthstencil
= FALSE
;
587 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
588 /* Image specific variables */
589 struct __DRIimageList images
;
590 /* Dri2 specific variables */
591 __DRIbuffer
*buffers
= NULL
;
592 struct winsys_handle whandle
;
593 unsigned num_buffers
= statts_count
;
595 /* First get the buffers from the loader */
597 if (!dri_image_drawable_get_buffers(drawable
, &images
,
598 statts
, statts_count
))
602 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
603 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
604 drawable
->old_w
== dri_drawable
->w
&&
605 drawable
->old_h
== dri_drawable
->h
&&
606 memcmp(drawable
->old
, buffers
,
607 sizeof(__DRIbuffer
) * num_buffers
) == 0))
611 /* Second clean useless resources*/
613 /* See if we need a depth-stencil buffer. */
614 for (i
= 0; i
< statts_count
; i
++) {
615 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
616 alloc_depthstencil
= TRUE
;
621 /* Delete the resources we won't need. */
622 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
623 /* Don't delete the depth-stencil buffer, we can reuse it. */
624 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
627 /* Flush the texture before unreferencing, so that other clients can
628 * see what the driver has rendered.
630 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
631 struct pipe_context
*pipe
= ctx
->st
->pipe
;
632 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
635 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
638 if (drawable
->stvis
.samples
> 1) {
639 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
642 /* Don't delete MSAA resources for the attachments which are enabled,
643 * we can reuse them. */
644 for (j
= 0; j
< statts_count
; j
++) {
645 if (i
== statts
[j
]) {
652 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
657 /* Third use the buffers retrieved to fill the drawable info */
659 memset(&templ
, 0, sizeof(templ
));
660 templ
.target
= screen
->target
;
661 templ
.last_level
= 0;
663 templ
.array_size
= 1;
666 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
667 struct pipe_resource
**buf
=
668 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
669 struct pipe_resource
*texture
= images
.front
->texture
;
671 dri_drawable
->w
= texture
->width0
;
672 dri_drawable
->h
= texture
->height0
;
674 pipe_resource_reference(buf
, texture
);
677 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
678 struct pipe_resource
**buf
=
679 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
680 struct pipe_resource
*texture
= images
.back
->texture
;
682 dri_drawable
->w
= texture
->width0
;
683 dri_drawable
->h
= texture
->height0
;
685 pipe_resource_reference(buf
, texture
);
688 /* Note: if there is both a back and a front buffer,
689 * then they have the same size.
691 templ
.width0
= dri_drawable
->w
;
692 templ
.height0
= dri_drawable
->h
;
695 memset(&whandle
, 0, sizeof(whandle
));
697 /* Process DRI-provided buffers and get pipe_resources. */
698 for (i
= 0; i
< num_buffers
; i
++) {
699 __DRIbuffer
*buf
= &buffers
[i
];
700 enum st_attachment_type statt
;
701 enum pipe_format format
;
703 switch (buf
->attachment
) {
704 case __DRI_BUFFER_FRONT_LEFT
:
705 if (!screen
->auto_fake_front
) {
706 continue; /* invalid attachment */
709 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
710 statt
= ST_ATTACHMENT_FRONT_LEFT
;
712 case __DRI_BUFFER_BACK_LEFT
:
713 statt
= ST_ATTACHMENT_BACK_LEFT
;
716 continue; /* invalid attachment */
719 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
720 if (format
== PIPE_FORMAT_NONE
)
723 /* dri2_drawable_get_buffers has already filled dri_drawable->w
724 * and dri_drawable->h */
725 templ
.width0
= dri_drawable
->w
;
726 templ
.height0
= dri_drawable
->h
;
727 templ
.format
= format
;
729 whandle
.handle
= buf
->name
;
730 whandle
.stride
= buf
->pitch
;
732 if (screen
->can_share_buffer
)
733 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
735 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
736 drawable
->textures
[statt
] =
737 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
739 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
740 assert(drawable
->textures
[statt
]);
744 /* Allocate private MSAA colorbuffers. */
745 if (drawable
->stvis
.samples
> 1) {
746 for (i
= 0; i
< statts_count
; i
++) {
747 enum st_attachment_type statt
= statts
[i
];
749 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
752 if (drawable
->textures
[statt
]) {
753 templ
.format
= drawable
->textures
[statt
]->format
;
754 templ
.bind
= drawable
->textures
[statt
]->bind
&
755 ~(PIPE_BIND_SCANOUT
| PIPE_BIND_SHARED
);
756 templ
.nr_samples
= drawable
->stvis
.samples
;
758 /* Try to reuse the resource.
759 * (the other resource parameters should be constant)
761 if (!drawable
->msaa_textures
[statt
] ||
762 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
763 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
764 /* Allocate a new one. */
765 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
767 drawable
->msaa_textures
[statt
] =
768 screen
->base
.screen
->resource_create(screen
->base
.screen
,
770 assert(drawable
->msaa_textures
[statt
]);
772 /* If there are any MSAA resources, we should initialize them
773 * such that they contain the same data as the single-sample
774 * resources we just got from the X server.
776 * The reason for this is that the state tracker (and
777 * therefore the app) can access the MSAA resources only.
778 * The single-sample resources are not exposed
779 * to the state tracker.
782 dri_pipe_blit(ctx
->st
->pipe
,
783 drawable
->msaa_textures
[statt
],
784 drawable
->textures
[statt
]);
788 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
793 /* Allocate a private depth-stencil buffer. */
794 if (alloc_depthstencil
) {
795 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
796 struct pipe_resource
**zsbuf
;
797 enum pipe_format format
;
800 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
803 templ
.format
= format
;
804 templ
.bind
= bind
& ~PIPE_BIND_SHARED
;
806 if (drawable
->stvis
.samples
> 1) {
807 templ
.nr_samples
= drawable
->stvis
.samples
;
808 zsbuf
= &drawable
->msaa_textures
[statt
];
811 templ
.nr_samples
= 0;
812 zsbuf
= &drawable
->textures
[statt
];
815 /* Try to reuse the resource.
816 * (the other resource parameters should be constant)
819 (*zsbuf
)->width0
!= templ
.width0
||
820 (*zsbuf
)->height0
!= templ
.height0
) {
821 /* Allocate a new one. */
822 pipe_resource_reference(zsbuf
, NULL
);
823 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
829 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
830 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
834 /* For DRI2, we may get the same buffers again from the server.
835 * To prevent useless imports of gem names, drawable->old* is used
836 * to bypass the import if we get the same buffers. This doesn't apply
837 * to DRI3/Wayland, users of image.loader, since the buffer is managed
838 * by the client (no import), and the back buffer is going to change
842 drawable
->old_num
= num_buffers
;
843 drawable
->old_w
= dri_drawable
->w
;
844 drawable
->old_h
= dri_drawable
->h
;
845 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
850 dri2_flush_frontbuffer(struct dri_context
*ctx
,
851 struct dri_drawable
*drawable
,
852 enum st_attachment_type statt
)
854 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
855 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
856 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
857 struct pipe_context
*pipe
= ctx
->st
->pipe
;
859 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
862 if (drawable
->stvis
.samples
> 1) {
863 /* Resolve the front buffer. */
864 dri_pipe_blit(ctx
->st
->pipe
,
865 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
866 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
869 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
870 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
873 pipe
->flush(pipe
, NULL
, 0);
876 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
878 else if (loader
->flushFrontBuffer
) {
879 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
884 * The struct dri_drawable flush_swapbuffers callback
887 dri2_flush_swapbuffers(struct dri_context
*ctx
,
888 struct dri_drawable
*drawable
)
890 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
891 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
893 if (image
&& image
->base
.version
>= 3 && image
->flushSwapBuffers
) {
894 image
->flushSwapBuffers(dri_drawable
, dri_drawable
->loaderPrivate
);
899 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
900 struct dri_context
*ctx
,
901 struct pipe_resource
*res
)
907 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
908 int width
, int height
, int format
,
909 int num_handles
, struct winsys_handle
*whandle
,
912 struct dri_screen
*screen
= dri_screen(_screen
);
913 struct pipe_screen
*pscreen
= screen
->base
.screen
;
915 struct pipe_resource templ
;
920 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
922 pf
= dri2_format_to_pipe_format (format
);
923 if (pf
== PIPE_FORMAT_NONE
)
926 img
= CALLOC_STRUCT(__DRIimageRec
);
930 memset(&templ
, 0, sizeof(templ
));
931 templ
.bind
= tex_usage
;
932 templ
.target
= screen
->target
;
933 templ
.last_level
= 0;
935 templ
.array_size
= 1;
937 for (i
= num_handles
- 1; i
>= 0; i
--) {
938 struct pipe_resource
*tex
;
940 /* TODO: something a lot less ugly */
943 templ
.width0
= width
;
944 templ
.height0
= height
;
948 templ
.width0
= width
/ 2;
949 templ
.height0
= height
/ 2;
950 templ
.format
= (num_handles
== 2) ?
951 PIPE_FORMAT_RG88_UNORM
: /* NV12, etc */
952 PIPE_FORMAT_R8_UNORM
; /* I420, etc */
955 templ
.width0
= width
/ 2;
956 templ
.height0
= height
/ 2;
957 templ
.format
= PIPE_FORMAT_R8_UNORM
;
960 unreachable("too many planes!");
963 tex
= pscreen
->resource_from_handle(pscreen
,
964 &templ
, &whandle
[i
], PIPE_HANDLE_USAGE_READ_WRITE
);
966 pipe_resource_reference(&img
->texture
, NULL
);
971 tex
->next
= img
->texture
;
977 img
->dri_format
= format
;
979 img
->loader_private
= loaderPrivate
;
985 dri2_create_image_from_name(__DRIscreen
*_screen
,
986 int width
, int height
, int format
,
987 int name
, int pitch
, void *loaderPrivate
)
989 struct winsys_handle whandle
;
992 memset(&whandle
, 0, sizeof(whandle
));
993 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
994 whandle
.handle
= name
;
995 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
997 pf
= dri2_format_to_pipe_format (format
);
998 if (pf
== PIPE_FORMAT_NONE
)
1001 whandle
.stride
= pitch
* util_format_get_blocksize(pf
);
1003 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
1004 1, &whandle
, loaderPrivate
);
1008 dri2_create_image_from_fd(__DRIscreen
*_screen
,
1009 int width
, int height
, int fourcc
,
1010 uint64_t modifier
, int *fds
, int num_fds
,
1011 int *strides
, int *offsets
, unsigned *error
,
1012 int *dri_components
, void *loaderPrivate
)
1014 struct winsys_handle whandles
[3];
1016 __DRIimage
*img
= NULL
;
1017 unsigned err
= __DRI_IMAGE_ERROR_SUCCESS
;
1018 int expected_num_fds
, i
;
1021 case __DRI_IMAGE_FOURCC_YUV420
:
1022 case __DRI_IMAGE_FOURCC_YVU420
:
1023 expected_num_fds
= 3;
1025 case __DRI_IMAGE_FOURCC_NV12
:
1026 expected_num_fds
= 2;
1029 expected_num_fds
= 1;
1033 if (num_fds
!= expected_num_fds
) {
1034 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1038 format
= convert_fourcc(fourcc
, dri_components
);
1040 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1044 memset(whandles
, 0, sizeof(whandles
));
1046 for (i
= 0; i
< num_fds
; i
++) {
1048 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1052 whandles
[i
].type
= DRM_API_HANDLE_TYPE_FD
;
1053 whandles
[i
].handle
= (unsigned)fds
[i
];
1054 whandles
[i
].stride
= (unsigned)strides
[i
];
1055 whandles
[i
].offset
= (unsigned)offsets
[i
];
1056 whandles
[i
].modifier
= modifier
;
1059 if (fourcc
== __DRI_IMAGE_FOURCC_YVU420
) {
1060 /* convert to YUV420 by swapping 2nd and 3rd planes: */
1061 struct winsys_handle tmp
= whandles
[1];
1062 whandles
[1] = whandles
[2];
1064 fourcc
= __DRI_IMAGE_FOURCC_YUV420
;
1067 img
= dri2_create_image_from_winsys(_screen
, width
, height
, format
,
1068 num_fds
, whandles
, loaderPrivate
);
1070 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1080 dri2_create_image_common(__DRIscreen
*_screen
,
1081 int width
, int height
,
1082 int format
, unsigned int use
,
1083 const uint64_t *modifiers
,
1084 const unsigned count
,
1085 void *loaderPrivate
)
1087 struct dri_screen
*screen
= dri_screen(_screen
);
1089 struct pipe_resource templ
;
1091 enum pipe_format pf
;
1093 /* createImageWithModifiers doesn't supply usage, and we should not get
1094 * here with both modifiers and a usage flag.
1096 assert(!(use
&& (modifiers
!= NULL
)));
1098 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1100 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1101 tex_usage
|= PIPE_BIND_SCANOUT
;
1102 if (use
& __DRI_IMAGE_USE_SHARE
)
1103 tex_usage
|= PIPE_BIND_SHARED
;
1104 if (use
& __DRI_IMAGE_USE_LINEAR
)
1105 tex_usage
|= PIPE_BIND_LINEAR
;
1106 if (use
& __DRI_IMAGE_USE_CURSOR
) {
1107 if (width
!= 64 || height
!= 64)
1109 tex_usage
|= PIPE_BIND_CURSOR
;
1112 pf
= dri2_format_to_pipe_format (format
);
1113 if (pf
== PIPE_FORMAT_NONE
)
1116 img
= CALLOC_STRUCT(__DRIimageRec
);
1120 memset(&templ
, 0, sizeof(templ
));
1121 templ
.bind
= tex_usage
;
1123 templ
.target
= PIPE_TEXTURE_2D
;
1124 templ
.last_level
= 0;
1125 templ
.width0
= width
;
1126 templ
.height0
= height
;
1128 templ
.array_size
= 1;
1133 ->resource_create_with_modifiers(screen
->base
.screen
,
1139 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
1140 if (!img
->texture
) {
1147 img
->dri_format
= format
;
1148 img
->dri_components
= 0;
1151 img
->loader_private
= loaderPrivate
;
1156 dri2_create_image(__DRIscreen
*_screen
,
1157 int width
, int height
, int format
,
1158 unsigned int use
, void *loaderPrivate
)
1160 return dri2_create_image_common(_screen
, width
, height
, format
, use
,
1161 NULL
/* modifiers */, 0 /* count */,
1166 dri2_create_image_with_modifiers(__DRIscreen
*dri_screen
,
1167 int width
, int height
, int format
,
1168 const uint64_t *modifiers
,
1169 const unsigned count
,
1170 void *loaderPrivate
)
1172 return dri2_create_image_common(dri_screen
, width
, height
, format
,
1173 0 /* use */, modifiers
, count
,
1178 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
1180 struct winsys_handle whandle
;
1183 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1184 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
;
1186 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1188 memset(&whandle
, 0, sizeof(whandle
));
1191 case __DRI_IMAGE_ATTRIB_STRIDE
:
1192 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1193 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1194 NULL
, image
->texture
, &whandle
, usage
))
1196 *value
= whandle
.stride
;
1198 case __DRI_IMAGE_ATTRIB_OFFSET
:
1199 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1200 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1201 NULL
, image
->texture
, &whandle
, usage
))
1203 *value
= whandle
.offset
;
1205 case __DRI_IMAGE_ATTRIB_HANDLE
:
1206 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1207 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1208 NULL
, image
->texture
, &whandle
, usage
))
1210 *value
= whandle
.handle
;
1212 case __DRI_IMAGE_ATTRIB_NAME
:
1213 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
1214 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1215 NULL
, image
->texture
, &whandle
, usage
))
1217 *value
= whandle
.handle
;
1219 case __DRI_IMAGE_ATTRIB_FD
:
1220 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1221 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1222 NULL
, image
->texture
, &whandle
, usage
))
1225 *value
= whandle
.handle
;
1227 case __DRI_IMAGE_ATTRIB_FORMAT
:
1228 *value
= image
->dri_format
;
1230 case __DRI_IMAGE_ATTRIB_WIDTH
:
1231 *value
= image
->texture
->width0
;
1233 case __DRI_IMAGE_ATTRIB_HEIGHT
:
1234 *value
= image
->texture
->height0
;
1236 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
1237 if (image
->dri_components
== 0)
1239 *value
= image
->dri_components
;
1241 case __DRI_IMAGE_ATTRIB_FOURCC
:
1242 *value
= convert_to_fourcc(image
->dri_format
);
1244 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1247 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1248 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1249 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1250 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1251 NULL
, image
->texture
, &whandle
, usage
))
1253 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1255 *value
= (whandle
.modifier
>> 32) & 0xffffffff;
1257 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1258 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1259 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1260 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1261 NULL
, image
->texture
, &whandle
, usage
))
1263 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1265 *value
= whandle
.modifier
& 0xffffffff;
1273 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
1277 img
= CALLOC_STRUCT(__DRIimageRec
);
1281 img
->texture
= NULL
;
1282 pipe_resource_reference(&img
->texture
, image
->texture
);
1283 img
->level
= image
->level
;
1284 img
->layer
= image
->layer
;
1285 img
->dri_format
= image
->dri_format
;
1286 /* This should be 0 for sub images, but dup is also used for base images. */
1287 img
->dri_components
= image
->dri_components
;
1288 img
->loader_private
= loaderPrivate
;
1294 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
1296 if (!image
|| !image
->texture
)
1299 struct pipe_screen
*screen
= image
->texture
->screen
;
1300 if (!screen
->check_resource_capability
)
1303 /* We don't want to check these:
1304 * __DRI_IMAGE_USE_SHARE (all images are shareable)
1305 * __DRI_IMAGE_USE_BACKBUFFER (all images support this)
1308 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1309 bind
|= PIPE_BIND_SCANOUT
;
1310 if (use
& __DRI_IMAGE_USE_LINEAR
)
1311 bind
|= PIPE_BIND_LINEAR
;
1312 if (use
& __DRI_IMAGE_USE_CURSOR
)
1313 bind
|= PIPE_BIND_CURSOR
;
1318 return screen
->check_resource_capability(screen
, image
->texture
, bind
);
1322 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
1323 int *names
, int num_names
, int *strides
, int *offsets
,
1324 void *loaderPrivate
)
1328 struct winsys_handle whandle
;
1333 format
= convert_fourcc(format
, &dri_components
);
1337 memset(&whandle
, 0, sizeof(whandle
));
1338 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
1339 whandle
.handle
= names
[0];
1340 whandle
.stride
= strides
[0];
1341 whandle
.offset
= offsets
[0];
1342 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1344 img
= dri2_create_image_from_winsys(screen
, width
, height
, format
,
1345 1, &whandle
, loaderPrivate
);
1349 img
->dri_components
= dri_components
;
1354 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1361 if (image
->dri_components
== 0)
1364 img
= dri2_dup_image(image
, loaderPrivate
);
1368 if (img
->texture
->screen
->resource_changed
)
1369 img
->texture
->screen
->resource_changed(img
->texture
->screen
,
1372 /* set this to 0 for sub images. */
1373 img
->dri_components
= 0;
1378 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1379 int *fds
, int num_fds
, int *strides
, int *offsets
,
1380 void *loaderPrivate
)
1385 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1386 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1387 strides
, offsets
, NULL
,
1388 &dri_components
, loaderPrivate
);
1392 img
->dri_components
= dri_components
;
1397 dri2_query_dma_buf_formats(__DRIscreen
*_screen
, int max
, int *formats
,
1400 struct dri_screen
*screen
= dri_screen(_screen
);
1401 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1402 const unsigned bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1405 for (i
= 0, j
= 0; (i
< ARRAY_SIZE(fourcc_formats
)) &&
1406 (j
< max
|| max
== 0); i
++) {
1407 if (pscreen
->is_format_supported(pscreen
,
1408 fourcc_to_pipe_format(
1413 formats
[j
] = fourcc_formats
[i
];
1422 dri2_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1423 uint64_t *modifiers
, unsigned int *external_only
,
1426 struct dri_screen
*screen
= dri_screen(_screen
);
1427 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1428 enum pipe_format format
= fourcc_to_pipe_format(fourcc
);
1429 const unsigned usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1431 if (pscreen
->query_dmabuf_modifiers
!= NULL
&&
1432 pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, usage
)) {
1433 pscreen
->query_dmabuf_modifiers(pscreen
, format
, max
, modifiers
,
1434 external_only
, count
);
1441 dri2_from_dma_bufs(__DRIscreen
*screen
,
1442 int width
, int height
, int fourcc
,
1443 int *fds
, int num_fds
,
1444 int *strides
, int *offsets
,
1445 enum __DRIYUVColorSpace yuv_color_space
,
1446 enum __DRISampleRange sample_range
,
1447 enum __DRIChromaSiting horizontal_siting
,
1448 enum __DRIChromaSiting vertical_siting
,
1450 void *loaderPrivate
)
1455 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1456 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1457 strides
, offsets
, error
,
1458 &dri_components
, loaderPrivate
);
1462 img
->yuv_color_space
= yuv_color_space
;
1463 img
->sample_range
= sample_range
;
1464 img
->horizontal_siting
= horizontal_siting
;
1465 img
->vertical_siting
= vertical_siting
;
1466 img
->dri_components
= dri_components
;
1468 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1473 dri2_from_dma_bufs2(__DRIscreen
*screen
,
1474 int width
, int height
, int fourcc
,
1475 uint64_t modifier
, int *fds
, int num_fds
,
1476 int *strides
, int *offsets
,
1477 enum __DRIYUVColorSpace yuv_color_space
,
1478 enum __DRISampleRange sample_range
,
1479 enum __DRIChromaSiting horizontal_siting
,
1480 enum __DRIChromaSiting vertical_siting
,
1482 void *loaderPrivate
)
1487 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1488 modifier
, fds
, num_fds
, strides
, offsets
,
1489 error
, &dri_components
, loaderPrivate
);
1493 img
->yuv_color_space
= yuv_color_space
;
1494 img
->sample_range
= sample_range
;
1495 img
->horizontal_siting
= horizontal_siting
;
1496 img
->vertical_siting
= vertical_siting
;
1497 img
->dri_components
= dri_components
;
1499 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1504 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1505 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1506 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1509 struct dri_context
*ctx
= dri_context(context
);
1510 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1511 struct pipe_screen
*screen
;
1512 struct pipe_fence_handle
*fence
;
1513 struct pipe_blit_info blit
;
1518 memset(&blit
, 0, sizeof(blit
));
1519 blit
.dst
.resource
= dst
->texture
;
1520 blit
.dst
.box
.x
= dstx0
;
1521 blit
.dst
.box
.y
= dsty0
;
1522 blit
.dst
.box
.width
= dstwidth
;
1523 blit
.dst
.box
.height
= dstheight
;
1524 blit
.dst
.box
.depth
= 1;
1525 blit
.dst
.format
= dst
->texture
->format
;
1526 blit
.src
.resource
= src
->texture
;
1527 blit
.src
.box
.x
= srcx0
;
1528 blit
.src
.box
.y
= srcy0
;
1529 blit
.src
.box
.width
= srcwidth
;
1530 blit
.src
.box
.height
= srcheight
;
1531 blit
.src
.box
.depth
= 1;
1532 blit
.src
.format
= src
->texture
->format
;
1533 blit
.mask
= PIPE_MASK_RGBA
;
1534 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1536 pipe
->blit(pipe
, &blit
);
1538 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1539 pipe
->flush_resource(pipe
, dst
->texture
);
1540 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1541 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1542 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1543 pipe
->flush_resource(pipe
, dst
->texture
);
1544 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1545 (void) screen
->fence_finish(screen
, NULL
, fence
, PIPE_TIMEOUT_INFINITE
);
1546 screen
->fence_reference(screen
, &fence
, NULL
);
1551 dri2_map_image(__DRIcontext
*context
, __DRIimage
*image
,
1552 int x0
, int y0
, int width
, int height
,
1553 unsigned int flags
, int *stride
, void **data
)
1555 struct dri_context
*ctx
= dri_context(context
);
1556 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1557 enum pipe_transfer_usage pipe_access
= 0;
1558 struct pipe_transfer
*trans
;
1561 if (!image
|| !data
|| *data
)
1564 if (flags
& __DRI_IMAGE_TRANSFER_READ
)
1565 pipe_access
|= PIPE_TRANSFER_READ
;
1566 if (flags
& __DRI_IMAGE_TRANSFER_WRITE
)
1567 pipe_access
|= PIPE_TRANSFER_WRITE
;
1569 map
= pipe_transfer_map(pipe
, image
->texture
,
1570 0, 0, pipe_access
, x0
, y0
, width
, height
,
1574 *stride
= trans
->stride
;
1581 dri2_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *data
)
1583 struct dri_context
*ctx
= dri_context(context
);
1584 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1586 pipe_transfer_unmap(pipe
, (struct pipe_transfer
*)data
);
1590 dri2_get_capabilities(__DRIscreen
*_screen
)
1592 struct dri_screen
*screen
= dri_screen(_screen
);
1594 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1597 /* The extension is modified during runtime if DRI_PRIME is detected */
1598 static __DRIimageExtension dri2ImageExtension
= {
1599 .base
= { __DRI_IMAGE
, 17 },
1601 .createImageFromName
= dri2_create_image_from_name
,
1602 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1603 .destroyImage
= dri2_destroy_image
,
1604 .createImage
= dri2_create_image
,
1605 .queryImage
= dri2_query_image
,
1606 .dupImage
= dri2_dup_image
,
1607 .validateUsage
= dri2_validate_usage
,
1608 .createImageFromNames
= dri2_from_names
,
1609 .fromPlanar
= dri2_from_planar
,
1610 .createImageFromTexture
= dri2_create_from_texture
,
1611 .createImageFromFds
= NULL
,
1612 .createImageFromDmaBufs
= NULL
,
1613 .blitImage
= dri2_blit_image
,
1614 .getCapabilities
= dri2_get_capabilities
,
1615 .mapImage
= dri2_map_image
,
1616 .unmapImage
= dri2_unmap_image
,
1617 .createImageWithModifiers
= NULL
,
1618 .createImageFromDmaBufs2
= NULL
,
1619 .queryDmaBufFormats
= NULL
,
1620 .queryDmaBufModifiers
= NULL
,
1621 .queryDmaBufFormatModifierAttribs
= NULL
,
1622 .createImageFromRenderbuffer2
= dri2_create_image_from_renderbuffer2
,
1625 static const __DRIrobustnessExtension dri2Robustness
= {
1626 .base
= { __DRI2_ROBUSTNESS
, 1 }
1630 dri2_interop_query_device_info(__DRIcontext
*_ctx
,
1631 struct mesa_glinterop_device_info
*out
)
1633 struct pipe_screen
*screen
= dri_context(_ctx
)->st
->pipe
->screen
;
1635 /* There is no version 0, thus we do not support it */
1636 if (out
->version
== 0)
1637 return MESA_GLINTEROP_INVALID_VERSION
;
1639 out
->pci_segment_group
= screen
->get_param(screen
, PIPE_CAP_PCI_GROUP
);
1640 out
->pci_bus
= screen
->get_param(screen
, PIPE_CAP_PCI_BUS
);
1641 out
->pci_device
= screen
->get_param(screen
, PIPE_CAP_PCI_DEVICE
);
1642 out
->pci_function
= screen
->get_param(screen
, PIPE_CAP_PCI_FUNCTION
);
1644 out
->vendor_id
= screen
->get_param(screen
, PIPE_CAP_VENDOR_ID
);
1645 out
->device_id
= screen
->get_param(screen
, PIPE_CAP_DEVICE_ID
);
1647 /* Instruct the caller that we support up-to version one of the interface */
1650 return MESA_GLINTEROP_SUCCESS
;
1654 dri2_interop_export_object(__DRIcontext
*_ctx
,
1655 struct mesa_glinterop_export_in
*in
,
1656 struct mesa_glinterop_export_out
*out
)
1658 struct st_context_iface
*st
= dri_context(_ctx
)->st
;
1659 struct pipe_screen
*screen
= st
->pipe
->screen
;
1660 struct gl_context
*ctx
= ((struct st_context
*)st
)->ctx
;
1661 struct pipe_resource
*res
= NULL
;
1662 struct winsys_handle whandle
;
1663 unsigned target
, usage
;
1666 /* There is no version 0, thus we do not support it */
1667 if (in
->version
== 0 || out
->version
== 0)
1668 return MESA_GLINTEROP_INVALID_VERSION
;
1670 /* Validate the target. */
1671 switch (in
->target
) {
1672 case GL_TEXTURE_BUFFER
:
1676 case GL_TEXTURE_RECTANGLE
:
1677 case GL_TEXTURE_1D_ARRAY
:
1678 case GL_TEXTURE_2D_ARRAY
:
1679 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1680 case GL_TEXTURE_CUBE_MAP
:
1681 case GL_TEXTURE_2D_MULTISAMPLE
:
1682 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1683 case GL_TEXTURE_EXTERNAL_OES
:
1684 case GL_RENDERBUFFER
:
1685 case GL_ARRAY_BUFFER
:
1686 target
= in
->target
;
1688 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1690 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1694 target
= GL_TEXTURE_CUBE_MAP
;
1697 return MESA_GLINTEROP_INVALID_TARGET
;
1700 /* Validate the simple case of miplevel. */
1701 if ((target
== GL_RENDERBUFFER
|| target
== GL_ARRAY_BUFFER
) &&
1703 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1705 /* Validate the OpenGL object and get pipe_resource. */
1706 simple_mtx_lock(&ctx
->Shared
->Mutex
);
1708 if (target
== GL_ARRAY_BUFFER
) {
1711 * The error checking is based on the documentation of
1712 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1714 struct gl_buffer_object
*buf
= _mesa_lookup_bufferobj(ctx
, in
->obj
);
1716 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1717 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1718 * a GL buffer object but does not have an existing data store or
1719 * the size of the buffer is 0."
1721 if (!buf
|| buf
->Size
== 0) {
1722 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1723 return MESA_GLINTEROP_INVALID_OBJECT
;
1726 res
= st_buffer_object(buf
)->buffer
;
1728 /* this shouldn't happen */
1729 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1730 return MESA_GLINTEROP_INVALID_OBJECT
;
1733 out
->buf_offset
= 0;
1734 out
->buf_size
= buf
->Size
;
1736 buf
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1737 } else if (target
== GL_RENDERBUFFER
) {
1740 * The error checking is based on the documentation of
1741 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1743 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, in
->obj
);
1745 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1746 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1747 * object or if the width or height of renderbuffer is zero."
1749 if (!rb
|| rb
->Width
== 0 || rb
->Height
== 0) {
1750 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1751 return MESA_GLINTEROP_INVALID_OBJECT
;
1754 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1755 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1756 * renderbuffer object."
1758 if (rb
->NumSamples
> 1) {
1759 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1760 return MESA_GLINTEROP_INVALID_OPERATION
;
1763 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1764 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1765 * required by the OpenCL implementation on the device."
1767 res
= st_renderbuffer(rb
)->texture
;
1769 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1770 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1773 out
->internal_format
= rb
->InternalFormat
;
1774 out
->view_minlevel
= 0;
1775 out
->view_numlevels
= 1;
1776 out
->view_minlayer
= 0;
1777 out
->view_numlayers
= 1;
1781 * The error checking is based on the documentation of
1782 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1784 struct gl_texture_object
*obj
= _mesa_lookup_texture(ctx
, in
->obj
);
1787 _mesa_test_texobj_completeness(ctx
, obj
);
1789 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1790 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1791 * type matches texture_target, if the specified miplevel of texture
1792 * is not defined, or if the width or height of the specified
1793 * miplevel is zero or if the GL texture object is incomplete."
1796 obj
->Target
!= target
||
1797 !obj
->_BaseComplete
||
1798 (in
->miplevel
> 0 && !obj
->_MipmapComplete
)) {
1799 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1800 return MESA_GLINTEROP_INVALID_OBJECT
;
1803 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1804 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1805 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1806 * implementations); or greater than the value of q (for both OpenGL
1807 * and OpenGL ES). levelbase and q are defined for the texture in
1808 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1809 * specification and section 3.7.10 of the OpenGL ES 2.0."
1811 if (in
->miplevel
< obj
->BaseLevel
|| in
->miplevel
> obj
->_MaxLevel
) {
1812 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1813 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1816 if (!st_finalize_texture(ctx
, st
->pipe
, obj
, 0)) {
1817 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1818 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1821 res
= st_get_texobj_resource(obj
);
1823 /* Incomplete texture buffer object? This shouldn't really occur. */
1824 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1825 return MESA_GLINTEROP_INVALID_OBJECT
;
1828 if (target
== GL_TEXTURE_BUFFER
) {
1829 out
->internal_format
= obj
->BufferObjectFormat
;
1830 out
->buf_offset
= obj
->BufferOffset
;
1831 out
->buf_size
= obj
->BufferSize
== -1 ? obj
->BufferObject
->Size
:
1834 obj
->BufferObject
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1836 out
->internal_format
= obj
->Image
[0][0]->InternalFormat
;
1837 out
->view_minlevel
= obj
->MinLevel
;
1838 out
->view_numlevels
= obj
->NumLevels
;
1839 out
->view_minlayer
= obj
->MinLayer
;
1840 out
->view_numlayers
= obj
->NumLayers
;
1844 /* Get the handle. */
1845 switch (in
->access
) {
1846 case MESA_GLINTEROP_ACCESS_READ_WRITE
:
1847 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1849 case MESA_GLINTEROP_ACCESS_READ_ONLY
:
1850 usage
= PIPE_HANDLE_USAGE_READ
;
1852 case MESA_GLINTEROP_ACCESS_WRITE_ONLY
:
1853 usage
= PIPE_HANDLE_USAGE_WRITE
;
1859 memset(&whandle
, 0, sizeof(whandle
));
1860 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1862 success
= screen
->resource_get_handle(screen
, st
->pipe
, res
, &whandle
,
1864 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1867 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY
;
1869 out
->dmabuf_fd
= whandle
.handle
;
1870 out
->out_driver_data_written
= 0;
1872 if (res
->target
== PIPE_BUFFER
)
1873 out
->buf_offset
+= whandle
.offset
;
1875 /* Instruct the caller that we support up-to version one of the interface */
1879 return MESA_GLINTEROP_SUCCESS
;
1882 static const __DRI2interopExtension dri2InteropExtension
= {
1883 .base
= { __DRI2_INTEROP
, 1 },
1884 .query_device_info
= dri2_interop_query_device_info
,
1885 .export_object
= dri2_interop_export_object
1889 * \brief the DRI2ConfigQueryExtension configQueryb method
1892 dri2GalliumConfigQueryb(__DRIscreen
*sPriv
, const char *var
,
1895 struct dri_screen
*screen
= dri_screen(sPriv
);
1897 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_BOOL
))
1898 return dri2ConfigQueryExtension
.configQueryb(sPriv
, var
, val
);
1900 *val
= driQueryOptionb(&screen
->dev
->option_cache
, var
);
1906 * \brief the DRI2ConfigQueryExtension configQueryi method
1909 dri2GalliumConfigQueryi(__DRIscreen
*sPriv
, const char *var
, int *val
)
1911 struct dri_screen
*screen
= dri_screen(sPriv
);
1913 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_INT
) &&
1914 !driCheckOption(&screen
->dev
->option_cache
, var
, DRI_ENUM
))
1915 return dri2ConfigQueryExtension
.configQueryi(sPriv
, var
, val
);
1917 *val
= driQueryOptioni(&screen
->dev
->option_cache
, var
);
1923 * \brief the DRI2ConfigQueryExtension configQueryf method
1926 dri2GalliumConfigQueryf(__DRIscreen
*sPriv
, const char *var
, float *val
)
1928 struct dri_screen
*screen
= dri_screen(sPriv
);
1930 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_FLOAT
))
1931 return dri2ConfigQueryExtension
.configQueryf(sPriv
, var
, val
);
1933 *val
= driQueryOptionf(&screen
->dev
->option_cache
, var
);
1939 * \brief the DRI2ConfigQueryExtension struct.
1941 * We first query the driver option cache. Then the dri2 option cache.
1943 static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension
= {
1944 .base
= { __DRI2_CONFIG_QUERY
, 1 },
1946 .configQueryb
= dri2GalliumConfigQueryb
,
1947 .configQueryi
= dri2GalliumConfigQueryi
,
1948 .configQueryf
= dri2GalliumConfigQueryf
,
1952 * Backend function init_screen.
1955 static const __DRIextension
*dri_screen_extensions
[] = {
1956 &driTexBufferExtension
.base
,
1957 &dri2FlushExtension
.base
,
1958 &dri2ImageExtension
.base
,
1959 &dri2RendererQueryExtension
.base
,
1960 &dri2GalliumConfigQueryExtension
.base
,
1961 &dri2ThrottleExtension
.base
,
1962 &dri2FenceExtension
.base
,
1963 &dri2InteropExtension
.base
,
1964 &dri2NoErrorExtension
.base
,
1965 &dri2FlushControlExtension
.base
,
1969 static const __DRIextension
*dri_robust_screen_extensions
[] = {
1970 &driTexBufferExtension
.base
,
1971 &dri2FlushExtension
.base
,
1972 &dri2ImageExtension
.base
,
1973 &dri2RendererQueryExtension
.base
,
1974 &dri2GalliumConfigQueryExtension
.base
,
1975 &dri2ThrottleExtension
.base
,
1976 &dri2FenceExtension
.base
,
1977 &dri2InteropExtension
.base
,
1978 &dri2Robustness
.base
,
1979 &dri2NoErrorExtension
.base
,
1980 &dri2FlushControlExtension
.base
,
1985 * This is the driver specific part of the createNewScreen entry point.
1987 * Returns the struct gl_config supported by this driver.
1989 static const __DRIconfig
**
1990 dri2_init_screen(__DRIscreen
* sPriv
)
1992 const __DRIconfig
**configs
;
1993 struct dri_screen
*screen
;
1994 struct pipe_screen
*pscreen
= NULL
;
1995 const struct drm_conf_ret
*throttle_ret
;
1996 const struct drm_conf_ret
*dmabuf_ret
;
1999 screen
= CALLOC_STRUCT(dri_screen
);
2003 screen
->sPriv
= sPriv
;
2004 screen
->fd
= sPriv
->fd
;
2005 (void) mtx_init(&screen
->opencl_func_mutex
, mtx_plain
);
2007 sPriv
->driverPrivate
= (void *)screen
;
2009 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
2013 if (pipe_loader_drm_probe_fd(&screen
->dev
, fd
)) {
2014 dri_init_options(screen
);
2016 pscreen
= pipe_loader_create_screen(screen
->dev
);
2022 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
2023 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
2025 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
2026 screen
->throttling_enabled
= TRUE
;
2027 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
2030 if (pscreen
->resource_create_with_modifiers
)
2031 dri2ImageExtension
.createImageWithModifiers
=
2032 dri2_create_image_with_modifiers
;
2034 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
2037 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2038 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2039 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2040 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2041 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2042 if (pscreen
->query_dmabuf_modifiers
) {
2043 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2044 dri2ImageExtension
.queryDmaBufModifiers
=
2045 dri2_query_dma_buf_modifiers
;
2050 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
2051 sPriv
->extensions
= dri_robust_screen_extensions
;
2052 screen
->has_reset_status_query
= true;
2055 sPriv
->extensions
= dri_screen_extensions
;
2057 configs
= dri_init_screen_helper(screen
, pscreen
);
2059 goto destroy_screen
;
2061 screen
->can_share_buffer
= true;
2062 screen
->auto_fake_front
= dri_with_format(sPriv
);
2063 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2064 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2069 dri_destroy_screen_helper(screen
);
2073 pipe_loader_release(&screen
->dev
, 1);
2083 * This is the driver specific part of the createNewScreen entry point.
2085 * Returns the struct gl_config supported by this driver.
2087 static const __DRIconfig
**
2088 dri_kms_init_screen(__DRIscreen
* sPriv
)
2090 #if defined(GALLIUM_SOFTPIPE)
2091 const __DRIconfig
**configs
;
2092 struct dri_screen
*screen
;
2093 struct pipe_screen
*pscreen
= NULL
;
2097 screen
= CALLOC_STRUCT(dri_screen
);
2101 screen
->sPriv
= sPriv
;
2102 screen
->fd
= sPriv
->fd
;
2104 sPriv
->driverPrivate
= (void *)screen
;
2106 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
2109 if (pipe_loader_sw_probe_kms(&screen
->dev
, fd
)) {
2110 dri_init_options(screen
);
2111 pscreen
= pipe_loader_create_screen(screen
->dev
);
2117 if (pscreen
->resource_create_with_modifiers
)
2118 dri2ImageExtension
.createImageWithModifiers
=
2119 dri2_create_image_with_modifiers
;
2121 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2122 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2123 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2124 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2125 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2126 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2127 dri2ImageExtension
.queryDmaBufModifiers
= dri2_query_dma_buf_modifiers
;
2130 sPriv
->extensions
= dri_screen_extensions
;
2132 configs
= dri_init_screen_helper(screen
, pscreen
);
2134 goto destroy_screen
;
2136 screen
->can_share_buffer
= false;
2137 screen
->auto_fake_front
= dri_with_format(sPriv
);
2138 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2139 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2144 dri_destroy_screen_helper(screen
);
2148 pipe_loader_release(&screen
->dev
, 1);
2154 #endif // GALLIUM_SOFTPIPE
2159 dri2_create_buffer(__DRIscreen
* sPriv
,
2160 __DRIdrawable
* dPriv
,
2161 const struct gl_config
* visual
, boolean isPixmap
)
2163 struct dri_drawable
*drawable
= NULL
;
2165 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
2168 drawable
= dPriv
->driverPrivate
;
2170 drawable
->allocate_textures
= dri2_allocate_textures
;
2171 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
2172 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
2173 drawable
->flush_swapbuffers
= dri2_flush_swapbuffers
;
2179 * DRI driver virtual function table.
2181 * DRI versions differ in their implementation of init_screen and swap_buffers.
2183 const struct __DriverAPIRec galliumdrm_driver_api
= {
2184 .InitScreen
= dri2_init_screen
,
2185 .DestroyScreen
= dri_destroy_screen
,
2186 .CreateContext
= dri_create_context
,
2187 .DestroyContext
= dri_destroy_context
,
2188 .CreateBuffer
= dri2_create_buffer
,
2189 .DestroyBuffer
= dri_destroy_buffer
,
2190 .MakeCurrent
= dri_make_current
,
2191 .UnbindContext
= dri_unbind_context
,
2193 .AllocateBuffer
= dri2_allocate_buffer
,
2194 .ReleaseBuffer
= dri2_release_buffer
,
2198 * DRI driver virtual function table.
2200 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
2201 * hook. The latter is used to explicitly initialise the kms_swrast driver
2202 * rather than selecting the approapriate driver as suggested by the loader.
2204 const struct __DriverAPIRec dri_kms_driver_api
= {
2205 .InitScreen
= dri_kms_init_screen
,
2206 .DestroyScreen
= dri_destroy_screen
,
2207 .CreateContext
= dri_create_context
,
2208 .DestroyContext
= dri_destroy_context
,
2209 .CreateBuffer
= dri2_create_buffer
,
2210 .DestroyBuffer
= dri_destroy_buffer
,
2211 .MakeCurrent
= dri_make_current
,
2212 .UnbindContext
= dri_unbind_context
,
2214 .AllocateBuffer
= dri2_allocate_buffer
,
2215 .ReleaseBuffer
= dri2_release_buffer
,
2218 /* This is the table of extensions that the loader will dlsym() for. */
2219 const __DRIextension
*galliumdrm_driver_extensions
[] = {
2220 &driCoreExtension
.base
,
2221 &driImageDriverExtension
.base
,
2222 &driDRI2Extension
.base
,
2223 &gallium_config_options
.base
,
2227 /* vim: set sw=3 ts=8 sts=3 expandtab: */