From b0b568e32e854a720e97e1085151f54c7e62f047 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 29 Mar 2018 20:05:30 -0700 Subject: Implemented option to specify hardware adapter when initializing the engine in d3d mode --- .../interface/EngineD3D11Attribs.h | 5 +++++ .../src/RenderDeviceFactoryD3D11.cpp | 23 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h b/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h index 912cb474..bdb2a28b 100644 --- a/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h +++ b/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h @@ -49,6 +49,11 @@ namespace Diligent /// Attributes of the Direct3D11-based engine implementation struct EngineD3D11Attribs : public EngineCreationAttribs { + static constexpr Uint32 DefaultAdapterId = 0xFFFFFFFF; + + /// Id of the hardware adapter the engine should be initialized on + Uint32 AdapterId = DefaultAdapterId; + /// Debug flags. See Diligent::EngineD3D11DebugFlags for a list of allowed values. /// /// \sa CreateDeviceAndContextsD3D11Type, CreateSwapChainD3D11Type, LoadGraphicsEngineD3D11 diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp index e6a1f711..fc33ddb7 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp @@ -102,7 +102,10 @@ inline bool SdkLayersAvailable() /// of deferred contexts is requested, pointers to the /// contexts are written to ppContexts array starting /// at position 1 -void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs, IRenderDevice **ppDevice, IDeviceContext **ppContexts, Uint32 NumDeferredContexts ) +void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs, + IRenderDevice **ppDevice, + IDeviceContext **ppContexts, + Uint32 NumDeferredContexts ) { if (EngineAttribs.DebugMessageCallback != nullptr) SetDebugMessageCallback(EngineAttribs.DebugMessageCallback); @@ -148,10 +151,22 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr CComPtr pd3d11Device; CComPtr pd3d11Context; + CComPtr hardwareAdapter; + if(EngineAttribs.AdapterId != EngineD3D11Attribs::DefaultAdapterId) + { + auto Adapters = FindCompatibleAdapters(); + if (EngineAttribs.AdapterId < Adapters.size()) + hardwareAdapter = Adapters[EngineAttribs.AdapterId]; + else + { + LOG_ERROR_AND_THROW(EngineAttribs.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size()); + } + } + D3D_FEATURE_LEVEL d3dFeatureLevel = D3D_FEATURE_LEVEL_11_0; HRESULT hr = D3D11CreateDevice( - nullptr, // Specify nullptr to use the default adapter. - D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. + hardwareAdapter, // Specify nullptr to use the default adapter. + hardwareAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. creationFlags, // Set debug and Direct2D compatibility flags. featureLevels, // List of feature levels this app can support. @@ -168,7 +183,7 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr // For more information on WARP, see: // http://go.microsoft.com/fwlink/?LinkId=286690 hr = D3D11CreateDevice( - nullptr, + nullptr, D3D_DRIVER_TYPE_WARP, // Create a WARP device instead of a hardware device. 0, creationFlags, -- cgit v1.2.3