Skip to content

Commit

Permalink
Merge pull request #1927 from billhollings/demo-support-immediate-pre…
Browse files Browse the repository at this point in the history
…sent-mode

Add support for VK_PRESENT_MODE_IMMEDIATE_KHR to macOS Cube demo.
  • Loading branch information
billhollings authored May 31, 2023
2 parents 2a4e415 + 107be11 commit 0332055
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
24 changes: 20 additions & 4 deletions Demos/Cube/macOS/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ -(void) viewDidLoad {

self.view.wantsLayer = YES; // Back the view with a layer created by the makeBackingLayer method.

const char* argv[] = { "cube" };
// Enabling this will sync the rendering loop with the natural display link (60 fps).
// Disabling this will allow the rendering loop to run flat out, limited only by the rendering speed.
bool useDisplayLink = true;

VkPresentModeKHR vkPresentMode = useDisplayLink ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR;
char vkPresentModeStr[64];
sprintf(vkPresentModeStr, "%d", vkPresentMode);

const char* argv[] = { "cube", "--present_mode", vkPresentModeStr };
int argc = sizeof(argv)/sizeof(char*);
demo_main(&demo, self.view.layer, argc, argv);

CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo);
CVDisplayLinkStart(_displayLink);
if (useDisplayLink) {
CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
CVDisplayLinkSetOutputCallback(_displayLink, &DisplayLinkCallback, &demo);
CVDisplayLinkStart(_displayLink);
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while(true) {
demo_draw(&demo);
}
});
}
}


Expand Down
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MoltenVK 1.2.5
Released TBD

- Ensure non-dispatch compute commands don't interfere with compute encoding state used by dispatch commands.
- Add support for `VK_PRESENT_MODE_IMMEDIATE_KHR` to macOS Cube demo.



Expand Down
1 change: 0 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,6 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}

void MVKDevice::logPerformanceSummary() {
if (_activityPerformanceLoggingStyle == MVK_CONFIG_ACTIVITY_PERFORMANCE_LOGGING_STYLE_IMMEDIATE) { return; }

// Get a copy to minimize time under lock
MVKPerformanceStatistics perfStats;
Expand Down
4 changes: 3 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@
perfLogCntLimit,
(1000.0 / _device->_performanceStatistics.queue.frameInterval.averageDuration),
mvkGetElapsedMilliseconds() / 1000.0);
_device->logPerformanceSummary();
if (mvkConfig().activityPerformanceLoggingStyle == MVK_CONFIG_ACTIVITY_PERFORMANCE_LOGGING_STYLE_FRAME_COUNT) {
_device->logPerformanceSummary();
}
}
}

Expand Down

0 comments on commit 0332055

Please sign in to comment.