From 34fcb9cbe2bf92672c212224e88be6ba6c1b7cdc Mon Sep 17 00:00:00 2001 From: Andrew Wolfers Date: Mon, 23 Jun 2025 17:00:47 +0000 Subject: [PATCH] virtio: Add USE_CURSOR buffer padding This change modifies buffer allocation to include necessary padding for buffers with the BO_USE_CURSOR flag. This behavior mirrors identical logic in the i915, xe, and mtk implementations. Bug: b/426503691 Change-Id: Ic572a970dcde0606fa9ec5844c57d3136c5d0b84 (cherry picked from commit f13b0faac8501a3bf3eb90f2fd07107728576876) --- virtgpu_virgl.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index 763bdbc..835a3a3 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -421,6 +421,28 @@ static void virgl_add_combinations(struct driver *drv, const uint32_t *drm_forma static int virgl_2d_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint64_t use_flags) { + /* + * 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 (bo->meta.use_flags & BO_USE_CURSOR) { + uint64_t cursor_width = 0; + uint64_t cursor_height = 0; + // These values are not properly set in virtio, and will return the default dimensions of 64x64. + 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; + } + } + if (bo->meta.format != DRM_FORMAT_R8) { width = ALIGN(width, MESA_LLVMPIPE_TILE_SIZE); height = ALIGN(height, MESA_LLVMPIPE_TILE_SIZE);