diff --git a/gfx/common/ctr_common.h b/gfx/common/ctr_common.h index 4726d1c96f..b18fd8a4aa 100644 --- a/gfx/common/ctr_common.h +++ b/gfx/common/ctr_common.h @@ -87,6 +87,9 @@ typedef struct ctr_video ctr_video_mode_enum video_mode; int current_buffer_top; + bool p3d_event_pending; + bool ppf_event_pending; + struct { ctr_vertex_t* buffer; diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index f554504e3e..5b1747e123 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -239,6 +239,7 @@ static void ctr_lcd_aptHook(APT_HookType hook, void* param) GPUCMD_Finalize(); ctrGuFlushAndRun(true); gspWaitForEvent(GSPGPU_EVENT_P3D, false); + ctr->p3d_event_pending = false; } if((hook == APTHOOK_ONSUSPEND) && (ctr->video_mode == CTR_VIDEO_MODE_400x240)) @@ -386,10 +387,7 @@ static void* ctr_init(const video_info_t* video, sizeof(ctr_vertex_t)); GPUCMD_Finalize(); ctrGuFlushAndRun(true); - - ctrGuDisplayTransfer(true, ctr->drawbuffers.top.left, 240, 400, CTRGU_RGBA8, - gfxTopLeftFramebuffers[ctr->current_buffer_top], - 240,CTRGU_RGB8, CTRGU_MULTISAMPLE_NONE); + gspWaitForEvent(GSPGPU_EVENT_P3D, false); if (input && input_data) { @@ -422,8 +420,8 @@ static void* ctr_init(const video_info_t* video, } ctr->msg_rendering_enabled = false; - -// DEBUG_HOLD(); + ctr->p3d_event_pending = false; + ctr->ppf_event_pending = false; return ctr; } @@ -488,9 +486,17 @@ static bool ctr_frame(void* data, const void* frame, ctr->lcd_buttom_on = !ctr->lcd_buttom_on; } - gspWaitForEvent(GSPGPU_EVENT_P3D, false); - gspWaitForEvent(GSPGPU_EVENT_PPF, false); + if (ctr->p3d_event_pending) + { + gspWaitForEvent(GSPGPU_EVENT_P3D, false); + ctr->p3d_event_pending = false; + } + if (ctr->ppf_event_pending) + { + gspWaitForEvent(GSPGPU_EVENT_PPF, false); + ctr->ppf_event_pending = false; + } frames++; if (ctr->vsync) @@ -505,7 +511,6 @@ static bool ctr_frame(void* data, const void* frame, frames = 0; } - //#define CTR_INSPECT_MEMORY_USAGE #ifdef CTR_INSPECT_MEMORY_USAGE @@ -780,7 +785,8 @@ static bool ctr_frame(void* data, const void* frame, framebufferInfoHeader[0x1]=1; ctr->current_buffer_top ^= 1; - + ctr->p3d_event_pending = true; + ctr->ppf_event_pending = true; performance_counter_stop(&ctrframe_f); return true; @@ -840,7 +846,6 @@ static void ctr_free(void* data) linearFree(ctr->empty_framebuffer); linearFree(ctr->vertex_cache.buffer); linearFree(ctr); -// DEBUG_HOLD(); // gfxExit(); } @@ -957,6 +962,7 @@ static void ctr_viewport_info(void* data, struct video_viewport* vp) static uintptr_t ctr_load_texture(void *video_data, void *data, bool threaded, enum texture_filter_type filter_type) { + ctr_video_t* ctr = (ctr_video_t*)video_data; struct texture_image *image = (struct texture_image*)data; ctr_texture_t* texture = calloc(1, sizeof(ctr_texture_t)); @@ -998,8 +1004,12 @@ static uintptr_t ctr_load_texture(void *video_data, void *data, // printf("ctrGuCopyImage 0x%08X, %i, %i, 0x%08X, %i\n", tmpdata, image->width, image->height, texture->data, texture->width); ctrGuCopyImage(true, tmpdata, image->width, image->height, CTRGU_RGBA8, false, texture->data, texture->width, CTRGU_RGBA8, true); - - // gspWaitForEvent(GSPGPU_EVENT_PPF, false); +#if 0 + gspWaitForEvent(GSPGPU_EVENT_PPF, false); + ctr->ppf_event_pending = false; +#else + ctr->ppf_event_pending = true; +#endif linearFree(tmpdata); } diff --git a/gfx/drivers_font/ctr_font.c b/gfx/drivers_font/ctr_font.c index b5aad4f394..448a13dfd7 100644 --- a/gfx/drivers_font/ctr_font.c +++ b/gfx/drivers_font/ctr_font.c @@ -30,6 +30,11 @@ #include "../../configuration.h" #include "../../verbosity.h" +/* FIXME: this is just a workaround to avoid + * using ctrGuCopyImage, since it seems to cause + * a freeze/blackscreen when used here. */ +//#define FONT_TEXTURE_IN_VRAM + typedef struct { ctr_texture_t texture; @@ -38,10 +43,11 @@ typedef struct void* font_data; } ctr_font_t; -static void* ctr_font_init_font(void* gl_data, const char* font_path, float font_size) +static void* ctr_font_init_font(void* data, const char* font_path, float font_size) { const struct font_atlas* atlas = NULL; ctr_font_t* font = (ctr_font_t*)calloc(1, sizeof(*font)); + ctr_video_t* ctr = (ctr_video_t*)data; if (!font) return NULL; @@ -59,9 +65,14 @@ static void* ctr_font_init_font(void* gl_data, const char* font_path, float font font->texture.width = next_pow2(atlas->width); font->texture.height = next_pow2(atlas->height); +#if FONT_TEXTURE_IN_VRAM font->texture.data = vramAlloc(font->texture.width * font->texture.height); - uint8_t* tmp = linearAlloc(font->texture.width * font->texture.height); +#else + font->texture.data = linearAlloc(font->texture.width * font->texture.height); + uint8_t* tmp = font->texture.data; +#endif + int i, j; const uint8_t* src = atlas->buffer; @@ -75,10 +86,13 @@ static void* ctr_font_init_font(void* gl_data, const char* font_path, float font } GSPGPU_FlushDataCache(tmp, font->texture.width * font->texture.height); + +#if FONT_TEXTURE_IN_VRAM ctrGuCopyImage(true, tmp, font->texture.width >> 2, font->texture.height, CTRGU_RGBA8, true, font->texture.data, font->texture.width >> 2, CTRGU_RGBA8, true); linearFree(tmp); +#endif ctr_set_scale_vector(&font->scale_vector, 400, 240, font->texture.width, font->texture.height); @@ -95,7 +109,11 @@ static void ctr_font_free_font(void* data) if (font->font_driver && font->font_data) font->font_driver->free(font->font_data); +#ifdef FONT_TEXTURE_IN_VRAM vramFree(font->texture.data); +#else + linearFree(font->texture.data); +#endif free(font); }