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/disk_cache.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "util/format/u_format.h"
37 #include "util/u_debug.h"
38 #include "frontend/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"
50 #include "dri_helpers.h"
51 #include "dri_drawable.h"
52 #include "dri_query_renderer.h"
54 #include "drm-uapi/drm_fourcc.h"
59 struct pipe_resource
*resource
;
62 static inline struct dri2_buffer
*
63 dri2_buffer(__DRIbuffer
* driBufferPriv
)
65 return (struct dri2_buffer
*) driBufferPriv
;
69 * DRI2 flush extension.
72 dri2_flush_drawable(__DRIdrawable
*dPriv
)
74 dri_flush(dPriv
->driContextPriv
, dPriv
, __DRI2_FLUSH_DRAWABLE
, -1);
78 dri2_invalidate_drawable(__DRIdrawable
*dPriv
)
80 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
82 dri2InvalidateDrawable(dPriv
);
83 drawable
->dPriv
->lastStamp
= drawable
->dPriv
->dri2
.stamp
;
84 drawable
->texture_mask
= 0;
86 p_atomic_inc(&drawable
->base
.stamp
);
89 static const __DRI2flushExtension dri2FlushExtension
= {
90 .base
= { __DRI2_FLUSH
, 4 },
92 .flush
= dri2_flush_drawable
,
93 .invalidate
= dri2_invalidate_drawable
,
94 .flush_with_flags
= dri_flush
,
98 * Retrieve __DRIbuffer from the DRI loader.
101 dri2_drawable_get_buffers(struct dri_drawable
*drawable
,
102 const enum st_attachment_type
*atts
,
105 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
106 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
108 __DRIbuffer
*buffers
;
110 unsigned attachments
[10];
111 unsigned num_attachments
, i
;
114 with_format
= dri_with_format(drawable
->sPriv
);
118 /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */
120 attachments
[num_attachments
++] = __DRI_BUFFER_FRONT_LEFT
;
122 for (i
= 0; i
< *count
; i
++) {
123 enum pipe_format format
;
127 dri_drawable_get_format(drawable
, atts
[i
], &format
, &bind
);
128 if (format
== PIPE_FORMAT_NONE
)
132 case ST_ATTACHMENT_FRONT_LEFT
:
136 att
= __DRI_BUFFER_FRONT_LEFT
;
138 case ST_ATTACHMENT_BACK_LEFT
:
139 att
= __DRI_BUFFER_BACK_LEFT
;
141 case ST_ATTACHMENT_FRONT_RIGHT
:
142 att
= __DRI_BUFFER_FRONT_RIGHT
;
144 case ST_ATTACHMENT_BACK_RIGHT
:
145 att
= __DRI_BUFFER_BACK_RIGHT
;
152 * In this switch statement we must support all formats that
153 * may occur as the stvis->color_format.
156 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
159 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
162 case PIPE_FORMAT_B10G10R10A2_UNORM
:
163 case PIPE_FORMAT_R10G10B10A2_UNORM
:
164 case PIPE_FORMAT_BGRA8888_UNORM
:
165 case PIPE_FORMAT_RGBA8888_UNORM
:
168 case PIPE_FORMAT_R10G10B10X2_UNORM
:
169 case PIPE_FORMAT_B10G10R10X2_UNORM
:
172 case PIPE_FORMAT_BGRX8888_UNORM
:
173 case PIPE_FORMAT_RGBX8888_UNORM
:
176 case PIPE_FORMAT_B5G6R5_UNORM
:
180 depth
= util_format_get_blocksizebits(format
);
181 assert(!"Unexpected format in dri2_drawable_get_buffers()");
184 attachments
[num_attachments
++] = att
;
186 attachments
[num_attachments
++] = depth
;
191 num_attachments
/= 2;
192 buffers
= loader
->getBuffersWithFormat(dri_drawable
,
193 &dri_drawable
->w
, &dri_drawable
->h
,
194 attachments
, num_attachments
,
195 &num_buffers
, dri_drawable
->loaderPrivate
);
198 buffers
= loader
->getBuffers(dri_drawable
,
199 &dri_drawable
->w
, &dri_drawable
->h
,
200 attachments
, num_attachments
,
201 &num_buffers
, dri_drawable
->loaderPrivate
);
205 *count
= num_buffers
;
211 dri_image_drawable_get_buffers(struct dri_drawable
*drawable
,
212 struct __DRIimageList
*images
,
213 const enum st_attachment_type
*statts
,
214 unsigned statts_count
)
216 __DRIdrawable
*dPriv
= drawable
->dPriv
;
217 __DRIscreen
*sPriv
= drawable
->sPriv
;
218 unsigned int image_format
= __DRI_IMAGE_FORMAT_NONE
;
220 uint32_t buffer_mask
= 0;
223 for (i
= 0; i
< statts_count
; i
++) {
224 dri_drawable_get_format(drawable
, statts
[i
], &pf
, &bind
);
225 if (pf
== PIPE_FORMAT_NONE
)
229 case ST_ATTACHMENT_FRONT_LEFT
:
230 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
232 case ST_ATTACHMENT_BACK_LEFT
:
233 buffer_mask
|= __DRI_IMAGE_BUFFER_BACK
;
240 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
241 image_format
= __DRI_IMAGE_FORMAT_ABGR16161616F
;
243 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
244 image_format
= __DRI_IMAGE_FORMAT_XBGR16161616F
;
246 case PIPE_FORMAT_B5G5R5A1_UNORM
:
247 image_format
= __DRI_IMAGE_FORMAT_ARGB1555
;
249 case PIPE_FORMAT_B5G6R5_UNORM
:
250 image_format
= __DRI_IMAGE_FORMAT_RGB565
;
252 case PIPE_FORMAT_BGRX8888_UNORM
:
253 image_format
= __DRI_IMAGE_FORMAT_XRGB8888
;
255 case PIPE_FORMAT_BGRA8888_UNORM
:
256 image_format
= __DRI_IMAGE_FORMAT_ARGB8888
;
258 case PIPE_FORMAT_RGBX8888_UNORM
:
259 image_format
= __DRI_IMAGE_FORMAT_XBGR8888
;
261 case PIPE_FORMAT_RGBA8888_UNORM
:
262 image_format
= __DRI_IMAGE_FORMAT_ABGR8888
;
264 case PIPE_FORMAT_B10G10R10X2_UNORM
:
265 image_format
= __DRI_IMAGE_FORMAT_XRGB2101010
;
267 case PIPE_FORMAT_B10G10R10A2_UNORM
:
268 image_format
= __DRI_IMAGE_FORMAT_ARGB2101010
;
270 case PIPE_FORMAT_R10G10B10X2_UNORM
:
271 image_format
= __DRI_IMAGE_FORMAT_XBGR2101010
;
273 case PIPE_FORMAT_R10G10B10A2_UNORM
:
274 image_format
= __DRI_IMAGE_FORMAT_ABGR2101010
;
277 image_format
= __DRI_IMAGE_FORMAT_NONE
;
282 return (*sPriv
->image
.loader
->getBuffers
) (dPriv
, image_format
,
283 (uint32_t *) &drawable
->base
.stamp
,
284 dPriv
->loaderPrivate
, buffer_mask
,
289 dri2_allocate_buffer(__DRIscreen
*sPriv
,
290 unsigned attachment
, unsigned format
,
291 int width
, int height
)
293 struct dri_screen
*screen
= dri_screen(sPriv
);
294 struct dri2_buffer
*buffer
;
295 struct pipe_resource templ
;
298 struct winsys_handle whandle
;
300 switch (attachment
) {
301 case __DRI_BUFFER_FRONT_LEFT
:
302 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
303 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
305 case __DRI_BUFFER_BACK_LEFT
:
306 bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
308 case __DRI_BUFFER_DEPTH
:
309 case __DRI_BUFFER_DEPTH_STENCIL
:
310 case __DRI_BUFFER_STENCIL
:
311 bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
315 /* because we get the handle and stride */
316 bind
|= PIPE_BIND_SHARED
;
320 pf
= PIPE_FORMAT_R16G16B16A16_FLOAT
;
323 pf
= PIPE_FORMAT_R16G16B16X16_FLOAT
;
326 pf
= PIPE_FORMAT_BGRA8888_UNORM
;
329 pf
= PIPE_FORMAT_B10G10R10X2_UNORM
;
332 pf
= PIPE_FORMAT_BGRX8888_UNORM
;
335 pf
= PIPE_FORMAT_Z16_UNORM
;
341 buffer
= CALLOC_STRUCT(dri2_buffer
);
345 memset(&templ
, 0, sizeof(templ
));
348 templ
.target
= PIPE_TEXTURE_2D
;
349 templ
.last_level
= 0;
350 templ
.width0
= width
;
351 templ
.height0
= height
;
353 templ
.array_size
= 1;
356 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
357 if (!buffer
->resource
) {
362 memset(&whandle
, 0, sizeof(whandle
));
363 if (screen
->can_share_buffer
)
364 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
366 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
368 screen
->base
.screen
->resource_get_handle(screen
->base
.screen
, NULL
,
369 buffer
->resource
, &whandle
,
370 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
);
372 buffer
->base
.attachment
= attachment
;
373 buffer
->base
.name
= whandle
.handle
;
374 buffer
->base
.cpp
= util_format_get_blocksize(pf
);
375 buffer
->base
.pitch
= whandle
.stride
;
377 return &buffer
->base
;
381 dri2_release_buffer(__DRIscreen
*sPriv
, __DRIbuffer
*bPriv
)
383 struct dri2_buffer
*buffer
= dri2_buffer(bPriv
);
385 pipe_resource_reference(&buffer
->resource
, NULL
);
390 * Backend functions for st_framebuffer interface.
394 dri2_allocate_textures(struct dri_context
*ctx
,
395 struct dri_drawable
*drawable
,
396 const enum st_attachment_type
*statts
,
397 unsigned statts_count
)
399 __DRIscreen
*sPriv
= drawable
->sPriv
;
400 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
401 struct dri_screen
*screen
= dri_screen(sPriv
);
402 struct pipe_resource templ
;
403 boolean alloc_depthstencil
= FALSE
;
405 const __DRIimageLoaderExtension
*image
= sPriv
->image
.loader
;
406 /* Image specific variables */
407 struct __DRIimageList images
;
408 /* Dri2 specific variables */
409 __DRIbuffer
*buffers
= NULL
;
410 struct winsys_handle whandle
;
411 unsigned num_buffers
= statts_count
;
413 /* First get the buffers from the loader */
415 if (!dri_image_drawable_get_buffers(drawable
, &images
,
416 statts
, statts_count
))
420 buffers
= dri2_drawable_get_buffers(drawable
, statts
, &num_buffers
);
421 if (!buffers
|| (drawable
->old_num
== num_buffers
&&
422 drawable
->old_w
== dri_drawable
->w
&&
423 drawable
->old_h
== dri_drawable
->h
&&
424 memcmp(drawable
->old
, buffers
,
425 sizeof(__DRIbuffer
) * num_buffers
) == 0))
429 /* Second clean useless resources*/
431 /* See if we need a depth-stencil buffer. */
432 for (i
= 0; i
< statts_count
; i
++) {
433 if (statts
[i
] == ST_ATTACHMENT_DEPTH_STENCIL
) {
434 alloc_depthstencil
= TRUE
;
439 /* Delete the resources we won't need. */
440 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
441 /* Don't delete the depth-stencil buffer, we can reuse it. */
442 if (i
== ST_ATTACHMENT_DEPTH_STENCIL
&& alloc_depthstencil
)
445 /* Flush the texture before unreferencing, so that other clients can
446 * see what the driver has rendered.
448 if (i
!= ST_ATTACHMENT_DEPTH_STENCIL
&& drawable
->textures
[i
]) {
449 struct pipe_context
*pipe
= ctx
->st
->pipe
;
450 pipe
->flush_resource(pipe
, drawable
->textures
[i
]);
453 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
456 if (drawable
->stvis
.samples
> 1) {
457 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
460 /* Don't delete MSAA resources for the attachments which are enabled,
461 * we can reuse them. */
462 for (j
= 0; j
< statts_count
; j
++) {
463 if (i
== statts
[j
]) {
470 pipe_resource_reference(&drawable
->msaa_textures
[i
], NULL
);
475 /* Third use the buffers retrieved to fill the drawable info */
477 memset(&templ
, 0, sizeof(templ
));
478 templ
.target
= screen
->target
;
479 templ
.last_level
= 0;
481 templ
.array_size
= 1;
484 if (images
.image_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
485 struct pipe_resource
**buf
=
486 &drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
487 struct pipe_resource
*texture
= images
.front
->texture
;
489 dri_drawable
->w
= texture
->width0
;
490 dri_drawable
->h
= texture
->height0
;
492 pipe_resource_reference(buf
, texture
);
495 if (images
.image_mask
& __DRI_IMAGE_BUFFER_BACK
) {
496 struct pipe_resource
**buf
=
497 &drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
498 struct pipe_resource
*texture
= images
.back
->texture
;
500 dri_drawable
->w
= texture
->width0
;
501 dri_drawable
->h
= texture
->height0
;
503 pipe_resource_reference(buf
, texture
);
506 /* Note: if there is both a back and a front buffer,
507 * then they have the same size.
509 templ
.width0
= dri_drawable
->w
;
510 templ
.height0
= dri_drawable
->h
;
513 memset(&whandle
, 0, sizeof(whandle
));
515 /* Process DRI-provided buffers and get pipe_resources. */
516 for (i
= 0; i
< num_buffers
; i
++) {
517 __DRIbuffer
*buf
= &buffers
[i
];
518 enum st_attachment_type statt
;
519 enum pipe_format format
;
521 switch (buf
->attachment
) {
522 case __DRI_BUFFER_FRONT_LEFT
:
523 if (!screen
->auto_fake_front
) {
524 continue; /* invalid attachment */
527 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
528 statt
= ST_ATTACHMENT_FRONT_LEFT
;
530 case __DRI_BUFFER_BACK_LEFT
:
531 statt
= ST_ATTACHMENT_BACK_LEFT
;
534 continue; /* invalid attachment */
537 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
538 if (format
== PIPE_FORMAT_NONE
)
541 /* dri2_drawable_get_buffers has already filled dri_drawable->w
542 * and dri_drawable->h */
543 templ
.width0
= dri_drawable
->w
;
544 templ
.height0
= dri_drawable
->h
;
545 templ
.format
= format
;
547 whandle
.handle
= buf
->name
;
548 whandle
.stride
= buf
->pitch
;
550 whandle
.format
= format
;
551 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
552 if (screen
->can_share_buffer
)
553 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
555 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
556 drawable
->textures
[statt
] =
557 screen
->base
.screen
->resource_from_handle(screen
->base
.screen
,
559 PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
);
560 assert(drawable
->textures
[statt
]);
564 /* Allocate private MSAA colorbuffers. */
565 if (drawable
->stvis
.samples
> 1) {
566 for (i
= 0; i
< statts_count
; i
++) {
567 enum st_attachment_type statt
= statts
[i
];
569 if (statt
== ST_ATTACHMENT_DEPTH_STENCIL
)
572 if (drawable
->textures
[statt
]) {
573 templ
.format
= drawable
->textures
[statt
]->format
;
574 templ
.bind
= drawable
->textures
[statt
]->bind
&
575 ~(PIPE_BIND_SCANOUT
| PIPE_BIND_SHARED
);
576 templ
.nr_samples
= drawable
->stvis
.samples
;
577 templ
.nr_storage_samples
= drawable
->stvis
.samples
;
579 /* Try to reuse the resource.
580 * (the other resource parameters should be constant)
582 if (!drawable
->msaa_textures
[statt
] ||
583 drawable
->msaa_textures
[statt
]->width0
!= templ
.width0
||
584 drawable
->msaa_textures
[statt
]->height0
!= templ
.height0
) {
585 /* Allocate a new one. */
586 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
588 drawable
->msaa_textures
[statt
] =
589 screen
->base
.screen
->resource_create(screen
->base
.screen
,
591 assert(drawable
->msaa_textures
[statt
]);
593 /* If there are any MSAA resources, we should initialize them
594 * such that they contain the same data as the single-sample
595 * resources we just got from the X server.
597 * The reason for this is that the gallium frontend (and
598 * therefore the app) can access the MSAA resources only.
599 * The single-sample resources are not exposed
600 * to the gallium frontend.
603 dri_pipe_blit(ctx
->st
->pipe
,
604 drawable
->msaa_textures
[statt
],
605 drawable
->textures
[statt
]);
609 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
614 /* Allocate a private depth-stencil buffer. */
615 if (alloc_depthstencil
) {
616 enum st_attachment_type statt
= ST_ATTACHMENT_DEPTH_STENCIL
;
617 struct pipe_resource
**zsbuf
;
618 enum pipe_format format
;
621 dri_drawable_get_format(drawable
, statt
, &format
, &bind
);
624 templ
.format
= format
;
625 templ
.bind
= bind
& ~PIPE_BIND_SHARED
;
627 if (drawable
->stvis
.samples
> 1) {
628 templ
.nr_samples
= drawable
->stvis
.samples
;
629 templ
.nr_storage_samples
= drawable
->stvis
.samples
;
630 zsbuf
= &drawable
->msaa_textures
[statt
];
633 templ
.nr_samples
= 0;
634 templ
.nr_storage_samples
= 0;
635 zsbuf
= &drawable
->textures
[statt
];
638 /* Try to reuse the resource.
639 * (the other resource parameters should be constant)
642 (*zsbuf
)->width0
!= templ
.width0
||
643 (*zsbuf
)->height0
!= templ
.height0
) {
644 /* Allocate a new one. */
645 pipe_resource_reference(zsbuf
, NULL
);
646 *zsbuf
= screen
->base
.screen
->resource_create(screen
->base
.screen
,
652 pipe_resource_reference(&drawable
->msaa_textures
[statt
], NULL
);
653 pipe_resource_reference(&drawable
->textures
[statt
], NULL
);
657 /* For DRI2, we may get the same buffers again from the server.
658 * To prevent useless imports of gem names, drawable->old* is used
659 * to bypass the import if we get the same buffers. This doesn't apply
660 * to DRI3/Wayland, users of image.loader, since the buffer is managed
661 * by the client (no import), and the back buffer is going to change
665 drawable
->old_num
= num_buffers
;
666 drawable
->old_w
= dri_drawable
->w
;
667 drawable
->old_h
= dri_drawable
->h
;
668 memcpy(drawable
->old
, buffers
, sizeof(__DRIbuffer
) * num_buffers
);
673 dri2_flush_frontbuffer(struct dri_context
*ctx
,
674 struct dri_drawable
*drawable
,
675 enum st_attachment_type statt
)
677 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
678 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
679 const __DRIdri2LoaderExtension
*loader
= drawable
->sPriv
->dri2
.loader
;
680 struct pipe_context
*pipe
= ctx
->st
->pipe
;
682 if (statt
!= ST_ATTACHMENT_FRONT_LEFT
)
685 if (drawable
->stvis
.samples
> 1) {
686 /* Resolve the front buffer. */
687 dri_pipe_blit(ctx
->st
->pipe
,
688 drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
],
689 drawable
->msaa_textures
[ST_ATTACHMENT_FRONT_LEFT
]);
692 if (drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]) {
693 pipe
->flush_resource(pipe
, drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
]);
696 pipe
->flush(pipe
, NULL
, 0);
699 image
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
701 else if (loader
->flushFrontBuffer
) {
702 loader
->flushFrontBuffer(dri_drawable
, dri_drawable
->loaderPrivate
);
707 * The struct dri_drawable flush_swapbuffers callback
710 dri2_flush_swapbuffers(struct dri_context
*ctx
,
711 struct dri_drawable
*drawable
)
713 __DRIdrawable
*dri_drawable
= drawable
->dPriv
;
714 const __DRIimageLoaderExtension
*image
= drawable
->sPriv
->image
.loader
;
716 if (image
&& image
->base
.version
>= 3 && image
->flushSwapBuffers
) {
717 image
->flushSwapBuffers(dri_drawable
, dri_drawable
->loaderPrivate
);
722 dri2_update_tex_buffer(struct dri_drawable
*drawable
,
723 struct dri_context
*ctx
,
724 struct pipe_resource
*res
)
730 dri2_create_image_from_winsys(__DRIscreen
*_screen
,
731 int width
, int height
, const struct dri2_format_mapping
*map
,
732 int num_handles
, struct winsys_handle
*whandle
,
735 struct dri_screen
*screen
= dri_screen(_screen
);
736 struct pipe_screen
*pscreen
= screen
->base
.screen
;
738 struct pipe_resource templ
;
739 unsigned tex_usage
= 0;
741 bool use_lowered
= false;
743 if (pscreen
->is_format_supported(pscreen
, map
->pipe_format
, screen
->target
, 0, 0,
744 PIPE_BIND_RENDER_TARGET
))
745 tex_usage
|= PIPE_BIND_RENDER_TARGET
;
746 if (pscreen
->is_format_supported(pscreen
, map
->pipe_format
, screen
->target
, 0, 0,
747 PIPE_BIND_SAMPLER_VIEW
))
748 tex_usage
|= PIPE_BIND_SAMPLER_VIEW
;
750 if (!tex_usage
&& util_format_is_yuv(map
->pipe_format
)) {
751 /* YUV format sampling can be emulated by the GL gallium frontend by
752 * using multiple samplers of varying formats.
753 * If no tex_usage is set and we detect a YUV format,
754 * test for support of all planes' sampler formats and
755 * add sampler view usage.
758 if (dri2_yuv_dma_buf_supported(screen
, map
))
759 tex_usage
|= PIPE_BIND_SAMPLER_VIEW
;
765 img
= CALLOC_STRUCT(__DRIimageRec
);
769 memset(&templ
, 0, sizeof(templ
));
770 templ
.bind
= tex_usage
;
771 templ
.target
= screen
->target
;
772 templ
.last_level
= 0;
774 templ
.array_size
= 1;
776 for (i
= (use_lowered
? map
->nplanes
: num_handles
) - 1; i
>= 0; i
--) {
777 struct pipe_resource
*tex
;
779 templ
.next
= img
->texture
;
780 templ
.width0
= width
>> map
->planes
[i
].width_shift
;
781 templ
.height0
= height
>> map
->planes
[i
].height_shift
;
783 templ
.format
= dri2_get_pipe_format_for_dri_format(map
->planes
[i
].dri_format
);
785 templ
.format
= map
->pipe_format
;
786 assert(templ
.format
!= PIPE_FORMAT_NONE
);
788 tex
= pscreen
->resource_from_handle(pscreen
,
789 &templ
, &whandle
[use_lowered
? map
->planes
[i
].buffer_index
: i
],
790 PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
);
792 pipe_resource_reference(&img
->texture
, NULL
);
803 img
->loader_private
= loaderPrivate
;
809 dri2_create_image_from_name(__DRIscreen
*_screen
,
810 int width
, int height
, int format
,
811 int name
, int pitch
, void *loaderPrivate
)
813 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
814 struct winsys_handle whandle
;
820 memset(&whandle
, 0, sizeof(whandle
));
821 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
822 whandle
.handle
= name
;
823 whandle
.format
= map
->pipe_format
;
824 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
826 whandle
.stride
= pitch
* util_format_get_blocksize(map
->pipe_format
);
828 img
= dri2_create_image_from_winsys(_screen
, width
, height
, map
,
829 1, &whandle
, loaderPrivate
);
834 img
->dri_components
= map
->dri_components
;
835 img
->dri_fourcc
= map
->dri_fourcc
;
836 img
->dri_format
= map
->dri_format
;
842 dri2_get_modifier_num_planes(uint64_t modifier
, int fourcc
)
844 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_fourcc(fourcc
);
850 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS
:
851 case I915_FORMAT_MOD_Y_TILED_CCS
:
853 case DRM_FORMAT_MOD_BROADCOM_UIF
:
854 case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED
:
855 case DRM_FORMAT_MOD_LINEAR
:
856 /* DRM_FORMAT_MOD_NONE is the same as LINEAR */
857 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_EIGHT_GOB
:
858 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_FOUR_GOB
:
859 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_ONE_GOB
:
860 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB
:
861 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB
:
862 case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK_TWO_GOB
:
863 case DRM_FORMAT_MOD_QCOM_COMPRESSED
:
864 case DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED
:
865 case DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED
:
866 case DRM_FORMAT_MOD_VIVANTE_SUPER_TILED
:
867 case DRM_FORMAT_MOD_VIVANTE_TILED
:
868 /* FD_FORMAT_MOD_QCOM_TILED is not in drm_fourcc.h */
869 case I915_FORMAT_MOD_X_TILED
:
870 case I915_FORMAT_MOD_Y_TILED
:
871 case DRM_FORMAT_MOD_INVALID
:
879 dri2_create_image_from_fd(__DRIscreen
*_screen
,
880 int width
, int height
, int fourcc
,
881 uint64_t modifier
, int *fds
, int num_fds
,
882 int *strides
, int *offsets
, unsigned *error
,
885 struct winsys_handle whandles
[3];
886 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_fourcc(fourcc
);
887 __DRIimage
*img
= NULL
;
888 unsigned err
= __DRI_IMAGE_ERROR_SUCCESS
;
889 int i
, expected_num_fds
;
890 int num_handles
= dri2_get_modifier_num_planes(modifier
, fourcc
);
892 if (!map
|| num_handles
== 0) {
893 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
898 case DRM_FORMAT_YUYV
:
899 case DRM_FORMAT_UYVY
:
900 expected_num_fds
= 1;
903 expected_num_fds
= num_handles
;
907 if (num_fds
!= expected_num_fds
) {
908 err
= __DRI_IMAGE_ERROR_BAD_MATCH
;
912 memset(whandles
, 0, sizeof(whandles
));
914 for (i
= 0; i
< num_fds
; i
++) {
916 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
920 whandles
[i
].type
= WINSYS_HANDLE_TYPE_FD
;
921 whandles
[i
].handle
= (unsigned)fds
[i
];
922 whandles
[i
].stride
= (unsigned)strides
[i
];
923 whandles
[i
].offset
= (unsigned)offsets
[i
];
924 whandles
[i
].format
= map
->pipe_format
;
925 whandles
[i
].modifier
= modifier
;
926 whandles
[i
].plane
= i
;
929 img
= dri2_create_image_from_winsys(_screen
, width
, height
, map
,
930 num_fds
, whandles
, loaderPrivate
);
932 err
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
936 img
->dri_components
= map
->dri_components
;
937 img
->dri_fourcc
= fourcc
;
938 img
->dri_format
= map
->dri_format
;
939 img
->imported_dmabuf
= TRUE
;
949 dri2_create_image_common(__DRIscreen
*_screen
,
950 int width
, int height
,
951 int format
, unsigned int use
,
952 const uint64_t *modifiers
,
953 const unsigned count
,
956 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
957 struct dri_screen
*screen
= dri_screen(_screen
);
959 struct pipe_resource templ
;
965 tex_usage
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
967 if (use
& __DRI_IMAGE_USE_SCANOUT
)
968 tex_usage
|= PIPE_BIND_SCANOUT
;
969 if (use
& __DRI_IMAGE_USE_SHARE
)
970 tex_usage
|= PIPE_BIND_SHARED
;
971 if (use
& __DRI_IMAGE_USE_LINEAR
)
972 tex_usage
|= PIPE_BIND_LINEAR
;
973 if (use
& __DRI_IMAGE_USE_CURSOR
) {
974 if (width
!= 64 || height
!= 64)
976 tex_usage
|= PIPE_BIND_CURSOR
;
979 img
= CALLOC_STRUCT(__DRIimageRec
);
983 memset(&templ
, 0, sizeof(templ
));
984 templ
.bind
= tex_usage
;
985 templ
.format
= map
->pipe_format
;
986 templ
.target
= PIPE_TEXTURE_2D
;
987 templ
.last_level
= 0;
988 templ
.width0
= width
;
989 templ
.height0
= height
;
991 templ
.array_size
= 1;
996 ->resource_create_with_modifiers(screen
->base
.screen
,
1002 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
1003 if (!img
->texture
) {
1010 img
->dri_format
= format
;
1011 img
->dri_fourcc
= map
->dri_fourcc
;
1012 img
->dri_components
= 0;
1015 img
->loader_private
= loaderPrivate
;
1020 dri2_create_image(__DRIscreen
*_screen
,
1021 int width
, int height
, int format
,
1022 unsigned int use
, void *loaderPrivate
)
1024 return dri2_create_image_common(_screen
, width
, height
, format
, use
,
1025 NULL
/* modifiers */, 0 /* count */,
1030 dri2_create_image_with_modifiers(__DRIscreen
*dri_screen
,
1031 int width
, int height
, int format
,
1032 const uint64_t *modifiers
,
1033 const unsigned count
,
1034 void *loaderPrivate
)
1036 return dri2_create_image_common(dri_screen
, width
, height
, format
,
1037 __DRI_IMAGE_USE_SHARE
, modifiers
, count
,
1042 dri2_query_image_common(__DRIimage
*image
, int attrib
, int *value
)
1045 case __DRI_IMAGE_ATTRIB_FORMAT
:
1046 *value
= image
->dri_format
;
1048 case __DRI_IMAGE_ATTRIB_WIDTH
:
1049 *value
= image
->texture
->width0
;
1051 case __DRI_IMAGE_ATTRIB_HEIGHT
:
1052 *value
= image
->texture
->height0
;
1054 case __DRI_IMAGE_ATTRIB_COMPONENTS
:
1055 if (image
->dri_components
== 0)
1057 *value
= image
->dri_components
;
1059 case __DRI_IMAGE_ATTRIB_FOURCC
:
1060 if (image
->dri_fourcc
) {
1061 *value
= image
->dri_fourcc
;
1063 const struct dri2_format_mapping
*map
;
1065 map
= dri2_get_mapping_by_format(image
->dri_format
);
1069 *value
= map
->dri_fourcc
;
1078 dri2_query_image_by_resource_handle(__DRIimage
*image
, int attrib
, int *value
)
1080 struct pipe_screen
*pscreen
= image
->texture
->screen
;
1081 struct winsys_handle whandle
;
1083 memset(&whandle
, 0, sizeof(whandle
));
1084 whandle
.plane
= image
->plane
;
1087 case __DRI_IMAGE_ATTRIB_STRIDE
:
1088 case __DRI_IMAGE_ATTRIB_OFFSET
:
1089 case __DRI_IMAGE_ATTRIB_HANDLE
:
1090 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1092 case __DRI_IMAGE_ATTRIB_NAME
:
1093 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
1095 case __DRI_IMAGE_ATTRIB_FD
:
1096 whandle
.type
= WINSYS_HANDLE_TYPE_FD
;
1098 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1101 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1102 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1103 whandle
.type
= WINSYS_HANDLE_TYPE_KMS
;
1104 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1110 usage
= PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
;
1112 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1113 usage
|= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
;
1115 if (!pscreen
->resource_get_handle(pscreen
, NULL
, image
->texture
,
1120 case __DRI_IMAGE_ATTRIB_STRIDE
:
1121 *value
= whandle
.stride
;
1123 case __DRI_IMAGE_ATTRIB_OFFSET
:
1124 *value
= whandle
.offset
;
1126 case __DRI_IMAGE_ATTRIB_HANDLE
:
1127 case __DRI_IMAGE_ATTRIB_NAME
:
1128 case __DRI_IMAGE_ATTRIB_FD
:
1129 *value
= whandle
.handle
;
1131 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1132 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1134 *value
= (whandle
.modifier
>> 32) & 0xffffffff;
1136 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1137 if (whandle
.modifier
== DRM_FORMAT_MOD_INVALID
)
1139 *value
= whandle
.modifier
& 0xffffffff;
1147 dri2_resource_get_param(__DRIimage
*image
, enum pipe_resource_param param
,
1148 unsigned handle_usage
, uint64_t *value
)
1150 struct pipe_screen
*pscreen
= image
->texture
->screen
;
1151 if (!pscreen
->resource_get_param
)
1154 return pscreen
->resource_get_param(pscreen
, NULL
, image
->texture
,
1155 image
->plane
, 0, param
, handle_usage
,
1160 dri2_query_image_by_resource_param(__DRIimage
*image
, int attrib
, int *value
)
1162 enum pipe_resource_param param
;
1164 unsigned handle_usage
;
1166 if (!image
->texture
->screen
->resource_get_param
)
1170 case __DRI_IMAGE_ATTRIB_STRIDE
:
1171 param
= PIPE_RESOURCE_PARAM_STRIDE
;
1173 case __DRI_IMAGE_ATTRIB_OFFSET
:
1174 param
= PIPE_RESOURCE_PARAM_OFFSET
;
1176 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1177 param
= PIPE_RESOURCE_PARAM_NPLANES
;
1179 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1180 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1181 param
= PIPE_RESOURCE_PARAM_MODIFIER
;
1183 case __DRI_IMAGE_ATTRIB_HANDLE
:
1184 param
= PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS
;
1186 case __DRI_IMAGE_ATTRIB_NAME
:
1187 param
= PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED
;
1189 case __DRI_IMAGE_ATTRIB_FD
:
1190 param
= PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD
;
1196 handle_usage
= PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE
;
1198 if (image
->use
& __DRI_IMAGE_USE_BACKBUFFER
)
1199 handle_usage
|= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH
;
1201 if (!dri2_resource_get_param(image
, param
, handle_usage
, &res_param
))
1205 case __DRI_IMAGE_ATTRIB_STRIDE
:
1206 case __DRI_IMAGE_ATTRIB_OFFSET
:
1207 case __DRI_IMAGE_ATTRIB_NUM_PLANES
:
1208 if (res_param
> INT_MAX
)
1210 *value
= (int)res_param
;
1212 case __DRI_IMAGE_ATTRIB_HANDLE
:
1213 case __DRI_IMAGE_ATTRIB_NAME
:
1214 case __DRI_IMAGE_ATTRIB_FD
:
1215 if (res_param
> UINT_MAX
)
1217 *value
= (int)res_param
;
1219 case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER
:
1220 if (res_param
== DRM_FORMAT_MOD_INVALID
)
1222 *value
= (res_param
>> 32) & 0xffffffff;
1224 case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER
:
1225 if (res_param
== DRM_FORMAT_MOD_INVALID
)
1227 *value
= res_param
& 0xffffffff;
1235 dri2_query_image(__DRIimage
*image
, int attrib
, int *value
)
1237 if (dri2_query_image_common(image
, attrib
, value
))
1239 else if (dri2_query_image_by_resource_param(image
, attrib
, value
))
1241 else if (dri2_query_image_by_resource_handle(image
, attrib
, value
))
1248 dri2_dup_image(__DRIimage
*image
, void *loaderPrivate
)
1252 img
= CALLOC_STRUCT(__DRIimageRec
);
1256 img
->texture
= NULL
;
1257 pipe_resource_reference(&img
->texture
, image
->texture
);
1258 img
->level
= image
->level
;
1259 img
->layer
= image
->layer
;
1260 img
->dri_format
= image
->dri_format
;
1261 /* This should be 0 for sub images, but dup is also used for base images. */
1262 img
->dri_components
= image
->dri_components
;
1263 img
->loader_private
= loaderPrivate
;
1269 dri2_validate_usage(__DRIimage
*image
, unsigned int use
)
1271 if (!image
|| !image
->texture
)
1274 struct pipe_screen
*screen
= image
->texture
->screen
;
1275 if (!screen
->check_resource_capability
)
1278 /* We don't want to check these:
1279 * __DRI_IMAGE_USE_SHARE (all images are shareable)
1280 * __DRI_IMAGE_USE_BACKBUFFER (all images support this)
1283 if (use
& __DRI_IMAGE_USE_SCANOUT
)
1284 bind
|= PIPE_BIND_SCANOUT
;
1285 if (use
& __DRI_IMAGE_USE_LINEAR
)
1286 bind
|= PIPE_BIND_LINEAR
;
1287 if (use
& __DRI_IMAGE_USE_CURSOR
)
1288 bind
|= PIPE_BIND_CURSOR
;
1293 return screen
->check_resource_capability(screen
, image
->texture
, bind
);
1297 dri2_from_names(__DRIscreen
*screen
, int width
, int height
, int format
,
1298 int *names
, int num_names
, int *strides
, int *offsets
,
1299 void *loaderPrivate
)
1301 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_format(format
);
1303 struct winsys_handle whandle
;
1311 memset(&whandle
, 0, sizeof(whandle
));
1312 whandle
.type
= WINSYS_HANDLE_TYPE_SHARED
;
1313 whandle
.handle
= names
[0];
1314 whandle
.stride
= strides
[0];
1315 whandle
.offset
= offsets
[0];
1316 whandle
.format
= map
->pipe_format
;
1317 whandle
.modifier
= DRM_FORMAT_MOD_INVALID
;
1319 img
= dri2_create_image_from_winsys(screen
, width
, height
, map
,
1320 1, &whandle
, loaderPrivate
);
1324 img
->dri_components
= map
->dri_components
;
1325 img
->dri_fourcc
= map
->dri_fourcc
;
1326 img
->dri_format
= map
->pipe_format
;
1332 dri2_from_planar(__DRIimage
*image
, int plane
, void *loaderPrivate
)
1338 } else if (plane
> 0) {
1340 if (!dri2_resource_get_param(image
, PIPE_RESOURCE_PARAM_NPLANES
, 0,
1347 if (image
->dri_components
== 0) {
1349 if (!dri2_resource_get_param(image
, PIPE_RESOURCE_PARAM_MODIFIER
, 0,
1351 modifier
== DRM_FORMAT_MOD_INVALID
) {
1356 img
= dri2_dup_image(image
, loaderPrivate
);
1360 if (img
->texture
->screen
->resource_changed
)
1361 img
->texture
->screen
->resource_changed(img
->texture
->screen
,
1364 /* set this to 0 for sub images. */
1365 img
->dri_components
= 0;
1371 dri2_from_fds(__DRIscreen
*screen
, int width
, int height
, int fourcc
,
1372 int *fds
, int num_fds
, int *strides
, int *offsets
,
1373 void *loaderPrivate
)
1375 return dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1376 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1377 strides
, offsets
, NULL
, loaderPrivate
);
1381 dri2_query_dma_buf_modifiers(__DRIscreen
*_screen
, int fourcc
, int max
,
1382 uint64_t *modifiers
, unsigned int *external_only
,
1385 struct dri_screen
*screen
= dri_screen(_screen
);
1386 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1387 const struct dri2_format_mapping
*map
= dri2_get_mapping_by_fourcc(fourcc
);
1388 enum pipe_format format
;
1393 format
= map
->pipe_format
;
1395 if (pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, 0,
1396 PIPE_BIND_RENDER_TARGET
) ||
1397 pscreen
->is_format_supported(pscreen
, format
, screen
->target
, 0, 0,
1398 PIPE_BIND_SAMPLER_VIEW
) ||
1399 dri2_yuv_dma_buf_supported(screen
, map
)) {
1400 if (pscreen
->query_dmabuf_modifiers
!= NULL
)
1401 pscreen
->query_dmabuf_modifiers(pscreen
, format
, max
, modifiers
,
1402 external_only
, count
);
1411 dri2_query_dma_buf_format_modifier_attribs(__DRIscreen
*_screen
,
1412 uint32_t fourcc
, uint64_t modifier
,
1413 int attrib
, uint64_t *value
)
1415 struct dri_screen
*screen
= dri_screen(_screen
);
1416 struct pipe_screen
*pscreen
= screen
->base
.screen
;
1418 if (!pscreen
->query_dmabuf_modifiers
)
1422 case __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT
: {
1423 uint64_t mod_planes
= dri2_get_modifier_num_planes(modifier
, fourcc
);
1425 *value
= mod_planes
;
1426 return mod_planes
> 0;
1434 dri2_from_dma_bufs(__DRIscreen
*screen
,
1435 int width
, int height
, int fourcc
,
1436 int *fds
, int num_fds
,
1437 int *strides
, int *offsets
,
1438 enum __DRIYUVColorSpace yuv_color_space
,
1439 enum __DRISampleRange sample_range
,
1440 enum __DRIChromaSiting horizontal_siting
,
1441 enum __DRIChromaSiting vertical_siting
,
1443 void *loaderPrivate
)
1447 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1448 DRM_FORMAT_MOD_INVALID
, fds
, num_fds
,
1449 strides
, offsets
, error
, loaderPrivate
);
1453 img
->yuv_color_space
= yuv_color_space
;
1454 img
->sample_range
= sample_range
;
1455 img
->horizontal_siting
= horizontal_siting
;
1456 img
->vertical_siting
= vertical_siting
;
1458 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1463 dri2_from_dma_bufs2(__DRIscreen
*screen
,
1464 int width
, int height
, int fourcc
,
1465 uint64_t modifier
, int *fds
, int num_fds
,
1466 int *strides
, int *offsets
,
1467 enum __DRIYUVColorSpace yuv_color_space
,
1468 enum __DRISampleRange sample_range
,
1469 enum __DRIChromaSiting horizontal_siting
,
1470 enum __DRIChromaSiting vertical_siting
,
1472 void *loaderPrivate
)
1476 img
= dri2_create_image_from_fd(screen
, width
, height
, fourcc
,
1477 modifier
, fds
, num_fds
, strides
, offsets
,
1478 error
, loaderPrivate
);
1482 img
->yuv_color_space
= yuv_color_space
;
1483 img
->sample_range
= sample_range
;
1484 img
->horizontal_siting
= horizontal_siting
;
1485 img
->vertical_siting
= vertical_siting
;
1487 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
1492 dri2_blit_image(__DRIcontext
*context
, __DRIimage
*dst
, __DRIimage
*src
,
1493 int dstx0
, int dsty0
, int dstwidth
, int dstheight
,
1494 int srcx0
, int srcy0
, int srcwidth
, int srcheight
,
1497 struct dri_context
*ctx
= dri_context(context
);
1498 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1499 struct pipe_screen
*screen
;
1500 struct pipe_fence_handle
*fence
;
1501 struct pipe_blit_info blit
;
1506 memset(&blit
, 0, sizeof(blit
));
1507 blit
.dst
.resource
= dst
->texture
;
1508 blit
.dst
.box
.x
= dstx0
;
1509 blit
.dst
.box
.y
= dsty0
;
1510 blit
.dst
.box
.width
= dstwidth
;
1511 blit
.dst
.box
.height
= dstheight
;
1512 blit
.dst
.box
.depth
= 1;
1513 blit
.dst
.format
= dst
->texture
->format
;
1514 blit
.src
.resource
= src
->texture
;
1515 blit
.src
.box
.x
= srcx0
;
1516 blit
.src
.box
.y
= srcy0
;
1517 blit
.src
.box
.width
= srcwidth
;
1518 blit
.src
.box
.height
= srcheight
;
1519 blit
.src
.box
.depth
= 1;
1520 blit
.src
.format
= src
->texture
->format
;
1521 blit
.mask
= PIPE_MASK_RGBA
;
1522 blit
.filter
= PIPE_TEX_FILTER_NEAREST
;
1524 pipe
->blit(pipe
, &blit
);
1526 if (flush_flag
== __BLIT_FLAG_FLUSH
) {
1527 pipe
->flush_resource(pipe
, dst
->texture
);
1528 ctx
->st
->flush(ctx
->st
, 0, NULL
, NULL
, NULL
);
1529 } else if (flush_flag
== __BLIT_FLAG_FINISH
) {
1530 screen
= dri_screen(ctx
->sPriv
)->base
.screen
;
1531 pipe
->flush_resource(pipe
, dst
->texture
);
1532 ctx
->st
->flush(ctx
->st
, 0, &fence
, NULL
, NULL
);
1533 (void) screen
->fence_finish(screen
, NULL
, fence
, PIPE_TIMEOUT_INFINITE
);
1534 screen
->fence_reference(screen
, &fence
, NULL
);
1539 dri2_map_image(__DRIcontext
*context
, __DRIimage
*image
,
1540 int x0
, int y0
, int width
, int height
,
1541 unsigned int flags
, int *stride
, void **data
)
1543 struct dri_context
*ctx
= dri_context(context
);
1544 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1545 enum pipe_transfer_usage pipe_access
= 0;
1546 struct pipe_resource
*resource
= image
->texture
;
1547 struct pipe_transfer
*trans
;
1550 if (!image
|| !data
|| *data
)
1553 unsigned plane
= image
->plane
;
1554 if (plane
>= dri2_get_mapping_by_format(image
->dri_format
)->nplanes
)
1558 resource
= resource
->next
;
1560 if (flags
& __DRI_IMAGE_TRANSFER_READ
)
1561 pipe_access
|= PIPE_TRANSFER_READ
;
1562 if (flags
& __DRI_IMAGE_TRANSFER_WRITE
)
1563 pipe_access
|= PIPE_TRANSFER_WRITE
;
1565 map
= pipe_transfer_map(pipe
, resource
, 0, 0, pipe_access
, x0
, y0
,
1566 width
, height
, &trans
);
1569 *stride
= trans
->stride
;
1576 dri2_unmap_image(__DRIcontext
*context
, __DRIimage
*image
, void *data
)
1578 struct dri_context
*ctx
= dri_context(context
);
1579 struct pipe_context
*pipe
= ctx
->st
->pipe
;
1581 pipe_transfer_unmap(pipe
, (struct pipe_transfer
*)data
);
1585 dri2_get_capabilities(__DRIscreen
*_screen
)
1587 struct dri_screen
*screen
= dri_screen(_screen
);
1589 return (screen
->can_share_buffer
? __DRI_IMAGE_CAP_GLOBAL_NAMES
: 0);
1592 /* The extension is modified during runtime if DRI_PRIME is detected */
1593 static __DRIimageExtension dri2ImageExtension
= {
1594 .base
= { __DRI_IMAGE
, 17 },
1596 .createImageFromName
= dri2_create_image_from_name
,
1597 .createImageFromRenderbuffer
= dri2_create_image_from_renderbuffer
,
1598 .destroyImage
= dri2_destroy_image
,
1599 .createImage
= dri2_create_image
,
1600 .queryImage
= dri2_query_image
,
1601 .dupImage
= dri2_dup_image
,
1602 .validateUsage
= dri2_validate_usage
,
1603 .createImageFromNames
= dri2_from_names
,
1604 .fromPlanar
= dri2_from_planar
,
1605 .createImageFromTexture
= dri2_create_from_texture
,
1606 .createImageFromFds
= NULL
,
1607 .createImageFromDmaBufs
= NULL
,
1608 .blitImage
= dri2_blit_image
,
1609 .getCapabilities
= dri2_get_capabilities
,
1610 .mapImage
= dri2_map_image
,
1611 .unmapImage
= dri2_unmap_image
,
1612 .createImageWithModifiers
= NULL
,
1613 .createImageFromDmaBufs2
= NULL
,
1614 .queryDmaBufFormats
= NULL
,
1615 .queryDmaBufModifiers
= NULL
,
1616 .queryDmaBufFormatModifierAttribs
= NULL
,
1617 .createImageFromRenderbuffer2
= dri2_create_image_from_renderbuffer2
,
1620 static const __DRIrobustnessExtension dri2Robustness
= {
1621 .base
= { __DRI2_ROBUSTNESS
, 1 }
1625 dri2_interop_query_device_info(__DRIcontext
*_ctx
,
1626 struct mesa_glinterop_device_info
*out
)
1628 struct pipe_screen
*screen
= dri_context(_ctx
)->st
->pipe
->screen
;
1630 /* There is no version 0, thus we do not support it */
1631 if (out
->version
== 0)
1632 return MESA_GLINTEROP_INVALID_VERSION
;
1634 out
->pci_segment_group
= screen
->get_param(screen
, PIPE_CAP_PCI_GROUP
);
1635 out
->pci_bus
= screen
->get_param(screen
, PIPE_CAP_PCI_BUS
);
1636 out
->pci_device
= screen
->get_param(screen
, PIPE_CAP_PCI_DEVICE
);
1637 out
->pci_function
= screen
->get_param(screen
, PIPE_CAP_PCI_FUNCTION
);
1639 out
->vendor_id
= screen
->get_param(screen
, PIPE_CAP_VENDOR_ID
);
1640 out
->device_id
= screen
->get_param(screen
, PIPE_CAP_DEVICE_ID
);
1642 /* Instruct the caller that we support up-to version one of the interface */
1645 return MESA_GLINTEROP_SUCCESS
;
1649 dri2_interop_export_object(__DRIcontext
*_ctx
,
1650 struct mesa_glinterop_export_in
*in
,
1651 struct mesa_glinterop_export_out
*out
)
1653 struct st_context_iface
*st
= dri_context(_ctx
)->st
;
1654 struct pipe_screen
*screen
= st
->pipe
->screen
;
1655 struct gl_context
*ctx
= ((struct st_context
*)st
)->ctx
;
1656 struct pipe_resource
*res
= NULL
;
1657 struct winsys_handle whandle
;
1658 unsigned target
, usage
;
1661 /* There is no version 0, thus we do not support it */
1662 if (in
->version
== 0 || out
->version
== 0)
1663 return MESA_GLINTEROP_INVALID_VERSION
;
1665 /* Validate the target. */
1666 switch (in
->target
) {
1667 case GL_TEXTURE_BUFFER
:
1671 case GL_TEXTURE_RECTANGLE
:
1672 case GL_TEXTURE_1D_ARRAY
:
1673 case GL_TEXTURE_2D_ARRAY
:
1674 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1675 case GL_TEXTURE_CUBE_MAP
:
1676 case GL_TEXTURE_2D_MULTISAMPLE
:
1677 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1678 case GL_TEXTURE_EXTERNAL_OES
:
1679 case GL_RENDERBUFFER
:
1680 case GL_ARRAY_BUFFER
:
1681 target
= in
->target
;
1683 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1684 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1685 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1687 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1688 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1689 target
= GL_TEXTURE_CUBE_MAP
;
1692 return MESA_GLINTEROP_INVALID_TARGET
;
1695 /* Validate the simple case of miplevel. */
1696 if ((target
== GL_RENDERBUFFER
|| target
== GL_ARRAY_BUFFER
) &&
1698 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1700 /* Validate the OpenGL object and get pipe_resource. */
1701 simple_mtx_lock(&ctx
->Shared
->Mutex
);
1703 if (target
== GL_ARRAY_BUFFER
) {
1706 * The error checking is based on the documentation of
1707 * clCreateFromGLBuffer from OpenCL 2.0 SDK.
1709 struct gl_buffer_object
*buf
= _mesa_lookup_bufferobj(ctx
, in
->obj
);
1711 /* From OpenCL 2.0 SDK, clCreateFromGLBuffer:
1712 * "CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is
1713 * a GL buffer object but does not have an existing data store or
1714 * the size of the buffer is 0."
1716 if (!buf
|| buf
->Size
== 0) {
1717 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1718 return MESA_GLINTEROP_INVALID_OBJECT
;
1721 res
= st_buffer_object(buf
)->buffer
;
1723 /* this shouldn't happen */
1724 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1725 return MESA_GLINTEROP_INVALID_OBJECT
;
1728 out
->buf_offset
= 0;
1729 out
->buf_size
= buf
->Size
;
1731 buf
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1732 } else if (target
== GL_RENDERBUFFER
) {
1735 * The error checking is based on the documentation of
1736 * clCreateFromGLRenderbuffer from OpenCL 2.0 SDK.
1738 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, in
->obj
);
1740 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1741 * "CL_INVALID_GL_OBJECT if renderbuffer is not a GL renderbuffer
1742 * object or if the width or height of renderbuffer is zero."
1744 if (!rb
|| rb
->Width
== 0 || rb
->Height
== 0) {
1745 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1746 return MESA_GLINTEROP_INVALID_OBJECT
;
1749 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1750 * "CL_INVALID_OPERATION if renderbuffer is a multi-sample GL
1751 * renderbuffer object."
1753 if (rb
->NumSamples
> 1) {
1754 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1755 return MESA_GLINTEROP_INVALID_OPERATION
;
1758 /* From OpenCL 2.0 SDK, clCreateFromGLRenderbuffer:
1759 * "CL_OUT_OF_RESOURCES if there is a failure to allocate resources
1760 * required by the OpenCL implementation on the device."
1762 res
= st_renderbuffer(rb
)->texture
;
1764 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1765 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1768 out
->internal_format
= rb
->InternalFormat
;
1769 out
->view_minlevel
= 0;
1770 out
->view_numlevels
= 1;
1771 out
->view_minlayer
= 0;
1772 out
->view_numlayers
= 1;
1776 * The error checking is based on the documentation of
1777 * clCreateFromGLTexture from OpenCL 2.0 SDK.
1779 struct gl_texture_object
*obj
= _mesa_lookup_texture(ctx
, in
->obj
);
1782 _mesa_test_texobj_completeness(ctx
, obj
);
1784 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1785 * "CL_INVALID_GL_OBJECT if texture is not a GL texture object whose
1786 * type matches texture_target, if the specified miplevel of texture
1787 * is not defined, or if the width or height of the specified
1788 * miplevel is zero or if the GL texture object is incomplete."
1791 obj
->Target
!= target
||
1792 !obj
->_BaseComplete
||
1793 (in
->miplevel
> 0 && !obj
->_MipmapComplete
)) {
1794 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1795 return MESA_GLINTEROP_INVALID_OBJECT
;
1798 if (target
== GL_TEXTURE_BUFFER
) {
1799 struct st_buffer_object
*stBuf
=
1800 st_buffer_object(obj
->BufferObject
);
1802 if (!stBuf
|| !stBuf
->buffer
) {
1803 /* this shouldn't happen */
1804 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1805 return MESA_GLINTEROP_INVALID_OBJECT
;
1807 res
= stBuf
->buffer
;
1809 out
->internal_format
= obj
->BufferObjectFormat
;
1810 out
->buf_offset
= obj
->BufferOffset
;
1811 out
->buf_size
= obj
->BufferSize
== -1 ? obj
->BufferObject
->Size
:
1814 obj
->BufferObject
->UsageHistory
|= USAGE_DISABLE_MINMAX_CACHE
;
1816 /* From OpenCL 2.0 SDK, clCreateFromGLTexture:
1817 * "CL_INVALID_MIP_LEVEL if miplevel is less than the value of
1818 * levelbase (for OpenGL implementations) or zero (for OpenGL ES
1819 * implementations); or greater than the value of q (for both OpenGL
1820 * and OpenGL ES). levelbase and q are defined for the texture in
1821 * section 3.8.10 (Texture Completeness) of the OpenGL 2.1
1822 * specification and section 3.7.10 of the OpenGL ES 2.0."
1824 if (in
->miplevel
< obj
->BaseLevel
|| in
->miplevel
> obj
->_MaxLevel
) {
1825 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1826 return MESA_GLINTEROP_INVALID_MIP_LEVEL
;
1829 if (!st_finalize_texture(ctx
, st
->pipe
, obj
, 0)) {
1830 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1831 return MESA_GLINTEROP_OUT_OF_RESOURCES
;
1834 res
= st_get_texobj_resource(obj
);
1836 /* Incomplete texture buffer object? This shouldn't really occur. */
1837 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1838 return MESA_GLINTEROP_INVALID_OBJECT
;
1841 out
->internal_format
= obj
->Image
[0][0]->InternalFormat
;
1842 out
->view_minlevel
= obj
->MinLevel
;
1843 out
->view_numlevels
= obj
->NumLevels
;
1844 out
->view_minlayer
= obj
->MinLayer
;
1845 out
->view_numlayers
= obj
->NumLayers
;
1849 /* Get the handle. */
1850 switch (in
->access
) {
1851 case MESA_GLINTEROP_ACCESS_READ_ONLY
:
1854 case MESA_GLINTEROP_ACCESS_READ_WRITE
:
1855 case MESA_GLINTEROP_ACCESS_WRITE_ONLY
:
1856 usage
= PIPE_HANDLE_USAGE_SHADER_WRITE
;
1862 memset(&whandle
, 0, sizeof(whandle
));
1863 whandle
.type
= WINSYS_HANDLE_TYPE_FD
;
1865 success
= screen
->resource_get_handle(screen
, st
->pipe
, res
, &whandle
,
1867 simple_mtx_unlock(&ctx
->Shared
->Mutex
);
1870 return MESA_GLINTEROP_OUT_OF_HOST_MEMORY
;
1872 out
->dmabuf_fd
= whandle
.handle
;
1873 out
->out_driver_data_written
= 0;
1875 if (res
->target
== PIPE_BUFFER
)
1876 out
->buf_offset
+= whandle
.offset
;
1878 /* Instruct the caller that we support up-to version one of the interface */
1882 return MESA_GLINTEROP_SUCCESS
;
1885 static const __DRI2interopExtension dri2InteropExtension
= {
1886 .base
= { __DRI2_INTEROP
, 1 },
1887 .query_device_info
= dri2_interop_query_device_info
,
1888 .export_object
= dri2_interop_export_object
1892 * \brief the DRI2bufferDamageExtension set_damage_region method
1895 dri2_set_damage_region(__DRIdrawable
*dPriv
, unsigned int nrects
, int *rects
)
1897 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
1898 struct pipe_box
*boxes
= NULL
;
1901 boxes
= CALLOC(nrects
, sizeof(*boxes
));
1904 for (unsigned int i
= 0; i
< nrects
; i
++) {
1905 int *rect
= &rects
[i
* 4];
1907 u_box_2d(rect
[0], rect
[1], rect
[2], rect
[3], &boxes
[i
]);
1911 FREE(drawable
->damage_rects
);
1912 drawable
->damage_rects
= boxes
;
1913 drawable
->num_damage_rects
= nrects
;
1915 /* Only apply the damage region if the BACK_LEFT texture is up-to-date. */
1916 if (drawable
->texture_stamp
== drawable
->dPriv
->lastStamp
&&
1917 (drawable
->texture_mask
& (1 << ST_ATTACHMENT_BACK_LEFT
))) {
1918 struct pipe_screen
*screen
= drawable
->screen
->base
.screen
;
1919 struct pipe_resource
*resource
;
1921 if (drawable
->stvis
.samples
> 1)
1922 resource
= drawable
->msaa_textures
[ST_ATTACHMENT_BACK_LEFT
];
1924 resource
= drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
1926 screen
->set_damage_region(screen
, resource
,
1927 drawable
->num_damage_rects
,
1928 drawable
->damage_rects
);
1932 static __DRI2bufferDamageExtension dri2BufferDamageExtension
= {
1933 .base
= { __DRI2_BUFFER_DAMAGE
, 1 },
1937 * \brief the DRI2ConfigQueryExtension configQueryb method
1940 dri2GalliumConfigQueryb(__DRIscreen
*sPriv
, const char *var
,
1943 struct dri_screen
*screen
= dri_screen(sPriv
);
1945 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_BOOL
))
1946 return dri2ConfigQueryExtension
.configQueryb(sPriv
, var
, val
);
1948 *val
= driQueryOptionb(&screen
->dev
->option_cache
, var
);
1954 * \brief the DRI2ConfigQueryExtension configQueryi method
1957 dri2GalliumConfigQueryi(__DRIscreen
*sPriv
, const char *var
, int *val
)
1959 struct dri_screen
*screen
= dri_screen(sPriv
);
1961 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_INT
) &&
1962 !driCheckOption(&screen
->dev
->option_cache
, var
, DRI_ENUM
))
1963 return dri2ConfigQueryExtension
.configQueryi(sPriv
, var
, val
);
1965 *val
= driQueryOptioni(&screen
->dev
->option_cache
, var
);
1971 * \brief the DRI2ConfigQueryExtension configQueryf method
1974 dri2GalliumConfigQueryf(__DRIscreen
*sPriv
, const char *var
, float *val
)
1976 struct dri_screen
*screen
= dri_screen(sPriv
);
1978 if (!driCheckOption(&screen
->dev
->option_cache
, var
, DRI_FLOAT
))
1979 return dri2ConfigQueryExtension
.configQueryf(sPriv
, var
, val
);
1981 *val
= driQueryOptionf(&screen
->dev
->option_cache
, var
);
1987 * \brief the DRI2ConfigQueryExtension struct.
1989 * We first query the driver option cache. Then the dri2 option cache.
1991 static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension
= {
1992 .base
= { __DRI2_CONFIG_QUERY
, 1 },
1994 .configQueryb
= dri2GalliumConfigQueryb
,
1995 .configQueryi
= dri2GalliumConfigQueryi
,
1996 .configQueryf
= dri2GalliumConfigQueryf
,
2000 * \brief the DRI2blobExtension set_cache_funcs method
2003 set_blob_cache_funcs(__DRIscreen
*sPriv
, __DRIblobCacheSet set
,
2004 __DRIblobCacheGet get
)
2006 struct dri_screen
*screen
= dri_screen(sPriv
);
2007 struct pipe_screen
*pscreen
= screen
->base
.screen
;
2009 if (!pscreen
->get_disk_shader_cache
)
2012 struct disk_cache
*cache
= pscreen
->get_disk_shader_cache(pscreen
);
2017 disk_cache_set_callbacks(cache
, set
, get
);
2020 static const __DRI2blobExtension driBlobExtension
= {
2021 .base
= { __DRI2_BLOB
, 1 },
2022 .set_cache_funcs
= set_blob_cache_funcs
2026 * Backend function init_screen.
2029 static const __DRIextension
*dri_screen_extensions
[] = {
2030 &driTexBufferExtension
.base
,
2031 &dri2FlushExtension
.base
,
2032 &dri2ImageExtension
.base
,
2033 &dri2RendererQueryExtension
.base
,
2034 &dri2GalliumConfigQueryExtension
.base
,
2035 &dri2ThrottleExtension
.base
,
2036 &dri2FenceExtension
.base
,
2037 &dri2BufferDamageExtension
.base
,
2038 &dri2InteropExtension
.base
,
2039 &dri2NoErrorExtension
.base
,
2040 &driBlobExtension
.base
,
2044 static const __DRIextension
*dri_robust_screen_extensions
[] = {
2045 &driTexBufferExtension
.base
,
2046 &dri2FlushExtension
.base
,
2047 &dri2ImageExtension
.base
,
2048 &dri2RendererQueryExtension
.base
,
2049 &dri2GalliumConfigQueryExtension
.base
,
2050 &dri2ThrottleExtension
.base
,
2051 &dri2FenceExtension
.base
,
2052 &dri2InteropExtension
.base
,
2053 &dri2BufferDamageExtension
.base
,
2054 &dri2Robustness
.base
,
2055 &dri2NoErrorExtension
.base
,
2056 &driBlobExtension
.base
,
2061 * This is the driver specific part of the createNewScreen entry point.
2063 * Returns the struct gl_config supported by this driver.
2065 static const __DRIconfig
**
2066 dri2_init_screen(__DRIscreen
* sPriv
)
2068 const __DRIconfig
**configs
;
2069 struct dri_screen
*screen
;
2070 struct pipe_screen
*pscreen
= NULL
;
2072 screen
= CALLOC_STRUCT(dri_screen
);
2076 screen
->sPriv
= sPriv
;
2077 screen
->fd
= sPriv
->fd
;
2078 (void) mtx_init(&screen
->opencl_func_mutex
, mtx_plain
);
2080 sPriv
->driverPrivate
= (void *)screen
;
2082 if (pipe_loader_drm_probe_fd(&screen
->dev
, screen
->fd
)) {
2083 dri_init_options(screen
);
2085 pscreen
= pipe_loader_create_screen(screen
->dev
);
2091 screen
->throttle
= pscreen
->get_param(pscreen
, PIPE_CAP_THROTTLE
);
2093 if (pscreen
->resource_create_with_modifiers
)
2094 dri2ImageExtension
.createImageWithModifiers
=
2095 dri2_create_image_with_modifiers
;
2097 if (pscreen
->get_param(pscreen
, PIPE_CAP_DMABUF
)) {
2100 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2101 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2102 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2103 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2104 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2105 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2106 dri2ImageExtension
.queryDmaBufModifiers
=
2107 dri2_query_dma_buf_modifiers
;
2108 dri2ImageExtension
.queryDmaBufFormatModifierAttribs
=
2109 dri2_query_dma_buf_format_modifier_attribs
;
2113 if (pscreen
->set_damage_region
)
2114 dri2BufferDamageExtension
.set_damage_region
= dri2_set_damage_region
;
2116 if (pscreen
->get_param(pscreen
, PIPE_CAP_DEVICE_RESET_STATUS_QUERY
)) {
2117 sPriv
->extensions
= dri_robust_screen_extensions
;
2118 screen
->has_reset_status_query
= true;
2121 sPriv
->extensions
= dri_screen_extensions
;
2123 configs
= dri_init_screen_helper(screen
, pscreen
);
2125 goto destroy_screen
;
2127 screen
->can_share_buffer
= true;
2128 screen
->auto_fake_front
= dri_with_format(sPriv
);
2129 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2130 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2135 dri_destroy_screen_helper(screen
);
2139 pipe_loader_release(&screen
->dev
, 1);
2146 * This is the driver specific part of the createNewScreen entry point.
2148 * Returns the struct gl_config supported by this driver.
2150 static const __DRIconfig
**
2151 dri_kms_init_screen(__DRIscreen
* sPriv
)
2153 #if defined(GALLIUM_SOFTPIPE)
2154 const __DRIconfig
**configs
;
2155 struct dri_screen
*screen
;
2156 struct pipe_screen
*pscreen
= NULL
;
2159 screen
= CALLOC_STRUCT(dri_screen
);
2163 screen
->sPriv
= sPriv
;
2164 screen
->fd
= sPriv
->fd
;
2166 sPriv
->driverPrivate
= (void *)screen
;
2168 if (pipe_loader_sw_probe_kms(&screen
->dev
, screen
->fd
)) {
2169 dri_init_options(screen
);
2170 pscreen
= pipe_loader_create_screen(screen
->dev
);
2176 if (pscreen
->resource_create_with_modifiers
)
2177 dri2ImageExtension
.createImageWithModifiers
=
2178 dri2_create_image_with_modifiers
;
2180 if (drmGetCap(sPriv
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2181 (cap
& DRM_PRIME_CAP_IMPORT
)) {
2182 dri2ImageExtension
.createImageFromFds
= dri2_from_fds
;
2183 dri2ImageExtension
.createImageFromDmaBufs
= dri2_from_dma_bufs
;
2184 dri2ImageExtension
.createImageFromDmaBufs2
= dri2_from_dma_bufs2
;
2185 dri2ImageExtension
.queryDmaBufFormats
= dri2_query_dma_buf_formats
;
2186 dri2ImageExtension
.queryDmaBufModifiers
= dri2_query_dma_buf_modifiers
;
2189 sPriv
->extensions
= dri_screen_extensions
;
2191 configs
= dri_init_screen_helper(screen
, pscreen
);
2193 goto destroy_screen
;
2195 screen
->can_share_buffer
= false;
2196 screen
->auto_fake_front
= dri_with_format(sPriv
);
2197 screen
->broken_invalidate
= !sPriv
->dri2
.useInvalidate
;
2198 screen
->lookup_egl_image
= dri2_lookup_egl_image
;
2203 dri_destroy_screen_helper(screen
);
2207 pipe_loader_release(&screen
->dev
, 1);
2210 #endif // GALLIUM_SOFTPIPE
2215 dri2_create_buffer(__DRIscreen
* sPriv
,
2216 __DRIdrawable
* dPriv
,
2217 const struct gl_config
* visual
, boolean isPixmap
)
2219 struct dri_drawable
*drawable
= NULL
;
2221 if (!dri_create_buffer(sPriv
, dPriv
, visual
, isPixmap
))
2224 drawable
= dPriv
->driverPrivate
;
2226 drawable
->allocate_textures
= dri2_allocate_textures
;
2227 drawable
->flush_frontbuffer
= dri2_flush_frontbuffer
;
2228 drawable
->update_tex_buffer
= dri2_update_tex_buffer
;
2229 drawable
->flush_swapbuffers
= dri2_flush_swapbuffers
;
2235 * DRI driver virtual function table.
2237 * DRI versions differ in their implementation of init_screen and swap_buffers.
2239 const struct __DriverAPIRec galliumdrm_driver_api
= {
2240 .InitScreen
= dri2_init_screen
,
2241 .DestroyScreen
= dri_destroy_screen
,
2242 .CreateContext
= dri_create_context
,
2243 .DestroyContext
= dri_destroy_context
,
2244 .CreateBuffer
= dri2_create_buffer
,
2245 .DestroyBuffer
= dri_destroy_buffer
,
2246 .MakeCurrent
= dri_make_current
,
2247 .UnbindContext
= dri_unbind_context
,
2249 .AllocateBuffer
= dri2_allocate_buffer
,
2250 .ReleaseBuffer
= dri2_release_buffer
,
2254 * DRI driver virtual function table.
2256 * KMS/DRM version of the DriverAPI above sporting a different InitScreen
2257 * hook. The latter is used to explicitly initialise the kms_swrast driver
2258 * rather than selecting the approapriate driver as suggested by the loader.
2260 const struct __DriverAPIRec dri_kms_driver_api
= {
2261 .InitScreen
= dri_kms_init_screen
,
2262 .DestroyScreen
= dri_destroy_screen
,
2263 .CreateContext
= dri_create_context
,
2264 .DestroyContext
= dri_destroy_context
,
2265 .CreateBuffer
= dri2_create_buffer
,
2266 .DestroyBuffer
= dri_destroy_buffer
,
2267 .MakeCurrent
= dri_make_current
,
2268 .UnbindContext
= dri_unbind_context
,
2270 .AllocateBuffer
= dri2_allocate_buffer
,
2271 .ReleaseBuffer
= dri2_release_buffer
,
2274 /* This is the table of extensions that the loader will dlsym() for. */
2275 const __DRIextension
*galliumdrm_driver_extensions
[] = {
2276 &driCoreExtension
.base
,
2277 &driImageDriverExtension
.base
,
2278 &driDRI2Extension
.base
,
2279 &gallium_config_options
.base
,
2283 /* vim: set sw=3 ts=8 sts=3 expandtab: */