From 8c6c6e4948578884c1b0f437081bc0f00a5facab Mon Sep 17 00:00:00 2001 From: pengxin99 Date: Mon, 27 Nov 2023 21:47:35 +0800 Subject: [PATCH] [Decode] Fix memory issues for stage code --- .../hal/codechal_kernel_olp_mdf_xe_xpm.cpp | 26 +++++++------------ .../media_interfaces_dg2.cpp | 8 ++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/media_driver/agnostic/Xe_M/Xe_XPM/codec/hal/codechal_kernel_olp_mdf_xe_xpm.cpp b/media_driver/agnostic/Xe_M/Xe_XPM/codec/hal/codechal_kernel_olp_mdf_xe_xpm.cpp index dd8a8cee162..a7620d8fb5c 100644 --- a/media_driver/agnostic/Xe_M/Xe_XPM/codec/hal/codechal_kernel_olp_mdf_xe_xpm.cpp +++ b/media_driver/agnostic/Xe_M/Xe_XPM/codec/hal/codechal_kernel_olp_mdf_xe_xpm.cpp @@ -161,16 +161,16 @@ MOS_STATUS CodechalKernelOlpMdf::Execute(PMOS_SURFACE src, uint16_t *srcMemory_o CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmDevice->CreateThreadGroupSpace(1, 1, threadWidth, threadHeight, m_threadGroupSpaces[0])); CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmKernels[0]->AssociateThreadGroupSpace(m_threadGroupSpaces[0])); CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmTask->AddKernel(m_cmKernels[0])); + + auto delete_event = [&]() + { + MOS_Delete(event); + }; + if (!m_SingleTaskPhase) { - auto sts = m_cmQueue->EnqueueWithGroup(m_cmTask, event); - MOS_STATUS stmtStatus = (MOS_STATUS)(sts); - if (stmtStatus != MOS_STATUS_SUCCESS) - { - event = CM_NO_EVENT; - return stmtStatus; - } - CODECHAL_ENCODE_CHK_STATUS_RETURN(m_cmTask->Reset()); + CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_cmQueue->EnqueueWithGroup(m_cmTask, event), delete_event); + CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_cmTask->Reset(), delete_event); } threadWidth = MOS_ALIGN_CEIL(src->dwWidth, 16) / 16; @@ -180,14 +180,8 @@ MOS_STATUS CodechalKernelOlpMdf::Execute(PMOS_SURFACE src, uint16_t *srcMemory_o CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmDevice->CreateThreadGroupSpace(1, 1, threadWidth, threadHeight, m_threadGroupSpaces[1])); CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmKernels[1]->AssociateThreadGroupSpace(m_threadGroupSpaces[1])); CODECHAL_DECODE_CHK_STATUS_RETURN(m_cmTask->AddKernel(m_cmKernels[1])); - auto sts = m_cmQueue->EnqueueWithGroup(m_cmTask, event); - MOS_STATUS stmtStatus = (MOS_STATUS)(sts); - if (stmtStatus != MOS_STATUS_SUCCESS) - { - event = CM_NO_EVENT; - return stmtStatus; - } - CODECHAL_ENCODE_CHK_STATUS_RETURN(m_cmTask->Reset()); + CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_cmQueue->EnqueueWithGroup(m_cmTask, event), delete_event); + CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_cmTask->Reset(), delete_event); return MOS_STATUS_SUCCESS; } diff --git a/media_driver/media_interface/media_interfaces_dg2/media_interfaces_dg2.cpp b/media_driver/media_interface/media_interfaces_dg2/media_interfaces_dg2.cpp index b4d8fef8d43..c007f3cb701 100644 --- a/media_driver/media_interface/media_interfaces_dg2/media_interfaces_dg2.cpp +++ b/media_driver/media_interface/media_interfaces_dg2/media_interfaces_dg2.cpp @@ -853,6 +853,8 @@ MOS_STATUS CodechalInterfacesNextXe_Hpm::Initialize( if (CodecHalIsDecode(CodecFunction)) { + MOS_Delete(hwInterface); + mhwInterfaces->SetDestroyState(true); CODECHAL_PUBLIC_ASSERTMESSAGE("Decode allocation failed, Decoder with CodechalDeviceNext is not supported!"); return MOS_STATUS_INVALID_PARAMETER; @@ -873,12 +875,16 @@ MOS_STATUS CodechalInterfacesNextXe_Hpm::Initialize( } else { + MOS_Delete(hwInterface); + mhwInterfaces->SetDestroyState(true); return MOS_STATUS_INVALID_PARAMETER; } } else #endif { + MOS_Delete(hwInterface); + mhwInterfaces->SetDestroyState(true); CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported encode function requested."); return MOS_STATUS_INVALID_PARAMETER; } @@ -886,6 +892,8 @@ MOS_STATUS CodechalInterfacesNextXe_Hpm::Initialize( } else { + MOS_Delete(hwInterface); + mhwInterfaces->SetDestroyState(true); CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested."); return MOS_STATUS_INVALID_PARAMETER; }