Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuke wlr_renderer implementation #666

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 4 additions & 82 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CVulkanTexture> vulkan_create_texture_from_wlr_buffer( struct wlr_buffer *buf )
{

Expand Down
17 changes: 4 additions & 13 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@ extern "C" {
#include <vulkan/vulkan.h>
#include <drm_fourcc.h>

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 )
Expand Down Expand Up @@ -395,8 +384,6 @@ std::shared_ptr<CVulkanTexture> vulkan_get_hacky_blank_texture();

bool vulkan_screenshot( const struct FrameInfo_t *frameInfo, std::shared_ptr<CVulkanTexture> pScreenshotTexture );

struct wlr_renderer *vulkan_renderer_create( void );

using mat3x4 = std::array<std::array<float, 4>, 3>;

#include "color_helpers.h"
Expand Down Expand Up @@ -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();
43 changes: 34 additions & 9 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ extern "C" {
#include <wlr/backend/libinput.h>
#include <wlr/backend/multi.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_shm.h>
#include <wlr/types/wlr_touch.h>
#include <wlr/util/log.h>
#include <wlr/xwayland/server.h>
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down
5 changes: 2 additions & 3 deletions src/wlserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -112,12 +111,12 @@ struct wlserver_t {

std::vector<std::unique_ptr<gamescope_xwayland_server_t>> 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 <uint32_t> touch_down_ids;

Expand Down
Loading