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: 1373b0966c ("turnip: ANB/AHB support")
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29260>
This commit is contained in:
Roman Stratiienko 2024-05-17 07:22:45 +00:00 committed by Marge Bot
parent 2934e1fad5
commit 7ae4a2ae34
2 changed files with 17 additions and 5 deletions

View file

@ -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],

View file

@ -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;
}