Skip to content

Commit

Permalink
[Encode] Align programming with cmodel
Browse files Browse the repository at this point in the history
* [Encode] Align programming with cmodel

Changes to match cmodel
  • Loading branch information
ivan-losev authored and intel-mediadev committed Oct 25, 2021
1 parent 8117c0f commit b06a74a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 35 deletions.
79 changes: 46 additions & 33 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,11 @@ CodechalVdencAvcState::~CodechalVdencAvcState()
}
}

m_osInterface->pfnFreeResource(m_osInterface, &m_resVdencBrcConstDataBuffer);
for (uint32_t i = 0; i < CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM; i++)
{
m_osInterface->pfnFreeResource(m_osInterface, &m_resVdencBrcConstDataBuffer[i]);
}

m_osInterface->pfnFreeResource(m_osInterface, &m_resVdencBrcHistoryBuffer);
m_osInterface->pfnFreeResource(m_osInterface, &m_resVdencSfdImageStateReadBuffer);
m_osInterface->pfnFreeResource(m_osInterface, &m_resVdencBrcDbgBuffer);
Expand Down Expand Up @@ -3451,7 +3455,7 @@ void CodechalVdencAvcState::InitializeDataMember()

MOS_ZeroMemory(&m_resVdencBrcImageStatesReadBuffer, sizeof(MOS_RESOURCE) * CODECHAL_ENCODE_RECYCLED_BUFFER_NUM);

MOS_ZeroMemory(&m_resVdencBrcConstDataBuffer, sizeof(MOS_RESOURCE));
MOS_ZeroMemory(&m_resVdencBrcConstDataBuffer, sizeof(MOS_RESOURCE) * CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM);
MOS_ZeroMemory(&m_resVdencBrcHistoryBuffer, sizeof(MOS_RESOURCE));
MOS_ZeroMemory(&m_resVdencBrcRoiBuffer, sizeof(MOS_RESOURCE) * CODECHAL_ENCODE_RECYCLED_BUFFER_NUM);
MOS_ZeroMemory(&m_resVdencBrcDbgBuffer, sizeof(MOS_RESOURCE));
Expand Down Expand Up @@ -5207,7 +5211,8 @@ MOS_STATUS CodechalVdencAvcState::HuCBrcUpdate()
{
virtualAddrParams.regionParams[4].presRegion = &m_resSfdOutputBuffer[m_currRecycledBufIdx];
}
virtualAddrParams.regionParams[5].presRegion = &m_resVdencBrcConstDataBuffer;
virtualAddrParams.regionParams[5].presRegion = &m_resVdencBrcConstDataBuffer[GetCurrConstDataBufIdx()];

if (m_nonNativeBrcRoiSupported && m_avcPicParam->NumROI && !m_avcPicParam->bNativeROI) // Only for BRC non-native ROI
{
if (m_osInterface->osCpInterface != nullptr && m_osInterface->osCpInterface->IsCpEnabled())
Expand Down Expand Up @@ -5389,15 +5394,22 @@ MOS_STATUS CodechalVdencAvcState::SetConstDataHuCBrcUpdate()
if (m_brcInit)
{
MOS_LOCK_PARAMS lockFlagsWriteOnly;
auto hucConstData = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &m_resVdencBrcConstDataBuffer, &lockFlagsWriteOnly);
FillHucConstData(hucConstData);
m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer);
for (uint8_t picType = 0; picType < CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM; picType++)
{
auto hucConstData = (uint8_t*)m_osInterface->pfnLockResource(
m_osInterface, &m_resVdencBrcConstDataBuffer[picType], &lockFlagsWriteOnly);
CODECHAL_ENCODE_CHK_NULL_RETURN(hucConstData);

FillHucConstData(hucConstData, picType);
m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer[picType]);
}
}

