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_screen.h"
49 #include "dri_context.h"
50 #include "dri_drawable.h"
51 #include "dri_extensions.h"
52 #include "dri_query_renderer.h"
53 #include "dri2_buffer.h"
55 #ifndef DRM_FORMAT_MOD_INVALID
56 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
59 static const int fourcc_formats
[] = {
60 __DRI_IMAGE_FOURCC_ARGB8888
,
61 __DRI_IMAGE_FOURCC_ABGR8888
,
62 __DRI_IMAGE_FOURCC_SARGB8888
,
63 __DRI_IMAGE_FOURCC_XRGB8888
,
64 __DRI_IMAGE_FOURCC_XBGR8888
,
65 __DRI_IMAGE_FOURCC_ARGB1555
,
66 __DRI_IMAGE_FOURCC_RGB565
,
67 __DRI_IMAGE_FOURCC_R8
,
68 __DRI_IMAGE_FOURCC_R16
,
69 __DRI_IMAGE_FOURCC_GR88
,
70 __DRI_IMAGE_FOURCC_GR1616
,
71 __DRI_IMAGE_FOURCC_YUV410
,
72 __DRI_IMAGE_FOURCC_YUV411
,
73 __DRI_IMAGE_FOURCC_YUV420
,
74 __DRI_IMAGE_FOURCC_YUV422
,
75 __DRI_IMAGE_FOURCC_YUV444
,
76 __DRI_IMAGE_FOURCC_YVU410
,
77 __DRI_IMAGE_FOURCC_YVU411
,
78 __DRI_IMAGE_FOURCC_YVU420
,
79 __DRI_IMAGE_FOURCC_YVU422
,
80 __DRI_IMAGE_FOURCC_YVU444
,
81 __DRI_IMAGE_FOURCC_NV12
,
82 __DRI_IMAGE_FOURCC_NV16
,
83 __DRI_IMAGE_FOURCC_YUYV
86 static int convert_fourcc(int format
, int *dri_components_p
)
90 case __DRI_IMAGE_FOURCC_RGB565
:
91 format
= __DRI_IMAGE_FORMAT_RGB565
;
92 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
94 case __DRI_IMAGE_FOURCC_ARGB8888
:
95 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
96 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
98 case __DRI_IMAGE_FOURCC_XRGB8888
:
99 format
= __DRI_IMAGE_FORMAT_XRGB8888
;
100 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
102 case __DRI_IMAGE_FOURCC_ABGR8888
:
103 format
= __DRI_IMAGE_FORMAT_ABGR8888
;
104 dri_components
= __DRI_IMAGE_COMPONENTS_RGBA
;
106 case __DRI_IMAGE_FOURCC_XBGR8888
:
107 format
= __DRI_IMAGE_FORMAT_XBGR8888
;
108 dri_components
= __DRI_IMAGE_COMPONENTS_RGB
;
110 case __DRI_IMAGE_FOURCC_R8
:
111 format
= __DRI_IMAGE_FORMAT_R8
;
112 dri_components
= __DRI_IMAGE_COMPONENTS_R
;
114 case __DRI_IMAGE_FOURCC_GR88
:
115 format
= __DRI_IMAGE_FORMAT_GR88
;
116 dri_components
= __DRI_IMAGE_COMPONENTS_RG
;
119 * For multi-planar YUV formats, we return the format of the first
120 * plane only. Since there is only one caller which supports multi-
121 * planar YUV it gets to figure out the remaining planes on it's
124 case __DRI_IMAGE_FOURCC_YUV420
:
125 case __DRI_IMAGE_FOURCC_YVU420
:
126 format
= __DRI_IMAGE_FORMAT_R8
;
127 dri_components
= __DRI_IMAGE_COMPONENTS_Y_U_V
;
129 case __DRI_IMAGE_FOURCC_NV12
:
130 format
= __DRI_IMAGE_FORMAT_R8
;
131 dri_components
= __DRI_IMAGE_COMPONENTS_Y_UV
;
136 *dri_components_p
= dri_components
;
140 /* NOTE this probably isn't going to do the right thing for YUV images
141 * (but I think the same can be said for intel_query_image()). I think
142 * only needed for exporting dmabuf's, so I think I won't loose much
145 static int convert_to_fourcc(int format
)
148 case __DRI_IMAGE_FORMAT_RGB565
:
149 format
= __DRI_IMAGE_FOURCC_RGB565
;
151 case __DRI_IMAGE_FORMAT_ARGB8888
:
152 format
= __DRI_IMAGE_FOURCC_ARGB8888
;
154 case __DRI_IMAGE_FORMAT_XRGB8888
:
155 format
= __DRI_IMAGE_FOURCC_XRGB8888
;
157 case __DRI_IMAGE_FORMAT_ABGR8888
:
158 format
= __DRI_IMAGE_FOURCC_ABGR8888
;
160 case __DRI_IMAGE_FORMAT_XBGR8888
:
161 format
= __DRI_IMAGE_FOURCC_XBGR8888
;
163 case __DRI_IMAGE_FORMAT_R8
:
164 format
= __DRI_IMAGE_FOURCC_R8
;
166 case __DRI_IMAGE_FORMAT_GR88
:
167 format
= __DRI_IMAGE_FOURCC_GR88
;
175 static enum pipe_format
dri2_format_to_pipe_format (int format
)
180 case __DRI_IMAGE_FORMAT_RGB565
:
181 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
183 case __DRI_IMAGE_FORMAT_XRGB8888
:
184 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
186 case __DRI_IMAGE_FORMAT_ARGB8888
:
187 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
189 case __DRI_IMAGE_FORMAT_XBGR8888
:
190 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
192 case __DRI_IMAGE_FORMAT_ABGR8888
:
193 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
195 case __DRI_IMAGE_FORMAT_R8
:
196 pf
= PIPE_FORMAT_R8_UNORM
;
198 case __DRI_IMAGE_FORMAT_GR88
:
199 pf
= PIPE_FORMAT_RG88_UNORM
;
202 pf
= PIPE_FORMAT_NONE
;
209 static enum pipe_format
fourcc_to_pipe_format(int fourcc
)
214 case __DRI_IMAGE_FOURCC_R8
:
215 pf
= PIPE_FORMAT_R8_UNORM
;
217 case __DRI_IMAGE_FOURCC_GR88
:
218 pf
= PIPE_FORMAT_RG88_UNORM
;
220 case __DRI_IMAGE_FOURCC_ARGB1555
:
221 pf
= PIPE_FORMAT_B5G5R5A1_UNORM
;
223 case __DRI_IMAGE_FOURCC_R16
:
224 pf
= PIPE_FORMAT_R16_UNORM
;
226 case __DRI_IMAGE_FOURCC_GR1616
:
227 pf
= PIPE_FORMAT_RG1616_UNORM
;
229 case __DRI_IMAGE_FOURCC_RGB565
:
230 pf
= PIPE_FORMAT_B5G6R5_UNORM
;
232 case __DRI_IMAGE_FOURCC_ARGB8888
:
233 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
235 case __DRI_IMAGE_FOURCC_XRGB8888
:
236 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
238 case __DRI_IMAGE_FOURCC_ABGR8888
:
239 pf
= PIPE_FORMAT_RGBA8888_UNORM
;
241 case __DRI_IMAGE_FOURCC_XBGR8888
:
242 pf
= PIPE_FORMAT_RGBX8888_UNORM
;
245 case __DRI_IMAGE_FOURCC_NV12
:
246 pf
= PIPE_FORMAT_NV12
;
248 case __DRI_IMAGE_FOURCC_YUYV
:
249 pf
= PIPE_FORMAT_YUYV
;
251 case __DRI_IMAGE_FOURCC_YUV420
:
252 case __DRI_IMAGE_FOURCC_YVU420
:
253 pf
= PIPE_FORMAT_YV12
;
256 case __DRI_IMAGE_FOURCC_SARGB8888
:
257 case __DRI_IMAGE_FOURCC_YUV410
:
258 case __DRI_IMAGE_FOURCC_YUV411
:
259 case __DRI_IMAGE_FOURCC_YUV422
:
260 case __DRI_IMAGE_FOURCC_YUV444
:
261 case __DRI_IMAGE_FOURCC_NV16
:
262 case __DRI_IMAGE_FOURCC_YVU410
:
263 case __DRI_IMAGE_FOURCC_YVU411
:
264 case __DRI_IMAGE_FOURCC_YVU422
:
265 case __DRI_IMAGE_FOURCC_YVU444
:
267 pf
= PIPE_FORMAT_NONE
;
274 * DRI2 flush extension.
277 dri2_flush_drawable(__DRIdrawable
*dPriv
)
279 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
283 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
285 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
287 dri2InvalidateDrawable(dPriv
);
288 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
289 drawable
->texture_mask
= 0;
291 p_atomic_inc(&drawable
->base
.stamp
);
294 static const __DRI2flushExtension dri2FlushExtension
= {
295 .base
= { __DRI2_FLUSH
, 4 },
297 .flush
= dri2_flush_drawable
,
298 .invalidate
= dri2_invalidate_drawable
,
299 .flush_with_flags
= dri_flush
,
303 * Retrieve __DRIbuffer from the DRI loader.
306 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
307 const enum st_attachment_type
*atts
,
310 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
311 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
313 __DRIbuffer
*buffers
;
315 unsigned attachments
[10];
316 unsigned num_attachments
, i
;
319 with_format
= dri_with_format(drawable
->sPriv
);
323 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
325 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
327 for (i
= 0; i
< *count
; i
++) {
328 enum pipe_format format
;
332 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
333 if (format
== PIPE_FORMAT_NONE
)
337 case ST_ATTACHMENT_FRONT_LEFT
:
341 att
= __DRI_BUFFER_FRONT_LEFT
;
343 case ST_ATTACHMENT_BACK_LEFT
:
344 att
= __DRI_BUFFER_BACK_LEFT
;
346 case ST_ATTACHMENT_FRONT_RIGHT
:
347 att
= __DRI_BUFFER_FRONT_RIGHT
;
349 case ST_ATTACHMENT_BACK_RIGHT
:
350 att
= __DRI_BUFFER_BACK_RIGHT
;
357 * In this switch statement we must support all formats that
358 * may occur as the stvis->color_format.
361 case PIPE_FORMAT_BGRA8888_UNORM
:
362 case PIPE_FORMAT_RGBA8888_UNORM
:
365 case PIPE_FORMAT_BGRX8888_UNORM
:
366 case PIPE_FORMAT_RGBX8888_UNORM
:
369 case PIPE_FORMAT_B5G6R5_UNORM
:
373 depth
= util_format_get_blocksizebits(format
);
374 assert(!"Unexpected format in dri2_drawable_get_buffers()");
377 attachments
[num_attachments
++] = att
;
379 attachments
[num_attachments
++] = depth
;
384 num_attachments
/= 2;
385 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
386 &dri_drawable
->w
, &dri_drawable
->h
,
387 attachments
, num_attachments
,
388 &num_buffers
, dri_drawable
->loaderPrivate
);
391 buffers
= loader
->getBuffers(dri_drawable
,
392 &dri_drawable
->w
, &dri_drawable
->h
,
393 attachments
, num_attachments
,
394 &num_buffers
, dri_drawable
->loaderPrivate
);
398 *count
= num_buffers
;
404 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
405 struct __DRIimageList
*images
,
406 const enum st_attachment_type
*statts
,
407 unsigned statts_count
)
409 __DRIdrawable
*dPriv
= drawable
->dPriv
;
410 __DRIscreen
*sPriv
= drawable
->sPriv
;
411 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
413 uint32_t buffer_mask
= 0;
416 for (i
= 0; i
< statts_count
; i
++) {
417 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
418 if (pf
== PIPE_FORMAT_NONE
)
422 case ST_ATTACHMENT_FRONT_LEFT
:
423 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
425 case ST_ATTACHMENT_BACK_LEFT
:
426 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
433 case PIPE_FORMAT_B5G6R5_UNORM
:
434 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
436 case PIPE_FORMAT_BGRX8888_UNORM
:
437 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
439 case PIPE_FORMAT_BGRA8888_UNORM
:
440 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
442 case PIPE_FORMAT_RGBX8888_UNORM
:
443 image_format
= __DRI_IMAGE_FORMAT_XBGR8888
;
445 case PIPE_FORMAT_RGBA8888_UNORM
:
446 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
449 image_format
= __DRI_IMAGE_FORMAT_NONE
;
454 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
455 (uint32_t *) &drawable
->base
.stamp
,
456 dPriv
->loaderPrivate
, buffer_mask
,
461 dri2_allocate_buffer(__DRIscreen
*sPriv
,
462 unsigned attachment
, unsigned format
,
463 int width
, int height
)
465 struct dri_screen
*screen
= dri_screen(sPriv
);
466 struct dri2_buffer
*buffer
;
467 struct pipe_resource templ
;
470 struct winsys_handle whandle
;
472 switch (attachment
) {
473 case __DRI_BUFFER_FRONT_LEFT
:
474 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
475 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
477 case __DRI_BUFFER_BACK_LEFT
:
478 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
480 case __DRI_BUFFER_DEPTH
:
481 case __DRI_BUFFER_DEPTH_STENCIL
:
482 case __DRI_BUFFER_STENCIL
:
483 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
487 /* because we get the handle and stride */
488 bind
|= PIPE_BIND_SHARED
;
492 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
495 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
498 pf
= PIPE_FORMAT_Z16_UNORM
;
504 buffer
= CALLOC_STRUCT(dri2_buffer
);
508 memset(&templ
, 0, sizeof(templ
));
511 templ
.target
= PIPE_TEXTURE_2D
;
512 templ
.last_level
= 0;
513 templ
.width0
= width
;
514 templ
.height0
= height
;
516 templ
.array_size
= 1;
519 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
520 if (!buffer
->resource
) {
525 memset(&whandle
, 0, sizeof(whandle
));
526 if (screen
->can_share_buffer
)
527 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
529 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
531 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
, NULL
,
532 buffer
->resource
, &whandle
,
533 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
535 buffer
->base
.attachment
= attachment
;
536 buffer
->base
.name
= whandle
.handle
;
537 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
538 buffer
->base
.pitch
= whandle
.stride
;
540 return &buffer
->base
;
544 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
546 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
548 pipe_resource_reference(&buffer
->resource
, NULL
);
553 * Backend functions for st_framebuffer interface.
557 dri2_allocate_textures(struct dri_context
*ctx
,
558 struct dri_drawable
*drawable
,
559 const enum st_attachment_type
*statts
,
560 unsigned statts_count
)
562 __DRIscreen
*sPriv
= drawable
->sPriv
;
563 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
564 struct dri_screen
*screen
= dri_screen(sPriv
);
565 struct pipe_resource templ
;
566 boolean alloc_depthstencil
= FALSE
;
568 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
569 /* Image specific variables */
570 struct __DRIimageList images
;
571 /* Dri2 specific variables */
572 __DRIbuffer
*buffers
= NULL
;
573 struct winsys_handle whandle
;
574 unsigned num_buffers
= statts_count
;
576 /* First get the buffers from the loader */
578 if (!dri_image_drawable_get_buffers(drawable
, &images
,
579 statts
, statts_count
))
583 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
584 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
585 drawable
->old_w
== dri_drawable
->w
&&
586 drawable
->old_h
== dri_drawable
->h
&&
587 memcmp(drawable
->old
, buffers
,
588 sizeof(__DRIbuffer
) * num_buffers
) == 0))
592 /* Second clean useless resources*/
594 /* See if we need a depth-stencil buffer. */
595 for (i
= 0; i
< statts_count
; i
++) {
596 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
597 alloc_depthstencil
= TRUE
;
602 /* Delete the resources we won't need. */
603 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
604 /* Don't delete the depth-stencil buffer, we can reuse it. */
605 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
608 /* Flush the texture before unreferencing, so that other clients can
609 * see what the driver has rendered.
611 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
612 struct pipe_context
*pipe
= ctx
->st
->pipe
;
613 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
616 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
619 if (drawable
->stvis
.samples
> 1) {
620 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
623 /* Don't delete MSAA resources for the attachments which are enabled,
624 * we can reuse them. */
625 for (j
= 0; j
< statts_count
; j
++) {
626 if (i
== statts
[j
]) {
633 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
638 /* Third use the buffers retrieved to fill the drawable info */
640 memset(&templ
, 0, sizeof(templ
));
641 templ
.target
= screen
->target
;
642 templ
.last_level
= 0;
644 templ
.array_size
= 1;
647 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
648 struct pipe_resource
**buf
=
649 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
650 struct pipe_resource
*texture
= images
.front
->texture
;
652 dri_drawable
->w
= texture
->width0
;
653 dri_drawable
->h
= texture
->height0
;
655 pipe_resource_reference(buf
, texture
);
658 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
659 struct pipe_resource
**buf
=
660 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
661 struct pipe_resource
*texture
= images
.back
->texture
;
663 dri_drawable
->w
= texture
->width0
;
664 dri_drawable
->h
= texture
->height0
;
666 pipe_resource_reference(buf
, texture
);
669 /* Note: if there is both a back and a front buffer,
670 * then they have the same size.
672 templ
.width0
= dri_drawable
->w
;
673 templ
.height0
= dri_drawable
->h
;
676 memset(&whandle
, 0, sizeof(whandle
));
678 /* Process DRI-provided buffers and get pipe_resources. */
679 for (i
= 0; i
< num_buffers
; i
++) {
680 __DRIbuffer
*buf
= &buffers
[i
];
681 enum st_attachment_type statt
;
682 enum pipe_format format
;
684 switch (buf
->attachment
) {
685 case __DRI_BUFFER_FRONT_LEFT
:
686 if (!screen
->auto_fake_front
) {
687 continue; /* invalid attachment */
690 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
691 statt
= ST_ATTACHMENT_FRONT_LEFT
;
693 case __DRI_BUFFER_BACK_LEFT
:
694 statt
= ST_ATTACHMENT_BACK_LEFT
;
697 continue; /* invalid attachment */
700 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
701 if (format
== PIPE_FORMAT_NONE
)
704 /* dri2_drawable_get_buffers has already filled dri_drawable->w
705 * and dri_drawable->h */
706 templ
.width0
= dri_drawable
->w
;
707 templ
.height0
= dri_drawable
->h
;
708 templ
.format
= format
;
710 whandle
.handle
= buf
->name
;
711 whandle
.stride
= buf
->pitch
;
713 if (screen
->can_share_buffer
)
714 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
716 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
717 drawable
->textures
[statt
] =
718 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
720 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
);
721 assert(drawable
->textures
[statt
]);
725 /* Allocate private MSAA colorbuffers. */
726 if (drawable
->stvis
.samples
> 1) {
727 for (i
= 0; i
< statts_count
; i
++) {
728 enum st_attachment_type statt
= statts
[i
];
730 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
733 if (drawable
->textures
[statt
]) {
734 templ
.format
= drawable
->textures
[statt
]->format
;
735 templ
.bind
= drawable
->textures
[statt
]->bind
& ~PIPE_BIND_SCANOUT
;
736 templ
.nr_samples
= drawable
->stvis
.samples
;
738 /* Try to reuse the resource.
739 * (the other resource parameters should be constant)
741 if (!drawable
->msaa_textures
[statt
] ||
742 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
743 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
744 /* Allocate a new one. */
745 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
747 drawable
->msaa_textures
[statt
] =
748 screen
->base
.screen
->resource_create(screen
->base
.screen
,
750 assert(drawable
->msaa_textures
[statt
]);
752 /* If there are any MSAA resources, we should initialize them
753 * such that they contain the same data as the single-sample
754 * resources we just got from the X server.
756 * The reason for this is that the state tracker (and
757 * therefore the app) can access the MSAA resources only.
758 * The single-sample resources are not exposed
759 * to the state tracker.
762 dri_pipe_blit(ctx
->st
->pipe
,
763 drawable
->msaa_textures
[statt
],
764 drawable
->textures
[statt
]);
768 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
773 /* Allocate a private depth-stencil buffer. */
774 if (alloc_depthstencil
) {
775 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
776 struct pipe_resource
**zsbuf
;
777 enum pipe_format format
;
780 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
783 templ
.format
= format
;
786 if (drawable
->stvis
.samples
> 1) {
787 templ
.nr_samples
= drawable
->stvis
.samples
;
788 zsbuf
= &drawable
->msaa_textures
[statt
];
791 templ
.nr_samples
= 0;
792 zsbuf
= &drawable
->textures
[statt
];
795 /* Try to reuse the resource.
796 * (the other resource parameters should be constant)
799 (*zsbuf
)->width0
!= templ
.width0
||
800 (*zsbuf
)->height0
!= templ
.height0
) {
801 /* Allocate a new one. */
802 pipe_resource_reference(zsbuf
, NULL
);
803 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
809 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
810 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
814 /* For DRI2, we may get the same buffers again from the server.
815 * To prevent useless imports of gem names, drawable->old* is used
816 * to bypass the import if we get the same buffers. This doesn't apply
817 * to DRI3/Wayland, users of image.loader, since the buffer is managed
818 * by the client (no import), and the back buffer is going to change
822 drawable
->old_num
= num_buffers
;
823 drawable
->old_w
= dri_drawable
->w
;
824 drawable
->old_h
= dri_drawable
->h
;
825 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
830 dri2_flush_frontbuffer(struct dri_context
*ctx
,
831 struct dri_drawable
*drawable
,
832 enum st_attachment_type statt
)
834 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
835 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
836 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
837 struct pipe_context
*pipe
= ctx
->st
->pipe
;
839 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
842 if (drawable
->stvis
.samples
> 1) {
843 /* Resolve the front buffer. */
844 dri_pipe_blit(ctx
->st
->pipe
,
845 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
846 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
849 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
850 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
853 pipe
->flush(pipe
, NULL
, 0);
856 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
858 else if (loader
->flushFrontBuffer
) {
859 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
864 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
865 struct dri_context
*ctx
,
866 struct pipe_resource
*res
)
872 dri2_lookup_egl_image(struct dri_screen
*screen
, void *handle
)
874 const __DRIimageLookupExtension
*loader
= screen
->sPriv
->dri2
.image
;
877 if (!loader
->lookupEGLImage
)
880 img
= loader
->lookupEGLImage(screen
->sPriv
,
881 handle
, screen
->sPriv
->loaderPrivate
);
887 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
888 int width
, int height
, int format
,
889 int num_handles
, struct winsys_handle
*whandle
,
892 struct dri_screen
*screen
= dri_screen(_screen
);
893 struct pipe_screen
*pscreen
= screen
->base
.screen
;
895 struct pipe_resource templ
;
900 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
902 pf
= dri2_format_to_pipe_format (format
);
903 if (pf
== PIPE_FORMAT_NONE
)
906 img
= CALLOC_STRUCT(__DRIimageRec
);
910 memset(&templ
, 0, sizeof(templ
));
911 templ
.bind
= tex_usage
;
912 templ
.target
= screen
->target
;
913 templ
.last_level
= 0;
915 templ
.array_size
= 1;
917 for (i
= num_handles
- 1; i
>= 0; i
--) {
918 struct pipe_resource
*tex
;
920 /* TODO: something a lot less ugly */
923 templ
.width0
= width
;
924 templ
.height0
= height
;
928 templ
.width0
= width
/ 2;
929 templ
.height0
= height
/ 2;
930 templ
.format
= (num_handles
== 2) ?
931 PIPE_FORMAT_RG88_UNORM
: /* NV12, etc */
932 PIPE_FORMAT_R8_UNORM
; /* I420, etc */
935 templ
.width0
= width
/ 2;
936 templ
.height0
= height
/ 2;
937 templ
.format
= PIPE_FORMAT_R8_UNORM
;
940 unreachable("too many planes!");
943 tex
= pscreen
->resource_from_handle(pscreen
,
944 &templ
, &whandle
[i
], PIPE_HANDLE_USAGE_READ_WRITE
);
946 pipe_resource_reference(&img
->texture
, NULL
);
951 tex
->next
= img
->texture
;
957 img
->dri_format
= format
;
959 img
->loader_private
= loaderPrivate
;
965 dri2_create_image_from_name(__DRIscreen
*_screen
,
966 int width
, int height
, int format
,
967 int name
, int pitch
, void *loaderPrivate
)
969 struct winsys_handle whandle
;
972 memset(&whandle
, 0, sizeof(whandle
));
973 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
974 whandle
.handle
= name
;
975 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
977 pf
= dri2_format_to_pipe_format (format
);
978 if (pf
== PIPE_FORMAT_NONE
)
981 whandle
.stride
= pitch
* util_format_get_blocksize(pf
);
983 return dri2_create_image_from_winsys(_screen
, width
, height
, format
,
984 1, &whandle
, loaderPrivate
);
988 dri2_create_image_from_fd(__DRIscreen
*_screen
,
989 int width
, int height
, int fourcc
,
990 uint64_t modifier
, int *fds
, int num_fds
,
991 int *strides
, int *offsets
, unsigned *error
,
992 int *dri_components
, void *loaderPrivate
)
994 struct winsys_handle whandles
[3];
996 __DRIimage
*img
= NULL
;
997 unsigned err
= __DRI_IMAGE_ERROR_SUCCESS
;
998 int expected_num_fds
, i
;
1001 case __DRI_IMAGE_FOURCC_YUV420
:
1002 case __DRI_IMAGE_FOURCC_YVU420
:
1003 expected_num_fds
= 3;
1005 case __DRI_IMAGE_FOURCC_NV12
:
1006 expected_num_fds
= 2;
1009 expected_num_fds
= 1;
1013 if (num_fds
!= expected_num_fds
) {
1014 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1018 format
= convert_fourcc(fourcc
, dri_components
);
1020 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1024 memset(whandles
, 0, sizeof(whandles
));
1026 for (i
= 0; i
< num_fds
; i
++) {
1028 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1032 whandles
[i
].type
= DRM_API_HANDLE_TYPE_FD
;
1033 whandles
[i
].handle
= (unsigned)fds
[i
];
1034 whandles
[i
].stride
= (unsigned)strides
[i
];
1035 whandles
[i
].offset
= (unsigned)offsets
[i
];
1036 whandles
[i
].modifier
= modifier
;
1039 if (fourcc
== __DRI_IMAGE_FOURCC_YVU420
) {
1040 /* convert to YUV420 by swapping 2nd and 3rd planes: */
1041 struct winsys_handle tmp
= whandles
[1];
1042 whandles
[1] = whandles
[2];
1044 fourcc
= __DRI_IMAGE_FOURCC_YUV420
;
1047 img
= dri2_create_image_from_winsys(_screen
, width
, height
, format
,
1048 num_fds
, whandles
, loaderPrivate
);
1050 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1060 dri2_create_image_from_renderbuffer(__DRIcontext
*context
,
1061 int renderbuffer
, void *loaderPrivate
)
1063 struct dri_context
*ctx
= dri_context(context
);
1065 if (!ctx
->st
->get_resource_for_egl_image
)
1073 dri2_create_image_common(__DRIscreen
*_screen
,
1074 int width
, int height
,
1075 int format
, unsigned int use
,
1076 const uint64_t *modifiers
,
1077 const unsigned count
,
1078 void *loaderPrivate
)
1080 struct dri_screen
*screen
= dri_screen(_screen
);
1082 struct pipe_resource templ
;
1084 enum pipe_format pf
;
1086 /* createImageWithModifiers doesn't supply usage, and we should not get
1087 * here with both modifiers and a usage flag.
1089 assert(!(use
&& (modifiers
!= NULL
)));
1091 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1093 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1094 tex_usage
|= PIPE_BIND_SCANOUT
;
1095 if (use
& __DRI_IMAGE_USE_SHARE
)
1096 tex_usage
|= PIPE_BIND_SHARED
;
1097 if (use
& __DRI_IMAGE_USE_LINEAR
)
1098 tex_usage
|= PIPE_BIND_LINEAR
;
1099 if (use
& __DRI_IMAGE_USE_CURSOR
) {
1100 if (width
!= 64 || height
!= 64)
1102 tex_usage
|= PIPE_BIND_CURSOR
;
1105 pf
= dri2_format_to_pipe_format (format
);
1106 if (pf
== PIPE_FORMAT_NONE
)
1109 img
= CALLOC_STRUCT(__DRIimageRec
);
1113 memset(&templ
, 0, sizeof(templ
));
1114 templ
.bind
= tex_usage
;
1116 templ
.target
= PIPE_TEXTURE_2D
;
1117 templ
.last_level
= 0;
1118 templ
.width0
= width
;
1119 templ
.height0
= height
;
1121 templ
.array_size
= 1;
1126 ->resource_create_with_modifiers(screen
->base
.screen
,
1132 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
1133 if (!img
->texture
) {
1140 img
->dri_format
= format
;
1141 img
->dri_components
= 0;
1144 img
->loader_private
= loaderPrivate
;
1149 dri2_create_image(__DRIscreen
*_screen
,
1150 int width
, int height
, int format
,
1151 unsigned int use
, void *loaderPrivate
)
1153 return dri2_create_image_common(_screen
, width
, height
, format
, use
,
1154 NULL
/* modifiers */, 0 /* count */,
1159 dri2_create_image_with_modifiers(__DRIscreen
*dri_screen
,
1160 int width
, int height
, int format
,
1161 const uint64_t *modifiers
,
1162 const unsigned count
,
1163 void *loaderPrivate
)
1165 return dri2_create_image_common(dri_screen
, width
, height
, format
,
1166 0 /* use */, modifiers
, count
,
1171 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
1173 struct winsys_handle whandle
;
1176 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1177 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
| PIPE_HANDLE_USAGE_READ
;
1179 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1181 memset(&whandle
, 0, sizeof(whandle
));
1184 case __DRI_IMAGE_ATTRIB_STRIDE
:
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
.stride
;
1191 case __DRI_IMAGE_ATTRIB_OFFSET
:
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
.offset
;
1198 case __DRI_IMAGE_ATTRIB_HANDLE
:
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
.handle
;
1205 case __DRI_IMAGE_ATTRIB_NAME
:
1206 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
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_FD
:
1213 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1214 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1215 NULL
, image
->texture
, &whandle
, usage
))
1218 *value
= whandle
.handle
;
1220 case __DRI_IMAGE_ATTRIB_FORMAT
:
1221 *value
= image
->dri_format
;
1223 case __DRI_IMAGE_ATTRIB_WIDTH
:
1224 *value
= image
->texture
->width0
;
1226 case __DRI_IMAGE_ATTRIB_HEIGHT
:
1227 *value
= image
->texture
->height0
;
1229 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
1230 if (image
->dri_components
== 0)
1232 *value
= image
->dri_components
;
1234 case __DRI_IMAGE_ATTRIB_FOURCC
:
1235 *value
= convert_to_fourcc(image
->dri_format
);
1237 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1240 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1241 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1242 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1243 NULL
, image
->texture
, &whandle
, usage
))
1245 *value
= (whandle
.modifier
>> 32) & 0xffffffff;
1247 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1248 whandle
.type
= DRM_API_HANDLE_TYPE_KMS
;
1249 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1250 NULL
, image
->texture
, &whandle
, usage
))
1252 *value
= whandle
.modifier
& 0xffffffff;
1260 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
1264 img
= CALLOC_STRUCT(__DRIimageRec
);
1268 img
->texture
= NULL
;
1269 pipe_resource_reference(&img
->texture
, image
->texture
);
1270 img
->level
= image
->level
;
1271 img
->layer
= image
->layer
;
1272 img
->dri_format
= image
->dri_format
;
1273 /* This should be 0 for sub images, but dup is also used for base images. */
1274 img
->dri_components
= image
->dri_components
;
1275 img
->loader_private
= loaderPrivate
;
1281 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
1284 * Gallium drivers are bad at adding usages to the resources
1285 * once opened again in another process, which is the main use
1286 * case for this, so we have to lie.
1295 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
1296 int *names
, int num_names
, int *strides
, int *offsets
,
1297 void *loaderPrivate
)
1301 struct winsys_handle whandle
;
1306 format
= convert_fourcc(format
, &dri_components
);
1310 memset(&whandle
, 0, sizeof(whandle
));
1311 whandle
.type
= DRM_API_HANDLE_TYPE_SHARED
;
1312 whandle
.handle
= names
[0];
1313 whandle
.stride
= strides
[0];
1314 whandle
.offset
= offsets
[0];
1315 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1317 img
= dri2_create_image_from_winsys(screen
, width
, height
, format
,
1318 1, &whandle
, loaderPrivate
);
1322 img
->dri_components
= dri_components
;
1327 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1334 if (image
->dri_components
== 0)
1337 img
= dri2_dup_image(image
, loaderPrivate
);
1341 if (img
->texture
->screen
->resource_changed
)
1342 img
->texture
->screen
->resource_changed(img
->texture
->screen
,
1345 /* set this to 0 for sub images. */
1346 img
->dri_components
= 0;
1351 dri2_create_from_texture(__DRIcontext
*context
, int target
, unsigned texture
,
1352 int depth
, int level
, unsigned *error
,
1353 void *loaderPrivate
)
1356 struct gl_context
*ctx
= ((struct st_context
*)dri_context(context
)->st
)->ctx
;
1357 struct gl_texture_object
*obj
;
1358 struct pipe_resource
*tex
;
1361 obj
= _mesa_lookup_texture(ctx
, texture
);
1362 if (!obj
|| obj
->Target
!= target
) {
1363 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1367 tex
= st_get_texobj_resource(obj
);
1369 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1373 if (target
== GL_TEXTURE_CUBE_MAP
)
1376 _mesa_test_texobj_completeness(ctx
, obj
);
1377 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
1378 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1382 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
1383 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1387 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< depth
) {
1388 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
1392 img
= CALLOC_STRUCT(__DRIimageRec
);
1394 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
1400 img
->dri_format
= driGLFormatToImageFormat(obj
->Image
[face
][level
]->TexFormat
);
1402 img
->loader_private
= loaderPrivate
;
1404 if (img
->dri_format
== __DRI_IMAGE_FORMAT_NONE
) {
1405 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
1410 pipe_resource_reference(&img
->texture
, tex
);
1412 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1417 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1418 int *fds
, int num_fds
, int *strides
, int *offsets
,
1419 void *loaderPrivate
)
1424 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1425 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1426 strides
, offsets
, NULL
,
1427 &dri_components
, loaderPrivate
);
1431 img
->dri_components
= dri_components
;
1436 dri2_query_dma_buf_formats(__DRIscreen
*_screen
, int max
, int *formats
,
1439 struct dri_screen
*screen
= dri_screen(_screen
);
1440 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1441 const unsigned bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1444 for (i
= 0, j
= 0; (i
< ARRAY_SIZE(fourcc_formats
)) &&
1445 (j
< max
|| max
== 0); i
++) {
1446 if (pscreen
->is_format_supported(pscreen
,
1447 fourcc_to_pipe_format(
1452 formats
[j
] = fourcc_formats
[i
];
1461 dri2_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1462 uint64_t *modifiers
, unsigned int *external_only
,
1465 struct dri_screen
*screen
= dri_screen(_screen
);
1466 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1467 enum pipe_format format
= fourcc_to_pipe_format(fourcc
);
1468 const unsigned usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1470 if (pscreen
->query_dmabuf_modifiers
!= NULL
&&
1471 pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, usage
)) {
1472 pscreen
->query_dmabuf_modifiers(pscreen
, format
, max
, modifiers
,
1473 external_only
, count
);
1480 dri2_from_dma_bufs(__DRIscreen
*screen
,
1481 int width
, int height
, int fourcc
,
1482 int *fds
, int num_fds
,
1483 int *strides
, int *offsets
,
1484 enum __DRIYUVColorSpace yuv_color_space
,
1485 enum __DRISampleRange sample_range
,
1486 enum __DRIChromaSiting horizontal_siting
,
1487 enum __DRIChromaSiting vertical_siting
,
1489 void *loaderPrivate
)
1494 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1495 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1496 strides
, offsets
, error
,
1497 &dri_components
, loaderPrivate
);
1501 img
->yuv_color_space
= yuv_color_space
;
1502 img
->sample_range
= sample_range
;
1503 img
->horizontal_siting
= horizontal_siting
;
1504 img
->vertical_siting
= vertical_siting
;
1505 img
->dri_components
= dri_components
;
1507 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1512 dri2_from_dma_bufs2(__DRIscreen
*screen
,
1513 int width
, int height
, int fourcc
,
1514 uint64_t modifier
, int *fds
, int num_fds
,
1515 int *strides
, int *offsets
,
1516 enum __DRIYUVColorSpace yuv_color_space
,
1517 enum __DRISampleRange sample_range
,
1518 enum __DRIChromaSiting horizontal_siting
,
1519 enum __DRIChromaSiting vertical_siting
,
1521 void *loaderPrivate
)
1526 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1527 modifier
, fds
, num_fds
, strides
, offsets
,
1528 error
, &dri_components
, loaderPrivate
);
1532 img
->yuv_color_space
= yuv_color_space
;
1533 img
->sample_range
= sample_range
;
1534 img
->horizontal_siting
= horizontal_siting
;
1535 img
->vertical_siting
= vertical_siting
;
1536 img
->dri_components
= dri_components
;
1538 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1543 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1544 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1545 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1548 struct dri_context
*ctx
= dri_context(context
);
1549 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1550 struct pipe_screen
*screen
;
1551 struct pipe_fence_handle
*fence
;
1552 struct pipe_blit_info blit
;
1557 memset(&blit
, 0, sizeof(blit
));
1558 blit
.dst
.resource
= dst
->texture
;
1559 blit
.dst
.box
.x
= dstx0
;
1560 blit
.dst
.box
.y
= dsty0
;
1561 blit
.dst
.box
.width
= dstwidth
;
1562 blit
.dst
.box
.height
= dstheight
;
1563 blit
.dst
.box
.depth
= 1;
1564 blit
.dst
.format
= dst
->texture
->format
;
1565 blit
.src
.resource
= src
->texture
;
1566 blit
.src
.box
.x
= srcx0
;
1567 blit
.src
.box
.y
= srcy0
;
1568 blit
.src
.box
.width
= srcwidth
;
1569 blit
.src
.box
.height
= srcheight
;
1570 blit
.src
.box
.depth
= 1;
1571 blit
.src
.format
= src
->texture
->format
;
1572 blit
.mask
= PIPE_MASK_RGBA
;
1573 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1575 pipe
->blit(pipe
, &blit
);
1577 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1578 pipe
->flush_resource(pipe
, dst
->texture
);
1579 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1580 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1581 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1582 pipe
->flush_resource(pipe
, dst
->texture
);
1583 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1584 (void) screen
->fence_finish(screen
, NULL
, fence
, PIPE_TIMEOUT_INFINITE
);
1585 screen
->fence_reference(screen
, &fence
, NULL
);
1590 dri2_map_image(__DRIcontext
*context
, __DRIimage
*image
,
1591 int x0
, int y0
, int width
, int height
,
1592 unsigned int flags
, int *stride
, void **data
)
1594 struct dri_context
*ctx
= dri_context(context
);
1595 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1596 enum pipe_transfer_usage pipe_access
= 0;
1597 struct pipe_transfer
*trans
;
1600 if (!image
|| !data
|| *data
)
1603 if (flags
& __DRI_IMAGE_TRANSFER_READ
)
1604 pipe_access
|= PIPE_TRANSFER_READ
;
1605 if (flags
& __DRI_IMAGE_TRANSFER_WRITE
)
1606 pipe_access
|= PIPE_TRANSFER_WRITE
;
1608 map
= pipe_transfer_map(pipe
, image
->texture
,
1609 0, 0, pipe_access
, x0
, y0
, width
, height
,
1613 *stride
= trans
->stride
;
1620 dri2_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *data
)
1622 struct dri_context
*ctx
= dri_context(context
);
1623 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1625 pipe_transfer_unmap(pipe
, (struct pipe_transfer
*)data
);
1629 dri2_destroy_image(__DRIimage
*img
)
1631 pipe_resource_reference(&img
->texture
, NULL
);
1636 dri2_get_capabilities(__DRIscreen
*_screen
)
1638 struct dri_screen
*screen
= dri_screen(_screen
);
1640 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1643 /* The extension is modified during runtime if DRI_PRIME is detected */
1644 static __DRIimageExtension dri2ImageExtension
= {
1645 .base
= { __DRI_IMAGE
, 15 },
1647 .createImageFromName
= dri2_create_image_from_name
,
1648 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1649 .destroyImage
= dri2_destroy_image
,
1650 .createImage
= dri2_create_image
,
1651 .queryImage
= dri2_query_image
,
1652 .dupImage
= dri2_dup_image
,
1653 .validateUsage
= dri2_validate_usage
,
1654 .createImageFromNames
= dri2_from_names
,
1655 .fromPlanar
= dri2_from_planar
,
1656 .createImageFromTexture
= dri2_create_from_texture
,
1657 .createImageFromFds
= NULL
,
1658 .createImageFromDmaBufs
= NULL
,
1659 .blitImage
= dri2_blit_image
,
1660 .getCapabilities
= dri2_get_capabilities
,
1661 .mapImage
= dri2_map_image
,
1662 .unmapImage
= dri2_unmap_image
,
1665 static const __DRIrobustnessExtension dri2Robustness
= {
1666 .base
= { __DRI2_ROBUSTNESS
, 1 }
1670 dri2_interop_query_device_info(__DRIcontext
*_ctx
,
1671 struct mesa_glinterop_device_info
*out
)
1673 struct pipe_screen
*screen
= dri_context(_ctx
)->st
->pipe
->screen
;
1675 /* There is no version 0, thus we do not support it */
1676 if (out
->version
== 0)
1677 return MESA_GLINTEROP_INVALID_VERSION
;
1679 out
->pci_segment_group
= screen
->get_param(screen
, PIPE_CAP_PCI_GROUP
);
1680 out
->pci_bus
= screen
->get_param(screen
, PIPE_CAP_PCI_BUS
);
1681 out
->pci_device
= screen
->get_param(screen
, PIPE_CAP_PCI_DEVICE
);
1682 out
->pci_function
= screen
->get_param(screen
, PIPE_CAP_PCI_FUNCTION
);
1684 out
->vendor_id
= screen
->get_param(screen
, PIPE_CAP_VENDOR_ID
);
1685 out
->device_id
= screen
->get_param(screen
, PIPE_CAP_DEVICE_ID
);
1687 /* Instruct the caller that we support up-to version one of the interface */
1690 return MESA_GLINTEROP_SUCCESS
;
1694 dri2_interop_export_object(__DRIcontext
*_ctx
,
1695 struct mesa_glinterop_export_in
*in
,
1696 struct mesa_glinterop_export_out
*out
)
1698 struct st_context_iface
*st
= dri_context(_ctx
)->st
;
1699 struct pipe_screen
*screen
= st
->pipe
->screen
;
1700 struct gl_context
*ctx
= ((struct st_context
*)st
)->ctx
;
1701 struct pipe_resource
*res
= NULL
;
1702 struct winsys_handle whandle
;
1703 unsigned target
, usage
;
1706 /* There is no version 0, thus we do not support it */
1707 if (in
->version
== 0 || out
->version
== 0)
1708 return MESA_GLINTEROP_INVALID_VERSION
;
1710 /* Validate the target. */
1711 switch (in
->target
) {
1712 case GL_TEXTURE_BUFFER
:
1716 case GL_TEXTURE_RECTANGLE
:
1717 case GL_TEXTURE_1D_ARRAY
:
1718 case GL_TEXTURE_2D_ARRAY
:
1719 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1720 case GL_TEXTURE_CUBE_MAP
:
1721 case GL_TEXTURE_2D_MULTISAMPLE
:
1722 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1723 case GL_TEXTURE_EXTERNAL_OES
:
1724 case GL_RENDERBUFFER
:
1725 case GL_ARRAY_BUFFER
:
1726 target
= in
->target
;
1728 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1729 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1730 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1731 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1732 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1733 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1734 target
= GL_TEXTURE_CUBE_MAP
;
1737 return MESA_GLINTEROP_INVALID_TARGET
;
1740 /* Validate the simple case of miplevel. */
1741 if ((target
== GL_RENDERBUFFER
|| target
== GL_ARRAY_BUFFER
) &&
1743 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1745 /* Validate the OpenGL object and get pipe_resource. */
1746 mtx_lock(&ctx
->Shared
->Mutex
);
1748 if (target
== GL_ARRAY_BUFFER
) {
1751 * The error checking is based on the documentation of
1752 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1754 struct gl_buffer_object
*buf
= _mesa_lookup_bufferobj(ctx
, in
->obj
);
1756 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1757 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1758 * a GL buffer object but does not have an existing data store or
1759 * the size of the buffer is 0."
1761 if (!buf
|| buf
->Size
== 0) {
1762 mtx_unlock(&ctx
->Shared
->Mutex
);
1763 return MESA_GLINTEROP_INVALID_OBJECT
;
1766 res
= st_buffer_object(buf
)->buffer
;
1768 /* this shouldn't happen */
1769 mtx_unlock(&ctx
->Shared
->Mutex
);
1770 return MESA_GLINTEROP_INVALID_OBJECT
;
1773 out
->buf_offset
= 0;
1774 out
->buf_size
= buf
->Size
;
1776 buf
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1777 } else if (target
== GL_RENDERBUFFER
) {
1780 * The error checking is based on the documentation of
1781 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1783 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, in
->obj
);
1785 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1786 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1787 * object or if the width or height of renderbuffer is zero."
1789 if (!rb
|| rb
->Width
== 0 || rb
->Height
== 0) {
1790 mtx_unlock(&ctx
->Shared
->Mutex
);
1791 return MESA_GLINTEROP_INVALID_OBJECT
;
1794 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1795 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1796 * renderbuffer object."
1798 if (rb
->NumSamples
> 1) {
1799 mtx_unlock(&ctx
->Shared
->Mutex
);
1800 return MESA_GLINTEROP_INVALID_OPERATION
;
1803 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1804 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1805 * required by the OpenCL implementation on the device."
1807 res
= st_renderbuffer(rb
)->texture
;
1809 mtx_unlock(&ctx
->Shared
->Mutex
);
1810 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1813 out
->internal_format
= rb
->InternalFormat
;
1814 out
->view_minlevel
= 0;
1815 out
->view_numlevels
= 1;
1816 out
->view_minlayer
= 0;
1817 out
->view_numlayers
= 1;
1821 * The error checking is based on the documentation of
1822 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1824 struct gl_texture_object
*obj
= _mesa_lookup_texture(ctx
, in
->obj
);
1827 _mesa_test_texobj_completeness(ctx
, obj
);
1829 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1830 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1831 * type matches texture_target, if the specified miplevel of texture
1832 * is not defined, or if the width or height of the specified
1833 * miplevel is zero or if the GL texture object is incomplete."
1836 obj
->Target
!= target
||
1837 !obj
->_BaseComplete
||
1838 (in
->miplevel
> 0 && !obj
->_MipmapComplete
)) {
1839 mtx_unlock(&ctx
->Shared
->Mutex
);
1840 return MESA_GLINTEROP_INVALID_OBJECT
;
1843 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1844 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1845 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1846 * implementations); or greater than the value of q (for both OpenGL
1847 * and OpenGL ES). levelbase and q are defined for the texture in
1848 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1849 * specification and section 3.7.10 of the OpenGL ES 2.0."
1851 if (in
->miplevel
< obj
->BaseLevel
|| in
->miplevel
> obj
->_MaxLevel
) {
1852 mtx_unlock(&ctx
->Shared
->Mutex
);
1853 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1856 if (!st_finalize_texture(ctx
, st
->pipe
, obj
, 0)) {
1857 mtx_unlock(&ctx
->Shared
->Mutex
);
1858 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1861 res
= st_get_texobj_resource(obj
);
1863 /* Incomplete texture buffer object? This shouldn't really occur. */
1864 mtx_unlock(&ctx
->Shared
->Mutex
);
1865 return MESA_GLINTEROP_INVALID_OBJECT
;
1868 if (target
== GL_TEXTURE_BUFFER
) {
1869 out
->internal_format
= obj
->BufferObjectFormat
;
1870 out
->buf_offset
= obj
->BufferOffset
;
1871 out
->buf_size
= obj
->BufferSize
== -1 ? obj
->BufferObject
->Size
:
1874 obj
->BufferObject
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1876 out
->internal_format
= obj
->Image
[0][0]->InternalFormat
;
1877 out
->view_minlevel
= obj
->MinLevel
;
1878 out
->view_numlevels
= obj
->NumLevels
;
1879 out
->view_minlayer
= obj
->MinLayer
;
1880 out
->view_numlayers
= obj
->NumLayers
;
1884 /* Get the handle. */
1885 switch (in
->access
) {
1886 case MESA_GLINTEROP_ACCESS_READ_WRITE
:
1887 usage
= PIPE_HANDLE_USAGE_READ_WRITE
;
1889 case MESA_GLINTEROP_ACCESS_READ_ONLY
:
1890 usage
= PIPE_HANDLE_USAGE_READ
;
1892 case MESA_GLINTEROP_ACCESS_WRITE_ONLY
:
1893 usage
= PIPE_HANDLE_USAGE_WRITE
;
1899 memset(&whandle
, 0, sizeof(whandle
));
1900 whandle
.type
= DRM_API_HANDLE_TYPE_FD
;
1902 success
= screen
->resource_get_handle(screen
, st
->pipe
, res
, &whandle
,
1904 mtx_unlock(&ctx
->Shared
->Mutex
);
1907 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY
;
1909 out
->dmabuf_fd
= whandle
.handle
;
1910 out
->out_driver_data_written
= 0;
1912 if (res
->target
== PIPE_BUFFER
)
1913 out
->buf_offset
+= whandle
.offset
;
1915 /* Instruct the caller that we support up-to version one of the interface */
1919 return MESA_GLINTEROP_SUCCESS
;
1922 static const __DRI2interopExtension dri2InteropExtension
= {
1923 .base
= { __DRI2_INTEROP
, 1 },
1924 .query_device_info
= dri2_interop_query_device_info
,
1925 .export_object
= dri2_interop_export_object
1929 * \brief the DRI2ConfigQueryExtension configQueryb method
1932 dri2GalliumConfigQueryb(__DRIscreen
*sPriv
, const char *var
,
1935 struct dri_screen
*screen
= dri_screen(sPriv
);
1937 if (!driCheckOption(&screen
->optionCache
, var
, DRI_BOOL
))
1938 return dri2ConfigQueryExtension
.configQueryb(sPriv
, var
, val
);
1940 *val
= driQueryOptionb(&screen
->optionCache
, var
);
1946 * \brief the DRI2ConfigQueryExtension configQueryi method
1949 dri2GalliumConfigQueryi(__DRIscreen
*sPriv
, const char *var
, int *val
)
1951 struct dri_screen
*screen
= dri_screen(sPriv
);
1953 if (!driCheckOption(&screen
->optionCache
, var
, DRI_INT
) &&
1954 !driCheckOption(&screen
->optionCache
, var
, DRI_ENUM
))
1955 return dri2ConfigQueryExtension
.configQueryi(sPriv
, var
, val
);
1957 *val
= driQueryOptioni(&screen
->optionCache
, var
);
1963 * \brief the DRI2ConfigQueryExtension configQueryf method
1966 dri2GalliumConfigQueryf(__DRIscreen
*sPriv
, const char *var
, float *val
)
1968 struct dri_screen
*screen
= dri_screen(sPriv
);
1970 if (!driCheckOption(&screen
->optionCache
, var
, DRI_FLOAT
))
1971 return dri2ConfigQueryExtension
.configQueryf(sPriv
, var
, val
);
1973 *val
= driQueryOptionf(&screen
->optionCache
, var
);
1979 * \brief the DRI2ConfigQueryExtension struct.
1981 * We first query the driver option cache. Then the dri2 option cache.
1983 static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension
= {
1984 .base
= { __DRI2_CONFIG_QUERY
, 1 },
1986 .configQueryb
= dri2GalliumConfigQueryb
,
1987 .configQueryi
= dri2GalliumConfigQueryi
,
1988 .configQueryf
= dri2GalliumConfigQueryf
,
1992 * Backend function init_screen.
1995 static const __DRIextension
*dri_screen_extensions
[] = {
1996 &driTexBufferExtension
.base
,
1997 &dri2FlushExtension
.base
,
1998 &dri2ImageExtension
.base
,
1999 &dri2RendererQueryExtension
.base
,
2000 &dri2GalliumConfigQueryExtension
.base
,
2001 &dri2ThrottleExtension
.base
,
2002 &dri2FenceExtension
.base
,
2003 &dri2InteropExtension
.base
,
2004 &dri2NoErrorExtension
.base
,
2008 static const __DRIextension
*dri_robust_screen_extensions
[] = {
2009 &driTexBufferExtension
.base
,
2010 &dri2FlushExtension
.base
,
2011 &dri2ImageExtension
.base
,
2012 &dri2RendererQueryExtension
.base
,
2013 &dri2GalliumConfigQueryExtension
.base
,
2014 &dri2ThrottleExtension
.base
,
2015 &dri2FenceExtension
.base
,
2016 &dri2InteropExtension
.base
,
2017 &dri2Robustness
.base
,
2018 &dri2NoErrorExtension
.base
,
2023 * This is the driver specific part of the createNewScreen entry point.
2025 * Returns the struct gl_config supported by this driver.
2027 static const __DRIconfig
**
2028 dri2_init_screen(__DRIscreen
* sPriv
)
2030 const __DRIconfig
**configs
;
2031 struct dri_screen
*screen
;
2032 struct pipe_screen
*pscreen
= NULL
;
2033 const struct drm_conf_ret
*throttle_ret
;
2034 const struct drm_conf_ret
*dmabuf_ret
;
2037 screen
= CALLOC_STRUCT(dri_screen
);
2041 screen
->sPriv
= sPriv
;
2042 screen
->fd
= sPriv
->fd
;
2043 (void) mtx_init(&screen
->opencl_func_mutex
, mtx_plain
);
2045 sPriv
->driverPrivate
= (void *)screen
;
2047 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
2051 if (pipe_loader_drm_probe_fd(&screen
->dev
, fd
)) {
2053 dri_init_options_get_screen_flags(screen
, screen
->dev
->driver_name
);
2055 pscreen
= pipe_loader_create_screen(screen
->dev
, flags
);
2061 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
2062 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
2064 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
2065 screen
->throttling_enabled
= TRUE
;
2066 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
2069 if (pscreen
->resource_create_with_modifiers
)
2070 dri2ImageExtension
.createImageWithModifiers
=
2071 dri2_create_image_with_modifiers
;
2073 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
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
=
2083 dri2_query_dma_buf_modifiers
;
2087 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
2088 sPriv
->extensions
= dri_robust_screen_extensions
;
2089 screen
->has_reset_status_query
= true;
2092 sPriv
->extensions
= dri_screen_extensions
;
2094 configs
= dri_init_screen_helper(screen
, pscreen
);
2096 goto destroy_screen
;
2098 screen
->can_share_buffer
= true;
2099 screen
->auto_fake_front
= dri_with_format(sPriv
);
2100 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2101 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2106 dri_destroy_screen_helper(screen
);
2110 pipe_loader_release(&screen
->dev
, 1);
2120 * This is the driver specific part of the createNewScreen entry point.
2122 * Returns the struct gl_config supported by this driver.
2124 static const __DRIconfig
**
2125 dri_kms_init_screen(__DRIscreen
* sPriv
)
2127 #if defined(GALLIUM_SOFTPIPE)
2128 const __DRIconfig
**configs
;
2129 struct dri_screen
*screen
;
2130 struct pipe_screen
*pscreen
= NULL
;
2134 screen
= CALLOC_STRUCT(dri_screen
);
2138 screen
->sPriv
= sPriv
;
2139 screen
->fd
= sPriv
->fd
;
2141 sPriv
->driverPrivate
= (void *)screen
;
2143 if (screen
->fd
< 0 || (fd
= fcntl(screen
->fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
2146 unsigned flags
= dri_init_options_get_screen_flags(screen
, "swrast");
2148 if (pipe_loader_sw_probe_kms(&screen
->dev
, fd
))
2149 pscreen
= pipe_loader_create_screen(screen
->dev
, flags
);
2154 if (pscreen
->resource_create_with_modifiers
)
2155 dri2ImageExtension
.createImageWithModifiers
=
2156 dri2_create_image_with_modifiers
;
2158 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2159 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2160 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2161 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2162 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2163 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2164 dri2ImageExtension
.queryDmaBufModifiers
= dri2_query_dma_buf_modifiers
;
2167 sPriv
->extensions
= dri_screen_extensions
;
2169 configs
= dri_init_screen_helper(screen
, pscreen
);
2171 goto destroy_screen
;
2173 screen
->can_share_buffer
= false;
2174 screen
->auto_fake_front
= dri_with_format(sPriv
);
2175 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2176 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2181 dri_destroy_screen_helper(screen
);
2185 pipe_loader_release(&screen
->dev
, 1);
2191 #endif // GALLIUM_SOFTPIPE
2196 dri2_create_buffer(__DRIscreen
* sPriv
,
2197 __DRIdrawable
* dPriv
,
2198 const struct gl_config
* visual
, boolean isPixmap
)
2200 struct dri_drawable
*drawable
= NULL
;
2202 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
2205 drawable
= dPriv
->driverPrivate
;
2207 drawable
->allocate_textures
= dri2_allocate_textures
;
2208 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
2209 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
2215 * DRI driver virtual function table.
2217 * DRI versions differ in their implementation of init_screen and swap_buffers.
2219 const struct __DriverAPIRec galliumdrm_driver_api
= {
2220 .InitScreen
= dri2_init_screen
,
2221 .DestroyScreen
= dri_destroy_screen
,
2222 .CreateContext
= dri_create_context
,
2223 .DestroyContext
= dri_destroy_context
,
2224 .CreateBuffer
= dri2_create_buffer
,
2225 .DestroyBuffer
= dri_destroy_buffer
,
2226 .MakeCurrent
= dri_make_current
,
2227 .UnbindContext
= dri_unbind_context
,
2229 .AllocateBuffer
= dri2_allocate_buffer
,
2230 .ReleaseBuffer
= dri2_release_buffer
,
2234 * DRI driver virtual function table.
2236 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
2237 * hook. The latter is used to explicitly initialise the kms_swrast driver
2238 * rather than selecting the approapriate driver as suggested by the loader.
2240 const struct __DriverAPIRec dri_kms_driver_api
= {
2241 .InitScreen
= dri_kms_init_screen
,
2242 .DestroyScreen
= dri_destroy_screen
,
2243 .CreateContext
= dri_create_context
,
2244 .DestroyContext
= dri_destroy_context
,
2245 .CreateBuffer
= dri2_create_buffer
,
2246 .DestroyBuffer
= dri_destroy_buffer
,
2247 .MakeCurrent
= dri_make_current
,
2248 .UnbindContext
= dri_unbind_context
,
2250 .AllocateBuffer
= dri2_allocate_buffer
,
2251 .ReleaseBuffer
= dri2_release_buffer
,
2254 /* This is the table of extensions that the loader will dlsym() for. */
2255 const __DRIextension
*galliumdrm_driver_extensions
[] = {
2256 &driCoreExtension
.base
,
2257 &driImageDriverExtension
.base
,
2258 &driDRI2Extension
.base
,
2259 &gallium_config_options
.base
,
2263 /* vim: set sw=3 ts=8 sts=3 expandtab: */