From e23fdcbdfe89933ee74a7c7ccf2939ed29d551ca Mon Sep 17 00:00:00 2001 From: Brendan Szymanski Date: Fri, 10 Jul 2026 22:40:41 -0400 Subject: [PATCH] Apply RK3588 compatibility patches to EGL and PanVK - EGL: 64-bit gralloc usage, API level guard removal, buffer dequeue optimization - PanVK: SHA1 cache UUID, legacy scanout LINEAR default Copyright (C) 2026 Brendan Szymanski --- src/egl/drivers/dri2/egl_dri2.h | 4 +-- src/egl/drivers/dri2/platform_android.c | 21 ++++++++----- src/panfrost/vulkan/panvk_image.c | 4 +++ src/panfrost/vulkan/panvk_physical_device.c | 34 ++++++++++----------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 15da921421a..3a15ff531a3 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -292,7 +292,7 @@ struct dri2_egl_display { #ifdef HAVE_ANDROID_PLATFORM struct u_gralloc *gralloc; /* gralloc vendor usage bit for front rendering */ - uint32_t front_rendering_usage; + uint64_t front_rendering_usage; bool has_native_fence_fd; bool pure_swrast; #endif @@ -379,7 +379,7 @@ struct dri2_egl_surface { struct ANativeWindowBuffer *buffer; int age; } *color_buffers, *back; - uint32_t gralloc_usage; + uint64_t gralloc_usage; #endif /* surfaceless and device */ diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 7db9f6bccb6..ac83358fe6b 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -230,7 +230,6 @@ droid_window_cancel_buffer(struct dri2_egl_surface *dri2_surf) static bool droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode) { -#if ANDROID_API_LEVEL >= 24 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); struct ANativeWindow *window = dri2_surf->window; @@ -261,11 +260,6 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode) } return true; -#else - _eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, - __LINE__); - return false; -#endif } static _EGLSurface * @@ -672,6 +666,12 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) draw->ActiveRenderBuffer = draw->RequestedRenderBuffer; } + /* Optimization: Dequeue the buffer for a next frame: + * This reduces CPU time spent by next frame on a road + * from start-of-frame event to GPU job-submit event. + */ + update_buffers(dri2_surf); + return EGL_TRUE; } @@ -1245,7 +1245,6 @@ dri2_initialize_android(_EGLDisplay *disp) disp->Extensions.KHR_image = EGL_TRUE; dri2_dpy->front_rendering_usage = 0; -#if ANDROID_API_LEVEL >= 24 if (!dri2_dpy->swrast_not_kms && dri2_dpy->loader_extensions == droid_image_loader_extensions && /* In big GL, front rendering is done at the core API level by directly @@ -1259,6 +1258,12 @@ dri2_initialize_android(_EGLDisplay *disp) */ (disp->ClientAPIs & ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR)) == 0) { + +#if ANDROID_API_LEVEL >= 33 + /* align with BufferUsage::FRONT_BUFFER */ + dri2_dpy->front_rendering_usage = 1UL << 32; + disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE; +#else /* For cros gralloc, if the front rendering query is supported, then all * available window surface configs support front rendering because: * @@ -1280,8 +1285,8 @@ dri2_initialize_android(_EGLDisplay *disp) dri2_dpy->front_rendering_usage = front_rendering_usage; disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE; } - } #endif + } /* Create configs *after* enabling extensions because presence of DRI * driver extensions can affect the capabilities of EGLConfigs. diff --git a/src/panfrost/vulkan/panvk_image.c b/src/panfrost/vulkan/panvk_image.c index 46dbb0348c3..86671684d1b 100644 --- a/src/panfrost/vulkan/panvk_image.c +++ b/src/panfrost/vulkan/panvk_image.c @@ -223,6 +223,10 @@ panvk_image_get_mod(struct panvk_image *image, assert(!"Missing modifier info"); } + /* legacy scanout (images without any external modifier info) should default to LINEAR. */ + if (image->vk.wsi_legacy_scanout) + return DRM_FORMAT_MOD_LINEAR; + return panvk_image_get_mod_from_list(image, NULL, 0); } diff --git a/src/panfrost/vulkan/panvk_physical_device.c b/src/panfrost/vulkan/panvk_physical_device.c index 44f4196675b..2ae01601ff8 100644 --- a/src/panfrost/vulkan/panvk_physical_device.c +++ b/src/panfrost/vulkan/panvk_physical_device.c @@ -12,7 +12,7 @@ #include #include -#include "util/disk_cache.h" +#include "util/mesa-sha1.h" #include "git_sha1.h" #include "vk_device.h" @@ -132,20 +132,24 @@ get_drm_device_ids(struct panvk_physical_device *device, return VK_SUCCESS; } -static int -get_cache_uuid(uint16_t family, void *uuid) +static void +get_cache_sha1(struct panvk_physical_device *device, + const struct panvk_instance *instance) { - uint32_t mesa_timestamp; - uint16_t f = family; + struct mesa_sha1 sha_ctx; + _mesa_sha1_init(&sha_ctx); - if (!disk_cache_get_function_timestamp(get_cache_uuid, &mesa_timestamp)) - return -1; + _mesa_sha1_update(&sha_ctx, instance->driver_build_sha, + sizeof(instance->driver_build_sha)); - memset(uuid, 0, VK_UUID_SIZE); - memcpy(uuid, &mesa_timestamp, 4); - memcpy((char *)uuid + 4, &f, 2); - snprintf((char *)uuid + 6, VK_UUID_SIZE - 10, "pan"); - return 0; + _mesa_sha1_update(&sha_ctx, &device->kmod.props.gpu_id, + sizeof(device->kmod.props.gpu_id)); + + unsigned char sha[SHA1_DIGEST_LENGTH]; + _mesa_sha1_final(&sha_ctx, sha); + + STATIC_ASSERT(VK_UUID_SIZE <= SHA1_DIGEST_LENGTH); + memcpy(device->cache_uuid, sha, VK_UUID_SIZE); } static VkResult @@ -301,11 +305,7 @@ panvk_physical_device_init(struct panvk_physical_device *device, memset(device->name, 0, sizeof(device->name)); sprintf(device->name, "%s", device->model->name); - if (get_cache_uuid(device->kmod.props.gpu_id, device->cache_uuid)) { - result = panvk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, - "cannot generate UUID"); - goto fail; - } + get_cache_sha1(device, instance); result = get_core_masks(device, instance); if (result != VK_SUCCESS)