doitsujin / dxvk

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

Unreal Tournament 2004: Shader compilation stutter #3534

Open K0bin opened 1 year ago

K0bin commented 1 year ago

Unreal Tournament 2004 (with D3D8to9 or D8VK) suffers from shader compilation stutters. DXVK generates a lot of fixed function vertex shaders. Additionally the game has a queue sync every frame, which naturally means that we also synchronize with the CS thread. So each shader compilation stalls both threads making it even worse.

A possible solution would be to move our generated fixed function shaders more towards uber-shaders and handle multiple versions in one shader.

Software information

Unreal Tournament 2004

System information

Apitrace file(s)

https://drive.google.com/file/d/1dTbqCiJL8AJESJWZZsJNliCZvV0tc4Cl/view?usp=sharing

Log files

I made it print out the 4 uint32_t words of the FF VS key. shader_compilation_log.txt

WinterSnowfall commented 1 year ago

Most likely related: https://github.com/AlpyneDreams/d8vk/issues/165

It's also using UE2, and arguably the stuttering is nowhere near as bad as it is in UT2004, but it's there. It's probably more evident in single player.

K0bin commented 1 year ago

According to Josh it's mostly down to TexcoordFlags, TransformFlags and TexcoordDeclMask.

netborg-afps commented 1 year ago

This eliminates stutters almost completely, but has rendering artifacts on the HUD: https://github.com/doitsujin/dxvk/compare/master...netborg-afps:dxvk:2023_06_fixing_ut2004_stutters

Not sure if this is a fix or a hack? Edit: Seems like I forgot that Vertex Shader and Pixel Shader are part of the Pipeline definition, so this obviously is a hack.

What I also found out is that Pipeline compilation did take at most 0.5 ms in most cases and 30 ms very rarely (OK, that seems to be because of nvidia cache).

netborg-afps commented 1 year ago

Because my previous hack made me confident the game is actually largely stutter-free when moving some variables to the shader, I made a real fix last week. In case someone wants to play UT2004, or any UE2 game via dxvk, the fix is available here: https://github.com/netborg-afps/dxvk/tree/2023_06_fixing_ut2004_stutters

The disadvantage of the fix though is that vertex shader compile times roughly doubled, so the only true solution which works for all games would be a single uber-shader which wouldn't need to be compiled at runtime.

adolfintel commented 5 months ago

Still an issue unfortunately :disappointed:

netborg-afps commented 4 months ago

Still an issue unfortunately 😞

Have you tried my fix? Unfortunately, this won't get into upstream because it slows down other games, but it allows you to play this game largely stutter-free.

adolfintel commented 4 months ago

@netborg-afps I did and it's better than regular dxvk, but not really a stutter-free experience, especially at the beginning of the game. Other UE2 games like Postal 2 20th anniversary are still a very stuttery experience and basically unplayable :cry: