From 1290bbad36f3c16a34a17ec623a73d9eaed77894 Mon Sep 17 00:00:00 2001 From: Bossonor Date: Sat, 12 Oct 2024 11:44:43 +0800 Subject: [PATCH] [Encode] Adaptive TU Enable * [Encode] adaptive TU for AVC/HEVC/AV1 adaptive tu --- .../codec/shared/codec_def_encode_av1.h | 2 +- .../codec/shared/codec_def_encode_avc.h | 2 + .../codec/shared/codec_def_encode_hevc.h | 2 + .../hal/enc/av1/features/encode_av1_brc.cpp | 10 ++++ .../packet/encode_av1_brc_update_packet.cpp | 40 +++++++++++--- .../av1/packet/encode_av1_brc_update_packet.h | 6 ++- .../hal/enc/avc/features/encode_avc_brc.cpp | 10 ++++ .../encode_avc_huc_brc_update_packet.cpp | 29 ++++++++-- .../packet/encode_avc_huc_brc_update_packet.h | 6 ++- .../hal/enc/hevc/features/encode_hevc_brc.cpp | 11 ++++ .../hevc/packet/encode_hevc_vdenc_packet.cpp | 8 ++- .../packet/encode_huc_brc_update_packet.cpp | 54 ++++++++++++++++--- .../packet/encode_huc_brc_update_packet.h | 7 ++- .../shared/pipeline/encode_user_setting.cpp | 6 +++ 14 files changed, 169 insertions(+), 24 deletions(-) diff --git a/media_common/agnostic/common/codec/shared/codec_def_encode_av1.h b/media_common/agnostic/common/codec/shared/codec_def_encode_av1.h index b93f82548f3..61b99f88489 100644 --- a/media_common/agnostic/common/codec/shared/codec_def_encode_av1.h +++ b/media_common/agnostic/common/codec/shared/codec_def_encode_av1.h @@ -366,7 +366,7 @@ typedef struct _CODEC_AV1_ENCODE_PICTURE_PARAMS uint8_t ref_frame_idx[7]; // [0..6] uint8_t HierarchLevelPlus1; uint8_t primary_ref_frame; // [0..7] - uint8_t Reserved8b3; + uint8_t AdaptiveTUEnabled; uint8_t Reserved8b4; uint8_t order_hint; diff --git a/media_common/agnostic/common/codec/shared/codec_def_encode_avc.h b/media_common/agnostic/common/codec/shared/codec_def_encode_avc.h index 69db7eba9b0..fc6b48e0a0f 100644 --- a/media_common/agnostic/common/codec/shared/codec_def_encode_avc.h +++ b/media_common/agnostic/common/codec/shared/codec_def_encode_avc.h @@ -1050,6 +1050,8 @@ typedef struct _CODEC_AVC_ENCODE_PIC_PARAMS */ uint8_t QpModulationStrength; + uint8_t AdaptiveTUEnabled; + /*! \brief StatusReportEnable * * Request features to be enabled at status report. diff --git a/media_common/agnostic/common/codec/shared/codec_def_encode_hevc.h b/media_common/agnostic/common/codec/shared/codec_def_encode_hevc.h index 8cae546ef17..ee2dc64460d 100644 --- a/media_common/agnostic/common/codec/shared/codec_def_encode_hevc.h +++ b/media_common/agnostic/common/codec/shared/codec_def_encode_hevc.h @@ -978,6 +978,8 @@ typedef struct _CODEC_HEVC_ENCODE_PICTURE_PARAMS } fields; uint8_t value; } QualityInfoSupportFlags; + + uint8_t AdaptiveTUEnabled; } CODEC_HEVC_ENCODE_PICTURE_PARAMS, *PCODEC_HEVC_ENCODE_PICTURE_PARAMS; /*! \brief Slice-level parameters of a compressed picture for HEVC encoding. diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/features/encode_av1_brc.cpp b/media_softlet/agnostic/common/codec/hal/enc/av1/features/encode_av1_brc.cpp index 5b9caf55b05..5f31f0346fe 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/features/encode_av1_brc.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/features/encode_av1_brc.cpp @@ -85,6 +85,15 @@ namespace encode "Encode RateControl Method", m_rcMode, MediaUserSetting::Group::Sequence); + + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_av1PicParams); + MediaUserSetting::Value outValue; + ReadUserSetting( + m_userSettingPtr, + outValue, + "Adaptive TU Enable", + MediaUserSetting::Group::Sequence); + m_basicFeature->m_av1PicParams->AdaptiveTUEnabled |= outValue.Get(); #endif return MOS_STATUS_SUCCESS; } @@ -211,6 +220,7 @@ namespace encode dmem->UPD_CurHeight = (uint16_t)m_basicFeature->m_oriFrameHeight; dmem->UPD_Asyn = 0; dmem->UPD_EnableAdaptiveRounding = (m_basicFeature->m_roundingMethod == RoundingMethod::adaptiveRounding); + dmem->UPD_AdaptiveTUEnabled = picParams->AdaptiveTUEnabled; if (seqParams->GopRefDist == 16 && m_rcMode == RATECONTROL_CQL) dmem->UPD_MaxBRCLevel = 4; 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 bdcf4aba362..bb837e20e89 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 @@ -115,11 +115,19 @@ namespace encode { // VDEnc read batch buffer (input for HuC FW) allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_hwInterface->m_vdencReadBatchBufferSize, CODECHAL_PAGE_SIZE); - allocParamsForBufferLinear.pBufName = "VDENC Read Batch Buffer"; + allocParamsForBufferLinear.pBufName = "VDENC Read Origin Batch Buffer"; allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_WRITE; allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); ENCODE_CHK_NULL_RETURN(allocatedbuffer); - m_vdencReadBatchBuffer[k][i] = *allocatedbuffer; + m_vdencReadBatchBufferOrigin[k][i] = *allocatedbuffer; + + // VDEnc read batch buffer (input for HuC FW) + allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_hwInterface->m_vdencReadBatchBufferSize, CODECHAL_PAGE_SIZE); + allocParamsForBufferLinear.pBufName = "VDENC Read TU7 Batch Buffer"; + allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_WRITE; + allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); + ENCODE_CHK_NULL_RETURN(allocatedbuffer); + m_vdencReadBatchBufferTU7[k][i] = *allocatedbuffer; // BRC update DMEM allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_vdencBrcUpdateDmemBufferSize, CODECHAL_CACHELINE_SIZE); @@ -156,8 +164,19 @@ namespace encode ENCODE_CHK_NULL_RETURN(m_basicFeature); ENCODE_CHK_NULL_RETURN(m_basicFeature->m_recycleBuf); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_av1PicParams); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_av1SeqParams); + + ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBufferOrigin[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); + + if (m_basicFeature->m_av1PicParams->AdaptiveTUEnabled != 0) + { + auto original_TU = m_basicFeature->m_targetUsage; + m_basicFeature->m_targetUsage = m_basicFeature->m_av1SeqParams->TargetUsage = 7; + ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBufferTU7[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); + m_basicFeature->m_targetUsage = m_basicFeature->m_av1SeqParams->TargetUsage = original_TU; + } - ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBuffer[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); ENCODE_CHK_STATUS_RETURN(ConstructPakInsertHucBRC(&m_vdencPakInsertBatchBuffer[m_pipeline->m_currRecycledBufIdx])); bool firstTaskInPhase = packetPhase & firstPacket; @@ -502,11 +521,15 @@ namespace encode ENCODE_CHK_STATUS_RETURN(DumpRegion(0, "_BrcHistory", true, hucRegionDumpUpdate, 6080)); ENCODE_CHK_STATUS_RETURN(DumpRegion(1, "_VdencStats", true, hucRegionDumpUpdate, 48*4)); - ENCODE_CHK_STATUS_RETURN(DumpRegion(3, "_InputSLBB", true, hucRegionDumpUpdate, 600*4)); + ENCODE_CHK_STATUS_RETURN(DumpRegion(3, "_InputSLBB_Origin", true, hucRegionDumpUpdate, 600*4)); ENCODE_CHK_STATUS_RETURN(DumpRegion(5, "_ConstData", true, hucRegionDumpUpdate, MOS_ALIGN_CEIL(m_vdencBrcConstDataBufferSize, CODECHAL_PAGE_SIZE))); ENCODE_CHK_STATUS_RETURN(DumpRegion(7, "_PakMmio", true, hucRegionDumpUpdate, 16*4)); ENCODE_CHK_STATUS_RETURN(DumpRegion(8, "_InputPakInsert", true, hucRegionDumpUpdate, 100)); ENCODE_CHK_STATUS_RETURN(DumpRegion(10, "_InputCdfTable", true, hucRegionDumpUpdate, 4 * MOS_ALIGN_CEIL(m_basicFeature->m_cdfMaxNumBytes, CODECHAL_CACHELINE_SIZE))); + if (m_basicFeature->m_av1PicParams->AdaptiveTUEnabled != 0) + { + ENCODE_CHK_STATUS_RETURN(DumpRegion(12, "_InputSLBB_TU7", true, hucRegionDumpUpdate, 600 * 4)); + } return MOS_STATUS_SUCCESS; } @@ -598,8 +621,8 @@ namespace encode // Region 1 - VDenc Stats Buffer (Input) params.regionParams[1].presRegion = resTileBasedStatisticsBuffer; params.regionParams[1].dwOffset = offset; - // Region 3 - Input SLB Buffer (Input) - params.regionParams[3].presRegion = const_cast(&m_vdencReadBatchBuffer[bufIdx][currentPass]); + // Region 3 - Input SLB Buffer (Input Origin) + params.regionParams[3].presRegion = const_cast(&m_vdencReadBatchBufferOrigin[bufIdx][currentPass]); // Region 4 - BRC Data for next frame's width/height - (Output) params.regionParams[4].presRegion = resBrcDataBuffer; params.regionParams[4].isWritable = true; @@ -620,6 +643,11 @@ namespace encode // Region 11 - CDF (output) params.regionParams[11].presRegion = m_basicFeature->m_defaultCdfBufferInUse; params.regionParams[11].isWritable = true; + // Region 12 - Input SLB Buffer (Input TU7) + if (m_basicFeature->m_av1PicParams->AdaptiveTUEnabled != 0) + { + params.regionParams[12].presRegion = const_cast(&m_vdencReadBatchBufferTU7[bufIdx][currentPass]); + } return MOS_STATUS_SUCCESS; } diff --git a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.h b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.h index cb3e596f256..fb7a61cb185 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.h +++ b/media_softlet/agnostic/common/codec/hal/enc/av1/packet/encode_av1_brc_update_packet.h @@ -143,8 +143,9 @@ namespace encode uint8_t UPD_CQMEnabled; uint8_t UPD_TempCurrentlayer; uint8_t UPD_TempScalable; + uint8_t UPD_AdaptiveTUEnabled; - uint8_t RSVD8[62]; + uint8_t RSVD8[61]; }; typedef struct _HUC_MODE_COST @@ -235,7 +236,8 @@ namespace encode static constexpr uint32_t m_vdboxHucAv1BrcUpdateKernelDescriptor = 19;//!< Huc AV1 Brc init kernel descriptor // Batch Buffer for VDEnc - MOS_RESOURCE m_vdencReadBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer + MOS_RESOURCE m_vdencReadBatchBufferOrigin[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer + MOS_RESOURCE m_vdencReadBatchBufferTU7[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer MOS_RESOURCE m_vdencPakInsertBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< VDEnc read batch buffer MOS_RESOURCE m_vdencBrcConstDataBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< VDEnc brc constant data buffer diff --git a/media_softlet/agnostic/common/codec/hal/enc/avc/features/encode_avc_brc.cpp b/media_softlet/agnostic/common/codec/hal/enc/avc/features/encode_avc_brc.cpp index 20df54bad42..1a48e5ddff0 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/avc/features/encode_avc_brc.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/avc/features/encode_avc_brc.cpp @@ -190,6 +190,14 @@ MOS_STATUS AvcEncodeBRC::Update(void *params) "Encode RateControl Method", m_rcMode, MediaUserSetting::Group::Sequence); + + MediaUserSetting::Value outValue; + ReadUserSetting( + m_userSettingPtr, + outValue, + "Adaptive TU Enable", + MediaUserSetting::Group::Sequence); + m_basicFeature->m_picParam->AdaptiveTUEnabled |= outValue.Get(); #endif return MOS_STATUS_SUCCESS; } @@ -640,6 +648,8 @@ MOS_STATUS AvcEncodeBRC::SetDmemForUpdate(void *params, uint16_t currPass, bool hucVdencBrcUpdateDmem->UPD_PAKPassNum_U8 = (uint8_t)currPass; hucVdencBrcUpdateDmem->UPD_MaxNumPass_U8 = m_featureManager->GetNumPass(); + hucVdencBrcUpdateDmem->UPD_AdaptiveTUEnabled = avcPicParams->AdaptiveTUEnabled; + uint32_t numP = 0; if (avcSeqParams->GopRefDist && (avcSeqParams->GopPicSize > 0)) { diff --git a/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.cpp b/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.cpp index c19ef41c8c5..ff9ab82ffab 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.cpp @@ -141,7 +141,15 @@ MOS_STATUS AvcHucBrcUpdatePkt::AllocateResources() allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_CACHE; allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); ENCODE_CHK_NULL_RETURN(allocatedbuffer); - m_vdencBrcImageStatesReadBuffer[k] = allocatedbuffer; + m_vdencBrcImageStatesReadBufferOrigin[k] = allocatedbuffer; + + // VDENC IMG STATE read buffer + allocParamsForBufferLinear.dwBytes = m_brcFeature->GetVdencBRCImgStateBufferSize(); + allocParamsForBufferLinear.pBufName = "VDENC BRC IMG State Read Buffer"; + allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_CACHE; + allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); + ENCODE_CHK_NULL_RETURN(allocatedbuffer); + m_vdencBrcImageStatesReadBufferTU7[k] = allocatedbuffer; for (auto i = 0; i < VDENC_BRC_NUM_OF_PASSES; i++) { @@ -334,8 +342,18 @@ MOS_STATUS AvcHucBrcUpdatePkt::Execute(PMOS_COMMAND_BUFFER cmdBuffer, bool store MOS_STATUS AvcHucBrcUpdatePkt::Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase) { ENCODE_FUNC_CALL(); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_picParam); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_seqParam); + + ENCODE_CHK_STATUS_RETURN(ConstructImageStateReadBuffer(m_vdencBrcImageStatesReadBufferOrigin[m_pipeline->m_currRecycledBufIdx])); - ENCODE_CHK_STATUS_RETURN(ConstructImageStateReadBuffer(m_vdencBrcImageStatesReadBuffer[m_pipeline->m_currRecycledBufIdx])); + if (m_basicFeature->m_picParam->AdaptiveTUEnabled != 0) + { + auto original_TU = m_basicFeature->m_targetUsage; + m_basicFeature->m_targetUsage = m_basicFeature->m_seqParam->TargetUsage = 7; + ENCODE_CHK_STATUS_RETURN(ConstructImageStateReadBuffer(m_vdencBrcImageStatesReadBufferTU7[m_pipeline->m_currRecycledBufIdx])); + m_basicFeature->m_targetUsage = m_basicFeature->m_seqParam->TargetUsage = original_TU; + } bool firstTaskInPhase = packetPhase & firstPacket; bool requestProlog = false; @@ -525,7 +543,7 @@ MHW_SETPAR_DECL_SRC(HUC_VIRTUAL_ADDR_STATE, AvcHucBrcUpdatePkt) // Input regions params.regionParams[1].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(VdencStatsBuffer, 0); params.regionParams[2].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(BrcPakStatisticBuffer, 0); - params.regionParams[3].presRegion = m_vdencBrcImageStatesReadBuffer[m_pipeline->m_currRecycledBufIdx]; + params.regionParams[3].presRegion = m_vdencBrcImageStatesReadBufferOrigin[m_pipeline->m_currRecycledBufIdx]; params.regionParams[5].presRegion = m_vdencBrcConstDataBuffer[GetCurrConstDataBufIdx()]; params.regionParams[7].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(PakSliceSizeStreamOutBuffer, m_pipeline->GetCurrentPass() ? m_basicFeature->m_frameNum : m_basicFeature->m_frameNum ? m_basicFeature->m_frameNum-1 : 0); // use stats from previous frame for pass 0 @@ -542,6 +560,11 @@ MHW_SETPAR_DECL_SRC(HUC_VIRTUAL_ADDR_STATE, AvcHucBrcUpdatePkt) params.regionParams[8].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(RecycleResId::HucRoiMapBuffer, m_basicFeature->m_frameNum); } + if (m_basicFeature->m_picParam->AdaptiveTUEnabled != 0) + { + params.regionParams[12].presRegion = m_vdencBrcImageStatesReadBufferTU7[m_pipeline->m_currRecycledBufIdx]; + } + return MOS_STATUS_SUCCESS; } diff --git a/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.h b/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.h index baa5fec41a0..7797ce4c46a 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.h +++ b/media_softlet/agnostic/common/codec/hal/enc/avc/packet/encode_avc_huc_brc_update_packet.h @@ -123,7 +123,8 @@ struct VdencAvcHucBrcUpdateDmem uint16_t UPD_NumSlicesForRounding; uint32_t UPD_UserMaxFramePB; // In Bytes uint8_t UPD_ExtCurrFrameType; // correctly calculated FrameType for all cases (including hierarchy golden BGops) - uint8_t RSVD2[3]; + uint8_t UPD_AdaptiveTUEnabled; + uint8_t RSVD2[2]; }; struct VdencAvcHucBrcConstantData @@ -248,7 +249,8 @@ class AvcHucBrcUpdatePkt : public EncodeHucPkt uint32_t m_vdencBrcUpdateDmemBufferSize = sizeof(VdencAvcHucBrcUpdateDmem); //!< Offset of BRC update DMEM buffer uint32_t m_vdencBrcConstDataBufferSize = sizeof(VdencAvcHucBrcConstantData); //!< Offset of BRC const data buffer - PMOS_RESOURCE m_vdencBrcImageStatesReadBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Read-only VDENC+PAK IMG STATE buffer. + PMOS_RESOURCE m_vdencBrcImageStatesReadBufferOrigin[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Read-only VDENC+PAK IMG STATE buffer. + PMOS_RESOURCE m_vdencBrcImageStatesReadBufferTU7[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< Read-only VDENC+PAK IMG STATE buffer. PMOS_RESOURCE m_vdencBrcUpdateDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< Brc Update DMEM Buffer Array. PMOS_RESOURCE m_vdencBrcConstDataBuffer[CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM] = {}; //!< BRC Const Data Buffer for each frame type. diff --git a/media_softlet/agnostic/common/codec/hal/enc/hevc/features/encode_hevc_brc.cpp b/media_softlet/agnostic/common/codec/hal/enc/hevc/features/encode_hevc_brc.cpp index 6b49b5a4f2d..eed1bd90538 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/hevc/features/encode_hevc_brc.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/hevc/features/encode_hevc_brc.cpp @@ -104,6 +104,15 @@ namespace encode "HEVC VDEnc ACQP Enable", m_hevcVDEncAcqpEnabled, MediaUserSetting::Group::Sequence); + + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_hevcPicParams); + MediaUserSetting::Value outValue; + ReadUserSetting( + m_userSettingPtr, + outValue, + "Adaptive TU Enable", + MediaUserSetting::Group::Sequence); + m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled |= outValue.Get(); #endif return MOS_STATUS_SUCCESS; } @@ -286,6 +295,8 @@ namespace encode hucVdencBrcUpdateDmem->UPD_Randomaccess = m_basicFeature->m_hevcSeqParams->LowDelayMode == 1 ? 0 : 1; + hucVdencBrcUpdateDmem->UPD_AdaptiveTUEnabled = m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled; + return MOS_STATUS_SUCCESS; } diff --git a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_hevc_vdenc_packet.cpp b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_hevc_vdenc_packet.cpp index 02e6380653d..957f4d168d3 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_hevc_vdenc_packet.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_hevc_vdenc_packet.cpp @@ -1397,6 +1397,10 @@ namespace encode secondLevelBatchBufferUsed->dwOffset, false, m_basicFeature->m_vdencBatchBufferPerSlicePart2Size[currSlcIdx]); + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled == 0) + { + SETPAR_AND_ADDCMD(VDENC_HEVC_VP9_TILE_SLICE_STATE, m_vdencItf, &cmdBuffer); + } } else { @@ -1412,8 +1416,10 @@ namespace encode ENCODE_CHK_STATUS_RETURN(AddAllCmds_HCP_PAK_INSERT_OBJECT(&cmdBuffer)); SETPAR_AND_ADDCMD(VDENC_WEIGHTSOFFSETS_STATE, m_vdencItf, &cmdBuffer); + + SETPAR_AND_ADDCMD(VDENC_HEVC_VP9_TILE_SLICE_STATE, m_vdencItf, &cmdBuffer); } - SETPAR_AND_ADDCMD(VDENC_HEVC_VP9_TILE_SLICE_STATE, m_vdencItf, &cmdBuffer); + SETPAR_AND_ADDCMD(VDENC_WALKER_STATE, m_vdencItf, &cmdBuffer); return eStatus; } diff --git a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.cpp b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.cpp index b29f3a886f6..e7b6e623ec3 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.cpp @@ -147,11 +147,19 @@ namespace encode { // VDEnc read batch buffer (input for HuC FW) allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_hwInterface->m_vdencReadBatchBufferSize, CODECHAL_PAGE_SIZE); - allocParamsForBufferLinear.pBufName = "VDENC Read Batch Buffer"; + allocParamsForBufferLinear.pBufName = "VDENC Read Batch Buffer Origin"; allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_CACHE; allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); ENCODE_CHK_NULL_RETURN(allocatedbuffer); - m_vdencReadBatchBuffer[k][i] = *allocatedbuffer; + m_vdencReadBatchBufferOrigin[k][i] = *allocatedbuffer; + + // VDEnc read batch buffer (input for HuC FW) + allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_hwInterface->m_vdencReadBatchBufferSize, CODECHAL_PAGE_SIZE); + allocParamsForBufferLinear.pBufName = "VDENC Read Batch Buffer TU7"; + allocParamsForBufferLinear.ResUsageType = MOS_HW_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_CACHE; + allocatedbuffer = m_allocator->AllocateResource(allocParamsForBufferLinear, true); + ENCODE_CHK_NULL_RETURN(allocatedbuffer); + m_vdencReadBatchBufferTU7[k][i] = *allocatedbuffer; // BRC update DMEM allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(m_vdencBrcUpdateDmemBufferSize, CODECHAL_CACHELINE_SIZE); @@ -219,7 +227,7 @@ namespace encode SetCurrRecycledBufIdx, m_pipeline->m_currRecycledBufIdx); params.regionParams[2].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(FrameStatStreamOutBuffer, 0); // Region 2 PAK Statistics Buffer (Input) - MFX_PAK_FRAME_STATISTICS - params.regionParams[3].presRegion = const_cast(&m_vdencReadBatchBuffer[m_pipeline->m_currRecycledBufIdx][currentPass]); // Region 3 - Input SLB Buffer (Input) + params.regionParams[3].presRegion = const_cast(&m_vdencReadBatchBufferOrigin[m_pipeline->m_currRecycledBufIdx][currentPass]); // Region 3 - Input SLB Buffer (Input Origin) params.regionParams[4].presRegion = const_cast(&m_vdencBrcConstDataBuffer[m_pipeline->m_currRecycledBufIdx]); // Region 4 - Constant Data (Input) params.regionParams[6].presRegion = const_cast(&m_dataFromPicsBuffer); // Region 6 - Data Buffer of Current and Reference Pictures for Weighted Prediction (Input/Output) params.regionParams[6].isWritable = true; @@ -258,6 +266,11 @@ namespace encode params.regionParams[1].presRegion = m_basicFeature->m_recycleBuf->GetBuffer(VdencStatsBuffer, 0); // Region 1 VDEnc Statistics Buffer (Input) - VDENC_HEVC_VP9_FRAME_BASED_STATISTICS_STREAMOUT } + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled != 0) + { + params.regionParams[12].presRegion = const_cast(&m_vdencReadBatchBufferTU7[m_pipeline->m_currRecycledBufIdx][currentPass]); // Region 12 - Input SLB Buffer (Input TU7) + } + return MOS_STATUS_SUCCESS; } @@ -601,7 +614,7 @@ namespace encode currentLocation += m_hcpSliceStateCmdSize; // VDENC_WEIGHT_OFFSETS_STATE cmd - hucConstData->Slice[slcCount].VdencWeightOffset_StartInBytes // VdencWeightOffset cmd is the last one expect BatchBufferEnd cmd + hucConstData->Slice[slcCount].VdencWeightOffset_StartInBytes // VdencWeightOffset cmd is the last one expect BatchBufferEnd cmd when adaptive tu disabled = (uint16_t)(baseLocation + hucConstData->Slice[slcCount].SizeOfCMDs - m_vdencWeightOffsetStateCmdSize - m_miBatchBufferEndCmdSize - m_alignSize[slcCount]); currentLocation += m_miBatchBufferEndCmdSize; @@ -653,9 +666,26 @@ namespace encode ENCODE_CHK_NULL_RETURN(m_basicFeature); ENCODE_CHK_NULL_RETURN(m_basicFeature->m_recycleBuf); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_hevcPicParams); + ENCODE_CHK_NULL_RETURN(m_basicFeature->m_hevcSeqParams); ENCODE_CHK_STATUS_RETURN(SetTcbrcMode()); - ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBuffer[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); + + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled != 0 && m_bufConstSizeFlagForAdaptiveTU == false) + { + m_bufConstSizeFlagForAdaptiveTU = true; + m_hwInterface->m_vdencBatchBufferPerSliceConstSize += m_vdencItf->MHW_GETSIZE_F(VDENC_HEVC_VP9_TILE_SLICE_STATE)(); + } + + ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBufferOrigin[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); + + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled != 0) + { + auto original_TU = m_basicFeature->m_targetUsage; + m_basicFeature->m_targetUsage = m_basicFeature->m_hevcSeqParams->TargetUsage = 7; + ENCODE_CHK_STATUS_RETURN(ConstructBatchBufferHuCBRC(&m_vdencReadBatchBufferTU7[m_pipeline->m_currRecycledBufIdx][m_pipeline->GetCurrentPass()])); + m_basicFeature->m_targetUsage = m_basicFeature->m_hevcSeqParams->TargetUsage = original_TU; + } bool firstTaskInPhase = packetPhase & firstPacket; bool requestProlog = false; @@ -901,6 +931,10 @@ namespace encode cmdBufOffset = constructedCmdBuf.iOffset; SETPAR_AND_ADDCMD(VDENC_WEIGHTSOFFSETS_STATE, m_vdencItf, &constructedCmdBuf); + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled != 0) + { + SETPAR_AND_ADDCMD(VDENC_HEVC_VP9_TILE_SLICE_STATE, m_vdencItf, &constructedCmdBuf); + } m_vdencWeightOffsetStateCmdSize = constructedCmdBuf.iOffset - cmdBufOffset; // set MI_BATCH_BUFFER_END command @@ -1005,8 +1039,8 @@ namespace encode size = MOS_ALIGN_CEIL(HevcBasicFeature::m_sizeOfHcpPakFrameStats * hevcBasicFeature->m_maxTileNumber, CODECHAL_PAGE_SIZE); ENCODE_CHK_STATUS_RETURN(DumpRegion(2, "_PakStats", true, hucRegionDumpUpdate, size)); - // Region 3 - Input SLB Buffer - ENCODE_CHK_STATUS_RETURN(DumpRegion(3, "_Slb", true, hucRegionDumpUpdate, m_hwInterface->m_vdencReadBatchBufferSize)); + // Region 3 - Input Origin SLB Buffer + ENCODE_CHK_STATUS_RETURN(DumpRegion(3, "_Slb_Origin", true, hucRegionDumpUpdate, m_hwInterface->m_vdencReadBatchBufferSize)); // Region 4 - Constant Data Buffer dump ENCODE_CHK_STATUS_RETURN(DumpRegion(4, "_ConstData", true, hucRegionDumpUpdate, m_vdencBrcConstDataBufferSize)); @@ -1027,6 +1061,12 @@ namespace encode { ENCODE_CHK_STATUS_RETURN(DumpRegion(10, "_DeltaQp", true, hucRegionDumpUpdate, vdencDeltaQpBuffer->iSize)); } + + // Region 12 - Input TU7 SLB Buffer + if (m_basicFeature->m_hevcPicParams->AdaptiveTUEnabled != 0) + { + ENCODE_CHK_STATUS_RETURN(DumpRegion(12, "_Slb_TU7", true, hucRegionDumpUpdate, m_hwInterface->m_vdencReadBatchBufferSize)); + } } else { diff --git a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.h b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.h index ee4f0954d13..2d74786fe88 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.h +++ b/media_softlet/agnostic/common/codec/hal/enc/hevc/packet/encode_huc_brc_update_packet.h @@ -124,8 +124,9 @@ namespace encode uint32_t UPD_UserMaxFrame = 0; uint32_t UPD_UserMaxFramePB = 0; uint8_t UPD_Randomaccess = 0; + uint8_t UPD_AdaptiveTUEnabled = 0; - uint8_t RSVD[43] = {}; // 64 bytes aligned + uint8_t RSVD[42] = {}; // 64 bytes aligned }; C_ASSERT(256 == sizeof(VdencHevcHucBrcUpdateDmem)); @@ -257,7 +258,8 @@ namespace encode static constexpr uint32_t m_vdboxHucHevcBrcLowdelayKernelDescriptor = 10;//!< Huc HEVC Brc low delay kernel descriptor // Batch Buffer for VDEnc - MOS_RESOURCE m_vdencReadBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer + MOS_RESOURCE m_vdencReadBatchBufferOrigin[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer + MOS_RESOURCE m_vdencReadBatchBufferTU7[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][VDENC_BRC_NUM_OF_PASSES] = {}; //!< VDEnc read batch buffer MOS_RESOURCE m_vdencBrcConstDataBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< VDEnc brc constant data buffer MOS_RESOURCE m_dataFromPicsBuffer = {}; //!< Data Buffer of Current and Reference Pictures for Weighted Prediction @@ -275,6 +277,7 @@ namespace encode uint32_t m_vdencBrcConstDataBufferSize = sizeof(VdencHevcHucBrcConstantData); //!< Offset of BRC const data buffer uint32_t m_slbDataSizeInBytes = 0; //!< Size of SLB Data uint8_t m_tcbrcQualityBoost = 0; + bool m_bufConstSizeFlagForAdaptiveTU = false; //!< VdencBatchBufferPerSliceConstSize flag for adaptiveTU MOS_RESOURCE m_vdencBrcInitDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; //!< VDEnc BrcInit DMEM buffer diff --git a/media_softlet/agnostic/common/codec/hal/enc/shared/pipeline/encode_user_setting.cpp b/media_softlet/agnostic/common/codec/hal/enc/shared/pipeline/encode_user_setting.cpp index 7206a131f9a..744dc62a5f9 100644 --- a/media_softlet/agnostic/common/codec/hal/enc/shared/pipeline/encode_user_setting.cpp +++ b/media_softlet/agnostic/common/codec/hal/enc/shared/pipeline/encode_user_setting.cpp @@ -217,6 +217,12 @@ MOS_STATUS EncodePipeline::InitUserSetting(MediaUserSettingSharedPtr userSetting MediaUserSetting::Group::Sequence, int32_t(0), true); + DeclareUserSettingKeyForDebug( + userSettingPtr, + "Adaptive TU Enable", + MediaUserSetting::Group::Sequence, + int32_t(0), + false); #endif #if _MEDIA_RESERVED