mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Slow startup when using `gpu-api = vulkan` with NVIDIA

Open GrzegorzKozub opened this issue 3 years ago • 11 comments

Important Information

  • Source of the mpv binary: https://sourceforge.net/projects/mpv-player-windows/files/
  • mpv version: mpv-x86_64-v3-20231126-git-6898d57.7z
  • Relevant hardware spec: AMD Ryzen 9 5900X, NVIDIA GeForce RTX 3080
  • Windows version: 11 23H2 22631.2715
  • NVIDIA driver version: 546.17

Reproduction steps

Run on Windows with NVIDIA and setup mpv to use Vulkan as GPU API. This is my config file:

vo = gpu-next
hwdec = nvdec or vulkan
gpu-api = vulkan

Expected behavior

The player starts without a delay.

Actual behavior

The player takes about 2 seconds to start and there are reports of delays when creating Vulkan instance and device:

[vo/gpu-next/libplacebo] Spent 1037.710 ms creating vulkan instance (slow!)
[vo/gpu-next/libplacebo] Spent 350.304 ms creating vulkan device (slow!)

When does it NOT happen

Tested on multiple machines and OS. This does NOT happen in the following situations:

  • When running on Linux with AMD using Wayland with the config above
  • When running on Windows with AMD with the config above
  • When running on Linux with NVIDIA using X11 with the config above
  • When running on Windows with NVIDIA (same setup as with the issue) but NOT using Vulkan, for example:
vo = gpu-next
hwdec = nvdec
gpu-api = opengl
gpu-context = win

Log file

The relevant part of the log file (also attached as output.txt):

[vo/gpu-next/vulkan] Initializing GPU context 'winvk'
[vo/gpu-next/libplacebo] Initialized libplacebo v6.338.0-60-g795600a-dirty (API v342)
[vo/gpu-next/libplacebo] Spent 93.897 ms enumerating instance extensions
[vo/gpu-next/libplacebo] Creating vulkan instance with extensions:
[vo/gpu-next/libplacebo]     VK_KHR_get_physical_device_properties2
[vo/gpu-next/libplacebo]     VK_KHR_surface
[vo/gpu-next/libplacebo]     VK_EXT_swapchain_colorspace
[vo/gpu-next/libplacebo]     VK_KHR_external_memory_capabilities
[vo/gpu-next/libplacebo]     VK_KHR_external_semaphore_capabilities
[vo/gpu-next/libplacebo]     VK_KHR_get_surface_capabilities2
[vo/gpu-next/libplacebo]     VK_KHR_portability_enumeration
[vo/gpu-next/libplacebo]     VK_KHR_surface
[vo/gpu-next/libplacebo]     VK_KHR_win32_surface
[vo/gpu-next/libplacebo] Spent 1037.710 ms creating vulkan instance (slow!)
[vo/gpu-next/libplacebo] Probing for vulkan devices:
[vo/gpu-next/libplacebo]     GPU 0: NVIDIA GeForce RTX 3080 v1.3.260 (discrete)
[vo/gpu-next/libplacebo]            uuid: F7:9C:C7:F0:2E:57:EB:B3:87:B4:E8:95:88:06:06:BF
[vo/gpu-next/libplacebo] Vulkan device properties:
[vo/gpu-next/libplacebo]     Device Name: NVIDIA GeForce RTX 3080
[vo/gpu-next/libplacebo]     Device ID: 10de:2206
[vo/gpu-next/libplacebo]     Device UUID: F7:9C:C7:F0:2E:57:EB:B3:87:B4:E8:95:88:06:06:BF
[vo/gpu-next/libplacebo]     Driver version: 88844000
[vo/gpu-next/libplacebo]     API version: 1.3.260
[vo/gpu-next/libplacebo] Using async transfer (queue 1)
[vo/gpu-next/libplacebo] Using async compute (queue 2)
[vo/gpu-next/libplacebo] Creating vulkan device with extensions:
[vo/gpu-next/libplacebo]     VK_KHR_swapchain
[vo/gpu-next/libplacebo]     VK_KHR_swapchain
[vo/gpu-next/libplacebo]     VK_KHR_push_descriptor
[vo/gpu-next/libplacebo]     VK_KHR_external_memory_win32
[vo/gpu-next/libplacebo]     VK_EXT_external_memory_host
[vo/gpu-next/libplacebo]     VK_KHR_external_semaphore_win32
[vo/gpu-next/libplacebo]     VK_EXT_pci_bus_info
[vo/gpu-next/libplacebo]     VK_EXT_hdr_metadata
[vo/gpu-next/libplacebo]     VK_EXT_full_screen_exclusive
[vo/gpu-next/libplacebo]     VK_EXT_descriptor_buffer
[vo/gpu-next/libplacebo]     VK_EXT_shader_atomic_float
[vo/gpu-next/libplacebo]     VK_KHR_video_decode_queue
[vo/gpu-next/libplacebo]     VK_KHR_video_decode_h264
[vo/gpu-next/libplacebo]     VK_KHR_video_decode_h265
[vo/gpu-next/libplacebo]     VK_KHR_video_queue
[vo/gpu-next/libplacebo] Spent 350.304 ms creating vulkan device (slow!)

