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).
This commit is contained in:
Volker Ruppert 2017-08-15 21:30:45 +00:00
parent 7f4a9b4b08
commit fcb5f6d1d3
3 changed files with 21 additions and 9 deletions

View File

@ -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);
}

View File

@ -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
};

View File

@ -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;
}