From a96bb3b5b514a8da5c7b158dfed930621fcc582e Mon Sep 17 00:00:00 2001 From: "He, Yue" Date: Fri, 1 Nov 2024 08:02:08 +0000 Subject: [PATCH] Add the special gralloc private 2 flag check If has the GRALLOC_USAGE_PRIVATE_2, use local memory, otherwise use the system memroy. Tracked-On: OAM-127209 Signed-off-by: He, Yue --- cros_gralloc/cros_gralloc_helpers.cc | 1 + drv.h | 1 + i915.c | 17 +++++++++-------- virtgpu_cross_domain.c | 2 +- virtgpu_virgl.c | 8 ++++---- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc index 6ded3880..83aefed7 100644 --- a/cros_gralloc/cros_gralloc_helpers.cc +++ b/cros_gralloc/cros_gralloc_helpers.cc @@ -160,6 +160,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage) BO_USE_SENSOR_DIRECT_DATA); handle_usage(&usage, BUFFER_USAGE_GPU_DATA_BUFFER, &use_flags, BO_USE_GPU_DATA_BUFFER); handle_usage(&usage, BUFFER_USAGE_FRONT_RENDERING_MASK, &use_flags, BO_USE_FRONT_RENDERING); + handle_usage(&usage, GRALLOC_USAGE_PRIVATE_2, &use_flags, BO_USE_LOCAL_MEMORY); if (usage) { ALOGE("Unhandled gralloc usage: %llx", (unsigned long long)usage); diff --git a/drv.h b/drv.h index d4d0ff28..5da5b526 100644 --- a/drv.h +++ b/drv.h @@ -45,6 +45,7 @@ extern "C" { #define BO_USE_RENDERSCRIPT (1ull << 17) #define BO_USE_GPU_DATA_BUFFER (1ull << 18) #define BO_USE_SENSOR_DIRECT_DATA (1ull << 19) +#define BO_USE_LOCAL_MEMORY (1ull << 20) #define BO_USE_ARC_SCREEN_CAP_PROBED (1ull << 63) diff --git a/i915.c b/i915.c index a07a7b5b..ea21a8e0 100644 --- a/i915.c +++ b/i915.c @@ -214,10 +214,9 @@ static int i915_add_combinations(struct driver *drv) { struct i915_device *i915 = drv->priv; - const uint64_t scanout_and_render = BO_USE_RENDER_MASK | BO_USE_SCANOUT; - const uint64_t render = BO_USE_RENDER_MASK; - const uint64_t texture_only = BO_USE_TEXTURE_MASK; - uint64_t render_flags = BO_USE_RENDER_MASK; + const uint64_t scanout_and_render = BO_USE_RENDER_MASK | BO_USE_SCANOUT | BO_USE_LOCAL_MEMORY; + const uint64_t render = BO_USE_RENDER_MASK | BO_USE_LOCAL_MEMORY; + const uint64_t texture_only = BO_USE_TEXTURE_MASK | BO_USE_LOCAL_MEMORY; uint64_t texture_flags = BO_USE_TEXTURE_MASK; bool is_kvm = vm_type() & HYPERTYPE_TYPE_KVM; @@ -915,14 +914,16 @@ static int i915_bo_compute_metadata(struct bo *bo, uint32_t width, uint32_t heig static bool is_need_local(int64_t use_flags) { - static bool local = true; + static bool local = false; + + if (use_flags & BO_USE_LOCAL_MEMORY) { + local = true; + } if (use_flags & BO_USE_SW_READ_RARELY || use_flags & BO_USE_SW_READ_OFTEN || use_flags & BO_USE_SW_WRITE_RARELY || use_flags & BO_USE_SW_WRITE_OFTEN) { local = false; - } else { - local = true; - } + return local; } diff --git a/virtgpu_cross_domain.c b/virtgpu_cross_domain.c index 45b5580b..0c4ecb0f 100644 --- a/virtgpu_cross_domain.c +++ b/virtgpu_cross_domain.c @@ -76,7 +76,7 @@ static void add_combinations(struct driver *drv) metadata.modifier = DRM_FORMAT_MOD_LINEAR; drv_add_combinations(drv, scanout_render_formats, ARRAY_SIZE(scanout_render_formats), - &metadata, BO_USE_RENDER_MASK | BO_USE_SCANOUT); + &metadata, BO_USE_RENDER_MASK | BO_USE_SCANOUT | BO_USE_LOCAL_MEMORY); drv_add_combinations(drv, texture_only_formats, ARRAY_SIZE(texture_only_formats), &metadata, BO_USE_TEXTURE_MASK); diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index ed6890e5..afff827d 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -625,7 +625,7 @@ static int virgl_init(struct driver *drv) * hypervisor can show it. */ virgl_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), &LINEAR_METADATA, - BO_USE_RENDER_MASK | BO_USE_SCANOUT); + BO_USE_RENDER_MASK | BO_USE_SCANOUT | BO_USE_LOCAL_MEMORY); virgl_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), &LINEAR_METADATA, BO_USE_TEXTURE_MASK); @@ -638,16 +638,16 @@ static int virgl_init(struct driver *drv) } else { /* Virtio primary plane only allows this format. */ virgl_add_combination(drv, DRM_FORMAT_XRGB8888, &LINEAR_METADATA, - BO_USE_RENDER_MASK | BO_USE_SCANOUT); + BO_USE_RENDER_MASK | BO_USE_SCANOUT | BO_USE_LOCAL_MEMORY); /* Virtio cursor plane only allows this format and Chrome cannot live without * ARGB888 renderable format. */ virgl_add_combination(drv, DRM_FORMAT_ARGB8888, &LINEAR_METADATA, - BO_USE_RENDER_MASK | BO_USE_CURSOR); + BO_USE_RENDER_MASK | BO_USE_CURSOR | BO_USE_LOCAL_MEMORY); /* Android needs more, but they cannot be bound as scanouts anymore after * "drm/virtio: fix DRM_FORMAT_* handling" */ virgl_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), &LINEAR_METADATA, - BO_USE_RENDER_MASK); + BO_USE_RENDER_MASK | BO_USE_LOCAL_MEMORY); virgl_add_combinations(drv, dumb_texture_source_formats, ARRAY_SIZE(dumb_texture_source_formats), &LINEAR_METADATA, BO_USE_TEXTURE_MASK);