Added Windows support (untested though, sorry)

Added Windows support for WGPU, although it is untested since I don't
have a Windows machine to test it on.
This commit is contained in:
The Stickmahn 2026-05-30 16:16:55 +02:00
parent 715bcdc231
commit 9f502500a2
3 changed files with 70 additions and 0 deletions

View file

@ -96,6 +96,12 @@ typedef struct WGPUSurfaceSourceXlibWindow {
uint64_t window;
} WGPUSurfaceSourceXlibWindow;
typedef struct WGPUSurfaceSourceWindowsHWND {
WGPUChainedStruct chain;
void * hinstance;
void * hwnd;
} WGPUSurfaceSourceWindowsHWND;
typedef WGPUSurface (*WGPUProcInstanceCreateSurface)(WGPUInstance instance, WGPUSurfaceDescriptor const *descriptor) WGPU_FUNCTION_ATTRIBUTE;
#if defined(WGPU_STATIC)

View file

@ -0,0 +1,52 @@
#include "SDL_internal.h"
#if defined(SDL_VIDEO_WGPU) && defined(SDL_VIDEO_DRIVER_WINDOWS)
#include "SDL_windowsvideo.h"
#include "../SDL_wgpu_defs.h"
#include "SDL_windoiwswgpu.h"
WGPUSurface WIN_WGPU_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, WGPUInstance instance)
{
SDL_PropertiesID windowProperties = SDL_GetWindowProperties(window);
void *hwnd = SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WIN32_HWND_POINTER, 0);
void *hinstance = SDL_GetPointerProperty(windowProperties, SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER, 0);
WGPUSurfaceDescriptor desc;
WGPUSurfaceSourceWindowsHWND source;
source.hwnd = hwnd;
source.hinstance = hinstance;
source.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
source.chain.next = NULL;
desc.label = (WGPUStringView){ NULL, WGPU_STRLEN };
desc.nextInChain = &source.chain;
#if defined(WGPU_STATIC)
return wgpuInstanceCreateSurface(instance, &desc);
#else
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
}
#endif

View file

@ -0,0 +1,12 @@
// NOTE: I don't have a Windows machine to test this on. - TheStickmahn
#ifndef SDL_windowswgpu_h_
#define SDL_windowswgpu_h_
#include <SDL3/SDL_wgpu.h>
#if defined(SDL_VIDEO_WGPU) && defined(SDL_VIDEO_DRIVER_WINDOWS)
extern WGPUSurface WIN_WGPU_CreateSurface(SDL_VSDL_VideoDevice *_this, SDL_Window *window, WGPUInstance instance);
#endif
#endif // SDL_windowswgpu_h_