Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Implement vulkan renderer #2771

Merged
merged 1 commit into from
Oct 18, 2021
Merged

Implement vulkan renderer #2771

merged 1 commit into from
Oct 18, 2021

Conversation

nyorain
Copy link
Contributor

@nyorain nyorain commented Mar 6, 2021

Reworked version of #1214, building upon the new wlr_allocator abstraction. A lot of the old discussion points have been resolved.

  • the renderer has a hard dependency on VK_EXT_image_drm_format_modifier. No undefined image importing hackery or linear image layouts anymore
  • the old wlr_render_surface concept is removed, vulkan integrates very well with the wlr_allocator concept :)
  • this does no API changes to wlroots at all
  • The vulkan renderer is an optional compile-time feature. Only if compiled with vulkan and if the WLR_RENDERER=vulkan environment variable is set, the vulkan renderer will be created by wlr_renderer_autocreate.
  • A couple of functions are currently not implemented: wlr_renderer_read_pixels, wlr_renderer_blit_dmabuf, wlr_texture_to_dmabuf (functions have been removed from wlroots). We can implement all of them but implementations would be poor, I would much rather propose interface changes to implement them efficiently, without completely blocking the compositor. These functions being unimplemented should only have an impact on multi-GPU support and wlr_screencopy_v1 not working under vulkan.
  • There are still a couple of smaller improvements noted in the code but nothing of this seems too important to me, it's mostly performance improvements or simplifications.
  • This support YCbCr textures (for shm as well as dmabuf texture importing) but I couldn't find a way to test that yet. It does not support rendering to such formats but I don't think that's ever needed.

