diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-03-30 03:05:30 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-03-30 03:05:30 +0000 |
| commit | b0b568e32e854a720e97e1085151f54c7e62f047 (patch) | |
| tree | 8d3d99becd2b835ed247e4c90f38c6409287aab3 /Graphics/GraphicsEngineD3D11 | |
| parent | Implemented hardware adapter and display mode enumeration (diff) | |
| download | DiligentCore-b0b568e32e854a720e97e1085151f54c7e62f047.tar.gz DiligentCore-b0b568e32e854a720e97e1085151f54c7e62f047.zip | |
Implemented option to specify hardware adapter when initializing the engine in d3d mode
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
| -rw-r--r-- | Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h | 5 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp | 23 |
2 files changed, 24 insertions, 4 deletions
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<ID3D11Device> pd3d11Device; CComPtr<ID3D11DeviceContext> pd3d11Context; + CComPtr<IDXGIAdapter1> 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, |
