From 8b59e45e6e8ffdd733abaa53d6ee4eea7ee6bc5d Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 17 May 2010 07:22:26 +0000 Subject: PSP: added option for render by callback and fixed up and cleaned up debug mechanism. This allows for about 4% speedup since we no longer need to wait for VSYNC in our main thread. I'll activate it as soon as I've tested it out properly. svn-id: r49055 --- backends/platform/psp/cursor.cpp | 1 + backends/platform/psp/default_display_client.cpp | 1 + backends/platform/psp/display_client.cpp | 2 + backends/platform/psp/display_client.h | 1 - backends/platform/psp/display_manager.cpp | 63 +++++++++++++- backends/platform/psp/display_manager.h | 5 ++ backends/platform/psp/input.cpp | 1 + backends/platform/psp/osys_psp.cpp | 1 + backends/platform/psp/psp_main.cpp | 5 +- backends/platform/psp/pspkeyboard.cpp | 14 +-- backends/platform/psp/pspkeyboard.h | 2 +- backends/platform/psp/trace.cpp | 6 +- backends/platform/psp/trace.h | 103 +++++++++++------------ 13 files changed, 134 insertions(+), 71 deletions(-) (limited to 'backends') diff --git a/backends/platform/psp/cursor.cpp b/backends/platform/psp/cursor.cpp index abd9166f7a..ae3b8f0050 100644 --- a/backends/platform/psp/cursor.cpp +++ b/backends/platform/psp/cursor.cpp @@ -24,6 +24,7 @@ */ #include "common/scummsys.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/display_client.h" #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" diff --git a/backends/platform/psp/default_display_client.cpp b/backends/platform/psp/default_display_client.cpp index b6ce08ca49..4aa4f88c51 100644 --- a/backends/platform/psp/default_display_client.cpp +++ b/backends/platform/psp/default_display_client.cpp @@ -24,6 +24,7 @@ */ #include "common/scummsys.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/display_client.h" #include "backends/platform/psp/default_display_client.h" diff --git a/backends/platform/psp/display_client.cpp b/backends/platform/psp/display_client.cpp index ab4e649708..90c41e796d 100644 --- a/backends/platform/psp/display_client.cpp +++ b/backends/platform/psp/display_client.cpp @@ -24,10 +24,12 @@ */ #include +#include #include #include #include "common/scummsys.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/display_client.h" #include "backends/platform/psp/display_manager.h" #include "backends/platform/psp/memory.h" diff --git a/backends/platform/psp/display_client.h b/backends/platform/psp/display_client.h index 8d0f827415..d05b0b046c 100644 --- a/backends/platform/psp/display_client.h +++ b/backends/platform/psp/display_client.h @@ -29,7 +29,6 @@ #include "common/singleton.h" #include "graphics/surface.h" #include "common/system.h" -#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/memory.h" #define MAX_TEXTURE_SIZE 512 diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp index c11604c273..8d2ec597af 100644 --- a/backends/platform/psp/display_manager.cpp +++ b/backends/platform/psp/display_manager.cpp @@ -25,13 +25,17 @@ #include #include +#include #include "common/scummsys.h" #include "backends/base-backend.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/display_client.h" #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" #include "backends/platform/psp/pspkeyboard.h" + +//#define USE_DISPLAY_CALLBACK // to use callback for finishing the render #include "backends/platform/psp/display_manager.h" #define PSP_BUFFER_WIDTH (512) @@ -56,9 +60,45 @@ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = { {0, 0, 0} }; +bool MasterGuRenderer::_renderFinished = true; // synchronizes the callback thread // Class MasterGuRenderer ---------------------------------------------- +void MasterGuRenderer::setupCallbackThread() { + DEBUG_ENTER_FUNC(); + int thid = sceKernelCreateThread("displayCbThread", guCallbackThread, 0x11, 4*1024, THREAD_ATTR_USER, 0); + + PSP_DEBUG_PRINT("Display CB thread id is %x\n", thid); + + if (thid >= 0) { + sceKernelStartThread(thid, 0, 0); + } else + PSP_ERROR("failed to create display callback thread\n"); +} + +// thread that reacts to the callback +int MasterGuRenderer::guCallbackThread(SceSize, void *) { + DEBUG_ENTER_FUNC(); + + if (sceGuSetCallback(GU_CALLBACK_FINISH, guDisplayCallback) != 0) { + PSP_ERROR("Warning: previous display callback found.\n"); + } + PSP_DEBUG_PRINT("set callback. Going to sleep\n"); + + sceKernelSleepThreadCB(); // sleep until we get a callback + return 0; +} + +// This callback is called when the render is finished. It swaps the buffers +void MasterGuRenderer::guDisplayCallback(int) { + if (_renderFinished == true) + PSP_ERROR("callback thread found wrong value[true] in _renderFinished\n"); + + sceDisplayWaitVblankStart(); // wait for v-blank without eating main thread cycles + sceGuSwapBuffers(); + _renderFinished = true; // Only this thread can set the variable to true +} + void MasterGuRenderer::guInit() { DEBUG_ENTER_FUNC(); @@ -110,6 +150,8 @@ void MasterGuRenderer::guProgramDisplayBufferSizes() { inline void MasterGuRenderer::guPreRender() { DEBUG_ENTER_FUNC(); + _renderFinished = false; // set to synchronize with callback thread + #ifdef ENABLE_RENDER_MEASURE _lastRenderTime = g_system->getMillis(); #endif /* ENABLE_RENDER_MEASURE */ @@ -132,7 +174,8 @@ inline void MasterGuRenderer::guPostRender() { DEBUG_ENTER_FUNC(); sceGuFinish(); - sceGuSync(0, 0); +#ifndef USE_DISPLAY_CALLBACK + sceGuSync(0, 0); #ifdef ENABLE_RENDER_MEASURE uint32 now = g_system->getMillis(); @@ -141,6 +184,8 @@ inline void MasterGuRenderer::guPostRender() { sceDisplayWaitVblankStart(); sceGuSwapBuffers(); + _renderFinished = true; +#endif /* !USE_DISPLAY_CALLBACK */ } void MasterGuRenderer::guShutDown() { @@ -164,11 +209,15 @@ void DisplayManager::init() { _overlay->init(); _cursor->init(); + _masterGuRenderer.guInit(); // start up the renderer +#ifdef USE_DISPLAY_CALLBACK + _masterGuRenderer.setupCallbackThread(); +#endif + } void DisplayManager::setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format) { - DEBUG_ENTER_FUNC(); PSP_DEBUG_PRINT("w[%u], h[%u], pformat[%p]\n", width, height, format); @@ -248,9 +297,15 @@ void DisplayManager::calculateScaleParams() { void DisplayManager::renderAll() { DEBUG_ENTER_FUNC(); - if (!isTimeToUpdate()) { +#ifdef USE_DISPLAY_CALLBACK + if (!_masterGuRenderer.isRenderFinished()) { + PSP_DEBUG_PRINT("Callback render not finished.\n"); + return; + } +#endif /* USE_DISPLAY_CALLBACK */ + + if (!isTimeToUpdate()) return; - } if (!_screen->isDirty() && (!_overlay->isDirty()) && diff --git a/backends/platform/psp/display_manager.h b/backends/platform/psp/display_manager.h index 54b4b78938..6b81c69b72 100644 --- a/backends/platform/psp/display_manager.h +++ b/backends/platform/psp/display_manager.h @@ -36,10 +36,15 @@ public: void guPreRender(); void guPostRender(); void guShutDown(); + bool isRenderFinished() { return _renderFinished; } + void setupCallbackThread(); private: static uint32 _displayList[]; uint32 _lastRenderTime; // For measuring rendering void guProgramDisplayBufferSizes(); + static bool _renderFinished; + static int guCallbackThread(SceSize, void *); + static void guDisplayCallback(int); }; class Screen; diff --git a/backends/platform/psp/input.cpp b/backends/platform/psp/input.cpp index 6e747a430f..4fe7cb3f92 100644 --- a/backends/platform/psp/input.cpp +++ b/backends/platform/psp/input.cpp @@ -31,6 +31,7 @@ #include "backends/platform/psp/trace.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/input.h" // Defines for working with PSP buttons diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index db1f9fb716..58d98bc219 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -34,6 +34,7 @@ #include "common/events.h" #include "common/scummsys.h" +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/osys_psp.h" #include "backends/platform/psp/powerman.h" diff --git a/backends/platform/psp/psp_main.cpp b/backends/platform/psp/psp_main.cpp index 5a14abf4f7..e568184990 100644 --- a/backends/platform/psp/psp_main.cpp +++ b/backends/platform/psp/psp_main.cpp @@ -41,8 +41,9 @@ #include "backends/platform/psp/powerman.h" #include "backends/plugins/psp/psp-provider.h" -#include "osys_psp.h" -#include "./trace.h" +#include "backends/platform/psp/psppixelformat.h" +#include "backends/platform/psp/osys_psp.h" +#include "backends/platform/psp/trace.h" #ifdef ENABLE_PROFILING #include diff --git a/backends/platform/psp/pspkeyboard.cpp b/backends/platform/psp/pspkeyboard.cpp index 5cd46789a8..eb081fc5f4 100644 --- a/backends/platform/psp/pspkeyboard.cpp +++ b/backends/platform/psp/pspkeyboard.cpp @@ -29,18 +29,22 @@ #define PSP_KB_SHELL_PATH "ms0:/psp/game4xx/scummvm-solid/" /* path to kbd.zip */ #endif -//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */ -//#define __PSP_DEBUG_PRINT__ -#include "backends/platform/psp/trace.h" #include -#include "pspkernel.h" -#include "png.h" +#include +#include + +#include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/pspkeyboard.h" #include "common/keyboard.h" #include "common/fs.h" #include "common/unzip.h" +//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */ +//#define __PSP_DEBUG_PRINT__ + +#include "backends/platform/psp/trace.h" + #define PSP_SCREEN_WIDTH 480 #define PSP_SCREEN_HEIGHT 272 #define K(x) ((short)(Common::KEYCODE_INVALID + (x))) diff --git a/backends/platform/psp/pspkeyboard.h b/backends/platform/psp/pspkeyboard.h index 072bec6c27..a30e7d0f32 100644 --- a/backends/platform/psp/pspkeyboard.h +++ b/backends/platform/psp/pspkeyboard.h @@ -76,7 +76,7 @@ private: GuRenderer _renderer; int loadPngImage(Common::SeekableReadStream *file, Buffer &buffer, Palette &palette); - int getPngImageSize(Common::SeekableReadStream *, uint32 *png_width, uint32 *png_height, u32 *paletteSize); + int getPngImageSize(Common::SeekableReadStream *, uint32 *png_width, uint32 *png_height, uint32 *paletteSize); uint32 convert_pow2(uint32 size); void increaseKeyboardLocationX(int amount); // Move keyboard onscreen void increaseKeyboardLocationY(int amount); diff --git a/backends/platform/psp/trace.cpp b/backends/platform/psp/trace.cpp index 872e1aabf4..4bf5450177 100644 --- a/backends/platform/psp/trace.cpp +++ b/backends/platform/psp/trace.cpp @@ -23,11 +23,11 @@ * */ -#define TRACE_C + #include #include -#include "backends/platform/psp/trace.h" - +#include +#include int psp_debug_indent = 0; diff --git a/backends/platform/psp/trace.h b/backends/platform/psp/trace.h index 5bb861e32d..1aad0f6781 100644 --- a/backends/platform/psp/trace.h +++ b/backends/platform/psp/trace.h @@ -24,47 +24,19 @@ */ -#ifndef TRACE_H -#define TRACE_H +// This section can only be included once +#ifndef PSP_TRACE_H +#define PSP_TRACE_H -#include -#include -#include - -// Use these defines for debugging - -//#define __PSP_PRINT_TO_FILE__ -//#define __PSP_PRINT_TO_FILE_AND_SCREEN__ -//#define __PSP_DEBUG_FUNCS__ /* can put this locally too */ -//#define __PSP_DEBUG_PRINT__ - -void PSPDebugTrace(bool alsoToScreen, const char *format, ...); - -#ifndef TRACE_C -extern int psp_debug_indent; -#endif - -// From here on, we allow multiple definitions -#undef __PSP_PRINT__ -#undef PSP_ERROR -#undef __PSP_INDENT__ -#undef PSP_INFO_PRINT -#undef PSP_INFO_PRINT_INDENT -#undef PSP_DEBUG_PRINT -#undef PSP_DEBUG_PRINT_FUNC -#undef PSP_DEBUG_PRINT_SAMELN -#undef PSP_DEBUG_DO -#undef DEBUG_ENTER_FUNC -#undef DEBUG_EXIT_FUNC -#undef INLINE +#include "common/str.h" /* Choose to print to file/screen/both */ #ifdef __PSP_PRINT_TO_FILE__ -#define __PSP_PRINT__(format,...) PSPDebugTrace(false, format, ## __VA_ARGS__) + #define __PSP_PRINT__(format,...) PSPDebugTrace(false, format, ## __VA_ARGS__) #elif defined __PSP_PRINT_TO_FILE_AND_SCREEN__ -#define __PSP_PRINT__(format,...) PSPDebugTrace(true, format, ## __VA_ARGS__) + #define __PSP_PRINT__(format,...) PSPDebugTrace(true, format, ## __VA_ARGS__) #else /* default - print to screen */ -#define __PSP_PRINT__(format,...) fprintf(stderr, format, ## __VA_ARGS__) + #define __PSP_PRINT__(format,...) fprintf(stderr, format, ## __VA_ARGS__) #endif /* PSP_PRINT_TO_FILE/SCREEN */ /* Error function */ @@ -80,28 +52,13 @@ extern int psp_debug_indent; #define PSP_INFO_PRINT_INDENT(format,...) { __PSP_INDENT__; \ __PSP_PRINT__(format, ## __VA_ARGS__); } -#ifdef __PSP_DEBUG_PRINT__ -/* printf with indents */ -#define PSP_DEBUG_PRINT_SAMELN(format,...) __PSP_PRINT__(format, ## __VA_ARGS__) -#define PSP_DEBUG_PRINT(format,...) { __PSP_INDENT__; \ - __PSP_PRINT__(format, ## __VA_ARGS__); } -#define PSP_DEBUG_PRINT_FUNC(format,...) { __PSP_INDENT__; \ - __PSP_PRINT__("In %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); } -#define PSP_DEBUG_DO(x) (x) - -#else /* no debug print */ -#define PSP_DEBUG_PRINT_SAMELN(format,...) -#define PSP_DEBUG_PRINT(format,...) -#define PSP_DEBUG_PRINT_FUNC(format,...) -#define PSP_DEBUG_DO(x) -#endif /* __PSP_DEBUG_PRINT__ */ +void PSPDebugTrace(bool alsoToScreen, const char *format, ...); -/* Debugging function calls */ -#ifdef __PSP_DEBUG_FUNCS__ +extern int psp_debug_indent; // We use this class to print out function calls on the stack in an easy way. // -#include "common/str.h" + class PSPStackDebugFuncs { Common::String _name; @@ -119,7 +76,45 @@ public: } }; +#endif /* PSP_TRACE_H */ + + + + +// From here on, we allow multiple redefinitions + +// Use these defines for debugging + +//#define __PSP_PRINT_TO_FILE__ +//#define __PSP_PRINT_TO_FILE_AND_SCREEN__ +//#define __PSP_DEBUG_FUNCS__ /* can put this locally too */ +//#define __PSP_DEBUG_PRINT__ + +#undef PSP_DEBUG_PRINT +#undef PSP_DEBUG_PRINT_FUNC +#undef PSP_DEBUG_PRINT_SAMELN +#undef PSP_DEBUG_DO +#undef DEBUG_ENTER_FUNC +#undef DEBUG_EXIT_FUNC + +#ifdef __PSP_DEBUG_PRINT__ +/* printf with indents */ +#define PSP_DEBUG_PRINT_SAMELN(format,...) __PSP_PRINT__(format, ## __VA_ARGS__) +#define PSP_DEBUG_PRINT(format,...) PSP_INFO_PRINT_INDENT(format, ## __VA_ARGS__) +#define PSP_DEBUG_PRINT_FUNC(format,...) { __PSP_INDENT__; \ + __PSP_PRINT__("In %s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); } +#define PSP_DEBUG_DO(x) (x) + +#else /* no debug print */ + #define PSP_DEBUG_PRINT_SAMELN(format,...) + #define PSP_DEBUG_PRINT(format,...) + #define PSP_DEBUG_PRINT_FUNC(format,...) + #define PSP_DEBUG_DO(x) +#endif /* __PSP_DEBUG_PRINT__ */ + /* We don't need anything but this line at the beginning of each function to debug function calls */ +/* Debugging function calls */ +#ifdef __PSP_DEBUG_FUNCS__ #define DEBUG_ENTER_FUNC() volatile PSPStackDebugFuncs __foo(__PRETTY_FUNCTION__) #else /* Don't debug function calls */ #define DEBUG_ENTER_FUNC() @@ -130,5 +125,3 @@ public: #undef __PSP_PRINT_TO_FILE_AND_SCREEN__ #undef __PSP_DEBUG_FUNCS__ #undef __PSP_DEBUG_PRINT__ - -#endif /* TRACE_H */ -- cgit v1.2.3