Sample files

This issue is irrelevant of the media file used.

GrzegorzKozub avatar Dec 02 '23 06:12 GrzegorzKozub

It is unfortunate but this time is spent fully in vkCreateInstance and vkCreateDevice, which is outside our control. We don't even request that much extensions.

I've looked at this few months ago, nothing really we can do. On AMD the init time is significantly faster, still noticeable, but clearly not as bad as in your case.

vo/gpu-next/libplacebo: Spent 5.893 ms enumerating instance layers
vo/gpu-next/libplacebo: Spent 68.399 ms enumerating instance extensions
vo/gpu-next/libplacebo: Spent 35.837 ms creating vulkan instance
vo/gpu-next/libplacebo: Spent 23.900 ms creating vulkan device

Only way is to complain to NVIDIA, but I wouldn't get your hopes high.

As a sanity check you can run mpv with higher verbosity (-v) and observe Available layers: to see if something is hiding there, but I doubt. Especially that both device and instance is taking long for you.

kasper93 avatar Dec 02 '23 08:12 kasper93

I ran into the same problem on GNU/Linux, X11, NVIDIA

Info

Provide following Information:

  • mpv version
mpv v0.37.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
 built on Jan 19 2024 09:09:45
libplacebo version: v6.338.2
FFmpeg version: n6.1.1
FFmpeg library versions:
   libavutil       58.29.100
   libavcodec      60.31.102
   libavformat     60.16.100
   libswscale      7.5.100
   libavfilter     9.12.100
   libswresample   4.12.100
  • Linux Distribution and Version

Linux arch 6.6.21-x64v3-xanmod1-1-lts-clang-v3 #1 SMP PREEMPT_DYNAMIC Thu, 07 Mar 2024 12:57:11 +0000 x86_64 GNU/Linux

  • Source of the mpv binary

Arch Linux Repository

  • If known which version of mpv introduced the problem

  • Window Manager and version

Cinnamon 6.0.4

  • GPU model, driver and version

NVIDIA GTX 1650 nvidia-dkms 550.54.14-5

perdakovich avatar Mar 17 '24 14:03 perdakovich

As this is still reproducible on Linux and Windows and only affects nvidia I've removed os:win and added down-upstream:nvidia.

Traneptora avatar Mar 24 '25 14:03 Traneptora

It's not only nvidia, I am facing the same slow startup with AMD and mpv v0.40.0 on Arch Linux

[vo/gpu/libplacebo] Spent 3761.001 ms enumerating physical devices (slow!)

Here is the log.txt

With --gpu-api=opengl instead vulkan, it works great.

munzirtaha avatar Mar 27 '25 15:03 munzirtaha

May be an issue with mesa or placebo, but atm I've removed the down-upstream nvidia tag if this is reproducible on AMD.

Traneptora avatar Apr 25 '25 09:04 Traneptora

