diff --git a/.gitmodules b/.gitmodules index ae4c65c07..51fa23b89 100644 --- a/.gitmodules +++ b/.gitmodules @@ -112,4 +112,9 @@ path = deps/Tencent/rapidjson url = https://github.com/Tencent/rapidjson ignore = dirty - branch = master \ No newline at end of file + branch = master +[submodule "glfw3webgpu"] + path = deps/eliemichel/glfw3webgpu + url = https://github.com/eliemichel/glfw3webgpu + ignore = dirty + branch = main \ No newline at end of file diff --git a/Runtime/Bindings/FFI/glfw/glfw.lua b/Runtime/Bindings/FFI/glfw/glfw.lua index 6896bf379..517b583d0 100644 --- a/Runtime/Bindings/FFI/glfw/glfw.lua +++ b/Runtime/Bindings/FFI/glfw/glfw.lua @@ -34,7 +34,7 @@ struct static_glfw_exports_table { const char* (*glfw_version)(void); int (*glfw_find_constant)(const char* name); - WGPUSurface (*glfw_get_wgpu_surface)(WGPUInstance instance, GLFWwindow* window); + WGPUSurface (*glfw_create_window_wgpu_surface)(WGPUInstance instance, GLFWwindow* window); int (*glfw_init)(void); void (*glfw_terminate)(void); diff --git a/Runtime/Bindings/FFI/glfw/glfw_exports.h b/Runtime/Bindings/FFI/glfw/glfw_exports.h index 3e3f37938..8fd6e04bb 100644 --- a/Runtime/Bindings/FFI/glfw/glfw_exports.h +++ b/Runtime/Bindings/FFI/glfw/glfw_exports.h @@ -2,7 +2,7 @@ struct static_glfw_exports_table { const char* (*glfw_version)(void); int (*glfw_find_constant)(const char* name); - WGPUSurface (*glfw_get_wgpu_surface)(WGPUInstance instance, GLFWwindow* window); + WGPUSurface (*glfw_create_window_wgpu_surface)(WGPUInstance instance, GLFWwindow* window); int (*glfw_init)(void); void (*glfw_terminate)(void); diff --git a/Runtime/Bindings/FFI/glfw/glfw_ffi.cpp b/Runtime/Bindings/FFI/glfw/glfw_ffi.cpp index c51e162a4..c38c0fcc4 100644 --- a/Runtime/Bindings/FFI/glfw/glfw_ffi.cpp +++ b/Runtime/Bindings/FFI/glfw/glfw_ffi.cpp @@ -230,7 +230,7 @@ namespace glfw_ffi { exports.glfw_version = glfw_version; exports.glfw_find_constant = glfw_find_constant; - exports.glfw_get_wgpu_surface = glfwGetWGPUSurface; + exports.glfw_create_window_wgpu_surface = glfwCreateWindowWGPUSurface; exports.glfw_init = glfwInit; exports.glfw_terminate = glfwTerminate; diff --git a/Runtime/Bindings/FFI/wgpu/webgpu/webgpu.h b/Runtime/Bindings/FFI/wgpu/webgpu/webgpu.h new file mode 100644 index 000000000..e227b62f9 --- /dev/null +++ b/Runtime/Bindings/FFI/wgpu/webgpu/webgpu.h @@ -0,0 +1,3 @@ +// Workaround for the hardcoded header path in glfw3wgpu - remove later + +#include \ No newline at end of file diff --git a/Tests/BDD/glfw-library.spec.lua b/Tests/BDD/glfw-library.spec.lua index e729896b2..bf01d534f 100644 --- a/Tests/BDD/glfw-library.spec.lua +++ b/Tests/BDD/glfw-library.spec.lua @@ -6,7 +6,7 @@ describe("glfw", function() local exportedApiSurface = { "glfw_version", "glfw_find_constant", - "glfw_get_wgpu_surface", + "glfw_create_window_wgpu_surface", "glfw_init", "glfw_terminate", "glfw_poll_events", diff --git a/Tests/BDD/runtime-library.spec.lua b/Tests/BDD/runtime-library.spec.lua index c1392c040..22dc55420 100644 --- a/Tests/BDD/runtime-library.spec.lua +++ b/Tests/BDD/runtime-library.spec.lua @@ -68,7 +68,7 @@ describe("runtime", function() assertSubmoduleVersion(runtime.submodules["deps/zhaog/lua-openssl"]) assertSubmoduleVersion(runtime.submodules["deps/Tencent/rapidjson"]) - assertEquals(table.count(runtime.submodules), 23) + assertEquals(table.count(runtime.submodules), 24) end) end) end) diff --git a/Tests/Integration/glfw-webgpu-surface.lua b/Tests/Integration/glfw-webgpu-surface.lua index 499d64a53..c2504b2b6 100644 --- a/Tests/Integration/glfw-webgpu-surface.lua +++ b/Tests/Integration/glfw-webgpu-surface.lua @@ -26,7 +26,7 @@ local window = glfw.bindings.glfw_create_window(640, 480, "WebGPU Surface Test", assert(window, "Failed to create window") print("Requesting adapter...") -local surface = glfw.bindings.glfw_get_wgpu_surface(instance, window) +local surface = glfw.bindings.glfw_create_window_wgpu_surface(instance, window) assert(surface, "Failed to create WebGPU surface") local adapterOpts = ffi.new("WGPURequestAdapterOptions") diff --git a/Tests/Integration/rml-glfw-wgpu-setup.lua b/Tests/Integration/rml-glfw-wgpu-setup.lua index 71e87455a..477057b53 100644 --- a/Tests/Integration/rml-glfw-wgpu-setup.lua +++ b/Tests/Integration/rml-glfw-wgpu-setup.lua @@ -32,7 +32,7 @@ local function createDevice(window) error("Could not initialize WebGPU!") end - local surface = glfw.bindings.glfw_get_wgpu_surface(instance, window) + local surface = glfw.bindings.glfw_create_window_wgpu_surface(instance, window) assert(surface, "Failed to create WebGPU surface") local adapterOptions = ffi.new("WGPURequestAdapterOptions") diff --git a/deps/eliemichel/glfw3webgpu b/deps/eliemichel/glfw3webgpu new file mode 160000 index 000000000..9a240a807 --- /dev/null +++ b/deps/eliemichel/glfw3webgpu @@ -0,0 +1 @@ +Subproject commit 9a240a807a2d7cc6f16914b718d363469aaf0ed0 diff --git a/deps/eliemichel/glfw3webgpu/glfw3webgpu.c b/deps/eliemichel/glfw3webgpu/glfw3webgpu.c deleted file mode 100644 index 996db76f7..000000000 --- a/deps/eliemichel/glfw3webgpu/glfw3webgpu.c +++ /dev/null @@ -1,161 +0,0 @@ -/** - * This is an extension of GLFW for WebGPU, abstracting away the details of - * OS-specific operations. - * - * This file is part of the "Learn WebGPU for C++" book. - * https://eliemichel.github.io/LearnWebGPU - * - * Most of this code comes from the wgpu-native triangle example: - * https://github.com/gfx-rs/wgpu-native/blob/master/examples/triangle/main.c - * - * MIT License - * Copyright (c) 2022-2023 Elie Michel and the wgpu-native authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "glfw3webgpu.h" - -#include - -#define WGPU_TARGET_MACOS 1 -#define WGPU_TARGET_LINUX_X11 2 -#define WGPU_TARGET_WINDOWS 3 -#define WGPU_TARGET_LINUX_WAYLAND 4 -#define WGPU_TARGET_EMSCRIPTEN 5 - -#if defined(__EMSCRIPTEN__) -#define WGPU_TARGET WGPU_TARGET_EMSCRIPTEN -#elif defined(_WIN32) -#define WGPU_TARGET WGPU_TARGET_WINDOWS -#elif defined(__APPLE__) -#define WGPU_TARGET WGPU_TARGET_MACOS -#elif defined(_GLFW_WAYLAND) -#define WGPU_TARGET WGPU_TARGET_LINUX_WAYLAND -#else -#define WGPU_TARGET WGPU_TARGET_LINUX_X11 -#endif - -#if WGPU_TARGET == WGPU_TARGET_MACOS -#include -#include -#endif - -#include -#if WGPU_TARGET == WGPU_TARGET_MACOS -#define GLFW_EXPOSE_NATIVE_COCOA -#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11 -#define GLFW_EXPOSE_NATIVE_X11 -#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND -#define GLFW_EXPOSE_NATIVE_WAYLAND -#elif WGPU_TARGET == WGPU_TARGET_WINDOWS -#define GLFW_EXPOSE_NATIVE_WIN32 -#endif - -#if !defined(__EMSCRIPTEN__) -#include -#endif - -WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { -#if WGPU_TARGET == WGPU_TARGET_MACOS - { - id metal_layer = [CAMetalLayer layer]; - NSWindow* ns_window = glfwGetCocoaWindow(window); - [ns_window.contentView setWantsLayer : YES] ; - [ns_window.contentView setLayer : metal_layer] ; - - WGPUSurfaceDescriptorFromMetalLayer fromMetalLayer; - fromMetalLayer.chain.next = NULL; - fromMetalLayer.chain.sType = WGPUSType_SurfaceDescriptorFromMetalLayer; - fromMetalLayer.layer = metal_layer; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = &fromMetalLayer.chain; - surfaceDescriptor.label = NULL; - - return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); - } -#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11 - { - Display* x11_display = glfwGetX11Display(); - Window x11_window = glfwGetX11Window(window); - - WGPUSurfaceDescriptorFromXlibWindow fromXlibWindow; - fromXlibWindow.chain.next = NULL; - fromXlibWindow.chain.sType = WGPUSType_SurfaceDescriptorFromXlibWindow; - fromXlibWindow.display = x11_display; - fromXlibWindow.window = x11_window; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = &fromXlibWindow.chain; - surfaceDescriptor.label = NULL; - - return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); - } -#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND - { - struct wl_display* wayland_display = glfwGetWaylandDisplay(); - struct wl_surface* wayland_surface = glfwGetWaylandWindow(window); - - WGPUSurfaceDescriptorFromWaylandSurface fromWaylandSurface; - fromWaylandSurface.chain.next = NULL; - fromWaylandSurface.chain.sType = WGPUSType_SurfaceDescriptorFromWaylandSurface; - fromWaylandSurface.display = wayland_display; - fromWaylandSurface.surface = wayland_surface; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = &fromWaylandSurface.chain; - surfaceDescriptor.label = NULL; - - return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); - } -#elif WGPU_TARGET == WGPU_TARGET_WINDOWS - { - HWND hwnd = glfwGetWin32Window(window); - HINSTANCE hinstance = GetModuleHandle(NULL); - - WGPUSurfaceDescriptorFromWindowsHWND fromWindowsHWND; - fromWindowsHWND.chain.next = NULL; - fromWindowsHWND.chain.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND; - fromWindowsHWND.hinstance = hinstance; - fromWindowsHWND.hwnd = hwnd; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = &fromWindowsHWND.chain; - surfaceDescriptor.label = NULL; - - return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); - } -#elif WGPU_TARGET == WGPU_TARGET_EMSCRIPTEN - { - WGPUSurfaceDescriptorFromCanvasHTMLSelector fromCanvasHTMLSelector; - fromCanvasHTMLSelector.chain.next = NULL; - fromCanvasHTMLSelector.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; - fromCanvasHTMLSelector.selector = "canvas"; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = &fromCanvasHTMLSelector.chain; - surfaceDescriptor.label = NULL; - - return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); - } -#else -#error "Unsupported WGPU_TARGET" -#endif -} diff --git a/deps/eliemichel/glfw3webgpu/glfw3webgpu.h b/deps/eliemichel/glfw3webgpu/glfw3webgpu.h deleted file mode 100644 index e469c7f38..000000000 --- a/deps/eliemichel/glfw3webgpu/glfw3webgpu.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * This is an extension of GLFW for WebGPU, abstracting away the details of - * OS-specific operations. - * - * This file is part of the "Learn WebGPU for C++" book. - * https://eliemichel.github.io/LearnWebGPU - * - * MIT License - * Copyright (c) 2022-2023 Elie Michel and the wgpu-native authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef _glfw3_webgpu_h_ -#define _glfw3_webgpu_h_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Get a WGPUSurface from a GLFW window. - */ -WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window); - -#ifdef __cplusplus -} -#endif - -#endif // _glfw3_webgpu_h_