gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.69k stars 930 forks source link

Long startup time #3332

Closed truchi closed 1 year ago

truchi commented 1 year ago

Hello !

Description Startup time painfully long.

Repro steps cargo run --example <any example> Same in bevy.

Expected vs observed behavior 10s of non responding window.

Extra materials

$ cargo r -q --example mipmap
<10 sec here>
MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0

Using Intel(R) UHD Graphics (TGL GT1) (Vulkan)
<...>

Platform Ubuntu 20.04.5 LTS Just cloned wgpu

$ glxinfo | grep -i vendor
server glx vendor string: SGI
client glx vendor string: Mesa Project and SGI
    Vendor: Intel (0x8086)
OpenGL vendor string: Intel

$ lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Intel Corporation Device 9a60 (rev 01)
    DeviceName: Onboard - Video
    Subsystem: Dell Device 0a62
    Kernel driver in use: i915
--
01:00.0 3D controller: NVIDIA Corporation Device 25b8 (rev a1)
    Subsystem: Dell Device 0a62
    Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
02:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd Device a80a

This must be an issue with my system. I am trying to play around with bevy. I hope you can help me!

Thank you, Happy christmas 🎄

nical commented 1 year ago

Could you profile the startup (using perf or some other performance profiling tool) and report where the time is spent?

truchi commented 1 year ago

Hello, Thanks for your reply !

First thing, I upgraded my system packages and the MESA-INTEL: warning: ... went away! Also I noticed the logging: it hangs on [INFO boids::framework] Initializing the surface.... With warn:

<during the freeze> [WARN  wgpu_hal::vulkan::instance] Unable to find layer: VK_LAYER_KHRONOS_validation
<after the freeze> [WARN  wgpu_hal::gles::adapter] Detected skylake derivative running on mesa i915. Clears to srgb textures will use manual shader clears.

First time using perf :) perf version 5.14.21. I added debuginfo-level = 1 to the boids [[example]] section in wgpu/Cargo.toml (not so sure this is the right place), and process::exit() right before the event loop. Running:

$ sudo perf record ./target/release/examples/boids # Complains about paranoia without sudo 

gives a non-utf8 file and firefox profiler is not happy about that. So here we go:

