1. Swap Chain
1.1 What is a Swap Chain
- We all know that the function of the DirectX12 driver is simply to read graphic Resource data, submit it to various shaders in the Pipeline, and then render one frame of image data. The final display process still needs to transfer the frame data to the Windows system and hand it over to the DirectX10 driver for display.
- So where does DirectX12 submit the data to
This is the theme of this article: Swap Chain . When initializing the DX12 APP, it is necessary to call the CreatSwapChain() interface from the DXGI library (a unified graphical interaction interface provided by DirectX runtime), create one or more Resource resources, and inform the DirectX12 driver of this resource through RTV (render target view): fill all the rendered image data into the SwapChain Resource I provide you with according to a certain format, and leave the rest to me for display. - From the above, we can also understand that in the development of DirectX12 drivers, it is necessary to wait for the DirectX10 driver to be ready before actual development can take place. Because the Windows system can only start normally and DirectX12 data can only be displayed normally after DirectX10 is driven, it is also quite awkward.
1.2 Why is it called a Swap Chain
- We know that the rendering efficiency of GPUs is very high. In contrast, the system display speed may not keep up with the rendering speed of GPUs. To maximize the efficiency of GPUs, we can do this:
- When initializing the DX12 APP, calling CreatSwapChain() creates two RTV resources, both of which have the same size and format, and are called Resource A& B.
- At any given moment of display, the GPU renders Resource A well, and the APP uses CPU& The Fence mechanism between GPUs (refer to another article) learns that Resource A is ready, and then submits Resource A to the system for display, while also submitting Resource B to GPU rendering. Here, Resource A refers to it as Front Buffer Resource B refers to it as Back Buffer .
- When rendering the next frame, the APP will display Resource A& B exchanges roles, and after the GPU finishes rendering Resource B, the APP submits Resource B to the system for display, while handing Resource A over to the GPU for rendering
- When submitting to the system for display, only pointers are provided without actions such as Resource Copy, so the efficiency is very high
Of course, if the GPU speed is faster, we can also set a Triple Buffer, and the principle is similar.