Skip to content

Instantly share code, notes, and snippets.

@equalent
Last active July 21, 2019 05:19
Show Gist options
  • Save equalent/213779e8edca8e0c15afd10400f88324 to your computer and use it in GitHub Desktop.
Save equalent/213779e8edca8e0c15afd10400f88324 to your computer and use it in GitHub Desktop.
Check DirectX Raytracing support [WITH COMMENTS]
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;
}
// Copyright (c) 2019 Antinomy Interactive. All rights reserved.
// PURPOSE: Check for DXR support
// AUTHOR: Andrey Tsurkan (andrey.turcan@hotmail.com)
#include <iostream>
#include <windows.h>
#include <dxgi.h>
#include <d3d12.h>
#include <wrl.h>
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d12.lib")
using namespace Microsoft::WRL;
// 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()
{
ComPtr<IDXGIFactory1> pFactory;
ComPtr<IDXGIAdapter1> pAdapter;
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&pFactory)))) {
std::cout << "Unable to create IDXGIFactory1!\n";
return 1;
}
HRESULT hr = pFactory->EnumAdapters1(0, &pAdapter);
if (FAILED(hr)) {
std::cout << "Unable to enumerate adapters!\n";
return 1;
}
if (IsDirectXRaytracingSupported(pAdapter.Get())) {
std::cout << "DirectX 12 Raytracing is supported!\n";
}
else {
std::cout << "DirectX 12 Raytracing is not supported!\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment