Skip to content

Commit

Permalink
Frame Sync improvement
Browse files Browse the repository at this point in the history
further reduce frametime variance by eliminating influence from frame painting.
  • Loading branch information
JTGaming committed Feb 19, 2024
1 parent 8fb7d0b commit 240052f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Source/DX11VideoProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,11 +2072,13 @@ BOOL CDX11VideoProcessor::GetAlignmentSize(const CMediaType& mt, SIZE& Size)
return FALSE;
}

void CDX11VideoProcessor::SleepToSync(CRefTime& rtClock, const REFERENCE_TIME& rtStart)
void CDX11VideoProcessor::SleepToSync(const REFERENCE_TIME& rtStart)
{
if (!m_bVPFrameSyncing)
return;

CRefTime rtClock(rtStart);

//with this we more finely sync the frames based on how much offset we are from 0ms
static LONG sync_miss = 1l;
//frame sync variance. we want to offset our average by this amount
Expand Down Expand Up @@ -2165,7 +2167,6 @@ HRESULT CDX11VideoProcessor::ProcessSample(IMediaSample* pSample)
return hr;
}

SleepToSync(rtClock, rtStart);
// always Render(1) a frame after CopySample()
hr = Render(1);
m_pFilter->m_DrawStats.Add(GetPreciseTick());
Expand All @@ -2188,7 +2189,6 @@ HRESULT CDX11VideoProcessor::ProcessSample(IMediaSample* pSample)
}

rtStart += rtFrameDur / 2;
SleepToSync(rtClock, rtStart);
hr = Render(2);
m_pFilter->m_DrawStats.Add(GetPreciseTick());
if (m_pFilter->m_filterState == State_Running) {
Expand Down Expand Up @@ -2535,8 +2535,14 @@ HRESULT CDX11VideoProcessor::Render(int field)
}
#endif

m_RenderStats.paintticks = GetPreciseTick() - tick1;

{
const REFERENCE_TIME rtStart = field == 2 ? m_rtStart + m_pFilter->m_FrameStats.GetAverageFrameDuration() / 2 : m_rtStart;
SleepToSync(rtStart);
}

uint64_t tick3 = GetPreciseTick();
m_RenderStats.paintticks = tick3 - tick1;

if (m_pDXGISwapChain4) {
if (m_hdr10.bValid) {
Expand Down
2 changes: 1 addition & 1 deletion Source/DX11VideoProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class CDX11VideoProcessor
bool HandleHDRToggle();
bool SuperResValid();
bool RTXVideoHDRValid();
void SleepToSync(CRefTime& rtClock, const REFERENCE_TIME& rtStart);
void SleepToSync(const REFERENCE_TIME& rtStart);

public:
HRESULT SetDevice(ID3D11Device *pDevice, ID3D11DeviceContext *pContext, const bool bDecoderDevice);
Expand Down

0 comments on commit 240052f

Please sign in to comment.