Skip to content

Commit

Permalink
[Encode] Wait HW semaphore before CSC
Browse files Browse the repository at this point in the history
In remote gaming usage, when input is RGB surface, insert
MI_SEMAPHORE_WAIT to wait for external copy to be done before CSC.
It can help to remove the latency gap between external copy and CSC.
This change is for AVC VDEnc only, and it is off by default for now.

Change-Id: I2070816e5408d75983a2638784ceca416c10f601
  • Loading branch information
LouZhan authored and intel-mediadev committed May 16, 2019
1 parent 676951b commit 7c0258c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1455,12 +1455,42 @@ MOS_STATUS CodechalEncodeCscDs::CscKernel(
walkerParams.GroupIdLoopSelect = m_groupId;
}

// In remote gaming scenario, when input is RGB surface, insert HW semaphore to wait for
// external copy completion before CSC. Once the marker is overwritten by external copy,
// HW semaphore will be signalled and CSC will start.
bool isRgbInput = (m_surfaceParamsCsc.psInputSurface->Format == Format_A8R8G8B8) ||
(m_surfaceParamsCsc.psInputSurface->Format == Format_A8B8G8R8) ||
(m_surfaceParamsCsc.psInputSurface->Format == Format_X8R8G8B8) ||
(m_surfaceParamsCsc.psInputSurface->Format == Format_X8B8G8R8);
uint32_t offset = m_surfaceParamsCsc.psInputSurface->dwWidth * (m_surfaceParamsCsc.psInputSurface->dwHeight - 16) * 4 - 4;
if (m_externalCopySync && isRgbInput)
{
MHW_MI_SEMAPHORE_WAIT_PARAMS miSemaphoreWaitParams;
MOS_ZeroMemory((&miSemaphoreWaitParams), sizeof(miSemaphoreWaitParams));
miSemaphoreWaitParams.presSemaphoreMem = &m_surfaceParamsCsc.psInputSurface->OsResource;
miSemaphoreWaitParams.dwResourceOffset = offset;
miSemaphoreWaitParams.bPollingWaitMode = true;
miSemaphoreWaitParams.dwSemaphoreData = 0x01234501; // the marker to check in source surface
miSemaphoreWaitParams.CompareOperation = MHW_MI_SAD_NOT_EQUAL_SDD;
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiSemaphoreWaitCmd(&cmdBuffer, &miSemaphoreWaitParams));
}

CODECHAL_ENCODE_CHK_STATUS_RETURN(m_renderInterface->AddMediaObjectWalkerCmd(&cmdBuffer, &walkerParams));

CODECHAL_ENCODE_CHK_STATUS_RETURN(m_encoder->EndStatusReport(&cmdBuffer, encFunctionType));

CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->SubmitBlocks(m_cscKernelState));

// write the marker to source surface for next MI_SEMAPHORE_WAIT to check.
if (m_externalCopySync && isRgbInput)
{
MHW_MI_STORE_DATA_PARAMS storeDataParams;
storeDataParams.pOsResource = &m_surfaceParamsCsc.psInputSurface->OsResource;
storeDataParams.dwResourceOffset = offset;
storeDataParams.dwValue = 0x01234501; // write the marker to source surface
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiStoreDataImmCmd(&cmdBuffer, &storeDataParams));
}

