Module: Mesa Branch: main Commit: 68c53ec2c2b6e898f7e93c8e79f1b91d95ac07de URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=68c53ec2c2b6e898f7e93c8e79f1b91d95ac07de
Author: Rob Clark <[email protected]> Date: Sat Oct 28 08:24:46 2023 -0700 freedreno: Add layout metadata support Add support to use layout metadata to communicate modifier between exporter and importer. This is required because EXT_external_objects does not have modifier support, so when importing a memobj we must use a back-channel to communicate the modifier with the exporter. Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25945> --- src/gallium/drivers/freedreno/freedreno_resource.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index b981a5612a7..b4a082f3cd0 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -1108,6 +1108,13 @@ fd_resource_get_handle(struct pipe_screen *pscreen, struct pipe_context *pctx, handle->modifier = fd_resource_modifier(rsc); + if (prsc->target != PIPE_BUFFER) { + struct fdl_metadata metadata = { + .modifier = handle->modifier, + }; + fd_bo_set_metadata(rsc->bo, &metadata, sizeof(metadata)); + } + DBG("%" PRSC_FMT ", modifier=%" PRIx64, PRSC_ARGS(prsc), handle->modifier); bool ret = fd_screen_bo_get_handle(pscreen, rsc->bo, rsc->scanout, @@ -1661,14 +1668,20 @@ fd_resource_from_memobj(struct pipe_screen *pscreen, struct fd_memory_object *memobj = fd_memory_object(pmemobj); struct pipe_resource *prsc; struct fd_resource *rsc; + struct fdl_metadata metadata; uint32_t size; + assert(memobj->bo); + assert(offset == 0); /* We shouldn't get a scanout buffer here. */ assert(!(tmpl->bind & PIPE_BIND_SCANOUT)); uint64_t modifiers = DRM_FORMAT_MOD_INVALID; - if (tmpl->bind & PIPE_BIND_LINEAR) { + if (pmemobj->dedicated && + !fd_bo_get_metadata(memobj->bo, &metadata, sizeof(metadata))) { + modifiers = metadata.modifier; + } else if (tmpl->bind & PIPE_BIND_LINEAR) { modifiers = DRM_FORMAT_MOD_LINEAR; } else if (is_a6xx(screen) && tmpl->width0 >= FDL_MIN_UBWC_WIDTH) { modifiers = DRM_FORMAT_MOD_QCOM_COMPRESSED;
