![]() |
Vireo
0.0
Vireo 3D Rendering Hardware Interface
|
A swapchain is the GPU–window system bridge: a queue of images you render into and then present to the screen. It manages double- or triple-buffering under the hood and provide the application mechanisms to wait for the frame to be presented and which frame in currently rendering.
A CPU/GPU synchronization must be used to ensure that the image we want to use is ready to be used and a GPU/GPU synchronization to ensure that the rendering of the frame is terminated before presenting the image to the screen.
The CPU/GPU synchronization is done with a fence and the GPU/GPU synchronization is done internally by the SwapChain and SubmitQueue classes for portability between graphic API.
To create a swap chain we need :
There is two presentation modes :
Before using the swap chain for rendering make sure to :
For CPU/GPU synchronization when rendering you need to use a fence. For rendering multiple frames in flight you need one fence par frame. The best solution is to put them in the same data structure as the frame command list :
When rendering get the frame data corresponding to the current frame, acquire the next frame buffer (while waiting for the frame buffer to be ready with the fence) with vireo::SwapChain::acquire, draw the frame then, after submitting all the frame command lists, present the frame buffer to the screen vireo::SwapChain::present.
At the end of the rendering, get the next frame index with vireo::SwapChain::nextFrameIndex. By doing that at the end of the rendering, the new frame index can be used in the application to update the frame specific data during the next frame update and rendering.