if (!m_singleTaskPhaseSupported || m_lastTaskInPhase)
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->UpdateGlobalCmdBufId());
Expand Down Expand Up @@ -1798,7 +1828,8 @@ CodechalEncodeCscDs::CodechalEncodeCscDs(CodechalEncoderState *encoder)
m_currRefList(encoder->m_currRefList),
m_resMbStatsBuffer(encoder->m_resMbStatsBuffer),
m_rawSurfaceToEnc(encoder->m_rawSurfaceToEnc),
m_rawSurfaceToPak(encoder->m_rawSurfaceToPak)
m_rawSurfaceToPak(encoder->m_rawSurfaceToPak),
m_externalCopySync(encoder->m_externalCopySync)
{
// Initilize interface pointers
m_encoder = encoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ class CodechalEncodeCscDs
bool& m_singleTaskPhaseSupported;
bool& m_firstTaskInPhase;
bool& m_lastTaskInPhase;
bool& m_externalCopySync;
uint8_t& m_groupId;
uint8_t& m_outputChromaFormat;
uint32_t& m_standard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,7 @@ class CodechalEncoderState : public Codechal
bool m_2xScalingEnabled = false; //!< 2x Scaling kernel only used by HEVC now
bool m_useRawForRef = false; //!< Flag to indicate if using raw surface for reference
bool m_disableReconMMCD = false; //!< disable Recon surface's MMC
bool m_externalCopySync = false; //!< Flag to indicate if GPU polling based sync for raw surface copy is enabled
uint8_t m_prevReconFrameIdx = 0; //!< Previous reconstruct frame index
uint8_t m_currReconFrameIdx = 0; //!< Current reconstruct frame index

Expand Down
9 changes: 9 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 @@ -1186,6 +1186,13 @@ MOS_STATUS CodechalVdencAvcState::Initialize(CodechalSetting * settings)
&userFeatureData);
m_tlbPrefetchEnable = userFeatureData.bData == 1;

MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
MOS_UserFeature_ReadValue_ID(
nullptr,
__MEDIA_USER_FEATURE_VALUE_EXTERNAL_COPY_SYNC_ID,
&userFeatureData);
m_externalCopySync = userFeatureData.bData == 1;

MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
MOS_UserFeature_ReadValue_ID(
nullptr,
Expand Down Expand Up @@ -3155,6 +3162,8 @@ MOS_STATUS CodechalVdencAvcState::ExecuteKernelFunctions()

m_firstTaskInPhase = true;

m_externalCopySync &= (m_avcSeqParam->ScenarioInfo == ESCENARIO_REMOTEGAMING);

if (m_cscDsState->UseSfc() && m_cscDsState->RequireCsc())
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_cscDsState->CscUsingSfc(m_avcSeqParam->InputColorSpace));
Expand Down
9 changes: 9 additions & 0 deletions media_driver/agnostic/common/os/mos_utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,15 @@ static MOS_USER_FEATURE_VALUE MOSUserFeatureDescFields[__MOS_USER_FEATURE_KEY_MA
MOS_USER_FEATURE_VALUE_TYPE_UINT32,
"0",
"Enable MOS to simualte random memory allocate fail. "),
MOS_DECLARE_UF_KEY_DBGONLY(__MEDIA_USER_FEATURE_VALUE_EXTERNAL_COPY_SYNC_ID,
"External Copy Sync",
__MEDIA_USER_FEATURE_SUBKEY_INTERNAL,
__MEDIA_USER_FEATURE_SUBKEY_INTERNAL,
"Encode",
MOS_USER_FEATURE_TYPE_USER,
MOS_USER_FEATURE_VALUE_TYPE_UINT32,
"0",
"Enable GPU polling based sync for external raw surface copy."),
};

#define MOS_NUM_USER_FEATURE_VALUES (sizeof(MOSUserFeatureDescFields) / sizeof(MOSUserFeatureDescFields[0]))
Expand Down
1 change: 1 addition & 0 deletions media_driver/agnostic/common/os/mos_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ typedef enum _MOS_USER_FEATURE_VALUE_ID
__MEDIA_USER_FEATURE_VALUE_CMD_PARS_FILES_DIRECORY_ID,
__MEDIA_USER_FEATURE_VALUE_APOGEIOS_ENABLE_ID,
__MEDIA_USER_FEATURE_VALUE_SIMULATE_RANDOM_ALLOC_MEMORY_FAIL_ID,
__MEDIA_USER_FEATURE_VALUE_EXTERNAL_COPY_SYNC_ID,
__MOS_USER_FEATURE_KEY_MAX_ID,
} MOS_USER_FEATURE_VALUE_ID;

Expand Down

0 comments on commit 7c0258c

Please sign in to comment.