As this isn't perfect and needs a lot of testing on all possible hardware, the renderer currently always enables the vulkan validation layers. You will need this patch as there were errors in the validation layers for VK_EXT_image_drm_format_modifier. You will need to build the vulkan validation layers from master as there was an error with validation of a used extension just fixed recently.
I tested this on an intel 8th gen GPU with the anv mesa MR (there isn't support for importing YCbCr dmabufs yet), using tinywl with the wayland and drm backend, running the sample weston-* applications as well as firefox and some GTK applications. Sadly, I don't have a >=GFX9 (vega) AMD GPU, and since radv already has support for the vulkan extension on those GPUs I'd be thankful for people testing it. Tests on any other driver/platform where the extension is available would certainly be useful as well.

If you can think of applications that this should be tested with, let me know (something that uses YCbCr shm buffers would be nice).

@David96
Copy link
Contributor

David96 commented Mar 8, 2021

Hey, I just tried to try out this PR. I have a Ryzen 3700U with vega graphics. But I failed to get it running. Having installed all the vulkan*-git and mesa-git packages on ArchLinux as well as the validation layers with your patch and libdrm-git, I get a MESA-LOADER: failed to open radeonsi: libLLVM-12.so: cannot open shared object file: No such file or directory (search paths /usr/lib/dri).

$ ll /usr/lib/dri/
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 i915_dri.so*
-rwxr-xr-x  4 root root  14M  2. Feb 11:12 i965_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 iris_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 kms_swrast_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 nouveau_dri.so*
-rwxr-xr-x  3 root root 9,8M  2. Feb 11:12 nouveau_drv_video.so*
-rwxr-xr-x  4 root root  14M  2. Feb 11:12 nouveau_vieux_dri.so*
-rwxr-xr-x  4 root root  14M  2. Feb 11:12 r200_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 r300_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 r600_dri.so*
-rwxr-xr-x  3 root root 9,8M  2. Feb 11:12 r600_drv_video.so*
-rwxr-xr-x  4 root root  14M  2. Feb 11:12 radeon_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 radeonsi_dri.so*
-rwxr-xr-x  3 root root 9,8M  2. Feb 11:12 radeonsi_drv_video.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 swrast_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 virtio_gpu_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 vmwgfx_dri.so*
-rwxr-xr-x 11 root root  22M  2. Feb 11:12 zink_dri.so*

So I think the radeonsi driver should be there 🤔

Do you have any ideas what I'm missing?

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

Do other gl/vulkan programs work for you? Try e.g. vulkaninfo. This sounds like a dependency issue on your system. I just had to compile mesa and the validation layers (which in turn require the spirv-tools-git, spirv-headers-git, vulkan-headers-git packages) from scratch.

@David96
Copy link
Contributor

David96 commented Mar 8, 2021

Ahh I think I found the issue, I install the git packages from chaotic-aur as building everything on the laptop is quite painful and it seems they built the last mesa-git package against llvm-libs v12, but llvm-libs is already v13. I'll try to get that working tomorrow, maybe after chaotic-aur rebuilt their packages it all works.

In the meantime, anything specific you would like me to test?

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

You can try running tinywl with the wayland backend (if that works without validation errors you can try the drm backend, i.e. from tty, exit via alt + escape) with WLR_RENDERER=vulkan. Then start the the weston-* sample apps (have to run them with WAYLAND_DISPLAY=wayland-1 if you run tinywl on the wayland backend), especially weston-simple-dmabuf-egl. You could also try something more complex like a browser (e.g. firefox on its wayland backend via MOZ_ENABLE_WAYLAND=1).

@David96
Copy link
Contributor

David96 commented Mar 8, 2021

Alright, got to it before tomorrow ^^
But sadly, I get a validation error using the wayland backend:

00:00:00.210 [render/vulkan/renderer.c:1707] The vulkan renderer is only experimental and not expected to be ready for daily use
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_device_group_creation
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_display
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_external_fence_capabilities
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_external_memory_capabilities
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_external_semaphore_capabilities
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_get_display_properties2
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_get_physical_device_properties2
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_get_surface_capabilities2
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_surface
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_surface_protected_capabilities
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_wayland_surface
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_xcb_surface
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_KHR_xlib_surface
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_EXT_acquire_xlib_display
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_EXT_debug_report
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_EXT_direct_mode_display
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_EXT_display_surface_counter
00:00:00.223 [render/vulkan/vulkan.c:125] Vulkan Instance extensions VK_EXT_debug_utils
00:00:00.241 [render/vulkan/vulkan.c:67] Validation Error: [ UNASSIGNED-API-Version-Violation ] Object 0: VK_NULL_HANDLE, type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0xc495fcb4 | Attemped to call vkGetPhysicalDeviceProperties2() with an effective API version of 1.1.0 (0x00401000), which is the minimum of version requested in pApplicationInfo (1.0.168 (0x004000a8)) and supported by this physical device (1.0.168 (0x004000a8)), but this API was not promoted until version 1.1.0 (0x00401000). (UNASSIGNED-API-Version-Violation)

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

Oh that one is to be expected, I got it too and think it's a validation layer error but didn't have time to dig into it yet. The message does not make sense, it even says we have an effective API version of 1.1.0 (and we definitely do) but then outputs incorrect properties and complains that the called function requires 1.1.0. This one shouldn't be a problem, just ignore it. Do things work other than that?

@David96
Copy link
Contributor

David96 commented Mar 8, 2021

Nope, after that it crashes, but in the Vulkan-ValidationLayers. I just glanced over your pull request but my guess would be that there is some other place where GetPhysicalDeviceFormatProperties2 is called in a wrong way.
The backtrace:

Thread 1 "tinywl" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in  ()
#1  0x00007fff993c421c in vulkan_layer_chassis::GetPhysicalDeviceProperties2(VkPhysicalDevice_T*, VkPhysicalDeviceProperties2*) (physicalDevice=0x55555662b9f0, pProperties=0x7fffffffd0b0)
    at /home/iuser/Dokumente/ABS/packages/vulkan-validation-layers/repos/extra-x86_64/src/Vulkan-ValidationLayers/layers/generated/chassis.cpp:3990
#2  0x00007fffd805019d in  () at /usr/lib/libVkLayer_MESA_device_select.so
#3  0x00007fffd8051927 in  () at /usr/lib/libVkLayer_MESA_device_select.so
#4  0x00007ffff79792d3 in  () at /usr/lib/libvulkan.so.1
#5  0x00007ffff797be88 in vkEnumeratePhysicalDevices () at /usr/lib/libvulkan.so.1
#6  0x00007ffff7f0e4ed in wlr_vk_find_drm_phdev (ini=0x5555561d1c40, drm_fd=6) at ../render/vulkan/vulkan.c:321
#7  0x00007ffff7f0a9b9 in wlr_vk_renderer_create_from_drm_fd (drm_fd=6) at ../render/vulkan/renderer.c:1720
#8  0x00007ffff7f00c36 in wlr_renderer_autocreate_with_drm_fd (drm_fd=6) at ../render/wlr_renderer.c:288
#9  0x00007ffff7f00ceb in wlr_renderer_autocreate (backend=0x55555556bc70) at ../render/wlr_renderer.c:311
#10 0x00007ffff7f23755 in wlr_wl_backend_create (display=0x55555556bb00, remote=0x0) at ../backend/wayland/backend.c:441
#11 0x00007ffff7f10d00 in attempt_wl_backend (display=0x55555556bb00) at ../backend/backend.c:99
#12 0x00007ffff7f113f3 in wlr_backend_autocreate (display=0x55555556bb00) at ../backend/backend.c:268
#13 0x0000555555557f70 in main (argc=1, argv=0x7fffffffe1f8) at tinywl.c:845

Don't get confused by the fact that the validationlayers are in the directory of the extra repo, I modified the PKGBUILD to pull your repo.

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

Ah damn I remember encountering problems with the MESA_device_select layer as well. You could try to disable it by using NODEVICE_SELECT=1.

@David96
Copy link
Contributor

David96 commented Mar 8, 2021

With that I get a little bit further, but now it crashes with:

00:00:09.357 [render/vulkan/vulkan.c:510] vulkan: VK_EXT_queue_family_foreign not supported
00:00:09.357 [render/vulkan/vulkan.c:523] YCbCr device feature: 1
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format AR24 (0x34325241), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format XR24 (0x34325258), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format XB24 (0x34324258), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format AB24 (0x34324241), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format NV12 (0x3231564e), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format NV16 (0x3631564e), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format YU12 (0x32315559), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format YU16 (0x36315559), supported for textures
00:00:09.369 [render/vulkan/pixel_format.c:397] vulkan: Format YU24 (0x34325559), supported for textures
00:00:09.371 [backend/wayland/backend.c:465] Renderer doesn't support DRM format 0x34325241

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

Alright! This means that no formats/modifiers at all are detected as supporting dmabuf imports which also means we can't render anything. Which is weird. Thank you for your help so far, I'll add more detailed debug logging regarding format querying, maybe we can get further then :)

