From ccc491d0e6eee70375929488b710856ab074cb3d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 28 Jan 2022 18:06:59 +0100 Subject: [PATCH 1/3] Adjust dynamic resolution based on refresh rate This removes the fixed target of 60fps --- .../Helpers/DynamicResolutionManager.cs | 20 ++- .../Helpers/SwapChainManager.Rendering.cs | 2 +- .../TerraFX.Interop.Windows.projitems | 3 + .../Windows/um/dwmapi/DWM_TIMING_INFO.cs | 124 ++++++++++++++++++ .../Windows/um/dwmapi/UNSIGNED_RATIO.cs | 18 +++ .../Windows/um/dwmapi/Windows.cs | 14 ++ 6 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs create mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs create mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs diff --git a/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs b/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs index ac3b07ec..796acbb1 100644 --- a/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs +++ b/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs @@ -1,6 +1,9 @@ using System; using System.Runtime.CompilerServices; using System.Threading; +using ComputeSharp.Core.Extensions; +using TerraFX.Interop.Windows; +using Win32 = TerraFX.Interop.Windows.Windows; #if WINDOWS_UWP namespace ComputeSharp.Uwp.Helpers; @@ -66,9 +69,22 @@ internal unsafe ref struct DynamicResolutionManager /// /// Initializes a new instance. /// - /// The target framerate to use. - public DynamicResolutionManager(int targetFramerate) + public DynamicResolutionManager() { + DWM_TIMING_INFO dwmTimingInfo = default; + + dwmTimingInfo.cbSize = (uint)sizeof(DWM_TIMING_INFO); + + // Get the composition timing info (the refresh rate depends on the compositor) + Win32.DwmGetCompositionTimingInfo(HWND.NULL, &dwmTimingInfo).Assert(); + + // Calculates the best target framerate based on monitor refresh rate. Even with v-sync disabled, + // the target framerate should always match the refresh rate in use, instead of being capped to + // 60fps (as users could have a 120Hz screen and disabled v-sync). Here the refresh rate is retrieved, + // then the target framerate is calculated as being the rounding of this value to the next integer, + // then rounded up to the next multiple of 30, and then clamped between 30 and 240fps. + double refreshRateInHz = dwmTimingInfo.rateRefresh.uiNumerator / (double)dwmTimingInfo.rateRefresh.uiDenominator; + int targetFramerate = Math.Clamp((((int)Math.Ceiling(refreshRateInHz) + 29) / 30) * 30, 30, 240); long targetFrameTimeInTicks = TimeSpan.FromSeconds(1).Ticks / targetFramerate; long upperFrameTimeThresholdInTicks = TimeSpan.FromSeconds(1).Ticks / (targetFramerate - 2); long lowerFrameTimeThresholdInTicks = TimeSpan.FromSeconds(1).Ticks / (targetFramerate + 2); diff --git a/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs b/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs index 9a51483a..12858505 100644 --- a/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs +++ b/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs @@ -263,7 +263,7 @@ partial class SwapChainManager Stopwatch renderStopwatch = this.renderStopwatch ??= new(); Stopwatch frameStopwatch = new(); CancellationToken cancellationToken = this.renderCancellationTokenSource!.Token; - DynamicResolutionManager frameTimeWatcher = new(60); + DynamicResolutionManager frameTimeWatcher = new(); if (!OnFrameRequest(out object? parameter, cancellationToken)) { diff --git a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems index fd914b80..5a927617 100644 --- a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems +++ b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems @@ -228,6 +228,9 @@ + + + diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs new file mode 100644 index 00000000..99ddf4b4 --- /dev/null +++ b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs @@ -0,0 +1,124 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System.Runtime.InteropServices; + +namespace TerraFX.Interop.Windows; + +[StructLayout(LayoutKind.Sequential, Pack = 1)] +internal partial struct DWM_TIMING_INFO +{ + [NativeTypeName("UINT32")] + public uint cbSize; + + public UNSIGNED_RATIO rateRefresh; + + [NativeTypeName("QPC_TIME")] + public ulong qpcRefreshPeriod; + + public UNSIGNED_RATIO rateCompose; + + [NativeTypeName("QPC_TIME")] + public ulong qpcVBlank; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefresh; + + public uint cDXRefresh; + + [NativeTypeName("QPC_TIME")] + public ulong qpcCompose; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFrame; + + public uint cDXPresent; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshFrame; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFrameSubmitted; + + public uint cDXPresentSubmitted; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFrameConfirmed; + + public uint cDXPresentConfirmed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshConfirmed; + + public uint cDXRefreshConfirmed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesLate; + + public uint cFramesOutstanding; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFrameDisplayed; + + [NativeTypeName("QPC_TIME")] + public ulong qpcFrameDisplayed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshFrameDisplayed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFrameComplete; + + [NativeTypeName("QPC_TIME")] + public ulong qpcFrameComplete; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramePending; + + [NativeTypeName("QPC_TIME")] + public ulong qpcFramePending; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesDisplayed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesComplete; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesPending; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesAvailable; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesDropped; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cFramesMissed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshNextDisplayed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshNextPresented; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshesDisplayed; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshesPresented; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cRefreshStarted; + + [NativeTypeName("ULONGLONG")] + public ulong cPixelsReceived; + + [NativeTypeName("ULONGLONG")] + public ulong cPixelsDrawn; + + [NativeTypeName("DWM_FRAME_COUNT")] + public ulong cBuffersEmpty; +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs new file mode 100644 index 00000000..9d950570 --- /dev/null +++ b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs @@ -0,0 +1,18 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System.Runtime.InteropServices; + +namespace TerraFX.Interop.Windows; + +[StructLayout(LayoutKind.Sequential, Pack = 1)] +internal partial struct UNSIGNED_RATIO +{ + [NativeTypeName("UINT32")] + public uint uiNumerator; + + [NativeTypeName("UINT32")] + public uint uiDenominator; +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs new file mode 100644 index 00000000..ed27198f --- /dev/null +++ b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs @@ -0,0 +1,14 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System.Runtime.InteropServices; + +namespace TerraFX.Interop.Windows; + +internal static unsafe partial class Windows +{ + [DllImport("dwmapi", ExactSpelling = true)] + public static extern HRESULT DwmGetCompositionTimingInfo(HWND hwnd, DWM_TIMING_INFO* pTimingInfo); +} \ No newline at end of file From 276f9da199e5c600a2624d8524216bf3e09d136e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 29 Jan 2022 01:54:07 +0100 Subject: [PATCH 2/3] Fix computation of compositor refresh rate Cannot use DwmGetCompositionTimingInfo as it fails WACK --- src/ComputeSharp.UI/ComputeSharp.UI.projitems | 1 + .../Extensions/IDXGIAdapterExtensions.cs | 55 +++++++++++++++++++ .../Helpers/DynamicResolutionManager.cs | 20 +------ .../Helpers/SwapChainManager.Rendering.cs | 13 ++++- .../Helpers/SwapChainManager.cs | 13 +++++ src/ComputeSharp/Graphics/GraphicsDevice.cs | 12 ++++ .../DirectX/shared/dxgi1_2/DXGIOutput1.cs | 27 +++++++++ .../DirectX/shared/dxgi1_2/DXGI_MODE_DESC1.cs | 26 +++++++++ .../shared/dxgicommon/DXGI_RATIONAL.cs | 14 +++++ .../shared/dxgitype/DXGI_MODE_SCALING.cs | 16 ++++++ .../dxgitype/DXGI_MODE_SCANLINE_ORDER.cs | 18 ++++++ .../TerraFX.Interop.Windows.projitems | 5 ++ 12 files changed, 199 insertions(+), 21 deletions(-) create mode 100644 src/ComputeSharp.UI/Extensions/IDXGIAdapterExtensions.cs create mode 100644 src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGIOutput1.cs create mode 100644 src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGI_MODE_DESC1.cs create mode 100644 src/TerraFX.Interop.Windows/DirectX/shared/dxgicommon/DXGI_RATIONAL.cs create mode 100644 src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCALING.cs create mode 100644 src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCANLINE_ORDER.cs diff --git a/src/ComputeSharp.UI/ComputeSharp.UI.projitems b/src/ComputeSharp.UI/ComputeSharp.UI.projitems index 2f58b838..8d9208f4 100644 --- a/src/ComputeSharp.UI/ComputeSharp.UI.projitems +++ b/src/ComputeSharp.UI/ComputeSharp.UI.projitems @@ -13,6 +13,7 @@ + diff --git a/src/ComputeSharp.UI/Extensions/IDXGIAdapterExtensions.cs b/src/ComputeSharp.UI/Extensions/IDXGIAdapterExtensions.cs new file mode 100644 index 00000000..8244edde --- /dev/null +++ b/src/ComputeSharp.UI/Extensions/IDXGIAdapterExtensions.cs @@ -0,0 +1,55 @@ +using System; +using ComputeSharp.Core.Extensions; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; +using Win32 = TerraFX.Interop.Windows.Windows; + +#if WINDOWS_UWP +namespace ComputeSharp.Uwp.Extensions; +#else +namespace ComputeSharp.WinUI.Extensions; +#endif + +/// +/// A with extensions for the type. +/// +internal static unsafe class IDXGIAdapterExtensions +{ + /// + /// Calculates the refresh rate for a given adapter. + /// + /// The input adapter to query. + /// The in use to render content. + /// The current composition refresh rate. + public static int GetCompositionRefreshRate(this ref IDXGIAdapter dxgiAdapter, DXGI_FORMAT dxgiFormat) + { + using ComPtr dxgiAdapter1 = default; + + dxgiAdapter.QueryInterface(Win32.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert(); + + using ComPtr dxgiOutput = default; + + dxgiAdapter1.Get()->EnumOutputs(0, dxgiOutput.GetAddressOf()).Assert(); + + using ComPtr dxgiOutput1 = default; + + dxgiOutput.CopyTo(dxgiOutput1.GetAddressOf()).Assert(); + + DXGI_MODE_DESC1 dxgiModeDescIn = default; + + dxgiModeDescIn.Format = dxgiFormat; + + DXGI_MODE_DESC1 dxgiModeDescOut = default; + + dxgiOutput1.Get()->FindClosestMatchingMode1(&dxgiModeDescIn, &dxgiModeDescOut, null).Assert(); + + // Calculates the best target framerate based on monitor refresh rate. Even with v-sync disabled, the target framerate + // should always match the refresh rate in use, instead of being capped to 60fps (as users could have a 120Hz screen + // and disabled v-sync). Here the refresh rate is retrieved, then the target framerate is calculated as being the + // rounding up of this value to the next integer, and then clamped between 30 and 360fps. + double refreshRateInHz = dxgiModeDescOut.RefreshRate.Numerator / (double)dxgiModeDescOut.RefreshRate.Denominator; + int refreshRate = Math.Clamp((int)Math.Ceiling(refreshRateInHz), 30, 360); + + return refreshRate; + } +} diff --git a/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs b/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs index 796acbb1..ac3b07ec 100644 --- a/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs +++ b/src/ComputeSharp.UI/Helpers/DynamicResolutionManager.cs @@ -1,9 +1,6 @@ using System; using System.Runtime.CompilerServices; using System.Threading; -using ComputeSharp.Core.Extensions; -using TerraFX.Interop.Windows; -using Win32 = TerraFX.Interop.Windows.Windows; #if WINDOWS_UWP namespace ComputeSharp.Uwp.Helpers; @@ -69,22 +66,9 @@ internal unsafe ref struct DynamicResolutionManager /// /// Initializes a new instance. /// - public DynamicResolutionManager() + /// The target framerate to use. + public DynamicResolutionManager(int targetFramerate) { - DWM_TIMING_INFO dwmTimingInfo = default; - - dwmTimingInfo.cbSize = (uint)sizeof(DWM_TIMING_INFO); - - // Get the composition timing info (the refresh rate depends on the compositor) - Win32.DwmGetCompositionTimingInfo(HWND.NULL, &dwmTimingInfo).Assert(); - - // Calculates the best target framerate based on monitor refresh rate. Even with v-sync disabled, - // the target framerate should always match the refresh rate in use, instead of being capped to - // 60fps (as users could have a 120Hz screen and disabled v-sync). Here the refresh rate is retrieved, - // then the target framerate is calculated as being the rounding of this value to the next integer, - // then rounded up to the next multiple of 30, and then clamped between 30 and 240fps. - double refreshRateInHz = dwmTimingInfo.rateRefresh.uiNumerator / (double)dwmTimingInfo.rateRefresh.uiDenominator; - int targetFramerate = Math.Clamp((((int)Math.Ceiling(refreshRateInHz) + 29) / 30) * 30, 30, 240); long targetFrameTimeInTicks = TimeSpan.FromSeconds(1).Ticks / targetFramerate; long upperFrameTimeThresholdInTicks = TimeSpan.FromSeconds(1).Ticks / (targetFramerate - 2); long lowerFrameTimeThresholdInTicks = TimeSpan.FromSeconds(1).Ticks / (targetFramerate + 2); diff --git a/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs b/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs index 12858505..479f22b2 100644 --- a/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs +++ b/src/ComputeSharp.UI/Helpers/SwapChainManager.Rendering.cs @@ -254,16 +254,23 @@ partial class SwapChainManager } } + /// + /// Gets the instance to use in . + /// + /// The instance to use. + private unsafe partial void OnGetDynamicResolutionManager(out DynamicResolutionManager resolutionManager); + /// /// The core render loop with dynamic resolution. /// [MethodImpl(MethodImplOptions.NoInlining)] - private void RenderLoopWithDynamicResolution() + private unsafe void RenderLoopWithDynamicResolution() { Stopwatch renderStopwatch = this.renderStopwatch ??= new(); Stopwatch frameStopwatch = new(); CancellationToken cancellationToken = this.renderCancellationTokenSource!.Token; - DynamicResolutionManager frameTimeWatcher = new(); + + OnGetDynamicResolutionManager(out DynamicResolutionManager resolutionManager); if (!OnFrameRequest(out object? parameter, cancellationToken)) { @@ -308,7 +315,7 @@ partial class SwapChainManager OnPresent(); // Evaluate the dynamic resolution frame time step - if (frameTimeWatcher.Advance(frameStopwatch.ElapsedTicks, ref this.dynamicResolutionScale)) + if (resolutionManager.Advance(frameStopwatch.ElapsedTicks, ref this.dynamicResolutionScale)) { this.isResizePending = true; } diff --git a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs index 2d3fd60b..65d44117 100644 --- a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs +++ b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs @@ -4,6 +4,11 @@ using System.Threading; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Helpers; using ComputeSharp.Interop; +#if WINDOWS_UWP +using ComputeSharp.Uwp.Extensions; +#else +using ComputeSharp.WinUI.Extensions; +#endif #if !WINDOWS_UWP using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml.Controls; @@ -471,6 +476,14 @@ internal sealed unsafe partial class SwapChainManager : NativeObject } } + /// + private unsafe partial void OnGetDynamicResolutionManager(out DynamicResolutionManager resolutionManager) + { + int targetFramerate = GraphicsDevice.Default.DXGIAdapter->GetCompositionRefreshRate(DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM); + + resolutionManager = new DynamicResolutionManager(targetFramerate); + } + /// protected override void OnDispose() { diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 27fb32d7..36297c8f 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -27,6 +27,11 @@ public sealed unsafe partial class GraphicsDevice : NativeObject /// private ComPtr d3D12Device; + /// + /// The that was created from. + /// + private ComPtr dxgiAdapter; + /// /// The instance to use for compute operations. /// @@ -93,6 +98,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject internal GraphicsDevice(ID3D12Device* d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1) { this.d3D12Device = new ComPtr(d3D12Device); + this.dxgiAdapter = new ComPtr(dxgiAdapter); this.d3D12ComputeCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE); this.d3D12CopyCommandQueue = d3D12Device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COPY); @@ -169,6 +175,11 @@ public sealed unsafe partial class GraphicsDevice : NativeObject /// internal ID3D12Device* D3D12Device => this.d3D12Device; + /// + /// Gets the underlying wrapped by the current instance. + /// + internal IDXGIAdapter* DXGIAdapter => this.dxgiAdapter; + #if NET6_0_OR_GREATER /// /// Gets the underlying wrapped by the current instance. @@ -352,6 +363,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject DeviceHelper.NotifyDisposedDevice(this); this.d3D12Device.Dispose(); + this.dxgiAdapter.Dispose(); this.d3D12ComputeCommandQueue.Dispose(); this.d3D12CopyCommandQueue.Dispose(); this.d3D12ComputeFence.Dispose(); diff --git a/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGIOutput1.cs b/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGIOutput1.cs new file mode 100644 index 00000000..8ef6175b --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGIOutput1.cs @@ -0,0 +1,27 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from shared/dxgi1_2.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.Windows; + +namespace TerraFX.Interop.DirectX +{ + [Guid("00CDDEA8-939B-4B83-A340-A685226666CC")] + [NativeTypeName("struct IDXGIOutput1 : IDXGIOutput")] + [NativeInheritance("IDXGIOutput")] + internal unsafe partial struct IDXGIOutput1 + { + public void** lpVtbl; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(20)] + public HRESULT FindClosestMatchingMode1([NativeTypeName("const DXGI_MODE_DESC1 *")] DXGI_MODE_DESC1* pModeToMatch, DXGI_MODE_DESC1* pClosestMatch, IUnknown* pConcernedDevice) + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[20]))((IDXGIOutput1*)Unsafe.AsPointer(ref this), pModeToMatch, pClosestMatch, pConcernedDevice); + } + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGI_MODE_DESC1.cs b/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGI_MODE_DESC1.cs new file mode 100644 index 00000000..698876b4 --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/shared/dxgi1_2/DXGI_MODE_DESC1.cs @@ -0,0 +1,26 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from shared/dxgi1_2.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using TerraFX.Interop.Windows; + +namespace TerraFX.Interop.DirectX +{ + internal partial struct DXGI_MODE_DESC1 + { + public uint Width; + + public uint Height; + + public DXGI_RATIONAL RefreshRate; + + public DXGI_FORMAT Format; + + public DXGI_MODE_SCANLINE_ORDER ScanlineOrdering; + + public DXGI_MODE_SCALING Scaling; + + public BOOL Stereo; + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/DirectX/shared/dxgicommon/DXGI_RATIONAL.cs b/src/TerraFX.Interop.Windows/DirectX/shared/dxgicommon/DXGI_RATIONAL.cs new file mode 100644 index 00000000..df398c81 --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/shared/dxgicommon/DXGI_RATIONAL.cs @@ -0,0 +1,14 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from shared/dxgicommon.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal partial struct DXGI_RATIONAL + { + public uint Numerator; + + public uint Denominator; + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCALING.cs b/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCALING.cs new file mode 100644 index 00000000..4d01c537 --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCALING.cs @@ -0,0 +1,16 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from shared/dxgitype.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal enum DXGI_MODE_SCALING + { + DXGI_MODE_SCALING_UNSPECIFIED = 0, + + DXGI_MODE_SCALING_CENTERED = 1, + + DXGI_MODE_SCALING_STRETCHED = 2, + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCANLINE_ORDER.cs b/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCANLINE_ORDER.cs new file mode 100644 index 00000000..a5a7ad3e --- /dev/null +++ b/src/TerraFX.Interop.Windows/DirectX/shared/dxgitype/DXGI_MODE_SCANLINE_ORDER.cs @@ -0,0 +1,18 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from shared/dxgitype.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +namespace TerraFX.Interop.DirectX +{ + internal enum DXGI_MODE_SCANLINE_ORDER + { + DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED = 0, + + DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE = 1, + + DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST = 2, + + DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST = 3, + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems index 5a927617..0be125ea 100644 --- a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems +++ b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems @@ -25,7 +25,9 @@ + + @@ -38,9 +40,12 @@ + + + From 8ef486249be4eb90d57381c944dbca24ad79c466 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 29 Jan 2022 01:55:09 +0100 Subject: [PATCH 3/3] Remove leftover polyfills --- .../TerraFX.Interop.Windows.projitems | 3 - .../Windows/um/dwmapi/DWM_TIMING_INFO.cs | 124 ------------------ .../Windows/um/dwmapi/UNSIGNED_RATIO.cs | 18 --- .../Windows/um/dwmapi/Windows.cs | 14 -- 4 files changed, 159 deletions(-) delete mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs delete mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs delete mode 100644 src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs diff --git a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems index 0be125ea..72e40d22 100644 --- a/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems +++ b/src/TerraFX.Interop.Windows/TerraFX.Interop.Windows.projitems @@ -233,9 +233,6 @@ - - - diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs deleted file mode 100644 index 99ddf4b4..00000000 --- a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/DWM_TIMING_INFO.cs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 -// Original source is Copyright © Microsoft. All rights reserved. - -using System.Runtime.InteropServices; - -namespace TerraFX.Interop.Windows; - -[StructLayout(LayoutKind.Sequential, Pack = 1)] -internal partial struct DWM_TIMING_INFO -{ - [NativeTypeName("UINT32")] - public uint cbSize; - - public UNSIGNED_RATIO rateRefresh; - - [NativeTypeName("QPC_TIME")] - public ulong qpcRefreshPeriod; - - public UNSIGNED_RATIO rateCompose; - - [NativeTypeName("QPC_TIME")] - public ulong qpcVBlank; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefresh; - - public uint cDXRefresh; - - [NativeTypeName("QPC_TIME")] - public ulong qpcCompose; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFrame; - - public uint cDXPresent; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshFrame; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFrameSubmitted; - - public uint cDXPresentSubmitted; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFrameConfirmed; - - public uint cDXPresentConfirmed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshConfirmed; - - public uint cDXRefreshConfirmed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesLate; - - public uint cFramesOutstanding; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFrameDisplayed; - - [NativeTypeName("QPC_TIME")] - public ulong qpcFrameDisplayed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshFrameDisplayed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFrameComplete; - - [NativeTypeName("QPC_TIME")] - public ulong qpcFrameComplete; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramePending; - - [NativeTypeName("QPC_TIME")] - public ulong qpcFramePending; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesDisplayed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesComplete; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesPending; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesAvailable; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesDropped; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cFramesMissed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshNextDisplayed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshNextPresented; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshesDisplayed; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshesPresented; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cRefreshStarted; - - [NativeTypeName("ULONGLONG")] - public ulong cPixelsReceived; - - [NativeTypeName("ULONGLONG")] - public ulong cPixelsDrawn; - - [NativeTypeName("DWM_FRAME_COUNT")] - public ulong cBuffersEmpty; -} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs deleted file mode 100644 index 9d950570..00000000 --- a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/UNSIGNED_RATIO.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 -// Original source is Copyright © Microsoft. All rights reserved. - -using System.Runtime.InteropServices; - -namespace TerraFX.Interop.Windows; - -[StructLayout(LayoutKind.Sequential, Pack = 1)] -internal partial struct UNSIGNED_RATIO -{ - [NativeTypeName("UINT32")] - public uint uiNumerator; - - [NativeTypeName("UINT32")] - public uint uiDenominator; -} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs b/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs deleted file mode 100644 index ed27198f..00000000 --- a/src/TerraFX.Interop.Windows/Windows/um/dwmapi/Windows.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. - -// Ported from um/dwmapi.h in the Windows SDK for Windows 10.0.22000.0 -// Original source is Copyright © Microsoft. All rights reserved. - -using System.Runtime.InteropServices; - -namespace TerraFX.Interop.Windows; - -internal static unsafe partial class Windows -{ - [DllImport("dwmapi", ExactSpelling = true)] - public static extern HRESULT DwmGetCompositionTimingInfo(HWND hwnd, DWM_TIMING_INFO* pTimingInfo); -} \ No newline at end of file