# DX11 Nothing renders in windowed mode on Windows 10 with dedicated Nvidia card

This topic is 1016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Not sure if GDNet is the best place for this, but recently I "upgraded" my laptop to Windows 10, and ever since then, I've been seeing an issue with one of my projects where I'll get an empty window if I run the game in windowed mode with my dedicated graphics card (an Nvidia GTX 860M) - D3D won't even clear the screen to black, and my card makes a screeching noise. The problem doesn't manifest if I either run in fullscreen (no GPU noises) or force the game to run with my integrated card. This was NOT happening in Windows 8.1, so I'm inclined to suspect either a driver problem or possibly Win8.1 let me get away with doing something "naughty."

I haven't seen any similar problems with other DX11 games (though I haven't actually run any of them in windowed mode, so I'm wondering if I may be doing something wrong. Here is the code that sets up my device and swap chain:

// setup swap chain description
DXGI_SWAP_CHAIN_DESC mSwapChainDesc = { 0 };
mSwapChainDesc.OutputWindow = hwnd;
mSwapChainDesc.Windowed = !fullscreen;
mSwapChainDesc.BufferDesc.Width = windowWidth;
mSwapChainDesc.BufferDesc.Height = windowHeight;
mSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
mSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
mSwapChainDesc.BufferCount = 1;
mSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
mSwapChainDesc.SampleDesc.Count = 1;
mSwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

// create the mDevice
HRESULT result = S_OK;
if (FAILED(result = D3D11CreateDeviceAndSwapChain(nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
&mSwapChainDesc,
nullptr,
{
ErrorMsg("Failed to create D3D11 mDevice and swap chain");
return false;
}

There doesn't appear to be any error messages - all D3D calls, including the above, appear to succeed.

edit: Updated thread title to better reflect the symptoms of the problem. Edited by Oberon_Command

##### Share on other sites

Hm, this seems rather odd. I have been running DX11 for my studies for the past few months and I haven't seen any such problem (running W10, same graphics card). I've played a bit with the initialization to get the same settings for the swap chain as you have, but I'm not running into any problems. Granted, the code for initialization is not mine (from Luna's DX11 book), but I did rewrite the initialization part at some point for my own goals and didn't run into any problems either.

The only real difference I have is that I call D3D11CreateDevice and CreateSwapChain (on the DXGIFactory) separately, rather than the unified call. That might be a clue as to why things are going haywire.

If it helps, here's my initialization of the swapchain, though I haven't been able to actually test it for a while unfortunately. You can also dig through Luna's samples to see if he does anything differently, though I can guarantee that it's pretty much the code below written somewhat differently (and wouldn't explain any such problem).

        DXGI_SWAP_CHAIN_DESC swapChainDescription;
swapChainDescription.BufferDesc.Width = m_Width;
swapChainDescription.BufferDesc.Height = m_Height;
swapChainDescription.BufferDesc.RefreshRate.Numerator = 60;
swapChainDescription.BufferDesc.RefreshRate.Denominator = 1;
swapChainDescription.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDescription.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDescription.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDescription.SampleDesc.Count = 1;
swapChainDescription.SampleDesc.Quality = 0;
swapChainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDescription.BufferCount = 1;
swapChainDescription.OutputWindow = m_WindowHandle;
swapChainDescription.Windowed = true;
swapChainDescription.Flags = 0;

IDXGIDevice* dxgiDevice = nullptr;
HR(m_Device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));
IDXGIFactory* dxgiFactory = nullptr;
HR(dxgiFactory->CreateSwapChain(m_Device, &swapChainDescription, &m_SwapChain));

dxgiDevice->Release();
dxgiFactory->Release();


(That's not to say I'm denying driver problems, but perhaps this can get you around it. I can imagine it being 'fairly' annoying to not be able to run in windowed mode')

On a sidenote, screeching noise makes me think of coilwhine caused by super high FPS (which would make sense if you're not drawing anything). I have this problem on my pc quite a bit, but haven't heard about it occuring on a laptop GPU before.

Edited by AthosVG

##### Share on other sites

The "screeching noise" sounds like coil whine / squeaking. Does it sound like this or like this?

If so, this usually (but not always) means your card is drawing near maximum power.

Coil whine is considered harmless to your hardware, though some people believe if you hear coil noise, there's strong vibrations, if there's strong vibrations, it means gradual wear and tear over time (i.e. shorten lifespan); thus it's often advised to reduce the amount of time your GPU spends whining, just in case this turns to be more than a myth.

##### Share on other sites

I found it!

First of all, what didn't work: I tried the set of flags AthosVG posted; no difference in behaviour. I also tried pasting Luna's equivalent code to see if that would make a difference; no difference in behaviour. I looked at compiling the full samples, but they depend on D3DX and XNAMath which I apparently don't have since I'd heard these were deprecated. Is there a more up to date version somewhere?

I had a look at the samples here and those do appear to run correctly in windowed mode. Near as I can tell, I'm not doing anything differently, though I'm using the 11.0 code path instead of 11.1. I don't think that should make a difference - I broke into the samples in the debugger and forced them down the 11.0 path to see what would happen and they still worked correctly. In fact, I took my own initialization code and pasted it into the sample code (rearranging some of the names) and everything still worked correctly!

Then I looked at the initialization code and noticed that I'm deriving the back buffer width and height from a configuration file, whereas the tutorial is computing it directly from the window's client rectangle. Changing my code to use the client rectangle bounds for the back buffer got things rendering again! I also noticed that in windowed mode, the window's client rect appeared slightly smaller than it did when I ran the program on 8.1 - as though the window borders take up more room and infringe on some of the client rectangle where they didn't before. So maybe the OS has changed the way window sizes are calculated? Strange that this would only manifest when using my dedicated card, though.

So: moral of the story, ensure that your back buffer size matches that of your client rect!

edit: And it did indeed sound like coil whine. My best guess (without being much of a graphics programmer) for what must have been happening was that the back buffer was created successfully, but with a 0 size, causing all my initialization and draw calls to succeed without actually doing anything meaningful.

Edited by Oberon_Command

##### Share on other sites

I suspect the problem would also go away if you used FLIP_DISCARD instead of DISCARD. On laptops like that, when using the discrete GPU, the OS asks the discrete to put the contents somewhere that the integrated can see it, so that composition is fast and efficient. Apparently this operation doesn't work so well when the source and dest are different sizes (back buffer size != window size). With FLIP_DISCARD, the image is in something that's back-buffer-sized all the way through the stack until composition samples from it.

##### Share on other sites

I suspect the problem would also go away if you used FLIP_DISCARD instead of DISCARD. On laptops like that, when using the discrete GPU, the OS asks the discrete to put the contents somewhere that the integrated can see it, so that composition is fast and efficient. Apparently this operation doesn't work so well when the source and dest are different sizes (back buffer size != window size). With FLIP_DISCARD, the image is in something that's back-buffer-sized all the way through the stack until composition samples from it.

Possible, but it's also a performance issue if the sizes mismatch, so you really should match the sizes rather than try to work around it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 34
• 16
• 11
• 11
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015646
×