| 54 | } |
| 55 | |
| 56 | void Initialize(D3D_FEATURE_LEVEL minFeatureLevel) |
| 57 | { |
| 58 | ShuttingDown = false; |
| 59 | |
| 60 | HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&Factory)); |
| 61 | if(FAILED(hr)) |
| 62 | throw Exception(L"Unable to create a DXGI 1.4 device.\n " |
| 63 | L"Make sure that your OS and driver support DirectX 12"); |
| 64 | |
| 65 | // Just use the first adapter for now |
| 66 | uint32 adapterIdx = 0; |
| 67 | LARGE_INTEGER umdVersion = { }; |
| 68 | Factory->EnumAdapters1(adapterIdx, &Adapter); |
| 69 | |
| 70 | if(Adapter == nullptr) |
| 71 | throw Exception(L"Unable to locate a DXGI 1.4 adapter that supports a D3D12 device.\n" |
| 72 | L"Make sure that your OS and driver support DirectX 12"); |
| 73 | |
| 74 | #if UseDebugDevice_ |
| 75 | ID3D12DebugPtr d3d12debug; |
| 76 | DXCall(D3D12GetDebugInterface(IID_PPV_ARGS(&d3d12debug))); |
| 77 | d3d12debug->EnableDebugLayer(); |
| 78 | #endif |
| 79 | |
| 80 | DXCall(D3D12CreateDevice(Adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&Device))); |
| 81 | |
| 82 | // Check the maximum feature level, and make sure it's above our minimum |
| 83 | D3D_FEATURE_LEVEL featureLevelsArray[4]; |
| 84 | featureLevelsArray[0] = D3D_FEATURE_LEVEL_11_0; |
| 85 | featureLevelsArray[1] = D3D_FEATURE_LEVEL_11_1; |
| 86 | featureLevelsArray[2] = D3D_FEATURE_LEVEL_12_0; |
| 87 | featureLevelsArray[3] = D3D_FEATURE_LEVEL_12_1; |
| 88 | D3D12_FEATURE_DATA_FEATURE_LEVELS featureLevels = { }; |
| 89 | featureLevels.NumFeatureLevels = ArraySize_(featureLevelsArray); |
| 90 | featureLevels.pFeatureLevelsRequested = featureLevelsArray; |
| 91 | DXCall(Device->CheckFeatureSupport(D3D12_FEATURE_FEATURE_LEVELS, &featureLevels, sizeof(featureLevels))); |
| 92 | FeatureLevel = featureLevels.MaxSupportedFeatureLevel; |
| 93 | |
| 94 | if(FeatureLevel < minFeatureLevel) |
| 95 | { |
| 96 | std::wstring majorLevel = ToString<int>(minFeatureLevel >> 12); |
| 97 | std::wstring minorLevel = ToString<int>((minFeatureLevel >> 8) & 0xF); |
| 98 | throw Exception(L"The device doesn't support the minimum feature level required to run this sample (DX" + majorLevel + L"." + minorLevel + L")"); |
| 99 | } |
| 100 | |
| 101 | #if UseDebugDevice_ |
| 102 | ID3D12InfoQueuePtr infoQueue; |
| 103 | DXCall(Device->QueryInterface(IID_PPV_ARGS(&infoQueue))); |
| 104 | |
| 105 | D3D12_MESSAGE_ID disabledMessages[] = |
| 106 | { |
| 107 | D3D12_MESSAGE_ID_CLEARRENDERTARGETVIEW_MISMATCHINGCLEARVALUE, |
| 108 | |
| 109 | // These happen when capturing with VS diagnostics |
| 110 | D3D12_MESSAGE_ID_MAP_INVALID_NULLRANGE, |
| 111 | D3D12_MESSAGE_ID_UNMAP_INVALID_NULLRANGE, |
| 112 | }; |
| 113 |
no test coverage detected