Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Created October 18, 2019 13:28
Show Gist options
  • Save ryutorion/a71272e7dd5abd47c51400bc3f07e73b to your computer and use it in GitHub Desktop.
Save ryutorion/a71272e7dd5abd47c51400bc3f07e73b to your computer and use it in GitHub Desktop.
// IDXGIFactory7は生成済み
ComPtr<IDXGIFactory7> p_factory;
// 実際にはグローバル変数ではなく,何らかのメンバ変数など
D3D_FEATURE_LEVEL minimum_feature_level = D3D_FEATURE_LEVEL_12_0;
ComPtr<ID3D12Device6> p_device;
ComPtr<IDXGIAdapter4> p_adapter;
bool selectAdapter()
{
for(
uint32_t i = 0;
p_factory->EnumAdapterByGpuPreference(i, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&p_adapter) != DXGI_ERROR_NOT_FOUND;
++i
)
{
DXGI_ADAPTER_DESC3 adapter_desc;
HRESULT hr = p_adapter->GetDesc3(&adapter_desc);
if(FAILED(hr) || (adapter_desc.Flags & DXGI_ADAPTER_FLAG3_SOFTWARE))
{
continue;
}
hr = D3D12CreateDevice(
p_adapter.Get(),
minimum_feature_level,
__uuidof(*&p_device),
nullptr
);
if(SUCCEEDED(hr))
{
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment