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

[d3d9] Majesty 2 woes with iGPUs and system memory heaps #1542

Closed
WinterSnowfall opened this issue Apr 1, 2020 · 10 comments · Fixed by #2612
Closed

[d3d9] Majesty 2 woes with iGPUs and system memory heaps #1542

WinterSnowfall opened this issue Apr 1, 2020 · 10 comments · Fixed by #2612

Comments

@WinterSnowfall
Copy link
Contributor

While trying to start Majesty 2 on a laptop with only 4GB of RAM (unfortunately not upgradable) and an iGPU, the game hangs on startup with the infamous: DxvkMemoryAllocator: Memory allocation failed exception.

I thought initially it's LAA related, but it's not. The game starts up and plays just fine if I use:

d3d9.maxAvailableMemory = 1024

A couple of other points:

  • This is a 2008 game, so expecting it to run on 4GB of RAM is not unreasonable
  • There's about 3GB of free RAM when the hang occurs
  • The game works fine on my other gaming system which has 32GB of RAM (hardly a surprise)
  • WineD3D handles itself ok (performance aside), the game starts as expected

I have a feeling this has the potential of opening a can of worms, but can anything be done to improve the memory allocation logic in such scenarios?

Software information

Majesty 2 (GOG version), others may be affected as well.

System information

  • GPU: Intel(R) UHD Graphics 605 (Geminilake)
  • Driver: 19.2.8
  • Wine version: 5.5 Staging
  • DXVK version: 1.6

Apitrace file(s)

N/A

Log files

@doitsujin
Copy link
Owner

doitsujin commented Apr 1, 2020

I'd say setting d3d9.maxAvailableMemory = 1024 is a reasonable workaround for systems with little memory. It's hard to say what exactly the game is doing, but if reporting a different amount of VRAM to the game fixes the issue, it's not really our fault.

d3d9.evictManagedOnUnlock = True might be another option to try.

DXVK is known to have very high memory overhead, it's not really possible to change that without a complete rewrite (and potentially sacrificing performance for memory efficiency). Memory efficiency was never really a goal since it started out as a 64-bit only D3D11 translation layer.

@WinterSnowfall
Copy link
Contributor Author

I'd say setting d3d9.maxAvailableMemory = 1024 is a reasonable workaround for systems with little memory. It's hard to say what exactly the game is doing, but if reporting a different amount of VRAM to the game fixes the issue, it's not really our fault.

Fair enough. I think the game's pre-loading a ton of stuff on startup, which is a bit weird anyway.

d3d9.evictManagedOnUnlock = True might be another option to try.

It doesn't help in terms of getting the game to not crash on startup and also tanks the framerate during gameplay (the hardware's somewhat maxed out anyway). The game will manage its memory well once it's started, so it doesn't really help here.

DXVK is known to have very high memory overhead, it's not really possible to change that without a complete rewrite (and potentially sacrificing performance for memory efficiency).

I thought as much, hence the can of worms I mentioned. Ok, got it and I'll close this, I just had to ask :). Thanks!

@WinterSnowfall WinterSnowfall changed the title [d3d9] DxvkMemoryAllocator woes with iGPUs and small heaps [d3d9] Majesty 2 woes with iGPUs and system memory heaps May 13, 2021
@WinterSnowfall
Copy link
Contributor Author

WinterSnowfall commented May 13, 2021

With new hardware comes new insight into old issues.

I've recently upgraded to an 8GB laptop with an Iris Xe-LP G7 iGPU and I'm still seeing the same behavior. It's the only game out of 30+ D3D9 games I've tried that has this problem, so it's not a system-specific or low heap memory problem, as I initially thought. It appears the game will reserve all the VRAM it possibly can + whatever RAM it needs for its 32-bit LAA-aware process. While this allocation logic works fine with dedicated GPUs, it eats up all available memory on iGPUs and causes the game to crash on startup.

Could you please add d3d9.maxAvailableMemory = 1024 as a permanent workaround for this game? I have confirmed it works on my new system as well. In fact 2048 and 3072 work as well, problems start around 4096 and above or with no value. However, considering this is a game from 2009 and the top tier GPUs at the time had either 512MB or 1GB VRAM, I think it's the value that makes most sense. I had no issues with it on several playthroughs.

Either way, there has to be a limit in place on systems with an iGPU or the game will not start with DXVK. I'm not sure how WineD3D works around what the game is doing to be honest... but it offers worse performance, so I also don't care that much.

As a last note, I've also tried d3d9.memoryTrackTest = True, but it makes no difference here.

Log files

@misyltoad
Copy link
Collaborator

Hm, I think we should maybe add maxAvailableMemory to something sane on iGPUs to avoid the "allocating all RAM" problem.

@WinterSnowfall
Copy link
Contributor Author

Fair point, but to be honest this is the only game I've ever had issues with. All other D3D9 stuff seems to behave nicely and NOT crunch on all they detect.

It's hard IMHO to determine what might be a sane limit using a hard cutoff value, unless you go for something dynamic like 30% of system RAM for example.

@misyltoad
Copy link
Collaborator

How much memory does your new laptop have out of curiosity?

@WinterSnowfall
Copy link
Contributor Author

WinterSnowfall commented May 13, 2021

8GB in total.

If my understanding is correct on how the heap size is calculated, having more RAM could potentially prevent the memory allocation error. But the game would still take up an unjustifiably large portion of RAM/VRAM.

@misyltoad
Copy link
Collaborator

Well, not if the game decides it wants to eat all of it if you're on UMA.

Maybe something like min(60%, 4GB) for UMA would be sensible

@WinterSnowfall
Copy link
Contributor Author

I'll be happy to test whatever you come up with and think is best :). But for this particular game the crashes started between 3GB and 4GB max VRAM, as I mentioned above.

@WinterSnowfall
Copy link
Contributor Author

WinterSnowfall commented May 13, 2021

While trying to narrow down the exact point on which the game breaks (just for fun), I noticed the following behavior: starting with d3d9.maxAvailableMemory = 3502 (wtf???), the game will "gracefully" show its own out of video memory message rather than crash directly. Further increasing the available memory up to 4096 will cause it to just crash without the error at some point.

mem_error

It clearly does not know how to handle more video memory than it's ever been designed for... at this point I'm intrigued by why it works on my GTX 1080. Ancient NUMA magic maybe.

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

Successfully merging a pull request may close this issue.

3 participants