From 758941ab0cf36676664f1082a100c9bdcaf2b1a9 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Thu, 7 Nov 2024 14:45:12 +0100 Subject: [PATCH] v3d: Support SAND128 base modifier The BROADCOM_SAND128 modifier is usually used with an extra parameter to pass in the stride via a side channel. Quoting from drm_fourcc.h: > The pitch between the start of each column is set to optimally > switch between SDRAM banks. This is passed as the number of lines > of column width in the modifier (we can't use the stride value due > to various core checks that look at it , so you should set the > stride to width*cpp). So apparently this is just a workaround for limitations in some kernel APIs. DRM modifiers, however, are arguably a bad fit for extra parameters that aren't known in advance. In the Wayland/KMS ecosystem many components depend on being able to treat modifiers as opaque, e.g. for negotiations etc. In practice the current approach requires various software components to manually use the `DRM_FORMAT_MOD_BROADCOM_SAND128_COL_HEIGHT()` macro - using the `DRM_FORMAT_MOD_BROADCOM_SAND128` modifier directly with formats like `NV12` results in a rejection in the KMS driver and corrupted output in Mesa (because we'd bail out early in `v3d_sand8_blit()`). Fortunately the stride check limitations mentioned above don't seem to apply to Mesa though. Thus we can just add support for the base modifier and stride (coming from V4L2), allowing various toolkits, Wayland compositors and V4L2 decoder implementations to support e.g. `NV12` + `DRM_FORMAT_MOD_BROADCOM_SAND128` (`NC12` in V4L2) in a generic way. Notes: 1. Wayland compositors trying to offload composition to KMS will still fail when doing a test commit. 2. There is another limitation - in the V4L2 MPLANE API - that requires userspace to know the correct offset of the second plane. That's a known API limitation though and only affects V4L2 decoder implementations. Cc: mesa-stable Signed-off-by: Robert Mader Reviewed-by: Jose Maria Casanova Crespo Part-of: --- src/gallium/drivers/v3d/v3d_resource.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gallium/drivers/v3d/v3d_resource.c b/src/gallium/drivers/v3d/v3d_resource.c index 030caad6abf..cbffde0ea4b 100644 --- a/src/gallium/drivers/v3d/v3d_resource.c +++ b/src/gallium/drivers/v3d/v3d_resource.c @@ -919,6 +919,10 @@ v3d_resource_from_handle(struct pipe_screen *pscreen, case DRM_FORMAT_MOD_INVALID: rsc->tiled = false; break; + case DRM_FORMAT_MOD_BROADCOM_SAND128: + rsc->tiled = false; + rsc->sand_col128_stride = whandle->stride; + break; default: switch(fourcc_mod_broadcom_mod(whandle->modifier)) { case DRM_FORMAT_MOD_BROADCOM_SAND128: