mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
26.69k stars 2.83k forks source link

HDR broken on AMD using vulkan #13534

Open Silver-Fullbuster opened 4 months ago

Silver-Fullbuster commented 4 months ago

Important Information

Provide following Information:

Reproduction steps

  1. Use any reference HDR video, say test.webm from a youtube HDR video
  2. mpv --no-config --vo=gpu-next --gpu-api=d3d11 --target-colorspace-hint test.webm (works after going fullscreen)
  3. mpv --no-config --vo=gpu-next --gpu-api=vulkan --target-colorspace-hint test.webm (no HDR here)

Expected behavior

Monitor switches into HDR and video plays with HDR

Actual behavior

mpv starts tonemapping the video instead, on vulkan

Log file

broken.txt works.txt

Andarwinux commented 4 months ago
[   0.080][v][vo/gpu-next/libplacebo] Available surface configurations:
[   0.080][v][vo/gpu-next/libplacebo]     0: VK_FORMAT_R8G8B8A8_UNORM                 VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
[   0.080][v][vo/gpu-next/libplacebo]     1: VK_FORMAT_B8G8R8A8_UNORM                 VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
[   0.080][v][vo/gpu-next/libplacebo]     2: VK_FORMAT_R8G8B8A8_SRGB                  VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
[   0.080][v][vo/gpu-next/libplacebo]     3: VK_FORMAT_B8G8R8A8_SRGB                  VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
[   0.080][v][vo/gpu-next/libplacebo] Picked surface configuration 0: VK_FORMAT_R8G8B8A8_UNORM + VK_COLOR_SPACE_SRGB_NONLINEAR_KHR

Your log indicates that the driver does not expose any HDR10_ST2084_EXT colorspace surfaces. So it's not a mpv problem.

The possible reason is that you don't have monitor directly connected to dGPU, for CASO, Intel AMD NV Vulkan driver don't support HDR at all, but Direct3D driver doesn't have this problem. The only solution is to use the DXGI swapchain instead of Vulkan WSI, ref #12539. You should stick to d3d11, nowadays winvk and vulkan hwdec don't work well on Windows.

Silver-Fullbuster commented 4 months ago

Okay, my monitor is directly connected to the dGPU but it sounds like a driver issue (?). I've tried using the same monitor through my laptop and with its Nvidia dGPU, vulkan works fine with HDR.

I'm sticking with d3d11 currently, if it's indeed a driver/AMD problem then I don't mind having this issue closed.

Silver-Fullbuster commented 4 months ago

Adding some additional investigation results:

Upon turning on Windows HDR, HDR on vulkan works, but it sometimes doesn't take over the HDR colorspace rendering(?):

Reproduction Steps

  1. Turn on Windows HDR
  2. mpv --no-config --vo=gpu-next --gpu-api=vulkan --target-colorspace-hint test.webm
  3. Fullscreen, otherwise colors are weird

Log file: working_run_logs.txt Log file: failed_hdr_takeover_run.txt

Going fullscreen is flaky, sometimes the HDR colorspace applies properly, sometimes everything's way too dark. I tested it with a test pattern video and I think it sometime gives up on using an HDR colorspace and keeps tonemapping everything back to SDR.

Also, no matter HDR or not, toggling fullscreen often causes a crash with vulkan. I don't see any errors in the logs, probably due to some internal crash + it's unrelated to this issue so I'll try to recreate the crash with gdb attached later and create a separate issue for that

EDIT: Disabling all overlays does indeed apply HDR correctly

Andarwinux commented 4 months ago

Logs don't seem to be abnormal, mpv selected VK_FORMAT_A2B10G10R10_UNORM_PACK32 + VK_COLOR_SPACE_HDR10_ST2084_EXT. Flaky HDR brightness could be normal, HDR metadata is only sent to monitor if it's full screen and the OSD isn't visible, otherwise it'll use default metadata.

I'll try to recreate the crash with gdb attached later and create a separate issue for that

Shinchiro builds have been changed to distribute pdb debugging symbols so can't use gdb. You need to install Windbg from MS Store to debug mpv.

kasper93 commented 4 months ago

I'll try to recreate the crash with gdb attached later and create a separate issue for that

You can just share the crash dump from %LOCALAPPDATA%\CrashDumps and related mpv build. It is enough to diagnose the issue.

Silver-Fullbuster commented 4 months ago

While creating the issue for the crash, I found out that mpv doesn't crash with RivaTunerStatistics OSD disabled. RTS OSD hooks into GPU-rendered apps and it shows some system information as a permanent overlay, and it somehow interfered with mpv when mpv tries to go Fullscreen.

tl;dr: mpv seems fine on that end. Probably a 3rd-party overlay bug

If someone is interested in the dmp files anyway, here they are: mpv.exe.crash_on_rts_overlay_fullscreen_toggle_dumps.zip

EDIT: and it only crashes on gpu-api=vulkan, gpu-api=d3d11 has no issues with the overlay

EDIT 2: And disabling the RTS OSD also makes HDR apply properly much less flakier on vulkan,

lextra2 commented 2 months ago

https://github.com/mpv-player/mpv/issues/13780#issuecomment-2035371393

Also, turn off RTSS