From 885f9bbcc3eeea3a8822d16cba261d806b0680f7 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 15 Jan 2021 22:29:53 +0100 Subject: [PATCH 1/4] Implement Alpha for the PS2_GFX driver --- Makefile.ps2 | 4 +- gfx/drivers/ps2_gfx.c | 128 ++++++++++++++++++++++-------------- gfx/drivers_font/ps2_font.c | 6 +- 3 files changed, 84 insertions(+), 54 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index e531044ced..8ce6586d8c 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -27,10 +27,10 @@ INCDIR += -Ips2/include -Ilibretro-common/include -Ideps -Ideps/stb -Ideps/7zip CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant ASFLAGS = $(CFLAGS) -RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS -DHAVE_RGUI +RARCH_DEFINES += -DPS2 -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DHAVE_SCREENSHOTS -DHAVE_REWIND -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_CHEATS RARCH_DEFINES += -DHAVE_ZLIB -DHAVE_NO_BUILTINZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -D_7ZIP_ST -DHAVE_CC_RESAMPLER -DHAVE_AUDIOMIXER +RARCH_DEFINES += -DHAVE_VIDEO_FILTER -DHAVE_RGUI RARCH_DEFINES += -DHAVE_DSP_FILTER -RARCH_DEFINES += -DHAVE_VIDEO_FILTER LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L. # Lib cdvd is needed to get proper time diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 68e5050897..9ff2cb5f44 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -23,10 +23,10 @@ #include "../../libretro-common/include/libretro_gskit_ps2.h" -/* turn white GS Screen */ -#define GS_TEXT GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) -/* turn white GS Screen */ -#define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) +/* Generic tint color */ +#define GS_TEXT GS_SETREG_RGBA(0x80,0x80,0x80,0x80) +/* turn black GS Screen */ +#define GS_BLACK GS_SETREG_RGBA(0x00,0x00,0x00,0x80) #define NTSC_WIDTH 640 #define NTSC_HEIGHT 448 @@ -67,6 +67,32 @@ static int vsync_handler() return 0; } +// Copy of gsKit_sync_flip, but without the 'flip' +static void gsKit_sync(GSGLOBAL *gsGlobal) +{ + if(!gsGlobal->FirstFrame) + WaitSema(vsync_sema_id); + + while (PollSema(vsync_sema_id) >= 0); +} + +static void gsKit_flip(GSGLOBAL *gsGlobal) +{ + if(!gsGlobal->FirstFrame) + { + if(gsGlobal->DoubleBuffering == GS_SETTING_ON) + { + GS_SET_DISPFB2( gsGlobal->ScreenBuffer[gsGlobal->ActiveBuffer & 1] / 8192, + gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 ); + + gsGlobal->ActiveBuffer ^= 1; + } + + } + + gsKit_setactive(gsGlobal); +} + static GSGLOBAL *init_GSGlobal(void) { ee_sema_t sema; @@ -75,6 +101,12 @@ static GSGLOBAL *init_GSGlobal(void) sema.option = 0; vsync_sema_id = CreateSema(&sema); + dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, + D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); + + /* Initialize the DMAC */ + dmaKit_chan_init(DMA_CHANNEL_GIF); + GSGLOBAL *gsGlobal = gsKit_init_global(); gsGlobal->Mode = GS_MODE_NTSC; @@ -82,22 +114,24 @@ static GSGLOBAL *init_GSGlobal(void) gsGlobal->Field = GS_FIELD; gsGlobal->Width = NTSC_WIDTH; gsGlobal->Height = NTSC_HEIGHT; - - gsGlobal->PSM = GS_PSM_CT16; - gsGlobal->PSMZ = GS_PSMZ_16; - gsGlobal->DoubleBuffering = GS_SETTING_OFF; + gsGlobal->PSM = GS_PSM_CT32; + gsGlobal->PSMZ = GS_PSMZ_16S; + gsGlobal->DoubleBuffering = GS_SETTING_ON; gsGlobal->ZBuffering = GS_SETTING_OFF; - gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; + gsGlobal->Dithering = GS_SETTING_ON; - dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, - D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); - - /* Initialize the DMAC */ - dmaKit_chan_init(DMA_CHANNEL_GIF); + gsGlobal->Test->ATST = 7; // NOTEQUAL to AREF passes + gsGlobal->Test->AREF = 0x00; + gsGlobal->Test->AFAIL = 0; // KEEP gsKit_init_screen(gsGlobal); gsKit_mode_switch(gsGlobal, GS_ONESHOT); + + gsKit_set_test(gsGlobal, GS_ZTEST_OFF); + gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0); + gsKit_clear(gsGlobal, GS_BLACK); + gsKit_flip(gsGlobal); return gsGlobal; } @@ -109,37 +143,9 @@ static void deinit_GSGlobal(GSGLOBAL *gsGlobal) gsKit_deinit_global(gsGlobal); } -/* Copy of gsKit_sync_flip, but without the 'flip' */ -static void gsKit_sync(GSGLOBAL *gsGlobal) -{ - if (!gsGlobal->FirstFrame) - WaitSema(vsync_sema_id); - - while (PollSema(vsync_sema_id) >= 0); -} - -/* Copy of gsKit_sync_flip, but without the 'sync' */ -static void gsKit_flip(GSGLOBAL *gsGlobal) -{ - if (!gsGlobal->FirstFrame) - { - if (gsGlobal->DoubleBuffering == GS_SETTING_ON) - { - GS_SET_DISPFB2( gsGlobal->ScreenBuffer[ - gsGlobal->ActiveBuffer & 1] / 8192, - gsGlobal->Width / 64, gsGlobal->PSM, 0, 0 ); - - gsGlobal->ActiveBuffer ^= 1; - } - - } - - gsKit_setactive(gsGlobal); -} - static GSTEXTURE *prepare_new_texture(void) { - GSTEXTURE *texture = (GSTEXTURE*)calloc(1, sizeof(*texture)); + GSTEXTURE *texture = (GSTEXTURE*)calloc(1, sizeof(GSTEXTURE)); return texture; } @@ -223,13 +229,18 @@ static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, static void refreshScreen(ps2_video_t *ps2) { - if (ps2->vsync) - { - gsKit_sync(ps2->gsGlobal); - gsKit_flip(ps2->gsGlobal); - } + // Draw everything + gsKit_set_finish(ps2->gsGlobal); gsKit_queue_exec(ps2->gsGlobal); + gsKit_finish(); + + // Let texture manager know we're moving to the next frame gsKit_TexManager_nextFrame(ps2->gsGlobal); + + // Sync and flip + if (ps2->vsync) + gsKit_sync(ps2->gsGlobal); + gsKit_flip(ps2->gsGlobal); } static void *ps2_gfx_init(const video_info_t *video, @@ -286,6 +297,8 @@ static bool ps2_gfx_frame(void *data, const void *frame, printf("ps2_gfx_frame %llu\n", frame_count); #endif + gsKit_clear(ps2->gsGlobal, GS_BLACK); + if (frame) { struct retro_hw_ps2_insets padding = empty_ps2_insets; @@ -304,6 +317,10 @@ static bool ps2_gfx_frame(void *data, const void *frame, padding = ps2->iface.padding; } + /* Disable Alpha for cores */ + ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; + gsKit_set_test(ps2->gsGlobal, GS_ATEST_OFF); + gsKit_TexManager_invalidate(ps2->gsGlobal, ps2->coreTexture); gsKit_TexManager_bind(ps2->gsGlobal, ps2->coreTexture); prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect, padding); @@ -320,8 +337,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, else if (statistics_show) { if (osd_params) - font_driver_render_msg(ps2, video_info->stat_text, - osd_params, NULL); + font_driver_render_msg(ps2, video_info->stat_text, osd_params, NULL); } if (!string_is_empty(msg)) @@ -405,6 +421,16 @@ static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen) ps2->fullscreen = fullscreen; } +static void ps2_set_osd_msg(void *data, + const char *msg, + const void *params, void *font) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + font_driver_render_msg(data, msg, params, font); +} + static bool ps2_get_hw_render_interface(void* data, const struct retro_hw_render_interface** iface) { @@ -431,7 +457,7 @@ static const video_poke_interface_t ps2_poke_interface = { NULL, /* apply_state_changes */ ps2_set_texture_frame, ps2_set_texture_enable, - font_driver_render_msg, /* set_osd_msg */ + ps2_set_osd_msg, /* set_osd_msg */ NULL, /* show_mouse */ NULL, /* grab_mouse_toggle */ NULL, /* get_current_shader */ diff --git a/gfx/drivers_font/ps2_font.c b/gfx/drivers_font/ps2_font.c index e79d6ecab8..a754fce247 100644 --- a/gfx/drivers_font/ps2_font.c +++ b/gfx/drivers_font/ps2_font.c @@ -146,6 +146,10 @@ static void ps2_font_render_line( if (!ps2) return; + + /* Enable Alpha for font */ + ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_ON; + gsKit_set_test(ps2->gsGlobal, GS_ATEST_ON); switch (text_align) { @@ -159,7 +163,7 @@ static void ps2_font_render_line( } /* We need to >> 1, because GS_SETREG_RGBAQ expect 0x80 as max color */ - colorA = (int)(((color & 0xFF000000) >> 24) >> 1); + colorA = (int)(((color & 0xFF000000) >> 24) >> 2); colorB = (int)(((color & 0x00FF0000) >> 16) >> 1); colorG = (int)(((color & 0x0000FF00) >> 8) >> 1); colorR = (int)(((color & 0x000000FF) >> 0) >> 1); From 97db0291d2033e6f414ad7ed0280ecf80ae6691d Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Sat, 7 Aug 2021 15:42:12 +1000 Subject: [PATCH 2/4] (WiiU) Add ICInvalidateRange --- wiiu/system/imports.h | 1 + 1 file changed, 1 insertion(+) diff --git a/wiiu/system/imports.h b/wiiu/system/imports.h index bfff0e860c..7694261110 100644 --- a/wiiu/system/imports.h +++ b/wiiu/system/imports.h @@ -65,6 +65,7 @@ IMPORT(DCInvalidateRange); IMPORT(DCFlushRange); IMPORT(DCStoreRange); IMPORT(DCStoreRangeNoSync); +IMPORT(ICInvalidateRange); IMPORT(__gh_errno_ptr); From c19c6a3ca8e1ddb2c130e370b5e9416e2562e666 Mon Sep 17 00:00:00 2001 From: Autechre Date: Sat, 7 Aug 2021 16:20:07 +0200 Subject: [PATCH 3/4] Update CHANGES.md --- CHANGES.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a36832dbe1..aca9e18ea4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,23 @@ # Future - -# 1.9.8 +- CHEEVOS: Hide challenge indicators when resetting +- CONTENT INFORMATION: Show content info label+path rows always - DUMMY CORE: Skip state_manager_event_{deinit/init} when core type is dummy, should skip warning spam 'Implementation uses threaded audio. Cannot use rewind..' when using rewind +- INPUT/UDEV: Limit udev device scan to subsystem 'input' - LIBNX/SWITCH: Fix poll missing for controller 2-8 - LIBNX/SWITCH: Fix layout not applied correctly and hangs when splitting joycons +- DATABASE/EXPLORE: Fix CRC32 reading in explore menu +- DATABASE/LIBRETRODB: Fix writing of numerical values +- DATABASE/LIBRETRODB: Fix libretro-db loading on big endian platforms +- MOUSE: Change default mouse index to port index +- MOUSE: Friendly names for mice where available +- OSX: Fix some memory leaks +- PS2: Implement alpha for the video driver - WINRAW: Trigger joypad driver reinit on DEVICECHANGE - avoids fullscreen toggle +- WINRAW: Alt sticky fix +- WINRAW: Prevent Alt getting stuck when Alt-Tabbing +- WINRAW: Add pointer status - WIIU: Compress RPX libretro cores +- WIIU: Add ICInvalidateRange (necessary for JITs) # 1.9.7 - 3DS: Add unique ID's From b513a3d166892035c4a6614e32f8592a9771bb3e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 7 Aug 2021 18:24:46 +0200 Subject: [PATCH 4/4] (OSX) Prevent crash on startup on OSX Platforms with no ARC enabled - CFSearchPathForDirectoriesInDomains - CFTypeRef returned by NSSearchPathForDIrectoriesInDomains should not be freed --- frontend/drivers/platform_darwin.m | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index e0cd1368fd..625bfc3526 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -153,20 +153,25 @@ static void CFSearchPathForDirectoriesInDomains(unsigned flags, CFTypeRef array_val = (CFTypeRef)CFBridgingRetainCompat( NSSearchPathForDirectoriesInDomains(NSConvertFlagsCF(flags), NSConvertDomainFlagsCF(domain_mask), (BOOL)expand_tilde)); - CFArrayRef array = array_val ? CFRetain(array_val) : NULL; - CFTypeRef path_val = (CFTypeRef)CFArrayGetValueAtIndex(array, 0); - CFStringRef path = path_val ? CFRetain(path_val) : NULL; - CFRelease(array_val); - if (!path || !array) - { - if (path) - CFRelease(path); - return; - } - CFStringGetCString(path, s, len, kCFStringEncodingUTF8); - CFRelease(path); - CFRelease(array); + if (array_val) + { + CFArrayRef array = CFRetain(array_val); + CFTypeRef path_val = (CFTypeRef)CFArrayGetValueAtIndex(array, 0); + + if (path_val) + { + CFStringRef path = CFRetain(path_val); + if (path) + { + CFStringGetCString(path, s, len, kCFStringEncodingUTF8); + CFRelease(path); + } + } + + if (array) + CFRelease(array); + } } static void CFTemporaryDirectory(char *s, size_t len)