mirror of
https://github.com/mupen64plus-ae/parallel-rdp-standalone.git
synced 2025-02-17 05:47:50 +00:00
Update to e5efa5836cd43a597c706e07f04e79083d5ffb4f
This commit is contained in:
parent
e79d0cb775
commit
0dcebe11ee
2
COMMIT
2
COMMIT
@ -1 +1 @@
|
||||
b3eeb49e708a215ee990415f303ce9936e55bd66
|
||||
e5efa5836cd43a597c706e07f04e79083d5ffb4f
|
||||
|
130
util/timer.cpp
130
util/timer.cpp
@ -23,16 +23,12 @@
|
||||
#include "timer.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/timerfd.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace Util
|
||||
{
|
||||
FrameTimer::FrameTimer()
|
||||
@ -102,11 +98,6 @@ struct QPCFreq
|
||||
} static static_qpc_freq;
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(CLOCK_MONOTONIC_RAW)
|
||||
#warning "CLOCK_MONOTONIC_RAW is not defined?"
|
||||
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
int64_t get_current_time_nsecs()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -132,123 +123,4 @@ double Timer::end()
|
||||
auto nt = get_current_time_nsecs();
|
||||
return double(nt - t) * 1e-9;
|
||||
}
|
||||
|
||||
struct FrameLimiter::Impl
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE timer_handle = nullptr;
|
||||
#else
|
||||
int timer_fd = -1;
|
||||
#endif
|
||||
|
||||
bool begin_interval_ns(uint64_t ns)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!timer_handle)
|
||||
{
|
||||
timer_handle = CreateWaitableTimerA(nullptr, FALSE, nullptr);
|
||||
if (timer_handle)
|
||||
timeBeginPeriod(1);
|
||||
}
|
||||
|
||||
if (!timer_handle)
|
||||
return false;
|
||||
|
||||
LARGE_INTEGER due_time;
|
||||
due_time.QuadPart = -int64_t(ns) / 100;
|
||||
if (!SetWaitableTimer(timer_handle, &due_time, ns / 1000000,
|
||||
nullptr, nullptr, FALSE))
|
||||
{
|
||||
CloseHandle(timer_handle);
|
||||
timer_handle = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
#elif defined(__linux__)
|
||||
if (timer_fd < 0)
|
||||
timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
|
||||
if (timer_fd >= 0)
|
||||
{
|
||||
itimerspec timerspec = {};
|
||||
timerspec.it_value.tv_nsec = ns % (1000 * 1000 * 1000);
|
||||
timerspec.it_value.tv_sec = ns / (1000 * 1000 * 1000);
|
||||
timerspec.it_interval = timerspec.it_value;
|
||||
if (timerfd_settime(timer_fd, TFD_TIMER_CANCEL_ON_SET, &timerspec, nullptr) < 0)
|
||||
{
|
||||
close(timer_fd);
|
||||
timer_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return timer_fd >= 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wait_interval()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!timer_handle)
|
||||
return false;
|
||||
return WaitForSingleObject(timer_handle, INFINITE) == WAIT_OBJECT_0;
|
||||
#elif defined(__linux__)
|
||||
if (timer_fd < 0)
|
||||
return false;
|
||||
uint64_t expirations = 0;
|
||||
return ::read(timer_fd, &expirations, sizeof(expirations)) > 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_active() const
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return timer_handle != nullptr;
|
||||
#else
|
||||
return timer_fd >= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
~Impl()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (timer_handle)
|
||||
{
|
||||
CloseHandle(timer_handle);
|
||||
timeEndPeriod(1);
|
||||
}
|
||||
#else
|
||||
if (timer_fd >= 0)
|
||||
::close(timer_fd);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
FrameLimiter::FrameLimiter()
|
||||
{
|
||||
impl.reset(new Impl);
|
||||
}
|
||||
|
||||
FrameLimiter::~FrameLimiter()
|
||||
{
|
||||
}
|
||||
|
||||
bool FrameLimiter::is_active() const
|
||||
{
|
||||
return impl->is_active();
|
||||
}
|
||||
|
||||
bool FrameLimiter::begin_interval_ns(uint64_t ns)
|
||||
{
|
||||
return impl->begin_interval_ns(ns);
|
||||
}
|
||||
|
||||
bool FrameLimiter::wait_interval()
|
||||
{
|
||||
return impl->wait_interval();
|
||||
}
|
||||
}
|
@ -23,7 +23,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Util
|
||||
{
|
||||
@ -50,20 +49,6 @@ private:
|
||||
int64_t get_time();
|
||||
};
|
||||
|
||||
class FrameLimiter
|
||||
{
|
||||
public:
|
||||
FrameLimiter();
|
||||
~FrameLimiter();
|
||||
bool begin_interval_ns(uint64_t ns);
|
||||
bool wait_interval();
|
||||
bool is_active() const;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
|
@ -30,15 +30,6 @@ namespace Vulkan
|
||||
{
|
||||
WSI::WSI()
|
||||
{
|
||||
const char *frame_time_ms = getenv("GRANITE_FRAME_TIME_MS");
|
||||
if (frame_time_ms)
|
||||
{
|
||||
auto period_ms = atol(frame_time_ms);
|
||||
LOGI("Limiting frame time to %ld ms.\n", period_ms);
|
||||
if (!frame_limiter.begin_interval_ns(1000000ull * period_ms))
|
||||
LOGE("Failed to begin timer.\n");
|
||||
}
|
||||
|
||||
// With frame latency of 1, we get the ideal latency where
|
||||
// we present, and then wait for the previous present to complete.
|
||||
// Once this unblocks, it means that the present we just queued up is scheduled to complete next vblank,
|
||||
@ -436,9 +427,6 @@ bool WSI::end_frame()
|
||||
{
|
||||
device->end_frame_context();
|
||||
|
||||
if (frame_limiter.is_active())
|
||||
frame_limiter.wait_interval();
|
||||
|
||||
// Take ownership of the release semaphore so that the external user can use it.
|
||||
if (frame_is_external)
|
||||
{
|
||||
|
@ -239,7 +239,6 @@ private:
|
||||
unsigned present_frame_latency = 0;
|
||||
|
||||
WSITiming timing;
|
||||
Util::FrameLimiter frame_limiter;
|
||||
|
||||
void tear_down_swapchain();
|
||||
void drain_swapchain();
|
||||
|
Loading…
x
Reference in New Issue
Block a user