Hi community
I am experimenting some artifacts at the beginning of swap chain buffer presentation. When I move the camera, they appear and then dissapear, they are like horizontal lines (VSync problem apparently). I am pretty sure this is related with the swap chain.
I created this video so the flickering is more noticeable.
I create the swap chain in the following way:
void D3dData::CreateSwapChain(const HWND hwnd, ID3D12CommandQueue& cmdQueue) noexcept {
IDXGISwapChain* swapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC sd = {};
sd.BufferDesc.Width = Settings::sWindowWidth;
sd.BufferDesc.Height = Settings::sWindowHeight;
sd.BufferDesc.RefreshRate.Numerator = 60U;
sd.BufferDesc.RefreshRate.Denominator = 1U;
sd.BufferDesc.Format = Settings::sBackBufferFormat;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
sd.SampleDesc.Count = 1U;
sd.SampleDesc.Quality = 0U;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = Settings::sSwapChainBufferCount;
sd.OutputWindow = hwnd;
sd.Windowed = true;
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
sd.Flags = 0;
// Note: Swap chain uses queue to perform flush.
CHECK_HR(D3dData::mDxgiFactory->CreateSwapChain(&cmdQueue, &sd, &swapChain));
CHECK_HR(swapChain->QueryInterface(IID_PPV_ARGS(D3dData::mSwapChain.GetAddressOf())));
// Set sRGB color space
D3dData::mSwapChain->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
D3dData::mSwapChain->SetFullscreenState(Settings::sFullscreen, nullptr);
// Resize the swap chain.
CHECK_HR(D3dData::mSwapChain->ResizeBuffers(Settings::sSwapChainBufferCount, Settings::sWindowWidth, Settings::sWindowHeight, Settings::sBackBufferFormat, 0U));
}
The number of queued frames is equal to Settings::sSwapChainBufferCount - 1.
The Settings::sFullscreen is true.
As you can see, I work in fullscreen space, with VSync and with FLIP_DISCARD effect.
If swap chain buffer count is 2, and then at presentation I set a sync interval of 0 through Present(0, 0) then I see these artifacts (like a VSync problem or something like that). But if I set a sync interval of 1 (Present(1, 0)), then these artifacts are not shown anymore.
If I increment swap chain buffers, I see those artifacts, unless I use a sync interval of Settings::sSwapChainBufferCount - 1, but when I move the camera I note like a slow responsiveness. You can see it in this video
I tried changing to FLIP_SEQUENTIAL, windowed mode, etc but nothing worked.
What could be the error? I want to make sure I totally understand this because maybe I am missing something abour VSync, Swap Chain, Present, etc
Thanks!