diff --git a/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.cpp b/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.cpp index 8a0befa133..2907555522 100644 --- a/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.cpp +++ b/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.cpp @@ -852,6 +852,17 @@ MOS_STATUS VpAllocator::ReAllocateSurface( return eStatus; } + // reuse the allocated buffer if the allocated size was larger than request size when OptimizeCpuTiming is enabled + if (m_osInterface->bOptimizeCpuTiming && + surface && + surface->osSurface && + (!Mos_ResourceIsNull(&surface->osSurface->OsResource)) && + (Format_Buffer == format) && + (surface->bufferWidth * surface->bufferHeight >= width * height)) + { + return eStatus; + } + if (surface && nullptr == surface->osSurface) { // VP_SURFACE should always be allocated by interface in VpAllocator, @@ -988,6 +999,15 @@ MOS_STATUS VpAllocator::ReAllocateSurface( return eStatus; } + // reuse the allocated buffer if the allocated size was larger than request size when OptimizeCpuTiming is enabled + if (m_osInterface->bOptimizeCpuTiming && + (!Mos_ResourceIsNull(&surface->OsResource)) && + (Format_Buffer == format) && + (surface->dwWidth * surface->dwHeight >= width * height)) + { + return eStatus; + } + MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); VpHal_AllocParamsInitType(&allocParams, surface, defaultResType, defaultTileType); diff --git a/media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.cpp b/media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.cpp index 669e26e7d1..552eaec1b4 100644 --- a/media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.cpp +++ b/media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.cpp @@ -423,6 +423,8 @@ MOS_STATUS VpPipeline::ExecuteVpPipeline() { params = m_pvpParams.renderParams; VP_PUBLIC_CHK_NULL_RETURN(params); + // Get the OptimizeCpuTiming flag from params + m_osInterface->bOptimizeCpuTiming = params->bOptimizeCpuTiming; // Set Pipeline status Table m_statusReport->SetPipeStatusReportParams(params, m_vpMhwInterface.m_statusTable); diff --git a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp index 48ff88b87e..f609d5393d 100644 --- a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp +++ b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp @@ -67,9 +67,11 @@ MOS_STATUS VpUtils::ReAllocateSurface( goto finish; } - if (osInterface->bOptimizeCpuTiming && - (defaultResType == MOS_GFXRES_BUFFER) && - (surface->dwWidth >= dwWidth)) + // reuse the allocated buffer if the allocated size was larger than request size when OptimizeCpuTiming is enabled + if (osInterface->bOptimizeCpuTiming && + !Mos_ResourceIsNull(&surface->OsResource) && + (Format_Buffer == format) && + (surface->dwWidth * surface->dwHeight >= dwWidth * dwHeight)) { goto finish; }