Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastian Emanuel Dawid
1471e07ceb Partially Revert "Remove function to pass address of wgpuInstanceCreateSurface."
This reverts commit 8c2f255906.
2025-09-29 15:30:00 +02:00
Sebastian Emanuel Dawid
044774dcee Provide weak default implementation for wgpuInstanceCreateSurface 2025-09-29 14:40:31 +02:00
4 changed files with 35 additions and 3 deletions

View File

@ -73,8 +73,16 @@ int main(void)
exit(EXIT_FAILURE);
}
WGPUAdapter adapter;
WGPUSurface surface = glfwCreateWindowWGPUSurface(instance, window);
if (!surface)
{
fprintf(stderr, "Error: Failed to create WebGPU surface.\n");
wgpuInstanceRelease(instance);
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_FAILURE);
}
WGPUAdapter adapter;
WGPUDevice device;
WGPUQueue queue;
bool success = false;

View File

@ -6536,6 +6536,19 @@ 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.

View File

@ -367,7 +367,8 @@ typedef struct WGPUSurfaceDescriptor
WGPUStringView label;
} WGPUSurfaceDescriptor;
extern WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor) __attribute((weak));
typedef WGPUSurface (*PFN_wgpuInstanceCreateSurface)(WGPUInstance, const WGPUSurfaceDescriptor*);
#define wgpuInstanceCreateSurface _glfw.wgpu.instanceCreateSurface
#include "platform.h"
@ -914,6 +915,10 @@ struct _GLFWlibrary
GLFWbool EXT_headless_surface;
} vk;
struct {
PFN_wgpuInstanceCreateSurface instanceCreateSurface;
} wgpu;
struct {
GLFWmonitorfun monitor;
GLFWjoystickfun joystick;

View File

@ -29,6 +29,12 @@
#include <assert.h>
#include <stdlib.h>
GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*))
{
_GLFW_REQUIRE_INIT()
_glfw.wgpu.instanceCreateSurface = addr;
}
GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL)
@ -37,7 +43,7 @@ GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindo
assert(window != NULL);
assert(instance != NULL);
assert(&wgpuInstanceCreateSurface != NULL);
assert(_glfw.wgpu.instanceCreateSurface != NULL);
if (window->context.client != GLFW_NO_API)
{