Skip to content

Commit

Permalink
MSDK resolution reset fix
Browse files Browse the repository at this point in the history
Change-Id: I7007b3323d60c378e71968818263ac0bcd8816ec
  • Loading branch information
madhurin authored and hanlong1 committed Mar 21, 2019
1 parent a6e0fe1 commit e801bff
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -807,17 +807,23 @@ MOS_STATUS CodechalEncodeHevcBase::SetSequenceStructs()

if (m_firstFrame)
{
m_oriFrameHeight = frameHeight;
m_oriFrameWidth = frameWidth;
m_oriFrameWidth = frameWidth;
m_oriFrameHeight = frameHeight;
m_prevFrameWidth = m_oriFrameWidth; //to ensure resolution reset at frame 0 is captured
m_prevFrameHeight = m_oriFrameHeight;
}

// check if there is a dynamic resolution change
if ((m_oriFrameHeight && (m_oriFrameHeight != frameHeight)) ||
(m_oriFrameWidth && (m_oriFrameWidth != frameWidth)))
if ((m_prevFrameHeight && (m_prevFrameHeight != frameHeight)) ||
(m_prevFrameWidth && (m_prevFrameWidth != frameWidth)))
{
if (frameHeight > m_createHeight || frameWidth > m_createWidth)
{
CODECHAL_ENCODE_ASSERTMESSAGE("Resolution reset from lower resolution to higher resolution not supported if it is higher than the resolution of first frame.%d, %d %d, %d", m_createWidth, m_createHeight, frameWidth, frameHeight);
eStatus = MOS_STATUS_INVALID_PARAMETER;
return eStatus;
}
m_resolutionChanged = true;
m_oriFrameHeight = frameHeight;
m_oriFrameWidth = frameWidth;
m_brcInit = true;
}
else
Expand All @@ -826,8 +832,9 @@ MOS_STATUS CodechalEncodeHevcBase::SetSequenceStructs()
}

// setup internal parameters
m_oriFrameWidth = m_frameWidth = frameWidth;
m_oriFrameHeight = m_frameHeight = frameHeight;
m_prevFrameWidth = m_oriFrameWidth = m_frameWidth = frameWidth;
m_prevFrameHeight = m_oriFrameHeight = m_frameHeight = frameHeight;

m_picWidthInMb = (uint16_t)CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_oriFrameWidth);
m_picHeightInMb = (uint16_t)CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_oriFrameHeight);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ MOS_STATUS CodechalEncoderState::Initialize(
m_picHeightInMb = (uint16_t)CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_oriFrameHeight);
m_frameWidth = m_picWidthInMb * CODECHAL_MACROBLOCK_WIDTH;
m_frameHeight = m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT;
m_createWidth = m_frameWidth;
m_createHeight = m_frameHeight;

// HME Scaling WxH
m_downscaledWidthInMb4x =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,10 @@ class CodechalEncoderState : public Codechal
uint32_t m_frameFieldHeight = 0; //!< Frame height in luma samples
uint32_t m_oriFrameHeight = 0; //!< Original frame height
uint32_t m_oriFrameWidth = 0; //!< Original frame width
uint32_t m_prevFrameWidth = 0; //!< Previous frame width
uint32_t m_prevFrameHeight = 0; //!< Previous frame height
uint32_t m_createWidth = 0; //!< Max Frame Width for resolution reset
uint32_t m_createHeight = 0; //!< Max Frame Height for resolution reset
uint16_t m_picWidthInMb = 0; //!< Picture Width in MB width count
uint16_t m_picHeightInMb = 0; //!< Picture Height in MB height count
uint16_t m_frameFieldHeightInMb = 0; //!< Frame/field Height in MB
Expand Down
56 changes: 40 additions & 16 deletions media_driver/agnostic/gen11/codec/hal/codechal_encode_hevc_g11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ MOS_STATUS CodechalEncHevcStateG11::InitializePicture(const EncoderParams& param

CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncHevcState::InitializePicture(params));

if (m_resolutionChanged)
{
ResizeBufferOffset();
}