@nyorain
Copy link
Contributor Author

nyorain commented Mar 8, 2021

For reference, this is the output for anv.

@David96
Copy link
Contributor

David96 commented Mar 9, 2021

Somehow the format querying changes seem to have fixed my issue, I can start tinywl now and weston-simple-dmabuf-egl works like a charm.
Then I went a bit crazy and tried starting sway with the vulkan renderer, that fails with Renderer doesn't support XRGB8888 though, not sure whether that's expected. The format querying debug output now looks like:

00:00:00.249 [render/vulkan/vulkan.c:523] YCbCr device feature: 1
00:00:00.260 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format AR24 (0x34325241)
00:00:00.260 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.260 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format XR24 (0x34325258)
00:00:00.260 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.260 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format XB24 (0x34324258)
00:00:00.260 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000a01: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.260 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.260 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000901: features 0xdd81
00:00:00.260 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format AB24 (0x34324241)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401a01: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000401901: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000a01: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x200000000000901: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0xdd81
00:00:00.261 [render/vulkan/pixel_format.c:331]     >> rendering: supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format YUYV (0x56595559)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.261 [render/vulkan/pixel_format.c:413]  >> shmtex: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format UYVY (0x59565955)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 5
00:00:00.261 [render/vulkan/pixel_format.c:413]  >> shmtex: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format NV12 (0x3231564e)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 1
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0x86c001
00:00:00.261 [render/vulkan/pixel_format.c:336]     >> rendering: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format NV16 (0x3631564e)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 1
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0x86c001
00:00:00.261 [render/vulkan/pixel_format.c:336]     >> rendering: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format YU12 (0x32315559)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 1
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0x86c001
00:00:00.261 [render/vulkan/pixel_format.c:336]     >> rendering: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format YU16 (0x36315559)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 1
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0x86c001
00:00:00.261 [render/vulkan/pixel_format.c:336]     >> rendering: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported
00:00:00.261 [render/vulkan/pixel_format.c:200] vulkan: Checking support for format YU24 (0x34325559)
00:00:00.261 [render/vulkan/pixel_format.c:247]   drmFormatModifierCount: 1
00:00:00.261 [render/vulkan/pixel_format.c:296]   modifier: 0x0: features 0x86c001
00:00:00.261 [render/vulkan/pixel_format.c:336]     >> rendering: format features not supported
00:00:00.261 [render/vulkan/pixel_format.c:371]     >> dmatex: supported
00:00:00.261 [render/vulkan/pixel_format.c:405]  >> shmtex: supported

After sway failed, I ran firefox in tinywl, which seemed to work so I wanted to write this comment in there, it always crashed when I got to the 2FA part of github though with Exiting due to channel error. - should I try to get a better Firefox debug log/back trace or what kind of log would be helpful here?

The only errors I see from tinywl are:

00:00:30.094 [render/swapchain.c:97] No free output buffer slot
00:00:30.094 [types/wlr_output.c:1058] Falling back to software cursor on output 'WL-1'

But they appear wihtout the vulkan renderer, too, so nothing special apparently.

@David96
Copy link
Contributor

David96 commented Mar 9, 2021

Trying the DRM backend somehow doesn't work at all, the screen just freezes after running the tinywl command (still showing the tty), ctrl+alt+F1 doesn't work then, but ALT+ESC to quit tinywl. I attached the log with all the validation errors (quite a few).
Although if I interpret the logs correctly, the validation errors only appear upon exiting tinywl.
The main error because of which nothing gets rendered seems to be:

00:00:00.418 [DEBUG] [render/gbm_allocator.c:123] Allocated 1920x1080 GBM buffer (format 0x34325241, modifier 0xFFFFFFFFFFFFFF)
00:00:00.418 [ERROR] [render/vulkan/texture.c:400] Format 875713089 can't be used with modifier 72057594037927935
00:00:00.418 [ERROR] [backend/drm/renderer.c:117] Failed to bind buffer to renderer
00:00:00.418 [ERROR] [backend/drm/drm.c:722] connector eDP-1: Failed to initialize renderer:initial page-flip failed
00:00:00.418 [ERROR] [backend/drm/drm.c:813] connector eDP-1: Failed to initialize renderer for plane

This appears for both screens (eDP-1 is my internal screen, DP-1 an external one).

Log: drm.log.

@emersion
Copy link
Member

emersion commented Mar 9, 2021

If you're using amdgpu, you'll need a pretty recent kernel (5.11+). You can check whether the kernel has DRM_CAP_ADDFB2_MODIFIERS support via drm_info.

@David96
Copy link
Contributor

David96 commented Mar 9, 2021

ah gotcha, I was staying on 5.10 because 5.11 has issues suspending for me. Will try 5.11 in the next few days.

@nyorain
Copy link
Contributor Author

nyorain commented Mar 9, 2021

Thanks for the detailed report @David96.
Radv seems to have support for YCbCr formats, great! If you have more time and are feeling experimental you could try to get a dmabuf application using such a format running, e.g. NV12 (I always tried weston-simple-dmabuf-v4l but configuring v4l and getting the right format can be a bit of a struggle. Video players might be using it as well). That codepath is completely untested as of now though, so things will likely go wrong.

Somehow the format querying changes seem to have fixed my issue

