Add WebGPU support for Windows

This commit is contained in:
Sebastian Dawid 2025-08-16 00:30:16 +02:00
parent 205bf6c768
commit 4cbb4db70c
3 changed files with 24 additions and 1 deletions

View File

@ -669,7 +669,8 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
.getEGLNativeWindow = _glfwGetEGLNativeWindowWin32, .getEGLNativeWindow = _glfwGetEGLNativeWindowWin32,
.getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWin32, .getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWin32,
.getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWin32, .getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWin32,
.createWindowSurface = _glfwCreateWindowSurfaceWin32 .createWindowSurface = _glfwCreateWindowSurfaceWin32,
.createWindowWGPUSurface = _glfwCreateWindowWGPUSurfaceWin32
}; };
*platform = win32; *platform = win32;

View File

@ -544,6 +544,8 @@ void _glfwGetRequiredInstanceExtensionsWin32(char** extensions);
GLFWbool _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); GLFWbool _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
WGPUSurface _glfwCreateWindowWGPUSurfaceWin32(WGPUInstance instance, _GLFWwindow* window);
void _glfwFreeMonitorWin32(_GLFWmonitor* monitor); void _glfwFreeMonitorWin32(_GLFWmonitor* monitor);
void _glfwGetMonitorPosWin32(_GLFWmonitor* monitor, int* xpos, int* ypos); void _glfwGetMonitorPosWin32(_GLFWmonitor* monitor, int* xpos, int* ypos);
void _glfwGetMonitorContentScaleWin32(_GLFWmonitor* monitor, float* xscale, float* yscale); void _glfwGetMonitorContentScaleWin32(_GLFWmonitor* monitor, float* xscale, float* yscale);

View File

@ -2562,6 +2562,26 @@ VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance,
return err; return err;
} }
typedef struct WGPUSurfaceSourceWindowsHWND {
WGPUChainedStruct chain;
void * hinstance;
void * hwnd;
} WGPUSurfaceSourceWindowsHWND;
WGPUSurface _glfwCreateWindowWGPUSurfaceWin32(WGPUInstance instance, _GLFWwindow *window) {
WGPUSurfaceSourceWindowsHWND windowsSurface;
windowsSurface.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
windowsSurface.chain.next = NULL;
windowsSurface.hinstance = _glfw.win32.instance;
windowsSurface.hwnd = window->win32.handle;
WGPUSurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.nextInChain = &windowsSurface.chain;
surfaceDescriptor.label = (WGPUStringView){ NULL, SIZE_MAX };
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
}
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{ {
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);