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

* Fix clang Objective-C++ flags for macOS command line builds

* Fix getAssetPath() and getShaderBasePath() for macOS command line builds

* Protect debugUtilsMessageCallback() from failing when pMessageIdName is NULL

* Fix a few clang function override and mismatched type warnings

* Fix validation layer warnings on exit for computeraytracing example

* Fix regression in text visibility toggle for textOverlay example

* Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACOS_MVK / DVK_USE_PLATFORM_IOS_MVK

* Check dynamic state features before enabling capabilities in dynamicstate example

* Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesystem example

* Update examples list and restore benchmarking script (to top level)

* Fix validation warning in descriptorindexing example

* Fix device max recursion depth validation warnings in ray tracing examples

* Fix OpenMP build settings for texture3d example on all platforms

* Update and simplify build instructions for macOS

* Update CI script with correct library path for libomp on macOS x86_64

* Update CI scipt to install libomp prior to macOS builds

* Trying one more time to get the CI script working for macOS libomp

* Fix vertexCount argument using calculated size in particlesystem example

* Fix combined image descriptor offset calculation in descriptorbuffer example

* macOS: Support non-system level Vulkan SDK installs, with fallback to MoltenVK library
This commit is contained in:
SRSaunders 2024-05-04 07:53:08 -04:00 committed by GitHub
parent 4a0c8b8f23
commit bdfd4709ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 320 additions and 88 deletions

View file

@ -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 .

View file

