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 f5c4b9772d2..df078729e64 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 @@ -728,14 +728,12 @@ typedef struct _CODEC_AVC_ENCODE_PIC_PARAMS CODEC_PICTURE RefFrameList[CODEC_AVC_MAX_NUM_REF_FRAME]; - /*! \brief Defines each entry in the list that specifies the frame resource for reference pictures. - * - * the index of RefFrameListSurface[] corresponds to a FrameIdx, and the stored content is the surface resource associated with that FrameIdx. - * Valid FrameIdx values range from [0..14, 0x7F]. - * RefFrameList[] must include all reference pictures in the Decoded Picture Buffer (DPB), ensuring that any picture referenced by the current or future pictures has a valid entry. - * - * Note: This structure is currently applicable only for Vulkan encoding. - */ + /*! \brief Each entry of the list specifies the frame resource of the reference pictures. + * + * The value of FrameIdx is the same as the reference frame index saved in RefList. And valid value range is [0..14, 0x7F]. + * RefFrameList[] should include all the reference pictures in DPB, which means either the picture is referred by current picture or future pictures, it should have a valid entry in it. + * currently only for Vulkan encode + */ MOS_SURFACE RefFrameListSurface[CODEC_AVC_MAX_NUM_REF_FRAME]; /*! \brief Denotes "used for reference" frames as defined in the AVC specification. diff --git a/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp b/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp index 5e96a75d826..6a3ca792000 100644 --- a/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp +++ b/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp @@ -8048,6 +8048,80 @@ bool CodechalVdencAvcState::IsMBBRCControlEnabled() return m_mbBrcEnabled || m_avcPicParam->bNativeROI; } +MOS_STATUS CodechalVdencAvcState::GetVulkanQueryPoolResults( + uint32_t queryFrameIndex, + void *pData, + uint64_t dataOffset, + bool is64bit, + uint8_t reportStatus, + bool reportOffset, + bool reportBitstreamSize) +{ + CODECHAL_ENCODE_FUNCTION_ENTER; + MOS_STATUS eStatus = MOS_STATUS_SUCCESS; + + EncodeStatusBuffer *encodeStatusBuf = &m_encodeStatusBuf; + + uint32_t baseOffset = + queryFrameIndex * m_encodeStatusBuf.dwReportSize + + sizeof(uint32_t) * 2; + + uint8_t *bytePtr = reinterpret_cast(pData); + uint64_t vkDataoffset = dataOffset; + uint8_t *statusData = reinterpret_cast(m_encodeStatusBuf.pData); + + size_t dataSize = is64bit ? sizeof(uint64_t) : sizeof(uint32_t); + uint64_t offsetResult = 0; + uint64_t statusResult = 1; + void *pOffsetResult = &offsetResult; + void *pStatusResult = &statusResult; + + if (!is64bit) + { + offsetResult = static_cast(offsetResult); + statusResult = static_cast(statusResult); + pOffsetResult = reinterpret_cast(&offsetResult); + pStatusResult = reinterpret_cast(&statusResult); + } + + if (reportOffset) + { + eStatus = MOS_SecureMemcpy(bytePtr + vkDataoffset, dataSize, pOffsetResult, dataSize); + if (eStatus != MOS_STATUS_SUCCESS) + { + CODECHAL_ENCODE_ASSERTMESSAGE("Failed to get bitstream offset."); + return eStatus; + } + vkDataoffset += dataSize; + } + if (reportBitstreamSize) + { + eStatus = MOS_SecureMemcpy( + bytePtr + vkDataoffset, + dataSize, + statusData + baseOffset + encodeStatusBuf->dwBSByteCountOffset, + dataSize); + if (eStatus != MOS_STATUS_SUCCESS) + { + CODECHAL_ENCODE_ASSERTMESSAGE("Failed to get bitstream size from status buffer."); + return eStatus; + } + vkDataoffset += dataSize; + } + if (reportStatus) + { + eStatus = MOS_SecureMemcpy(bytePtr + vkDataoffset, dataSize, pStatusResult, dataSize); + if (eStatus != MOS_STATUS_SUCCESS) + { + CODECHAL_ENCODE_ASSERTMESSAGE("Failed to get encode status"); + return eStatus; + } + } + + return eStatus; +} + + MOS_STATUS CodechalVdencAvcState::PrepareHWMetaData( PMOS_RESOURCE presMetadataBuffer, PMOS_RESOURCE presSliceSizeStreamoutBuffer, diff --git a/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h b/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h index 7e7bcfaa3f2..4f66bb6bf6c 100644 --- a/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h +++ b/media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h @@ -967,6 +967,36 @@ class CodechalVdencAvcState : public CodechalEncodeAvcBase PMOS_RESOURCE vdencBrcImgBuffer, PMHW_VDBOX_AVC_IMG_PARAMS params); + //! + //! \brief Get Encode Status for Vulkan Query Pool + //! \details Retrieve the necessary status and results for the Vulkan query pool + //! from the status buffer, such as bitstream size, hardware encoding status, bitstream offset + //! \param [in] queryFrameIndex + //! The specified frame index + //! [in] pData + //! Points to the buffer passed by Vulkan for storing the results. + //! [in] dataOffset + //! Starting position for writing to pData + //! [in] is64bit + //! Whether each result is 64-bit, otherwise 32-bit. + //! [in] reportStatus + //! Whether the encode status needs to be returned + //! [in] reportOffset + //! Whether the bitstream offset needs to be returned + //! [in] reportBitstream + //! Whether the bitstream size needs to be returned + //! \return MOS_STATUS + //! MOS_STATUS_SUCCESS if success, else fail reason + //! + virtual MOS_STATUS GetVulkanQueryPoolResults( + uint32_t queryFrameIndex, + void *pData, + uint64_t dataOffset, + bool is64bit, + uint8_t reportStatus, + bool reportOffset, + bool reportBitstream) override; + //! //! \brief Report Slice Size to MetaData buffer //! \details Report Slice Size to MetaData buffer. diff --git a/media_softlet/agnostic/common/codec/hal/codechal_common.h b/media_softlet/agnostic/common/codec/hal/codechal_common.h index ce579502e53..58f82ac15ee 100644 --- a/media_softlet/agnostic/common/codec/hal/codechal_common.h +++ b/media_softlet/agnostic/common/codec/hal/codechal_common.h @@ -299,6 +299,40 @@ class Codechal void *status, uint16_t numStatus); + //! + //! \brief Get Encode Status for Vulkan Query Pool + //! \details Retrieve the necessary status and results for the Vulkan query pool + //! from the status buffer, such as bitstream size, hardware encoding status, bitstream offset + //! \param [in] queryFrameIndex + //! The specified frame index + //! [in] pData + //! Points to the buffer passed by Vulkan for storing the results. + //! [in] dataOffset + //! Starting position for writing to pData + //! [in] is64bit + //! Whether each result is 64-bit, otherwise 32-bit. + //! [in] reportStatus + //! Whether the encode status needs to be returned + //! [in] reportOffset + //! Whether the bitstream offset needs to be returned + //! [in] reportBitstream + //! Whether the bitstream size needs to be returned + //! \return MOS_STATUS + //! MOS_STATUS_SUCCESS if success, else fail reason + //! + virtual MOS_STATUS GetVulkanQueryPoolResults( + uint32_t queryFrameIndex, + void *pData, + uint64_t dataOffset, + bool is64bit, + uint8_t reportStatus, + bool reportOffset, + bool reportBitstream) + { + return MOS_STATUS_SUCCESS; + } + + //! //! \brief Destroy codechl state //!