Skip to content

Commit

Permalink
Use CAMetalLayer to create MVK surfaces to avoid potential deadlocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinKG authored and pixelflinger committed Feb 7, 2025
1 parent 68719f9 commit c16cab2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
11 changes: 2 additions & 9 deletions libs/filamentapp/src/FilamentApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,19 +704,12 @@ FilamentApp::Window::Window(FilamentApp* filamentApp,
::prepareNativeWindow(mWindow);

void* metalLayer = nullptr;
if (config.backend == filament::Engine::Backend::METAL) {
if (config.backend == filament::Engine::Backend::METAL || config.backend == filament::Engine::Backend::VULKAN) {
metalLayer = setUpMetalLayer(nativeWindow);
// The swap chain on Metal is a CAMetalLayer.
// The swap chain on both native Metal and MoltenVK is a CAMetalLayer.
nativeSwapChain = metalLayer;
}

#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
if (config.backend == filament::Engine::Backend::VULKAN) {
// We request a Metal layer for rendering via MoltenVK.
setUpMetalLayer(nativeWindow);
}
#endif

#endif

// Write back the active feature level.
Expand Down
10 changes: 2 additions & 8 deletions samples/multiple_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,11 @@ void setup_window(Window& w, Engine* engine) {
void* nativeSwapChain = nativeWindow;
#if defined(__APPLE__)
void* metalLayer = nullptr;
if (kBackend == filament::Engine::Backend::METAL) {
if (kBackend == filament::Engine::Backend::METAL || kBackend == filament::Engine::Backend::VULKAN) {
metalLayer = setUpMetalLayer(nativeWindow);
// The swap chain on Metal is a CAMetalLayer.
// The swap chain on both native Metal and MoltenVK is a CAMetalLayer.
nativeSwapChain = metalLayer;
}
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
if (kBackend == filament::Engine::Backend::VULKAN) {
// We request a Metal layer for rendering via MoltenVK.
setUpMetalLayer(nativeWindow);
}
#endif
#endif
w.swapChain = engine->createSwapChain(nativeSwapChain);

Expand Down

0 comments on commit c16cab2

Please sign in to comment.