Refactoring to enable future time scaling, coordinated clocks, etc.

This commit is contained in:
Ben Vanik
2015-05-26 22:20:46 -07:00
parent 05f2577fb7
commit 8244409501
19 changed files with 213 additions and 57 deletions

View File

@@ -59,7 +59,6 @@ CommandProcessor::CommandProcessor(GL4GraphicsSystem* graphics_system)
trace_state_(TraceState::kDisabled),
worker_running_(true),
swap_mode_(SwapMode::kNormal),
time_base_(0),
counter_(0),
primary_buffer_ptr_(0),
primary_buffer_size_(0),
@@ -83,19 +82,10 @@ CommandProcessor::CommandProcessor(GL4GraphicsSystem* graphics_system)
draw_index_count_(0),
draw_batcher_(graphics_system_->register_file()),
scratch_buffer_(kScratchBufferCapacity, kScratchBufferAlignment) {
LARGE_INTEGER perf_counter;
QueryPerformanceCounter(&perf_counter);
time_base_ = perf_counter.QuadPart;
}
CommandProcessor::~CommandProcessor() { CloseHandle(write_ptr_index_event_); }
uint64_t CommandProcessor::QueryTime() {
LARGE_INTEGER perf_counter;
QueryPerformanceCounter(&perf_counter);
return perf_counter.QuadPart - time_base_;
}
bool CommandProcessor::Initialize(std::unique_ptr<GLContext> context) {
context_ = std::move(context);

View File

@@ -62,7 +62,6 @@ class CommandProcessor {
typedef std::function<void(const SwapParameters& params)> SwapHandler;
void set_swap_handler(SwapHandler fn) { swap_handler_ = fn; }
uint64_t QueryTime();
uint32_t counter() const { return counter_; }
void increment_counter() { counter_++; }
@@ -243,7 +242,6 @@ class CommandProcessor {
SwapMode swap_mode_;
uint64_t time_base_;
uint32_t counter_;
uint32_t primary_buffer_ptr_;

View File

@@ -9,6 +9,7 @@
#include "xenia/gpu/gl4/gl4_graphics_system.h"
#include "xenia/base/clock.h"
#include "xenia/base/logging.h"
#include "xenia/base/threading.h"
#include "xenia/cpu/processor.h"
@@ -86,11 +87,11 @@ X_STATUS GL4GraphicsSystem::Setup(cpu::Processor* processor,
kernel::object_ref<kernel::XHostThread>(new kernel::XHostThread(
emulator()->kernel_state(), 128 * 1024, 0, [this]() {
uint64_t vsync_duration = FLAGS_vsync ? 16 : 1;
uint64_t last_frame_time = xe::threading::ticks();
uint64_t last_frame_time = Clock::QueryGuestTickCount();
while (worker_running_) {
uint64_t current_time = xe::threading::ticks();
uint64_t current_time = Clock::QueryGuestTickCount();
uint64_t elapsed = (current_time - last_frame_time) /
(xe::threading::ticks_per_second() / 1000);
(Clock::guest_tick_frequency() / 1000);
if (elapsed >= vsync_duration) {
MarkVblank();
last_frame_time = current_time;

View File

@@ -11,6 +11,7 @@
#include "third_party/imgui/imgui.h"
#include "xenia/base/clock.h"
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
#include "xenia/base/mapped_memory.h"
@@ -2272,10 +2273,10 @@ int trace_viewer_main(std::vector<std::wstring>& args) {
imgui_setup = true;
}
auto& io = ImGui::GetIO();
auto current_ticks = xe::threading::ticks();
auto current_ticks = Clock::QueryHostTickCount();
static uint64_t last_ticks = 0;
io.DeltaTime = (current_ticks - last_ticks) /
float(xe::threading::ticks_per_second());
io.DeltaTime =
(current_ticks - last_ticks) / float(Clock::host_tick_frequency());
last_ticks = current_ticks;
io.DisplaySize =