Skip to content

Commit

Permalink
[Encode] Fix AVC quality drop and PF for camera padding surface
Browse files Browse the repository at this point in the history
Fix AVC quality drop for 16-unaligned height introduced by input surface copy.
Fix the corner case when width and pitch are both 16-aligned but pitch > width due to extra padding.
  • Loading branch information
walter-bai authored and intel-mediadev committed Nov 2, 2023
1 parent 51129e4 commit 816b1ad
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "encode_avc_basic_feature_xe_lpm_plus_base.h"
#include "mhw_vdbox_vdenc_hwcmd_xe_lpm_plus.h"
#include "mos_os_cp_interface_specific.h"

namespace encode
{
Expand All @@ -43,4 +44,51 @@ MHW_SETPAR_DECL_SRC(VDENC_PIPE_MODE_SELECT, AvcBasicFeatureXe_Lpm_Plus_Base)
return MOS_STATUS_SUCCESS;
}

bool AvcBasicFeatureXe_Lpm_Plus_Base::InputSurfaceNeedsExtraCopy(const MOS_SURFACE &input)
{
#if _DEBUG || _RELEASE_INTERNAL
static int8_t supported = -1;

if (supported == -1)
{
MediaUserSetting::Value outValue{};

ReadUserSettingForDebug(
m_userSettingPtr,
outValue,
"DisableInputSurfaceCopy",
MediaUserSetting::Group::Sequence);

supported = !outValue.Get<bool>();
}

if (!supported)
{
return false;
}
#endif

if (m_osInterface->osCpInterface && m_osInterface->osCpInterface->IsCpEnabled())
{
return false;
}

uint32_t alignedSize = 0;
uint32_t pitch = MOS_MAX((uint32_t)m_picWidthInMb * CODECHAL_MACROBLOCK_WIDTH, (uint32_t)input.dwPitch);
switch (input.Format)
{
case Format_NV12:
alignedSize = pitch * (m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT) * 3 / 2;
break;
case Format_A8R8G8B8:
alignedSize = pitch * (m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT) * 4;
break;
default:
alignedSize = 0;
break;
}

return input.dwSize < alignedSize;
}

} // namespace encode
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class AvcBasicFeatureXe_Lpm_Plus_Base : public AvcBasicFeature

virtual ~AvcBasicFeatureXe_Lpm_Plus_Base() {}

bool InputSurfaceNeedsExtraCopy(const MOS_SURFACE &input) override;

MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT);

MEDIA_CLASS_DEFINE_END(encode__AvcBasicFeatureXe_Lpm_Plus_Base)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,14 +637,20 @@ bool AvcBasicFeature::InputSurfaceNeedsExtraCopy(const MOS_SURFACE &input)
}
#endif

if (m_osInterface->osCpInterface && m_osInterface->osCpInterface->IsCpEnabled())
{
return false;
}

uint32_t alignedSize = 0;
uint32_t pitch = MOS_MAX((uint32_t)m_seqParam->FrameWidth, (uint32_t)input.dwPitch);
switch (input.Format)
{
case Format_NV12:
alignedSize = (m_picWidthInMb * CODECHAL_MACROBLOCK_WIDTH) * (m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT) * 3 / 2;
alignedSize = pitch * m_seqParam->FrameHeight * 3 / 2;
break;
case Format_A8R8G8B8:
alignedSize = (m_picWidthInMb * CODECHAL_MACROBLOCK_WIDTH) * (m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT) * 4;
alignedSize = pitch * m_seqParam->FrameHeight * 4;
break;
default:
alignedSize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class AvcBasicFeature : public EncodeBasicFeature,
MOS_STATUS SetSliceStructs();
void CheckResolutionChange();
MOS_STATUS PackPictureHeader();
bool InputSurfaceNeedsExtraCopy(const MOS_SURFACE& input);
virtual bool InputSurfaceNeedsExtraCopy(const MOS_SURFACE &input);

virtual MOS_STATUS UpdateTrackedBufferParameters() override;
virtual MOS_STATUS GetTrackedBuffers() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ MOS_STATUS AvcVdencPipeline::InitUserSetting(MediaUserSettingSharedPtr userSetti
userSettingPtr,
"DisableInputSurfaceCopy",
MediaUserSetting::Group::Sequence,
"",
false,
false);
#endif
return MOS_STATUS_SUCCESS;
Expand Down

0 comments on commit 816b1ad

Please sign in to comment.