From: Hirokazu Honda Date: Fri, 11 Oct 2019 06:54:50 +0000 (+0900) Subject: mediatek: Allocate a buffer expected by encoder if BO_USE_HW_VIDEO_ENCODER X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2a2bfc25bb4eaf53d6d1d9e1990c6b2888d4d3fb;p=android-x86%2Fexternal-minigbm.git mediatek: Allocate a buffer expected by encoder if BO_USE_HW_VIDEO_ENCODER MediaTek driver expects 16 aligned width and 32 aligned height for an input buffer on encoding [1]. Besides, there is an extra data between planes. This changes the minigbm allocation to match the expectation though width is aligned by 64 for the AMD cache-width optimization. [1] https://chromium.googlesource.com/chromiumos/third_party/kernel/+/3c551224d8600b956ed53097520501d58f31cf59/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c#278 BUG=b:144135251 TEST=ARC++ encoder on kukui Change-Id: Id330a8a6b0a40040098920427e6e29f05fcb64d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/1855520 Reviewed-by: Tomasz Figa Tested-by: Hirokazu Honda Auto-Submit: Hirokazu Honda Commit-Queue: Hsu Wei-Cheng --- diff --git a/helpers.c b/helpers.c index ec5fdac..e29f539 100644 --- a/helpers.c +++ b/helpers.c @@ -186,6 +186,15 @@ uint32_t drv_height_from_format(uint32_t format, uint32_t height, size_t plane) return DIV_ROUND_UP(height, layout->vertical_subsampling[plane]); } +uint32_t drv_vertical_subsampling_from_format(uint32_t format, size_t plane) +{ + const struct planar_layout *layout = layout_from_format(format); + + assert(plane < layout->num_planes); + + return layout->vertical_subsampling[plane]; +} + uint32_t drv_bytes_per_pixel_from_format(uint32_t format, size_t plane) { const struct planar_layout *layout = layout_from_format(format); @@ -242,7 +251,13 @@ static uint32_t subsample_stride(uint32_t stride, uint32_t format, size_t plane) */ int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format) { + uint32_t padding[DRV_MAX_PLANES] = { 0 }; + return drv_bo_from_format_and_padding(bo, stride, aligned_height, format, padding); +} +int drv_bo_from_format_and_padding(struct bo *bo, uint32_t stride, uint32_t aligned_height, + uint32_t format, uint32_t padding[DRV_MAX_PLANES]) +{ size_t p, num_planes; uint32_t offset = 0; @@ -263,7 +278,8 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, for (p = 0; p < num_planes; p++) { bo->meta.strides[p] = subsample_stride(stride, format, p); bo->meta.sizes[p] = - drv_size_from_format(format, bo->meta.strides[p], aligned_height, p); + drv_size_from_format(format, bo->meta.strides[p], aligned_height, p) + + padding[p]; bo->meta.offsets[p] = offset; offset += bo->meta.sizes[p]; } diff --git a/helpers.h b/helpers.h index c503b01..fe4519d 100644 --- a/helpers.h +++ b/helpers.h @@ -13,8 +13,11 @@ #include "helpers_array.h" uint32_t drv_height_from_format(uint32_t format, uint32_t height, size_t plane); +uint32_t drv_vertical_subsampling_from_format(uint32_t format, size_t plane); uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane); int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height, uint32_t format); +int drv_bo_from_format_and_padding(struct bo *bo, uint32_t stride, uint32_t aligned_height, + uint32_t format, uint32_t padding[DRV_MAX_PLANES]); 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, diff --git a/mediatek.c b/mediatek.c index ce84b43..5581e8f 100644 --- a/mediatek.c +++ b/mediatek.c @@ -115,7 +115,21 @@ static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint */ stride = drv_stride_from_format(format, width, 0); stride = ALIGN(stride, 64); - drv_bo_from_format(bo, stride, height, format); + + if (bo->meta.use_flags & BO_USE_HW_VIDEO_ENCODER) { + uint32_t aligned_height = ALIGN(height, 32); + uint32_t padding[DRV_MAX_PLANES] = { 0 }; + + for (plane = 0; plane < bo->meta.num_planes; ++plane) { + uint32_t plane_stride = drv_stride_from_format(format, stride, plane); + padding[plane] = plane_stride * + (32 / drv_vertical_subsampling_from_format(format, plane)); + } + + drv_bo_from_format_and_padding(bo, stride, aligned_height, format, padding); + } else { + drv_bo_from_format(bo, stride, height, format); + } memset(&gem_create, 0, sizeof(gem_create)); gem_create.size = bo->meta.total_size; @@ -252,9 +266,10 @@ static uint32_t mediatek_resolve_format(struct driver *drv, uint32_t format, uin case DRM_FORMAT_FLEX_YCbCr_420_888: #ifdef MTK_MT8183 /* MT8183 camera and decoder subsystems require NV12. */ - if (use_flags & - (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_HW_VIDEO_DECODER)) + if (use_flags & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | + BO_USE_HW_VIDEO_DECODER | BO_USE_HW_VIDEO_ENCODER)) { return DRM_FORMAT_NV12; + } #endif return DRM_FORMAT_YVU420; default: