Skip to content

Vulkan with Wayland #130

Open
Open

Description

@serid

https://vulkan-tutorial.com/Development_environment#page_Linux

only cotains guide for X Window System. And what about Wayland? I suggest adding another section for it, but this may be not so easy, because as far as I know Wayland support in Vulkan is a new feature.

Activity

  1. Overv commented on Apr 28, 2019

    @Overv
    Owner

    I will include it once Wayland is no longer an experimental feature in GLFW (https://www.glfw.org/docs/latest/news.html#news_31_wayland).

  2. Tooniis commented on May 31, 2020

    @Tooniis

    It has been working right away with Wayland provided. Just have glfw-wayland installed and you should be good to go; after all glfw handles all the window-related stuff

  3. alephpt commented on Aug 7, 2021

    @alephpt

    Update on this issue after some trouble-shooting and trial and error...

    Issue #1 -
    https://vulkan-tutorial.com/Development_environment#page_Setting-up-a-makefile-project is geared towards X11
    Wayland does support x11 with xorg-xwayland, but you cannot install and link against glfw-x11 and have glfw-wayland installed side by side due to packaging conflicts (at least on arch).

    Issue #2 -
    The initial VulkanTest does not create a Window instance on Wayland, and after much confusion I found on a GLFW/Wayland issue (glfw/glfw#1398 (comment)) that
    ".. by design. A Wayland window is not shown until a buffer is commited. If consistency is desired here, GLFW could clear the surface to black and commit it when the surface is created." - jjagg

    Solution:
    A slight difference in the way files should be linked for Vulkan to work with Wayland, and an explanation about the Wayland/GLFW buffer creation could be specified in the Vulkan-tutorial linked above, to help offer some clarity for future wayland users.

    Here is the Makefile config I found to work:

    VULKAN_SDK_PATH = /usr/include/vulkan
    VK_EXP_PATH = /etc/vulkan/explicit_layer.d
    
    CFLAGS = -std=c++17 -I $(VULKAN_SDK_PATH)
    LDFLAGS = -L $(VULKAN_SDK_PATH) -lglfw -lvulkan -ldl -pthread
    DBFLAGS = -fsanitize=address,undefined --debug
    
    VulkanTest: main.cpp
    	g++ $(CFLAGS) -o VulkanTest main.cpp $(LDFLAGS)
    
    .PHONY: test clean
    
    debug:
    	g++ $(CFLAGS) -o Triangles main.cpp $(LDFLAGS) $(DBFLAGS)
    
    test: VulkanTest
    	LD_LIBRARY_PATH=$(VULKAN_SDK_PATH) VK_LAYER_PATH=$(VK_EXP_PATH)	./VulkanTest
    
  4. graslany commented on Nov 23, 2022

    @graslany

    I ran into the same problem and came up with a different but similar solution to the GLFW link problem; the one above would probably not work for me anyway, since there is no glfw.so file in /usr/include/vulkan on my system apparently, which I could link with.

    What I did was download the glfw sources from its website, and compile it with wayland support :

    cmake -S lib/glfw/ -B glfw_bin/ -DGLFW_BUILD_WAYLAND=1 -DBUILD_SHARED_LIBS=1 -DGLFW_BUILD_EXAMPLES=0 -DGLFW_BUILD_TESTS=0 -DGLFW_BUILD_DOCS=0
    

    Then I copied the resulting libglfw.so, libglfw.so.3 and libglfw.so.3.3 files into my project files, and used the -L and LD_LIBRARY_PATH to compile and run the example, like in alephpt's solution above (pointing to my local project binaries of course).

  5. graslany commented on Nov 23, 2022

    @graslany

    One interesting thing though : the GLFW binary on my system (Fedora 36) has X11 support only, apparently :

    $ readelf -Ws /usr/lib64/libglfw.so | grep Display
        50: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND XOpenDisplay
        58: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND XDisplayKeycodes
        63: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND XCloseDisplay
       215: 0000000000019ea0    57 FUNC    GLOBAL DEFAULT   14 glfwGetX11Display
       253: 000000000001baf0    57 FUNC    GLOBAL DEFAULT   14 glfwGetEGLDisplay
    

    However, the one I just compiled seems to have support for both :

    $ readelf -Ws lib/libglfw.so | grep Display
       130: 000000000002c973   109 FUNC    GLOBAL DEFAULT   12 glfwGetX11Display
       138: 0000000000039452   109 FUNC    GLOBAL DEFAULT   12 glfwGetWaylandDisplay
       168: 000000000001c04f    60 FUNC    GLOBAL DEFAULT   12 glfwGetEGLDisplay
       471: 00000000000352d1   194 FUNC    LOCAL  DEFAULT   12 flushDisplay
       589: 0000000000039265    20 FUNC    LOCAL  DEFAULT   12 _glfwGetEGLNativeDisplayWayland
       667: 000000000001e4ed    11 FUNC    LOCAL  DEFAULT   12 _glfwGetEGLNativeDisplayNull
       719: 000000000002c48a    20 FUNC    LOCAL  DEFAULT   12 _glfwGetEGLNativeDisplayX11
       999: 000000000002c973   109 FUNC    GLOBAL DEFAULT   12 glfwGetX11Display
      1014: 0000000000039452   109 FUNC    GLOBAL DEFAULT   12 glfwGetWaylandDisplay
      1019: 000000000001c04f    60 FUNC    GLOBAL DEFAULT   12 glfwGetEGLDisplay
    

    I wonder why the maintainers for Fedora only included one of them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions