i fount unreal engine code here:
void FD3D9DynamicRHI::EndDrawingViewport(FViewportRHIParamRef ViewportRHI,UBOOL bPresent,UBOOL bLockToVsync)
{
DYNAMIC_CAST_D3D9RESOURCE(Viewport,Viewport);
SCOPE_CYCLE_COUNTER(STAT_D3D9PresentTime);
GPUFrameTiming.EndTiming();
extern DWORD GGPUFrameTime;
if ( GPUFrameTiming.IsSupported() )
{
QWORD GPUTiming = GPUFrameTiming.GetTiming();
QWORD GPUFreq = GPUFrameTiming.GetTimingFrequency();
GGPUFrameTime = appTrunc( DOUBLE(GPUTiming) / DOUBLE(GPUFreq) / GSecondsPerCycle );
}
else
{
GGPUFrameTime = 0;
}
check(DrawingViewport.GetReference() == Viewport);
DrawingViewport = NULL;
// Clear references the device might have to resources.
Direct3DDevice->SetRenderTarget(0,*BackBuffer);
Direct3DDevice->SetDepthStencilSurface(NULL);
UnsetPSTextures();
UnsetVSTextures();
Direct3DDevice->SetVertexShader(NULL);
ResetVertexStreams();
Direct3DDevice->SetIndices(NULL);
Direct3DDevice->SetPixelShader(NULL);
#if WITH_PANORAMA
extern void appPanoramaRenderHookRender(void);
// Allow G4WLive to render the Live Guide as needed (or toasts)
appPanoramaRenderHookRender();
#endif
// Tell D3D we're done rendering.
Direct3DDevice->EndScene();
if(bPresent)
{
// Present the back buffer to the viewport window.
HRESULT Result = S_OK;
if(Viewport->IsFullscreen())
{
Result = Direct3DDevice->Present(NULL,NULL,NULL,NULL);
}
else
{
RECT DestRect;
if(GetClientRect((HWND)Viewport->GetWindowHandle(),&DestRect))
{
RECT SourceRect;
SourceRect.left = SourceRect.top = 0;
SourceRect.right = Viewport->GetSizeX();
SourceRect.bottom = Viewport->GetSizeY();
// Only present to the viewport if its client area isn't zero-sized.
if(DestRect.right > 0 && DestRect.bottom > 0)
{
Result = Direct3DDevice->Present(&SourceRect,NULL,(HWND)Viewport->GetWindowHandle(),NULL);
}
}
}
// Detect a lost device.
if(Result == D3DERR_DEVICELOST || Result == E_FAIL)
{
// This variable is checked periodically by the main thread.
bDeviceLost = TRUE;
}
else
{
VERIFYD3D9RESULT(Result);
}
}
// Wait for the GPU to finish rendering the previous frame before finishing this frame.
FrameSyncEvent.WaitForCompletion();
FrameSyncEvent.IssueEvent();
// If the input latency timer has been triggered, block until the GPU is completely
// finished displaying this frame and calculate the delta time.
if ( GInputLatencyTimer.RenderThreadTrigger )
{
FrameSyncEvent.WaitForCompletion();
DWORD EndTime = appCycles();
GInputLatencyTimer.DeltaTime = EndTime - GInputLatencyTimer.StartTime;
GInputLatencyTimer.RenderThreadTrigger = FALSE;
}
}
what the effect of this code:
FrameSyncEvent.WaitForCompletion();
FrameSyncEvent.IssueEvent();
if i comment them, the engine works well too.
so i want to know why they do this ?