| 55 | } |
| 56 | |
| 57 | void Device::CreateDevice() { |
| 58 | UINT dxgiFactoryFlags = 0; |
| 59 | |
| 60 | // Validation |
| 61 | #ifndef NDEBUG |
| 62 | { |
| 63 | ComPtr <ID3D12Debug> debugController; |
| 64 | |
| 65 | // Debug controller present? |
| 66 | if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { |
| 67 | debugController->EnableDebugLayer(); |
| 68 | |
| 69 | // Enable additional debug layers. |
| 70 | dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG; |
| 71 | } |
| 72 | } |
| 73 | #endif // NDEBUG |
| 74 | |
| 75 | // Create factory |
| 76 | ComPtr <IDXGIFactory4> factory; |
| 77 | REQUIRE(SUCCEEDED(CreateDXGIFactory2(dxgiFactoryFlags, IID_PPV_ARGS(&factory)))); |
| 78 | |
| 79 | // Revision 6? |
| 80 | ComPtr <IDXGIFactory6> factory6; |
| 81 | if (SUCCEEDED(factory->QueryInterface(IID_PPV_ARGS(&factory6)))) { |
| 82 | for (UINT i = 0; SUCCEEDED(factory6->EnumAdapterByGpuPreference(i, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter))); ++i) { |
| 83 | DXGI_ADAPTER_DESC1 desc; |
| 84 | adapter->GetDesc1(&desc); |
| 85 | |
| 86 | if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { |
| 87 | continue; |
| 88 | } |
| 89 | |
| 90 | if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) { |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // None available? |
| 97 | if (adapter.Get() == nullptr) { |
| 98 | for (UINT i = 0; SUCCEEDED(factory->EnumAdapters1(i, &adapter)); ++i) { |
| 99 | DXGI_ADAPTER_DESC1 desc; |
| 100 | adapter->GetDesc1(&desc); |
| 101 | |
| 102 | if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) { |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Pass down the environment |
| 113 | D3D12_DEVICE_GPUOPEN_GPU_RESHAPE_INFO gpuOpenInfo{}; |
| 114 | gpuOpenInfo.registry = registry; |
no test coverage detected