Skip to content

Commit

Permalink
[Encode] Enable QueryPool for Media
Browse files Browse the repository at this point in the history
* [Encode] Enable Vulkan Query Api for Media Encode

enable APIs: createVkQueryPool
getQueryPoolResult
cmdBeginQuery
EndBeginQuery
  • Loading branch information
WangLy-ada authored and intel-mediadev committed Dec 18, 2024
1 parent 3d2c719 commit 3e819f8
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 8 deletions.
14 changes: 6 additions & 8 deletions media_common/agnostic/common/codec/shared/codec_def_encode_avc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
74 changes: 74 additions & 0 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t *>(pData);
uint64_t vkDataoffset = dataOffset;
uint8_t *statusData = reinterpret_cast<uint8_t *>(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<uint32_t>(offsetResult);
statusResult = static_cast<uint32_t>(statusResult);
pOffsetResult = reinterpret_cast<uint32_t *>(&offsetResult);
pStatusResult = reinterpret_cast<uint32_t *>(&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,
Expand Down
30 changes: 30 additions & 0 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions media_softlet/agnostic/common/codec/hal/codechal_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down

0 comments on commit 3e819f8

Please sign in to comment.