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>
32 #include "GL/mesa_glinterop.h"
33 #include "util/u_memory.h"
34 #include "util/u_inlines.h"
35 #include "util/u_format.h"
36 #include "util/u_debug.h"
37 #include "state_tracker/drm_driver.h"
38 #include "state_tracker/st_cb_bufferobjects.h"
39 #include "state_tracker/st_cb_fbo.h"
40 #include "state_tracker/st_cb_texture.h"
41 #include "state_tracker/st_texture.h"
42 #include "state_tracker/st_context.h"
43 #include "pipe-loader/pipe_loader.h"
44 #include "main/bufferobj.h"
45 #include "main/texobj.h"
49 #include "dri_helpers.h"
50 #include "dri_drawable.h"
51 #include "dri_query_renderer.h"
53 #ifndef DRM_FORMAT_MOD_INVALID
54 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
60 struct pipe_resource
*resource
;
63 static inline struct dri2_buffer
*
64 dri2_buffer(__DRIbuffer
* driBufferPriv
)
66 return (struct dri2_buffer
*) driBufferPriv
;
69 struct dri2_format_mapping
{
73 enum pipe_format pipe_format
;
76 static const struct dri2_format_mapping dri2_format_table
[] = {
77 { __DRI_IMAGE_FOURCC_ARGB2101010
, __DRI_IMAGE_FORMAT_ARGB2101010
,
78 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_B10G10R10A2_UNORM
},
79 { __DRI_IMAGE_FOURCC_XRGB2101010
, __DRI_IMAGE_FORMAT_XRGB2101010
,
80 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_B10G10R10X2_UNORM
},
81 { __DRI_IMAGE_FOURCC_ABGR2101010
, __DRI_IMAGE_FORMAT_ABGR2101010
,
82 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_R10G10B10A2_UNORM
},
83 { __DRI_IMAGE_FOURCC_XBGR2101010
, __DRI_IMAGE_FORMAT_XBGR2101010
,
84 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_R10G10B10X2_UNORM
},
85 { __DRI_IMAGE_FOURCC_ARGB8888
, __DRI_IMAGE_FORMAT_ARGB8888
,
86 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_BGRA8888_UNORM
},
87 { __DRI_IMAGE_FOURCC_ABGR8888
, __DRI_IMAGE_FORMAT_ABGR8888
,
88 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_RGBA8888_UNORM
},
89 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_FORMAT_SARGB8
,
90 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_BGRA8888_SRGB
},
91 { __DRI_IMAGE_FOURCC_XRGB8888
, __DRI_IMAGE_FORMAT_XRGB8888
,
92 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_BGRX8888_UNORM
},
93 { __DRI_IMAGE_FOURCC_XBGR8888
, __DRI_IMAGE_FORMAT_XBGR8888
,
94 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_RGBX8888_UNORM
},
95 { __DRI_IMAGE_FOURCC_ARGB1555
, __DRI_IMAGE_FORMAT_RGB565
,
96 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_B5G5R5A1_UNORM
},
97 { __DRI_IMAGE_FOURCC_RGB565
, __DRI_IMAGE_FORMAT_RGB565
,
98 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_B5G6R5_UNORM
},
99 { __DRI_IMAGE_FOURCC_R8
, __DRI_IMAGE_FORMAT_R8
,
100 __DRI_IMAGE_COMPONENTS_R
, PIPE_FORMAT_R8_UNORM
},
101 { __DRI_IMAGE_FOURCC_R16
, __DRI_IMAGE_FORMAT_R16
,
102 __DRI_IMAGE_COMPONENTS_R
, PIPE_FORMAT_R16_UNORM
},
103 { __DRI_IMAGE_FOURCC_GR88
, __DRI_IMAGE_FORMAT_GR88
,
104 __DRI_IMAGE_COMPONENTS_RG
, PIPE_FORMAT_RG88_UNORM
},
105 { __DRI_IMAGE_FOURCC_GR1616
, __DRI_IMAGE_FORMAT_GR88
,
106 __DRI_IMAGE_COMPONENTS_RG
, PIPE_FORMAT_RG1616_UNORM
},
107 { __DRI_IMAGE_FOURCC_YUV420
, __DRI_IMAGE_FORMAT_NONE
,
108 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
},
109 { __DRI_IMAGE_FOURCC_YVU420
, __DRI_IMAGE_FORMAT_NONE
,
110 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_YV12
},
111 { __DRI_IMAGE_FOURCC_NV12
, __DRI_IMAGE_FORMAT_NONE
,
112 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_NV12
},
113 { __DRI_IMAGE_FOURCC_YUYV
, __DRI_IMAGE_FORMAT_YUYV
,
114 __DRI_IMAGE_COMPONENTS_Y_XUXV
, PIPE_FORMAT_YUYV
},
117 static const struct dri2_format_mapping
*
118 dri2_get_mapping_by_fourcc(int fourcc
) {
119 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_format_table
); i
++) {
120 if (dri2_format_table
[i
].dri_fourcc
== fourcc
)
121 return &dri2_format_table
[i
];
127 static const struct dri2_format_mapping
*
128 dri2_get_mapping_by_format(int format
) {
129 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_format_table
); i
++) {
130 if (dri2_format_table
[i
].dri_format
== format
)
131 return &dri2_format_table
[i
];
138 * DRI2 flush extension.
141 dri2_flush_drawable(__DRIdrawable
*dPriv
)
143 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
147 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
149 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
151 dri2InvalidateDrawable(dPriv
);
152 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
153 drawable
->texture_mask
= 0;
155 p_atomic_inc(&drawable
->base
.stamp
);
158 static const __DRI2flushExtension dri2FlushExtension
= {
159 .base
= { __DRI2_FLUSH
, 4 },
161 .flush
= dri2_flush_drawable
,
162 .invalidate
= dri2_invalidate_drawable
,
163 .flush_with_flags
= dri_flush
,
167 * Retrieve __DRIbuffer from the DRI loader.
170 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
171 const enum st_attachment_type
*atts
,
174 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
175 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
177 __DRIbuffer
*buffers
;
179 unsigned attachments
[10];
180 unsigned num_attachments
, i
;
183 with_format
= dri_with_format(drawable
->sPriv
);
187 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
189 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
191 for (i
= 0; i
< *count
; i
++) {
192 enum pipe_format format
;
196 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
197 if (format
== PIPE_FORMAT_NONE
)
201 case ST_ATTACHMENT_FRONT_LEFT
:
205 att
= __DRI_BUFFER_FRONT_LEFT
;
207 case ST_ATTACHMENT_BACK_LEFT
:
208 att
= __DRI_BUFFER_BACK_LEFT
;
210 case ST_ATTACHMENT_FRONT_RIGHT
:
211 att
= __DRI_BUFFER_FRONT_RIGHT
;
213 case ST_ATTACHMENT_BACK_RIGHT
:
214 att
= __DRI_BUFFER_BACK_RIGHT
;
221 * In this switch statement we must support all formats that
222 * may occur as the stvis->color_format.
225 case PIPE_FORMAT_B10G10R10A2_UNORM
:
226 case PIPE_FORMAT_R10G10B10A2_UNORM
:
227 case PIPE_FORMAT_BGRA8888_UNORM
:
228 case PIPE_FORMAT_RGBA8888_UNORM
:
231 case PIPE_FORMAT_R10G10B10X2_UNORM
:
232 case PIPE_FORMAT_B10G10R10X2_UNORM
:
235 case PIPE_FORMAT_BGRX8888_UNORM
:
236 case PIPE_FORMAT_RGBX8888_UNORM
:
239 case PIPE_FORMAT_B5G6R5_UNORM
:
243 depth
= util_format_get_blocksizebits(format
);
244 assert(!"Unexpected format in dri2_drawable_get_buffers()");
247 attachments
[num_attachments
++] = att
;
249 attachments
[num_attachments
++] = depth
;
254 num_attachments
/= 2;
255 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
256 &dri_drawable
->w
, &dri_drawable
->h
,
257 attachments
, num_attachments
,
258 &num_buffers
, dri_drawable
->loaderPrivate
);
261 buffers
= loader
->getBuffers(dri_drawable
,
262 &dri_drawable
->w
, &dri_drawable
->h
,
263 attachments
, num_attachments
,
264 &num_buffers
, dri_drawable
->loaderPrivate
);
268 *count
= num_buffers
;
274 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
275 struct __DRIimageList
*images
,
276 const enum st_attachment_type
*statts
,
277 unsigned statts_count
)
279 __DRIdrawable
*dPriv
= drawable
->dPriv
;
280 __DRIscreen
*sPriv
= drawable
->sPriv
;
281 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
283 uint32_t buffer_mask
= 0;
286 for (i
= 0; i
< statts_count
; i
++) {
287 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
288 if (pf
== PIPE_FORMAT_NONE
)
292 case ST_ATTACHMENT_FRONT_LEFT
:
293 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
295 case ST_ATTACHMENT_BACK_LEFT
:
296 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
303 case PIPE_FORMAT_B5G5R5A1_UNORM
:
304 image_format
= __DRI_IMAGE_FORMAT_ARGB1555
;
306 case PIPE_FORMAT_B5G6R5_UNORM
:
307 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
309 case PIPE_FORMAT_BGRX8888_UNORM
:
310 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
312 case PIPE_FORMAT_BGRA8888_UNORM
:
313 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
315 case PIPE_FORMAT_RGBX8888_UNORM
:
316 image_format
= __DRI_IMAGE_FORMAT_XBGR8888
;
318 case PIPE_FORMAT_RGBA8888_UNORM
:
319 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
321 case PIPE_FORMAT_B10G10R10X2_UNORM
:
322 image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
324 case PIPE_FORMAT_B10G10R10A2_UNORM
:
325 image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
327 case PIPE_FORMAT_R10G10B10X2_UNORM
:
328 image_format
= __DRI_IMAGE_FORMAT_XBGR2101010
;
330 case PIPE_FORMAT_R10G10B10A2_UNORM
:
331 image_format
= __DRI_IMAGE_FORMAT_ABGR2101010
;
334 image_format
= __DRI_IMAGE_FORMAT_NONE
;
339 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
340 (uint32_t *) &drawable
->base
.stamp
,
341 dPriv
->loaderPrivate
, buffer_mask
,
346 dri2_allocate_buffer(__DRIscreen
*sPriv
,
347 unsigned attachment
, unsigned format
,
348 int width
, int height
)
350 struct dri_screen
*screen
= dri_screen(sPriv
);
351 struct dri2_buffer
*buffer
;
352 struct pipe_resource templ
;
355 struct winsys_handle whandle
;
357 switch (attachment
) {
358 case __DRI_BUFFER_FRONT_LEFT
:
359 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
360 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
362 case __DRI_BUFFER_BACK_LEFT
:
363 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
365 case __DRI_BUFFER_DEPTH
:
366 case __DRI_BUFFER_DEPTH_STENCIL
:
367 case __DRI_BUFFER_STENCIL
:
368 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
372 /* because we get the handle and stride */
373 bind
|= PIPE_BIND_SHARED
;
377 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
380 pf
= PIPE_FORMAT_B10G10R10X2_UNORM
;
383 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
386 pf
= PIPE_FORMAT_Z16_UNORM
;
392 buffer
= CALLOC_STRUCT(dri2_buffer
);
396 memset(&templ
, 0, sizeof(templ
));
399 templ
.target
= PIPE_TEXTURE_2D
;
400 templ
.last_level
= 0;
401 templ
.width0
= width
;
402 templ
.height0
= height
;
404 templ
.array_size
= 1;
407 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
408 if (!buffer
->resource
) {
413 memset(&whandle
, 0, sizeof(whandle
));
414 if (screen
->can_share_buffer
)
415 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
417 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
419 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
, NULL
,
420 buffer
->resource
, &whandle
,
421 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
);
423 buffer
->base
.attachment
= attachment
;
424 buffer
->base
.name
= whandle
.handle
;
425 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
426 buffer
->base
.pitch
= whandle
.stride
;
428 return &buffer
->base
;
432 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
434 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
436 pipe_resource_reference(&buffer
->resource
, NULL
);
441 * Backend functions for st_framebuffer interface.
445 dri2_allocate_textures(struct dri_context
*ctx
,
446 struct dri_drawable
*drawable
,
447 const enum st_attachment_type
*statts
,
448 unsigned statts_count
)
450 __DRIscreen
*sPriv
= drawable
->sPriv
;
451 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
452 struct dri_screen
*screen
= dri_screen(sPriv
);
453 struct pipe_resource templ
;
454 boolean alloc_depthstencil
= FALSE
;
456 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
457 /* Image specific variables */
458 struct __DRIimageList images
;
459 /* Dri2 specific variables */
460 __DRIbuffer
*buffers
= NULL
;
461 struct winsys_handle whandle
;
462 unsigned num_buffers
= statts_count
;
464 /* First get the buffers from the loader */
466 if (!dri_image_drawable_get_buffers(drawable
, &images
,
467 statts
, statts_count
))
471 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
472 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
473 drawable
->old_w
== dri_drawable
->w
&&
474 drawable
->old_h
== dri_drawable
->h
&&
475 memcmp(drawable
->old
, buffers
,
476 sizeof(__DRIbuffer
) * num_buffers
) == 0))
480 /* Second clean useless resources*/
482 /* See if we need a depth-stencil buffer. */
483 for (i
= 0; i
< statts_count
; i
++) {
484 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
485 alloc_depthstencil
= TRUE
;
490 /* Delete the resources we won't need. */
491 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
492 /* Don't delete the depth-stencil buffer, we can reuse it. */
493 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
496 /* Flush the texture before unreferencing, so that other clients can
497 * see what the driver has rendered.
499 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
500 struct pipe_context
*pipe
= ctx
->st
->pipe
;
501 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
504 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
507 if (drawable
->stvis
.samples
> 1) {
508 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
511 /* Don't delete MSAA resources for the attachments which are enabled,
512 * we can reuse them. */
513 for (j
= 0; j
< statts_count
; j
++) {
514 if (i
== statts
[j
]) {
521 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
526 /* Third use the buffers retrieved to fill the drawable info */
528 memset(&templ
, 0, sizeof(templ
));
529 templ
.target
= screen
->target
;
530 templ
.last_level
= 0;
532 templ
.array_size
= 1;
535 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
536 struct pipe_resource
**buf
=
537 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
538 struct pipe_resource
*texture
= images
.front
->texture
;
540 dri_drawable
->w
= texture
->width0
;
541 dri_drawable
->h
= texture
->height0
;
543 pipe_resource_reference(buf
, texture
);
546 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
547 struct pipe_resource
**buf
=
548 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
549 struct pipe_resource
*texture
= images
.back
->texture
;
551 dri_drawable
->w
= texture
->width0
;
552 dri_drawable
->h
= texture
->height0
;
554 pipe_resource_reference(buf
, texture
);
557 /* Note: if there is both a back and a front buffer,
558 * then they have the same size.
560 templ
.width0
= dri_drawable
->w
;
561 templ
.height0
= dri_drawable
->h
;
564 memset(&whandle
, 0, sizeof(whandle
));
566 /* Process DRI-provided buffers and get pipe_resources. */
567 for (i
= 0; i
< num_buffers
; i
++) {
568 __DRIbuffer
*buf
= &buffers
[i
];
569 enum st_attachment_type statt
;
570 enum pipe_format format
;
572 switch (buf
->attachment
) {
573 case __DRI_BUFFER_FRONT_LEFT
:
574 if (!screen
->auto_fake_front
) {
575 continue; /* invalid attachment */
578 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
579 statt
= ST_ATTACHMENT_FRONT_LEFT
;
581 case __DRI_BUFFER_BACK_LEFT
:
582 statt
= ST_ATTACHMENT_BACK_LEFT
;
585 continue; /* invalid attachment */
588 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
589 if (format
== PIPE_FORMAT_NONE
)
592 /* dri2_drawable_get_buffers has already filled dri_drawable->w
593 * and dri_drawable->h */
594 templ
.width0
= dri_drawable
->w
;
595 templ
.height0
= dri_drawable
->h
;
596 templ
.format
= format
;
598 whandle
.handle
= buf
->name
;
599 whandle
.stride
= buf
->pitch
;
601 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
602 if (screen
->can_share_buffer
)
603 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
605 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
606 drawable
->textures
[statt
] =
607 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
609 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
);
610 assert(drawable
->textures
[statt
]);
614 /* Allocate private MSAA colorbuffers. */
615 if (drawable
->stvis
.samples
> 1) {
616 for (i
= 0; i
< statts_count
; i
++) {
617 enum st_attachment_type statt
= statts
[i
];
619 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
622 if (drawable
->textures
[statt
]) {
623 templ
.format
= drawable
->textures
[statt
]->format
;
624 templ
.bind
= drawable
->textures
[statt
]->bind
&
625 ~(PIPE_BIND_SCANOUT
| PIPE_BIND_SHARED
);
626 templ
.nr_samples
= drawable
->stvis
.samples
;
627 templ
.nr_storage_samples
= drawable
->stvis
.samples
;
629 /* Try to reuse the resource.
630 * (the other resource parameters should be constant)
632 if (!drawable
->msaa_textures
[statt
] ||
633 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
634 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
635 /* Allocate a new one. */
636 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
638 drawable
->msaa_textures
[statt
] =
639 screen
->base
.screen
->resource_create(screen
->base
.screen
,
641 assert(drawable
->msaa_textures
[statt
]);
643 /* If there are any MSAA resources, we should initialize them
644 * such that they contain the same data as the single-sample
645 * resources we just got from the X server.
647 * The reason for this is that the state tracker (and
648 * therefore the app) can access the MSAA resources only.
649 * The single-sample resources are not exposed
650 * to the state tracker.
653 dri_pipe_blit(ctx
->st
->pipe
,
654 drawable
->msaa_textures
[statt
],
655 drawable
->textures
[statt
]);
659 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
664 /* Allocate a private depth-stencil buffer. */
665 if (alloc_depthstencil
) {
666 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
667 struct pipe_resource
**zsbuf
;
668 enum pipe_format format
;
671 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
674 templ
.format
= format
;
675 templ
.bind
= bind
& ~PIPE_BIND_SHARED
;
677 if (drawable
->stvis
.samples
> 1) {
678 templ
.nr_samples
= drawable
->stvis
.samples
;
679 templ
.nr_storage_samples
= drawable
->stvis
.samples
;
680 zsbuf
= &drawable
->msaa_textures
[statt
];
683 templ
.nr_samples
= 0;
684 templ
.nr_storage_samples
= 0;
685 zsbuf
= &drawable
->textures
[statt
];
688 /* Try to reuse the resource.
689 * (the other resource parameters should be constant)
692 (*zsbuf
)->width0
!= templ
.width0
||
693 (*zsbuf
)->height0
!= templ
.height0
) {
694 /* Allocate a new one. */
695 pipe_resource_reference(zsbuf
, NULL
);
696 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
702 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
703 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
707 /* For DRI2, we may get the same buffers again from the server.
708 * To prevent useless imports of gem names, drawable->old* is used
709 * to bypass the import if we get the same buffers. This doesn't apply
710 * to DRI3/Wayland, users of image.loader, since the buffer is managed
711 * by the client (no import), and the back buffer is going to change
715 drawable
->old_num
= num_buffers
;
716 drawable
->old_w
= dri_drawable
->w
;
717 drawable
->old_h
= dri_drawable
->h
;
718 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
723 dri2_flush_frontbuffer(struct dri_context
*ctx
,
724 struct dri_drawable
*drawable
,
725 enum st_attachment_type statt
)
727 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
728 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
729 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
730 struct pipe_context
*pipe
= ctx
->st
->pipe
;
732 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
735 if (drawable
->stvis
.samples
> 1) {
736 /* Resolve the front buffer. */
737 dri_pipe_blit(ctx
->st
->pipe
,
738 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
739 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
742 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
743 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
746 pipe
->flush(pipe
, NULL
, 0);
749 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
751 else if (loader
->flushFrontBuffer
) {
752 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
757 * The struct dri_drawable flush_swapbuffers callback
760 dri2_flush_swapbuffers(struct dri_context
*ctx
,
761 struct dri_drawable
*drawable
)
763 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
764 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
766 if (image
&& image
->base
.version
>= 3 && image
->flushSwapBuffers
) {
767 image
->flushSwapBuffers(dri_drawable
, dri_drawable
->loaderPrivate
);
772 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
773 struct dri_context
*ctx
,
774 struct pipe_resource
*res
)
780 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
781 int width
, int height
, enum pipe_format pf
,
782 int num_handles
, struct winsys_handle
*whandle
,
785 struct dri_screen
*screen
= dri_screen(_screen
);
786 struct pipe_screen
*pscreen
= screen
->base
.screen
;
788 struct pipe_resource templ
;
789 unsigned tex_usage
= 0;
792 if (pscreen
->is_format_supported(pscreen
, pf
, screen
->target
, 0, 0,
793 PIPE_BIND_RENDER_TARGET
))
794 tex_usage
|= PIPE_BIND_RENDER_TARGET
;
795 if (pscreen
->is_format_supported(pscreen
, pf
, screen
->target
, 0, 0,
796 PIPE_BIND_SAMPLER_VIEW
))
797 tex_usage
|= PIPE_BIND_SAMPLER_VIEW
;
799 if (!tex_usage
&& util_format_is_yuv(pf
)) {
800 /* YUV format sampling can be emulated by the Mesa state tracker by
801 * using multiple R8/RG88 samplers. So try to rewrite the pipe format.
803 pf
= PIPE_FORMAT_R8_UNORM
;
805 if (pscreen
->is_format_supported(pscreen
, pf
, screen
->target
, 0, 0,
806 PIPE_BIND_SAMPLER_VIEW
))
807 tex_usage
|= PIPE_BIND_SAMPLER_VIEW
;
813 img
= CALLOC_STRUCT(__DRIimageRec
);
817 memset(&templ
, 0, sizeof(templ
));
818 templ
.bind
= tex_usage
;
819 templ
.target
= screen
->target
;
820 templ
.last_level
= 0;
822 templ
.array_size
= 1;
824 for (i
= num_handles
- 1; i
>= 0; i
--) {
825 struct pipe_resource
*tex
;
827 /* TODO: something a lot less ugly */
830 templ
.width0
= width
;
831 templ
.height0
= height
;
835 templ
.width0
= width
/ 2;
836 templ
.height0
= height
/ 2;
837 templ
.format
= (num_handles
== 2) ?
838 PIPE_FORMAT_RG88_UNORM
: /* NV12, etc */
839 PIPE_FORMAT_R8_UNORM
; /* I420, etc */
842 templ
.width0
= width
/ 2;
843 templ
.height0
= height
/ 2;
844 templ
.format
= PIPE_FORMAT_R8_UNORM
;
847 unreachable("too many planes!");
850 tex
= pscreen
->resource_from_handle(pscreen
,
851 &templ
, &whandle
[i
], PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
);
853 pipe_resource_reference(&img
->texture
, NULL
);
858 tex
->next
= img
->texture
;
865 img
->loader_private
= loaderPrivate
;
871 dri2_create_image_from_name(__DRIscreen
*_screen
,
872 int width
, int height
, int format
,
873 int name
, int pitch
, void *loaderPrivate
)
875 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
876 struct winsys_handle whandle
;
882 memset(&whandle
, 0, sizeof(whandle
));
883 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
884 whandle
.handle
= name
;
885 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
887 whandle
.stride
= pitch
* util_format_get_blocksize(map
->pipe_format
);
889 img
= dri2_create_image_from_winsys(_screen
, width
, height
, map
->pipe_format
,
890 1, &whandle
, loaderPrivate
);
895 img
->dri_components
= map
->dri_components
;
896 img
->dri_fourcc
= map
->dri_fourcc
;
897 img
->dri_format
= map
->dri_format
;
903 dri2_create_image_from_fd(__DRIscreen
*_screen
,
904 int width
, int height
, int fourcc
,
905 uint64_t modifier
, int *fds
, int num_fds
,
906 int *strides
, int *offsets
, unsigned *error
,
909 struct winsys_handle whandles
[3];
910 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_fourcc(fourcc
);
911 __DRIimage
*img
= NULL
;
912 unsigned err
= __DRI_IMAGE_ERROR_SUCCESS
;
913 int expected_num_fds
, i
;
916 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
921 case __DRI_IMAGE_FOURCC_YUV420
:
922 case __DRI_IMAGE_FOURCC_YVU420
:
923 expected_num_fds
= 3;
925 case __DRI_IMAGE_FOURCC_NV12
:
926 expected_num_fds
= 2;
929 expected_num_fds
= 1;
933 if (num_fds
!= expected_num_fds
) {
934 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
938 memset(whandles
, 0, sizeof(whandles
));
940 for (i
= 0; i
< num_fds
; i
++) {
942 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
946 whandles
[i
].type
= WINSYS_HANDLE_TYPE_FD
;
947 whandles
[i
].handle
= (unsigned)fds
[i
];
948 whandles
[i
].stride
= (unsigned)strides
[i
];
949 whandles
[i
].offset
= (unsigned)offsets
[i
];
950 whandles
[i
].modifier
= modifier
;
953 if (fourcc
== __DRI_IMAGE_FOURCC_YVU420
) {
954 /* convert to YUV420 by swapping 2nd and 3rd planes: */
955 struct winsys_handle tmp
= whandles
[1];
956 whandles
[1] = whandles
[2];
958 fourcc
= __DRI_IMAGE_FOURCC_YUV420
;
959 map
= dri2_get_mapping_by_fourcc(fourcc
);
962 img
= dri2_create_image_from_winsys(_screen
, width
, height
, map
->pipe_format
,
963 num_fds
, whandles
, loaderPrivate
);
965 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
969 img
->dri_components
= map
->dri_components
;
970 img
->dri_fourcc
= fourcc
;
971 img
->dri_format
= map
->dri_format
;
981 dri2_create_image_common(__DRIscreen
*_screen
,
982 int width
, int height
,
983 int format
, unsigned int use
,
984 const uint64_t *modifiers
,
985 const unsigned count
,
988 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
989 struct dri_screen
*screen
= dri_screen(_screen
);
991 struct pipe_resource templ
;
997 /* createImageWithModifiers doesn't supply usage, and we should not get
998 * here with both modifiers and a usage flag.
1000 assert(!(use
&& (modifiers
!= NULL
)));
1002 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
1004 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1005 tex_usage
|= PIPE_BIND_SCANOUT
;
1006 if (use
& __DRI_IMAGE_USE_SHARE
)
1007 tex_usage
|= PIPE_BIND_SHARED
;
1008 if (use
& __DRI_IMAGE_USE_LINEAR
)
1009 tex_usage
|= PIPE_BIND_LINEAR
;
1010 if (use
& __DRI_IMAGE_USE_CURSOR
) {
1011 if (width
!= 64 || height
!= 64)
1013 tex_usage
|= PIPE_BIND_CURSOR
;
1016 img
= CALLOC_STRUCT(__DRIimageRec
);
1020 memset(&templ
, 0, sizeof(templ
));
1021 templ
.bind
= tex_usage
;
1022 templ
.format
= map
->pipe_format
;
1023 templ
.target
= PIPE_TEXTURE_2D
;
1024 templ
.last_level
= 0;
1025 templ
.width0
= width
;
1026 templ
.height0
= height
;
1028 templ
.array_size
= 1;
1033 ->resource_create_with_modifiers(screen
->base
.screen
,
1039 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
1040 if (!img
->texture
) {
1047 img
->dri_format
= format
;
1048 img
->dri_fourcc
= map
->dri_fourcc
;
1049 img
->dri_components
= 0;
1052 img
->loader_private
= loaderPrivate
;
1057 dri2_create_image(__DRIscreen
*_screen
,
1058 int width
, int height
, int format
,
1059 unsigned int use
, void *loaderPrivate
)
1061 return dri2_create_image_common(_screen
, width
, height
, format
, use
,
1062 NULL
/* modifiers */, 0 /* count */,
1067 dri2_create_image_with_modifiers(__DRIscreen
*dri_screen
,
1068 int width
, int height
, int format
,
1069 const uint64_t *modifiers
,
1070 const unsigned count
,
1071 void *loaderPrivate
)
1073 return dri2_create_image_common(dri_screen
, width
, height
, format
,
1074 0 /* use */, modifiers
, count
,
1079 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
1081 struct winsys_handle whandle
;
1084 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1085 usage
= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
;
1087 usage
= PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
;
1089 memset(&whandle
, 0, sizeof(whandle
));
1092 case __DRI_IMAGE_ATTRIB_STRIDE
:
1093 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1094 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1095 NULL
, image
->texture
, &whandle
, usage
))
1097 *value
= whandle
.stride
;
1099 case __DRI_IMAGE_ATTRIB_OFFSET
:
1100 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1101 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1102 NULL
, image
->texture
, &whandle
, usage
))
1104 *value
= whandle
.offset
;
1106 case __DRI_IMAGE_ATTRIB_HANDLE
:
1107 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1108 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1109 NULL
, image
->texture
, &whandle
, usage
))
1111 *value
= whandle
.handle
;
1113 case __DRI_IMAGE_ATTRIB_NAME
:
1114 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
1115 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1116 NULL
, image
->texture
, &whandle
, usage
))
1118 *value
= whandle
.handle
;
1120 case __DRI_IMAGE_ATTRIB_FD
:
1121 whandle
.type
= WINSYS_HANDLE_TYPE_FD
;
1122 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1123 NULL
, image
->texture
, &whandle
, usage
))
1126 *value
= whandle
.handle
;
1128 case __DRI_IMAGE_ATTRIB_FORMAT
:
1129 *value
= image
->dri_format
;
1131 case __DRI_IMAGE_ATTRIB_WIDTH
:
1132 *value
= image
->texture
->width0
;
1134 case __DRI_IMAGE_ATTRIB_HEIGHT
:
1135 *value
= image
->texture
->height0
;
1137 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
1138 if (image
->dri_components
== 0)
1140 *value
= image
->dri_components
;
1142 case __DRI_IMAGE_ATTRIB_FOURCC
:
1143 if (image
->dri_fourcc
) {
1144 *value
= image
->dri_fourcc
;
1146 const struct dri2_format_mapping
*map
;
1148 map
= dri2_get_mapping_by_format(image
->dri_format
);
1152 *value
= map
->dri_fourcc
;
1155 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1158 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1159 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1160 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1161 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1162 NULL
, image
->texture
, &whandle
, usage
))
1164 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1166 *value
= (whandle
.modifier
>> 32) & 0xffffffff;
1168 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1169 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1170 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1171 if (!image
->texture
->screen
->resource_get_handle(image
->texture
->screen
,
1172 NULL
, image
->texture
, &whandle
, usage
))
1174 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1176 *value
= whandle
.modifier
& 0xffffffff;
1184 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
1188 img
= CALLOC_STRUCT(__DRIimageRec
);
1192 img
->texture
= NULL
;
1193 pipe_resource_reference(&img
->texture
, image
->texture
);
1194 img
->level
= image
->level
;
1195 img
->layer
= image
->layer
;
1196 img
->dri_format
= image
->dri_format
;
1197 /* This should be 0 for sub images, but dup is also used for base images. */
1198 img
->dri_components
= image
->dri_components
;
1199 img
->loader_private
= loaderPrivate
;
1205 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
1207 if (!image
|| !image
->texture
)
1210 struct pipe_screen
*screen
= image
->texture
->screen
;
1211 if (!screen
->check_resource_capability
)
1214 /* We don't want to check these:
1215 * __DRI_IMAGE_USE_SHARE (all images are shareable)
1216 * __DRI_IMAGE_USE_BACKBUFFER (all images support this)
1219 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1220 bind
|= PIPE_BIND_SCANOUT
;
1221 if (use
& __DRI_IMAGE_USE_LINEAR
)
1222 bind
|= PIPE_BIND_LINEAR
;
1223 if (use
& __DRI_IMAGE_USE_CURSOR
)
1224 bind
|= PIPE_BIND_CURSOR
;
1229 return screen
->check_resource_capability(screen
, image
->texture
, bind
);
1233 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
1234 int *names
, int num_names
, int *strides
, int *offsets
,
1235 void *loaderPrivate
)
1237 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
1239 struct winsys_handle whandle
;
1247 memset(&whandle
, 0, sizeof(whandle
));
1248 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
1249 whandle
.handle
= names
[0];
1250 whandle
.stride
= strides
[0];
1251 whandle
.offset
= offsets
[0];
1252 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1254 img
= dri2_create_image_from_winsys(screen
, width
, height
, map
->pipe_format
,
1255 1, &whandle
, loaderPrivate
);
1259 img
->dri_components
= map
->dri_components
;
1260 img
->dri_fourcc
= map
->dri_fourcc
;
1261 img
->dri_format
= map
->pipe_format
;
1267 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1274 if (image
->dri_components
== 0)
1277 img
= dri2_dup_image(image
, loaderPrivate
);
1281 if (img
->texture
->screen
->resource_changed
)
1282 img
->texture
->screen
->resource_changed(img
->texture
->screen
,
1285 /* set this to 0 for sub images. */
1286 img
->dri_components
= 0;
1291 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1292 int *fds
, int num_fds
, int *strides
, int *offsets
,
1293 void *loaderPrivate
)
1295 return dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1296 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1297 strides
, offsets
, NULL
, loaderPrivate
);
1301 dri2_query_dma_buf_formats(__DRIscreen
*_screen
, int max
, int *formats
,
1304 struct dri_screen
*screen
= dri_screen(_screen
);
1305 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1308 for (i
= 0, j
= 0; (i
< ARRAY_SIZE(dri2_format_table
)) &&
1309 (j
< max
|| max
== 0); i
++) {
1310 const struct dri2_format_mapping
*map
= &dri2_format_table
[i
];
1312 /* The sRGB format is not a real FourCC as defined by drm_fourcc.h, so we
1313 * must not leak it out to clients.
1315 if (dri2_format_table
[i
].dri_fourcc
== __DRI_IMAGE_FOURCC_SARGB8888
)
1318 if (pscreen
->is_format_supported(pscreen
, map
->pipe_format
,
1319 screen
->target
, 0, 0,
1320 PIPE_BIND_RENDER_TARGET
) ||
1321 pscreen
->is_format_supported(pscreen
, map
->pipe_format
,
1322 screen
->target
, 0, 0,
1323 PIPE_BIND_SAMPLER_VIEW
)) {
1325 formats
[j
] = map
->dri_fourcc
;
1334 dri2_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1335 uint64_t *modifiers
, unsigned int *external_only
,
1338 struct dri_screen
*screen
= dri_screen(_screen
);
1339 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1340 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_fourcc(fourcc
);
1341 enum pipe_format format
;
1346 format
= map
->pipe_format
;
1348 if (pscreen
->query_dmabuf_modifiers
!= NULL
&&
1349 (pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, 0,
1350 PIPE_BIND_RENDER_TARGET
) ||
1351 pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, 0,
1352 PIPE_BIND_SAMPLER_VIEW
))) {
1353 pscreen
->query_dmabuf_modifiers(pscreen
, format
, max
, modifiers
,
1354 external_only
, count
);
1361 dri2_from_dma_bufs(__DRIscreen
*screen
,
1362 int width
, int height
, int fourcc
,
1363 int *fds
, int num_fds
,
1364 int *strides
, int *offsets
,
1365 enum __DRIYUVColorSpace yuv_color_space
,
1366 enum __DRISampleRange sample_range
,
1367 enum __DRIChromaSiting horizontal_siting
,
1368 enum __DRIChromaSiting vertical_siting
,
1370 void *loaderPrivate
)
1374 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1375 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1376 strides
, offsets
, error
, loaderPrivate
);
1380 img
->yuv_color_space
= yuv_color_space
;
1381 img
->sample_range
= sample_range
;
1382 img
->horizontal_siting
= horizontal_siting
;
1383 img
->vertical_siting
= vertical_siting
;
1385 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1390 dri2_from_dma_bufs2(__DRIscreen
*screen
,
1391 int width
, int height
, int fourcc
,
1392 uint64_t modifier
, int *fds
, int num_fds
,
1393 int *strides
, int *offsets
,
1394 enum __DRIYUVColorSpace yuv_color_space
,
1395 enum __DRISampleRange sample_range
,
1396 enum __DRIChromaSiting horizontal_siting
,
1397 enum __DRIChromaSiting vertical_siting
,
1399 void *loaderPrivate
)
1403 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1404 modifier
, fds
, num_fds
, strides
, offsets
,
1405 error
, loaderPrivate
);
1409 img
->yuv_color_space
= yuv_color_space
;
1410 img
->sample_range
= sample_range
;
1411 img
->horizontal_siting
= horizontal_siting
;
1412 img
->vertical_siting
= vertical_siting
;
1414 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1419 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1420 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1421 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1424 struct dri_context
*ctx
= dri_context(context
);
1425 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1426 struct pipe_screen
*screen
;
1427 struct pipe_fence_handle
*fence
;
1428 struct pipe_blit_info blit
;
1433 memset(&blit
, 0, sizeof(blit
));
1434 blit
.dst
.resource
= dst
->texture
;
1435 blit
.dst
.box
.x
= dstx0
;
1436 blit
.dst
.box
.y
= dsty0
;
1437 blit
.dst
.box
.width
= dstwidth
;
1438 blit
.dst
.box
.height
= dstheight
;
1439 blit
.dst
.box
.depth
= 1;
1440 blit
.dst
.format
= dst
->texture
->format
;
1441 blit
.src
.resource
= src
->texture
;
1442 blit
.src
.box
.x
= srcx0
;
1443 blit
.src
.box
.y
= srcy0
;
1444 blit
.src
.box
.width
= srcwidth
;
1445 blit
.src
.box
.height
= srcheight
;
1446 blit
.src
.box
.depth
= 1;
1447 blit
.src
.format
= src
->texture
->format
;
1448 blit
.mask
= PIPE_MASK_RGBA
;
1449 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1451 pipe
->blit(pipe
, &blit
);
1453 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1454 pipe
->flush_resource(pipe
, dst
->texture
);
1455 ctx
->st
->flush(ctx
->st
, 0, NULL
);
1456 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1457 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1458 pipe
->flush_resource(pipe
, dst
->texture
);
1459 ctx
->st
->flush(ctx
->st
, 0, &fence
);
1460 (void) screen
->fence_finish(screen
, NULL
, fence
, PIPE_TIMEOUT_INFINITE
);
1461 screen
->fence_reference(screen
, &fence
, NULL
);
1466 dri2_map_image(__DRIcontext
*context
, __DRIimage
*image
,
1467 int x0
, int y0
, int width
, int height
,
1468 unsigned int flags
, int *stride
, void **data
)
1470 struct dri_context
*ctx
= dri_context(context
);
1471 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1472 enum pipe_transfer_usage pipe_access
= 0;
1473 struct pipe_transfer
*trans
;
1476 if (!image
|| !data
|| *data
)
1479 if (flags
& __DRI_IMAGE_TRANSFER_READ
)
1480 pipe_access
|= PIPE_TRANSFER_READ
;
1481 if (flags
& __DRI_IMAGE_TRANSFER_WRITE
)
1482 pipe_access
|= PIPE_TRANSFER_WRITE
;
1484 map
= pipe_transfer_map(pipe
, image
->texture
,
1485 0, 0, pipe_access
, x0
, y0
, width
, height
,
1489 *stride
= trans
->stride
;
1496 dri2_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *data
)
1498 struct dri_context
*ctx
= dri_context(context
);
1499 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1501 pipe_transfer_unmap(pipe
, (struct pipe_transfer
*)data
);
1505 dri2_get_capabilities(__DRIscreen
*_screen
)
1507 struct dri_screen
*screen
= dri_screen(_screen
);
1509 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1512 /* The extension is modified during runtime if DRI_PRIME is detected */
1513 static __DRIimageExtension dri2ImageExtension
= {
1514 .base
= { __DRI_IMAGE
, 17 },
1516 .createImageFromName
= dri2_create_image_from_name
,
1517 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1518 .destroyImage
= dri2_destroy_image
,
1519 .createImage
= dri2_create_image
,
1520 .queryImage
= dri2_query_image
,
1521 .dupImage
= dri2_dup_image
,
1522 .validateUsage
= dri2_validate_usage
,
1523 .createImageFromNames
= dri2_from_names
,
1524 .fromPlanar
= dri2_from_planar
,
1525 .createImageFromTexture
= dri2_create_from_texture
,
1526 .createImageFromFds
= NULL
,
1527 .createImageFromDmaBufs
= NULL
,
1528 .blitImage
= dri2_blit_image
,
1529 .getCapabilities
= dri2_get_capabilities
,
1530 .mapImage
= dri2_map_image
,
1531 .unmapImage
= dri2_unmap_image
,
1532 .createImageWithModifiers
= NULL
,
1533 .createImageFromDmaBufs2
= NULL
,
1534 .queryDmaBufFormats
= NULL
,
1535 .queryDmaBufModifiers
= NULL
,
1536 .queryDmaBufFormatModifierAttribs
= NULL
,
1537 .createImageFromRenderbuffer2
= dri2_create_image_from_renderbuffer2
,
1540 static const __DRIrobustnessExtension dri2Robustness
= {
1541 .base
= { __DRI2_ROBUSTNESS
, 1 }
1545 dri2_interop_query_device_info(__DRIcontext
*_ctx
,
1546 struct mesa_glinterop_device_info
*out
)
1548 struct pipe_screen
*screen
= dri_context(_ctx
)->st
->pipe
->screen
;
1550 /* There is no version 0, thus we do not support it */
1551 if (out
->version
== 0)
1552 return MESA_GLINTEROP_INVALID_VERSION
;
1554 out
->pci_segment_group
= screen
->get_param(screen
, PIPE_CAP_PCI_GROUP
);
1555 out
->pci_bus
= screen
->get_param(screen
, PIPE_CAP_PCI_BUS
);
1556 out
->pci_device
= screen
->get_param(screen
, PIPE_CAP_PCI_DEVICE
);
1557 out
->pci_function
= screen
->get_param(screen
, PIPE_CAP_PCI_FUNCTION
);
1559 out
->vendor_id
= screen
->get_param(screen
, PIPE_CAP_VENDOR_ID
);
1560 out
->device_id
= screen
->get_param(screen
, PIPE_CAP_DEVICE_ID
);
1562 /* Instruct the caller that we support up-to version one of the interface */
1565 return MESA_GLINTEROP_SUCCESS
;
1569 dri2_interop_export_object(__DRIcontext
*_ctx
,
1570 struct mesa_glinterop_export_in
*in
,
1571 struct mesa_glinterop_export_out
*out
)
1573 struct st_context_iface
*st
= dri_context(_ctx
)->st
;
1574 struct pipe_screen
*screen
= st
->pipe
->screen
;
1575 struct gl_context
*ctx
= ((struct st_context
*)st
)->ctx
;
1576 struct pipe_resource
*res
= NULL
;
1577 struct winsys_handle whandle
;
1578 unsigned target
, usage
;
1581 /* There is no version 0, thus we do not support it */
1582 if (in
->version
== 0 || out
->version
== 0)
1583 return MESA_GLINTEROP_INVALID_VERSION
;
1585 /* Validate the target. */
1586 switch (in
->target
) {
1587 case GL_TEXTURE_BUFFER
:
1591 case GL_TEXTURE_RECTANGLE
:
1592 case GL_TEXTURE_1D_ARRAY
:
1593 case GL_TEXTURE_2D_ARRAY
:
1594 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1595 case GL_TEXTURE_CUBE_MAP
:
1596 case GL_TEXTURE_2D_MULTISAMPLE
:
1597 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1598 case GL_TEXTURE_EXTERNAL_OES
:
1599 case GL_RENDERBUFFER
:
1600 case GL_ARRAY_BUFFER
:
1601 target
= in
->target
;
1603 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1604 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1605 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1609 target
= GL_TEXTURE_CUBE_MAP
;
1612 return MESA_GLINTEROP_INVALID_TARGET
;
1615 /* Validate the simple case of miplevel. */
1616 if ((target
== GL_RENDERBUFFER
|| target
== GL_ARRAY_BUFFER
) &&
1618 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1620 /* Validate the OpenGL object and get pipe_resource. */
1621 simple_mtx_lock(&ctx
->Shared
->Mutex
);
1623 if (target
== GL_ARRAY_BUFFER
) {
1626 * The error checking is based on the documentation of
1627 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1629 struct gl_buffer_object
*buf
= _mesa_lookup_bufferobj(ctx
, in
->obj
);
1631 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1632 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1633 * a GL buffer object but does not have an existing data store or
1634 * the size of the buffer is 0."
1636 if (!buf
|| buf
->Size
== 0) {
1637 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1638 return MESA_GLINTEROP_INVALID_OBJECT
;
1641 res
= st_buffer_object(buf
)->buffer
;
1643 /* this shouldn't happen */
1644 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1645 return MESA_GLINTEROP_INVALID_OBJECT
;
1648 out
->buf_offset
= 0;
1649 out
->buf_size
= buf
->Size
;
1651 buf
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1652 } else if (target
== GL_RENDERBUFFER
) {
1655 * The error checking is based on the documentation of
1656 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1658 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, in
->obj
);
1660 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1661 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1662 * object or if the width or height of renderbuffer is zero."
1664 if (!rb
|| rb
->Width
== 0 || rb
->Height
== 0) {
1665 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1666 return MESA_GLINTEROP_INVALID_OBJECT
;
1669 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1670 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1671 * renderbuffer object."
1673 if (rb
->NumSamples
> 1) {
1674 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1675 return MESA_GLINTEROP_INVALID_OPERATION
;
1678 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1679 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1680 * required by the OpenCL implementation on the device."
1682 res
= st_renderbuffer(rb
)->texture
;
1684 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1685 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1688 out
->internal_format
= rb
->InternalFormat
;
1689 out
->view_minlevel
= 0;
1690 out
->view_numlevels
= 1;
1691 out
->view_minlayer
= 0;
1692 out
->view_numlayers
= 1;
1696 * The error checking is based on the documentation of
1697 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1699 struct gl_texture_object
*obj
= _mesa_lookup_texture(ctx
, in
->obj
);
1702 _mesa_test_texobj_completeness(ctx
, obj
);
1704 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1705 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1706 * type matches texture_target, if the specified miplevel of texture
1707 * is not defined, or if the width or height of the specified
1708 * miplevel is zero or if the GL texture object is incomplete."
1711 obj
->Target
!= target
||
1712 !obj
->_BaseComplete
||
1713 (in
->miplevel
> 0 && !obj
->_MipmapComplete
)) {
1714 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1715 return MESA_GLINTEROP_INVALID_OBJECT
;
1718 if (target
== GL_TEXTURE_BUFFER
) {
1719 struct st_buffer_object
*stBuf
=
1720 st_buffer_object(obj
->BufferObject
);
1722 if (!stBuf
|| !stBuf
->buffer
) {
1723 /* this shouldn't happen */
1724 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1725 return MESA_GLINTEROP_INVALID_OBJECT
;
1727 res
= stBuf
->buffer
;
1729 out
->internal_format
= obj
->BufferObjectFormat
;
1730 out
->buf_offset
= obj
->BufferOffset
;
1731 out
->buf_size
= obj
->BufferSize
== -1 ? obj
->BufferObject
->Size
:
1734 obj
->BufferObject
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1736 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1737 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1738 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1739 * implementations); or greater than the value of q (for both OpenGL
1740 * and OpenGL ES). levelbase and q are defined for the texture in
1741 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1742 * specification and section 3.7.10 of the OpenGL ES 2.0."
1744 if (in
->miplevel
< obj
->BaseLevel
|| in
->miplevel
> obj
->_MaxLevel
) {
1745 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1746 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1749 if (!st_finalize_texture(ctx
, st
->pipe
, obj
, 0)) {
1750 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1751 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1754 res
= st_get_texobj_resource(obj
);
1756 /* Incomplete texture buffer object? This shouldn't really occur. */
1757 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1758 return MESA_GLINTEROP_INVALID_OBJECT
;
1761 out
->internal_format
= obj
->Image
[0][0]->InternalFormat
;
1762 out
->view_minlevel
= obj
->MinLevel
;
1763 out
->view_numlevels
= obj
->NumLevels
;
1764 out
->view_minlayer
= obj
->MinLayer
;
1765 out
->view_numlayers
= obj
->NumLayers
;
1769 /* Get the handle. */
1770 switch (in
->access
) {
1771 case MESA_GLINTEROP_ACCESS_READ_ONLY
:
1774 case MESA_GLINTEROP_ACCESS_READ_WRITE
:
1775 case MESA_GLINTEROP_ACCESS_WRITE_ONLY
:
1776 usage
= PIPE_HANDLE_USAGE_SHADER_WRITE
;
1782 memset(&whandle
, 0, sizeof(whandle
));
1783 whandle
.type
= WINSYS_HANDLE_TYPE_FD
;
1785 success
= screen
->resource_get_handle(screen
, st
->pipe
, res
, &whandle
,
1787 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1790 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY
;
1792 out
->dmabuf_fd
= whandle
.handle
;
1793 out
->out_driver_data_written
= 0;
1795 if (res
->target
== PIPE_BUFFER
)
1796 out
->buf_offset
+= whandle
.offset
;
1798 /* Instruct the caller that we support up-to version one of the interface */
1802 return MESA_GLINTEROP_SUCCESS
;
1805 static const __DRI2interopExtension dri2InteropExtension
= {
1806 .base
= { __DRI2_INTEROP
, 1 },
1807 .query_device_info
= dri2_interop_query_device_info
,
1808 .export_object
= dri2_interop_export_object
1812 * \brief the DRI2ConfigQueryExtension configQueryb method
1815 dri2GalliumConfigQueryb(__DRIscreen
*sPriv
, const char *var
,
1818 struct dri_screen
*screen
= dri_screen(sPriv
);
1820 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_BOOL
))
1821 return dri2ConfigQueryExtension
.configQueryb(sPriv
, var
, val
);
1823 *val
= driQueryOptionb(&screen
->dev
->option_cache
, var
);
1829 * \brief the DRI2ConfigQueryExtension configQueryi method
1832 dri2GalliumConfigQueryi(__DRIscreen
*sPriv
, const char *var
, int *val
)
1834 struct dri_screen
*screen
= dri_screen(sPriv
);
1836 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_INT
) &&
1837 !driCheckOption(&screen
->dev
->option_cache
, var
, DRI_ENUM
))
1838 return dri2ConfigQueryExtension
.configQueryi(sPriv
, var
, val
);
1840 *val
= driQueryOptioni(&screen
->dev
->option_cache
, var
);
1846 * \brief the DRI2ConfigQueryExtension configQueryf method
1849 dri2GalliumConfigQueryf(__DRIscreen
*sPriv
, const char *var
, float *val
)
1851 struct dri_screen
*screen
= dri_screen(sPriv
);
1853 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_FLOAT
))
1854 return dri2ConfigQueryExtension
.configQueryf(sPriv
, var
, val
);
1856 *val
= driQueryOptionf(&screen
->dev
->option_cache
, var
);
1862 * \brief the DRI2ConfigQueryExtension struct.
1864 * We first query the driver option cache. Then the dri2 option cache.
1866 static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension
= {
1867 .base
= { __DRI2_CONFIG_QUERY
, 1 },
1869 .configQueryb
= dri2GalliumConfigQueryb
,
1870 .configQueryi
= dri2GalliumConfigQueryi
,
1871 .configQueryf
= dri2GalliumConfigQueryf
,
1875 * Backend function init_screen.
1878 static const __DRIextension
*dri_screen_extensions
[] = {
1879 &driTexBufferExtension
.base
,
1880 &dri2FlushExtension
.base
,
1881 &dri2ImageExtension
.base
,
1882 &dri2RendererQueryExtension
.base
,
1883 &dri2GalliumConfigQueryExtension
.base
,
1884 &dri2ThrottleExtension
.base
,
1885 &dri2FenceExtension
.base
,
1886 &dri2InteropExtension
.base
,
1887 &dri2NoErrorExtension
.base
,
1891 static const __DRIextension
*dri_robust_screen_extensions
[] = {
1892 &driTexBufferExtension
.base
,
1893 &dri2FlushExtension
.base
,
1894 &dri2ImageExtension
.base
,
1895 &dri2RendererQueryExtension
.base
,
1896 &dri2GalliumConfigQueryExtension
.base
,
1897 &dri2ThrottleExtension
.base
,
1898 &dri2FenceExtension
.base
,
1899 &dri2InteropExtension
.base
,
1900 &dri2Robustness
.base
,
1901 &dri2NoErrorExtension
.base
,
1906 * This is the driver specific part of the createNewScreen entry point.
1908 * Returns the struct gl_config supported by this driver.
1910 static const __DRIconfig
**
1911 dri2_init_screen(__DRIscreen
* sPriv
)
1913 const __DRIconfig
**configs
;
1914 struct dri_screen
*screen
;
1915 struct pipe_screen
*pscreen
= NULL
;
1916 const struct drm_conf_ret
*throttle_ret
;
1917 const struct drm_conf_ret
*dmabuf_ret
;
1919 screen
= CALLOC_STRUCT(dri_screen
);
1923 screen
->sPriv
= sPriv
;
1924 screen
->fd
= sPriv
->fd
;
1925 (void) mtx_init(&screen
->opencl_func_mutex
, mtx_plain
);
1927 sPriv
->driverPrivate
= (void *)screen
;
1929 if (pipe_loader_drm_probe_fd(&screen
->dev
, screen
->fd
)) {
1930 dri_init_options(screen
);
1932 pscreen
= pipe_loader_create_screen(screen
->dev
);
1938 throttle_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_THROTTLE
);
1939 dmabuf_ret
= pipe_loader_configuration(screen
->dev
, DRM_CONF_SHARE_FD
);
1941 if (throttle_ret
&& throttle_ret
->val
.val_int
!= -1) {
1942 screen
->throttling_enabled
= TRUE
;
1943 screen
->default_throttle_frames
= throttle_ret
->val
.val_int
;
1946 if (pscreen
->resource_create_with_modifiers
)
1947 dri2ImageExtension
.createImageWithModifiers
=
1948 dri2_create_image_with_modifiers
;
1950 if (dmabuf_ret
&& dmabuf_ret
->val
.val_bool
) {
1953 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
1954 (cap
& DRM_PRIME_CAP_IMPORT
)) {
1955 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
1956 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
1957 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
1958 if (pscreen
->query_dmabuf_modifiers
) {
1959 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
1960 dri2ImageExtension
.queryDmaBufModifiers
=
1961 dri2_query_dma_buf_modifiers
;
1966 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
1967 sPriv
->extensions
= dri_robust_screen_extensions
;
1968 screen
->has_reset_status_query
= true;
1971 sPriv
->extensions
= dri_screen_extensions
;
1973 configs
= dri_init_screen_helper(screen
, pscreen
);
1975 goto destroy_screen
;
1977 screen
->can_share_buffer
= true;
1978 screen
->auto_fake_front
= dri_with_format(sPriv
);
1979 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
1980 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
1985 dri_destroy_screen_helper(screen
);
1989 pipe_loader_release(&screen
->dev
, 1);
1996 * This is the driver specific part of the createNewScreen entry point.
1998 * Returns the struct gl_config supported by this driver.
2000 static const __DRIconfig
**
2001 dri_kms_init_screen(__DRIscreen
* sPriv
)
2003 #if defined(GALLIUM_SOFTPIPE)
2004 const __DRIconfig
**configs
;
2005 struct dri_screen
*screen
;
2006 struct pipe_screen
*pscreen
= NULL
;
2009 screen
= CALLOC_STRUCT(dri_screen
);
2013 screen
->sPriv
= sPriv
;
2014 screen
->fd
= sPriv
->fd
;
2016 sPriv
->driverPrivate
= (void *)screen
;
2018 if (pipe_loader_sw_probe_kms(&screen
->dev
, screen
->fd
)) {
2019 dri_init_options(screen
);
2020 pscreen
= pipe_loader_create_screen(screen
->dev
);
2026 if (pscreen
->resource_create_with_modifiers
)
2027 dri2ImageExtension
.createImageWithModifiers
=
2028 dri2_create_image_with_modifiers
;
2030 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2031 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2032 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2033 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2034 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2035 if (pscreen
->query_dmabuf_modifiers
) {
2036 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2037 dri2ImageExtension
.queryDmaBufModifiers
= dri2_query_dma_buf_modifiers
;
2041 sPriv
->extensions
= dri_screen_extensions
;
2043 configs
= dri_init_screen_helper(screen
, pscreen
);
2045 goto destroy_screen
;
2047 screen
->can_share_buffer
= false;
2048 screen
->auto_fake_front
= dri_with_format(sPriv
);
2049 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2050 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2055 dri_destroy_screen_helper(screen
);
2059 pipe_loader_release(&screen
->dev
, 1);
2062 #endif // GALLIUM_SOFTPIPE
2067 dri2_create_buffer(__DRIscreen
* sPriv
,
2068 __DRIdrawable
* dPriv
,
2069 const struct gl_config
* visual
, boolean isPixmap
)
2071 struct dri_drawable
*drawable
= NULL
;
2073 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
2076 drawable
= dPriv
->driverPrivate
;
2078 drawable
->allocate_textures
= dri2_allocate_textures
;
2079 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
2080 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
2081 drawable
->flush_swapbuffers
= dri2_flush_swapbuffers
;
2087 * DRI driver virtual function table.
2089 * DRI versions differ in their implementation of init_screen and swap_buffers.
2091 const struct __DriverAPIRec galliumdrm_driver_api
= {
2092 .InitScreen
= dri2_init_screen
,
2093 .DestroyScreen
= dri_destroy_screen
,
2094 .CreateContext
= dri_create_context
,
2095 .DestroyContext
= dri_destroy_context
,
2096 .CreateBuffer
= dri2_create_buffer
,
2097 .DestroyBuffer
= dri_destroy_buffer
,
2098 .MakeCurrent
= dri_make_current
,
2099 .UnbindContext
= dri_unbind_context
,
2101 .AllocateBuffer
= dri2_allocate_buffer
,
2102 .ReleaseBuffer
= dri2_release_buffer
,
2106 * DRI driver virtual function table.
2108 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
2109 * hook. The latter is used to explicitly initialise the kms_swrast driver
2110 * rather than selecting the approapriate driver as suggested by the loader.
2112 const struct __DriverAPIRec dri_kms_driver_api
= {
2113 .InitScreen
= dri_kms_init_screen
,
2114 .DestroyScreen
= dri_destroy_screen
,
2115 .CreateContext
= dri_create_context
,
2116 .DestroyContext
= dri_destroy_context
,
2117 .CreateBuffer
= dri2_create_buffer
,
2118 .DestroyBuffer
= dri_destroy_buffer
,
2119 .MakeCurrent
= dri_make_current
,
2120 .UnbindContext
= dri_unbind_context
,
2122 .AllocateBuffer
= dri2_allocate_buffer
,
2123 .ReleaseBuffer
= dri2_release_buffer
,
2126 /* This is the table of extensions that the loader will dlsym() for. */
2127 const __DRIextension
*galliumdrm_driver_extensions
[] = {
2128 &driCoreExtension
.base
,
2129 &driImageDriverExtension
.base
,
2130 &driDRI2Extension
.base
,
2131 &gallium_config_options
.base
,
2135 /* vim: set sw=3 ts=8 sts=3 expandtab: */