diff --git a/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs b/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs index 16efe46909..9687a9fa5a 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/D3D11Resources.cs @@ -25,6 +25,7 @@ namespace BizHawk.Bizware.Graphics public ID3D11RasterizerState RasterizerState; public FeatureLevel DeviceFeatureLevel; + public bool PresentAllowTearing; public D3D11RenderTarget CurRenderTarget; public D3D11Pipeline CurPipeline; @@ -69,6 +70,9 @@ namespace BizHawk.Bizware.Graphics // however, it's not guaranteed to be available (only available in Win8+ or Win7 with the Platform Update) Factory2 = Factory1.QueryInterfaceOrNull(); + using var factory5 = Factory1.QueryInterfaceOrNull(); + PresentAllowTearing = factory5?.PresentAllowTearing ?? false; + var bd = default(BlendDescription); bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; diff --git a/src/BizHawk.Bizware.Graphics/D3D11/D3D11SwapChain.cs b/src/BizHawk.Bizware.Graphics/D3D11/D3D11SwapChain.cs index 00b687c1b8..663b09f466 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/D3D11SwapChain.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/D3D11SwapChain.cs @@ -35,6 +35,7 @@ namespace BizHawk.Bizware.Graphics public ID3D11Texture2D BackBufferTexture; public ID3D11RenderTargetView RTV; public IDXGISwapChain SwapChain; + public bool HasFlipModel; public bool AllowsTearing; public void Dispose() @@ -64,6 +65,7 @@ namespace BizHawk.Bizware.Graphics private ID3D11Texture2D BackBufferTexture => _resources.BackBufferTexture; private ID3D11RenderTargetView RTV => _resources.RTV; private IDXGISwapChain SwapChain => _resources.SwapChain; + private bool HasFlipModel => _resources.HasFlipModel; private bool AllowsTearing => _resources.AllowsTearing; internal D3D11SwapChain(SwapChainResources resources, Action resetDeviceCallback) @@ -80,7 +82,7 @@ namespace BizHawk.Bizware.Graphics Context.OMSetRenderTargets(RTV); PresentFlags presentFlags; - if (cp.Vsync) + if (cp.Vsync || !HasFlipModel) { presentFlags = PresentFlags.None; } diff --git a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs index 8e919770bf..c357d3d7cb 100644 --- a/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs +++ b/src/BizHawk.Bizware.Graphics/D3D11/IGL_D3D11.cs @@ -28,6 +28,8 @@ namespace BizHawk.Bizware.Graphics private ID3D11BlendState BlendDisableState => _resources.BlendDisableState; private ID3D11RasterizerState RasterizerState => _resources.RasterizerState; + private bool PresentAllowTearing => _resources.PresentAllowTearing; + private D3D11RenderTarget CurRenderTarget => _resources.CurRenderTarget; private D3D11Pipeline CurPipeline => _resources.CurPipeline; @@ -89,7 +91,7 @@ namespace BizHawk.Bizware.Graphics bufferCount: 2, scaling: Scaling.Stretch, alphaMode: AlphaMode.Ignore, - flags: SwapChainFlags.AllowTearing); + flags: PresentAllowTearing ? SwapChainFlags.AllowTearing : SwapChainFlags.None); try { @@ -97,9 +99,18 @@ namespace BizHawk.Bizware.Graphics } catch { - sd.SwapEffect = SwapEffect.Discard; - sd.Flags = SwapChainFlags.None; - ret = Factory2.CreateSwapChainForHwnd(Device, cp.Handle, sd); + try + { + // FlipSequential is supported on Win8+ + sd.SwapEffect = SwapEffect.FlipSequential; + ret = Factory2.CreateSwapChainForHwnd(Device, cp.Handle, sd); + } + catch + { + sd.SwapEffect = SwapEffect.Discard; + sd.Flags = SwapChainFlags.None; + ret = Factory2.CreateSwapChainForHwnd(Device, cp.Handle, sd); + } } } @@ -123,6 +134,7 @@ namespace BizHawk.Bizware.Graphics var bbTex = swapChain.GetBuffer(0); var bbRtvd = new RenderTargetViewDescription(RenderTargetViewDimension.Texture2D, Format.B8G8R8A8_UNorm); var rtv = Device.CreateRenderTargetView(bbTex, bbRtvd); + var swapChainDesc = swapChain.Description; _controlSwapChain.Device = Device; _controlSwapChain.Context = Context; @@ -130,7 +142,8 @@ namespace BizHawk.Bizware.Graphics _controlSwapChain.BackBufferTexture = bbTex; _controlSwapChain.RTV = rtv; _controlSwapChain.SwapChain = swapChain; - _controlSwapChain.AllowsTearing = (swapChain.Description.Flags & SwapChainFlags.AllowTearing) != 0; + _controlSwapChain.HasFlipModel = swapChainDesc.SwapEffect is SwapEffect.FlipSequential or SwapEffect.FlipDiscard; + _controlSwapChain.AllowsTearing = (swapChainDesc.Flags & SwapChainFlags.AllowTearing) != 0; } public D3D11SwapChain CreateSwapChain(D3D11SwapChain.ControlParameters cp) @@ -144,6 +157,7 @@ namespace BizHawk.Bizware.Graphics var bbTex = swapChain.GetBuffer(0); var rtvd = new RenderTargetViewDescription(RenderTargetViewDimension.Texture2D, Format.B8G8R8A8_UNorm); var rtv = Device.CreateRenderTargetView(bbTex, rtvd); + var swapChainDesc = swapChain.Description; _controlSwapChain = new() { @@ -153,7 +167,8 @@ namespace BizHawk.Bizware.Graphics BackBufferTexture = bbTex, RTV = rtv, SwapChain = swapChain, - AllowsTearing = (swapChain.Description.Flags & SwapChainFlags.AllowTearing) != 0, + HasFlipModel = swapChainDesc.SwapEffect is SwapEffect.FlipSequential or SwapEffect.FlipDiscard, + AllowsTearing = (swapChainDesc.Flags & SwapChainFlags.AllowTearing) != 0, }; return new(_controlSwapChain, ResetDevice);