m_sseEnabled = false;
// only 420 format support SSE output
// see TDR in scalability case, disable SSE for now before HW confirm the capability.
Expand Down Expand Up @@ -5550,25 +5555,19 @@ MOS_STATUS CodechalEncHevcStateG11::EncodeMbEncKernel(
CODECHAL_DEBUG_TOOL(
CODEC_REF_LIST currRefList;

currRefList = *(pRefList[m_currReconstructedPic.FrameIdx]);
currRefList.refPic = m_currOriginalPic;
m_currRefList = (m_refList[m_currReconstructedPic.FrameIdx]);
m_currRefList->RefPic = m_currOriginalPic;

m_debugInterface->CurrPic = m_currOriginalPic;
m_debugInterface->dwBufferDumpFrameNum = m_storeData;
m_debugInterface->wFrameType = m_pictureCodingType;
m_debugInterface->m_currPic = m_currOriginalPic;
m_debugInterface->m_bufferDumpFrameNum = m_storeData;
m_debugInterface->m_frameType = m_pictureCodingType;

//CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_DbgDumpEncodeMbEncMbPakOutput(
// m_debugInterface,
// this,
// &currRefList,
// (m_codecFunction != CODECHAL_FUNCTION_HYBRIDPAK) ?
// CODECHAL_MEDIA_STATE_ENC_NORMAL : CODECHAL_MEDIA_STATE_HYBRID_PAK_P2));
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer(
&currRefList.resRefMbCodeBuffer,
&m_currRefList->resRefMbCodeBuffer,
CodechalDbgAttr::attrOutput,
"MbCode",
m_picWidthInMb * m_frameFieldHeightInMb*64,
CodecHal_PictureIsBottomField(currRefList.RefPic) ? m_frameFieldHeightInMb * m_picWidthInMb * 64 : 0,
m_picWidthInMb * m_frameFieldHeightInMb * 64,
CodecHal_PictureIsBottomField(m_currRefList->RefPic) ? m_frameFieldHeightInMb * m_picWidthInMb * 64 : 0,
(m_codecFunction != CODECHAL_FUNCTION_HYBRIDPAK) ?
CODECHAL_MEDIA_STATE_ENC_NORMAL : CODECHAL_MEDIA_STATE_HYBRID_PAK_P2));

Expand All @@ -5583,6 +5582,7 @@ MOS_STATUS CodechalEncHevcStateG11::EncodeMbEncKernel(
(m_codecFunction != CODECHAL_FUNCTION_HYBRIDPAK) ?
CODECHAL_MEDIA_STATE_ENC_NORMAL : CODECHAL_MEDIA_STATE_HYBRID_PAK_P2));
}

if (CodecHalIsFeiEncode(m_codecFunction))
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer(
Expand All @@ -5597,7 +5597,7 @@ MOS_STATUS CodechalEncHevcStateG11::EncodeMbEncKernel(

)

CODECHAL_DEBUG_TOOL(
CODECHAL_DEBUG_TOOL(
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_DbgDumpEncodeCombineBuffer(
this,
&m_encBCombinedBuffer2[m_currRecycledBufIdx].sResource,
Expand Down Expand Up @@ -6219,7 +6219,7 @@ MOS_STATUS CodechalEncHevcStateG11::EncodeKernelFunctions()
}

// Dump SW scoreboard surface - Output of SW scoreboard Init Kernel and Input to MBENC
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpSurface(
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpSurface(
m_swScoreboardState->GetCurSwScoreboardSurface(),
CodechalDbgAttr::attrInput,
"InitSWScoreboard_In",
Expand Down Expand Up @@ -7263,6 +7263,30 @@ MOS_STATUS CodechalEncHevcStateG11::LoadPakCommandAndCuRecordFromFile()
return eStatus;
}

void CodechalEncHevcStateG11::ResizeBufferOffset()
{
CODECHAL_ENCODE_FUNCTION_ENTER;

m_widthAlignedMaxLcu = MOS_ALIGN_CEIL(m_frameWidth, MAX_LCU_SIZE);
m_heightAlignedMaxLcu = MOS_ALIGN_CEIL(m_frameHeight, MAX_LCU_SIZE);

m_widthAlignedLcu32 = MOS_ALIGN_CEIL(m_frameWidth, 32);
m_heightAlignedLcu32 = MOS_ALIGN_CEIL(m_frameHeight, 32);

uint32_t size = 0;
const uint32_t numLcu64 = m_widthAlignedMaxLcu * m_heightAlignedMaxLcu / 64 / 64;
MBENC_COMBINED_BUFFER2 fixedBuf;

//Re-Calculate m_encBCombinedBuffer2 Size and Offsets
m_historyOutBufferSize = MOS_ALIGN_CEIL(32 * numLcu64, CODECHAL_CACHELINE_SIZE);
m_threadTaskBufferSize = MOS_ALIGN_CEIL(96 * numLcu64, CODECHAL_CACHELINE_SIZE);

size = MOS_ALIGN_CEIL(sizeof(fixedBuf), CODECHAL_CACHELINE_SIZE) + m_historyOutBufferSize + m_threadTaskBufferSize;

m_historyOutBufferOffset = MOS_ALIGN_CEIL(sizeof(fixedBuf), CODECHAL_CACHELINE_SIZE);
m_threadTaskBufferOffset = m_historyOutBufferOffset + m_historyOutBufferSize;
}

uint8_t CodechalEncHevcStateG11::PicCodingTypeToSliceType(uint16_t pictureCodingType)
{
uint8_t sliceType = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,13 @@ class CodechalEncHevcStateG11 : public CodechalEncHevcState
//!
MOS_STATUS LoadPakCommandAndCuRecordFromFile();

//!
//! \brief Re-calculate buffer size and offets during resolution reset
//!
//! \return void
//!
void ResizeBufferOffset();

//!
//! \brief Set HCP_SLICE_STATE parameters that are different at slice level
//!
Expand Down

0 comments on commit e801bff

Please sign in to comment.