Add heuristic to deitermine run-time effect of VOSF acceleration, and

disable it if it turns out to not be profitable
This commit is contained in:
gbeauche 2004-06-26 15:22:02 +00:00
parent 46a9054861
commit 808b3e34c8
2 changed files with 70 additions and 23 deletions

View File

@ -99,7 +99,7 @@ static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread
static SDL_Thread *redraw_thread = NULL; // Redraw thread
#ifdef ENABLE_VOSF
static bool use_vosf = true; // Flag: VOSF enabled
static bool use_vosf = false; // Flag: VOSF enabled
#else
static const bool use_vosf = false; // VOSF not possible
#endif
@ -260,6 +260,12 @@ static void ErrorAlert(int error)
{
ErrorAlert(GetString(error));
}
// Display warning alert
static void WarningAlert(int warning)
{
WarningAlert(GetString(warning));
}
#endif
@ -624,14 +630,32 @@ driver_window::driver_window(SDL_monitor_desc &m)
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
#else
// Allocate memory for frame buffer
the_buffer_size = (aligned_height + 2) * s->pitch;
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
the_buffer = (uint8 *)calloc(1, the_buffer_size);
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
#endif
// Check whether we can initialize the VOSF subsystem and it's profitable
if (!video_vosf_init(m)) {
WarningAlert(STR_VOSF_INIT_ERR);
use_vosf = false;
}
else if (!video_vosf_profitable()) {
video_vosf_exit();
// WarningAlert(STR_VOSF_NOT_PROFITABLE_WARN);
printf("VOSF acceleration is not profitable on this platform\n");
use_vosf = false;
}
if (!use_vosf) {
free(the_buffer_copy);
vm_release(the_buffer, the_buffer_size);
the_host_buffer = NULL;
}
#endif
if (!use_vosf) {
// Allocate memory for frame buffer
the_buffer_size = (aligned_height + 2) * s->pitch;
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
the_buffer = (uint8 *)calloc(1, the_buffer_size);
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
}
#ifdef SHEEPSHAVER
// Create cursor
if ((sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, 0, 0)) != NULL) {
@ -823,16 +847,6 @@ bool SDL_monitor_desc::video_open(void)
return false;
}
#ifdef ENABLE_VOSF
if (use_vosf) {
// Initialize the VOSF system
if (!video_vosf_init(*this)) {
ErrorAlert(STR_VOSF_INIT_ERR);
return false;
}
}
#endif
// Initialize VideoRefresh function
VideoRefreshInit();
@ -1159,11 +1173,13 @@ void SDL_monitor_desc::set_palette(uint8 *pal, int num_in)
}
#ifdef ENABLE_VOSF
// We have to redraw everything because the interpretation of pixel values changed
LOCK_VOSF;
PFLAG_SET_ALL;
UNLOCK_VOSF;
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
if (use_vosf) {
// We have to redraw everything because the interpretation of pixel values changed
LOCK_VOSF;
PFLAG_SET_ALL;
UNLOCK_VOSF;
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y);
}
#endif
}

View File

@ -185,6 +185,37 @@ static uint32 page_extend(uint32 size)
}
/*
* Check if VOSF acceleration is profitable on this platform
*/
const int VOSF_PROFITABLE_THRESHOLD = 8000; // 8 ms, aka (60 Hz / 2) for work processing
static bool video_vosf_profitable(void)
{
uint64 start = GetTicks_usec();
for (int i = 0; i < mainBuffer.pageCount; i++) {
uint8 *addr = (uint8 *)(mainBuffer.memStart + (i * mainBuffer.pageSize));
memset(addr, 0, mainBuffer.pageSize); // Trigger Screen_fault_handler()
}
uint64 end = GetTicks_usec();
const int diff = end - start;
D(bug("Triggered %d screen faults in %ld usec\n", mainBuffer.pageCount, diff));
if (diff > (VOSF_PROFITABLE_THRESHOLD * (frame_skip + 1)))
return false;
// Reset VOSF variables to initial state
PFLAG_CLEAR_ALL;
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0)
return false;
mainBuffer.dirty = false;
return true;
}
/*
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler)
*/