if (m_vdencStaticFrame)
{
MOS_LOCK_PARAMS lockFlagsWriteOnly;
auto hucConstData = (PAVCVdencBRCCostantData)m_osInterface->pfnLockResource(m_osInterface, &m_resVdencBrcConstDataBuffer, &lockFlagsWriteOnly);
auto hucConstData = (PAVCVdencBRCCostantData)m_osInterface->pfnLockResource(
m_osInterface, &m_resVdencBrcConstDataBuffer[GetCurrConstDataBufIdx()], &lockFlagsWriteOnly);
CODECHAL_ENCODE_CHK_NULL_RETURN(hucConstData);

// adjustment due to dirty ROI
Expand All @@ -5407,8 +5419,7 @@ MOS_STATUS CodechalVdencAvcState::SetConstDataHuCBrcUpdate()
temp = (uint32_t)(temp * CODECHAL_VDENC_AVC_STATIC_FRAME_INTRACOSTSCLRatioP / 100.0 + 0.5);
hucConstData->UPD_P_Intra16x16[j] = Map44LutValue(temp, 0x8f);
}

m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer);
m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer[GetCurrConstDataBufIdx()]);
}

return eStatus;
Expand Down Expand Up @@ -6901,32 +6912,29 @@ MOS_STATUS CodechalVdencAvcState::AllocateResources()
// Const Data buffer
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(GetBRCCostantDataSize(), CODECHAL_PAGE_SIZE);
allocParamsForBufferLinear.pBufName = "VDENC BRC Const Data Buffer";

eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource(
m_osInterface,
&allocParamsForBufferLinear,
&m_resVdencBrcConstDataBuffer);

if (eStatus != MOS_STATUS_SUCCESS)
for (uint32_t i = 0; i < CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM; i++)
{
CODECHAL_ENCODE_ASSERTMESSAGE("%s: Failed to allocate VDENC BRC Const Data Buffer\n", __FUNCTION__);
return eStatus;
}
CODECHAL_ENCODE_CHK_STATUS_MESSAGE_RETURN(m_osInterface->pfnAllocateResource(
m_osInterface,
&allocParamsForBufferLinear,
&m_resVdencBrcConstDataBuffer[i]),
"%s: Failed to allocate 's'", __FUNCTION__, allocParamsForBufferLinear.pBufName);

uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource(
m_osInterface,
&(m_resVdencBrcConstDataBuffer),
&lockFlagsWriteOnly);
uint8_t* data = (uint8_t*)m_osInterface->pfnLockResource(
m_osInterface,
&m_resVdencBrcConstDataBuffer[i],
&lockFlagsWriteOnly);

if (data == nullptr)
{
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to Lock VDEnc VDENC BRC Const Data Buffer.");
eStatus = MOS_STATUS_UNKNOWN;
return eStatus;
}
if (data == nullptr)
{
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to Lock '%s'", allocParamsForBufferLinear.pBufName);
eStatus = MOS_STATUS_UNKNOWN;
return eStatus;
}

MOS_ZeroMemory(data, allocParamsForBufferLinear.dwBytes);
m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer);
MOS_ZeroMemory(data, allocParamsForBufferLinear.dwBytes);
m_osInterface->pfnUnlockResource(m_osInterface, &m_resVdencBrcConstDataBuffer[i]);
}

// BRC history buffer
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(CODECHAL_VDENC_AVC_BRC_HISTORY_BUF_SIZE, CODECHAL_PAGE_SIZE);
Expand Down Expand Up @@ -7777,7 +7785,7 @@ PMHW_VDBOX_VDENC_WALKER_STATE_PARAMS CodechalVdencAvcState::CreateMhwVdboxVdencW
return vdencWalkerStateParams;
}

MOS_STATUS CodechalVdencAvcState::FillHucConstData(uint8_t *data)
MOS_STATUS CodechalVdencAvcState::FillHucConstData(uint8_t *data, uint8_t /*picType*/)
{
auto hucConstData = (PAVCVdencBRCCostantData)data;
auto avcSeqParams = m_avcSeqParam;
Expand Down Expand Up @@ -8368,6 +8376,11 @@ void CodechalVdencAvcState::SetBufferToStorePakStatistics()
}
}

