Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS/iOS fixes plus other generic fixes for clang and validation warnings #1117

Merged
merged 20 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0768627
Fix clang Objective-C++ flags for macOS command line builds
SRSaunders Apr 22, 2024
63c162f
Fix getAssetPath() and getShaderBasePath() for macOS command line builds
SRSaunders Apr 22, 2024
2a5d52e
Protect debugUtilsMessageCallback() from failing when pMessageIdName …
SRSaunders Apr 22, 2024
4cb9cfa
Fix a few clang function override and mismatched type warnings
SRSaunders Apr 22, 2024
559a062
Fix validation layer warnings on exit for computeraytracing example
SRSaunders Apr 22, 2024
928d167
Fix regression in text visibility toggle for textOverlay example
SRSaunders Apr 22, 2024
25baa9c
Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACO…
SRSaunders Apr 22, 2024
a4db1d0
Check dynamic state features before enabling capabilities in dynamics…
SRSaunders Apr 22, 2024
b514b89
Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesyst…
SRSaunders Apr 22, 2024
0ca319f
Update examples list and restore benchmarking script (to top level)
SRSaunders Apr 22, 2024
ee02e79
Fix validation warning in descriptorindexing example
SRSaunders Apr 22, 2024
1f333d1
Fix device max recursion depth validation warnings in ray tracing exa…
SRSaunders Apr 22, 2024
912b694
Fix OpenMP build settings for texture3d example on all platforms
SRSaunders Apr 24, 2024
2057064
Update and simplify build instructions for macOS
SRSaunders Apr 24, 2024
37941db
Update CI script with correct library path for libomp on macOS x86_64
SRSaunders Apr 24, 2024
66a9a30
Update CI scipt to install libomp prior to macOS builds
SRSaunders Apr 24, 2024
5af14dd
Trying one more time to get the CI script working for macOS libomp
SRSaunders Apr 24, 2024
99067f9
Fix vertexCount argument using calculated size in particlesystem example
SRSaunders Apr 26, 2024
73a7109
Fix combined image descriptor offset calculation in descriptorbuffer …
SRSaunders Apr 26, 2024
677b77b
macOS: Support non-system level Vulkan SDK installs, with fallback to…
SRSaunders Apr 27, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ jobs:
--root ~/VulkanSDK/latest --accept-licenses --default-answer --confirm-command install
cd ~/VulkanSDK/latest
sudo python ./install_vulkan.py
brew install libomp
brew --prefix libomp
- name: Build
run: |
cmake -G "Xcode" -DOpenMP_C_FLAGS=/usr/local/opt/libomp -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp -DOpenMP_CXX_FOUND=/usr/local/opt/libomp
cmake -G "Xcode" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib
cmake --build .
31 changes: 14 additions & 17 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,25 @@ If you want to build and install on a connected device or emulator image, run ``

