virgl: Allow importing resources without known templ

On windows when external resources are imported
there is no information about them. And in such cases
resource_from_hanlde templ argument is equal NULL.

To support such case on virgl, virgl winsys can now
fill in template for resource, that will be used if
templ=NULL. Additionally helper functions were
added to convert virgl encoded enums to pipe.

Reviewed-by: Feng Jiang <jiangfeng@kylinos.cn>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27308>
This commit is contained in:
Max R
2023-08-13 18:23:56 +03:00
committed by Marge Bot
parent 8b7fa26b39
commit 15c21eafc2
3 changed files with 13 additions and 7 deletions

View File

@@ -717,22 +717,29 @@ static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *scre
uint32_t storage_size;
struct virgl_screen *vs = virgl_screen(screen);
if (templ->target == PIPE_BUFFER)
if (templ && templ->target == PIPE_BUFFER)
return NULL;
struct virgl_resource *res = CALLOC_STRUCT(virgl_resource);
res->b = *templ;
if (templ)
res->b = *templ;
res->b.screen = &vs->base;
pipe_reference_init(&res->b.reference, 1);
plane = winsys_stride = plane_offset = modifier = 0;
res->hw_res = vs->vws->resource_create_from_handle(vs->vws, whandle,
&res->b,
&plane,
&winsys_stride,
&plane_offset,
&modifier,
&res->blob_mem);
if (!res->hw_res) {
FREE(res);
return NULL;
}
/* do not use winsys returns for guest storage info of classic resource */
if (!res->blob_mem) {
winsys_stride = 0;
@@ -742,10 +749,6 @@ static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *scre
virgl_resource_layout(&res->b, &res->metadata, plane, winsys_stride,
plane_offset, modifier);
if (!res->hw_res) {
FREE(res);
return NULL;
}
/*
* If the overall resource is larger than a single page in size, we can

View File

@@ -27,6 +27,7 @@
#include "virtio-gpu/virgl_hw.h"
struct pipe_box;
struct pipe_resource;
struct pipe_fence_handle;
struct winsys_handle;
struct virgl_hw_res;
@@ -86,6 +87,7 @@ struct virgl_winsys {
struct virgl_hw_res *(*resource_create_from_handle)(struct virgl_winsys *vws,
struct winsys_handle *whandle,
struct pipe_resource *templ,
uint32_t *plane,
uint32_t *stride,
uint32_t *plane_offset,
@@ -184,5 +186,5 @@ static inline void virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps *caps)
}
extern enum virgl_formats pipe_to_virgl_format(enum pipe_format format);
extern enum pipe_format virgl_to_pipe_format(enum virgl_formats format);
#endif

View File

@@ -478,6 +478,7 @@ virgl_drm_winsys_resource_get_storage_size(struct virgl_winsys *qws,
static struct virgl_hw_res *
virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
struct winsys_handle *whandle,
UNUSED struct pipe_resource *templ,
uint32_t *plane,
uint32_t *stride,
uint32_t *plane_offset,