Sign in to follow this  
Mumsfilibaba

Swapchain won't display to window after resizing

Recommended Posts

So I've got a quite interesting problem that only happens on my laptop. I have a window with the following WNDCLASSEX struct specifed:

m_Desc.hInstance = (HINSTANCE)GetModuleHandle(0);
m_Desc.lpfnWndProc = stdWinProc;
m_Desc.cbClsExtra = 0;
m_Desc.cbWndExtra = 0;
m_Desc.hbrBackground = RE_WINDOW_BACKGROUND_COLOR_DARKGRAY;
m_Desc.hCursor = RE_CURSOR_STANDARD;
m_Desc.hIcon = RE_ICON_STANDARD;
m_Desc.hIconSm = 0;
m_Desc.cbSize = sizeof(WNDCLASSEX);
m_Desc.style = CS_HREDRAW | CS_VREDRAW;
m_Desc.lpszClassName = L"DefWndClass";
m_Desc.lpszMenuName = 0;

And I have a swapchain that have the following struct:

DXGI_SWAP_CHAIN_DESC swapChainDesc;
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Format = format;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.RefreshRate = mode.RefreshRate;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swapChainDesc.OutputWindow = (HWND)windowHandle;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Windowed = true;

I then bind and clear the rendertarget- and depthstencilview that is created for swapchain. And I do get the expected result as long as I don't resize my window. If I do the only thing that is displayed is the background that is specified in the WNDCLASSEX struct. I have had this problem before but haven't been able to really solve it. If I resize the buffers when I repond to the WM_SIZE message it works, but I want the buffers that are getting rendered to depend on the application's settings, like when you set the settings within the game for example. Or is the best practise to always resize the swapchain's buffers when the window gets resized and have I seperate rendertarget that I render my scene to, and then render that onto a quad to the buffers in the swapchain? And why do I not get the same results on my laptop and stationary computer? They are both nvidia and intelbased with the latest drivers so it should result in the same result right?

Would be nice if someone could shed some light on this, because I haven't been able to find any relevant information about this. 

Edited by Mumsfilibaba

Share this post


Link to post
Share on other sites

I've just been experimenting with window resizing, and I'm fairly sure that what you're seeing isn't the correct behavior. If you don't do any handling of WM_SIZE message, the swap chain should just stretch the back buffer to match the front buffer, ie your window client area, when presenting it to the screen. If you're seeing your window background instead, it probably means that IDXGISwapChain::Present method isn't working correctly. Could you take a look at the HRESULT it's returning or post your rendering code here?

Also, are you using debug DirectX runtime (creating d3d device with D3D11_CREATE_DEVICE_DEBUG flag)? It may report some relevant issues too.

Share this post


Link to post
Share on other sites

Or is the best practise to always resize the swapchain's buffers when the window gets resized and have I seperate rendertarget that I render my scene to, and then render that onto a quad to the buffers in the swapchain?

If you're looking for a way to render your scene at a fixed resolution, no matter the window size, I think it will be best to always resize your swapchain's buffers, but only render to a portion of the backbuffer by keeping the correct width and height in the D3D11_VIEWPORT. Keep in mind though, that this may not be what the user expects, especially if the window becomes smaller than the specified resolution and part of the rendered scene get cut off.

Share this post


Link to post
Share on other sites

This is a known problem that happens on some hybrid graphics configurations. Essentially, an attempt to optimize the cross-GPU presentation path results in a lack of ability to stretch. There are several workarounds, but the simplest one is to just not ask the hardware to stretch as part of Present.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this