mirror of https://github.com/AxioDL/boo.git
Remove targetFrameTime / Limiter
This commit is contained in:
parent
f4b1e12956
commit
55deba0913
|
@ -56,21 +56,20 @@ public:
|
||||||
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName,
|
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName,
|
||||||
SystemStringView friendlyName, SystemStringView pname, const std::vector<SystemString>& args,
|
SystemStringView friendlyName, SystemStringView pname, const std::vector<SystemString>& args,
|
||||||
std::string_view gfxApi = {}, uint32_t samples = 1, uint32_t anisotropy = 1, bool deepColor = false,
|
std::string_view gfxApi = {}, uint32_t samples = 1, uint32_t anisotropy = 1, bool deepColor = false,
|
||||||
int64_t targetFrameTime = 0, bool singleInstance = true);
|
bool singleInstance = true);
|
||||||
extern IApplication* APP;
|
extern IApplication* APP;
|
||||||
|
|
||||||
static inline int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb,
|
static inline int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb,
|
||||||
SystemStringView uniqueName, SystemStringView friendlyName, int argc,
|
SystemStringView uniqueName, SystemStringView friendlyName, int argc,
|
||||||
const SystemChar** argv, std::string_view gfxApi = {}, uint32_t samples = 1,
|
const SystemChar** argv, std::string_view gfxApi = {}, uint32_t samples = 1,
|
||||||
uint32_t anisotropy = 1, bool deepColor = false, int64_t targetFrameTime = 0,
|
uint32_t anisotropy = 1, bool deepColor = false, bool singleInstance = true) {
|
||||||
bool singleInstance = true) {
|
|
||||||
if (APP)
|
if (APP)
|
||||||
return 1;
|
return 1;
|
||||||
std::vector<SystemString> args;
|
std::vector<SystemString> args;
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
args.push_back(argv[i]);
|
args.push_back(argv[i]);
|
||||||
return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args, gfxApi, samples, anisotropy, deepColor,
|
return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args, gfxApi, samples, anisotropy, deepColor,
|
||||||
targetFrameTime, singleInstance);
|
singleInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace boo
|
} // namespace boo
|
||||||
|
|
|
@ -97,7 +97,6 @@ struct VulkanContext {
|
||||||
VkSampleCountFlags m_sampleCountDepth = VK_SAMPLE_COUNT_1_BIT;
|
VkSampleCountFlags m_sampleCountDepth = VK_SAMPLE_COUNT_1_BIT;
|
||||||
float m_anisotropy = 1.f;
|
float m_anisotropy = 1.f;
|
||||||
bool m_deepColor = false;
|
bool m_deepColor = false;
|
||||||
int64_t m_targetFrameTime = 0;
|
|
||||||
|
|
||||||
std::unordered_map<uint32_t, VkSampler> m_samplers;
|
std::unordered_map<uint32_t, VkSampler> m_samplers;
|
||||||
|
|
||||||
|
|
|
@ -15,26 +15,4 @@ void UpdateGammaLUT(ITextureD* tex, float gamma) {
|
||||||
tex->unmap();
|
tex->unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Limiter::Sleep(nanotime_t targetFrameTime) {
|
|
||||||
OPTICK_EVENT();
|
|
||||||
if (targetFrameTime == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto start = delta_clock::now();
|
|
||||||
nanotime_t sleepTime = targetFrameTime - TimeSince(m_oldTime);
|
|
||||||
m_overhead = std::accumulate(m_overheadTimes.begin(), m_overheadTimes.end(), nanotime_t{}) /
|
|
||||||
static_cast<nanotime_t>(m_overheadTimes.size());
|
|
||||||
if (sleepTime > m_overhead) {
|
|
||||||
nanotime_t adjustedSleepTime = sleepTime - m_overhead;
|
|
||||||
std::this_thread::sleep_for(std::chrono::nanoseconds(adjustedSleepTime));
|
|
||||||
nanotime_t overslept = TimeSince(start) - adjustedSleepTime;
|
|
||||||
if (overslept < targetFrameTime) {
|
|
||||||
m_overheadTimes[m_overheadTimeIdx] = overslept;
|
|
||||||
m_overheadTimeIdx = (m_overheadTimeIdx + 1) % m_overheadTimes.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_oldTime = delta_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace boo
|
} // namespace boo
|
||||||
|
|
|
@ -285,22 +285,4 @@ public:
|
||||||
#define SCOPED_GRAPHICS_DEBUG_GROUP(_, name, ...) OPTICK_EVENT(name)
|
#define SCOPED_GRAPHICS_DEBUG_GROUP(_, name, ...) OPTICK_EVENT(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Limiter {
|
|
||||||
using delta_clock = std::chrono::steady_clock;
|
|
||||||
using nanotime_t = std::chrono::nanoseconds::rep;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Sleep(nanotime_t targetFrameTimeNs);
|
|
||||||
|
|
||||||
private:
|
|
||||||
delta_clock::time_point m_oldTime;
|
|
||||||
std::array<nanotime_t, 4> m_overheadTimes{};
|
|
||||||
size_t m_overheadTimeIdx = 0;
|
|
||||||
nanotime_t m_overhead = 0;
|
|
||||||
|
|
||||||
nanotime_t TimeSince(delta_clock::time_point start) {
|
|
||||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(delta_clock::now() - start).count();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boo
|
} // namespace boo
|
||||||
|
|
|
@ -2883,8 +2883,6 @@ struct VulkanCommandQueue final : IGraphicsCommandQueue {
|
||||||
|
|
||||||
std::vector<boo::ObjToken<boo::IObj>> m_drawResTokens[2];
|
std::vector<boo::ObjToken<boo::IObj>> m_drawResTokens[2];
|
||||||
|
|
||||||
Limiter m_frameLimiter;
|
|
||||||
|
|
||||||
void resetCommandBuffer() {
|
void resetCommandBuffer() {
|
||||||
ThrowIfFailed(vk::ResetCommandBuffer(m_cmdBufs[m_fillBuf], 0));
|
ThrowIfFailed(vk::ResetCommandBuffer(m_cmdBufs[m_fillBuf], 0));
|
||||||
VkCommandBufferBeginInfo cmdBufBeginInfo = {};
|
VkCommandBufferBeginInfo cmdBufBeginInfo = {};
|
||||||
|
@ -4163,7 +4161,6 @@ void VulkanCommandQueue::execute() {
|
||||||
} else {
|
} else {
|
||||||
ThrowIfFailed(res);
|
ThrowIfFailed(res);
|
||||||
}
|
}
|
||||||
m_frameLimiter.Sleep(m_ctx->m_targetFrameTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resetCommandBuffer();
|
resetCommandBuffer();
|
||||||
|
|
|
@ -211,7 +211,6 @@ int ApplicationRun(IApplication::EPlatformType platform,
|
||||||
uint32_t samples,
|
uint32_t samples,
|
||||||
uint32_t anisotropy,
|
uint32_t anisotropy,
|
||||||
bool deepColor,
|
bool deepColor,
|
||||||
int64_t targetFrameTime,
|
|
||||||
bool singleInstance) {
|
bool singleInstance) {
|
||||||
std::string thrName = std::string(friendlyName) + " Main Thread";
|
std::string thrName = std::string(friendlyName) + " Main Thread";
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
|
|
|
@ -97,7 +97,7 @@ class ApplicationWin32 final : public IApplication {
|
||||||
public:
|
public:
|
||||||
ApplicationWin32(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName,
|
ApplicationWin32(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName,
|
||||||
SystemStringView pname, const std::vector<SystemString>& args, std::string_view gfxApi,
|
SystemStringView pname, const std::vector<SystemString>& args, std::string_view gfxApi,
|
||||||
uint32_t samples, uint32_t anisotropy, bool deepColor, int64_t targetFrameTime, bool singleInstance)
|
uint32_t samples, uint32_t anisotropy, bool deepColor, bool singleInstance)
|
||||||
: m_callback(callback), m_uniqueName(uniqueName), m_friendlyName(friendlyName), m_pname(pname), m_args(args) {
|
: m_callback(callback), m_uniqueName(uniqueName), m_friendlyName(friendlyName), m_pname(pname), m_args(args) {
|
||||||
m_3dCtx.m_ctx11.m_sampleCount = samples;
|
m_3dCtx.m_ctx11.m_sampleCount = samples;
|
||||||
m_3dCtx.m_ctx11.m_anisotropy = anisotropy;
|
m_3dCtx.m_ctx11.m_anisotropy = anisotropy;
|
||||||
|
@ -112,7 +112,6 @@ public:
|
||||||
g_VulkanContext.m_sampleCountDepth = samples;
|
g_VulkanContext.m_sampleCountDepth = samples;
|
||||||
g_VulkanContext.m_anisotropy = anisotropy;
|
g_VulkanContext.m_anisotropy = anisotropy;
|
||||||
g_VulkanContext.m_deepColor = deepColor;
|
g_VulkanContext.m_deepColor = deepColor;
|
||||||
g_VulkanContext.m_targetFrameTime = targetFrameTime;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HMODULE dxgilib = LoadLibraryW(L"dxgi.dll");
|
HMODULE dxgilib = LoadLibraryW(L"dxgi.dll");
|
||||||
|
@ -473,7 +472,7 @@ IApplication* APP = nullptr;
|
||||||
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName,
|
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName,
|
||||||
SystemStringView friendlyName, SystemStringView pname, const std::vector<SystemString>& args,
|
SystemStringView friendlyName, SystemStringView pname, const std::vector<SystemString>& args,
|
||||||
std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor,
|
std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor,
|
||||||
int64_t targetFrameTime, bool singleInstance) {
|
bool singleInstance) {
|
||||||
std::string thrName = WCSTMBS(friendlyName.data()) + " Main Thread";
|
std::string thrName = WCSTMBS(friendlyName.data()) + " Main Thread";
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
if (APP)
|
if (APP)
|
||||||
|
@ -502,7 +501,7 @@ int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& c
|
||||||
RegisterClassW(&wndClass);
|
RegisterClassW(&wndClass);
|
||||||
|
|
||||||
APP = new ApplicationWin32(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor,
|
APP = new ApplicationWin32(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor,
|
||||||
targetFrameTime, singleInstance);
|
singleInstance);
|
||||||
int ret = APP->run();
|
int ret = APP->run();
|
||||||
delete APP;
|
delete APP;
|
||||||
APP = nullptr;
|
APP = nullptr;
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace boo {
|
||||||
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, std::string_view uniqueName,
|
int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, std::string_view uniqueName,
|
||||||
std::string_view friendlyName, std::string_view pname, const std::vector<std::string>& args,
|
std::string_view friendlyName, std::string_view pname, const std::vector<std::string>& args,
|
||||||
std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor,
|
std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor,
|
||||||
int64_t targetFrameTime, bool singleInstance) {
|
bool singleInstance) {
|
||||||
std::string thrName = std::string(friendlyName) + " Main";
|
std::string thrName = std::string(friendlyName) + " Main";
|
||||||
logvisor::RegisterThreadName(thrName.c_str());
|
logvisor::RegisterThreadName(thrName.c_str());
|
||||||
if (APP)
|
if (APP)
|
||||||
|
@ -135,7 +135,7 @@ int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& c
|
||||||
singleInstance);
|
singleInstance);
|
||||||
else if (platform == IApplication::EPlatformType::Xlib || platform == IApplication::EPlatformType::Auto)
|
else if (platform == IApplication::EPlatformType::Xlib || platform == IApplication::EPlatformType::Auto)
|
||||||
APP = new ApplicationXlib(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor,
|
APP = new ApplicationXlib(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor,
|
||||||
targetFrameTime, singleInstance);
|
singleInstance);
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
int ret = APP->run();
|
int ret = APP->run();
|
||||||
|
|
|
@ -203,7 +203,7 @@ class ApplicationXlib final : public IApplication {
|
||||||
public:
|
public:
|
||||||
ApplicationXlib(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
ApplicationXlib(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName,
|
||||||
std::string_view pname, const std::vector<std::string>& args, std::string_view gfxApi,
|
std::string_view pname, const std::vector<std::string>& args, std::string_view gfxApi,
|
||||||
uint32_t samples, uint32_t anisotropy, bool deepColor, int64_t targetFrameTime, bool singleInstance)
|
uint32_t samples, uint32_t anisotropy, bool deepColor, bool singleInstance)
|
||||||
: m_callback(callback)
|
: m_callback(callback)
|
||||||
, m_uniqueName(uniqueName)
|
, m_uniqueName(uniqueName)
|
||||||
, m_friendlyName(friendlyName)
|
, m_friendlyName(friendlyName)
|
||||||
|
@ -218,7 +218,6 @@ public:
|
||||||
g_VulkanContext.m_sampleCountDepth = samples;
|
g_VulkanContext.m_sampleCountDepth = samples;
|
||||||
g_VulkanContext.m_anisotropy = anisotropy;
|
g_VulkanContext.m_anisotropy = anisotropy;
|
||||||
g_VulkanContext.m_deepColor = deepColor;
|
g_VulkanContext.m_deepColor = deepColor;
|
||||||
g_VulkanContext.m_targetFrameTime = targetFrameTime;
|
|
||||||
|
|
||||||
/* Check for Vulkan presence and preference */
|
/* Check for Vulkan presence and preference */
|
||||||
bool tryVulkan = true;
|
bool tryVulkan = true;
|
||||||
|
|
Loading…
Reference in New Issue