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 <aswolfers@chromium.org>
Reviewed-by: Lina Versace <linyaa@google.com>
Commit-Queue: Andrew Wolfers <aswolfers@chromium.org>
This commit is contained in:
Andrew Wolfers 2025-03-12 13:30:44 +00:00 committed by Chromeos LUCI
parent aec6536741
commit 3dd534cca2
2 changed files with 24 additions and 3 deletions

View file

@ -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); handle_usage(&usage, GRALLOC_USAGE_EXTERNAL_DISP, &use_flags, BO_USE_NONE);
/* Map PROTECTED to linear until real HW protection is available on Android. */ /* 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_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. */ /* HACK: See b/30054495 for BO_USE_SW_READ_OFTEN. */
handle_usage(&usage, GRALLOC_USAGE_HW_VIDEO_ENCODER, &use_flags, handle_usage(&usage, GRALLOC_USAGE_HW_VIDEO_ENCODER, &use_flags,
BO_USE_HW_VIDEO_ENCODER | BO_USE_SW_READ_OFTEN); BO_USE_HW_VIDEO_ENCODER | BO_USE_SW_READ_OFTEN);

25
i915.c
View file

@ -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, 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 use_flags, const uint64_t *modifiers, uint32_t count)
{ {
uint64_t modifier;
struct i915_device *i915 = bo->drv->priv; struct i915_device *i915 = bo->drv->priv;
bool huge_bo = (i915->graphics_version < 11) && (width > 4096);
uint64_t modifier;
if (modifiers) { if (modifiers) {
modifier = modifier =
drv_pick_modifier(modifiers, count, i915->modifier.order, i915->modifier.count); 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; 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. * 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. * 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 && if (huge_bo && format != DRM_FORMAT_NV12 && format != DRM_FORMAT_P010 &&
modifier != I915_FORMAT_MOD_X_TILED && modifier != DRM_FORMAT_MOD_LINEAR) { modifier != I915_FORMAT_MOD_X_TILED && modifier != DRM_FORMAT_MOD_LINEAR) {
uint32_t i; uint32_t i;