From 618759f68444512d380ca282b0101095998afc40 Mon Sep 17 00:00:00 2001 From: Daniel <3170456+fanciful-marmot@users.noreply.github.com> Date: Wed, 3 Dec 2025 15:41:01 -0800 Subject: [PATCH] Support playback on osx --- replay/Adapter.cpp | 15 +++++++++++++-- replay/CMakeLists.txt | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/replay/Adapter.cpp b/replay/Adapter.cpp index 46b3ee2..2c229bf 100644 --- a/replay/Adapter.cpp +++ b/replay/Adapter.cpp @@ -22,6 +22,10 @@ #define GLFW_EXPOSE_NATIVE_X11 #endif #include + #if __APPLE__ + #include + #include + #endif #endif namespace WebGPUNativeReplay { @@ -102,8 +106,15 @@ void Adapter::CreateSurface(const Window& window) { platformSurfaceSource.hinstance = GetModuleHandle(NULL); platformSurfaceSource.hwnd = glfwGetWin32Window(window.window); #elif __APPLE__ -#error "WebGPU surface support has not been implemented on Mac." - /// @todo Implement WGPUSurfaceSourceMetalLayer + NSWindow* nsWindow = glfwGetCocoaWindow(window.window); + NSView* contentView = [nsWindow contentView]; + [contentView setWantsLayer:YES]; + CAMetalLayer* metalLayer = [CAMetalLayer layer]; + [contentView setLayer:metalLayer]; + WGPUSurfaceSourceMetalLayer platformSurfaceSource = {}; + platformSurfaceSource.chain.next = nullptr; + platformSurfaceSource.chain.sType = WGPUSType_SurfaceSourceMetalLayer; + platformSurfaceSource.layer = metalLayer; #elif __linux__ WGPUSurfaceSourceXlibWindow platformSurfaceSource = {}; platformSurfaceSource.chain.next = nullptr; diff --git a/replay/CMakeLists.txt b/replay/CMakeLists.txt index f18c297..010e5c5 100644 --- a/replay/CMakeLists.txt +++ b/replay/CMakeLists.txt @@ -64,6 +64,9 @@ if (WEBGPU_NATIVE_REPLAY_DAWN_BACKEND) target_compile_definitions(WebGPUNativeReplayDawn PUBLIC WEBGPU_BACKEND_DAWN) set_property(TARGET WebGPUNativeReplayDawn PROPERTY CXX_STANDARD 20) set_property(TARGET WebGPUNativeReplayDawn PROPERTY CXX_STANDARD_REQUIRED ON) + if(APPLE) + set_source_files_properties(Adapter.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") + endif() endif() # wgpu @@ -90,7 +93,7 @@ if (WEBGPU_NATIVE_REPLAY_WGPU_BACKEND) if(MSVC) set(WGPU_OS_LIBRARIES "userenv" "ws2_32" "Dwmapi" "dbghelp" "d3dcompiler" "D3D12" "D3D11" "DXGI" "setupapi" "Bcrypt" "ntdll" "opengl32" "Propsys" "RuntimeObject") elseif(APPLE) - set(WGPU_OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore") + set(WGPU_OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore" "-framework Metal") endif() # Replayer @@ -106,4 +109,7 @@ if (WEBGPU_NATIVE_REPLAY_WGPU_BACKEND) target_compile_definitions(WebGPUNativeReplayWgpu PUBLIC WEBGPU_BACKEND_WGPU) set_property(TARGET WebGPUNativeReplayWgpu PROPERTY CXX_STANDARD 20) set_property(TARGET WebGPUNativeReplayWgpu PROPERTY CXX_STANDARD_REQUIRED ON) + if(APPLE) + set_source_files_properties(Adapter.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") + endif() endif() \ No newline at end of file