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

Disable nvapi/nvapi64 by default #165

Closed
AccountOneOff opened this issue Aug 22, 2018 · 9 comments
Closed

Disable nvapi/nvapi64 by default #165

AccountOneOff opened this issue Aug 22, 2018 · 9 comments

Comments

@AccountOneOff
Copy link

AccountOneOff commented Aug 22, 2018

Doitsujin recommends disabling nvapi/nvapi64 when using DXVK but Proton does not set this override. The Flame in the Flood runs at 18fps in the menu because of this and at 60fps with nvapi disabled. I haven't tested in-game yet.

Log: steam-318600.zip

screenshot from 2018-08-22 13-56-53

@romulasry
Copy link

Great idea!

@kode54
Copy link

kode54 commented Aug 27, 2018

Maybe this is related to #336 ? Can someone tell me how to disable nvapi/nvapi64 to test this with that? It only runs full speed in wine-staging, which doesn't have dxvk.

E: Tested, unrelated. Does not fix #336.

Incidentally, nvapi/nvapi64 is what makes it possible for PhysX to work on NVidia Linux drivers, but that's the extent that the implementation provides. I guess it doesn't work too well while running Vulkan?

@kisak-valve
Copy link
Member

UE4 games constantly searches for nvapi64.dll/nvapi64.dll.so

Issue transferred from #1290.
@lieff posted on 2018-09-06T22:15:08:

Form #1178 and doitsujin/dxvk#622 (comment) .
It seems one of UE4 threads do constant directory scan in search of nvapi64.dll/nvapi64.dll.so

stat(".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows/system32/nvapi64.dll", 0x171be330) = -1 ENOENT (No such file or directory)
stat(".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat(".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows/system32", {st_mode=S_IFDIR|0775, st_size=49152, ...}) = 0
stat(".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows/system32/nvapi64.dll", 0x171be3c0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, ".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows/system32", O_RDONLY|O_DIRECTORY) = 4529
ioctl(4529, VFAT_IOCTL_READDIR_BOTH, 0x121000) = -1 ENOTTY (Inappropriate ioctl for device)
close(4529)                             = 0
openat(AT_FDCWD, ".../SteamLibrary/steamapps/compatdata/414340/pfx/dosdevices/c:/windows/system32", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4529
fstat(4529, {st_mode=S_IFDIR|0775, st_size=49152, ...}) = 0
getdents(4529, /* 799 entries */, 32768) = 32752 << directory scan in inner loop!
getdents(4529, /* 86 entries */, 32768) = 3632
getdents(4529, /* 0 entries */, 32768)  = 0
close(4529)                             = 0

What affects performance.

@lieff
Copy link

lieff commented Sep 6, 2018

Can confirm, no UE4 directory scans with nvapi/nvapi64 disabled.

@lieff
Copy link

lieff commented Sep 7, 2018

I've checked Unreal source. Problem seems in D3D11RHI module.
There lot of code under IsRHIDeviceNVIDIA() check to handle SLI etc which uses NvAPI_* from nvapi.lib/nvapi64.lib. Even with disabled nvapi it still tries LoadLibrary("nvapi.dll").
If game do not calls FD3D11Texture3D too often disable nvapi approach helps, but if it uses even very simple function often in inner loop - even with disabled nvapi this path can decrease performance.
So nvapi stub or fake AMD card is better solution.

This can be fixed in UE as well. We just can transform checks from

if (IsRHIDeviceNVIDIA())
{
    NvAPI_call()->
    {
        if (!g_lib)
            g_lib = LoadLibrary("nvapi.dll");
        ...call from dll
    }
}

to

static bool GNVAPIChecked = false;
static bool GNVAPIAvailable = false;

bool IsNVAPIAvailable()
{
    if (GNVAPIChecked)
        return GNVAPIAvailable;
    if (IsRHIDeviceNVIDIA() && NVAPI_Loads())
        GNVAPIAvailable = true;
    GNVAPIChecked = true;
}

if (IsNVAPIAvailable())
{
    NvAPI_call()->
    {
        if (!g_lib)
            g_lib = LoadLibrary("nvapi.dll");
        ...call from dll
    }
}

@jarrard
Copy link

jarrard commented Sep 7, 2018

what happens if we just grab nvapi dll's and toss it in the desired path? will it just continue without issue?

@pchome
Copy link
Contributor

pchome commented Sep 8, 2018

Could it help if we'll have nvapi fake-dlls in system32 and syswow64 directories, and nvapi disabled?

Fake dlls can be generated quite simple, e.g. :

$ winebuild -m64 --dll --fake-module -o nvapi64.dll
$ winebuild -m32 --dll --fake-module -o nvapi.dll

Wine looking for requested dll wherever possible before "Load Order" logic will act (see load_dll and find_dll_file).

Disabling nvapi should prevent further searching for builtin nvapi.dll.so, or any actions with nvapi.dll as real dll file, and will return STATUS_DLL_NOT_FOUND immediately.

For UE4 result will be the same, but the way should be shorter.

@pchome
Copy link
Contributor

pchome commented Sep 12, 2018

An hack for proton+nvapi.

Enable/disable nvapi w/ PROTON_USE_NVAPI variable.

@pchome
Copy link
Contributor

pchome commented Sep 13, 2018

And you can build nvapi only, w/o needing to build/install wine-staging.

@aeikum
If you plan to include nvapi in Proton, this example can help you to integrate it in current Proton build process.
As well as hack mentioned above. Both of them together can behave same as DXVK in Proton.

Also there is an option (meson configure -Denable_d3d11=false) to build nvapi using only wined3d, which can be used for PROTON_NO_D3D11=1 needs (or even for DXVK, not sure).

I'm going to use those hacks locally for my own needs, but hope they will be useful to solve nvapi issues in Proton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants