virgl/vtest: implement resource_create_front

This is required for glXCopySubBufferMESA to work.

Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11714>
This commit is contained in:
Italo Nicola 2021-07-05 06:22:16 -03:00 committed by Marge Bot
parent b6d0447027
commit 0577a142de
6 changed files with 45 additions and 13 deletions

View File

@ -43,6 +43,7 @@ struct virgl_hw_res {
static struct virgl_hw_res *
fake_resource_create(struct virgl_winsys *vws,
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format, uint32_t bind,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t array_size,
@ -316,6 +317,7 @@ TEST_F(VirglStagingMgr, releases_resource_on_destruction)
static struct virgl_hw_res *
failing_resource_create(struct virgl_winsys *vws,
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format, uint32_t bind,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t array_size,

View File

@ -402,6 +402,7 @@ virgl_resource_realloc(struct virgl_context *vctx, struct virgl_resource *res)
vflags = pipe_to_virgl_flags(vs, templ->flags);
hw_res = vs->vws->resource_create(vs->vws,
templ->target,
NULL,
templ->format,
vbind,
templ->width0,
@ -567,8 +568,9 @@ static void virgl_resource_layout(struct pipe_resource *pt,
metadata->total_size = 0;
}
static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
const struct pipe_resource *templ)
static struct pipe_resource *virgl_resource_create_front(struct pipe_screen *screen,
const struct pipe_resource *templ,
const void *map_front_private)
{
unsigned vbind, vflags;
struct virgl_screen *vs = virgl_screen(screen);
@ -600,6 +602,7 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
alloc_size = res->metadata.total_size;
res->hw_res = vs->vws->resource_create(vs->vws, templ->target,
map_front_private,
templ->format, vbind,
templ->width0,
templ->height0,
@ -627,6 +630,12 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
}
static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,
const struct pipe_resource *templ)
{
return virgl_resource_create_front(screen, templ, NULL);
}
static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templ,
struct winsys_handle *whandle,
@ -715,6 +724,7 @@ static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *scre
void virgl_init_screen_resource_functions(struct pipe_screen *screen)
{
screen->resource_create_front = virgl_resource_create_front;
screen->resource_create = virgl_resource_create;
screen->resource_from_handle = virgl_resource_from_handle;
screen->resource_get_handle = virgl_resource_get_handle;

View File

@ -47,6 +47,7 @@ virgl_staging_alloc_buffer(struct virgl_staging_mgr *staging, unsigned min_size)
staging->hw_res = vws->resource_create(vws,
PIPE_BUFFER,
NULL,
PIPE_FORMAT_R8_UNORM,
VIRGL_BIND_STAGING,
size, /* width */

View File

@ -65,12 +65,13 @@ struct virgl_winsys {
uint32_t buf_offset, uint32_t level);
struct virgl_hw_res *(*resource_create)(struct virgl_winsys *vws,
enum pipe_texture_target target,
uint32_t format, uint32_t bind,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t array_size,
uint32_t last_level, uint32_t nr_samples,
uint32_t flags, uint32_t size);
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format, uint32_t bind,
uint32_t width, uint32_t height,
uint32_t depth, uint32_t array_size,
uint32_t last_level, uint32_t nr_samples,
uint32_t flags, uint32_t size);
void (*resource_reference)(struct virgl_winsys *qws,
struct virgl_hw_res **dres,

View File

@ -402,6 +402,7 @@ virgl_bo_transfer_get(struct virgl_winsys *vws,
static struct virgl_hw_res *
virgl_drm_winsys_resource_cache_create(struct virgl_winsys *qws,
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format,
uint32_t bind,
uint32_t width,

View File

@ -224,6 +224,7 @@ static void virgl_vtest_resource_reference(struct virgl_winsys *vws,
static struct virgl_hw_res *
virgl_vtest_winsys_resource_create(struct virgl_winsys *vws,
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format,
uint32_t bind,
uint32_t width,
@ -256,7 +257,7 @@ virgl_vtest_winsys_resource_create(struct virgl_winsys *vws,
if (bind & (VIRGL_BIND_DISPLAY_TARGET | VIRGL_BIND_SCANOUT)) {
res->dt = vtws->sws->displaytarget_create(vtws->sws, bind, format,
width, height, 64, NULL,
width, height, 64, map_front_private,
&res->stride);
} else if (vtws->protocol_version < 2) {
@ -279,6 +280,7 @@ virgl_vtest_winsys_resource_create(struct virgl_winsys *vws,
if (vtws->protocol_version >= 2) {
if (res->size == 0) {
res->ptr = NULL;
res->res_handle = handle;
goto out;
}
@ -301,9 +303,21 @@ virgl_vtest_winsys_resource_create(struct virgl_winsys *vws,
close(fd);
}
res->res_handle = handle;
if (map_front_private && res->ptr && res->dt) {
void *dt_map = vtws->sws->displaytarget_map(vtws->sws, res->dt, PIPE_MAP_READ_WRITE);
uint32_t shm_stride = util_format_get_stride(res->format, res->width);
util_copy_rect(res->ptr, res->format, shm_stride, 0, 0,
res->width, res->height, dt_map, res->stride, 0, 0);
struct pipe_box box;
u_box_2d(0, 0, res->width, res->height, &box);
virgl_vtest_transfer_put(vws, res, &box, res->stride, 0, 0, 0);
}
out:
virgl_resource_cache_entry_init(&res->cache_entry, params);
res->res_handle = handle++;
handle++;
pipe_reference_init(&res->reference, 1);
p_atomic_set(&res->num_cs_references, 0);
return res;
@ -350,6 +364,7 @@ static void virgl_vtest_resource_wait(struct virgl_winsys *vws,
static struct virgl_hw_res *
virgl_vtest_winsys_resource_cache_create(struct virgl_winsys *vws,
enum pipe_texture_target target,
const void *map_front_private,
uint32_t format,
uint32_t bind,
uint32_t width,
@ -392,9 +407,10 @@ virgl_vtest_winsys_resource_cache_create(struct virgl_winsys *vws,
mtx_unlock(&vtws->mutex);
alloc:
res = virgl_vtest_winsys_resource_create(vws, target, format, bind,
width, height, depth, array_size,
last_level, nr_samples, size);
res = virgl_vtest_winsys_resource_create(vws, target, map_front_private,
format, bind, width, height, depth,
array_size, last_level, nr_samples,
size);
return res;
}
@ -508,6 +524,7 @@ virgl_vtest_fence_create(struct virgl_winsys *vws)
*/
res = virgl_vtest_winsys_resource_create(vws,
PIPE_BUFFER,
NULL,
PIPE_FORMAT_R8_UNORM,
VIRGL_BIND_CUSTOM,
8, 1, 1, 0, 0, 0, 8);