From cb0c28908f78ddef154e55a9fc3fda43f2829108 Mon Sep 17 00:00:00 2001 From: Sebastian Emanuel Dawid Date: Fri, 15 Aug 2025 23:38:04 +0200 Subject: [PATCH] Try loading surface creation function via `dlsym` instead --- include/GLFW/glfw3.h | 13 ------------- src/init.c | 2 ++ src/internal.h | 2 ++ src/webgpu.c | 11 +++++++---- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 516852a9..f920bd7b 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -6531,19 +6531,6 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window #if defined(WEBGPU_H_) -/*! @brief Provide the address of the `wgpuInstanceCreateSurface` function to GLFW. - * - * This function passes the address provided for the `wgpuInstanceCreateSurface` function - * to GLFW. - * - * @param[in] addr The address of the `wgpuInstanceCreateSurface` function. - * - * @since Added in version 3.5 - * - * @ingroup webgpu - */ -GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)); - /*! @brief Creates a WebGPU surface for the specified window. * * This function creates a WebGPU surface for the specified window. diff --git a/src/init.c b/src/init.c index dbd5a900..d31d111e 100644 --- a/src/init.c +++ b/src/init.c @@ -402,6 +402,8 @@ GLFWAPI int glfwInit(void) if (!_glfwSelectPlatform(_glfw.hints.init.platformID, &_glfw.platform)) return GLFW_FALSE; + _glfwLoadWGPUInstanceCreateSurfaceAddr(); + if (!_glfw.platform.init()) { terminate(); diff --git a/src/internal.h b/src/internal.h index 1ee044c9..4b860140 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1051,6 +1051,8 @@ GLFWbool _glfwInitVulkan(int mode); void _glfwTerminateVulkan(void); const char* _glfwGetVulkanResultString(VkResult result); +void _glfwLoadWGPUInstanceCreateSurfaceAddr(void); + size_t _glfwEncodeUTF8(char* s, uint32_t codepoint); char** _glfwParseUriList(char* text, int* count); diff --git a/src/webgpu.c b/src/webgpu.c index 7a32cfe3..5b841bc2 100644 --- a/src/webgpu.c +++ b/src/webgpu.c @@ -28,11 +28,14 @@ #include #include - -GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)) { - _GLFW_REQUIRE_INIT() - _glfw.wgpu.instanceCreateSurface = addr; +#if defined(_GLFW_WIN32) +// TODO: Implement Window version +#else +#include +void _glfwLoadWGPUInstanceCreateSurfaceAddr() { + _glfw.wgpu.instanceCreateSurface = dlsym(RTLD_DEFAULT, "wgpuInstanceCreateSurface"); } +#endif GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL)