Macos ios fixes (#1192)
* Configure MoltenVK to use a dedicated compute queue for compute[*] examples with sync barriers * Modify descriptorindexing example for iOS and variable descriptor count limitations on MoltenVK * Remove obsolete macOS #ifdefs no longer needed for modern MoltenVK versions * Update iOS project to fix missing vkloader.c reference and revise example list * Set required features and API version for VVL in debugprintf example * Remove unnecessary Apple-specific code from descriptorindexing example * Add Layer Settings capability to VulkanExampleBase::createInstance() * Replace setenv() in examples with Layer Settings configuration for macOS/iOS * Update comments in examples.h and fix missing initializer in computeraytracing example * Update imgui overlay and example to support iOS Simulator * Update more comments in examples.h and remove redundant initializers in deferred* examples * Separate variable descriptor count declarations for apple and non-apple platforms * Consolidate variable descriptor count declarations for apple vs. non-apple platforms * Configure MoltenVK with a dedicated compute queue in VulkanExampleBase() and remove from samples
This commit is contained in:
parent
e1c962289f
commit
9a562a5426
17 changed files with 221 additions and 83 deletions
111
apple/examples.h
111
apple/examples.h
|
|
@ -40,6 +40,11 @@
|
|||
# include "../examples/triangle/triangle.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. MoltenVK does not yet support Vulkan 1.3
|
||||
#ifdef MVK_trianglevulkan13
|
||||
# include "../examples/trianglevulkan13/trianglevulkan13.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_pipelines
|
||||
# include "../examples/pipelines/pipelines.cpp"
|
||||
#endif
|
||||
|
|
@ -72,6 +77,7 @@
|
|||
# include "../examples/texturecubemap/texturecubemap.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support cube map arrays.
|
||||
#ifdef MVK_texturecubemaparray
|
||||
# include "../examples/texturecubemaparray/texturecubemaparray.cpp"
|
||||
#endif
|
||||
|
|
@ -134,32 +140,31 @@
|
|||
# include "../examples/shadowmapping/shadowmapping.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
|
||||
#ifdef MVK_shadowmappingcascade
|
||||
# include "../examples/shadowmappingcascade/shadowmappingcascade.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
|
||||
#ifdef MVK_shadowmappingomni
|
||||
# include "../examples/shadowmappingomni/shadowmappingomni.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support arrays of samplers.
|
||||
#ifdef MVK_texturemipmapgen
|
||||
# include "../examples/texturemipmapgen/texturemipmapgen.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support blitting to linear tiled images.
|
||||
#ifdef MVK_screenshot
|
||||
# include "../examples/screenshot/screenshot.cpp"
|
||||
#endif
|
||||
|
||||
// Runs, but some Apple GPUs may not support stores and atomic operations in the fragment stage.
|
||||
// Not supported on iOS Simulator due to VkDeviceMemory resource limitations.
|
||||
#ifdef MVK_oit
|
||||
# include "../examples/oit/oit.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Sparse image binding and residency not supported by MoltenVK/Metal.
|
||||
#ifdef MVK_texturesparseresidency
|
||||
# include "../examples/texturesparseresidency/texturesparseresidency.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// PERFORMANCE
|
||||
|
||||
|
|
@ -171,6 +176,7 @@
|
|||
# include "../examples/instancing/instancing.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support indirect drawing.
|
||||
#ifdef MVK_indirectdraw
|
||||
# include "../examples/indirectdraw/indirectdraw.cpp"
|
||||
#endif
|
||||
|
|
@ -179,11 +185,16 @@
|
|||
# include "../examples/occlusionquery/occlusionquery.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. MoltenVK/Metal does not support pipeline statistics.
|
||||
// Does not run. MoltenVK/Metal does not support pipeline statistics.
|
||||
#ifdef MVK_pipelinestatistics
|
||||
# include "../examples/pipelinestatistics/pipelinestatistics.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Sparse image binding and residency not supported by MoltenVK/Metal.
|
||||
#ifdef MVK_texturesparseresidency
|
||||
# include "../examples/texturesparseresidency/texturesparseresidency.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// PHYSICALLY BASED RENDERING
|
||||
|
||||
|
|
@ -242,6 +253,7 @@
|
|||
# include "../examples/computecloth/computecloth.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support indirect drawing.
|
||||
#ifdef MVK_computecullandlod
|
||||
# include "../examples/computecullandlod/computecullandlod.cpp"
|
||||
#endif
|
||||
|
|
@ -262,14 +274,17 @@
|
|||
|
||||
// TESSELLATION
|
||||
|
||||
// Not supported on iOS Simulator which does not support tessellation shaders.
|
||||
#ifdef MVK_displacement
|
||||
# include "../examples/displacement/displacement.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support tessellation shaders.
|
||||
#ifdef MVK_terraintessellation
|
||||
# include "../examples/terraintessellation/terraintessellation.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support tessellation shaders.
|
||||
#ifdef MVK_tessellation
|
||||
# include "../examples/tessellation/tessellation.cpp"
|
||||
#endif
|
||||
|
|
@ -277,52 +292,52 @@
|
|||
|
||||
// RAY TRACING - Currently unsupported by MoltenVK/Metal
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingbasic
|
||||
# include "../examples/raytracingbasic/raytracingbasic.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingshadows
|
||||
# include "../examples/raytracingshadows/raytracingshadows.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingreflections
|
||||
# include "../examples/raytracingreflections/raytracingreflections.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingtextures
|
||||
# include "../examples/raytracingtextures/raytracingtextures.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingcallable
|
||||
# include "../examples/raytracingcallable/raytracingcallable.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingintersection
|
||||
# include "../examples/raytracingintersection/raytracingintersection.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracinggltf
|
||||
# include "../examples/raytracinggltf/raytracinggltf.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_rayquery
|
||||
# include "../examples/rayquery/rayquery.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingpositionfetch
|
||||
# include "../examples/raytracingpositionfetch/raytracingpositionfetch.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Missing Vulkan extensions for ray tracing
|
||||
// Does not run. Missing Vulkan extensions for ray tracing.
|
||||
#ifdef MVK_raytracingsbtdata
|
||||
# include "../examples/raytracingsbtdata/raytracingsbtdata.cpp"
|
||||
#endif
|
||||
|
|
@ -356,25 +371,6 @@
|
|||
#endif
|
||||
|
||||
|
||||
// EFFECTS
|
||||
|
||||
#ifdef MVK_radialblur
|
||||
# include "../examples/radialblur/radialblur.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_bloom
|
||||
# include "../examples/bloom/bloom.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_parallaxmapping
|
||||
# include "../examples/parallaxmapping/parallaxmapping.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_sphericalenvmapping
|
||||
# include "../examples/sphericalenvmapping/sphericalenvmapping.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// EXTENSIONS
|
||||
|
||||
// Does not run. Requires VK_EXT_conservative_rasterization.
|
||||
|
|
@ -390,6 +386,7 @@
|
|||
# include "../examples/inlineuniformblocks/inlineuniformblocks.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
|
||||
#ifdef MVK_multiview
|
||||
# include "../examples/multiview/multiview.cpp"
|
||||
#endif
|
||||
|
|
@ -401,7 +398,6 @@
|
|||
|
||||
// Runs on MoltenVK 1.2.5 or later with VK_KHR_shader_non_semantic_info extension and VK_LAYER_KHRONOS_validation enabled.
|
||||
// No VK_LAYER_KHRONOS_validation layer when using MoltenVK examples project, builds/runs fine using vulkanExamples project.
|
||||
// Enable VK_LAYER_KHRONOS_validation layer with khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT
|
||||
//#ifdef MVK_debugprintf
|
||||
//# include "../examples/debugprintf/debugprintf.cpp"
|
||||
//#endif
|
||||
|
|
@ -419,7 +415,8 @@
|
|||
# include "../examples/variablerateshading/variablerateshading.cpp"
|
||||
#endif
|
||||
|
||||
// Runs on macOS 11.0 or later with Metal argument buffers enabled. Not yet supported on iOS.
|
||||
// Runs on macOS 11.0 or later with Metal argument buffers enabled.
|
||||
// Supported on iOS (not Simulator) as of MoltenVK version 1.2.10 / Vulkan SDK 1.3.290
|
||||
#ifdef MVK_descriptorindexing
|
||||
# include "../examples/descriptorindexing/descriptorindexing.cpp"
|
||||
#endif
|
||||
|
|
@ -428,6 +425,10 @@
|
|||
# include "../examples/dynamicrendering/dynamicrendering.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_dynamicrenderingmultisampling
|
||||
# include "../examples/dynamicrenderingmultisampling/dynamicrenderingmultisampling.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Requires VK_KHR_pipeline_library and VK_EXT_graphics_pipeline_library.
|
||||
#ifdef MVK_graphicspipelinelibrary
|
||||
# include "../examples/graphicspipelinelibrary/graphicspipelinelibrary.cpp"
|
||||
|
|
@ -448,17 +449,49 @@
|
|||
# include "../examples/shaderobjects/shaderobjects.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_hostimagecopy
|
||||
# include "../examples/hostimagecopy/hostimagecopy.cpp"
|
||||
#endif
|
||||
|
||||
// Not supported on iOS Simulator.
|
||||
#ifdef MVK_bufferdeviceaddress
|
||||
# include "../examples/bufferdeviceaddress/bufferdeviceaddress.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_timelinesemaphore
|
||||
# include "../examples/timelinesemaphore/timelinesemaphore.cpp"
|
||||
#endif
|
||||
|
||||
// Runs, but most VK_EXT_extended_dynamic_state3 features not supported on MoltenVK.
|
||||
#ifdef MVK_dynamicstate
|
||||
# include "../examples/dynamicstate/dynamicstate.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// EFFECTS
|
||||
|
||||
#ifdef MVK_radialblur
|
||||
# include "../examples/radialblur/radialblur.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_bloom
|
||||
# include "../examples/bloom/bloom.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_parallaxmapping
|
||||
# include "../examples/parallaxmapping/parallaxmapping.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_sphericalenvmapping
|
||||
# include "../examples/sphericalenvmapping/sphericalenvmapping.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// MISC
|
||||
|
||||
// Not supported on iOS Simulator which does not support indexed drawing with a non-zero base instance.
|
||||
#ifdef MVK_gears
|
||||
# include "../examples/gears/gears.cpp"
|
||||
# include "../examples/gears/vulkangear.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef MVK_vulkanscene
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@
|
|||
AAEE728A2BD6003F0053521D /* shaders in Resources */ = {isa = PBXBuildFile; fileRef = AAEE72892BD6003F0053521D /* shaders */; };
|
||||
AAEE728C2BD600830053521D /* assets in Resources */ = {isa = PBXBuildFile; fileRef = AAEE728B2BD600830053521D /* assets */; };
|
||||
AAEE728E2BD600970053521D /* shaders in Resources */ = {isa = PBXBuildFile; fileRef = AAEE728D2BD600970053521D /* shaders */; };
|
||||
AAF62FC42D6C319900E69F39 /* vkloader.c in Sources */ = {isa = PBXBuildFile; fileRef = AAF62FC32D6C319900E69F39 /* vkloader.c */; };
|
||||
AAF62FC52D6C319900E69F39 /* vkloader.c in Sources */ = {isa = PBXBuildFile; fileRef = AAF62FC32D6C319900E69F39 /* vkloader.c */; };
|
||||
C9A79EFC204504E000696219 /* VulkanUIOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */; };
|
||||
C9A79EFD2045051D00696219 /* VulkanUIOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */; };
|
||||
C9A79EFE2045051D00696219 /* VulkanUIOverlay.h in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFA204504E000696219 /* VulkanUIOverlay.h */; };
|
||||
|
|
@ -200,6 +202,7 @@
|
|||
AAEE72892BD6003F0053521D /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../shaders; sourceTree = "<group>"; };
|
||||
AAEE728B2BD600830053521D /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = ../assets; sourceTree = "<group>"; };
|
||||
AAEE728D2BD600970053521D /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../shaders; sourceTree = "<group>"; };
|
||||
AAF62FC32D6C319900E69F39 /* vkloader.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vkloader.c; path = ../external/ktx/lib/vkloader.c; sourceTree = "<group>"; };
|
||||
C9788FD02044D78D00AB0892 /* benchmark.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = benchmark.hpp; sourceTree = "<group>"; };
|
||||
C9A79EFA204504E000696219 /* VulkanUIOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VulkanUIOverlay.h; sourceTree = "<group>"; };
|
||||
C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VulkanUIOverlay.cpp; sourceTree = "<group>"; };
|
||||
|
|
@ -295,6 +298,7 @@
|
|||
A951FF011E9C349000FA9144 /* frustum.hpp */,
|
||||
A951FF021E9C349000FA9144 /* keycodes.hpp */,
|
||||
A951FF031E9C349000FA9144 /* threadpool.hpp */,
|
||||
AAF62FC32D6C319900E69F39 /* vkloader.c */,
|
||||
);
|
||||
name = base;
|
||||
path = ../base;
|
||||
|
|
@ -567,6 +571,7 @@
|
|||
AA54A6BE26E52CE300485C4A /* checkheader.c in Sources */,
|
||||
A9B67B7C1C3AAE9800373FFD /* main.m in Sources */,
|
||||
AA54A1B826E5275300485C4A /* VulkanDevice.cpp in Sources */,
|
||||
AAF62FC42D6C319900E69F39 /* vkloader.c in Sources */,
|
||||
AA54A1C026E5276C00485C4A /* VulkanSwapChain.cpp in Sources */,
|
||||
AA54A6E426E52CE400485C4A /* imgui_demo.cpp in Sources */,
|
||||
AA54A6E026E52CE400485C4A /* imgui.cpp in Sources */,
|
||||
|
|
@ -602,6 +607,7 @@
|
|||
AA54A6D926E52CE400485C4A /* swap.c in Sources */,
|
||||
AA54A6BF26E52CE300485C4A /* checkheader.c in Sources */,
|
||||
A951FF1C1E9C349000FA9144 /* VulkanTools.cpp in Sources */,
|
||||
AAF62FC52D6C319900E69F39 /* vkloader.c in Sources */,
|
||||
A951FF1A1E9C349000FA9144 /* vulkanexamplebase.cpp in Sources */,
|
||||
A9B67B8D1C3AAEA200373FFD /* DemoViewController.mm in Sources */,
|
||||
AA54A6E526E52CE400485C4A /* imgui_demo.cpp in Sources */,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
[(DemoViewController *)_viewController appInBackground];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
|
|
@ -36,6 +37,7 @@
|
|||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
[(DemoViewController *)_viewController appInForeground];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
/** The main view controller for the demo storyboard. */
|
||||
@interface DemoViewController : UIViewController <UIKeyInput>
|
||||
-(void) appInBackground;
|
||||
-(void) appInForeground;
|
||||
-(void) shutdownExample;
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ CALayer* layer;
|
|||
MVKExample* _mvkExample;
|
||||
CADisplayLink* _displayLink;
|
||||
BOOL _viewHasAppeared;
|
||||
BOOL _appInForeground;
|
||||
CGPoint _startPoint;
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +76,7 @@ CALayer* layer;
|
|||
[self.view addGestureRecognizer: pinchSelector];
|
||||
|
||||
_viewHasAppeared = NO;
|
||||
_appInForeground = NO;
|
||||
}
|
||||
|
||||
-(void) viewDidAppear: (BOOL) animated {
|
||||
|
|
@ -85,8 +87,18 @@ CALayer* layer;
|
|||
-(BOOL) canBecomeFirstResponder { return _viewHasAppeared; }
|
||||
|
||||
-(void) renderFrame {
|
||||
//_mvkExample->renderFrame();
|
||||
_mvkExample->displayLinkOutputCb(); // SRS - Call displayLinkOutputCb() to animate frames vs. renderFrame() for static image
|
||||
if (_appInForeground)
|
||||
{
|
||||
_mvkExample->displayLinkOutputCb(); // SRS - Call displayLinkOutputCb() to render/animate at displayLink frame rate
|
||||
}
|
||||
}
|
||||
|
||||
- (void)appInForeground {
|
||||
_appInForeground = YES;
|
||||
}
|
||||
|
||||
- (void)appInBackground {
|
||||
_appInForeground = NO;
|
||||
}
|
||||
|
||||
-(void) shutdownExample {
|
||||
|
|
|
|||
|
|
@ -270,17 +270,6 @@ 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_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);
|
||||
// SRS - When vsync is on, use minImageCount when not in fullscreen or when running on Apple Silcon
|
||||
// This forces swapchain image acquire frame rate to match display vsync frame rate
|
||||
if (vsync && (!fullscreen || strcmp(sysInfo.machine, "arm64") == 0))
|
||||
{
|
||||
desiredNumberOfSwapchainImages = surfCaps.minImageCount;
|
||||
}
|
||||
#endif
|
||||
if ((surfCaps.maxImageCount > 0) && (desiredNumberOfSwapchainImages > surfCaps.maxImageCount))
|
||||
{
|
||||
desiredNumberOfSwapchainImages = surfCaps.maxImageCount;
|
||||
|
|
|
|||
|
|
@ -405,7 +405,13 @@ namespace vks
|
|||
vkCmdDrawIndexed(commandBuffer, pcmd->ElemCount, 1, indexOffset, vertexOffset, 0);
|
||||
indexOffset += pcmd->ElemCount;
|
||||
}
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && TARGET_OS_SIMULATOR
|
||||
// Apple Device Simulator does not support vkCmdDrawIndexed() with vertexOffset > 0, so rebind vertex buffer instead
|
||||
offsets[0] += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets);
|
||||
#else
|
||||
vertexOffset += cmd_list->VtxBuffer.Size;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@
|
|||
#include "VulkanAndroid.h"
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
namespace vks
|
||||
{
|
||||
class UIOverlay
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ VkResult VulkanExampleBase::createInstance()
|
|||
if (std::find(supportedInstanceExtensions.begin(), supportedInstanceExtensions.end(), VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) != supportedInstanceExtensions.end())
|
||||
{
|
||||
instanceExtensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||
instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
|
||||
instanceCreateInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -148,6 +148,18 @@ VkResult VulkanExampleBase::createInstance()
|
|||
std::cerr << "Validation layer VK_LAYER_KHRONOS_validation not present, validation is disabled";
|
||||
}
|
||||
}
|
||||
|
||||
// If layer settings are defined, then activate the sample's required layer settings during instance creation.
|
||||
// Layer settings are typically used to activate specific features of a layer, such as the Validation Layer's
|
||||
// printf feature, or to configure specific capabilities of drivers such as MoltenVK on macOS and/or iOS.
|
||||
VkLayerSettingsCreateInfoEXT layerSettingsCreateInfo{VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT};
|
||||
if (enabledLayerSettings.size() > 0) {
|
||||
layerSettingsCreateInfo.settingCount = static_cast<uint32_t>(enabledLayerSettings.size());
|
||||
layerSettingsCreateInfo.pSettings = enabledLayerSettings.data();
|
||||
layerSettingsCreateInfo.pNext = instanceCreateInfo.pNext;
|
||||
instanceCreateInfo.pNext = &layerSettingsCreateInfo;
|
||||
}
|
||||
|
||||
VkResult result = vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
|
||||
|
||||
// If the debug utils extension is present we set up debug functions, so samples can label objects for debugging
|
||||
|
|
@ -853,6 +865,21 @@ VulkanExampleBase::VulkanExampleBase()
|
|||
if(commandLineParser.isSet("resourcepath")) {
|
||||
vks::tools::resourcePath = commandLineParser.getValueAsString("resourcepath", "");
|
||||
}
|
||||
#else
|
||||
// On Apple platforms, use layer settings extension to configure MoltenVK with common project config settings
|
||||
enabledInstanceExtensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
// Configure MoltenVK to use to use a dedicated compute queue (see compute[*] and timelinesemaphore samples)
|
||||
VkLayerSettingEXT layerSetting;
|
||||
layerSetting.pLayerName = "MoltenVK";
|
||||
layerSetting.pSettingName = "MVK_CONFIG_SPECIALIZED_QUEUE_FAMILIES";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make this static so layer setting reference remains valid after leaving constructor scope
|
||||
static const VkBool32 layerSettingOn = VK_TRUE;
|
||||
layerSetting.pValues = &layerSettingOn;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
#endif
|
||||
|
||||
#if !defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
//
|
||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
||||
#include <xcb/xcb.h>
|
||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -114,7 +116,10 @@ protected:
|
|||
VkPhysicalDeviceFeatures enabledFeatures{};
|
||||
/** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */
|
||||
std::vector<const char*> enabledDeviceExtensions;
|
||||
/** @brief Set of instance extensions to be enabled for this example (must be set in the derived constructor) */
|
||||
std::vector<const char*> enabledInstanceExtensions;
|
||||
/** @brief Set of layer settings to be enabled for this example (must be set in the derived constructor) */
|
||||
std::vector<VkLayerSettingEXT> enabledLayerSettings;
|
||||
/** @brief Optional pNext structure for passing extension structures to device creation */
|
||||
void* deviceCreatepNextChain = nullptr;
|
||||
/** @brief Logical device, application's view of the physical device (GPU) */
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public:
|
|||
glm::vec4 normalAndDistance;
|
||||
};
|
||||
struct SceneObject {
|
||||
SceneObjectProperty objectProperties;
|
||||
SceneObjectProperty objectProperties{};
|
||||
glm::vec3 diffuse;
|
||||
float specular{ 1.0f };
|
||||
uint32_t id{ 0 };
|
||||
|
|
@ -85,11 +85,6 @@ public:
|
|||
camera.setTranslation(glm::vec3(0.0f, 0.0f, -4.0f));
|
||||
camera.rotationSpeed = 0.0f;
|
||||
camera.movementSpeed = 2.5f;
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
|
|||
|
|
@ -47,12 +47,39 @@ public:
|
|||
enabledDeviceExtensions.push_back(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME);
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_EXAMPLE_XCODE_GENERATED)
|
||||
// SRS - Force validation on since debugPrintfEXT provided by VK_LAYER_KHRONOS_validation on macOS
|
||||
// SRS - Force validation on since shader printf provided by VK_LAYER_KHRONOS_validation on macOS
|
||||
settings.validation = true;
|
||||
setenv("VK_LAYER_ENABLES", "VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT", 1);
|
||||
|
||||
// SRS - RenderDoc not available on macOS so redirect debugPrintfEXT output to stdout
|
||||
setenv("VK_KHRONOS_VALIDATION_PRINTF_TO_STDOUT", "1", 1);
|
||||
// Use layer settings extension to configure Validation Layer
|
||||
enabledInstanceExtensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
// SRS - Enable the Validation Layer's printf feature
|
||||
VkLayerSettingEXT layerSetting;
|
||||
layerSetting.pLayerName = "VK_LAYER_KHRONOS_validation";
|
||||
layerSetting.pSettingName = "enables";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_STRING_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make static so layer setting reference remains valid after leaving constructor scope
|
||||
static const char *layerEnables = "VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT";
|
||||
layerSetting.pValues = &layerEnables;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
|
||||
// SRS - RenderDoc not available on macOS so redirect printf output to stdout
|
||||
layerSetting.pSettingName = "printf_to_stdout";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make static so layer setting reference remains valid after leaving constructor scope
|
||||
static const VkBool32 layerSettingOn = VK_TRUE;
|
||||
layerSetting.pValues = &layerSettingOn;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
|
||||
// Enable required features and set API version for Validation Layer printf
|
||||
enabledFeatures.fragmentStoresAndAtomics = VK_TRUE;
|
||||
enabledFeatures.vertexPipelineStoresAndAtomics = VK_TRUE;
|
||||
|
||||
apiVersion = VK_API_VERSION_1_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ public:
|
|||
} uniformDataComposition;
|
||||
|
||||
struct {
|
||||
vks::Buffer offscreen{ VK_NULL_HANDLE };
|
||||
vks::Buffer composition{ VK_NULL_HANDLE };
|
||||
vks::Buffer offscreen;
|
||||
vks::Buffer composition;
|
||||
} uniformBuffers;
|
||||
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ public:
|
|||
} uniformDataComposition;
|
||||
|
||||
struct {
|
||||
vks::Buffer offscreen{ VK_NULL_HANDLE };
|
||||
vks::Buffer composition{ VK_NULL_HANDLE };
|
||||
vks::Buffer offscreen;
|
||||
vks::Buffer composition;
|
||||
} uniformBuffers;
|
||||
|
||||
struct {
|
||||
|
|
@ -72,7 +72,7 @@ public:
|
|||
VkDescriptorSet model{ VK_NULL_HANDLE };
|
||||
VkDescriptorSet background{ VK_NULL_HANDLE };
|
||||
VkDescriptorSet composition{ VK_NULL_HANDLE };
|
||||
} descriptorSets{ VK_NULL_HANDLE };
|
||||
} descriptorSets;
|
||||
|
||||
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
|
||||
|
||||
|
|
|
|||
|
|
@ -68,10 +68,21 @@ public:
|
|||
|
||||
deviceCreatepNextChain = &physicalDeviceDescriptorIndexingFeatures;
|
||||
|
||||
#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);
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Use layer settings extension to configure MoltenVK
|
||||
enabledInstanceExtensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
// Configure MoltenVK to use Metal argument buffers (needed for descriptor indexing)
|
||||
VkLayerSettingEXT layerSetting;
|
||||
layerSetting.pLayerName = "MoltenVK";
|
||||
layerSetting.pSettingName = "MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make this static so layer setting reference remains valid after leaving constructor scope
|
||||
static const VkBool32 layerSettingOn = VK_TRUE;
|
||||
layerSetting.pValues = &layerSettingOn;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -214,8 +225,8 @@ 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) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Increase the per-stage descriptor samplers limit on macOS/iOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorPoolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT;
|
||||
#endif
|
||||
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||
|
|
@ -237,6 +248,27 @@ public:
|
|||
// Binding 1 are the fragment shader images, which use indexing
|
||||
// In the fragment shader:
|
||||
// layout (set = 0, binding = 1) uniform sampler2D textures[];
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Disable variable descriptor count feature on macOS/iOS until MoltenVK supports this feature when using combined image sampler textures
|
||||
// Note we are using only 1 descriptor set with a fixed descriptor count/pool size, so we can simply turn off the capability for now
|
||||
std::vector<VkDescriptorBindingFlagsEXT> descriptorBindingFlags = {
|
||||
0,
|
||||
0
|
||||
};
|
||||
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
||||
// Increase the per-stage descriptor samplers limit on macOS/iOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorSetLayoutCI.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
|
||||
descriptorSetLayoutCI.pNext = &setLayoutBindingFlags;
|
||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayout));
|
||||
|
||||
// [POI] Descriptor sets
|
||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1);
|
||||
allocInfo.pNext = nullptr;
|
||||
#else
|
||||
// Enable variable descriptor count feature on platforms other than macOS/iOS
|
||||
std::vector<VkDescriptorBindingFlagsEXT> descriptorBindingFlags = {
|
||||
0,
|
||||
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
|
||||
|
|
@ -244,10 +276,6 @@ public:
|
|||
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
||||
#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
|
||||
descriptorSetLayoutCI.pNext = &setLayoutBindingFlags;
|
||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayout));
|
||||
|
||||
|
|
@ -264,6 +292,7 @@ public:
|
|||
|
||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1);
|
||||
allocInfo.pNext = &variableDescriptorCountAllocInfo;
|
||||
#endif
|
||||
|
||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||
|
||||
|
|
|
|||
|
|
@ -524,7 +524,13 @@ public:
|
|||
vkCmdDrawIndexed(commandBuffer, pcmd->ElemCount, 1, indexOffset, vertexOffset, 0);
|
||||
indexOffset += pcmd->ElemCount;
|
||||
}
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && TARGET_OS_SIMULATOR
|
||||
// Apple Device Simulator does not support vkCmdDrawIndexed() with vertexOffset > 0, so rebind vertex buffer instead
|
||||
offsets[0] += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets);
|
||||
#else
|
||||
vertexOffset += cmd_list->VtxBuffer.Size;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,6 @@ public:
|
|||
camera.setPerspective(60.0f, ((float)width / 3.0f) / (float)height, 0.1f, 512.0f);
|
||||
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) || 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
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue