diff options
Diffstat (limited to 'src/device_context.cc')
| -rw-r--r-- | src/device_context.cc | 67 |
1 files changed, 28 insertions, 39 deletions
diff --git a/src/device_context.cc b/src/device_context.cc index 2214b71..b149311 100644 --- a/src/device_context.cc +++ b/src/device_context.cc @@ -1,7 +1,6 @@ #include "device_context.hh" #include "queue_context.hh" -#include <iostream> #include <utility> #include <vulkan/vulkan_core.h> @@ -23,22 +22,6 @@ DeviceContext::~DeviceContext() { } } -void DeviceContext::notify_acquire(const VkSwapchainKHR& swapchain, - const std::uint32_t& image_index, - const VkSemaphore& signal_semaphore) { - - /* - std::cerr << "notify acquire for swapchain: " << swapchain << " : " - << image_index << '\n'; - std::cerr << " signal semaphore: " << signal_semaphore << '\n'; - */ - - const auto it = this->swapchain_signals.try_emplace(swapchain).first; - - // Doesn't matter if it was already there, overwrite it. - it->second.insert_or_assign(image_index, signal_semaphore); -} - DeviceContext::Clock::Clock(const DeviceContext& context) : device(context) { this->calibrate(); } @@ -92,17 +75,14 @@ DeviceContext::Clock::ticks_to_time(const std::uint64_t& ticks) const { return time_point_t{delta}; } -const auto debug_log_time2 = [](auto& stream, const auto& diff) { - using namespace std::chrono; - const auto ms = duration_cast<milliseconds>(diff); - const auto us = duration_cast<microseconds>(diff - ms); - const auto ns = duration_cast<nanoseconds>(diff - ms - us); - stream << ms << " " << us << " " << ns << '\n'; -}; +void DeviceContext::notify_acquire(const VkSwapchainKHR& swapchain, + const std::uint32_t& image_index, + const VkSemaphore& signal_semaphore) { + const auto it = this->swapchain_signals.try_emplace(swapchain).first; -const auto debug_log_time = [](const auto& diff) { - debug_log_time2(std::cerr, diff); -}; + // Doesn't matter if it was already there, overwrite it. + it->second.insert_or_assign(image_index, signal_semaphore); +} void DeviceContext::sleep_in_input() { // Present hasn't happened yet, we don't know what queue to attack. @@ -110,26 +90,35 @@ void DeviceContext::sleep_in_input() { return; } - const auto before = std::chrono::steady_clock::now(); + const auto& frames = this->present_queue->in_flight_frames; + // No frame here means we're behind the GPU and do not need to delay. + // If anything we should speed up... + if (!std::size(frames)) { + return; + } + // If we're here, that means that there might be an outstanding frame that's // sitting on our present_queue which hasn't yet completed, so we need to // stall until it's finished. - const auto& frames = this->present_queue->in_flight_frames; - if (std::size(frames)) { - frames.back().submissions.back()->end_handle->get_time_spinlock(); - } - const auto after = std::chrono::steady_clock::now(); - //debug_log_time(after - before); - - // FIXME this should take into account 'cpu_time', which we currently do not... - // idk if it matters. + const auto& last_frame = frames.back(); + assert(std::size(last_frame.submissions)); + const auto& last_frame_submission = frames.back().submissions.back(); + last_frame_submission->end_handle->get_time_spinlock(); + + // From our sleep in present implementation, just spinning until + // the previous frame has completed did not work well. This was because + // there was a delay between presentation and when new work was given + // to the GPU. If we stalled the CPU without trying to account for this, we + // would get huge frame drops, loss of throughput, and the GPU would even + // clock down. So naturally I am concerned about this approach, but it seems + // to perform well so far in my own testing and is just beautifully elegant. } void DeviceContext::notify_antilag_update(const VkAntiLagDataAMD& data) { this->antilag_mode = data.mode; - this->antilag_fps = data.maxFPS; + this->antilag_fps = data.maxFPS; // TODO - // This might not be provided (probably just to set some settings). + // This might not be provided (probably just to set some settings?). if (!data.pPresentationInfo) { return; } |