If you want to build it through [Android Studio](https://developer.android.com/studio), open project folder ```android``` in Android Studio.

### <img src="./images/applelogo.png" alt="" height="32px"> [iOS and macOS](xcode/)
### <img src="./images/applelogo.png" alt="" height="32px"> macOS and iOS

**Note:** Running these examples on Mac OS and iOS requires [**MoltenVK**](https://github.com/KhronosGroup/MoltenVK) and a device that supports the *Metal* api.
**Note:** Running these examples on macOS and iOS requires [**MoltenVK**](https://github.com/KhronosGroup/MoltenVK) and a device that supports the *Metal* api.

#### MacOS
Install Libomp with:
-brew install libomp
find the path
-brew --prefix libomp
use the path from the above command to populate the path in the -DOpenMP_C_FLAGS, -DOpenMP_omp_LIBRARY & -DOpenMP_CXX_FOUND statement below
#### macOS
Download the most recent Vulkan SDK using:
```curl -O https://sdk.lunarg.com/sdk/download/latest/mac/vulkan_sdk.dmg```

Download Vulkan SDK and install it note the path as this will need to be configure in Xcode
curl -O https://sdk.lunarg.com/sdk/download/latest/mac/vulkan_sdk.dmg
Open **vulkan_sdk.dmg** and install the Vulkan SDK with *System Global Installation* selected.

Open vulkan_sdk.dmg and install Vulkan SDK
Navigate to the Vulkan SDK folder and run 'python install_vulkan.py'
Install **libomp** from [homebrew](https://brew.sh) using:
```brew install libomp```

Use the provided CMakeLists.txt with [CMake](https://cmake.org) to generate a build configuration for your favorite IDE or compiler, e.g.:
```
Example of cmake with libraries defined
cmake -G "Xcode" -DOpenMP_C_FLAGS=/usr/local/opt/libomp -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp -DOpenMP_CXX_FOUND=/usr/local/opt/libomp
```
Find the **libomp** path prefix using:
```brew --prefix libomp```

Use the **libomp** path prefix to adjust the path for ```-DOpenMP_omp_LIBRARY=``` in the cmake command below.

Use [CMake](https://cmake.org) to generate a build configuration for Xcode or your preferred build method (e.g. Unix Makefiles or Ninja).

Example of cmake generating for Xcode with **libomp** path defined for homebrew on Apple Silicon:
```cmake -G "Xcode" -DOpenMP_omp_LIBRARY=/opt/homebrew/opt/libomp/lib/libomp.dylib```
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,33 @@ ELSEIF(LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")
ENDIF(USE_D2D_WSI)
ELSEIF(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_MACOS_MVK -DVK_EXAMPLE_XCODE_GENERATED")
IF (CMAKE_GENERATOR MATCHES "Xcode")
# Suppress regeneration for Xcode since environment variables will be lost if not set in Xcode locations/custom paths
set(CMAKE_SUPPRESS_REGENERATION ON)
set(CMAKE_XCODE_GENERATE_SCHEME ON)
IF (Vulkan_FOUND)
# If the Vulkan loader was found and its environment variables are defined, make them available within Xcode schemes
IF (DEFINED ENV{VK_ADD_LAYER_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ADD_LAYER_PATH=$ENV{VK_ADD_LAYER_PATH}")
ENDIF()
IF (DEFINED ENV{VK_ICD_FILENAMES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ICD_FILENAMES=$ENV{VK_ICD_FILENAMES}")
ENDIF()
IF (DEFINED ENV{VK_DRIVER_FILES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_DRIVER_FILES=$ENV{VK_DRIVER_FILES}")
ENDIF()
ENDIF()
ENDIF()
IF (NOT Vulkan_FOUND)
# If the Vulkan loader was not found, then look for libMoltenVK.dylib in the Vulkan SDK and legacy MoltenVK locations
set(CMAKE_FIND_FRAMEWORK NEVER)
find_library(Vulkan_LIBRARY NAMES MoltenVK HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/dylib/macOS" REQUIRED)
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
MESSAGE(STATUS "Using MoltenVK Vulkan Portability library")
ENDIF()
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_METAL_EXT -DVK_EXAMPLE_XCODE_GENERATED")
# Todo : android?
ENDIF(WIN32)

Expand Down Expand Up @@ -138,11 +164,11 @@ endif()
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
ELSEIF(APPLE)
#if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -ObjC++")
#ELSE()
IF(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -ObjC++")
ELSE() # SRS - use objective-c++ language flag vs. ObjC++ for Xcode builds
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -xobjective-c++")
#ENDIF()
ENDIF()
ENDIF(MSVC)

IF(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion base/CommandLineParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CommandLineParser
std::string value = options[name].value;
if (value != "") {
char* numConvPtr;
int32_t intVal = strtol(value.c_str(), &numConvPtr, 10);
int32_t intVal = (int32_t)strtol(value.c_str(), &numConvPtr, 10);
return (intVal > 0) ? intVal : defaultValue;
}
else {
Expand Down
7 changes: 6 additions & 1 deletion base/VulkanDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ namespace vks

// Display message to default output (console/logcat)
std::stringstream debugMessage;
debugMessage << prefix << "[" << pCallbackData->messageIdNumber << "][" << pCallbackData->pMessageIdName << "] : " << pCallbackData->pMessage;
if (pCallbackData->pMessageIdName) {
debugMessage << prefix << "[" << pCallbackData->messageIdNumber << "][" << pCallbackData->pMessageIdName << "] : " << pCallbackData->pMessage;
}
else {
debugMessage << prefix << "[" << pCallbackData->messageIdNumber << "] : " << pCallbackData->pMessage;
}

#if defined(__ANDROID__)
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
Expand Down
4 changes: 2 additions & 2 deletions base/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - Enable beta extensions and make VK_KHR_portability_subset visible
#define VK_ENABLE_BETA_EXTENSIONS
#endif
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace vks
deviceCreateInfo.pNext = &physicalDeviceFeatures2;
}

#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) && defined(VK_KHR_portability_subset)
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_KHR_portability_subset)
// SRS - When running on iOS/macOS with MoltenVK and VK_KHR_portability_subset is defined and supported by the device, enable the extension
if (extensionSupported(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME))
{
Expand Down
11 changes: 10 additions & 1 deletion base/VulkanSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ void VulkanSwapChain::initSurface(wl_display *display, wl_surface *window)
void VulkanSwapChain::initSurface(xcb_connection_t* connection, xcb_window_t window)
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
void VulkanSwapChain::initSurface(void* view)
#elif defined(VK_USE_PLATFORM_METAL_EXT)
void VulkanSwapChain::initSurface(CAMetalLayer* metalLayer)
#elif (defined(_DIRECT2DISPLAY) || defined(VK_USE_PLATFORM_HEADLESS_EXT))
void VulkanSwapChain::initSurface(uint32_t width, uint32_t height)
#elif defined(VK_USE_PLATFORM_SCREEN_QNX)
Expand Down Expand Up @@ -57,6 +59,13 @@ void VulkanSwapChain::initSurface(screen_context_t screen_context, screen_window
surfaceCreateInfo.flags = 0;
surfaceCreateInfo.pView = view;
err = vkCreateMacOSSurfaceMVK(instance, &surfaceCreateInfo, NULL, &surface);
#elif defined(VK_USE_PLATFORM_METAL_EXT)
VkMetalSurfaceCreateInfoEXT surfaceCreateInfo = {};
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
surfaceCreateInfo.pNext = NULL;
surfaceCreateInfo.flags = 0;
surfaceCreateInfo.pLayer = metalLayer;
err = vkCreateMetalSurfaceEXT(instance, &surfaceCreateInfo, NULL, &surface);
#elif defined(_DIRECT2DISPLAY)
createDirect2DisplaySurface(width, height);
#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT)
Expand Down Expand Up @@ -275,7 +284,7 @@ void VulkanSwapChain::create(uint32_t *width, uint32_t *height, bool vsync, bool

// Determine the number of images
uint32_t desiredNumberOfSwapchainImages = surfCaps.minImageCount + 1;
#if (defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_EXAMPLE_XCODE_GENERATED))
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_EXAMPLE_XCODE_GENERATED)
// SRS - Work around known MoltenVK issue re 2x frame rate when vsync (VK_PRESENT_MODE_FIFO_KHR) enabled
struct utsname sysInfo;
uname(&sysInfo);
Expand Down
2 changes: 2 additions & 0 deletions base/VulkanSwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class VulkanSwapChain
void initSurface(xcb_connection_t* connection, xcb_window_t window);
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
void initSurface(void* view);
#elif defined(VK_USE_PLATFORM_METAL_EXT)
void initSurface(CAMetalLayer* metalLayer);
#elif (defined(_DIRECT2DISPLAY) || defined(VK_USE_PLATFORM_HEADLESS_EXT))
void initSurface(uint32_t width, uint32_t height);
#if defined(_DIRECT2DISPLAY)
Expand Down
7 changes: 2 additions & 5 deletions base/VulkanTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "VulkanTools.h"

#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// iOS & macOS: VulkanExampleBase::getAssetPath() implemented externally to allow access to Objective-C components
#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// iOS & macOS: getAssetPath() and getShaderBasePath() implemented externally for access to Obj-C++ path utilities
const std::string getAssetPath()
{
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -20,10 +20,7 @@ const std::string getAssetPath()
return "./../assets/";
#endif
}
#endif

#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// iOS & macOS: VulkanExampleBase::getAssetPath() implemented externally to allow access to Objective-C components
const std::string getShaderBasePath()
{
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand Down
2 changes: 1 addition & 1 deletion base/keycodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define KEY_SPACE 0x3E // AKEYCODE_SPACE
#define KEY_KPADD 0x9D // AKEYCODE_NUMPAD_ADD

#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#if !defined(VK_EXAMPLE_XCODE_GENERATED)
// For iOS and macOS pre-configured Xcode example project: Use character keycodes
// - Use numeric keys as optional alternative to function keys
Expand Down
43 changes: 35 additions & 8 deletions base/vulkanexamplebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

#include "vulkanexamplebase.h"

#if (defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_EXAMPLE_XCODE_GENERATED))
#if defined(VK_EXAMPLE_XCODE_GENERATED)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#include <Cocoa/Cocoa.h>
#include <QuartzCore/CAMetalLayer.h>
#include <CoreVideo/CVDisplayLink.h>
#endif
#else // !defined(VK_EXAMPLE_XCODE_GENERATED)
#if defined(VK_USE_PLATFORM_METAL_EXT)
// SRS - Metal layer is defined externally when using iOS/macOS displayLink-driven examples project
extern CAMetalLayer* layer;
#endif
#endif

std::vector<const char*> VulkanExampleBase::args;

Expand Down Expand Up @@ -50,6 +57,8 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
instanceExtensions.push_back(VK_MVK_IOS_SURFACE_EXTENSION_NAME);
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
instanceExtensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
#elif defined(VK_USE_PLATFORM_METAL_EXT)
instanceExtensions.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME);
#elif defined(VK_USE_PLATFORM_HEADLESS_EXT)
instanceExtensions.push_back(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME);
#elif defined(VK_USE_PLATFORM_SCREEN_QNX)
Expand All @@ -71,7 +80,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
}
}

#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - When running on iOS/macOS with MoltenVK, enable VK_KHR_get_physical_device_properties2 if not already enabled by the example (required by VK_KHR_portability_subset)
if (std::find(enabledInstanceExtensions.begin(), enabledInstanceExtensions.end(), VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == enabledInstanceExtensions.end())
{
Expand Down Expand Up @@ -106,7 +115,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
}


#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) && defined(VK_KHR_portability_enumeration)
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_KHR_portability_enumeration)
// SRS - When running on iOS/macOS with MoltenVK and VK_KHR_portability_enumeration is defined and supported by the instance, enable the extension and the flag
if (std::find(supportedInstanceExtensions.begin(), supportedInstanceExtensions.end(), VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) != supportedInstanceExtensions.end())
{
Expand Down Expand Up @@ -262,7 +271,7 @@ void VulkanExampleBase::nextFrame()
render();
frameCounter++;
auto tEnd = std::chrono::high_resolution_clock::now();
#if (defined(VK_USE_PLATFORM_IOS_MVK) || (defined(VK_USE_PLATFORM_MACOS_MVK) && !defined(VK_EXAMPLE_XCODE_GENERATED)))
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && !defined(VK_EXAMPLE_XCODE_GENERATED)
// SRS - Calculate tDiff as time between frames vs. rendering time for iOS/macOS displayLink-driven examples project
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tPrevEnd).count();
#else
Expand Down Expand Up @@ -306,7 +315,7 @@ void VulkanExampleBase::renderLoop()
{
// SRS - for non-apple plaforms, handle benchmarking here within VulkanExampleBase::renderLoop()
// - for macOS, handle benchmarking within NSApp rendering loop via displayLinkOutputCb()
#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
if (benchmark.active) {
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
while (!configured)
Expand Down Expand Up @@ -659,7 +668,7 @@ void VulkanExampleBase::renderLoop()
}
updateOverlay();
}
#elif (defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_EXAMPLE_XCODE_GENERATED))
#elif (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_EXAMPLE_XCODE_GENERATED)
[NSApp run];
#elif defined(VK_USE_PLATFORM_SCREEN_QNX)
while (!quit) {
Expand Down Expand Up @@ -1583,7 +1592,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
break;
}
}
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#if defined(VK_EXAMPLE_XCODE_GENERATED)
@interface AppDelegate : NSObject<NSApplicationDelegate>
{
Expand Down Expand Up @@ -1638,10 +1647,20 @@ dispatch_group_t concurrentGroup;
@end

const std::string getAssetPath() {
#if defined(VK_EXAMPLE_ASSETS_DIR)
return VK_EXAMPLE_ASSETS_DIR;
#else
return [NSBundle.mainBundle.resourcePath stringByAppendingString: @"/../../assets/"].UTF8String;
#endif
}

const std::string getShaderBasePath() { return [NSBundle.mainBundle.resourcePath stringByAppendingString: @"/../../shaders/"].UTF8String; }
const std::string getShaderBasePath() {
#if defined(VK_EXAMPLE_SHADERS_DIR)
return VK_EXAMPLE_SHADERS_DIR;
#else
return [NSBundle.mainBundle.resourcePath stringByAppendingString: @"/../../shaders/"].UTF8String;
#endif
}

static CVReturn displayLinkOutputCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *inNow,
const CVTimeStamp *inOutputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut,
Expand Down Expand Up @@ -1899,8 +1918,14 @@ void* VulkanExampleBase::setupWindow(void* view)
[window setDelegate:nsView];
[window setContentView:nsView];
this->view = (__bridge void*)nsView;
#if defined(VK_USE_PLATFORM_METAL_EXT)
this->metalLayer = (CAMetalLayer*)nsView.layer;
#endif
#else
this->view = view;
#if defined(VK_USE_PLATFORM_METAL_EXT)
this->metalLayer = (CAMetalLayer*)layer;
#endif
#endif
return view;
}
Expand Down Expand Up @@ -3236,6 +3261,8 @@ void VulkanExampleBase::initSwapchain()
swapChain.initSurface(androidApp->window);
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
swapChain.initSurface(view);
#elif defined(VK_USE_PLATFORM_METAL_EXT)
swapChain.initSurface(metalLayer);
#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT)
swapChain.initSurface(dfb, surface);
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
Expand Down
9 changes: 6 additions & 3 deletions base/vulkanexamplebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ class VulkanExampleBase
bool touchDown = false;
double touchTimer = 0.0;
int64_t lastTapTime = 0;
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
void* view;
#if defined(VK_USE_PLATFORM_METAL_EXT)
CAMetalLayer* metalLayer;
#endif
#if defined(VK_EXAMPLE_XCODE_GENERATED)
bool quit = false;
#endif
Expand Down Expand Up @@ -295,7 +298,7 @@ class VulkanExampleBase
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
static int32_t handleAppInput(struct android_app* app, AInputEvent* event);
static void handleAppCommand(android_app* app, int32_t cmd);
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
void* setupWindow(void* view);
void displayLinkOutputCb();
void mouseDragged(float x, float y);
Expand Down Expand Up @@ -523,7 +526,7 @@ int main(const int argc, const char *argv[]) \
delete(vulkanExample); \
return 0; \
}
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#if defined(VK_EXAMPLE_XCODE_GENERATED)
#define VULKAN_EXAMPLE_MAIN() \
VulkanExample *vulkanExample; \
Expand Down
Loading
Loading