Added X11 support for WGPU video backend

This commit is contained in:
The Stickmahn 2026-05-30 11:32:00 +02:00
parent 7e733d0934
commit 77d364e30d
3 changed files with 70 additions and 0 deletions

View file

@ -41,6 +41,7 @@
#include "SDL_x11shape.h"
#include "SDL_x11xsync.h"
#include "SDL_x11xtest.h"
#include "SDL_x11wgpu.h"
#ifdef SDL_VIDEO_OPENGL_EGL
#include "SDL_x11opengles.h"
@ -268,6 +269,10 @@ static SDL_VideoDevice *X11_CreateDevice(void)
device->Vulkan_GetPresentationSupport = X11_Vulkan_GetPresentationSupport;
#endif
#ifdef SDL_VIDEO_WGPU
device->WGPU_CreateSurface = X11_WGPU_CreateSurface;
#endif
#ifdef SDL_USE_LIBDBUS
if (SDL_SystemTheme_Init())
device->system_theme = SDL_SystemTheme_Get();

View file

@ -0,0 +1,52 @@
#include "SDL_internal.h"
#if defined(SDL_VIDEO_WGPU) && defined(SDL_VIDEO_DRIVER_X11)
#include "SDL_x11video.h"
#include "SDL_x11wgpu.h"
SDL_ELF_NOTE_DLOPEN(
"x11-wgpu",
"Support for for wgpu-native on X11 backend",
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libwgpu_native.so")
WGPUSurface X11_WGPU_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, WGPUInstance instance)
{
SDL_PropertiesID windowProperties = SDL_GetWindowProperties(window);
Display *x11_display = SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, 0);
Window x11_window = SDL_GetNumberProperty(windowProperties, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
WGPUSurfaceDescriptor desc;
WGPUSurfaceSourceXlibWindow source;
source.window = x11_window;
source.display = x11_display;
source.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
source.chain.next = NULL;
desc.label = (WGPUStringView){ NULL, WGPU_STRLEN };
desc.nextInChain = &source.chain;
SDL_SharedObject *wgpuLib = SDL_LoadObject("libwgpu_native.so");
if (wgpuLib == NULL) {
SDL_SetError("Failed to load wgpu-native shared library 'libwgpu_native.so'");
goto fail;
}
WGPUProcInstanceCreateSurface proc = (WGPUProcInstanceCreateSurface)SDL_LoadFunction(wgpuLib, "wgpuInstanceCreateSurface");
if (proc == NULL) {
SDL_SetError("Failed to load function 'wgpuInstanceCreateSurface' from loaded wgpu-native library!");
goto fail;
}
return proc(instance, &desc);
fail:
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Failed to create WGPU surface: %s", SDL_GetError());
return NULL;
}
#endif

View file

@ -0,0 +1,13 @@
#ifndef SDL_x11wgpu_h_
#define SDL_x11wgpu_h_
// NOTE: Again, Not sure if I'm allowed to do this.
#include "../webgpu/webgpu.h"
#include <SDL3/SDL_wgpu.h>
#if defined(SDL_VIDEO_WGPU) && defined(SDL_VIDEO_DRIVER_X11)
extern WGPUSurface X11_WGPU_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, WGPUInstance instance);
#endif
#endif // SDL_x11wgpu_h_