From aa5398689bcec8bcf97d654fae962c4cf734aefe Mon Sep 17 00:00:00 2001 From: Wenfeng Gao Date: Mon, 23 Mar 2026 10:04:18 -0700 Subject: [PATCH] mediafoundation: Fix the frame number validation logic for motion hint The external move region frame number was continuously generated. However, the current POC was reset based on IDR. Modified the logic of validation and logged a warning in case of mismatch. Reviewed-by: Pohsiang (John) Hsu Part-of: --- src/gallium/frontends/mediafoundation/encode_h264.cpp | 11 +++++++---- src/gallium/frontends/mediafoundation/encode_hevc.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gallium/frontends/mediafoundation/encode_h264.cpp b/src/gallium/frontends/mediafoundation/encode_h264.cpp index a3f50a16fa9..83851edcbd7 100644 --- a/src/gallium/frontends/mediafoundation/encode_h264.cpp +++ b/src/gallium/frontends/mediafoundation/encode_h264.cpp @@ -426,14 +426,17 @@ CDX12EncHMFT::PrepareForEncodeHelper( LPDX12EncodeContext pDX12EncodeContext, uint32_t current_poc = pPicInfo->pic_order_cnt; // Validate frame number first - if( moveRegionFrameNum != current_poc ) + // Due to the way the move region frame number is generated, there can be cases where the frame number doesn't match the + // current POC. In those cases, we will log a warning but still try to use the move regions. + if( m_uiGopSize > 0 && ( moveRegionFrameNum % m_uiGopSize ) != current_poc ) { - debug_printf( "[dx12 hmft 0x%p] MoveRegions frame mismatch (MRFN=%u, cur POC=%u), ignoring\n", + debug_printf( "[dx12 hmft 0x%p] WARNING: MoveRegions frame mismatch (MRFN=%u, cur POC=%u, GOPSize=%u)\n", this, moveRegionFrameNum, - current_poc ); + current_poc, + m_uiGopSize ); } - else + { MOVEREGION_INFO *pMoveInfo = reinterpret_cast( m_pMoveRegionBlob.data() ); uint32_t maxRects = m_EncoderCapabilities.m_HWSupportMoveRects.bits.max_motion_hints; diff --git a/src/gallium/frontends/mediafoundation/encode_hevc.cpp b/src/gallium/frontends/mediafoundation/encode_hevc.cpp index 0c79bc5ea25..bfc3d29ae78 100644 --- a/src/gallium/frontends/mediafoundation/encode_hevc.cpp +++ b/src/gallium/frontends/mediafoundation/encode_hevc.cpp @@ -434,14 +434,17 @@ CDX12EncHMFT::PrepareForEncodeHelper( LPDX12EncodeContext pDX12EncodeContext, uint32_t current_poc = pPicInfo->pic_order_cnt; // Validate frame number first - if( moveRegionFrameNum != current_poc ) + // Due to the way the move region frame number is generated, there can be cases where the frame number doesn't match the + // current POC. In those cases, we will log a warning but still try to use the move regions. + if( m_uiGopSize > 0 && ( moveRegionFrameNum % m_uiGopSize ) != current_poc ) { - debug_printf( "[dx12 hmft 0x%p] MoveRegions frame mismatch (MRFN=%u, cur POC=%u), ignoring\n", + debug_printf( "[dx12 hmft 0x%p] WARNING: MoveRegions frame mismatch (MRFN=%u, cur POC=%u, GOPSize=%u)\n", this, moveRegionFrameNum, - current_poc ); + current_poc, + m_uiGopSize ); } - else + { MOVEREGION_INFO *pMoveInfo = reinterpret_cast( m_pMoveRegionBlob.data() ); uint32_t maxRects = m_EncoderCapabilities.m_HWSupportMoveRects.bits.max_motion_hints;