protonscr

Video playback in Age of Empires II HD breaks d3d9 rendering

dxvkclosed appid 2013d3d9
doitsujin/dxvk#1726 · opened 2020-08-14 by aeikum · updated 2023-04-08 · 13 comments · github · game page · search this game
Aaeikum 2020-08-14 github

In AOE2:HD, if you have functional video playback, then DXVK's d3d9 rendering is broken. In v1.7, the video blinks rapidly. In v1.7.1, the video appears stretched and corrupted. In both cases, the main menu of the game doesn't render (i.e. the DXVK HUD FPS counter is blank; no rendering). With wined3d, the video and game render just fine. Wine's quartz implementation is using d3d9 to render, see dlls/quartz/vmr9.c.

Since I know getting video playback set up is a pain, I'm including as much info here as I can. I'm happy to provide more info or test patches, etc.

Software information

Age of Empires II HD (2013) (steam game id 221380)

System information

  • GPU: Nvidia GTX 970
  • Driver: 450.57
  • Wine version: 5.13
  • DXVK version: v1.7.1

Apitrace file(s)

wined3d (correct) apitrace: https://smokingonabike.com/AoK HD wined3d.trace.xz
dxvk (incorrect) apitrace: https://smokingonabike.com/AoK HD dxvk.trace.xz

Log files

Aaeikum 2020-08-14 github

Here's what the video looks like in DXVK v1.7.1.

Screenshot_2020-08-14_12-52-44

Mmisyltoad 2020-08-16 github

So it uses the format YV12 in the WineD3D trace, however we don't support that so it tries to use YUY2 in the DXVK trace.

It seems the YUY2 data that gets uploaded is garbage, same with how it is when replaying the trace on native for me.
Maybe this is a problem in Wine's quartz impl that needs to be looked into, or the game doing something wrong?

Anyway, I've implemented YV12. Please let me know if this works on your end.

Aaeikum 2020-08-17 github

Thanks. I built that branch (v1.7.1-2-g7e0bb971). The ConvertFormat warning is gone and the video no longer flickers, however the colors are incorrect and the game's main menu still does not render.

AoK-dxvk-branch

Mmisyltoad 2020-08-17 github

@aeikum Is there anything special I need to do to get the video to play?

I tried in proton_5.0-next and it just skipped over the video and went straight to the main menu (which worked) for me.

Mmisyltoad 2020-08-17 github

So, the main menu worked before the video thing worked.

The problem is you're creating multiple swapchains/surfaces for a window, this is a big no-no in Vulkan, but it should be possible to fix.

Mmisyltoad 2020-08-17 github

Hm, perhaps not. This is happening on another d3d9 instance and another d3d9 device.

The primary vulkan swapchain from the game still thinks everything is okay and it can present and even returns VK_SUCCESS.

I'm not super sure what to do about that given I have 0 information... :-/


Anyway, I fixed the YV12 rendering at least. I'll need to have a think about the swapchain dilemma, I'm not sure if this is something I can work around, or if I can work around it in Wine or maybe the driver is wrong for thinking everything is okay.

Aaeikum 2020-09-28 github

Just curious, any further thoughts on this? Do we know where the problem is?

PPlagman 2020-12-18 github

@Joshua-Ashton

Mmisyltoad 2021-01-08 github

I have tested this on Windows with DXVK and it works fine there.

On Windows in D3D9, you can have multiple swapchains on the same window.

The problem is that technically this is illegal in the Vulkan spec -- but it seems to just work on Windows too?

__
In WineX11, I would recommend wrapping the swapchain object, tracking ownership of swapchain->window, and make sure whoeever wants to present at a given time has the ownership. If they don't currently own the swapchain, return VK_OUT_OF_DATE_KHR on present and make them re-make the swapchain (and therefore update the ownership) when that happens.

Whoever creates a swapchain for a window last should be the "owner".


We should eventually write a VALVE extension that we enable all the time to make things spec-positive here. I can take that part once we know this works.

Nnsivov 2021-07-16 github

Another game that needs YUY2 in d3d9 path is Mary Skelter: Nightmares. It's using mediafoundation for intro video, with EVR renderer, that goes through dxva2. YUY2 is a main planar format there as I understand, at least for software devices. Winegstreamer is already able to output in YUY2, but that needs a hack to trigger + some smaller patches that are waiting to be included for mainline wine. Let me know if there is interest to test this, I can provide more info then.

Aaeikum 2021-10-20 github

As we're getting more videos online, we're running into this problem more often. Any hope of a workaround?

Aaeikum 2021-10-26 github

Rémi actually had some fixes for this in one of his trees. We've backported his work to 6.3 and it fixes AOE2 and some other affected games. It works by allowing multiple surfaces & swapchains per window, and rendering offscreen if multiple surfaces are active.

I've pushed this to my repo and it'll be in Experimental soon: https://github.com/aeikum/wine/commit/08db7c206acb691a3f9eb94c46cc3d3342c06a88

KK0bin maintainer 2023-04-08 github

This has been working for some time now.

Proton versions