Skip to content

Commit 9a562a5

Browse files
authored
Macos ios fixes (SaschaWillems#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
1 parent e1c9622 commit 9a562a5

File tree

17 files changed

+221
-83
lines changed

17 files changed

+221
-83
lines changed

apple/examples.h

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
# include "../examples/triangle/triangle.cpp"
4141
#endif
4242

43+
// Does not run. MoltenVK does not yet support Vulkan 1.3
44+
#ifdef MVK_trianglevulkan13
45+
# include "../examples/trianglevulkan13/trianglevulkan13.cpp"
46+
#endif
47+
4348
#ifdef MVK_pipelines
4449
# include "../examples/pipelines/pipelines.cpp"
4550
#endif
@@ -72,6 +77,7 @@
7277
# include "../examples/texturecubemap/texturecubemap.cpp"
7378
#endif
7479

80+
// Not supported on iOS Simulator which does not support cube map arrays.
7581
#ifdef MVK_texturecubemaparray
7682
# include "../examples/texturecubemaparray/texturecubemaparray.cpp"
7783
#endif
@@ -134,32 +140,31 @@
134140
# include "../examples/shadowmapping/shadowmapping.cpp"
135141
#endif
136142

143+
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
137144
#ifdef MVK_shadowmappingcascade
138145
# include "../examples/shadowmappingcascade/shadowmappingcascade.cpp"
139146
#endif
140147

148+
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
141149
#ifdef MVK_shadowmappingomni
142150
# include "../examples/shadowmappingomni/shadowmappingomni.cpp"
143151
#endif
144152

153+
// Not supported on iOS Simulator which does not support arrays of samplers.
145154
#ifdef MVK_texturemipmapgen
146155
# include "../examples/texturemipmapgen/texturemipmapgen.cpp"
147156
#endif
148157

158+
// Not supported on iOS Simulator which does not support blitting to linear tiled images.
149159
#ifdef MVK_screenshot
150160
# include "../examples/screenshot/screenshot.cpp"
151161
#endif
152162

153-
// Runs, but some Apple GPUs may not support stores and atomic operations in the fragment stage.
163+
// Not supported on iOS Simulator due to VkDeviceMemory resource limitations.
154164
#ifdef MVK_oit
155165
# include "../examples/oit/oit.cpp"
156166
#endif
157167

158-
// Does not run. Sparse image binding and residency not supported by MoltenVK/Metal.
159-
#ifdef MVK_texturesparseresidency
160-
# include "../examples/texturesparseresidency/texturesparseresidency.cpp"
161-
#endif
162-
163168

164169
// PERFORMANCE
165170

@@ -171,6 +176,7 @@
171176
# include "../examples/instancing/instancing.cpp"
172177
#endif
173178

179+
// Not supported on iOS Simulator which does not support indirect drawing.
174180
#ifdef MVK_indirectdraw
175181
# include "../examples/indirectdraw/indirectdraw.cpp"
176182
#endif
@@ -179,11 +185,16 @@
179185
# include "../examples/occlusionquery/occlusionquery.cpp"
180186
#endif
181187

182-
// Does not run. MoltenVK/Metal does not support pipeline statistics.
188+
// Does not run. MoltenVK/Metal does not support pipeline statistics.
183189
#ifdef MVK_pipelinestatistics
184190
# include "../examples/pipelinestatistics/pipelinestatistics.cpp"
185191
#endif
186192

193+
// Does not run. Sparse image binding and residency not supported by MoltenVK/Metal.
194+
#ifdef MVK_texturesparseresidency
195+
# include "../examples/texturesparseresidency/texturesparseresidency.cpp"
196+
#endif
197+
187198

188199
// PHYSICALLY BASED RENDERING
189200

@@ -242,6 +253,7 @@
242253
# include "../examples/computecloth/computecloth.cpp"
243254
#endif
244255

256+
// Not supported on iOS Simulator which does not support indirect drawing.
245257
#ifdef MVK_computecullandlod
246258
# include "../examples/computecullandlod/computecullandlod.cpp"
247259
#endif
@@ -262,67 +274,70 @@
262274

263275
// TESSELLATION
264276

277+
// Not supported on iOS Simulator which does not support tessellation shaders.
265278
#ifdef MVK_displacement
266279
# include "../examples/displacement/displacement.cpp"
267280
#endif
268281

282+
// Not supported on iOS Simulator which does not support tessellation shaders.
269283
#ifdef MVK_terraintessellation
270284
# include "../examples/terraintessellation/terraintessellation.cpp"
271285
#endif
272286

287+
// Not supported on iOS Simulator which does not support tessellation shaders.
273288
#ifdef MVK_tessellation
274289
# include "../examples/tessellation/tessellation.cpp"
275290
#endif
276291

277292

278293
// RAY TRACING - Currently unsupported by MoltenVK/Metal
279294

280-
// Does not run. Missing Vulkan extensions for ray tracing
295+
// Does not run. Missing Vulkan extensions for ray tracing.
281296
#ifdef MVK_raytracingbasic
282297
# include "../examples/raytracingbasic/raytracingbasic.cpp"
283298
#endif
284299

285-
// Does not run. Missing Vulkan extensions for ray tracing
300+
// Does not run. Missing Vulkan extensions for ray tracing.
286301
#ifdef MVK_raytracingshadows
287302
# include "../examples/raytracingshadows/raytracingshadows.cpp"
288303
#endif
289304

290-
// Does not run. Missing Vulkan extensions for ray tracing
305+
// Does not run. Missing Vulkan extensions for ray tracing.
291306
#ifdef MVK_raytracingreflections
292307
# include "../examples/raytracingreflections/raytracingreflections.cpp"
293308
#endif
294309

295-
// Does not run. Missing Vulkan extensions for ray tracing
310+
// Does not run. Missing Vulkan extensions for ray tracing.
296311
#ifdef MVK_raytracingtextures
297312
# include "../examples/raytracingtextures/raytracingtextures.cpp"
298313
#endif
299314

300-
// Does not run. Missing Vulkan extensions for ray tracing
315+
// Does not run. Missing Vulkan extensions for ray tracing.
301316
#ifdef MVK_raytracingcallable
302317
# include "../examples/raytracingcallable/raytracingcallable.cpp"
303318
#endif
304319

305-
// Does not run. Missing Vulkan extensions for ray tracing
320+
// Does not run. Missing Vulkan extensions for ray tracing.
306321
#ifdef MVK_raytracingintersection
307322
# include "../examples/raytracingintersection/raytracingintersection.cpp"
308323
#endif
309324

310-
// Does not run. Missing Vulkan extensions for ray tracing
325+
// Does not run. Missing Vulkan extensions for ray tracing.
311326
#ifdef MVK_raytracinggltf
312327
# include "../examples/raytracinggltf/raytracinggltf.cpp"
313328
#endif
314329

315-
// Does not run. Missing Vulkan extensions for ray tracing
330+
// Does not run. Missing Vulkan extensions for ray tracing.
316331
#ifdef MVK_rayquery
317332
# include "../examples/rayquery/rayquery.cpp"
318333
#endif
319334

320-
// Does not run. Missing Vulkan extensions for ray tracing
335+
// Does not run. Missing Vulkan extensions for ray tracing.
321336
#ifdef MVK_raytracingpositionfetch
322337
# include "../examples/raytracingpositionfetch/raytracingpositionfetch.cpp"
323338
#endif
324339

325-
// Does not run. Missing Vulkan extensions for ray tracing
340+
// Does not run. Missing Vulkan extensions for ray tracing.
326341
#ifdef MVK_raytracingsbtdata
327342
# include "../examples/raytracingsbtdata/raytracingsbtdata.cpp"
328343
#endif
@@ -356,25 +371,6 @@
356371
#endif
357372

358373

359-
// EFFECTS
360-
361-
#ifdef MVK_radialblur
362-
# include "../examples/radialblur/radialblur.cpp"
363-
#endif
364-
365-
#ifdef MVK_bloom
366-
# include "../examples/bloom/bloom.cpp"
367-
#endif
368-
369-
#ifdef MVK_parallaxmapping
370-
# include "../examples/parallaxmapping/parallaxmapping.cpp"
371-
#endif
372-
373-
#ifdef MVK_sphericalenvmapping
374-
# include "../examples/sphericalenvmapping/sphericalenvmapping.cpp"
375-
#endif
376-
377-
378374
// EXTENSIONS
379375

380376
// Does not run. Requires VK_EXT_conservative_rasterization.
@@ -390,6 +386,7 @@
390386
# include "../examples/inlineuniformblocks/inlineuniformblocks.cpp"
391387
#endif
392388

389+
// Not supported on iOS Simulator which does not support rendering to array (layered) attachments.
393390
#ifdef MVK_multiview
394391
# include "../examples/multiview/multiview.cpp"
395392
#endif
@@ -401,7 +398,6 @@
401398

402399
// Runs on MoltenVK 1.2.5 or later with VK_KHR_shader_non_semantic_info extension and VK_LAYER_KHRONOS_validation enabled.
403400
// No VK_LAYER_KHRONOS_validation layer when using MoltenVK examples project, builds/runs fine using vulkanExamples project.
404-
// Enable VK_LAYER_KHRONOS_validation layer with khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT
405401
//#ifdef MVK_debugprintf
406402
//# include "../examples/debugprintf/debugprintf.cpp"
407403
//#endif
@@ -419,7 +415,8 @@
419415
# include "../examples/variablerateshading/variablerateshading.cpp"
420416
#endif
421417

422-
// Runs on macOS 11.0 or later with Metal argument buffers enabled. Not yet supported on iOS.
418+
// Runs on macOS 11.0 or later with Metal argument buffers enabled.
419+
// Supported on iOS (not Simulator) as of MoltenVK version 1.2.10 / Vulkan SDK 1.3.290
423420
#ifdef MVK_descriptorindexing
424421
# include "../examples/descriptorindexing/descriptorindexing.cpp"
425422
#endif
@@ -428,6 +425,10 @@
428425
# include "../examples/dynamicrendering/dynamicrendering.cpp"
429426
#endif
430427

428+
#ifdef MVK_dynamicrenderingmultisampling
429+
# include "../examples/dynamicrenderingmultisampling/dynamicrenderingmultisampling.cpp"
430+
#endif
431+
431432
// Does not run. Requires VK_KHR_pipeline_library and VK_EXT_graphics_pipeline_library.
432433
#ifdef MVK_graphicspipelinelibrary
433434
# include "../examples/graphicspipelinelibrary/graphicspipelinelibrary.cpp"
@@ -448,17 +449,49 @@
448449
# include "../examples/shaderobjects/shaderobjects.cpp"
449450
#endif
450451

452+
#ifdef MVK_hostimagecopy
453+
# include "../examples/hostimagecopy/hostimagecopy.cpp"
454+
#endif
455+
456+
// Not supported on iOS Simulator.
457+
#ifdef MVK_bufferdeviceaddress
458+
# include "../examples/bufferdeviceaddress/bufferdeviceaddress.cpp"
459+
#endif
460+
461+
#ifdef MVK_timelinesemaphore
462+
# include "../examples/timelinesemaphore/timelinesemaphore.cpp"
463+
#endif
464+
451465
// Runs, but most VK_EXT_extended_dynamic_state3 features not supported on MoltenVK.
452466
#ifdef MVK_dynamicstate
453467
# include "../examples/dynamicstate/dynamicstate.cpp"
454468
#endif
455469

456470

471+
// EFFECTS
472+
473+
#ifdef MVK_radialblur
474+
# include "../examples/radialblur/radialblur.cpp"
475+
#endif
476+
477+
#ifdef MVK_bloom
478+
# include "../examples/bloom/bloom.cpp"
479+
#endif
480+
481+
#ifdef MVK_parallaxmapping
482+
# include "../examples/parallaxmapping/parallaxmapping.cpp"
483+
#endif
484+
485+
#ifdef MVK_sphericalenvmapping
486+
# include "../examples/sphericalenvmapping/sphericalenvmapping.cpp"
487+
#endif
488+
489+
457490
// MISC
458491

492+
// Not supported on iOS Simulator which does not support indexed drawing with a non-zero base instance.
459493
#ifdef MVK_gears
460494
# include "../examples/gears/gears.cpp"
461-
# include "../examples/gears/vulkangear.cpp"
462495
#endif
463496

464497
#ifdef MVK_vulkanscene

apple/examples.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
AAEE728A2BD6003F0053521D /* shaders in Resources */ = {isa = PBXBuildFile; fileRef = AAEE72892BD6003F0053521D /* shaders */; };
8080
AAEE728C2BD600830053521D /* assets in Resources */ = {isa = PBXBuildFile; fileRef = AAEE728B2BD600830053521D /* assets */; };
8181
AAEE728E2BD600970053521D /* shaders in Resources */ = {isa = PBXBuildFile; fileRef = AAEE728D2BD600970053521D /* shaders */; };
82+
AAF62FC42D6C319900E69F39 /* vkloader.c in Sources */ = {isa = PBXBuildFile; fileRef = AAF62FC32D6C319900E69F39 /* vkloader.c */; };
83+
AAF62FC52D6C319900E69F39 /* vkloader.c in Sources */ = {isa = PBXBuildFile; fileRef = AAF62FC32D6C319900E69F39 /* vkloader.c */; };
8284
C9A79EFC204504E000696219 /* VulkanUIOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */; };
8385
C9A79EFD2045051D00696219 /* VulkanUIOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */; };
8486
C9A79EFE2045051D00696219 /* VulkanUIOverlay.h in Sources */ = {isa = PBXBuildFile; fileRef = C9A79EFA204504E000696219 /* VulkanUIOverlay.h */; };
@@ -200,6 +202,7 @@
200202
AAEE72892BD6003F0053521D /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../shaders; sourceTree = "<group>"; };
201203
AAEE728B2BD600830053521D /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = ../assets; sourceTree = "<group>"; };
202204
AAEE728D2BD600970053521D /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../shaders; sourceTree = "<group>"; };
205+
AAF62FC32D6C319900E69F39 /* vkloader.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vkloader.c; path = ../external/ktx/lib/vkloader.c; sourceTree = "<group>"; };
203206
C9788FD02044D78D00AB0892 /* benchmark.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = benchmark.hpp; sourceTree = "<group>"; };
204207
C9A79EFA204504E000696219 /* VulkanUIOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VulkanUIOverlay.h; sourceTree = "<group>"; };
205208
C9A79EFB204504E000696219 /* VulkanUIOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VulkanUIOverlay.cpp; sourceTree = "<group>"; };
@@ -295,6 +298,7 @@
295298
A951FF011E9C349000FA9144 /* frustum.hpp */,
296299
A951FF021E9C349000FA9144 /* keycodes.hpp */,
297300
A951FF031E9C349000FA9144 /* threadpool.hpp */,
301+
AAF62FC32D6C319900E69F39 /* vkloader.c */,
298302
);
299303
name = base;
300304
path = ../base;
@@ -567,6 +571,7 @@
567571
AA54A6BE26E52CE300485C4A /* checkheader.c in Sources */,
568572
A9B67B7C1C3AAE9800373FFD /* main.m in Sources */,
569573
AA54A1B826E5275300485C4A /* VulkanDevice.cpp in Sources */,
574+
AAF62FC42D6C319900E69F39 /* vkloader.c in Sources */,
570575
AA54A1C026E5276C00485C4A /* VulkanSwapChain.cpp in Sources */,
571576
AA54A6E426E52CE400485C4A /* imgui_demo.cpp in Sources */,
572577
AA54A6E026E52CE400485C4A /* imgui.cpp in Sources */,
@@ -602,6 +607,7 @@
602607
AA54A6D926E52CE400485C4A /* swap.c in Sources */,
603608
AA54A6BF26E52CE300485C4A /* checkheader.c in Sources */,
604609
A951FF1C1E9C349000FA9144 /* VulkanTools.cpp in Sources */,
610+
AAF62FC52D6C319900E69F39 /* vkloader.c in Sources */,
605611
A951FF1A1E9C349000FA9144 /* vulkanexamplebase.cpp in Sources */,
606612
A9B67B8D1C3AAEA200373FFD /* DemoViewController.mm in Sources */,
607613
AA54A6E526E52CE400485C4A /* imgui_demo.cpp in Sources */,

