diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index bb871d55..f5144d4c 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -395,15 +395,15 @@ bool cros_gralloc_driver::get_resolved_format_and_use_flags( resolved_use_flags &= ~BO_USE_SCANOUT; combo = drv_get_combination(drv, resolved_format, descriptor->use_flags); } - // if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) && - // descriptor->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) { - // // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly - // // intermediate formats not passed directly to the encoder (e.g. - // // camera). YV12 is passed to the encoder component, but it is converted - // // to YCbCr_420_888 before being passed to the hw encoder. - // resolved_use_flags &= ~BO_USE_HW_VIDEO_ENCODER; - // combo = drv_get_combination(drv, resolved_format, resolved_use_flags); - // } + if (!combo && (descriptor->droid_usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) && + descriptor->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) { + // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly + // intermediate formats not passed directly to the encoder (e.g. + // camera). YV12 is passed to the encoder component, but it is converted + // to YCbCr_420_888 before being passed to the hw encoder. + resolved_use_flags &= ~BO_USE_HW_VIDEO_ENCODER; + combo = drv_get_combination(drv, resolved_format, resolved_use_flags); + } if (!combo && (descriptor->droid_usage & BUFFER_USAGE_FRONT_RENDERING_MASK)) { resolved_use_flags &= ~BO_USE_FRONT_RENDERING; resolved_use_flags |= BO_USE_LINEAR; diff --git a/cros_gralloc/cros_gralloc_helpers.cc b/cros_gralloc/cros_gralloc_helpers.cc index 179100be..43fa3583 100644 --- a/cros_gralloc/cros_gralloc_helpers.cc +++ b/cros_gralloc/cros_gralloc_helpers.cc @@ -154,7 +154,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage) handle_usage(&usage, GRALLOC_USAGE_HW_RENDER, &use_flags, BO_USE_RENDERING); handle_usage(&usage, GRALLOC_USAGE_HW_2D, &use_flags, BO_USE_RENDERING); /* HWC wants to use display hardware, but can defer to OpenGL. */ - handle_usage(&usage, GRALLOC_USAGE_HW_COMPOSER, &use_flags, BO_USE_TEXTURE | BO_USE_SCANOUT); + handle_usage(&usage, GRALLOC_USAGE_HW_COMPOSER, &use_flags, BO_USE_TEXTURE); handle_usage(&usage, GRALLOC_USAGE_PRIVATE_1, &use_flags, BO_USE_SCANOUT); handle_usage(&usage, GRALLOC_USAGE_HW_FB, &use_flags, BO_USE_NONE); /* @@ -167,7 +167,7 @@ uint64_t cros_gralloc_convert_usage(uint64_t usage) handle_usage(&usage, GRALLOC_USAGE_CURSOR, &use_flags, BO_USE_NONE); /* 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*/); + BO_USE_HW_VIDEO_ENCODER | BO_USE_SW_READ_OFTEN); handle_usage(&usage, GRALLOC_USAGE_HW_CAMERA_WRITE, &use_flags, BO_USE_CAMERA_WRITE); handle_usage(&usage, GRALLOC_USAGE_HW_CAMERA_READ, &use_flags, BO_USE_CAMERA_READ); handle_usage(&usage, GRALLOC_USAGE_RENDERSCRIPT, &use_flags, BO_USE_RENDERSCRIPT); diff --git a/xe.c b/xe.c index 111c019a..40c5a7a8 100644 --- a/xe.c +++ b/xe.c @@ -182,7 +182,7 @@ static int xe_add_combinations(struct driver *drv) BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_HW_VIDEO_DECODER | BO_USE_HW_VIDEO_ENCODER | BO_USE_GPU_DATA_BUFFER | BO_USE_SENSOR_DIRECT_DATA); - drv_modify_combination(drv, DRM_FORMAT_ABGR8888, &metadata_linear, BO_USE_CURSOR | BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER); + drv_modify_combination(drv, DRM_FORMAT_ABGR8888, &metadata_linear, BO_USE_CURSOR | BO_USE_SCANOUT); drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata_linear, BO_USE_RENDERING | BO_USE_TEXTURE | BO_USE_CAMERA_MASK); drv_modify_combination(drv, DRM_FORMAT_YUYV, &metadata_linear, @@ -240,9 +240,9 @@ static int xe_add_combinations(struct driver *drv) &metadata_4_tiled, render_not_linear); drv_add_combinations(drv, scanout_render_formats, ARRAY_SIZE(scanout_render_formats), &metadata_4_tiled, - scanout_and_render_not_linear); - drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_4_tiled, - texture_flags | BO_USE_NON_GPU_HW); + render_not_linear); + drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_4_tiled, + texture_flags | BO_USE_NON_GPU_HW); } else { struct format_metadata metadata_y_tiled = { .tiling = XE_TILING_Y, @@ -268,7 +268,7 @@ static int xe_add_combinations(struct driver *drv) */ drv_add_combinations(drv, scanout_render_formats, ARRAY_SIZE(scanout_render_formats), &metadata_y_tiled, - scanout_and_render_not_linear); + render_not_linear); drv_add_combinations(drv, source_formats, ARRAY_SIZE(source_formats), &metadata_y_tiled, texture_flags | BO_USE_NON_GPU_HW); @@ -347,11 +347,7 @@ static void xe_clflush(void *start, size_t size) __builtin_ia32_mfence(); while (p < end) { - #if defined(__CLFLUSHOPT__) - __builtin_ia32_clflushopt(p); - #else - __builtin_ia32_clflush(p); - #endif + __builtin_ia32_clflush(p); p = (void *)((uintptr_t)p + XE_CACHELINE_SIZE); } } @@ -657,6 +653,7 @@ static int xe_bo_create_from_metadata(struct bo *bo) int ret; size_t plane; uint32_t gem_handle; + uint32_t vm; /* From xe_drm.h: If a VM is specified, this BO must: * 1. Only ever be bound to that VM. @@ -665,28 +662,17 @@ static int xe_bo_create_from_metadata(struct bo *bo) * Should all buffers be defined as external? See here: * https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/intel/vulkan/xe/anv_kmd_backend.c?ref_type=heads#L60 */ + vm = 0; struct drm_xe_gem_create gem_create = { - .vm_id = 0, + .vm_id = vm, .size = ALIGN(bo->meta.total_size, PAGE_SIZE), - .flags = 0, + .flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT, }; + /* FIXME: let's assume iGPU with SYSMEM is only supported */ gem_create.placement |= BITFIELD_BIT(DRM_XE_MEM_REGION_CLASS_SYSMEM); - if ((bo->meta.use_flags & BO_USE_SCANOUT) && - !(bo->meta.use_flags & (BO_USE_RENDERSCRIPT | BO_USE_CAMERA_READ - | BO_USE_CAMERA_WRITE | BO_USE_SW_READ_OFTEN))) { - gem_create.flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT; - gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC; - } else if (((bo->meta.use_flags & BO_USE_SW_WRITE_OFTEN) || - (bo->meta.use_flags & BO_USE_SW_READ_OFTEN)) && - !(bo->meta.use_flags & BO_USE_HW_VIDEO_ENCODER)) { - gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WB; - } else { - gem_create.flags = DRM_XE_GEM_CREATE_FLAG_SCANOUT; - gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC; - } - + gem_create.cpu_caching = DRM_XE_GEM_CPU_CACHING_WC; ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_CREATE, &gem_create); if (ret) { @@ -730,17 +716,20 @@ static void *xe_bo_map(struct bo *bo, struct vma *vma, uint32_t map_flags) struct xe_device *xe = bo->drv->priv; if ((bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_CCS) || - (bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS)) + (bo->meta.format_modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS) || + (bo->meta.format_modifier == I915_FORMAT_MOD_4_TILED)) return MAP_FAILED; - struct drm_xe_gem_mmap_offset gem_map = { 0 }; - gem_map.handle = bo->handles[0].u32; + if ((bo->meta.tiling == XE_TILING_NONE) || (addr == MAP_FAILED)) { + struct drm_xe_gem_mmap_offset gem_map = { 0 }; + gem_map.handle = bo->handles[0].u32; - /* Get the fake offset back */ - ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &gem_map); - if (ret == 0) - addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags), - MAP_SHARED, bo->drv->fd, gem_map.offset); + /* Get the fake offset back */ + ret = drmIoctl(bo->drv->fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &gem_map); + if (ret == 0) + addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags), + MAP_SHARED, bo->drv->fd, gem_map.offset); + } if (addr == MAP_FAILED) { drv_loge("xe GEM mmap failed\n"); @@ -760,8 +749,7 @@ static int xe_bo_invalidate(struct bo *bo, struct mapping *mapping) static int xe_bo_flush(struct bo *bo, struct mapping *mapping) { struct xe_device *xe = bo->drv->priv; - if ((bo->meta.tiling == XE_TILING_NONE) - && (bo->meta.use_flags & BO_USE_SW_WRITE_OFTEN)) + if (bo->meta.tiling == XE_TILING_NONE) xe_clflush(mapping->vma->addr, mapping->vma->length); return 0;