Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When creating the device, use the one with the most video memory. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions Common/d3dApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,24 +411,43 @@ bool D3DApp::InitDirect3D()
}
#endif

Microsoft::WRL::ComPtr<ID3D12Device> pDevice;
Microsoft::WRL::ComPtr<IDXGIAdapter1> pAdapter;

SIZE_T biggestSize = 0;
Microsoft::WRL::ComPtr<IDXGIAdapter1> pBiggestAdapter;

DXGI_ADAPTER_DESC1 desc;

ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&mdxgiFactory)));

// Try to create hardware device.
HRESULT hardwareResult = D3D12CreateDevice(
nullptr, // default adapter
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&md3dDevice));
// Find the adapter with largest video memory in case we have multiple different adapters, like on some laptops.
for (uint32_t Idx = 0; DXGI_ERROR_NOT_FOUND != mdxgiFactory->EnumAdapters1(Idx, &pAdapter); ++Idx)
{
pAdapter->GetDesc1(&desc);
// We don't want software adapters.
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
continue;
}
if (desc.DedicatedVideoMemory > biggestSize)
{
pBiggestAdapter = pAdapter;
biggestSize = desc.DedicatedVideoMemory;
}
}

// Fallback to WARP device.
if(FAILED(hardwareResult))
// Try to create the device, require DirectX 12 support.
if (SUCCEEDED(D3D12CreateDevice(pBiggestAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&pDevice))))
{
ComPtr<IDXGIAdapter> pWarpAdapter;
ThrowIfFailed(mdxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&pWarpAdapter)));
md3dDevice = pDevice;
}

ThrowIfFailed(D3D12CreateDevice(
pWarpAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&md3dDevice)));
// Fallback to WARP device.
if (md3dDevice == nullptr)
{
ThrowIfFailed(mdxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&pAdapter)));
ThrowIfFailed(D3D12CreateDevice(pAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&md3dDevice)));
}

ThrowIfFailed(md3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
Expand Down