Move macOS benchmarking to NSApp rendering loop, makes example windows visible vs. headless

This commit is contained in:
Stephen Saunders 2022-08-01 16:52:06 -04:00
parent 1b3fe76cdb
commit 62f6dcf767
2 changed files with 22 additions and 1 deletions

View file

@ -291,6 +291,9 @@ void VulkanExampleBase::nextFrame()
void VulkanExampleBase::renderLoop() 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 (benchmark.active) { if (benchmark.active) {
benchmark.run([=] { render(); }, vulkanDevice->properties); benchmark.run([=] { render(); }, vulkanDevice->properties);
vkDeviceWaitIdle(device); vkDeviceWaitIdle(device);
@ -299,6 +302,7 @@ void VulkanExampleBase::renderLoop()
} }
return; return;
} }
#endif
destWidth = width; destWidth = width;
destHeight = height; destHeight = height;
@ -1550,6 +1554,12 @@ dispatch_group_t concurrentGroup;
vulkanExample->displayLinkOutputCb(); vulkanExample->displayLinkOutputCb();
} }
}); });
// SRS - When benchmarking, set up termination notification on main thread when concurrent queue completes
if (vulkanExample->benchmark.active) {
dispatch_queue_t notifyQueue = dispatch_get_main_queue();
dispatch_group_notify(concurrentGroup, notifyQueue, ^{ [NSApp terminate:nil]; });
}
} }
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
@ -1836,6 +1846,17 @@ void* VulkanExampleBase::setupWindow(void* view)
void VulkanExampleBase::displayLinkOutputCb() void VulkanExampleBase::displayLinkOutputCb()
{ {
#if defined(VK_EXAMPLE_XCODE_GENERATED)
if (benchmark.active) {
benchmark.run([=] { render(); }, vulkanDevice->properties);
if (benchmark.filename != "") {
benchmark.saveResults();
}
quit = true; // SRS - quit NSApp rendering loop when benchmarking complete
return;
}
#endif
if (prepared) if (prepared)
nextFrame(); nextFrame();
} }

View file

@ -1256,7 +1256,7 @@ int main(const int argc, const char *argv[])
vulkanExample->setupWindow(nullptr); vulkanExample->setupWindow(nullptr);
vulkanExample->prepare(); vulkanExample->prepare();
vulkanExample->renderLoop(); vulkanExample->renderLoop();
delete(vulkanExample); // SRS - handle benchmarking case, normally deleted by applicationWillTerminate() event handler delete(vulkanExample);
} }
return 0; return 0;
} }