From 4b204708556406c45266e5a8f6dafc69a4a90165 Mon Sep 17 00:00:00 2001 From: WangLuyue Date: Wed, 11 Oct 2023 19:45:56 +0800 Subject: [PATCH] [Encode] correct nalnum in AddAllCmds_AVP_PIPE_refineE_SELECT correct nalnum in AddAllCmds_AVP_PIPE_refineE_SELECT to distinguish nalnum = 0 with nalnum = 1 and refactor to delete duplicated codes --- .../encode_av1_vdenc_packet_xe_m_base.cpp | 92 ------------------ .../encode_av1_vdenc_packet_xe_m_base.h | 2 - ...code_av1_vdenc_packet_xe_lpm_plus_base.cpp | 92 ------------------ ...encode_av1_vdenc_packet_xe_lpm_plus_base.h | 2 - .../packet/encode_av1_brc_update_packet.cpp | 6 +- .../av1/packet/encode_av1_vdenc_packet.cpp | 94 +++++++++++++++++++ .../enc/av1/packet/encode_av1_vdenc_packet.h | 2 + 7 files changed, 99 insertions(+), 191 deletions(-) diff --git a/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.cpp b/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.cpp index e4eca4e898e..dc4455aa30e 100644 --- a/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.cpp +++ b/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.cpp @@ -765,98 +765,6 @@ namespace encode return MOS_STATUS_SUCCESS; } - MOS_STATUS Av1VdencPktXe_M_Base::AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const - { - ENCODE_FUNC_CALL(); - - ENCODE_CHK_NULL_RETURN(m_osInterface); - auto& params = m_avpItf->MHW_GETPAR_F(AVP_PAK_INSERT_OBJECT)(); - params = {}; - - auto GetExtraData = [&]() { return params.bsBuffer->pBase + params.offset; }; - auto GetExtraSize = [&]() { return (params.bitSize + 7) >> 3; }; - - // First, Send all other OBU bit streams other than tile group OBU when it's first tile in frame - uint32_t tileIdx = 0; - bool tgOBUValid = m_basicFeature->m_slcData[0].BitSize > 0 ? true : false; - - RUN_FEATURE_INTERFACE_RETURN(Av1EncodeTile, Av1FeatureIDs::encodeTile, GetTileIdx, tileIdx); - auto brcFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::av1BrcFeature)); - ENCODE_CHK_NULL_RETURN(brcFeature); - - if (tileIdx == 0) - { - uint32_t nalNum = 0; - for (uint32_t i = 0; i < MAX_NUM_OBU_TYPES && m_nalUnitParams[i]->uiSize > 0; i++) - { - nalNum = i; - } - - params.bsBuffer = &m_basicFeature->m_bsBuffer; - params.endOfHeaderInsertion = false; - - // Support multiple packed header buffer - for (uint32_t i = 0; i <= nalNum; i++) - { - uint32_t nalUnitSize = m_nalUnitParams[i]->uiSize; - uint32_t nalUnitOffset = m_nalUnitParams[i]->uiOffset; - - ENCODE_ASSERT(nalUnitSize < CODECHAL_ENCODE_AV1_PAK_INSERT_UNCOMPRESSED_HEADER); - - params.bitSize = nalUnitSize * 8; - params.offset = nalUnitOffset; - params.lastHeader = !tgOBUValid && (i == nalNum); - - if (IsFrameHeader(*(m_basicFeature->m_bsBuffer.pBase + nalUnitOffset))) - { - if (brcFeature->IsBRCEnabled()) - { - auto pakInsertOutputBatchBuffer = brcFeature->GetPakInsertOutputBatchBuffer(m_pipeline->m_currRecycledBufIdx); - ENCODE_CHK_NULL_RETURN(pakInsertOutputBatchBuffer); - // send pak insert obj cmds after back annotation - ENCODE_CHK_STATUS_RETURN(m_miItf->MHW_ADDCMD_F(MI_BATCH_BUFFER_START)(cmdBuffer, pakInsertOutputBatchBuffer)); - auto slbbData = brcFeature->GetSLBData(); - HalOcaInterfaceNext::OnSubLevelBBStart( - *cmdBuffer, - m_osInterface->pOsContext, - &pakInsertOutputBatchBuffer->OsResource, - pakInsertOutputBatchBuffer->dwOffset, - false, - slbbData.pakInsertSlbSize); - } - else - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - else - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - } - - // Second, Send tile group OBU when it is first tile in tile group - if (tgOBUValid) - { - ENCODE_CHK_NULL_RETURN(m_featureManager); - - auto tileFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::encodeTile)); - ENCODE_CHK_NULL_RETURN(tileFeature); - - MHW_CHK_STATUS_RETURN(tileFeature->MHW_SETPAR_F(AVP_PAK_INSERT_OBJECT)(params)); - if (params.bitSize) - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - - return MOS_STATUS_SUCCESS; - } - MOS_STATUS Av1VdencPktXe_M_Base::CalculateAvpPictureStateCommandSize(uint32_t * commandsSize, uint32_t * patchListSize) { ENCODE_FUNC_CALL(); diff --git a/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.h b/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.h index dff3a52a1ad..494814c0729 100644 --- a/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.h +++ b/media_driver/media_softlet/agnostic/Xe_M/Xe_M_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_m_base.h @@ -105,8 +105,6 @@ namespace encode MOS_STATUS AddAllCmds_AVP_SEGMENT_STATE(PMOS_COMMAND_BUFFER cmdBuffer) const; - MOS_STATUS AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const; - MOS_STATUS AddAllCmds_AVP_PIPE_MODE_SELECT(PMOS_COMMAND_BUFFER cmdBuffer) const; #if USE_CODECHAL_DEBUG_TOOL diff --git a/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.cpp b/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.cpp index 27fbadcd84e..de8a72a4c62 100644 --- a/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.cpp +++ b/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.cpp @@ -823,98 +823,6 @@ MHW_SETPAR_DECL_SRC(AVP_TILE_CODING, Av1VdencPktXe_Lpm_Plus_Base) return MOS_STATUS_SUCCESS; } -MOS_STATUS Av1VdencPktXe_Lpm_Plus_Base::AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const -{ - ENCODE_FUNC_CALL(); - - ENCODE_CHK_NULL_RETURN(m_osInterface); - auto ¶ms = m_avpItf->MHW_GETPAR_F(AVP_PAK_INSERT_OBJECT)(); - params = {}; - - auto GetExtraData = [&]() { return params.bsBuffer->pBase + params.offset; }; - auto GetExtraSize = [&]() { return (params.bitSize + 7) >> 3; }; - - // First, Send all other OBU bit streams other than tile group OBU when it's first tile in frame - uint32_t tileIdx = 0; - bool tgOBUValid = m_basicFeature->m_slcData[0].BitSize > 0 ? true : false; - - RUN_FEATURE_INTERFACE_RETURN(Av1EncodeTile, Av1FeatureIDs::encodeTile, GetTileIdx, tileIdx); - auto brcFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::av1BrcFeature)); - ENCODE_CHK_NULL_RETURN(brcFeature); - - if (tileIdx == 0) - { - uint32_t nalNum = 0; - for (uint32_t i = 0; i < MAX_NUM_OBU_TYPES && m_nalUnitParams[i]->uiSize > 0; i++) - { - nalNum = i; - } - - params.bsBuffer = &m_basicFeature->m_bsBuffer; - params.endOfHeaderInsertion = false; - - // Support multiple packed header buffer - for (uint32_t i = 0; i <= nalNum; i++) - { - uint32_t nalUnitSize = m_nalUnitParams[i]->uiSize; - uint32_t nalUnitOffset = m_nalUnitParams[i]->uiOffset; - - ENCODE_ASSERT(nalUnitSize < CODECHAL_ENCODE_AV1_PAK_INSERT_UNCOMPRESSED_HEADER); - - params.bitSize = nalUnitSize * 8; - params.offset = nalUnitOffset; - params.lastHeader = !tgOBUValid && (i == nalNum); - - if (IsFrameHeader(*(m_basicFeature->m_bsBuffer.pBase + nalUnitOffset))) - { - if (brcFeature->IsBRCEnabled()) - { - auto pakInsertOutputBatchBuffer = brcFeature->GetPakInsertOutputBatchBuffer(m_pipeline->m_currRecycledBufIdx); - ENCODE_CHK_NULL_RETURN(pakInsertOutputBatchBuffer); - // send pak insert obj cmds after back annotation - ENCODE_CHK_STATUS_RETURN(m_miItf->MHW_ADDCMD_F(MI_BATCH_BUFFER_START)(cmdBuffer, pakInsertOutputBatchBuffer)); - auto slbbData = brcFeature->GetSLBData(); - HalOcaInterfaceNext::OnSubLevelBBStart( - *cmdBuffer, - m_osInterface->pOsContext, - &pakInsertOutputBatchBuffer->OsResource, - pakInsertOutputBatchBuffer->dwOffset, - false, - slbbData.pakInsertSlbSize); - } - else - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - else - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - } - - // Second, Send tile group OBU when it is first tile in tile group - if (tgOBUValid) - { - ENCODE_CHK_NULL_RETURN(m_featureManager); - - auto tileFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::encodeTile)); - ENCODE_CHK_NULL_RETURN(tileFeature); - - MHW_CHK_STATUS_RETURN(tileFeature->MHW_SETPAR_F(AVP_PAK_INSERT_OBJECT)(params)); - if (params.bitSize) - { - m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); - m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); - } - } - - return MOS_STATUS_SUCCESS; -} - MOS_STATUS Av1VdencPktXe_Lpm_Plus_Base::AddAllCmds_AVP_PIPE_MODE_SELECT(PMOS_COMMAND_BUFFER cmdBuffer) const { ENCODE_FUNC_CALL(); diff --git a/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.h b/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.h index 3cbe5e67de5..c7425948d6b 100644 --- a/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.h +++ b/media_softlet/agnostic/Xe_M_plus/Xe_LPM_plus_base/codec/hal/enc/av1/packet/encode_av1_vdenc_packet_xe_lpm_plus_base.h @@ -90,8 +90,6 @@ class Av1VdencPktXe_Lpm_Plus_Base : public Av1VdencPkt MHW_SETPAR_DECL_HDR(AVP_TILE_CODING); - MOS_STATUS AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const; - MOS_STATUS AddAllCmds_AVP_PIPE_MODE_SELECT(PMOS_COMMAND_BUFFER cmdBuffer) const; MOS_STATUS AddAllCmds_AVP_SEGMENT_STATE(PMOS_COMMAND_BUFFER cmdBuffer) const; diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.cpp b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.cpp index e67a55c8f30..da3d6418ba4 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.cpp @@ -409,14 +409,14 @@ namespace encode uint32_t nalNum = 0; for (uint32_t i = 0; i < MAX_NUM_OBU_TYPES && m_basicFeature->m_nalUnitParams[i]->uiSize > 0; i++) { - nalNum = i; + nalNum++; } params.bsBuffer = &m_basicFeature->m_bsBuffer; params.endOfHeaderInsertion = false; // Support multiple packed header buffer - for (uint32_t i = 0; i <= nalNum; i++) + for (uint32_t i = 0; i < nalNum; i++) { uint32_t nalUnitSize = m_basicFeature->m_nalUnitParams[i]->uiSize; uint32_t nalUnitOffset = m_basicFeature->m_nalUnitParams[i]->uiOffset; @@ -427,7 +427,7 @@ namespace encode { params.bitSize = nalUnitSize * 8; params.offset = nalUnitOffset; - params.lastHeader = !tgOBUValid && (i == nalNum); + params.lastHeader = !tgOBUValid && (i+1 == nalNum); m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.cpp b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.cpp index e747ec8dfb8..1fb49f43bf0 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.cpp @@ -28,6 +28,7 @@ #include "encode_status_report_defs.h" #include "codec_def_common_av1.h" #include "media_perf_profiler.h" +#include "hal_oca_interface_next.h" namespace encode{ Av1VdencPkt::Av1VdencPkt(MediaPipeline* pipeline, MediaTask* task, CodechalHwInterfaceNext* hwInterface) : @@ -1060,6 +1061,99 @@ namespace encode{ return MOS_STATUS_SUCCESS; } + MOS_STATUS Av1VdencPkt::AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const + { + ENCODE_FUNC_CALL(); + + ENCODE_CHK_NULL_RETURN(m_osInterface); + ENCODE_CHK_NULL_RETURN(cmdBuffer); + + auto ¶ms = m_avpItf->MHW_GETPAR_F(AVP_PAK_INSERT_OBJECT)(); + params = {}; + + auto GetExtraData = [&]() { return params.bsBuffer->pBase + params.offset; }; + auto GetExtraSize = [&]() { return (params.bitSize + 7) >> 3; }; + + // First, Send all other OBU bit streams other than tile group OBU when it's first tile in frame + uint32_t tileIdx = 0; + const bool tgOBUValid = m_basicFeature->m_slcData[0].BitSize > 0 ? true : false; + + RUN_FEATURE_INTERFACE_RETURN(Av1EncodeTile, Av1FeatureIDs::encodeTile, GetTileIdx, tileIdx); + auto brcFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::av1BrcFeature)); + ENCODE_CHK_NULL_RETURN(brcFeature); + if (tileIdx == 0) + { + uint32_t nalNum = 0; + for (uint8_t i = 0; i < MAX_NUM_OBU_TYPES && m_nalUnitParams[i]->uiSize > 0; i++) + { + nalNum++; + } + + params.bsBuffer = &m_basicFeature->m_bsBuffer; + params.endOfHeaderInsertion = false; + + // Support multiple packed header buffer + for (uint32_t i = 0; i < nalNum; i++) + { + const uint32_t nalUnitSize = m_nalUnitParams[i]->uiSize; + const uint32_t nalUnitOffset = m_nalUnitParams[i]->uiOffset; + + ENCODE_ASSERT(nalUnitSize < CODECHAL_ENCODE_AV1_PAK_INSERT_UNCOMPRESSED_HEADER); + + params.bitSize = nalUnitSize * 8; + params.offset = nalUnitOffset; + params.lastHeader = !tgOBUValid && (i+1 == nalNum); + + if (IsFrameHeader(*(m_basicFeature->m_bsBuffer.pBase + nalUnitOffset))) + { + if (brcFeature->IsBRCEnabled()) + { + auto pakInsertOutputBatchBuffer = brcFeature->GetPakInsertOutputBatchBuffer(m_pipeline->m_currRecycledBufIdx); + ENCODE_CHK_NULL_RETURN(pakInsertOutputBatchBuffer); + // send pak insert obj cmds after back annotation + ENCODE_CHK_STATUS_RETURN(m_miItf->MHW_ADDCMD_F(MI_BATCH_BUFFER_START)(cmdBuffer, pakInsertOutputBatchBuffer)); + auto slbbData = brcFeature->GetSLBData(); + HalOcaInterfaceNext::OnSubLevelBBStart( + *cmdBuffer, + m_osInterface->pOsContext, + &pakInsertOutputBatchBuffer->OsResource, + pakInsertOutputBatchBuffer->dwOffset, + false, + slbbData.pakInsertSlbSize); + + } + else + { + m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); + m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); + } + } + else + { + m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); + m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); + } + } + } + + // Second, Send tile group OBU when it is first tile in tile group + if (tgOBUValid) + { + ENCODE_CHK_NULL_RETURN(m_featureManager); + + auto tileFeature = dynamic_cast(m_featureManager->GetFeature(Av1FeatureIDs::encodeTile)); + ENCODE_CHK_NULL_RETURN(tileFeature); + + MHW_CHK_STATUS_RETURN(tileFeature->MHW_SETPAR_F(AVP_PAK_INSERT_OBJECT)(params)); + if (params.bitSize) + { + m_avpItf->MHW_ADDCMD_F(AVP_PAK_INSERT_OBJECT)(cmdBuffer); + m_osInterface->pfnAddCommand(cmdBuffer, GetExtraData(), GetExtraSize()); + } + } + + return MOS_STATUS_SUCCESS; + } MOS_STATUS Av1VdencPkt::GetVdencStateCommandsDataSize(uint32_t *commandsSize, uint32_t *patchListSize) const { uint32_t maxSize = 0; diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.h b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.h index 6592c67e6ca..d59fbf86186 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.h +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_vdenc_packet.h @@ -316,6 +316,8 @@ class Av1VdencPkt : public CmdPacket, public MediaStatusReportObserver, public m virtual MOS_STATUS AddAllCmds_AVP_SURFACE_STATE(PMOS_COMMAND_BUFFER cmdBuffer) const; + virtual MOS_STATUS AddAllCmds_AVP_PAK_INSERT_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer) const; + virtual MOS_STATUS GetVdencStateCommandsDataSize(uint32_t *commandsSize, uint32_t *patchListSize) const; virtual MOS_STATUS GetVdencPrimitiveCommandsDataSize(uint32_t *commandsSize, uint32_t *patchListSize) const;