Last active
July 21, 2019 08:06
-
-
Save equalent/8b93aa4604fa44c79c82810e61f90ee1 to your computer and use it in GitHub Desktop.
Full code for DXR check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright (c) 2019 Antinomy Interactive. All rights reserved. | |
| // PURPOSE: Check for DXR support | |
| // AUTHOR: Andrey Tsurkan (andrey.turcan@hotmail.com) | |
| #include <iostream> | |
| #include <sstream> | |
| #include <string> | |
| #include <windows.h> | |
| #include <dxgi.h> | |
| #include <d3d12.h> | |
| #include <wrl.h> | |
| using namespace Microsoft::WRL; | |
| #pragma comment(lib, "dxgi.lib") | |
| #pragma comment(lib, "d3d12.lib") | |
| // https://gist.github.com/equalent/213779e8edca8e0c15afd10400f88324 | |
| inline bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter) | |
| { | |
| ComPtr<ID3D12Device> testDevice; | |
| D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureSupportData = {}; | |
| // create Direct3D 12 device with 11.0 FL | |
| // IID_PPV_ARGS automatically computes interface ID (REFIID that equals to IID_ID3D12Device) | |
| // and the pointer and passes them as two comma-separated arguments | |
| return SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&testDevice))) | |
| // check support for OPTIONS5 (will work only on Windows 10 1803+) | |
| // https://docs.microsoft.com/ru-ru/windows/win32/api/d3d12/ne-d3d12-d3d12_feature | |
| && SUCCEEDED(testDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &featureSupportData, sizeof(featureSupportData))) | |
| // verify that raytracing is supported | |
| // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_d3d12_options5 | |
| // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_raytracing_tier | |
| && featureSupportData.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED; | |
| } | |
| int main() | |
| { | |
| HRESULT hr = CoInitialize(NULL); | |
| if (FAILED(hr)) { | |
| std::cout << "Unable to initialize COM+!"; | |
| return 1; | |
| } | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Loading D3D12.DLL...\n"); | |
| #endif | |
| HINSTANCE dynamicLib = LoadLibraryW(L"d3d12.dll"); | |
| if (dynamicLib == NULL) | |
| { | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Unable to load D3D12.DLL!\n"); | |
| #endif | |
| std::cout << "DirectX 12 is not supported on this device!\n"; | |
| return 1; | |
| } | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Unloading D3D12.DLL...\n"); | |
| #endif | |
| FreeLibrary(dynamicLib); | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"First DXGI call will happen NOW!\n"); | |
| #endif | |
| ComPtr<IDXGIFactory1> pFactory; | |
| ComPtr<IDXGIAdapter1> pAdapter; | |
| if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&pFactory)))) { | |
| std::cout << "Unable to create IDXGIFactory1!\n"; | |
| return 1; | |
| } | |
| hr = pFactory->EnumAdapters1(0, &pAdapter); | |
| if (FAILED(hr)) { | |
| std::cout << "Unable to enumerate adapters!\n"; | |
| return 1; | |
| } | |
| DXGI_ADAPTER_DESC1 desc = {}; | |
| pAdapter->GetDesc1(&desc); | |
| std::wcout << L"Grapics card: " << desc.Description << L"\n"; | |
| std::wostringstream woss; | |
| woss << "DirectX 12 Raytracing Support Check for "; | |
| woss << desc.Description; | |
| SetConsoleTitleW(woss.str().c_str()); | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"First D3D12 call will happen NOW!\n"); | |
| #endif | |
| if (IsDirectXRaytracingSupported(pAdapter.Get())) { | |
| std::cout << "DirectX 12 Raytracing is supported!\n"; | |
| MessageBoxW(NULL, L"DirectX 12 Raytracing is supported!", desc.Description, MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); | |
| } | |
| else { | |
| std::cout << "DirectX 12 Raytracing is not supported!\n"; | |
| MessageBoxW(NULL, L"DirectX 12 Raytracing is not supported!", desc.Description, MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); | |
| } | |
| CoUninitialize(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright (c) 2019 Antinomy Interactive. All rights reserved. | |
| // PURPOSE: Check for DXR support | |
| // AUTHOR: Andrey Tsurkan (andrey.turcan@hotmail.com) | |
| #include <iostream> | |
| #include <sstream> | |
| #include <string> | |
| #include <windows.h> | |
| #include <dxgi.h> | |
| #include <d3d12.h> | |
| #include <wrl.h> | |
| using namespace Microsoft::WRL; | |
| #pragma comment(lib, "dxgi.lib") | |
| #pragma comment(lib, "d3d12.lib") | |
| // https://gist.github.com/equalent/213779e8edca8e0c15afd10400f88324 | |
| inline bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter) | |
| { | |
| ComPtr<ID3D12Device> testDevice; | |
| D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureSupportData = {}; | |
| // create Direct3D 12 device with 11.0 FL | |
| // IID_PPV_ARGS automatically computes interface ID (REFIID that equals to IID_ID3D12Device) | |
| // and the pointer and passes them as two comma-separated arguments | |
| return SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&testDevice))) | |
| // check support for OPTIONS5 (will work only on Windows 10 1803+) | |
| // https://docs.microsoft.com/ru-ru/windows/win32/api/d3d12/ne-d3d12-d3d12_feature | |
| && SUCCEEDED(testDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &featureSupportData, sizeof(featureSupportData))) | |
| // verify that raytracing is supported | |
| // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_d3d12_options5 | |
| // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_raytracing_tier | |
| && featureSupportData.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED; | |
| } | |
| int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int) | |
| { | |
| HRESULT hr = CoInitialize(NULL); | |
| if (FAILED(hr)) { | |
| MessageBoxW(NULL, L"Unable to initialize COM+!", L"DXR TEST", MB_OK | MB_ICONERROR | MB_DEFAULT_DESKTOP_ONLY); | |
| return 1; | |
| } | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Loading D3D12.DLL...\n"); | |
| #endif | |
| HINSTANCE dynamicLib = LoadLibraryW(L"d3d12.dll"); | |
| if (dynamicLib == NULL) | |
| { | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Unable to load D3D12.DLL!\n"); | |
| #endif | |
| MessageBoxW(NULL, L"DirectX 12 is not supported on this device!", L"DXR TEST", MB_OK | MB_ICONERROR | MB_DEFAULT_DESKTOP_ONLY); | |
| return 1; | |
| } | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"Unloading D3D12.DLL...\n"); | |
| #endif | |
| FreeLibrary(dynamicLib); | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"First DXGI call will happen NOW!\n"); | |
| #endif | |
| ComPtr<IDXGIFactory1> pFactory; | |
| ComPtr<IDXGIAdapter1> pAdapter; | |
| if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&pFactory)))) { | |
| MessageBoxW(NULL, L"Unable to create IDXGIFactory1!", L"DXR TEST", MB_OK | MB_ICONERROR | MB_DEFAULT_DESKTOP_ONLY); | |
| return 1; | |
| } | |
| hr = pFactory->EnumAdapters1(0, &pAdapter); | |
| if (FAILED(hr)) { | |
| MessageBoxW(NULL, L"Unable to enumarate adapters!", L"DXR TEST", MB_OK | MB_ICONERROR | MB_DEFAULT_DESKTOP_ONLY); | |
| return 1; | |
| } | |
| DXGI_ADAPTER_DESC1 desc = {}; | |
| pAdapter->GetDesc1(&desc); | |
| std::wostringstream woss; | |
| woss << "DirectX 12 Raytracing Support Check for "; | |
| woss << desc.Description; | |
| #ifdef _DEBUG | |
| OutputDebugStringW(L"First D3D12 call will happen NOW!\n"); | |
| #endif | |
| if (IsDirectXRaytracingSupported(pAdapter.Get())) { | |
| std::cout << "DirectX 12 Raytracing is supported!\n"; | |
| MessageBoxW(NULL, L"DirectX 12 Raytracing is SUPPORTED!", woss.str().c_str(), MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); | |
| } | |
| else { | |
| std::cout << "DirectX 12 Raytracing is not supported!\n"; | |
| MessageBoxW(NULL, L"DirectX 12 Raytracing is NOT SUPPORTED!", woss.str().c_str(), MB_OK | MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY); | |
| } | |
| CoUninitialize(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment