From 5026ecb26f728277c239c86d9ad9d9331b0832fe Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 30 May 2024 15:34:31 -0700 Subject: [PATCH 1/7] anv: use os_get_option instead of getenv so that the queue count override logic can catch Android system properties. Signed-off-by: Yiwei Zhang Reviewed-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_device.c | 6 +++--- src/intel/vulkan_hasvk/anv_device.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 13f534934f9..5615df6f1a5 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -1968,12 +1968,12 @@ anv_override_engine_counts(int *gc_count, int *g_count, int *c_count, int *v_cou int g_override = -1; int c_override = -1; int v_override = -1; - char *env = getenv("ANV_QUEUE_OVERRIDE"); + const char *env_ = os_get_option("ANV_QUEUE_OVERRIDE"); - if (env == NULL) + if (env_ == NULL) return; - env = strdup(env); + char *env = strdup(env_); char *save = NULL; char *next = strtok_r(env, ",", &save); while (next != NULL) { diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c index 2819dd634b2..434d533e89e 100644 --- a/src/intel/vulkan_hasvk/anv_device.c +++ b/src/intel/vulkan_hasvk/anv_device.c @@ -875,12 +875,12 @@ anv_override_engine_counts(int *gc_count, int *g_count, int *c_count) int gc_override = -1; int g_override = -1; int c_override = -1; - char *env = getenv("ANV_QUEUE_OVERRIDE"); + const char *env_ = os_get_option("ANV_QUEUE_OVERRIDE"); - if (env == NULL) + if (env_ == NULL) return; - env = strdup(env); + char *env = strdup(env_); char *save = NULL; char *next = strtok_r(env, ",", &save); while (next != NULL) { From eba4b6d6ad83a209b58f06a18b16ca7178be7718 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Tue, 8 Oct 2024 16:35:12 -0700 Subject: [PATCH 2/7] android: look for debug/vendor prefixed options Properties from the vendor partition must use a "vendor." prefix from Android T+. Meanwhile the "debug." prefix can be used for local overrides. The order of precedence thus becomes: 1. getenv 2. debug.mesa.* 3. vendor.mesa.* 4. mesa.* (as a fallback for older versions) Tracked-On: OAM-126014 Signed-off-by: Juston Li Part-of: --- src/util/os_misc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/util/os_misc.c b/src/util/os_misc.c index 7261577488f..99d63e27aa4 100644 --- a/src/util/os_misc.c +++ b/src/util/os_misc.c @@ -142,7 +142,10 @@ os_log_message(const char *message) * * 1) convert to lowercase * 2) replace '_' with '.' - * 3) if necessary, prepend "mesa." + * 3) replace "MESA_" or prepend with "mesa." + * 4) look for "debug.mesa." prefix + * 5) look for "vendor.mesa." prefix + * 6) look for "mesa." prefix * * For example: * - MESA_EXTENSION_OVERRIDE -> mesa.extension.override @@ -167,9 +170,16 @@ os_get_android_option(const char *name) } } - int len = property_get(key, os_android_option_value, NULL); - if (len > 1) { - return os_android_option_value; + /* prefixes to search sorted by preference */ + const char *prefices[] = { "debug.", "vendor.", "" }; + char full_key[PROPERTY_KEY_MAX]; + int len = 0; + for (int i = 0; i < ARRAY_SIZE(prefices); i++) { + strlcpy(full_key, prefices[i], PROPERTY_KEY_MAX); + strlcat(full_key, key, PROPERTY_KEY_MAX); + len = property_get(full_key, os_android_option_value, NULL); + if (len > 0) + return os_android_option_value; } return NULL; } From 79e5b76aa14e865047f5835bfcc13430d781a2e3 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Fri, 21 Jun 2024 11:54:27 -0700 Subject: [PATCH 3/7] anv/android: remove unneeded ANB implicit import flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ANB is only used by Android WSI which uses explicit sync so these flags can be dropped. Signed-off-by: Juston Li Reviewed-by: Tapani Pälli Part-of: (cherry picked from commit 34031e3e3bf19438b8ea482b231f20bd5cf9a70f) --- src/intel/vulkan/anv_android.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index b3405f6c96f..b6751a61278 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -338,19 +338,13 @@ anv_image_init_from_gralloc(struct anv_device *device, */ int dma_buf = gralloc_info->handle->data[0]; - /* We need to set the WRITE flag on window system buffers so that GEM will - * know we're writing to them and synchronize uses on other rings (for - * example, if the display server uses the blitter ring). - * - * If this function fails and if the imported bo was resident in the cache, + /* If this function fails and if the imported bo was resident in the cache, * we should avoid updating the bo's flags. Therefore, we defer updating * the flags until success is certain. * */ result = anv_device_import_bo(device, dma_buf, - ANV_BO_ALLOC_EXTERNAL | - ANV_BO_ALLOC_IMPLICIT_SYNC | - ANV_BO_ALLOC_IMPLICIT_WRITE, + ANV_BO_ALLOC_EXTERNAL, 0 /* client_address */, &bo); if (result != VK_SUCCESS) { @@ -440,20 +434,14 @@ anv_image_bind_from_gralloc(struct anv_device *device, */ int dma_buf = gralloc_info->handle->data[0]; - /* We need to set the WRITE flag on window system buffers so that GEM will - * know we're writing to them and synchronize uses on other rings (for - * example, if the display server uses the blitter ring). - * - * If this function fails and if the imported bo was resident in the cache, + /* If this function fails and if the imported bo was resident in the cache, * we should avoid updating the bo's flags. Therefore, we defer updating * the flags until success is certain. * */ struct anv_bo *bo = NULL; VkResult result = anv_device_import_bo(device, dma_buf, - ANV_BO_ALLOC_EXTERNAL | - ANV_BO_ALLOC_IMPLICIT_SYNC | - ANV_BO_ALLOC_IMPLICIT_WRITE, + ANV_BO_ALLOC_EXTERNAL, 0 /* client_address */, &bo); if (result != VK_SUCCESS) { From 73cf3429d3b6f42ca946584855cf3843db6b7091 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Mon, 8 Jul 2024 12:51:12 -0700 Subject: [PATCH 4/7] anv/android: handle R8G8B8X8 as R8G8B8A8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fall through to common vk_ahb_format_to_image_format() to handle R8G8B8X8 as R8G8B8A8. Fixes issues with querying for format feature support when its handled as R8G8B8. Signed-off-by: Juston Li Reviewed-by: Yiwei Zhang Reviewed-by: Tapani Pälli Part-of: (cherry picked from commit ef58f2408fe3d2454c22a2acecf4c73f9936c0db) --- src/intel/vulkan/anv_android.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index b6751a61278..c0d501562b8 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -114,8 +114,6 @@ inline VkFormat vk_format_from_android(unsigned android_format, unsigned android_usage) { switch (android_format) { - case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: - return VK_FORMAT_R8G8B8_UNORM; case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420: case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL: return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; From 925915fe84e27ae505a0d1d4650cb334699995a3 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Fri, 21 Jun 2024 11:50:30 -0700 Subject: [PATCH 5/7] anv/android: refactor out u_gralloc tiling query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor out shared code for the u_gralloc tiling query so it can also be used by ahw and later anb resolves. Signed-off-by: Juston Li Reviewed-by: Tapani Pälli Part-of: (cherry picked from commit bcb17acab9c2ac019a4738622e8de728587ff712) --- src/intel/vulkan/anv_android.c | 37 ++++++++++++++++++++-------- src/intel/vulkan/anv_android.h | 7 ++++++ src/intel/vulkan/anv_android_stubs.c | 8 ++++++ src/intel/vulkan/anv_image.c | 9 ++++++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index c0d501562b8..94d6b715e6a 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -316,6 +316,30 @@ anv_import_ahw_memory(VkDevice device_h, #endif } +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out) +{ + assert(device->u_gralloc); + + struct u_gralloc_buffer_basic_info buf_info; + if (u_gralloc_get_buffer_basic_info(device->u_gralloc, gr_handle, &buf_info)) + return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, + "failed to get tiling from gralloc buffer info"); + + const struct isl_drm_modifier_info *mod_info = + isl_drm_modifier_get_info(buf_info.modifier); + if (!mod_info) { + return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, + "invalid drm modifier from VkNativeBufferANDROID " + "gralloc buffer info 0x%"PRIx64"", buf_info.modifier); + } + + *tiling_out = mod_info->tiling; + return VK_SUCCESS; +} + VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, @@ -352,21 +376,14 @@ anv_image_init_from_gralloc(struct anv_device *device, enum isl_tiling tiling; if (device->u_gralloc) { - struct u_gralloc_buffer_basic_info buf_info; struct u_gralloc_buffer_handle gr_handle = { .handle = gralloc_info->handle, .hal_format = gralloc_info->format, .pixel_stride = gralloc_info->stride, }; - u_gralloc_get_buffer_basic_info(device->u_gralloc, &gr_handle, &buf_info); - const struct isl_drm_modifier_info *mod_info = - isl_drm_modifier_get_info(buf_info.modifier); - if (mod_info) { - tiling = mod_info->tiling; - } else { - return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, - "unknown modifier of BO from VkNativeBufferANDROID"); - } + result = anv_android_get_tiling(device, &gr_handle, &tiling); + if (result != VK_SUCCESS) + return result; } else { /* Fallback to get_tiling API. */ result = anv_device_get_bo_tiling(device, bo, &tiling); diff --git a/src/intel/vulkan/anv_android.h b/src/intel/vulkan/anv_android.h index e1f099e1f4f..6eeff850723 100644 --- a/src/intel/vulkan/anv_android.h +++ b/src/intel/vulkan/anv_android.h @@ -34,6 +34,13 @@ struct anv_device_memory; struct anv_device; struct anv_image; +struct u_gralloc_buffer_handle; +enum isl_tiling; + +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out); VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, diff --git a/src/intel/vulkan/anv_android_stubs.c b/src/intel/vulkan/anv_android_stubs.c index f1b2ef6b6f8..1c095e0aa82 100644 --- a/src/intel/vulkan/anv_android_stubs.c +++ b/src/intel/vulkan/anv_android_stubs.c @@ -23,6 +23,14 @@ #include "anv_android.h" +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out) +{ + return VK_ERROR_EXTENSION_NOT_PRESENT; +} + VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 6ead10079b2..cbadc914626 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1928,7 +1928,14 @@ resolve_ahw_image(struct anv_device *device, /* Check tiling. */ enum isl_tiling tiling; - result = anv_device_get_bo_tiling(device, mem->bo, &tiling); + const native_handle_t *handle = + AHardwareBuffer_getNativeHandle(mem->vk.ahardware_buffer); + struct u_gralloc_buffer_handle gr_handle = { + .handle = handle, + .hal_format = desc.format, + .pixel_stride = desc.stride, + }; + result = anv_android_get_tiling(device, &gr_handle, &tiling); assert(result == VK_SUCCESS); isl_tiling_flags_t isl_tiling_flags = (1u << tiling); From 60a899f6e2f27448226fc3f71da49761ef9654f9 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Wed, 19 Jun 2024 00:50:30 +0000 Subject: [PATCH 6/7] anv/android: resolve ANB swapchain images on bind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Like AHB, we don't know the layout for an image backed by gralloc swapchain memory until bind when gralloc information is passed by the platform. Signed-off-by: Juston Li Reviewed-by: Tapani Pälli Part-of: (cherry picked from commit 43cb986d9e7e33b0baf37b44a90c9edd1b9fe2b4) --- src/intel/vulkan/anv_android.c | 16 +++++++++--- src/intel/vulkan/anv_image.c | 47 +++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 94d6b715e6a..932d88ce48b 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -464,12 +464,22 @@ anv_image_bind_from_gralloc(struct anv_device *device, "failed to import dma-buf from VkNativeBufferANDROID"); } - uint64_t img_size = image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].memory_range.size; - if (img_size < bo->size) { + VkMemoryRequirements2 mem_reqs = { + .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, + }; + + anv_image_get_memory_requirements(device, image, image->vk.aspects, + &mem_reqs); + + VkDeviceSize aligned_image_size = + align64(mem_reqs.memoryRequirements.size, + mem_reqs.memoryRequirements.alignment); + + if (bo->size < aligned_image_size) { result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "dma-buf from VkNativeBufferANDROID is too small for " "VkImage: %"PRIu64"B < %"PRIu64"B", - bo->size, img_size); + bo->size, aligned_image_size); anv_device_release_bo(device, bo); return result; } diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index cbadc914626..26cd62973d1 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1638,6 +1638,15 @@ anv_image_init(struct anv_device *device, struct anv_image *image, image->n_planes = anv_get_format_planes(image->vk.format); +#ifdef VK_USE_PLATFORM_ANDROID_KHR + /* In the case of gralloc-backed swap chain image, we don't know the + * layout yet. + */ + if (vk_find_struct_const(pCreateInfo->pNext, + IMAGE_SWAPCHAIN_CREATE_INFO_KHR) != NULL) + return VK_SUCCESS; +#endif + image->from_wsi = vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA) != NULL; @@ -1863,9 +1872,9 @@ VkResult anv_CreateImage( __LINE__, pCreateInfo->flags); #ifndef VK_USE_PLATFORM_ANDROID_KHR - /* Ignore swapchain creation info on Android. Since we don't have an - * implementation in Mesa, we're guaranteed to access an Android object - * incorrectly. + /* Skip the WSI common swapchain creation here on Android. Similar to ahw, + * this case is handled by a partial image init and then resolved when the + * image is bound and gralloc info is passed. */ const VkImageSwapchainCreateInfoKHR *swapchain_info = vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR); @@ -1956,6 +1965,36 @@ resolve_ahw_image(struct anv_device *device, #endif } +static void +resolve_anb_image(struct anv_device *device, + struct anv_image *image, + const VkNativeBufferANDROID *gralloc_info) +{ +#if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 29 + VkResult result; + + /* Check tiling. */ + enum isl_tiling tiling; + struct u_gralloc_buffer_handle gr_handle = { + .handle = gralloc_info->handle, + .hal_format = gralloc_info->format, + .pixel_stride = gralloc_info->stride, + }; + result = anv_android_get_tiling(device, &gr_handle, &tiling); + assert(result == VK_SUCCESS); + + isl_tiling_flags_t isl_tiling_flags = (1u << tiling); + + /* Now we are able to fill anv_image fields properly and create + * isl_surface for it. + */ + result = add_all_surfaces_implicit_layout(device, image, NULL, gralloc_info->stride, + isl_tiling_flags, + ISL_SURF_USAGE_DISABLE_AUX_BIT); + assert(result == VK_SUCCESS); +#endif +} + void anv_image_get_memory_requirements(struct anv_device *device, struct anv_image *image, @@ -2366,6 +2405,8 @@ anv_bind_image_memory(struct anv_device *device, gralloc_info); if (result != VK_SUCCESS) return result; + + resolve_anb_image(device, image, gralloc_info); did_bind = true; break; } From 76add79bb77ae3e0f57b447176e2d52ece36be94 Mon Sep 17 00:00:00 2001 From: Aakash Sarkar Date: Wed, 18 Dec 2024 06:33:54 +0000 Subject: [PATCH 7/7] anv/android: Add support for missing AHB Format This patch adds the support for AHB to Vulkan format conversion for the pixel format: HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL (271). It is needed to fix the video playback crash seen while enabling ANGLE as the OpenGL ES driver with Vulkan as the backend. Crash Log: 501 517 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 517 (RenderEngine), pid 501 (surfaceflinger) 2774 2774 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 2774 2774 F DEBUG : Build fingerprint: 'intel/caas/caas:15/AP3A.241005.015.A2/eng.celado.00000000.000000:userdebug/test-keys' 2774 2774 F DEBUG : Revision: '0' 2774 2774 F DEBUG : ABI: 'x86_64' 2774 2774 F DEBUG : Timestamp: 2024-12-10 09:23:54.284397411+0000 2774 2774 F DEBUG : Process uptime: 208s 2774 2774 F DEBUG : Cmdline: /system/bin/surfaceflinger 2774 2774 F DEBUG : pid: 501, tid: 517, name: RenderEngine >>> /system/bin/surfaceflinger <<< 2774 2774 F DEBUG : uid: 1000 2774 2774 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- 2774 2774 F DEBUG : Abort message: 'Failed to create a valid texture. [0x71010801e090]:[848,480] isProtected:0 isWriteable:0 format:271' 2774 2774 F DEBUG : rax 0000000000000000 rbx 0000710087a941e8 rcx 0000710318a66b4e rdx 0000000000000006 2774 2774 F DEBUG : r8 0000710087a94f40 r9 0000710087a94f40 r10 0000710087a941f0 r11 0000000000000207 2774 2774 F DEBUG : r12 0000710087a94810 r13 0000000000000000 r14 00000000000001f5 r15 0000000000000205 2774 2774 F DEBUG : rdi 00000000000001f5 rsi 0000000000000205 2774 2774 F DEBUG : rbp 0000000000000000 rsp 0000710087a941e0 rip 0000710318a66b4e Tests done: - Android boot with angle and vulkan as backend - Video playback working correctly - Gallery app is not showing any visual artifacts Tracked-On: OAM-126014 Signed-off-by: Aakash Sarkar --- src/intel/vulkan/anv_android.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 932d88ce48b..e706fcbe2ce 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -104,6 +104,7 @@ anv_hal_close(struct hw_device_t *dev) #include /* See i915_private_android_types.h in minigbm. */ #define HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL 0x100 +#define HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL 0x10F enum { /* Usage bit equal to GRALLOC_USAGE_HW_CAMERA_MASK */ @@ -116,6 +117,7 @@ vk_format_from_android(unsigned android_format, unsigned android_usage) switch (android_format) { case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420: case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL: + case HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL: return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; case AHARDWAREBUFFER_FORMAT_YV12: return VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;