Skip to content
Snippets Groups Projects
Commit ca975750 authored by James Ross-Gowan's avatar James Ross-Gowan
Browse files

d3d11/context: fix device creation retries and log error code on failure

Older versions of the Direct3D 11 runtime return an error code from
D3D11CreateDevice when they don't recognise one of the requested feature
levels. Previously, we'd try to work around those errors by retrying
device creation with a smaller set of feature levels, but since we did
that regardless of the error code, when device creation failed for
reasons other than invalid feature levels, we'd still try creating the
device up to 6 times, and we'd never actually log the error code until
the last attempt, which might have failed for a different reason.

These unnecessary retries could also be especially annoying under Wine,
which can log debug messages for every failed attempt.

When D3D11CreateDevice fails due to unrecognised feature levels, it
returns E_INVALIDARG, so only adjust the feature levels on E_INVALIDARG.
When falling back to the WARP driver, log the error code. That way we
always know the error code when device creation fails, and we eliminate
some unnecessary retries.
parent bfd5b3a1
Branches master
No related tags found
No related merge requests found
......@@ -207,9 +207,8 @@ static ID3D11Device *create_device(struct pl_d3d11 *d3d11,
// Trying to create a D3D_FEATURE_LEVEL_12_0 device on Windows 8.1 or
// below will not succeed. Try an 11_1 device.
if (max_fl >= D3D_FEATURE_LEVEL_12_0 &&
min_fl <= D3D_FEATURE_LEVEL_11_1)
{
if (hr == E_INVALIDARG && max_fl >= D3D_FEATURE_LEVEL_12_0 &&
min_fl <= D3D_FEATURE_LEVEL_11_1) {
PL_DEBUG(ctx, "Failed to create 12_0+ device, trying 11_1");
max_fl = D3D_FEATURE_LEVEL_11_1;
continue;
......@@ -217,9 +216,8 @@ static ID3D11Device *create_device(struct pl_d3d11 *d3d11,
// Trying to create a D3D_FEATURE_LEVEL_11_1 device on Windows 7
// without the platform update will not succeed. Try an 11_0 device.
if (max_fl >= D3D_FEATURE_LEVEL_11_1 &&
min_fl <= D3D_FEATURE_LEVEL_11_0)
{
if (hr == E_INVALIDARG && max_fl >= D3D_FEATURE_LEVEL_11_1 &&
min_fl <= D3D_FEATURE_LEVEL_11_0) {
PL_DEBUG(ctx, "Failed to create 11_1+ device, trying 11_0");
max_fl = D3D_FEATURE_LEVEL_11_0;
continue;
......@@ -227,7 +225,8 @@ static ID3D11Device *create_device(struct pl_d3d11 *d3d11,
// Retry with WARP if allowed
if (!adapter && !warp && params->allow_software) {
PL_DEBUG(ctx, "Failed to create hardware device, trying WARP");
PL_DEBUG(ctx, "Failed to create hardware device, trying WARP: %s",
pl_hresult_to_str(hr));
warp = true;
max_fl = params->max_feature_level;
min_fl = params->min_feature_level;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment