diff --git a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs index 65d44117..e72fd447 100644 --- a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs +++ b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs @@ -479,7 +479,15 @@ 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); + using ComPtr dxgiFactory4 = default; + + DeviceHelper.CreateDXGIFactory4(dxgiFactory4.GetAddressOf()); + + using ComPtr dxgiAdapter = default; + + dxgiFactory4.Get()->EnumAdapters(0, dxgiAdapter.GetAddressOf()).Assert(); + + int targetFramerate = dxgiAdapter.Get()->GetCompositionRefreshRate(DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM); resolutionManager = new DynamicResolutionManager(targetFramerate); } diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs index 67f6821d..616a888a 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs @@ -27,11 +27,6 @@ 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. /// @@ -98,7 +93,6 @@ 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); @@ -175,11 +169,6 @@ 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. @@ -363,7 +352,6 @@ 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/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs index 07e8a8f0..ebeab8c7 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs @@ -27,6 +27,20 @@ internal static partial class DeviceHelper Configuration.IsDebugOutputEnabled ? (uint)DXGI.DXGI_CREATE_FACTORY_DEBUG : 0; #endif + /// + /// Creates a new instance to be used to enumerate devices. + /// + /// The resulting instance. + internal static unsafe void CreateDXGIFactory4(IDXGIFactory4** dxgiFactory4) + { + if (Configuration.IsDebugOutputEnabled) + { + EnableDebugMode(); + } + + DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof(), (void**)dxgiFactory4).Assert(); + } + /// /// Creates a new instance to be used to enumerate devices. ///