| 1563 | } |
| 1564 | |
| 1565 | void screenshotWriterThreadFunc() { |
| 1566 | bool pauseFileRecorded = false; |
| 1567 | if (!std::atomic_load(&pauseCapture)) { |
| 1568 | std::remove(settings.pauseFileName.c_str()); |
| 1569 | } |
| 1570 | while (true) { |
| 1571 | { |
| 1572 | std::lock_guard<std::mutex> lock(globalLock); |
| 1573 | if (globalLayerSettingSet != VK_NULL_HANDLE) { |
| 1574 | updatePauseCapture(globalLayerSettingSet); |
| 1575 | } |
| 1576 | } |
| 1577 | bool paused = std::atomic_load(&pauseCapture); |
| 1578 | if (!paused && pauseFileRecorded) { |
| 1579 | std::remove(settings.pauseFileName.c_str()); // delete file |
| 1580 | pauseFileRecorded = false; |
| 1581 | } |
| 1582 | |
| 1583 | std::shared_ptr<ScreenshotQueueData> dataToSave; |
| 1584 | { |
| 1585 | PROFILE(paused ? "paused" : "Waiting for CPU") |
| 1586 | std::unique_lock<std::mutex> lock(globalLock); |
| 1587 | if (screenshotsData.empty()) { |
| 1588 | if (paused && !pauseFileRecorded) { |
| 1589 | std::ofstream pauseFile(settings.pauseFileName.c_str()); |
| 1590 | pauseFileRecorded = true; |
| 1591 | } |
| 1592 | // Make sure we don't wait on the CPU thread if we are shutting down, will deadlock. |
| 1593 | if (shutdownScreenshotThread) break; |
| 1594 | screenshotQueuedCV.wait(lock); |
| 1595 | } |
| 1596 | if (screenshotsData.empty()) continue; |
| 1597 | dataToSave = screenshotsData.front(); |
| 1598 | } |
| 1599 | |
| 1600 | VkResult fenceWaitResult = VK_TIMEOUT; |
| 1601 | { |
| 1602 | PROFILE("Waiting for GPU") |
| 1603 | while (fenceWaitResult == VK_TIMEOUT) { |
| 1604 | fenceWaitResult = |
| 1605 | dataToSave->pTableDevice->WaitForFences(dataToSave->device, 1, &dataToSave->fence, VK_TRUE, UINT64_MAX); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | if (fenceWaitResult == VK_SUCCESS) { |
| 1610 | writeScreenshot(*dataToSave); |
| 1611 | std::lock_guard<std::mutex> lock(globalLock); |
| 1612 | screenshotDataCache[dataToSave->image1].emplace_back(dataToSave); |
| 1613 | } |
| 1614 | { |
| 1615 | std::lock_guard<std::mutex> lock(globalLock); |
| 1616 | screenshotsData.pop_front(); |
| 1617 | PROFILE_COUNTER("screenshot.QueueSize", screenshotsData.size()); |
| 1618 | } |
| 1619 | |
| 1620 | screenshotSavedCV.notify_all(); |
| 1621 | |
| 1622 | if (settings.isFrameAfterEndOfCaptureRange(dataToSave->frameNumber + 1)) { |
nothing calls this directly
no test coverage detected