| 333 | } |
| 334 | |
| 335 | void EndFrame(IDXGISwapChain4* swapChain, uint32 syncIntervals) |
| 336 | { |
| 337 | Assert_(Device); |
| 338 | |
| 339 | DXCall(CmdList->Close()); |
| 340 | |
| 341 | EndFrame_Upload(); |
| 342 | |
| 343 | ID3D12CommandList* commandLists[] = { CmdList }; |
| 344 | GfxQueue->ExecuteCommandLists(ArraySize_(commandLists), commandLists); |
| 345 | |
| 346 | // Present the frame. |
| 347 | if(swapChain) |
| 348 | DXCall(swapChain->Present(syncIntervals, syncIntervals == 0 ? DXGI_PRESENT_ALLOW_TEARING : 0)); |
| 349 | |
| 350 | ++CurrentCPUFrame; |
| 351 | |
| 352 | // Signal the fence with the current frame number, so that we can check back on it |
| 353 | FrameFence.Signal(GfxQueue, CurrentCPUFrame); |
| 354 | |
| 355 | // Wait for the GPU to catch up before we stomp an executing command buffer |
| 356 | const uint64 gpuLag = DX12::CurrentCPUFrame - DX12::CurrentGPUFrame; |
| 357 | Assert_(gpuLag <= DX12::RenderLatency); |
| 358 | if(gpuLag >= DX12::RenderLatency) |
| 359 | { |
| 360 | // Make sure that the previous frame is finished |
| 361 | FrameFence.Wait(DX12::CurrentGPUFrame + 1); |
| 362 | ++DX12::CurrentGPUFrame; |
| 363 | } |
| 364 | |
| 365 | CurrFrameIdx = DX12::CurrentCPUFrame % NumCmdAllocators; |
| 366 | |
| 367 | // Prepare the command buffers to be used for the next frame |
| 368 | DXCall(CmdAllocators[CurrFrameIdx]->Reset()); |
| 369 | DXCall(CmdList->Reset(CmdAllocators[CurrFrameIdx], nullptr)); |
| 370 | |
| 371 | EndFrame_Helpers(); |
| 372 | |
| 373 | // See if we have any deferred releases to process |
| 374 | ProcessDeferredReleases(CurrFrameIdx); |
| 375 | ProcessDeferredSRVCreates(CurrFrameIdx); |
| 376 | } |
| 377 | |
| 378 | void FlushGPU() |
| 379 | { |
no test coverage detected