MCPcopy Create free account
hub / github.com/LunarG/VulkanTools / onQueuePresentKHR

Function onQueuePresentKHR

layersvt/screenshot.cpp:1643–1707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1641}
1642
1643void onQueuePresentKHR(VkQueue queue, VkPresentInfoKHR &presentInfo) {
1644 static int frameNumber = -1;
1645 ++frameNumber;
1646 if (!settings.isFrameToCapture(frameNumber)) {
1647 return;
1648 }
1649 if (std::atomic_load(&pauseCapture)) {
1650 // Wake up screenshot thread to check whether we should unpause screenshot recording
1651 screenshotQueuedCV.notify_one();
1652 return;
1653 }
1654 if (presentInfo.swapchainCount == 0) {
1655 // If there are 0 swapchains, skip taking the snapshot
1656#ifdef ANDROID
1657 __android_log_print(ANDROID_LOG_ERROR, "screenshot", "Failure - no swapchain specified\n");
1658#else
1659 fprintf(stderr, "screenshot: Failure - no swapchain specified\n");
1660#endif
1661 return;
1662 }
1663
1664 std::unique_lock<std::mutex> lock(globalLock);
1665 if (!settings.allowToSkipFrames && screenshotsData.size() >= settings.maxScreenshotQueueSize) {
1666 PROFILE("screenshot.wait");
1667 screenshotSavedCV.wait(lock, [] { return screenshotsData.size() < settings.maxScreenshotQueueSize; });
1668 }
1669 // We'll dump only one image: the first
1670 VkSwapchainKHR swapchain = presentInfo.pSwapchains[0];
1671 if (swapchainMap.find(swapchain) == swapchainMap.end()) {
1672#ifdef ANDROID
1673 __android_log_print(ANDROID_LOG_INFO, "screenshot", "Present with inactive swapchain: %p", swapchain);
1674#else
1675 printf("screenshot: Present with inactive swapchain: %p\n", swapchain);
1676#endif
1677 return;
1678 }
1679 if (settings.allowToSkipFrames && screenshotsData.size() >= settings.maxScreenshotQueueSize) {
1680 static int skippedFrames = 0;
1681 PROFILE_COUNTER("screenshot.SkippedFrames", ++skippedFrames);
1682 return;
1683 }
1684 std::shared_ptr<ScreenshotQueueData> data;
1685 VkImage image = swapchainMap[swapchain].imageList[presentInfo.pImageIndices[0]];
1686 if (!screenshotDataCache[image].empty()) {
1687 data = screenshotDataCache[image].back();
1688 screenshotDataCache[image].pop_back();
1689 } else {
1690 data = std::make_shared<ScreenshotQueueData>();
1691 }
1692 if (queueScreenshot(*data, image, &presentInfo)) {
1693 presentInfo.pWaitSemaphores = &data->semaphore;
1694 presentInfo.waitSemaphoreCount = 1;
1695 data->frameNumber = frameNumber;
1696 screenshotsData.emplace_back(data);
1697 PROFILE_COUNTER("screenshot.QueueSize", screenshotsData.size());
1698 startScreenshotThread();
1699#ifdef ANDROID
1700 __android_log_print(ANDROID_LOG_INFO, "screenshot", "Queued screeshot for frame: %d", frameNumber);

Callers 1

QueuePresentKHRFunction · 0.85

Calls 3

queueScreenshotFunction · 0.85
startScreenshotThreadFunction · 0.85
isFrameToCaptureMethod · 0.80

Tested by

no test coverage detected