mpv-player / mpv

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

Slow startup when using `gpu-api = vulkan` on Windows with NVIDIA #13019

Open GrzegorzKozub opened 8 months ago

GrzegorzKozub commented 8 months ago

Important Information

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:

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.

kasper93 commented 8 months ago

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.

Goosegit11 commented 5 months ago

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