このサイトのSample/Desktop/D3D12Raytracingを主に参考にしてDirectX12のレイトレーシングについて勉強しています。
レイトレーシングをサポートしているかチェックするコードを
サンプルから抽出して書いてみたのですが”IsDirectXRaytracingSupported”関数内の
featureSupportData.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
がfalseになります。
プロジェクトの設定が違うのかなと思い上記のサンプル内に新しいプロジェクトを作りまったく同じコードを書いたところ
featureSupportData.RaytracingTier が D3D12_RAYTRACING_TIER_1_0となり機能しました。
なのでソースコード自体はあっていると思うのですがどういった設定が必要なのかわかりません。
解決方法があれば教えてください。
C++
1static const UINT FrameCount = 3; 2const static size_t MAX_BACK_BUFFER_COUNT = 3; 3 4static const unsigned int c_AllowTearing = 0x1; 5static const unsigned int c_RequireTearingSupport = 0x2; 6 7Microsoft::WRL::ComPtr<IDXGIFactory4> m_dxgiFactory; 8Microsoft::WRL::ComPtr<IDXGIAdapter1> m_adapter; 9D3D_FEATURE_LEVEL m_d3dMinFeatureLevel; 10std::wstring m_adapterDescription; 11UINT m_adapterIDoverride; 12UINT m_adapterID = UINT_MAX; 13 14 15void InitializeAdapter(IDXGIAdapter1** ppAdapter); 16bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter); 17 18 19int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 20{ 21 m_adapterIDoverride = m_adapterID; 22 UINT backBufferCount = FrameCount; 23 24 if (backBufferCount > MAX_BACK_BUFFER_COUNT) 25 { 26 return -1; 27 } 28 29 D3D_FEATURE_LEVEL minFeatureLevel = D3D_FEATURE_LEVEL_11_0; 30 m_d3dMinFeatureLevel = minFeatureLevel; 31 32 if (minFeatureLevel < D3D_FEATURE_LEVEL_11_0) 33 { 34 return -1; 35 } 36 unsigned int m_options = c_RequireTearingSupport; 37 38 if (m_options & c_RequireTearingSupport) 39 { 40 m_options |= c_AllowTearing; 41 } 42 43 44 ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&m_dxgiFactory))); 45 46 47 if (m_options & (c_AllowTearing | c_RequireTearingSupport)) 48 { 49 BOOL allowTearing = FALSE; 50 51 ComPtr<IDXGIFactory5> factory5; 52 HRESULT hr = m_dxgiFactory.As(&factory5); 53 if (SUCCEEDED(hr)) 54 { 55 hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing)); 56 } 57 58 if (FAILED(hr) || !allowTearing) 59 { 60 OutputDebugStringA("WARNING: Variable refresh rate displays are not supported.\n"); 61 if (m_options & c_RequireTearingSupport) 62 { 63 ThrowIfFailed(false, L"Error: Sample must be run on an OS with tearing support.\n"); 64 } 65 m_options &= ~c_AllowTearing; 66 } 67 } 68 69 InitializeAdapter(&m_adapter); 70 IsDirectXRaytracingSupported(m_adapter.Get()); 71} 72 73 74void InitializeAdapter(IDXGIAdapter1** ppAdapter) 75{ 76 *ppAdapter = nullptr; 77 78 ComPtr<IDXGIAdapter1> adapter; 79 ComPtr<IDXGIFactory6> factory6; 80 HRESULT hr = m_dxgiFactory.As(&factory6); 81 if (FAILED(hr)) 82 { 83 return; 84 } 85 for (UINT adapterID = 0; DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference(adapterID, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter)); ++adapterID) 86 { 87 if (m_adapterIDoverride != UINT_MAX && adapterID != m_adapterIDoverride) 88 { 89 continue; 90 } 91 92 DXGI_ADAPTER_DESC1 desc; 93 ThrowIfFailed(adapter->GetDesc1(&desc)); 94 95 if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { 96 continue; 97 } 98 99 if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), m_d3dMinFeatureLevel, _uuidof(ID3D12Device), nullptr))) 100 { 101 m_adapterID = adapterID; 102 m_adapterDescription = desc.Description; 103 104#ifdef _DEBUG 105 wchar_t buff[256] = {}; 106 swprintf_s(buff, L"Direct3D Adapter (%u): VID:%04X, PID:%04X - %ls\n", adapterID, desc.VendorId, desc.DeviceId, desc.Description); 107 OutputDebugStringW(buff); 108 109 //出力 Direct3D Adapter (0): VID:10DE, PID:1C03 - NVIDIA GeForce GTX 1060 6GB 110#endif 111 112 break; 113 } 114 } 115 116#if !defined(NDEBUG) 117 if (!adapter && m_adapterIDoverride == UINT_MAX) 118 { 119 if (FAILED(m_dxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&adapter)))) 120 { 121 return; 122 } 123 124 OutputDebugStringA("Direct3D Adapter - WARP12\n"); 125 } 126#endif 127 128 if (!adapter) 129 { 130 if (m_adapterIDoverride != UINT_MAX) 131 { 132 return; 133 } 134 else 135 { 136 return; 137 } 138 } 139 140 *ppAdapter = adapter.Detach(); 141} 142 143 144bool IsDirectXRaytracingSupported(IDXGIAdapter1* adapter) 145{ 146 ComPtr<ID3D12Device> testDevice; 147 D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureSupportData = {}; 148 149 bool b = SUCCEEDED(D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&testDevice))); 150 b &= SUCCEEDED(testDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &featureSupportData, sizeof(featureSupportData))); 151 b &= featureSupportData.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED; 152 return b; 153}
あなたの回答
tips
プレビュー