Previously, I discovered a strange issue with the DirectX11 engine I was working on: the integrated display did not produce any issues, while the standalone display experienced flickering images. This problem did not appear before, it only appeared after implementing the dirty rectangle algorithm. Moreover, the phenomenon of flashing screen is also very strange. After careful investigation, it should be that the previous image was not preserved before each draw, resulting in a large number of black areas in a buffer zone. But I didn't clear the RenderTargetView in the code, and why did it happen in a standalone display while the collective display was fine
So I started thinking about how to copy the content of the front-end buffer to the back-end buffer, and also consulted foreign programmers in GameDev. After debugging for several hours in a row, I was exhausted and finally couldn't help but go to sleep. (I usually don't feel like falling asleep when I have a bug that hasn't been resolved, and I don't go to sleep until I can't hold it anymore. Is this a common problem among programmers?)
After waking up, take a good look at the tutorial of DirectX11. After all, there are many contents that I have forgotten a few months later. Let's review the old and learn new things. As a result, while reading the tutorial, when I saw the exchange chain, I found that it has a property called SwapEffect, which I haven't noticed before. Upon checking the official documentation, it turned out that it was used to determine how to exchange buffers specifically. Upon careful examination of the document, it was found that:
- DXGI_ SWAP_ Effect_ DISCARD Use this flag to specify the bit block transfer (bitblt) model and to specify that DXGI discards the content of the back buffer after you call IDXGISwapChain1:: Present1 This flag is valid for a swap chain with more than one back buffer, appropriate, applications only have read and write access to buffer 0 Use this flag to enable the display driver to select the most effective presentation technology for the swap chain
The bold sentence I added above surprised me. It turned out that this marker would allow the graphics card to choose the most efficient switching technology. Isn't this the reason why different graphics cards have different switching effects? I checked my program and found that I did not set this attribute for my exchange chain. The default setting is DXGI_SWAP_EFFECT_DISCARD
. I suspect that the reason for not discarding the backup buffer is due to insufficient collection and display capabilities, while strong independent display capabilities may have discarded the backup buffer. Independent display may even have used flip instead of bitblt for exchange
Later on, how did I solve it? When creating the exchange chain, I added a sentence:
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
Solved this bug so easily
Why did I think for several hours without realizing that there was a problem with the properties of the exchange chain
It can be seen that insufficient sleep can affect Debug's analytical and reasoning abilities. The best solution after discovering a bug may be to take a deep sleep.