From fcb5f6d1d3675b1b0bd50a186918a78b46975744 Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Tue, 15 Aug 2017 21:30:45 +0000 Subject: [PATCH] Voodoo2: Now only start processing of the CMDFIFO at the vertical retrace. I noticed a speed improvement of around 10 % (tested with donut demo only). --- bochs/iodev/display/voodoo.cc | 17 ++++++++++++++++- bochs/iodev/display/voodoo_data.h | 3 +++ bochs/iodev/display/voodoo_func.h | 10 ++-------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bochs/iodev/display/voodoo.cc b/bochs/iodev/display/voodoo.cc index 3fd2dc836..ab217e12d 100644 --- a/bochs/iodev/display/voodoo.cc +++ b/bochs/iodev/display/voodoo.cc @@ -166,15 +166,22 @@ BX_THREAD_FUNC(cmdfifo_thread, indata) while (1) { #ifdef WIN32 if (WaitForSingleObject(v->fbi.cmdfifo[0].event, 1) == WAIT_OBJECT_0) { + BX_LOCK(cmdfifo_mutex); while (v->fbi.cmdfifo[0].enable && (v->fbi.cmdfifo[0].depth >= v->fbi.cmdfifo[0].depth_needed)) { cmdfifo_process(); } + v->fbi.cmdfifo[0].cmd_ready = 0; + BX_UNLOCK(cmdfifo_mutex); } #else + while (!v->fbi.cmdfifo[0].event) BX_MSLEEP(1); + BX_LOCK(cmdfifo_mutex); while (v->fbi.cmdfifo[0].enable && (v->fbi.cmdfifo[0].depth >= v->fbi.cmdfifo[0].depth_needed)) { cmdfifo_process(); } - BX_MSLEEP(1); + v->fbi.cmdfifo[0].cmd_ready = 0; + v->fbi.cmdfifo[0].event = 0; + BX_UNLOCK(cmdfifo_mutex); #endif } BX_THREAD_EXIT; @@ -603,6 +610,14 @@ void bx_voodoo_c::vertical_timer_handler(void *this_ptr) BX_VOODOO_THIS s.vdraw.frame_start = bx_virt_timer.time_usec(BX_VOODOO_THIS s.vdraw.realtime); + if (v->fbi.cmdfifo[0].cmd_ready) { +#ifdef WIN32 + SetEvent(v->fbi.cmdfifo[0].event); +#else + v->fbi.cmdfifo[0].event = 1; +#endif + } + if (v->fbi.vblank_swap_pending) { swap_buffers(v); } diff --git a/bochs/iodev/display/voodoo_data.h b/bochs/iodev/display/voodoo_data.h index 81bbf084c..3659a7ffa 100644 --- a/bochs/iodev/display/voodoo_data.h +++ b/bochs/iodev/display/voodoo_data.h @@ -1439,8 +1439,11 @@ struct _cmdfifo_info Bit32u depth; /* current depth */ Bit32u depth_needed; /* depth needed for command */ Bit32u holes; /* number of holes */ + bx_bool cmd_ready; #ifdef WIN32 HANDLE event; +#else + bx_bool event; #endif }; diff --git a/bochs/iodev/display/voodoo_func.h b/bochs/iodev/display/voodoo_func.h index aeb612283..cdafd36ed 100644 --- a/bochs/iodev/display/voodoo_func.h +++ b/bochs/iodev/display/voodoo_func.h @@ -2406,9 +2406,7 @@ Bit32u cmdfifo_calc_depth_needed(void) if (v->fbi.cmdfifo[0].depth == 0) return needed; - BX_LOCK(cmdfifo_mutex); command = *(Bit32u*)(&v->fbi.ram[v->fbi.cmdfifo[0].rdptr & v->fbi.mask]); - BX_UNLOCK(cmdfifo_mutex); type = (Bit8u)(command & 0x07); switch (type) { case 0: @@ -2462,26 +2460,22 @@ void cmdfifo_w(Bit32u fbi_offset, Bit32u data) BX_LOCK(cmdfifo_mutex); *(Bit32u*)(&v->fbi.ram[fbi_offset]) = data; v->fbi.cmdfifo[0].depth++; - BX_UNLOCK(cmdfifo_mutex); if (v->fbi.cmdfifo[0].depth_needed == BX_MAX_BIT32U) { v->fbi.cmdfifo[0].depth_needed = cmdfifo_calc_depth_needed(); } -#ifdef WIN32 if (v->fbi.cmdfifo[0].depth >= v->fbi.cmdfifo[0].depth_needed) { - SetEvent(v->fbi.cmdfifo[0].event); + v->fbi.cmdfifo[0].cmd_ready = 1; } -#endif + BX_UNLOCK(cmdfifo_mutex); } Bit32u cmdfifo_r(void) { Bit32u data; - BX_LOCK(cmdfifo_mutex); data = *(Bit32u*)(&v->fbi.ram[v->fbi.cmdfifo[0].rdptr & v->fbi.mask]); v->fbi.cmdfifo[0].rdptr += 4; v->fbi.cmdfifo[0].depth--; - BX_UNLOCK(cmdfifo_mutex); return data; }