title: Tearing with VSYNC in full screen mode only (windowed mode works fine) on Windows 10 / DirectX
body: <p>I think that my DirectX 11 application worked fine on the previous system (I'm about 70% sure). But now, in Windows 10 (laptop) <strong>I have tearing issue in full screen mode only</strong> (the windowed mode works without any tearing). </p>
  
  <p>The scene is quite "heavy" (it's supposed to be performance tested for my application). When DirectX renders "heavier" parts, it went down to about 50fps for a short time (my measurements may be a bit inaccurate) and then went back to 60-61fps. What is strange is, I do not not see tearing in the "heavier" parts (about 50fps).</p>
  
  <p>I've heard that it can be somehow related to DWM which provides its own synchronization for windowed applications (that's why my program works fine in windowed mode?).</p>
  
  <p><strong>What can I do about it?</strong></p>
  
  <p>The swap chain:</p>
  
  <pre><code>DXGI_SWAP_CHAIN_DESC sd;
  ZeroMemory(&amp;sd, sizeof(sd));
  sd.BufferCount = 1;
  sd.BufferDesc.Width = width;
  sd.BufferDesc.Height = height;
  sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  sd.BufferDesc.RefreshRate.Numerator = numerator;
  sd.BufferDesc.RefreshRate.Denominator = denominator;
  sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  sd.OutputWindow = *hwnd;
  sd.SampleDesc.Count = sampleCount; //1 (and 0 for quality) to turn off multisampling
  sd.SampleDesc.Quality = maxQualityLevel;
  sd.Windowed = fullScreen ? FALSE : TRUE;
  sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; //allow full-screen switchin
  
  // Set the scan line ordering and scaling to unspecified.
  sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
  sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
  // Discard the back buffer contents after presenting.
  sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
  </code></pre>
  
  <p>Where <code>numerator</code> and <code>denominator</code> are calculated based on <a href="http://www.rastertek.com/dx11tut03.html" rel="nofollow noreferrer">this tutorial</a>:</p>
  
  <pre><code>...
  numerator = displayModeList[i].RefreshRate.Numerator;
  denominator = displayModeList[i].RefreshRate.Denominator;
  </code></pre>
  
  <p>Which returns two very high values that gives about <code>60</code> when divided by each other (would I get the same effect by just setting them to <code>60</code> and <code>1</code>?):</p>
  
  <p><a href="https://i.stack.imgur.com/EszEu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EszEu.png" alt="enter image description here"></a></p>
  
  <p>I also render with:</p>
  
  <pre><code>if(VSYNC){
      swapChain-&gt;Present(1, 0); //lock to screen refresh rate
  }else{
      swapChain-&gt;Present(0, 0); //present as fast as possible
  }
  </code></pre>
  
  <p><strong>Did I miss something? Or did I do something wrong?</strong></p>