The AMD issue is already tracked in some other issue, it's not related to this.

For AMD (and seemingly all Mesa Vulkan drivers), the problem is enumerating devices wakes up devices if they're in sleep or otherwise inactive. https://gitlab.freedesktop.org/mesa/mesa/-/issues/11383

For Nvidia, the slow enumeration is a problem even with only 1 GPU that's not in any kind of sleep or low power mode. I'd suggest keeping the Nvidia tag, as the AMD issue is already tracked elsewhere. https://github.com/mpv-player/mpv/issues/16218

llyyr avatar Apr 25 '25 12:04 llyyr

The AMD issue is already tracked in some other issue, it's not related to this.

For AMD (and seemingly all Mesa Vulkan drivers), the problem is enumerating devices wakes up devices if they're in sleep or otherwise inactive. https://gitlab.freedesktop.org/mesa/mesa/-/issues/11383

and https://gitlab.freedesktop.org/mesa/mesa/-/issues/12972

For Nvidia, the slow enumeration is a problem even with only 1 GPU that's not in any kind of sleep or low power mode. I'd suggest keeping the Nvidia tag, as the AMD issue is already tracked elsewhere. #16218

Yes, those are different issues. In this (#13019) enumerating devices is not a problem Spent 0.569 ms enumerating physical devices. Creating Vulkan instance and devices is the problem and this is only issue on NVIDIA.

kasper93 avatar Apr 25 '25 12:04 kasper93

For me, I get:

vo/gpu-next/libplacebo: Spent 306.020 ms creating vulkan device (slow!)

Log: output.txt

vo=gpu-next
gpu-api=vulkan
hwdec=nvdec
mpv 'E:\test\Jujutsu Kaisen S02E03.mkv' --no-config --gpu-debug --log-file=E:\output.txt --vo=gpu-next --gpu-api=vulkan --hwdec=nvdec
mpv v0.41.0-90-gb7e8fe949 Copyright © 2000-2026 mpv/MPlayer/mplayer2 projects
 built on Jan 19 2026 00:07:45
libplacebo version: v7.358.0 (v7.351.0-145-g1dcaea8-dirty)
FFmpeg version: N-122481-g737953968
FFmpeg library versions:
   libavcodec      62.23.102
   libavdevice     62.2.100
   libavfilter     11.10.101
   libavformat     62.8.102
   libavutil       60.23.100
   libswresample   6.2.100
   libswscale      9.3.100
- Windows version: Windows 11 Pro 25H2
- GPU model, driver and version: RTX 5070, driver version 591.74
- CPU: Ryzen 9800X3D
- Source of mpv: shinchiro (git)

Samillion avatar Jan 22 '26 09:01 Samillion

Additionally, using hwdec=vulkan

[   0.150][v][vo/gpu-next/libplacebo] Spent 122.317 ms enumerating instance extensions (slow!)
[   0.549][v][vo/gpu-next/libplacebo] Spent 358.187 ms creating vulkan device (slow!)
mpv 'E:\test\Jujutsu Kaisen S02E03.mkv' --no-config --gpu-debug --log-file=E:\output.txt --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan

Log: output.txt

Samillion avatar Jan 22 '26 10:01 Samillion

I also experience this on FreeBSD 15.0 using PRIME with nvidia dGPU and Intel alder lake iGPU.

concussious avatar Feb 05 '26 17:02 concussious

This is also an issue for me

If i run with VK_DRIVER_FILES=/usr/share/vulkan/icd.d/radeon_icd.x86_64.json:/usr/share/vulkan/icd.d/radeon_icd.i686.json, which means it switches to my Radeon iGPU, its fine

but if i dont use anything, or use prime-run, which means run it /w my nvidia gpu, it does this thing [vo/gpu-next/libplacebo] Spent 1002.602 ms creating vulkan device (slow!)

GeForce RTX 4050 Max-Q / Mobile Radeon 680M KDE 6.6.5 wayland

Jeridonger avatar Jun 15 '26 11:06 Jeridonger