Skip to content

Commit

Permalink
[host] nvfbc: retry on failure to init
Browse files Browse the repository at this point in the history
@quantum has observed nvfbc under rare circumstances fail to initialize,
this adds a retry to the init with a short delay to hopefully recover
from this situation.
  • Loading branch information
gnif committed Dec 8, 2022
1 parent 60ac03e commit 8619f78
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions host/platform/Windows/capture/NVFBC/src/nvfbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,42 +316,54 @@ static bool nvfbc_init(void)
}

int adapterIndex = option_get_int("nvfbc", "adapterIndex");
// NOTE: Calling this on hardware that doesn't support NvFBC such as GeForce
// causes a substantial performance pentalty even if it fails! As such we only
// attempt NvFBC as a last resort, or if configured via the app:capture
// option.
if (adapterIndex < 0)

bool created = false;
for(int retry = 0; retry < 2; ++retry)
{
IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION);
int adapterCount = IDirect3D9_GetAdapterCount(d3d);
for(int i = 0; i < adapterCount; ++i)
// NOTE: Calling this on hardware that doesn't support NvFBC such as GeForce
// causes a substantial performance pentalty even if it fails! As such we only
// attempt NvFBC as a last resort, or if configured via the app:capture
// option.
if (adapterIndex < 0)
{
D3DADAPTER_IDENTIFIER9 ident;
IDirect3D9_GetAdapterIdentifier(d3d, i, 0, &ident);
if (ident.VendorId != 0x10DE)
continue;

if (NvFBCToSysCreate(i, privData, privDataLen, &this->nvfbc,
&this->maxWidth, &this->maxHeight))
IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION);
int adapterCount = IDirect3D9_GetAdapterCount(d3d);
for(int i = 0; i < adapterCount; ++i)
{
adapterIndex = i;
break;
D3DADAPTER_IDENTIFIER9 ident;
IDirect3D9_GetAdapterIdentifier(d3d, i, 0, &ident);
if (ident.VendorId != 0x10DE)
continue;

if (NvFBCToSysCreate(i, privData, privDataLen, &this->nvfbc,
&this->maxWidth, &this->maxHeight))
{
adapterIndex = i;
created = true;
break;
}
}
IDirect3D9_Release(d3d);
}
IDirect3D9_Release(d3d);

if (adapterIndex < 0)
else
{
free(privData);
return false;
if (!NvFBCToSysCreate(adapterIndex, privData, privDataLen, &this->nvfbc, &this->maxWidth, &this->maxHeight))
continue;
created = true;
}

if (created)
break;

//10ms delay before retry
nsleep(10000000);
}

if (!created)
{
free(privData);
return false;
}
else
if (!NvFBCToSysCreate(adapterIndex, privData, privDataLen, &this->nvfbc, &this->maxWidth, &this->maxHeight))
{
free(privData);
return false;
}

int diffRes = option_get_int("nvfbc", "diffRes");
enum DiffMapBlockSize blockSize;
Expand Down

0 comments on commit 8619f78

Please sign in to comment.