From b1619486d143050bd0c5d804488885310dd7a7ca Mon Sep 17 00:00:00 2001 From: HeYue Date: Tue, 24 Jun 2025 13:49:01 +0800 Subject: [PATCH] Use igpu for the sw usage codec buffer The camera use CPU to transcode, has sw read/write flag, need use igpu to allocate buffer, otherwise has frame drop issue. Tracked-On: Signed-off-by: HeYue --- cros_gralloc/cros_gralloc_driver.cc | 32 +++++++++++++++++++++++++++-- cros_gralloc/cros_gralloc_driver.h | 2 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index f5144d4c..3627d5e5 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -274,7 +274,7 @@ cros_gralloc_driver::cros_gralloc_driver(): drivers_(GPU_GRP_TYPE_NR, nullptr) drv_loge("No known device found!\n"); if (fallback_fd >= 0) { drv_fallback_ = drv_create(fallback_fd, gpu_grp_type_); - drv_render_ = drv_kms_ = drv_video_ = drv_fallback_; + drv_render_ = drv_kms_ = drv_video_ = drv_sw_video_ = drv_fallback_; } return; } @@ -296,6 +296,10 @@ cros_gralloc_driver::cros_gralloc_driver(): drivers_(GPU_GRP_TYPE_NR, nullptr) if (idx != -1) { drv_video_ = drivers_[idx]; } + idx = select_sw_video_driver(gpu_grp_type_); + if (idx != -1) { + drv_sw_video_ = drivers_[idx]; + } if (gpu_grp_type_ & GPU_GRP_TYPE_HAS_VIRTIO_GPU_IVSHMEM_BIT) { drv_ivshmem_ = drivers_[GPU_GRP_TYPE_VIRTIO_GPU_IVSHMEM_IDX]; } @@ -360,6 +364,9 @@ struct driver *cros_gralloc_driver::select_driver(const struct cros_gralloc_buff return drv_ivshmem_; } } + if (is_video_format(descriptor) && ((descriptor->use_flags & BO_USE_SW_READ_OFTEN) && (descriptor->use_flags & BO_USE_SW_WRITE_OFTEN))) { + return drv_sw_video_; + } if (is_video_format(descriptor)) { return drv_video_; } @@ -1008,4 +1015,25 @@ int cros_gralloc_driver::select_video_driver(uint64_t gpu_grp_type) } return -1; } - +int cros_gralloc_driver::select_sw_video_driver(uint64_t gpu_grp_type) +{ + if (gpu_grp_type & GPU_GRP_TYPE_HAS_INTEL_IGPU_BIT) { + return GPU_GRP_TYPE_INTEL_IGPU_IDX; + } + if (gpu_grp_type & GPU_GRP_TYPE_HAS_INTEL_DGPU_BIT) { + return GPU_GRP_TYPE_INTEL_DGPU_IDX; + } + if (gpu_grp_type & GPU_GRP_TYPE_HAS_VIRTIO_GPU_BLOB_BIT) { + return GPU_GRP_TYPE_VIRTIO_GPU_BLOB_IDX; + } + if (gpu_grp_type & GPU_GRP_TYPE_HAS_VIRTIO_GPU_BLOB_P2P_BIT) { + return GPU_GRP_TYPE_VIRTIO_GPU_BLOB_P2P_IDX; + } + if (gpu_grp_type & GPU_GRP_TYPE_HAS_VIRTIO_GPU_NO_BLOB_BIT) { + return GPU_GRP_TYPE_VIRTIO_GPU_NO_BLOB_IDX; + } + if (gpu_grp_type & GPU_GRP_TYPE_HAS_VIRTIO_GPU_IVSHMEM_BIT) { + return GPU_GRP_TYPE_VIRTIO_GPU_IVSHMEM_IDX; + } + return -1; +} diff --git a/cros_gralloc/cros_gralloc_driver.h b/cros_gralloc/cros_gralloc_driver.h index cf1ed5b0..6c45f27a 100644 --- a/cros_gralloc/cros_gralloc_driver.h +++ b/cros_gralloc/cros_gralloc_driver.h @@ -68,6 +68,7 @@ class cros_gralloc_driver static int select_render_driver(uint64_t gpu_grp_type); static int select_kms_driver(uint64_t gpu_grp_type); static int select_video_driver(uint64_t gpu_grp_type); + static int select_sw_video_driver(uint64_t gpu_grp_type); void set_gpu_grp_type(); struct driver *select_driver(const struct cros_gralloc_buffer_descriptor *descriptor, bool retain = false); int32_t reload(); @@ -98,6 +99,7 @@ class cros_gralloc_driver // otherwise they may be the same node. struct driver *drv_render_ = nullptr; struct driver *drv_video_ = nullptr; + struct driver *drv_sw_video_ = nullptr; // the drv_kms_ is used to allocate scanout non-video buffer. // in dGPU/iGPU SRIOV, BM or dual GPU scenario, the drv_kms_ = drv_render_ struct driver *drv_kms_ = nullptr;