Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions replay/Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#define GLFW_EXPOSE_NATIVE_X11
#endif
#include <GLFW/glfw3native.h>
#if __APPLE__
#include <QuartzCore/CAMetalLayer.h>
#include <AppKit/AppKit.h>
#endif
#endif

namespace WebGPUNativeReplay {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion replay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()