From 7ae4a2ae34954b8dd7213a9663a2f98907c49cd6 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Fri, 17 May 2024 07:22:45 +0000 Subject: [PATCH] u_gralloc/fallback: Extract modifier from QCOM native_handle After Turnip moved to u_gralloc, some users started complaining about issues. It turns out that modern platforms do not have grallocs{0,1} but have gralloc4 only. There's no known way to build mesa3d with gralloc4 support using NDK. So we add this workaround to fallback gralloc to mimic the original behavior of the Turnip driver before switching to u_gralloc. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11171 Fixes: 1373b0966cbd ("turnip: ANB/AHB support") Signed-off-by: Roman Stratiienko Reviewed-by: Rob Clark Part-of: --- src/util/u_gralloc/meson.build | 4 ++++ src/util/u_gralloc/u_gralloc_fallback.c | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/util/u_gralloc/meson.build b/src/util/u_gralloc/meson.build index 913fc7c786d..c834ee38c3d 100644 --- a/src/util/u_gralloc/meson.build +++ b/src/util/u_gralloc/meson.build @@ -23,6 +23,10 @@ if dep_android_mapper4.found() options_for_u_gralloc += 'cpp_std=c++17' endif +if with_freedreno_vk or with_gallium_freedreno + c_args_for_u_gralloc += '-DHAS_FREEDRENO' +endif + _libmesa_u_gralloc = static_library( '_mesa_u_gralloc', [files_u_gralloc], diff --git a/src/util/u_gralloc/u_gralloc_fallback.c b/src/util/u_gralloc/u_gralloc_fallback.c index ba21c207bbf..279c164ffaf 100644 --- a/src/util/u_gralloc/u_gralloc_fallback.c +++ b/src/util/u_gralloc/u_gralloc_fallback.c @@ -107,6 +107,9 @@ fallback_gralloc_get_buffer_info(struct u_gralloc *gralloc, int stride = 0; int fds[3]; + if (hnd->handle->numFds == 0) + return -EINVAL; + if (is_hal_format_yuv(hnd->hal_format)) { int ret = fallback_gralloc_get_yuv_info(gralloc, hnd, out); /* @@ -125,11 +128,7 @@ fallback_gralloc_get_buffer_info(struct u_gralloc *gralloc, * color compression state buffer, but the rest of the code isn't ready * yet to deal with modifiers: */ - num_planes = get_native_buffer_fds(hnd->handle, fds); - if (num_planes == 0) - return -EINVAL; - - assert(num_planes == 1); + num_planes = 1; drm_fourcc = get_fourcc_from_hal_format(hnd->hal_format); if (drm_fourcc == -1) { @@ -149,6 +148,15 @@ fallback_gralloc_get_buffer_info(struct u_gralloc *gralloc, out->fds[0] = fds[0]; out->strides[0] = stride; +#ifdef HAS_FREEDRENO + uint32_t gmsm = ('g' << 24) | ('m' << 16) | ('s' << 8) | 'm'; + if (hnd->handle->numInts >= 2 && hnd->handle->data[hnd->handle->numFds] == gmsm) { + /* This UBWC flag was introduced in a5xx. */ + bool ubwc = hnd->handle->data[hnd->handle->numFds + 1] & 0x08000000; + out->modifier = ubwc ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR; + } +#endif + return 0; }