OSDN Git Service

minigbm: add support for HAL_PIXEL_FORMAT_RGBA_FP16
[android-x86/external-minigbm.git] / i915.c
diff --git a/i915.c b/i915.c
index 9b7a6fe..af9d0ba 100644 (file)
--- a/i915.c
+++ b/i915.c
@@ -8,6 +8,7 @@
 
 #include <errno.h>
 #include <i915_drm.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/mman.h>
 #define I915_CACHELINE_SIZE 64
 #define I915_CACHELINE_MASK (I915_CACHELINE_SIZE - 1)
 
-static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888,    DRM_FORMAT_ARGB1555,
-                                                 DRM_FORMAT_ARGB8888,    DRM_FORMAT_RGB565,
-                                                 DRM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR8888,
-                                                 DRM_FORMAT_XRGB1555,    DRM_FORMAT_XRGB2101010,
-                                                 DRM_FORMAT_XRGB8888 };
+static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888,     DRM_FORMAT_ARGB1555,
+                                                 DRM_FORMAT_ARGB8888,     DRM_FORMAT_RGB565,
+                                                 DRM_FORMAT_XBGR2101010,  DRM_FORMAT_XBGR8888,
+                                                 DRM_FORMAT_XBGR16161616, DRM_FORMAT_XRGB1555,
+                                                 DRM_FORMAT_XRGB2101010,  DRM_FORMAT_XRGB8888 };
 
-static const uint32_t tileable_texture_source_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_NV12,
-                                                           DRM_FORMAT_R8, DRM_FORMAT_UYVY,
-                                                           DRM_FORMAT_YUYV };
+static const uint32_t tileable_texture_source_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_R8,
+                                                           DRM_FORMAT_UYVY, DRM_FORMAT_YUYV };
 
-static const uint32_t texture_source_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
+static const uint32_t texture_source_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID,
+                                                  DRM_FORMAT_NV12 };
 
 struct i915_device {
        uint32_t gen;
@@ -49,6 +50,31 @@ static uint32_t i915_get_gen(int device_id)
        return 4;
 }
 
+/*
+ * We allow allocation of ARGB formats for SCANOUT if the corresponding XRGB
+ * formats supports it. It's up to the caller (chrome ozone) to ultimately not
+ * scan out ARGB if the display controller only supports XRGB, but we'll allow
+ * the allocation of the bo here.
+ */
+static bool format_compatible(const struct combination *combo, uint32_t format)
+{
+       if (combo->format == format)
+               return true;
+
+       switch (format) {
+       case DRM_FORMAT_XRGB8888:
+               return combo->format == DRM_FORMAT_ARGB8888;
+       case DRM_FORMAT_XBGR8888:
+               return combo->format == DRM_FORMAT_ABGR8888;
+       case DRM_FORMAT_RGBX8888:
+               return combo->format == DRM_FORMAT_RGBA8888;
+       case DRM_FORMAT_BGRX8888:
+               return combo->format == DRM_FORMAT_BGRA8888;
+       default:
+               return false;
+       }
+}
+
 static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
 {
        uint32_t i;
@@ -60,10 +86,10 @@ static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
         */
        for (i = 0; i < drv_array_size(drv->combos); i++) {
                combo = (struct combination *)drv_array_at_idx(drv->combos, i);
-               if (combo->format != item->format)
+               if (!format_compatible(combo, item->format))
                        continue;
 
-               if (item->modifier == DRM_FORMAT_MOD_INVALID &&
+               if (item->modifier == DRM_FORMAT_MOD_LINEAR &&
                    combo->metadata.tiling == I915_TILING_X) {
                        /*
                         * FIXME: drv_query_kms() does not report the available modifiers
@@ -255,7 +281,7 @@ static int i915_init(struct driver *drv)
        get_param.value = &device_id;
        ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param);
        if (ret) {
-               fprintf(stderr, "drv: Failed to get I915_PARAM_CHIPSET_ID\n");
+               drv_log("Failed to get I915_PARAM_CHIPSET_ID\n");
                free(i915);
                return -EINVAL;
        }
@@ -267,7 +293,7 @@ static int i915_init(struct driver *drv)
        get_param.value = &i915->has_llc;
        ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param);
        if (ret) {
-               fprintf(stderr, "drv: Failed to get I915_PARAM_HAS_LLC\n");
+               drv_log("Failed to get I915_PARAM_HAS_LLC\n");
                free(i915);
                return -EINVAL;
        }
@@ -298,6 +324,8 @@ static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t h
                break;
        }
 
+       bo->format_modifiers[0] = modifier;
+
        stride = drv_stride_from_format(format, width, 0);
 
        ret = i915_align_dimensions(bo, bo->tiling, &stride, &height);
@@ -347,8 +375,7 @@ static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t h
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create);
        if (ret) {
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n",
-                       gem_create.size);
+               drv_log("DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n", gem_create.size);
                return ret;
        }
 
@@ -367,7 +394,7 @@ static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t h
                gem_close.handle = bo->handles[0].u32;
                drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
 
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_SET_TILING failed with %d", errno);
+               drv_log("DRM_IOCTL_I915_GEM_SET_TILING failed with %d\n", errno);
                return -errno;
        }
 
@@ -398,8 +425,6 @@ static int i915_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t
 
        modifier = drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order));
 
-       bo->format_modifiers[0] = modifier;
-
        return i915_bo_create_for_modifier(bo, width, height, format, modifier);
 }
 
@@ -425,7 +450,7 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_GET_TILING, &gem_get_tiling);
        if (ret) {
                drv_gem_bo_destroy(bo);
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_GET_TILING failed.");
+               drv_log("DRM_IOCTL_I915_GEM_GET_TILING failed.\n");
                return ret;
        }
 
@@ -451,7 +476,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
 
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP, &gem_map);
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_MMAP failed\n");
+                       drv_log("DRM_IOCTL_I915_GEM_MMAP failed\n");
                        return MAP_FAILED;
                }
 
@@ -464,7 +489,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
 
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &gem_map);
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_MMAP_GTT failed\n");
+                       drv_log("DRM_IOCTL_I915_GEM_MMAP_GTT failed\n");
                        return MAP_FAILED;
                }
 
@@ -473,7 +498,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
        }
 
        if (addr == MAP_FAILED) {
-               fprintf(stderr, "drv: i915 GEM mmap failed\n");
+               drv_log("i915 GEM mmap failed\n");
                return addr;
        }
 
@@ -500,7 +525,7 @@ static int i915_bo_invalidate(struct bo *bo, struct mapping *mapping)
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain);
        if (ret) {
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret);
+               drv_log("DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret);
                return ret;
        }
 
@@ -526,10 +551,16 @@ static uint32_t i915_resolve_format(uint32_t format, uint64_t use_flags)
                /*HACK: See b/28671744 */
                return DRM_FORMAT_XBGR8888;
        case DRM_FORMAT_FLEX_YCbCr_420_888:
-               /* KBL camera subsystem requires NV12. */
-               if (use_flags & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE))
-                       return DRM_FORMAT_NV12;
-               return DRM_FORMAT_YVU420;
+               /*
+                * KBL camera subsystem requires NV12. Our other use cases
+                * don't care:
+                * - Hardware video supports NV12,
+                * - USB Camera HALv3 supports NV12,
+                * - USB Camera HALv1 doesn't use this format.
+                * Moreover, NV12 is preferred for video, due to overlay
+                * support on SKL+.
+                */
+               return DRM_FORMAT_NV12;
        default:
                return format;
        }