@ -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```

View file

@ -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)
@ -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)

View file

@ -105,7 +105,7 @@ public:
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 {

View file

@ -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) {

View file

@ -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
@ -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))
{

View file

@ -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)
@ -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)
@ -264,7 +273,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);

View file

@ -60,6 +60,8 @@ public:
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)

View file

@ -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)
@ -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)

View file

@ -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

View file

@ -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;
@ -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)
@ -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())
{
@ -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())
{
@ -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
@ -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)
@ -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) {
@ -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>
{
@ -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,
@ -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;
}
@ -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)

View file

@ -238,8 +238,11 @@ public:
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
@ -295,7 +298,7 @@ public:
#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);
@ -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; \

116
benchmark-all-validate.py Normal file
View file

@ -0,0 +1,116 @@
# Benchmark all examples
import subprocess
import sys
import os
import platform
EXAMPLES = [
"bloom",
"computecloth",
"computecullandlod",
"computenbody",
"computeparticles",
"computeraytracing",
"computeshader",
"conditionalrender",
"conservativeraster",
"debugprintf",
"debugutils",
"deferred",
"deferredmultisampling",
"deferredshadows",
"descriptorbuffer",
"descriptorindexing",
"descriptorsets",
"displacement",
"distancefieldfonts",
"dynamicrendering",
"dynamicstate",
"dynamicuniformbuffer",
"gears",
"geometryshader",
"gltfloading",
"gltfscenerendering",
"gltfskinning",
"graphicspipelinelibrary",
"hdr",
"imgui",
"indirectdraw",
"inlineuniformblocks",
"inputattachments",
"instancing",
"meshshader",
"multisampling",
"multithreading",
"multiview",
"negativeviewportheight",
"occlusionquery",
"offscreen",
"oit",
"parallaxmapping",
"particlesystem",
"pbrbasic",
"pbribl",
"pbrtexture",
"pipelines",
"pipelinestatistics",
"pushconstants",
"pushdescriptors",
"radialblur",
"rayquery",
"raytracingbasic",
"raytracingcallable",
"raytracinggltf",
"raytracingintersection",
"raytracingpositionfetch",
"raytracingreflections",
"raytracingsbtdata",
"raytracingshadows",
"raytracingtextures",
"shaderobjects",
"shadowmapping",
"shadowmappingcascade",
"shadowmappingomni",
"specializationconstants",
"sphericalenvmapping",
"ssao",
"stencilbuffer",
"subpasses",
"terraintessellation",
"tessellation",
"textoverlay",
"texture",
"texture3d",
"texturearray",
"texturecubemap",
"texturecubemaparray",
"texturemipmapgen",
"texturesparseresidency",
"triangle",
"variablerateshading",
"vertexattributes",
"viewportarray",
"vulkanscene"
]
CURR_INDEX = 0
ARGS = "-fullscreen -b -br 2 -v"
print("Benchmarking all examples...")
os.makedirs("./benchmark", exist_ok=True)
for example in EXAMPLES:
print("---- (%d/%d) Running %s in benchmark mode ----" % (CURR_INDEX+1, len(EXAMPLES), example))
if platform.system() == 'Linux' or platform.system() == 'Darwin':
RESULT_CODE = subprocess.call("./%s %s -bf ./benchmark/%s.csv 5" % (example, ARGS, example), shell=True)
else:
RESULT_CODE = subprocess.call("%s %s -bf ./benchmark/%s.csv 5" % (example, ARGS, example))
if RESULT_CODE == 0:
print("Results written to ./benchmark/%s.csv" % example)
else:
print("Error, result code = %d" % RESULT_CODE)
CURR_INDEX += 1
print("Benchmark run finished")

View file

@ -65,7 +65,9 @@ function(buildExample EXAMPLE_NAME)
endif()
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
link_directories(${OpenMP_CXX_LIBRARY_DIRS})
set_target_properties(${EXAMPLE_NAME} PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
target_include_directories(${EXAMPLE_NAME} PRIVATE ${OpenMP_CXX_INCLUDE_DIRS})
target_link_libraries(${EXAMPLE_NAME} ${OpenMP_CXX_LIBRARIES})
endif()
endif()

View file

@ -24,7 +24,7 @@
#include <iostream>
#include <algorithm>
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#define VK_ENABLE_BETA_EXTENSIONS
#endif
#include <vulkan/vulkan.h>
@ -177,7 +177,7 @@ public:
instanceCreateInfo.enabledLayerCount = layerCount;
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - When running on macOS with MoltenVK, enable VK_KHR_get_physical_device_properties2 (required by VK_KHR_portability_subset)
instanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
#if defined(VK_KHR_portability_enumeration)
@ -260,7 +260,7 @@ public:
deviceCreateInfo.queueCreateInfoCount = 1;
deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo;
std::vector<const char*> deviceExtensions = {};
#if defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_KHR_portability_subset)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_KHR_portability_subset)
// SRS - When running on macOS with MoltenVK and VK_KHR_portability_subset is defined and supported by the device, enable the extension
uint32_t deviceExtCount = 0;
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &deviceExtCount, nullptr);

View file

@ -86,7 +86,7 @@ public:
camera.rotationSpeed = 0.0f;
camera.movementSpeed = 2.5f;
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - on macOS set environment variable to ensure MoltenVK disables Metal argument buffers for this example
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "0", 1);
#endif
@ -429,6 +429,8 @@ public:
VkBufferCopy copyRegion = { 0, 0, storageBufferSize};
vkCmdCopyBuffer(copyCmd, stagingBuffer.buffer, compute.objectStorageBuffer.buffer, 1, &copyRegion);
vulkanDevice->flushCommandBuffer(copyCmd, queue, true);
stagingBuffer.destroy();
}
// The descriptor pool will be shared between graphics and compute

View file

@ -56,6 +56,7 @@ public:
// [POI] Enable required extensions
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE3_EXTENSION_NAME);
enabledDeviceExtensions.push_back(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
@ -67,7 +68,7 @@ public:
deviceCreatepNextChain = &physicalDeviceDescriptorIndexingFeatures;
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - on macOS set environment variable to configure MoltenVK for using Metal argument buffers (needed for descriptor indexing)
// - MoltenVK supports Metal argument buffers on macOS, iOS possible in future (see https://github.com/KhronosGroup/MoltenVK/issues/1651)
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "1", 1);
@ -213,7 +214,7 @@ public:
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast<uint32_t>(textures.size()))
};
VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, 2);
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
descriptorPoolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT;
#endif
@ -243,7 +244,7 @@ public:
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
descriptorSetLayoutCI.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
#endif

View file

@ -94,23 +94,35 @@ public:
void getEnabledExtensions()
{
// Get the full list of extended dynamic state features supported by the device
extendedDynamicStateFeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
extendedDynamicStateFeaturesEXT.pNext = &extendedDynamicState2FeaturesEXT;
extendedDynamicState2FeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT;
extendedDynamicState2FeaturesEXT.pNext = &extendedDynamicState3FeaturesEXT;
extendedDynamicState3FeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT;
extendedDynamicState3FeaturesEXT.pNext = nullptr;
VkPhysicalDeviceFeatures2 physicalDeviceFeatures2;
physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
physicalDeviceFeatures2.pNext = &extendedDynamicStateFeaturesEXT;
vkGetPhysicalDeviceFeatures2(physicalDevice, &physicalDeviceFeatures2);
// Check what dynamic states are supported by the current implementation
hasDynamicState = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
hasDynamicState2 = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
hasDynamicState3 = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME);
// Checking for available features is probably sufficient, but retained redundant extension checks for clarity and consistency
hasDynamicState = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) && extendedDynamicStateFeaturesEXT.extendedDynamicState;
hasDynamicState2 = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME) && extendedDynamicState2FeaturesEXT.extendedDynamicState2;
hasDynamicState3 = vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME) && extendedDynamicState3FeaturesEXT.extendedDynamicState3ColorBlendEnable && extendedDynamicState3FeaturesEXT.extendedDynamicState3ColorBlendEquation;
hasDynamicVertexState = vulkanDevice->extensionSupported(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
// Enable dynamic state extensions if present. This function is called after physical and before logical device creation, so we can enabled extensions based on a list of supported extensions
if (vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME)) {
if (hasDynamicState) {
enabledDeviceExtensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
extendedDynamicStateFeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
extendedDynamicStateFeaturesEXT.extendedDynamicState = VK_TRUE;
extendedDynamicStateFeaturesEXT.pNext = nullptr;
deviceCreatepNextChain = &extendedDynamicStateFeaturesEXT;
}
if (vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME)) {
if (hasDynamicState2) {
enabledDeviceExtensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
extendedDynamicState2FeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT;
extendedDynamicState2FeaturesEXT.extendedDynamicState2 = VK_TRUE;
extendedDynamicState2FeaturesEXT.pNext = nullptr;
if (hasDynamicState) {
extendedDynamicStateFeaturesEXT.pNext = &extendedDynamicState2FeaturesEXT;
}
@ -118,11 +130,8 @@ public:
deviceCreatepNextChain = &extendedDynamicState2FeaturesEXT;
}
}
if (vulkanDevice->extensionSupported(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME)) {
if (hasDynamicState3) {
enabledDeviceExtensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME);
extendedDynamicState3FeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT;
extendedDynamicState3FeaturesEXT.extendedDynamicState3ColorBlendEnable = VK_TRUE;
extendedDynamicState3FeaturesEXT.extendedDynamicState3ColorBlendEquation = VK_TRUE;
if (hasDynamicState2) {
extendedDynamicState2FeaturesEXT.pNext = &extendedDynamicState3FeaturesEXT;
}
@ -131,7 +140,7 @@ public:
}
}
if (vulkanDevice->extensionSupported(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME)) {
if (hasDynamicVertexState) {
enabledDeviceExtensions.push_back(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
}
}
@ -377,7 +386,7 @@ public:
rebuildCB |= overlay->checkBox("Depth test", &dynamicState.depthTest);
rebuildCB |= overlay->checkBox("Depth write", &dynamicState.depthWrite);
} else {
overlay->text("Extension not supported");
overlay->text("Extension or features not supported");
}
}
if (overlay->header("Dynamic state 2")) {
@ -385,7 +394,7 @@ public:
rebuildCB |= overlay->checkBox("Rasterizer discard", &dynamicState2.rasterizerDiscardEnable);
}
else {
overlay->text("Extension not supported");
overlay->text("Extension or features not supported");
}
}
if (overlay->header("Dynamic state 3")) {
@ -394,7 +403,7 @@ public:
rebuildCB |= overlay->colorPicker("Clear color", clearColor);
}
else {
overlay->text("Extension not supported");
overlay->text("Extension or features not supported");
}
}
if (rebuildCB) {

View file

@ -185,7 +185,7 @@ public:
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
#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 - On macOS/iOS use linear tiling for atomic image access, see https://github.com/KhronosGroup/MoltenVK/issues/1027
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
#else

View file

@ -189,7 +189,7 @@ public:
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.particles, 0, nullptr);
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.particles);
vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &particles.buffer, offsets);
vkCmdDraw(drawCmdBuffers[i], static_cast<uint32_t>(particles.size), 1, 0, 0);
vkCmdDraw(drawCmdBuffers[i], static_cast<uint32_t>(particleBuffer.size()), 1, 0, 0);
drawUI(drawCmdBuffers[i]);

View file

@ -463,12 +463,20 @@ public:
shaderGroups.push_back(shaderGroup);
}
// Get max pipeline ray tracing recursion depth for physical device
VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {};
physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR;
VkPhysicalDeviceProperties2 physicalDeviceProperties2;
physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR;
vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2);
VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR();
rayTracingPipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
rayTracingPipelineCI.pStages = shaderStages.data();
rayTracingPipelineCI.groupCount = static_cast<uint32_t>(shaderGroups.size());
rayTracingPipelineCI.pGroups = shaderGroups.data();
rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2;
rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth);
rayTracingPipelineCI.layout = pipelineLayout;
VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline));
}

View file

@ -431,12 +431,20 @@ public:
shaderGroups.push_back(shaderGroup);
}
// Get max pipeline ray tracing recursion depth for physical device
VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {};
physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR;
VkPhysicalDeviceProperties2 physicalDeviceProperties2;
physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR;
vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2);
VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR();
rayTracingPipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
rayTracingPipelineCI.pStages = shaderStages.data();
rayTracingPipelineCI.groupCount = static_cast<uint32_t>(shaderGroups.size());
rayTracingPipelineCI.pGroups = shaderGroups.data();
rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2;
rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth);
rayTracingPipelineCI.layout = pipelineLayout;
VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline));
}

View file

@ -393,12 +393,20 @@ public:
shaderGroups.push_back(shaderGroup);
}
// Get max pipeline ray tracing recursion depth for physical device
VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {};
physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR;
VkPhysicalDeviceProperties2 physicalDeviceProperties2;
physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR;
vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2);
VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR();
rayTracingPipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
rayTracingPipelineCI.pStages = shaderStages.data();
rayTracingPipelineCI.groupCount = static_cast<uint32_t>(shaderGroups.size());
rayTracingPipelineCI.pGroups = shaderGroups.data();
rayTracingPipelineCI.maxPipelineRayRecursionDepth = 4;
rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(4), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth);
rayTracingPipelineCI.layout = pipelineLayout;
VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline));
}

View file

@ -393,12 +393,20 @@ public:
shaderGroups.push_back(shaderGroup);
}
// Get max pipeline ray tracing recursion depth for physical device
VkPhysicalDeviceRayTracingPipelinePropertiesKHR physicalDeviceRayTracingPipelinePropertiesKHR {};
physicalDeviceRayTracingPipelinePropertiesKHR.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR;
VkPhysicalDeviceProperties2 physicalDeviceProperties2;
physicalDeviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
physicalDeviceProperties2.pNext = &physicalDeviceRayTracingPipelinePropertiesKHR;
vkGetPhysicalDeviceProperties2(physicalDevice, &physicalDeviceProperties2);
VkRayTracingPipelineCreateInfoKHR rayTracingPipelineCI = vks::initializers::rayTracingPipelineCreateInfoKHR();
rayTracingPipelineCI.stageCount = static_cast<uint32_t>(shaderStages.size());
rayTracingPipelineCI.pStages = shaderStages.data();
rayTracingPipelineCI.groupCount = static_cast<uint32_t>(shaderGroups.size());
rayTracingPipelineCI.pGroups = shaderGroups.data();
rayTracingPipelineCI.maxPipelineRayRecursionDepth = 2;
rayTracingPipelineCI.maxPipelineRayRecursionDepth = std::min(uint32_t(2), physicalDeviceRayTracingPipelinePropertiesKHR.maxRayRecursionDepth);
rayTracingPipelineCI.layout = pipelineLayout;
VK_CHECK_RESULT(vkCreateRayTracingPipelinesKHR(device, VK_NULL_HANDLE, VK_NULL_HANDLE, 1, &rayTracingPipelineCI, nullptr, &pipeline));
}

View file

@ -30,7 +30,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
#define VK_ENABLE_BETA_EXTENSIONS
#endif
#include <vulkan/vulkan.h>
@ -208,7 +208,7 @@ public:
instanceCreateInfo.enabledLayerCount = layerCount;
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - When running on macOS with MoltenVK, enable VK_KHR_get_physical_device_properties2 (required by VK_KHR_portability_subset)
instanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
#if defined(VK_KHR_portability_enumeration)
@ -290,7 +290,7 @@ public:
deviceCreateInfo.queueCreateInfoCount = 1;
deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo;
std::vector<const char*> deviceExtensions = {};
#if defined(VK_USE_PLATFORM_MACOS_MVK) && defined(VK_KHR_portability_subset)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_KHR_portability_subset)
// SRS - When running on macOS with MoltenVK and VK_KHR_portability_subset is defined and supported by the device, enable the extension
uint32_t deviceExtCount = 0;
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &deviceExtCount, nullptr);

View file

@ -47,7 +47,7 @@ public:
camera.setRotation(glm::vec3(-40.0f, -90.0f, 0.0f));
camera.setTranslation(glm::vec3(0.0f, 0.0f, -2.0f));
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
// SRS - on macOS set environment variable to ensure MoltenVK disables Metal argument buffers for this example
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "0", 1);
#endif

View file

@ -516,7 +516,9 @@ public:
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
model.draw(drawCmdBuffers[i]);
textOverlay->draw(drawCmdBuffers[i]);
if (textOverlay->visible) {
textOverlay->draw(drawCmdBuffers[i]);
}
vkCmdEndRenderPass(drawCmdBuffers[i]);
@ -709,6 +711,7 @@ public:
case KEY_KPADD:
case KEY_SPACE:
textOverlay->visible = !textOverlay->visible;
buildCommandBuffers();
}
}
};

View file

@ -1160,7 +1160,7 @@ int main(const int argc, const char *argv[])
delete(vulkanExample);
return 0;
}
#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)
VulkanExample *vulkanExample;
int main(const int argc, const char *argv[])
{

View file

@ -53,18 +53,18 @@ public:
VulkanExample();
~VulkanExample();
virtual void getEnabledFeatures();
virtual void getEnabledFeatures() override;
void handleResize();
void buildCommandBuffers();
void buildCommandBuffers() override;
void loadAssets();
void prepareShadingRateImage();
void setupDescriptors();
void preparePipelines();
void prepareUniformBuffers();
void updateUniformBuffers();
void prepare();
void prepare() override;
void setupFrameBuffer() override;
void setupRenderPass() override;
virtual void render();
virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay);
};
virtual void render() override;
virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay) override;
};