doitsujin / dxvk

Vulkan-based implementation of D3D8, 9, 10 and 11 for Linux / Wine
zlib License
13.14k stars 846 forks source link

Feature Request: no VRAM access for game launchers #3356

Closed emansom closed 1 month ago

emansom commented 1 year ago

Currently certain game launchers (Epic, Rockstar) eat up quite a lot of VRAM and this hurts gaming performance.

It'd be beneficial if DXVK didn't allow these apps to allocate any VRAM, as it would allow games to swap between BAR space less when VRAM usage is above a certain threshold.

Especially on low-end and mid-range GPUs this'd help a ton.

doitsujin commented 1 year ago

This sounds like a really gross band-aid for memory management problems on (current) NV drivers.

Reason why I don't like it is because a) there's nothing in a game launcher that tells us it's a game launcher, so we'd need to keep weird random app hacks around for every single one, and b) doing this is likely going to be highly problematic on systems with low PCI-E bandwidth (or high latency), e.g. external GPUs which already suffer quite badly with DXVK.

misyltoad commented 1 year ago

The Rockstar Launcher uses swiftshader anyway on Proton, doesn't it?

Blisto91 commented 1 year ago

Not that i can tell no. But i think that is besides the original point anyway.

mbriar commented 1 year ago

This sounds like a really gross band-aid for memory management problems on (current) NV drivers.

I don't know why you think it's only an issue on nvidia? VRAM spilling behavior on AMD is also catastrophically bad, especially on RADV since https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6833, see https://gitlab.freedesktop.org/mesa/mesa/-/issues/8763 for some of the context.

The Rockstar Launcher uses swiftshader anyway on Proton, doesn't it?

Doesn't look like it's on the list: https://github.com/ValveSoftware/wine/blob/6f2e9039c530927b37c49e10a963af17ca36095d/dlls/kernelbase/process.c#L593

For what it's worth, you could kind of do your own workaround without any code changes by setting d3d9,dxgi,d3d11 to build-in in winecfg for only the launcher.exe, and then launching with LIBGL_ALWAYS_SOFTWARE=1 to use software rendering for any launchers using D3D or OpenGL. Nvidia might also need __GLX_VENDOR_LIBRARY_NAME set to something, can't say I've tested that.

emansom commented 1 year ago

For what it's worth, you could kind of do your own workaround without any code changes by setting d3d9,dxgi,d3d11 to build-in in winecfg for only the launcher.exe, and then launching with LIBGL_ALWAYS_SOFTWARE=1 to use software rendering for any launchers using D3D or OpenGL.

Great tip! Can't get this to work with Rockstar's Launcher though, it won't launch the game.

Hadrianneue commented 1 year ago

@emansom wow dude you read my mind, i was just about to post this, this is already possible actually but with one caveat...

@doitsujin most launchers use OPENGL and LIBGL_ALWAYS_SOFTWARE=1 does prevent using VRAM, but as mentioned by OP Rockstar game launcher uses directx which brings us to DXVK_FILTER_DEVICE_NAME = llvmpipe

which works beautifully on red dead redemption 2, because you can run the game with Vulkan, however you can't do the same for GTA V since you be running the whole thing with llvmpipe.

So the obvious thing to do here is to just pass that environment variable to just the game launcher, i think that is possible with mesa workarounds, i'll try it right now, but since DXVK already provides a solution i guess WINE itself *could provide this option then?

EDIT: not possible on /usr/share/drirc.d/00-radv-defaults.conf or /usr/share/drirc.d/00-mesa-defaults.conf out of the box and adding more dri options to this effect would go out of the scope of mesa i would guess (though it would be nice to be able to set which device to use there with stuff like RADV_FORCE_FAMILY...)

emansom commented 2 months ago

Has there been any progress on this in the larger ecosystem? Is there a method implemented to banish a certain app to BAR/system RAM allocation only?

Or is this already transparently happening?

When playing GTA V with two launchers open (Epic Games Store and Rockstar Game Launcher) through Wine GE on GNOME, VRAM is going up to around 5.5GB.

This is what is reported by MangoHud on a RX 580 using RADV.

I find this a little high on 1440p with Medium in-game settings but not entirely positive it paints the whole picture.

I'd like to have the game launchers not eat up VRAM, as then hopefully there'll be more left for both GTA V and a few Firefox windows.

Blisto91 commented 2 months ago

From the side dxvk at least there have only been progress in the sense that we have set dxvk.maxChunkSize to the minimum value for a few launchers. https://github.com/doitsujin/dxvk/blob/e2b823b760775a2dd48727b76997ee888ba664cf/src/util/config/config.cpp#L404

Lowering the chunk size to 1 means the launchers will only get allocated vram in 1MB chunks. The default is 256 which can lead to some fragmentation in that we can end up allocating more vram per time if the app doesn't use a lot and therefore doesn't request a lot.

Is the Epic Games Store launcher you talk about the Windows version? If so we can add it to the list

emansom commented 2 months ago

From the side dxvk at least there have only been progress in the sense that we have set dxvk.maxChunkSize to the minimum value for a few launchers.

Awesome!

Is the Epic Games Store launcher you talk about the Windows version? If so we can add it to the list

That'd be highly appreciated. Thanks!

Yes. The Windows version running within Wine-GE.

When running ps aux | grep -i epic the following process names show up:

C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\..\..\..\Portal\Binaries\Win64\EpicGamesLauncher.exe

C:/Program Files (x86)/Epic Games/Launcher/Engine/Binaries/Win64/EpicWebHelper.exe

The WebHelper seems (from its command line arguments) to be a embedded Chromium browser.

Blisto91 commented 2 months ago

Coolio. Doing a quick short test locally i think it can save up to 700-900MB between the two processes

Edit: You can download the master build with it included here https://github.com/doitsujin/dxvk/actions/runs/10228182978

emansom commented 2 months ago

Coolio. Doing a quick short test locally i think it can save up to 700-900MB between the two processes

Edit: You can download the master build with it included here https://github.com/doitsujin/dxvk/actions/runs/10228182978

Tested. Can confirm it shaves 500MB from total VRAM usage: from 5.5GB to 5GB. 🙌

That means more VRAM for Firefox! Thanks!

doitsujin commented 1 month ago

Changed some memory allocation logic, should help with launchers a bunch.

emansom commented 1 month ago

Can confirm the new allocation logic behaves the same as the max chunk workaround before. 🥳