uint32_t CodechalVdencAvcState::GetCurrConstDataBufIdx()
{
return m_avcPicParam->CodingType - 1;
}

#if USE_CODECHAL_DEBUG_TOOL
MOS_STATUS CodechalVdencAvcState::DumpHucBrcInit()
{
Expand Down Expand Up @@ -8411,7 +8424,7 @@ MOS_STATUS CodechalVdencAvcState::DumpHucBrcUpdate(bool isInput)

// Constant Data Buffer dump
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpHucRegion(
&m_resVdencBrcConstDataBuffer,
&m_resVdencBrcConstDataBuffer[GetCurrConstDataBufIdx()],
0,
GetBRCCostantDataSize(),
5,
Expand Down
10 changes: 8 additions & 2 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
#define CODECHAL_VDENC_AVC_POS_MULT_VBR 100
#define CODECHAL_VDENC_AVC_NEG_MULT_VBR -50

#define CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM (NUM_PIC_TYPES + 1) //!< For each frame type + 1 for ref B

#define __CODEGEN_BITFIELD(l, h) (h) - (l) + 1
//!
//! \brief CODECHAL_VDENC_STREAMIN_STATE
Expand Down Expand Up @@ -916,7 +918,7 @@ class CodechalVdencAvcState : public CodechalEncodeAvcBase

virtual uint32_t GetBRCCostantDataSize() { return sizeof(AVCVdencBRCCostantData); }

virtual MOS_STATUS FillHucConstData(uint8_t *data);
virtual MOS_STATUS FillHucConstData(uint8_t *data, uint8_t picType);

//!
//! \brief Prepare HW MetaData buffer
Expand Down Expand Up @@ -953,6 +955,8 @@ class CodechalVdencAvcState : public CodechalEncodeAvcBase

virtual void SetBufferToStorePakStatistics();

virtual uint32_t GetCurrConstDataBufIdx();

protected:
bool m_vdencSinglePassEnable = false; //!< Enable VDEnc single pass

Expand Down Expand Up @@ -1007,7 +1011,7 @@ class CodechalVdencAvcState : public CodechalEncodeAvcBase
MOS_RESOURCE m_resVdencBrcUpdateDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][CODECHAL_VDENC_BRC_NUM_OF_PASSES]; //!< Brc Update DMEM Buffer Array.
MOS_RESOURCE m_resVdencBrcInitDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Brc Init DMEM Buffer Array.
MOS_RESOURCE m_resVdencBrcImageStatesReadBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Read-only VDENC+PAK IMG STATE buffer.
MOS_RESOURCE m_resVdencBrcConstDataBuffer; //!< BRC Const Data Buffer.
MOS_RESOURCE m_resVdencBrcConstDataBuffer[CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM]; //!< BRC Const Data Buffer for each frame type.
MOS_RESOURCE m_resVdencBrcHistoryBuffer; //!< BRC History Buffer.
MOS_RESOURCE m_resVdencBrcRoiBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< BRC ROI Buffer.
MOS_RESOURCE m_resVdencBrcDbgBuffer; //!< BRC Debug Buffer.
Expand Down Expand Up @@ -1250,7 +1254,9 @@ MOS_STATUS CodechalVdencAvcState::SetDmemHuCBrcInitResetImpl(CODECHAL_VDENC_AVC_
hucVDEncBrcInitDmem->INIT_ProfileLevelMaxFrame_U32 = profileLevelMaxFrame;
if (avcSeqParams->GopRefDist && (avcSeqParams->GopPicSize > 0))
{
// Their ratio is used in BRC kernel to detect mini GOP structure. Have to be multiple.
hucVDEncBrcInitDmem->INIT_GopP_U16 = (avcSeqParams->GopPicSize - 1) / avcSeqParams->GopRefDist;
hucVDEncBrcInitDmem->INIT_GopB_U16 = (avcSeqParams->GopRefDist - 1) * hucVDEncBrcInitDmem->INIT_GopP_U16;
}

if (m_minMaxQpControlEnabled)
Expand Down

0 comments on commit b06a74a

Please sign in to comment.