Vulkan: Wayland Windowing #113007

Merged
Jeroen Bakker merged 3 commits from Jeroen-Bakker/blender:vulkan/wayland-surface into main 2023-10-06 14:45:17 +02:00
Member

Wayland WSI would crash the system when used. The reason is that the
wayland vulkan WSI doesn't provide windowing support. Vulkan gets full access
to the desktop of the OS and it is the responsibilty of the application to
do the right thing.

For OpenGL Wayland proved basic windowing support using wayland-egl.h.
Which essentially is a tiny wrapper that keeps track of the window position and
size.

This PR changes a few things to make the Wayland surface usable:

  • Do not load debug extensions when blender isn't started with
    --debug-gpu.
  • Recreate swapchain images when surface size changes.
Wayland WSI would crash the system when used. The reason is that the wayland vulkan WSI doesn't provide windowing support. Vulkan gets full access to the desktop of the OS and it is the responsibilty of the application to do the right thing. For OpenGL Wayland proved basic windowing support using `wayland-egl.h`. Which essentially is a tiny wrapper that keeps track of the window position and size. This PR changes a few things to make the Wayland surface usable: - Do not load debug extensions when blender isn't started with `--debug-gpu`. - Recreate swapchain images when surface size changes.
Jeroen Bakker added this to the 4.1 milestone 2023-09-28 12:36:19 +02:00
Jeroen Bakker added the
Interest
Vulkan
label 2023-09-28 12:36:19 +02:00
Jeroen Bakker self-assigned this 2023-09-28 12:36:20 +02:00
Jeroen Bakker requested review from Campbell Barton 2023-09-28 15:59:46 +02:00
Jeroen Bakker added this to the EEVEE & Viewport project 2023-09-29 07:55:59 +02:00
Jeroen Bakker changed title from WIP: Vulkan: Wayland Surface to Vulkan: Wayland Surface 2023-09-29 11:27:11 +02:00
Jeroen Bakker changed title from Vulkan: Wayland Surface to Vulkan: Wayland Window 2023-09-29 11:33:06 +02:00
Jeroen Bakker changed title from Vulkan: Wayland Window to Vulkan: Wayland Windowing 2023-09-29 11:33:18 +02:00
Jeroen Bakker added a new dependency 2023-09-29 14:03:31 +02:00
Campbell Barton reviewed 2023-10-03 14:49:33 +02:00
@ -471,6 +474,22 @@ GHOST_TSuccess GHOST_ContextVK::swapBuffers()
return GHOST_kFailure;
}
/* Wayland doesn't provice a WSI with windowing capabilities, therefore cannot detect whether the

picky (provide).

*picky* (provide).
Jeroen-Bakker marked this conversation as resolved
@ -474,0 +479,4 @@
* presenting. */
#ifdef WITH_GHOST_WAYLAND
if (m_wayland_window) {
const bool recreate_swapchain = m_render_extent.width != m_wayland_window->width ||

This comparison should use std::max(m_wayland_window->width, capabilities.minImageExtent.width), else it will continuously recreate the swapchain (not sure if it's an issue in practice, noting for correctness).. For this to be practical minImageExtent should probably be stored in the class.

This comparison should use `std::max(m_wayland_window->width, capabilities.minImageExtent.width)`, else it will continuously recreate the swapchain (not sure if it's an issue in practice, noting for correctness).. For this to be practical `minImageExtent` should probably be stored in the class.
Jeroen-Bakker marked this conversation as resolved

Testing over the patch and I agree that using an EGL context with Vulkan is a concern. Even though it works for me, the graphics driver may run callbacks from the EGL functions which could interfere with Vulkan operations.

So unless there a strong reason to keep the EGL window, I'd rather avoid using it for Vulkan.

Attached a patch that only uses EGL with the OpenGL back-end.

Testing over the patch and I agree that using an EGL context with Vulkan is a concern. Even though it works for me, the graphics driver may run callbacks from the EGL functions which could interfere with Vulkan operations. So unless there a strong reason to keep the EGL window, I'd rather avoid using it for Vulkan. Attached a patch that only uses EGL with the OpenGL back-end.
Campbell Barton requested changes 2023-10-03 14:55:55 +02:00
Campbell Barton left a comment
Owner

Attached patch with requested changes that remove EGL window usage: wayland_vulkan_no_egl.diff

Attached patch with requested changes that remove EGL window usage: `wayland_vulkan_no_egl.diff`

Some additional notes:

  • Resizing the window produces some glitches/artifacts though don't show up with OpenGL (not a blocker, but would be good to resolve).

  • When looking into this patch I checked on how other applications deal with Wayland+Vulkan swap-chains. There looks to be possible optimizations re-creating the swap-chain, https://code.videolan.org/videolan/libplacebo which looks to be a good reference. (used by VideoLan / MPV and deals with this issue too), specifically vk_sw_recreate.

Improvements here can be part of regular development though.

Some additional notes: - Resizing the window produces some glitches/artifacts though don't show up with OpenGL (not a blocker, but would be good to resolve). - When looking into this patch I checked on how other applications deal with Wayland+Vulkan swap-chains. There looks to be possible optimizations re-creating the swap-chain, https://code.videolan.org/videolan/libplacebo which looks to be a good reference. (used by VideoLan / MPV and deals with this issue too), specifically [vk_sw_recreate](https://code.videolan.org/videolan/libplacebo/-/blob/f25dfeb0c7655a02e5316a9bd129db994b4a3cf5/src/vulkan/swapchain.c#L574). Improvements here can be part of regular development though.
Jeroen Bakker force-pushed vulkan/wayland-surface from 97cf0746f6 to 5bf4bb2fe0 2023-10-05 10:18:40 +02:00 Compare
Author
Member

I applied your patch and changed a #if WITH_GHOST_WAYLAND to #ifdef WITH_GHOST_WAYLAND.

Your changes are aligned to one of my proposals of this patch so seems fine to continue.

During testing I sometimes get a connection lost between ghost and wayland. Unsure when it happens.
This might be something to check in a later stage.

I applied your patch and changed a `#if WITH_GHOST_WAYLAND` to `#ifdef WITH_GHOST_WAYLAND`. Your changes are aligned to one of my proposals of this patch so seems fine to continue. During testing I sometimes get a connection lost between ghost and wayland. Unsure when it happens. This might be something to check in a later stage.
Jeroen Bakker added 1 commit 2023-10-05 10:26:57 +02:00
Campbell Barton approved these changes 2023-10-06 11:01:22 +02:00
Author
Member

Yes there are some other extensions as well to better support Wayland.
I am aware that wayland is still far from optimal and needs more development.
thanks for looking into and thinking along!

Yes there are some other extensions as well to better support Wayland. I am aware that wayland is still far from optimal and needs more development. thanks for looking into and thinking along!
Jeroen Bakker added 1 commit 2023-10-06 14:44:51 +02:00
Jeroen Bakker merged commit 9a654c04de into main 2023-10-06 14:45:17 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: blender/blender#113007
No description provided.