OSDN Git Service

minigbm: virtio: restrict formats supported without 3D
authorDominik Behr <dbehr@chromium.org>
Wed, 9 Oct 2019 22:43:52 +0000 (15:43 -0700)
committerCommit Bot <commit-bot@chromium.org>
Thu, 12 Dec 2019 06:36:24 +0000 (06:36 +0000)
Upstream virtio drm commit "drm/virtio: fix DRM_FORMAT_* handling" severely
restricts supported formats and strictly enforces 32bpp dumb buffers.
Therefore now we only support XRGB8888 for scanout, ARGB8888 for cursor,
ARGB8888 for rendering. Also, we pretend all buffers are 32bpp when allocating
as dumb buffers.

BUG=none
TEST=tast run 127.0.0.1:9222 webrtc.RTCPeerConnection.vp8

Change-Id: I6225a9cb3c49f0850c6d94b2d12efaf9a33b149e
Signed-off-by: Dominik Behr <dbehr@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/1849773
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
drv.h
helpers.c
helpers.h
virtio_gpu.c

diff --git a/drv.h b/drv.h
index 15b9736..d3cfb45 100644 (file)
--- a/drv.h
+++ b/drv.h
@@ -37,6 +37,9 @@ extern "C" {
 #define BO_USE_HW_VIDEO_DECODER         (1ull << 14)
 #define BO_USE_RENDERSCRIPT            (1ull << 15)
 
+/* Quirks for allocating a buffer. */
+#define BO_QUIRK_NONE                  0
+#define BO_QUIRK_DUMB32BPP             (1ull << 0)
 
 /* Map flags */
 #define BO_MAP_NONE 0
index ad8a9f0..ec5fdac 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -272,8 +272,8 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height,
        return 0;
 }
 
-int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
-                      uint64_t use_flags)
+int drv_dumb_bo_create_ex(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+                         uint64_t use_flags, uint64_t quirks)
 {
        int ret;
        size_t plane;
@@ -303,9 +303,15 @@ int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t
        }
 
        memset(&create_dumb, 0, sizeof(create_dumb));
-       create_dumb.height = aligned_height;
+       if (quirks & BO_QUIRK_DUMB32BPP) {
+               aligned_width =
+                   DIV_ROUND_UP(aligned_width * layout_from_format(format)->bytes_per_pixel[0], 4);
+               create_dumb.bpp = 32;
+       } else {
+               create_dumb.bpp = layout_from_format(format)->bytes_per_pixel[0] * 8;
+       }
        create_dumb.width = aligned_width;
-       create_dumb.bpp = layout_from_format(format)->bytes_per_pixel[0] * 8;
+       create_dumb.height = aligned_height;
        create_dumb.flags = 0;
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
@@ -323,6 +329,12 @@ int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t
        return 0;
 }
 
+int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+                      uint64_t use_flags)
+{
+       return drv_dumb_bo_create_ex(bo, width, height, format, use_flags, BO_QUIRK_NONE);
+}
+
 int drv_dumb_bo_destroy(struct bo *bo)
 {
        struct drm_mode_destroy_dumb destroy_dumb;
index c09d2c2..c503b01 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -17,6 +17,8 @@ uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height,
 int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format);
 int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
                       uint64_t use_flags);
+int drv_dumb_bo_create_ex(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+                         uint64_t use_flags, uint64_t quirks);
 int drv_dumb_bo_destroy(struct bo *bo);
 int drv_gem_bo_destroy(struct bo *bo);
 int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
index aa3378c..50ca997 100644 (file)
@@ -75,7 +75,7 @@ static int virtio_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
                height = ALIGN(height, MESA_LLVMPIPE_TILE_SIZE);
        }
 
-       return drv_dumb_bo_create(bo, width, height, format, use_flags);
+       return drv_dumb_bo_create_ex(bo, width, height, format, use_flags, BO_QUIRK_DUMB32BPP);
 }
 
 static inline void handle_flag(uint64_t *flag, uint64_t check_flag, uint32_t *bind,
@@ -197,16 +197,26 @@ static int virtio_gpu_init(struct driver *drv)
                priv->has_3d = 0;
        }
 
-       /* This doesn't mean host can scanout everything, it just means host
-        * hypervisor can show it. */
-       drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
-                            &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT);
-
        if (priv->has_3d) {
+               /* This doesn't mean host can scanout everything, it just means host
+                * hypervisor can show it. */
+               drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
+                                    &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT);
                drv_add_combinations(drv, texture_source_formats,
                                     ARRAY_SIZE(texture_source_formats), &LINEAR_METADATA,
                                     BO_USE_TEXTURE_MASK);
        } else {
+               /* Virtio primary plane only allows this format. */
+               drv_add_combination(drv, DRM_FORMAT_XRGB8888, &LINEAR_METADATA,
+                                   BO_USE_RENDER_MASK | BO_USE_SCANOUT);
+               /* Virtio cursor plane only allows this format and Chrome cannot live without
+                * ARGB888 renderable format. */
+               drv_add_combination(drv, DRM_FORMAT_ARGB8888, &LINEAR_METADATA,
+                                   BO_USE_RENDER_MASK | BO_USE_CURSOR);
+               /* Android needs more, but they cannot be bound as scanouts anymore after
+                * "drm/virtio: fix DRM_FORMAT_* handling" */
+               drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
+                                    &LINEAR_METADATA, BO_USE_RENDER_MASK);
                drv_add_combinations(drv, dumb_texture_source_formats,
                                     ARRAY_SIZE(dumb_texture_source_formats), &LINEAR_METADATA,
                                     BO_USE_TEXTURE_MASK);