Making the GPU counter a vblank counter, not a timer.

This commit is contained in:
Ben Vanik 2013-10-20 02:00:51 -07:00
parent 39adeef2e3
commit fbea5a6394
6 changed files with 18 additions and 8 deletions

View File

@ -22,6 +22,7 @@ using namespace xe::gpu::d3d11;
namespace {
void __stdcall D3D11GraphicsSystemVsyncCallback(D3D11GraphicsSystem* gs, BOOLEAN) {
gs->MarkVblank();
gs->DispatchInterruptCallback(0);
}

View File

@ -160,6 +160,10 @@ void GraphicsSystem::WriteRegister(uint32_t r, uint64_t value) {
regs->values[r].u32 = (uint32_t)value;
}
void GraphicsSystem::MarkVblank() {
worker_->increment_counter();
}
void GraphicsSystem::DispatchInterruptCallback(
uint32_t source, uint32_t cpu) {
// Pick a CPU, if needed. We're going to guess 2. Because.

View File

@ -52,6 +52,7 @@ public:
virtual uint64_t ReadRegister(uint32_t r);
virtual void WriteRegister(uint32_t r, uint64_t value);
void MarkVblank();
void DispatchInterruptCallback(uint32_t source, uint32_t cpu = 0xFFFFFFFF);
bool swap_pending() const { return swap_pending_; }
void set_swap_pending(bool value) { swap_pending_ = value; }

View File

@ -21,6 +21,7 @@ using namespace xe::gpu::nop;
namespace {
void __stdcall NopGraphicsSystemVsyncCallback(NopGraphicsSystem* gs, BOOLEAN) {
gs->MarkVblank();
gs->DispatchInterruptCallback(0);
}

View File

@ -36,7 +36,8 @@ RingBufferWorker::RingBufferWorker(
LARGE_INTEGER perf_counter;
QueryPerformanceCounter(&perf_counter);
counter_base_ = perf_counter.QuadPart;
time_base_ = perf_counter.QuadPart;
counter_ = 0;
}
RingBufferWorker::~RingBufferWorker() {
@ -44,10 +45,10 @@ RingBufferWorker::~RingBufferWorker() {
CloseHandle(write_ptr_index_event_);
}
uint64_t RingBufferWorker::GetCounter() {
uint64_t RingBufferWorker::QueryTime() {
LARGE_INTEGER perf_counter;
QueryPerformanceCounter(&perf_counter);
return perf_counter.QuadPart - counter_base_;
return perf_counter.QuadPart - time_base_;
}
void RingBufferWorker::Initialize(GraphicsDriver* driver,
@ -476,9 +477,8 @@ uint32_t RingBufferWorker::ExecutePacket(PacketArgs& args) {
WriteRegister(XE_GPU_REG_VGT_EVENT_INITIATOR, initiator & 0x1F);
uint32_t data_value;
if ((initiator >> 31) & 0x1) {
// Write counter (GPU clock counter?).
// TODO(benvanik): 64-bit write?
data_value = (uint32_t)GetCounter();
// Write counter (GPU vblank counter?).
data_value = counter_;
} else {
// Write value.
data_value = value;

View File

@ -28,7 +28,9 @@ public:
xe_memory_ref memory();
uint64_t GetCounter();
uint64_t QueryTime();
uint32_t counter() const { return counter_; }
void increment_counter() { counter_++; }
void Initialize(GraphicsDriver* driver,
uint32_t ptr, uint32_t page_count);
@ -56,7 +58,8 @@ protected:
GraphicsSystem* graphics_system_;
GraphicsDriver* driver_;
uint64_t counter_base_;
uint64_t time_base_;
uint32_t counter_;
uint32_t primary_buffer_ptr_;
uint32_t primary_buffer_size_;