* Prepare to render the next frame. */
| 934 | * Prepare to render the next frame. |
| 935 | */ |
| 936 | void MoveToNextFrame(D3D12Global &d3d) |
| 937 | { |
| 938 | // Schedule a Signal command in the queue |
| 939 | const UINT64 currentFenceValue = d3d.fenceValues[d3d.frameIndex]; |
| 940 | HRESULT hr = d3d.cmdQueue->Signal(d3d.fence, currentFenceValue); |
| 941 | Utils::Validate(hr, L"Error: failed to signal command queue!"); |
| 942 | |
| 943 | // Update the frame index |
| 944 | d3d.frameIndex = d3d.swapChain->GetCurrentBackBufferIndex(); |
| 945 | |
| 946 | // If the next frame is not ready to be rendered yet, wait until it is |
| 947 | if (d3d.fence->GetCompletedValue() < d3d.fenceValues[d3d.frameIndex]) |
| 948 | { |
| 949 | hr = d3d.fence->SetEventOnCompletion(d3d.fenceValues[d3d.frameIndex], d3d.fenceEvent); |
| 950 | Utils::Validate(hr, L"Error: failed to set fence value!"); |
| 951 | |
| 952 | WaitForSingleObjectEx(d3d.fenceEvent, INFINITE, FALSE); |
| 953 | } |
| 954 | |
| 955 | // Set the fence value for the next frame |
| 956 | d3d.fenceValues[d3d.frameIndex] = currentFenceValue + 1; |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * Save the back buffer to disk using DirectxTk library. |