vc4: implement resource_get_param

Prior to this commit, the stride, offset and modifier were fetched
via WINSYS_HANDLE_TYPE_KMS. However we can't make such a query
succeed if the buffer couldn't be imported to the KMS device.

Instead, implement the resource_get_param hook to allow users to
fetch this information without WINSYS_HANDLE_TYPE_KMS.

A tiny helper function is introduced to compute the modifier of a
resource.

Signed-off-by: Simon Ser <contact@emersion.fr>
Fixes: 7bcb223639 ("v3d, vc4: Fix dmabuf import for non-scanout buffers")
Reported-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12370>
This commit is contained in:
Simon Ser 2021-08-14 14:07:28 +02:00 committed by Marge Bot
parent 99fc6f7271
commit b1fbceac6f

View file

@ -283,6 +283,15 @@ vc4_resource_destroy(struct pipe_screen *pscreen,
free(rsc);
}
static uint64_t
vc4_resource_modifier(struct vc4_resource *rsc)
{
if (rsc->tiled)
return DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED;
else
return DRM_FORMAT_MOD_LINEAR;
}
static bool
vc4_resource_get_handle(struct pipe_screen *pscreen,
struct pipe_context *pctx,
@ -295,6 +304,7 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
whandle->stride = rsc->slices[0].stride;
whandle->offset = 0;
whandle->modifier = vc4_resource_modifier(rsc);
/* If we're passing some reference to our BO out to some other part of
* the system, then we can't do any optimizations about only us being
@ -302,11 +312,6 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
*/
rsc->bo->private = false;
if (rsc->tiled)
whandle->modifier = DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED;
else
whandle->modifier = DRM_FORMAT_MOD_LINEAR;
switch (whandle->type) {
case WINSYS_HANDLE_TYPE_SHARED:
if (screen->ro) {
@ -334,6 +339,30 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
return false;
}
static bool
vc4_resource_get_param(struct pipe_screen *pscreen,
struct pipe_context *pctx, struct pipe_resource *prsc,
unsigned plane, unsigned layer, unsigned level,
enum pipe_resource_param param,
unsigned usage, uint64_t *value)
{
struct vc4_resource *rsc = vc4_resource(prsc);
switch (param) {
case PIPE_RESOURCE_PARAM_STRIDE:
*value = rsc->slices[level].stride;
return true;
case PIPE_RESOURCE_PARAM_OFFSET:
*value = 0;
return true;
case PIPE_RESOURCE_PARAM_MODIFIER:
*value = vc4_resource_modifier(rsc);
return true;
default:
return false;
}
}
static void
vc4_setup_slices(struct vc4_resource *rsc, const char *caller)
{
@ -1119,6 +1148,7 @@ vc4_resource_screen_init(struct pipe_screen *pscreen)
vc4_resource_create_with_modifiers;
pscreen->resource_from_handle = vc4_resource_from_handle;
pscreen->resource_get_handle = vc4_resource_get_handle;
pscreen->resource_get_param = vc4_resource_get_param;
pscreen->resource_destroy = vc4_resource_destroy;
pscreen->transfer_helper = u_transfer_helper_create(&transfer_vtbl,
false, false,