$ sudo perf report
Samples: 1K of event 'cycles', Event count (approx.): 745409699
Overhead  Command       Shared Object                     Symbol
   8,86%  boids         [kernel.kallsyms]                 [k] acpi_ns_search_one_scope
   7,23%  boids         [kernel.kallsyms]                 [k] pci_conf1_read
   3,55%  boids         [kernel.kallsyms]                 [k] acpi_ex_system_memory_space_handler
   3,43%  boids         [kernel.kallsyms]                 [k] acpi_os_read_port
   1,99%  boids         [kernel.kallsyms]                 [k] zap_pte_range.isra.0
   1,30%  boids         libX11.so.6.3.0                   [.] XGetVisualInfo
   1,27%  boids         libX11.so.6.3.0                   [.] 0x000000000006973a
   1,21%  boids         libc-2.31.so                      [.] 0x000000000018bb41
   1,21%  boids         [kernel.kallsyms]                 [k] acpi_ut_track_stack_ptr
   1,17%  boids         [kernel.kallsyms]                 [k] unix_stream_read_generic
   1,14%  boids         [kernel.kallsyms]                 [k] copy_page
   1,07%  boids         ld-2.31.so                        [.] 0x000000000000e314
   0,92%  modprobe      ld-2.31.so                        [.] 0x00000000000233c5
   0,85%  modprobe      libc-2.31.so                      [.] __uflow
   0,85%  boids         [kernel.kallsyms]                 [k] acpi_ds_clear_implicit_return
   0,84%  boids         [kernel.kallsyms]                 [k] security_vm_enough_memory_mm
   0,81%  boids         [kernel.kallsyms]                 [k] clear_page_erms
   0,77%  boids         [kernel.kallsyms]                 [k] next_uptodate_page
   0,76%  boids         libc-2.31.so                      [.] _IO_fgets
   0,74%  boids         [kernel.kallsyms]                 [k] acpi_ps_next_parse_state
   0,72%  boids         libX11.so.6.3.0                   [.] _XVIDtoVisual
   0,72%  boids         ld-2.31.so                        [.] 0x000000000000e2f9
   0,71%  boids         [kernel.kallsyms]                 [k] _raw_spin_lock_irqsave
   0,71%  boids         [kernel.kallsyms]                 [k] copy_pte_range.isra.0
   0,69%  boids         libc-2.31.so                      [.] 0x00000000001838ad
   0,68%  boids         libX11.so.6.3.0                   [.] _XrmInternalStringToQuark
   0,66%  boids         [kernel.kallsyms]                 [k] __kmalloc
   0,62%  boids         libX11.so.6.3.0                   [.] 0x0000000000068833
   0,61%  boids         [kernel.kallsyms]                 [k] sync_regs
   0,58%  boids         [kernel.kallsyms]                 [k] native_irq_return_iret
   0,56%  boids         [kernel.kallsyms]                 [k] m_show
   0,56%  boids         libX11.so.6.3.0                   [.] 0x0000000000019044
   0,55%  boids         [kernel.kallsyms]                 [k] _raw_spin_lock
   0,52%  boids         [kernel.kallsyms]                 [k] rmqueue_bulk
   0,51%  boids         libc-2.31.so                      [.] 0x0000000000076bae
   0,48%  boids         libnvidia-eglcore.so.470.161.03   [.] 0x0000000000d91ce2
   0,44%  boids         libGLX_nvidia.so.470.161.03       [.] strcspn@plt
   0,44%  boids         [kernel.kallsyms]                 [k] copy_user_enhanced_fast_string
   0,43%  boids         ld-2.31.so                        [.] 0x000000000000b7b5
   0,43%  boids         ld-2.31.so                        [.] 0x000000000000e311
   0,42%  boids         [kernel.kallsyms]                 [k] mutex_unlock
   0,40%  boids         libc-2.31.so                      [.] _dl_addr
   0,39%  boids         libGLX_nvidia.so.470.161.03       [.] 0x0000000000084292
   0,39%  boids         ld-2.31.so                        [.] 0x000000000000b58f
   0,38%  boids         ld-2.31.so                        [.] 0x000000000000b7bf
   0,38%  boids         [kernel.kallsyms]                 [k] page_remove_rmap
   0,37%  boids         [kernel.kallsyms]                 [k] __slab_free
   0,37%  boids         [kernel.kallsyms]                 [k] strncpy
   0,35%  boids         [kernel.kallsyms]                 [k] kmem_cache_free
   0,34%  boids         [kernel.kallsyms]                 [k] kmem_cache_alloc
   0,32%  boids         [kernel.kallsyms]                 [k] release_pages
   0,32%  boids         [kernel.kallsyms]                 [k] __pagevec_lru_add
   0,31%  boids         ld-2.31.so                        [.] 0x000000000000c131
   0,30%  boids         ld-2.31.so                        [.] 0x000000000000de5b
   0,30%  boids         ld-2.31.so                        [.] 0x000000000000b596
   0,30%  boids         [kernel.kallsyms]                 [k] memset_erms
   0,28%  boids         [kernel.kallsyms]                 [k] native_flush_tlb_one_user
   0,28%  boids         [kernel.kallsyms]                 [k] __check_object_size
   0,28%  boids         [kernel.kallsyms]                 [k] native_queued_spin_lock_slowpath
   0,27%  boids         libc-2.31.so                      [.] 0x00000000001838c0
   <-- snipped, has a ton more -->

I hope you can make sense out of this!

ErichDonGubler commented 1 year ago

For context, OP has also filed a related question on /r/rust.

truchi commented 1 year ago

Fixed it.

Removed all nvidia drivers. Re-installed with sudo ubuntu-drivers autoinstall. In Ubuntu's Software & Updates, chosing driver metapackage instead of driver (open kernel) metapackage (this might be the real issue).

pixels/tiny-skia example still weird (freezes when mouse moves, close not working).

teoxoy commented 1 year ago

Fixed it.

I think we can close this for now.

pixels/tiny-skia example still weird (freezes when mouse moves, close not working).

We don't seem to have those examples in our codebase. Please open new issues for those with more context since they sound like different issues than this one.