This is SunshineBooming, a small Driver engineer at GPU company, whose main job is to write DirectX12 Drivers. I will continue to update this DX12 Spec series, which may be unpopular, but it is all based on practical experience and work experience. If you have any GPU related questions, you can interact in the comment section without hesitation:
DirectX12 Spec General Catalog.
1. Basic concepts
- A common problem: Step (1) The CPU submits a Resource to the GPU, and Step (2) The CPU commands the GPU to use Resource for rendering. From step (1) to (2), the CPU needs to confirm that the Resource is fully committed to the GPU memory. How to ensure this?
- A feasible solution: Insert a synchronization instruction into the CPU between steps (1) and (2), confirm that the Resource submission is complete, and then issue the rendering instruction.
- When CPU/GPU processors work in parallel, various synchronization issues naturally arise, which are used in DirectX12 Fence mechanism If the CPU wants to confirm that all previous commands have been executed, it inserts a Fence after the command, and when the GPU returns this Fence, it can confirm that all previous commands have been executed.
- In fact, Fence in the GPU Driver is a memory containing numerical values, with an initial value of 0. Once Fence synchronization is performed, it will move up; 1 increment. Before submitting the Fence, the CPU knows that the Fence Value is n. After receiving the Fence, the GPU confirms that the current Command has been executed and rewrites the Fence Value to n; 1. CPU loop detection and confirmation of Fence Value as n; 1. Complete Fence synchronization .
2. Fence mechanism
- A more detailed explanation can be found in the following figure:
- CPU issues Comamnd1
- CPU insertion Fence; GPU execution Command1
- CPU waiting for Fence; GPU execution Command1
- GPU increment Fence (note that GPU Hardware will confirm that all previous commands have been executed before increment Fence)
- CPU confirms Fence returns, continue with other commands