apple/ios/AppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2323
- (void)applicationWillResignActive:(UIApplication *)application {
2424
// 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.
2525
// 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.
26+
[(DemoViewController *)_viewController appInBackground];
2627
}
2728

2829
- (void)applicationDidEnterBackground:(UIApplication *)application {
@@ -36,6 +37,7 @@ - (void)applicationWillEnterForeground:(UIApplication *)application {
3637

3738
- (void)applicationDidBecomeActive:(UIApplication *)application {
3839
// 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.
40+
[(DemoViewController *)_viewController appInForeground];
3941
}
4042

4143
- (void)applicationWillTerminate:(UIApplication *)application {

apple/ios/DemoViewController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/** The main view controller for the demo storyboard. */
1515
@interface DemoViewController : UIViewController <UIKeyInput>
16+
-(void) appInBackground;
17+
-(void) appInForeground;
1618
-(void) shutdownExample;
1719
@end
1820

apple/ios/DemoViewController.mm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ @implementation DemoViewController {
2727
MVKExample* _mvkExample;
2828
CADisplayLink* _displayLink;
2929
BOOL _viewHasAppeared;
30+
BOOL _appInForeground;
3031
CGPoint _startPoint;
3132
}
3233

@@ -75,6 +76,7 @@ -(void) viewDidLoad {
7576
[self.view addGestureRecognizer: pinchSelector];
7677

7778
_viewHasAppeared = NO;
79+
_appInForeground = NO;
7880
}
7981

8082
-(void) viewDidAppear: (BOOL) animated {
@@ -85,8 +87,18 @@ -(void) viewDidAppear: (BOOL) animated {
8587
-(BOOL) canBecomeFirstResponder { return _viewHasAppeared; }
8688

8789
-(void) renderFrame {
88-
//_mvkExample->renderFrame();
89-
_mvkExample->displayLinkOutputCb(); // SRS - Call displayLinkOutputCb() to animate frames vs. renderFrame() for static image
90+
if (_appInForeground)
91+
{
92+
_mvkExample->displayLinkOutputCb(); // SRS - Call displayLinkOutputCb() to render/animate at displayLink frame rate
93+
}
94+
}
95+
96+
- (void)appInForeground {
97+
_appInForeground = YES;
98+
}
99+
100+
- (void)appInBackground {
101+
_appInForeground = NO;
90102
}
91103

92104
-(void) shutdownExample {

0 commit comments

Comments
 (0)