From afe29b4ade45700132154474e08b365aa49c4e94 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 22 Nov 2023 15:49:44 +0100 Subject: [PATCH] Nuke wlr_renderer --- src/rendervulkan.cpp | 86 +++----------------------------------------- src/rendervulkan.hpp | 17 +++------ src/wlserver.cpp | 43 +++++++++++++++++----- src/wlserver.hpp | 5 ++- 4 files changed, 44 insertions(+), 107 deletions(-) diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index 80fc07df7e..c426e63998 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -3877,100 +3877,22 @@ bool vulkan_supports_modifiers(void) return g_device.supportsModifiers(); } -static void texture_destroy( struct wlr_texture *wlr_texture ) -{ - VulkanWlrTexture_t *tex = (VulkanWlrTexture_t *)wlr_texture; - wlr_buffer_unlock( tex->buf ); - delete tex; -} - -static const struct wlr_texture_impl texture_impl = { - .destroy = texture_destroy, -}; - -static uint32_t renderer_get_render_buffer_caps( struct wlr_renderer *renderer ) -{ - return 0; -} - -static bool renderer_begin( struct wlr_renderer *renderer, uint32_t width, uint32_t height ) -{ - abort(); // unreachable -} - -static void renderer_end( struct wlr_renderer *renderer ) -{ - abort(); // unreachable -} - -static void renderer_clear( struct wlr_renderer *renderer, const float color[4] ) -{ - abort(); // unreachable -} - -static void renderer_scissor( struct wlr_renderer *renderer, struct wlr_box *box ) -{ - abort(); // unreachable -} - -static bool renderer_render_subtexture_with_matrix( struct wlr_renderer *renderer, struct wlr_texture *texture, const struct wlr_fbox *box, const float matrix[9], float alpha ) -{ - abort(); // unreachable -} - -static void renderer_render_quad_with_matrix( struct wlr_renderer *renderer, const float color[4], const float matrix[9] ) -{ - abort(); // unreachable -} - -static const uint32_t *renderer_get_shm_texture_formats( struct wlr_renderer *wlr_renderer, size_t *len - ) +void vulkan_get_shm_formats(const uint32_t **formats, size_t *len) { + *formats = sampledShmFormats.data(); *len = sampledShmFormats.size(); - return sampledShmFormats.data(); } -static const struct wlr_drm_format_set *renderer_get_dmabuf_texture_formats( struct wlr_renderer *wlr_renderer ) +const struct wlr_drm_format_set *vulkan_get_dmabuf_texture_formats() { return &sampledDRMFormats; } -static int renderer_get_drm_fd( struct wlr_renderer *wlr_renderer ) +int vulkan_get_drm_fd() { return g_device.drmRenderFd(); } -static struct wlr_texture *renderer_texture_from_buffer( struct wlr_renderer *wlr_renderer, struct wlr_buffer *buf ) -{ - VulkanWlrTexture_t *tex = new VulkanWlrTexture_t(); - wlr_texture_init( &tex->base, wlr_renderer, &texture_impl, buf->width, buf->height ); - tex->buf = wlr_buffer_lock( buf ); - // TODO: check format/modifier - // TODO: if DMA-BUF, try importing it into Vulkan - return &tex->base; -} - -static const struct wlr_renderer_impl renderer_impl = { - .begin = renderer_begin, - .end = renderer_end, - .clear = renderer_clear, - .scissor = renderer_scissor, - .render_subtexture_with_matrix = renderer_render_subtexture_with_matrix, - .render_quad_with_matrix = renderer_render_quad_with_matrix, - .get_shm_texture_formats = renderer_get_shm_texture_formats, - .get_dmabuf_texture_formats = renderer_get_dmabuf_texture_formats, - .get_drm_fd = renderer_get_drm_fd, - .get_render_buffer_caps = renderer_get_render_buffer_caps, - .texture_from_buffer = renderer_texture_from_buffer, -}; - -struct wlr_renderer *vulkan_renderer_create( void ) -{ - VulkanRenderer_t *renderer = new VulkanRenderer_t(); - wlr_renderer_init(&renderer->base, &renderer_impl); - return &renderer->base; -} - std::shared_ptr vulkan_create_texture_from_wlr_buffer( struct wlr_buffer *buf ) { diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index 3e33bdce87..31535993ef 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -75,17 +75,6 @@ extern "C" { #include #include -struct VulkanRenderer_t -{ - struct wlr_renderer base; -}; - -struct VulkanWlrTexture_t -{ - struct wlr_texture base; - struct wlr_buffer *buf; -}; - inline VkFormat ToSrgbVulkanFormat( VkFormat format ) { switch ( format ) @@ -395,8 +384,6 @@ std::shared_ptr vulkan_get_hacky_blank_texture(); bool vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr pScreenshotTexture ); -struct wlr_renderer *vulkan_renderer_create( void ); - using mat3x4 = std::array, 3>; #include "color_helpers.h" @@ -911,3 +898,7 @@ uint32_t DRMFormatGetBPP( uint32_t nDRMFormat ); bool vulkan_supports_hdr10(); void vulkan_wait_idle(); + +void vulkan_get_shm_formats(const uint32_t **formats, size_t *len); +const struct wlr_drm_format_set *vulkan_get_dmabuf_texture_formats(); +int vulkan_get_drm_fd(); diff --git a/src/wlserver.cpp b/src/wlserver.cpp index 49f96ed62f..673de38da2 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -24,11 +24,12 @@ extern "C" { #include #include #include -#include #include #include +#include #include #include +#include #include #include #include @@ -158,13 +159,11 @@ void xwayland_surface_commit(struct wlr_surface *wlr_surface) { // Mutter and Weston have forward progress on the frame callback in this situation, // so let the commit go through. It will be duplication-eliminated later. - VulkanWlrTexture_t *tex = (VulkanWlrTexture_t *) wlr_surface_get_texture( wlr_surface ); - if ( tex == NULL ) - { + if (wlr_surface->current.buffer == NULL) { return; } - struct wlr_buffer *buf = wlr_buffer_lock( tex->buf ); + struct wlr_buffer *buf = wlr_buffer_lock(wlr_surface->current.buffer); gpuvis_trace_printf( "xwayland_surface_commit wlr_surface %p", wlr_surface ); @@ -1404,6 +1403,16 @@ void xdg_surface_new(struct wl_listener *listener, void *data) } } +static bool devid_from_fd(int fd, dev_t *devid) { + struct stat stat; + if (fstat(fd, &stat) != 0) { + wl_log.errorf("fstat failed"); + return false; + } + *devid = stat.st_rdev; + return true; +} + bool wlserver_init( void ) { assert( wlserver.display != nullptr ); @@ -1437,11 +1446,27 @@ bool wlserver_init( void ) { wlserver.wlr.virtual_keyboard_device = kbd; - wlserver.wlr.renderer = vulkan_renderer_create(); + const uint32_t *shm_formats = nullptr; + size_t shm_formats_len = 0; + vulkan_get_shm_formats(&shm_formats, &shm_formats_len); + wlr_shm_create(wlserver.display, 1, shm_formats, shm_formats_len); - wlr_renderer_init_wl_display(wlserver.wlr.renderer, wlserver.display); - - wlserver.wlr.compositor = wlr_compositor_create(wlserver.display, 5, wlserver.wlr.renderer); + dev_t devid; + if (!devid_from_fd(vulkan_get_drm_fd(), &devid)) + { + return false; + } + struct wlr_linux_dmabuf_feedback_v1 default_feedback = { + .main_device = devid, + }; + struct wlr_linux_dmabuf_feedback_v1_tranche *tranche = + wlr_linux_dmabuf_feedback_add_tranche(&default_feedback); + tranche->target_device = devid; + tranche->flags = 1; // SCANOUT + tranche->formats = *vulkan_get_dmabuf_texture_formats(); + wlr_linux_dmabuf_v1_create(wlserver.display, 4, &default_feedback); + + wlserver.wlr.compositor = wlr_compositor_create(wlserver.display, 5, nullptr); wl_signal_add( &wlserver.wlr.compositor->events.new_surface, &new_surface_listener ); diff --git a/src/wlserver.hpp b/src/wlserver.hpp index 07f36d6140..0807673540 100644 --- a/src/wlserver.hpp +++ b/src/wlserver.hpp @@ -102,7 +102,6 @@ struct wlserver_t { struct wlr_backend *headless_backend; struct wlr_backend *libinput_backend; - struct wlr_renderer *renderer; struct wlr_compositor *compositor; struct wlr_session *session; struct wlr_seat *seat; @@ -112,12 +111,12 @@ struct wlserver_t { std::vector> xwayland_servers; } wlr; - + struct wlr_surface *mouse_focus_surface; struct wlr_surface *kb_focus_surface; double mouse_surface_cursorx = 0.0f; double mouse_surface_cursory = 0.0f; - + bool button_held[ WLSERVER_BUTTON_COUNT ]; std::set touch_down_ids;