Yeah, well, I found a minor issue with the code looking over it again (that wasn't a problem on anv but apparently is on radv).

Then I went a bit crazy and tried starting sway with the vulkan renderer, that fails with Renderer doesn't support XRGB8888 though, not sure whether that's expected

Yes I didn't test the renderer with sway as sway seems to assume the gl renderer is used (e.g. here). Will gladly add support in sway down the line if there is interest. The error you are getting seems unrelated though, I might look into it.

00:00:30.094 [render/swapchain.c:97] No free output buffer slot

I got that one as well on both renderers. I looked into it and it's not related to the renderer. (EDIT: see #2554).

@David96
Copy link
Contributor

David96 commented Mar 10, 2021

I'd be happy to do that, but I'm not sure how to find a program that uses this format. I tried using v4l by running wf-recorder on a v4l2loopback device setting the pixel format to nv12 but then running weston-simple-dmabuf-v4l with -f NV12 -d NV12 gives me Insufficient buffer memory on /dev/video2.
What does work (with a lot of lag) is playing a 4k video in yuv420p with mpv. At least mpv says VO: [gpu] 3840x1608 yuv420p, not sure whether this really is the pixel format used in the end.

Edit - update on the drm backend:
with kernel 5.11 that also works, I'm able to run firefox inside tinywl, even watch netflix, use mpv to watch the mentioned video (still extremely laggy) and I don't have any validation errors whatsoever (running with NODEVICE_SELECT=1).

@nyorain
Copy link
Contributor Author

nyorain commented Mar 10, 2021

Alright, good to hear it works with the DRM backend! I investigated the lag you mentioned and it's likely because the mesa egl implementation currently falls back to shm buffers instead of using dmabufs. This happens because it requires the wl_drm protocol (legacy protocol, it only really needs it to get a device fd anyways) which isn't supported by the compositor when using this renderer. I completely forgot about this issue, am only now starting to seriously dig into linux graphic stack developments again.

It is possible to hack support for wl_drm into the vulkan renderer (just the device-fd part basically), I think I got it working the last time, it still lives on a branch, but it's terrible and ugly. The wp_linux_dmabuf_hints protocol is the better replacement, this mesa patch removes the hard wl_drm dependency from the egl driver.

Only vulkan clients and clients using linux_dmabuf_v1 directly (like weston-simple-dmabuf-egl) will make use of the dmabuf protocol with this renderer at the moment.

@emersion
Copy link
Member

It is possible to hack support for wl_drm into the vulkan renderer (just the device-fd part basically), I think I got it working the last time, it still lives on a branch, but it's terrible and ugly.

#2708 is basically this. Yeah, it isn't great.

@nyorain
Copy link
Contributor Author

nyorain commented Mar 10, 2021

#2708 is basically this. Yeah, it isn't great.

Given that you already have a finished implementation, maybe it's worth integrating it here after all for easier testing and as a workaround until wp_linux_dmabuf_hints lands. I'd prefer just using wp_linux_dmabuf_hints though, if there's any way to help with making that land, let me know.

@emersion
Copy link
Member

Yeah, I don't think we'll be able to get rid of wl_drm anytime soon. Even when the new linux-dmabuf hints stuff is shipped in Mesa, some other client will still rely on wl_drm, at least to get the DRM device (e.g. libva, xwayland, wlroots' Wayland backend itself).

I've also seen Xwayland falling back to wl_drm for creating buffer when the client has allocated buffers without modifiers. But I guess this one could be fixed by allowing wlroots to advertise support for implicit modifiers on GLES2 (not Vulkan).

.gitignore Outdated Show resolved Hide resolved
@emersion
Copy link
Member

Note, this kernel patch might be of interest, to be able to properly synchronize client buffers: https://lists.freedesktop.org/archives/dri-devel/2021-March/299766.html

@nyorain
Copy link
Contributor Author

nyorain commented Mar 20, 2021

Yeah, I don't think we'll be able to get rid of wl_drm anytime soon

Alright, I will pull your implementation in here after I split off the ycbcr support part.

properly synchronize client buffers

Interesting read, good to hear the explicit sync infrastructure is made as efficient as possible. Explicit sync is another rework (see #1685) that would be needed to make this renderer efficient and really use the advantages of vulkan. The compositor -> client direction is "solved" at the moment by waiting on the rendering fence in the compositor before releasing the buffer back to the client. For the client -> compositor direction we rely on the driver to enable implicit sync for buffers submitted to the compositor (which is weird in vulkan as the API is designed with explicit sync all the way). Explicit sync for wlr_buffers on the drm backend via IN_FENCE_FD would also be nice to have down the road (another reason we have to wait for rendering on the CPU at the moment).

@nyorain
Copy link
Contributor Author

nyorain commented Sep 29, 2021

Some of the texture uploading transitions @cyanreg commented on were indeed messy, this should be better now.

On the other issues, I agree with @emersion. I'm personally still not convinced that compute shaders bring a huge advantage here so I won't put my time into it. You can just do a new PR after this if you want it I guess.
Regarding the optimized texture uploading via importing host pointers, it won't require much refactoring as we will want to keep the current code path as fallback anyways, as previously discussed.

@jbeich
Copy link
Contributor

jbeich commented Sep 30, 2021

0ae5b0b breaks drm backend at least on FreeBSD with Mesa from git. wayland backend (e.g., Sway/Vulkan on Sway/OpenGL) still works fine.

$ WLR_RENDERER=vulkan sway -c /dev/null
00:00:00.023 [ERROR] [wlr] [render/vulkan/renderer.c:1512] Could not match drm and vulkan device
00:00:00.023 [ERROR] [wlr] [backend/backend.c:96] Failed to create backend renderer
00:00:00.026 [ERROR] [wlr] [render/vulkan/renderer.c:1512] Could not match drm and vulkan device
00:00:00.026 [ERROR] [wlr] [backend/backend.c:96] Failed to create backend renderer
00:00:00.027 [ERROR] [wlr] [backend/backend.c:289] Failed to create DRM backend
00:00:00.027 [ERROR] [wlr] [backend/backend.c:442] Failed to open any DRM device
00:00:00.027 [ERROR] [sway/server.c:55] Unable to create backend

$ WLR_RENDERER=vulkan cage -s foot -d none
00:00:00.020 [ERROR] [render/vulkan/renderer.c:1512] Could not match drm and vulkan device
00:00:00.021 [ERROR] [backend/backend.c:96] Failed to create backend renderer
00:00:00.024 [ERROR] [render/vulkan/renderer.c:1512] Could not match drm and vulkan device
00:00:00.024 [ERROR] [backend/backend.c:96] Failed to create backend renderer
00:00:00.024 [ERROR] [backend/backend.c:289] Failed to create DRM backend
00:00:00.024 [ERROR] [backend/backend.c:442] Failed to open any DRM device
00:00:00.024 [ERROR] [../cage.c:307] Unable to create the wlroots backend

Debug logs: sway, cage

@emersion
Copy link
Member

0ae5b0b breaks drm backend

Oops, fixed.

@jbeich
Copy link
Contributor

jbeich commented Sep 30, 2021

Doesn't work with x11 backend (e.g., Sway/Vulkan on Xorg). Tested both modesetting and xf86-video-intel (SNA + DRI3). Not a regression: wlroots 0.14.1 + 15c8453...dd039c5 have similar error. Note, PR description says unimplemented wlr_renderer_read_pixels "should only have an impact on multi-GPU support and wlr_screencopy_v1".

$ WLR_RENDERER=vulkan sway-1.6.1 -c /dev/null
00:00:00.179 [wlr] [render/vulkan/renderer.c:989] vulkan_read_pixels not implemented
00:00:00.187 [wlr] [render/vulkan/texture.c:371] Format 34325241 (AR24) can't be used with modifier ffffffffffffff
^C

$ WLR_RENDERER=vulkan sway-1.7 -c /dev/null
00:00:00.148 [wlr] [types/wlr_drm_lease_v1.c:705] No DRM backend supplied, failed to create wlr_drm_lease_v1_manager
00:00:00.179 [wlr] [render/vulkan/renderer.c:990] vulkan_read_pixels not implemented
00:00:00.184 [wlr] [render/vulkan/texture.c:400] Format 34325241 (AR24) can't be used with modifier ffffffffffffff
00:00:00.212 [wlr] [render/vulkan/texture.c:400] Format 34325241 (AR24) can't be used with modifier ffffffffffffff
^C

$ WLR_RENDERER=vulkan cage foot -d none
00:00:00.132 [ERROR] [render/vulkan/renderer.c:990] vulkan_read_pixels not implemented
00:00:00.139 [ERROR] [render/vulkan/renderer.c:990] vulkan_read_pixels not implemented
00:00:00.144 [ERROR] [render/vulkan/texture.c:400] Format 34325241 (AR24) can't be used with modifier ffffffffffffff
00:00:00.161 [ERROR] [render/vulkan/texture.c:400] Format 34325241 (AR24) can't be used with modifier ffffffffffffff

Debug log: sway-1.7

@emersion
Copy link
Member

It seems like your X11 server doesn't support DRM format modifiers. It should work if you run it via Xwayland (WLR_BACKEND=x11 WLR_RENDERER=vulkan under a Wayland compositor).

There's no way around it, Vulkan requires DRM format modifiers. However the error message could really be improved. The reason it doesn't just fail to start is that wlroots has an implicit assumption that the modifier-less codepath will always work. That's wrong and #2815 tries to fix that, it should help with this case.

@jbeich
Copy link
Contributor

jbeich commented Oct 5, 2021

Do you plan to enable Vulkan on FreeBSD CI (to avoid regressing Clang builds)? According to downstream recipe the extra dependencies are:

  • graphics/glslang
  • graphics/vulkan-headers
  • graphics/vulkan-loader

@emersion
Copy link
Member

emersion commented Oct 6, 2021

Done!

include/render/vulkan.h Outdated Show resolved Hide resolved
render/vulkan/renderer.c Outdated Show resolved Hide resolved
render/vulkan/renderer.c Outdated Show resolved Hide resolved
include/render/vulkan.h Outdated Show resolved Hide resolved
include/render/vulkan.h Outdated Show resolved Hide resolved
@nyorain
Copy link
Contributor Author

nyorain commented Oct 14, 2021

Thanks for the review @Joshua-Ashton.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start. Let's iterate in follow-up pull requests.

Thanks a lot for your hard work!

@emersion
Copy link
Member

Squashed everything since I don't think there's a reasonable way to split these additions up. Added Alpine CI.

This new renderer is implemented with the existing wlr_renderer API
(which is known to be sub-optimal for some operations). It's not
used by default, but users can opt-in by setting WLR_RENDERER=vulkan.

The renderer depends on VK_EXT_image_drm_format_modifier and
VK_EXT_physical_device_drm.

Co-authored-by: Simon Ser <[email protected]>
Co-authored-by: Jan Beich <[email protected]>
@misyltoad
Copy link
Contributor

Having some issues with it on AMD, looking into right now.

@misyltoad
Copy link
Contributor

(doesn't need to block it being merged though, if there is an issue I will PR to here or Mesa or whatever.)

@emersion emersion merged commit 8e34692 into swaywm:master Oct 18, 2021
@emersion
Copy link
Member

Thanks for your contribution!

@emersion
Copy link
Member

Also ref #3188 and #3252 to improve the wlr_renderer API.

@sjnewbury
Copy link

As I understand it VK_EXT_image_drm_format_modifier is only available on AMD GFX9 and later? Is there going to be any solution to this? I use a Polaris GPU, and I should think many others do too, they're still sold new after all...

@emersion
Copy link
Member

The solution is to add format modifiers support to GFX8. It's not possible to use a Vulkan compositor without this extension and without resorting to Mesa-specific hacks.

@sjnewbury
Copy link

I've left a comment asking about this on the mesa pr for gfx9 support: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6176#note_1123860

Hopefully, this wlroots Vulkan renderer is important enough for the amdgpu devs to address the lack of support. There must be more GFX8 AMD GPUs out there than any other AMD architecture.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.