From 3dd534cca22443d6ed2c7c0e2929a0a47c2a524c Mon Sep 17 00:00:00 2001 From: Andrew Wolfers Date: Wed, 12 Mar 2025 13:30:44 +0000 Subject: [PATCH] Add padding for i915 cursor buffers This change adds behavior to pad the requested buffer size when the BO_USE_CURSOR flag is set. This change is required due to restrictions on cursor planes with the i915 driver, where a buffer must be of a particular size in order to be committed to a cursor plane. The exact requirements can be queried from the DRM_CAP_CURSOR_{WIDTH|HEIGHT} properties, which if provided, will specify a known acceptable cursor buffer size. After this change, if the BO_USE_CURSOR flag is set and the requested size is less than indicated capability, the resulting buffer will be padded according to the difference. Bug: b/378461707 , b/388014686 Change-Id: I451421cc784d1e3fdc83eb4e9762d6f0f4caea7c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/6282179 Tested-by: Andrew Wolfers Reviewed-by: Lina Versace Commit-Queue: Andrew Wolfers --- cros_gralloc/cros_gralloc_helpers.cc | 2 +- i915.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc index 945552c..9495778 100644 --- a/cros_gralloc/cros_gralloc_helpers.cc +++ b/cros_gralloc/cros_gralloc_helpers.cc @@ -128,7 +128,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage) handle_usage(&usage, GRALLOC_USAGE_EXTERNAL_DISP, &use_flags, BO_USE_NONE); /* Map PROTECTED to linear until real HW protection is available on Android. */ handle_usage(&usage, GRALLOC_USAGE_PROTECTED, &use_flags, BO_USE_LINEAR); - handle_usage(&usage, GRALLOC_USAGE_CURSOR, &use_flags, BO_USE_NONE); + handle_usage(&usage, GRALLOC_USAGE_CURSOR, &use_flags, BO_USE_CURSOR); /* HACK: See b/30054495 for BO_USE_SW_READ_OFTEN. */ handle_usage(&usage, GRALLOC_USAGE_HW_VIDEO_ENCODER, &use_flags, BO_USE_HW_VIDEO_ENCODER | BO_USE_SW_READ_OFTEN); diff --git a/i915.c b/i915.c index f1c4eb7..adfd8c5 100644 --- a/i915.c +++ b/i915.c @@ -564,10 +564,9 @@ static size_t i915_num_planes_from_modifier(struct driver *drv, uint32_t format, static int i915_bo_compute_metadata(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint64_t use_flags, const uint64_t *modifiers, uint32_t count) { - uint64_t modifier; struct i915_device *i915 = bo->drv->priv; - bool huge_bo = (i915->graphics_version < 11) && (width > 4096); + uint64_t modifier; if (modifiers) { modifier = drv_pick_modifier(modifiers, count, i915->modifier.order, i915->modifier.count); @@ -578,10 +577,32 @@ static int i915_bo_compute_metadata(struct bo *bo, uint32_t width, uint32_t heig modifier = combo->metadata.modifier; } + /* + * For cursor buffer, add padding as needed to reach a known cursor-plane-supported + * buffer size, as reported by the cursor capability properties. + * + * If the requested dimensions exceed either of the reported capabilities, or if the + * capabilities couldn't be read, silently fallback by continuing without additional + * padding. The buffer can still be used normally, and be committed to non-cursor + * planes. + */ + if (use_flags & BO_USE_CURSOR) { + uint64_t cursor_width = 0; + uint64_t cursor_height = 0; + bool err = drmGetCap(bo->drv->fd, DRM_CAP_CURSOR_WIDTH, &cursor_width) || + drmGetCap(bo->drv->fd, DRM_CAP_CURSOR_HEIGHT, &cursor_height); + + if (!err && width <= cursor_width && height <= cursor_height) { + width = cursor_width; + height = cursor_height; + } + } + /* * i915 only supports linear/x-tiled above 4096 wide on Gen9/Gen10 GPU. * VAAPI decode in NV12 Y tiled format so skip modifier change for NV12/P010 huge bo. */ + bool huge_bo = (i915->graphics_version < 11) && (width > 4096); if (huge_bo && format != DRM_FORMAT_NV12 && format != DRM_FORMAT_P010 && modifier != I915_FORMAT_MOD_X_TILED && modifier != DRM_FORMAT_MOD_LINEAR) { uint32_t i;