From 22082ea18a3e70623b12447d0bc8aae8a274c345 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 9 Dec 2024 01:10:52 +0200 Subject: [PATCH 1/2] fix build libretro/pcsx_rearmed#855 --- plugins/gpulib/gpulib_thread_if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gpulib/gpulib_thread_if.c b/plugins/gpulib/gpulib_thread_if.c index c625c552..3654134d 100644 --- a/plugins/gpulib/gpulib_thread_if.c +++ b/plugins/gpulib/gpulib_thread_if.c @@ -78,7 +78,7 @@ static void *video_thread_main(void *arg) { #if defined(__arm__) && defined(__ARM_FP) // RunFast mode - u32 fpscr = ~0; + uint32_t fpscr = ~0; __asm__ volatile("vmrs %0, fpscr" : "=r"(fpscr)); fpscr &= ~0x00009f9f; fpscr |= 0x03000000; // DN | FZ From ed8077c5d08bf0c40b24ac774723728a0fca661d Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 9 Dec 2024 02:17:13 +0200 Subject: [PATCH 2/2] gpu: allow to force-enable dithering libretro/pcsx_rearmed#853 --- frontend/libretro.c | 22 +++++++++------------- frontend/libretro_core_options.h | 3 ++- frontend/main.c | 4 +--- frontend/menu.c | 10 ++++------ frontend/plugin_lib.h | 4 +--- plugins/dfxvideo/gpulib_if.c | 2 +- plugins/gpu_neon/psx_gpu/psx_gpu.h | 3 ++- plugins/gpu_neon/psx_gpu/psx_gpu_parse.c | 6 ++++-- plugins/gpu_neon/psx_gpu_if.c | 7 +++++-- plugins/gpu_unai/gpu.h | 1 + plugins/gpu_unai/gpu_unai.h | 6 +----- plugins/gpu_unai/gpulib_if.cpp | 3 ++- 12 files changed, 33 insertions(+), 38 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index 3f665684..07b108c6 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -2186,23 +2186,20 @@ static void update_variables(bool in_flight) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "disabled") == 0) + if (strcmp(var.value, "force") == 0) { - pl_rearmed_cbs.gpu_peops.iUseDither = 0; + pl_rearmed_cbs.dithering = 2; + pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1; + } + else if (strcmp(var.value, "disabled") == 0) + { + pl_rearmed_cbs.dithering = 0; pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0; - pl_rearmed_cbs.gpu_unai.dithering = 0; -#ifdef GPU_NEON - pl_rearmed_cbs.gpu_neon.allow_dithering = 0; -#endif } - else if (strcmp(var.value, "enabled") == 0) + else { - pl_rearmed_cbs.gpu_peops.iUseDither = 1; + pl_rearmed_cbs.dithering = 1; pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1; - pl_rearmed_cbs.gpu_unai.dithering = 1; -#ifdef GPU_NEON - pl_rearmed_cbs.gpu_neon.allow_dithering = 1; -#endif } } @@ -3648,7 +3645,6 @@ void retro_init(void) if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) rumble_cb = rumble.set_rumble_state; - pl_rearmed_cbs.gpu_peops.iUseDither = 1; pl_rearmed_cbs.gpu_peops.dwActFixes = GPU_PEOPS_OLD_FRAME_SKIP; SaveFuncs.open = save_open; diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 220df0f2..a07491b6 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -319,12 +319,13 @@ struct retro_core_option_v2_definition option_defs_us[] = { "pcsx_rearmed_dithering", "Dithering Pattern", NULL, - "Enable emulation of the dithering technique used by the PSX to smooth out color banding artifacts. Increases performance requirements.", + "Enable emulation of the dithering technique used by the PSX to smooth out color banding artifacts. \"Force\" enables it even if the game turns it off. Increases performance requirements.", NULL, "video", { { "disabled", NULL }, { "enabled", NULL }, + { "force", "Force" }, { NULL, NULL }, }, #if defined(_3DS) diff --git a/frontend/main.c b/frontend/main.c index 42a90d47..2dd5ca4c 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -129,19 +129,17 @@ void emu_set_default_config(void) Config.GpuListWalking = -1; Config.FractionalFramerate = -1; + pl_rearmed_cbs.dithering = 1; pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto - pl_rearmed_cbs.gpu_neon.allow_dithering = 1; pl_rearmed_cbs.gpu_neon.enhancement_enable = pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; pl_rearmed_cbs.gpu_neon.enhancement_tex_adj = 1; - pl_rearmed_cbs.gpu_peops.iUseDither = 0; pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7; pl_rearmed_cbs.gpu_unai.old_renderer = 0; pl_rearmed_cbs.gpu_unai.ilace_force = 0; pl_rearmed_cbs.gpu_unai.lighting = 1; pl_rearmed_cbs.gpu_unai.fast_lighting = 0; pl_rearmed_cbs.gpu_unai.blending = 1; - pl_rearmed_cbs.gpu_unai.dithering = 0; memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl)); pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64; pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1; diff --git a/frontend/menu.c b/frontend/menu.c index 438d2cff..773ad606 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -441,14 +441,13 @@ static const struct { CE_INTVAL_N("adev0_is_nublike", in_adev_is_nublike[0]), CE_INTVAL_N("adev1_is_nublike", in_adev_is_nublike[1]), CE_INTVAL_V(frameskip, 4), - CE_INTVAL_P(gpu_peops.iUseDither), + CE_INTVAL_PV(dithering, 2), CE_INTVAL_P(gpu_peops.dwActFixes), CE_INTVAL_P(gpu_unai.old_renderer), CE_INTVAL_P(gpu_unai.ilace_force), CE_INTVAL_P(gpu_unai.lighting), CE_INTVAL_P(gpu_unai.fast_lighting), CE_INTVAL_P(gpu_unai.blending), - CE_INTVAL_P(gpu_unai.dithering), CE_INTVAL_P(gpu_unai.scale_hires), CE_INTVAL_P(gpu_neon.allow_interlace), CE_INTVAL_P(gpu_neon.enhancement_enable), @@ -1427,7 +1426,6 @@ static menu_entry e_menu_plugin_gpu_neon[] = mee_onoff_h ("Enhanced res. speed hack", 0, pl_rearmed_cbs.gpu_neon.enhancement_no_main, 1, h_gpu_neon_enhanced_hack), mee_onoff_h ("Enh. res. texture adjust", 0, pl_rearmed_cbs.gpu_neon.enhancement_tex_adj, 1, h_gpu_neon_enhanced_texadj), mee_enum ("Enable interlace mode", 0, pl_rearmed_cbs.gpu_neon.allow_interlace, men_gpu_interlace), - mee_onoff ("Enable dithering", 0, pl_rearmed_cbs.gpu_neon.allow_dithering, 1), mee_end, }; @@ -1444,7 +1442,6 @@ static menu_entry e_menu_plugin_gpu_unai[] = { mee_onoff ("Old renderer", 0, pl_rearmed_cbs.gpu_unai.old_renderer, 1), mee_onoff ("Interlace", 0, pl_rearmed_cbs.gpu_unai.ilace_force, 1), - mee_onoff ("Dithering", 0, pl_rearmed_cbs.gpu_unai.dithering, 1), mee_onoff ("Lighting", 0, pl_rearmed_cbs.gpu_unai.lighting, 1), mee_onoff ("Fast lighting", 0, pl_rearmed_cbs.gpu_unai.fast_lighting, 1), mee_onoff ("Blending", 0, pl_rearmed_cbs.gpu_unai.blending, 1), @@ -1459,7 +1456,6 @@ static int menu_loop_plugin_gpu_unai(int id, int keys) } -static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL }; //static const char h_gpu_0[] = "Needed for Chrono Cross"; static const char h_gpu_1[] = "Capcom fighting games"; static const char h_gpu_2[] = "Black screens in Lunar"; @@ -1472,7 +1468,6 @@ static const char h_gpu_10[] = "Toggle busy flags after drawing"; static menu_entry e_menu_plugin_gpu_peops[] = { - mee_enum ("Dithering", 0, pl_rearmed_cbs.gpu_peops.iUseDither, men_gpu_dithering), // mee_onoff_h ("Odd/even bit hack", 0, pl_rearmed_cbs.gpu_peops.dwActFixes, 1<<0, h_gpu_0), mee_onoff_h ("Expand screen width", 0, pl_rearmed_cbs.gpu_peops.dwActFixes, 1<<1, h_gpu_1), mee_onoff_h ("Ignore brightness color", 0, pl_rearmed_cbs.gpu_peops.dwActFixes, 1<<2, h_gpu_2), @@ -1551,6 +1546,8 @@ static int menu_loop_plugin_spu(int id, int keys) return 0; } +static const char *men_gpu_dithering[] = { "OFF", "ON", "Force", NULL }; + static const char h_bios[] = "HLE is simulated BIOS. BIOS selection is saved in\n" "savestates and can't be changed there. Must save\n" "config and reload the game for change to take effect"; @@ -1572,6 +1569,7 @@ static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1 static menu_entry e_menu_plugin_options[] = { mee_enum_h ("BIOS", 0, bios_sel, bioses, h_bios), + mee_enum ("GPU Dithering", 0, pl_rearmed_cbs.dithering, men_gpu_dithering), mee_enum_h ("GPU plugin", 0, gpu_plugsel, gpu_plugins, h_plugin_gpu), mee_enum_h ("SPU plugin", 0, spu_plugsel, spu_plugins, h_plugin_spu), #ifdef BUILTIN_GPU_NEON diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index 6fee70b1..420f89f9 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -80,15 +80,14 @@ struct rearmed_cbs { unsigned int flip_cnt; // increment manually if not using pl_vout_flip unsigned int only_16bpp; // platform is 16bpp-only unsigned int thread_rendering; + unsigned int dithering; // 0 off, 1 on, 2 force struct { int allow_interlace; // 0 off, 1 on, 2 guess int enhancement_enable; int enhancement_no_main; - int allow_dithering; int enhancement_tex_adj; } gpu_neon; struct { - int iUseDither; int dwActFixes; float fFrameRateHz; int dwFrameRateTicks; @@ -99,7 +98,6 @@ struct rearmed_cbs { int lighting; int fast_lighting; int blending; - int dithering; int scale_hires; } gpu_unai; struct { diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index 8a3f2f9a..2c0a483f 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -496,7 +496,7 @@ void renderer_notify_update_lace(int updated) void renderer_set_config(const struct rearmed_cbs *cbs) { - iUseDither = cbs->gpu_peops.iUseDither; + iUseDither = cbs->dithering; dwActFixes = cbs->gpu_peops.dwActFixes; if (cbs->pl_set_gpu_caps) cbs->pl_set_gpu_caps(0); diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu.h b/plugins/gpu_neon/psx_gpu/psx_gpu.h index 2d0f7b12..1ea39170 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu.h +++ b/plugins/gpu_neon/psx_gpu/psx_gpu.h @@ -208,6 +208,8 @@ typedef struct u16 enhancement_scanout_eselect; // eviction selector u16 enhancement_current_buf; + u32 allow_dithering:1; + u32 force_dithering:1; u32 hack_disable_main:1; u32 hack_texture_adj:1; @@ -226,7 +228,6 @@ typedef struct u8 texture_4bpp_cache[32][256 * 256]; u8 texture_8bpp_even_cache[16][256 * 256]; u8 texture_8bpp_odd_cache[16][256 * 256]; - int use_dithering; } psx_gpu_struct; typedef struct __attribute__((aligned(16))) diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c index 1fa06a15..03d055d5 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c @@ -661,7 +661,8 @@ u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size, case 0xE1: set_texture(psx_gpu, list[0]); - if(list[0] & (1 << 9)) + if ((psx_gpu->allow_dithering && (list[0] & (1 << 9))) + || psx_gpu->force_dithering) psx_gpu->render_state_base |= RENDER_STATE_DITHER; else psx_gpu->render_state_base &= ~RENDER_STATE_DITHER; @@ -1588,7 +1589,8 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, case 0xE1: set_texture(psx_gpu, list[0]); - if(list[0] & (1 << 9)) + if ((psx_gpu->allow_dithering && (list[0] & (1 << 9))) + || psx_gpu->force_dithering) psx_gpu->render_state_base |= RENDER_STATE_DITHER; else psx_gpu->render_state_base &= ~RENDER_STATE_DITHER; diff --git a/plugins/gpu_neon/psx_gpu_if.c b/plugins/gpu_neon/psx_gpu_if.c index 02104586..5b6a3351 100644 --- a/plugins/gpu_neon/psx_gpu_if.c +++ b/plugins/gpu_neon/psx_gpu_if.c @@ -223,8 +223,10 @@ void renderer_set_config(const struct rearmed_cbs *cbs) if (cbs->pl_set_gpu_caps) cbs->pl_set_gpu_caps(GPU_CAP_SUPPORTS_2X); - egpu.use_dithering = cbs->gpu_neon.allow_dithering; - if(!egpu.use_dithering) { + egpu.allow_dithering = cbs->dithering; + egpu.force_dithering = cbs->dithering >> 1; + /* + if (!egpu.allow_dithering) { egpu.dither_table[0] = dither_table_row(0, 0, 0, 0); egpu.dither_table[1] = dither_table_row(0, 0, 0, 0); egpu.dither_table[2] = dither_table_row(0, 0, 0, 0); @@ -235,6 +237,7 @@ void renderer_set_config(const struct rearmed_cbs *cbs) egpu.dither_table[2] = dither_table_row(-3, 1, -4, 0); egpu.dither_table[3] = dither_table_row(3, -1, 2, -2); } + */ egpu.hack_disable_main = cbs->gpu_neon.enhancement_no_main; egpu.hack_texture_adj = cbs->gpu_neon.enhancement_tex_adj; diff --git a/plugins/gpu_unai/gpu.h b/plugins/gpu_unai/gpu.h index 17f80eb3..009cdfc4 100644 --- a/plugins/gpu_unai/gpu.h +++ b/plugins/gpu_unai/gpu.h @@ -46,6 +46,7 @@ struct gpu_unai_config_t { uint8_t fast_lighting:1; uint8_t blending:1; uint8_t dithering:1; + uint8_t force_dithering:1; uint8_t old_renderer:1; //senquack Only PCSX Rearmed's version of gpu_unai had this, and I diff --git a/plugins/gpu_unai/gpu_unai.h b/plugins/gpu_unai/gpu_unai.h index 6fe00bb9..ce2dac42 100644 --- a/plugins/gpu_unai/gpu_unai.h +++ b/plugins/gpu_unai/gpu_unai.h @@ -360,13 +360,9 @@ static inline bool DitheringEnabled() return gpu_unai.config.dithering; } -// For now, this is just for development/experimentation purposes.. -// If modified to return true, it will allow ignoring the status register -// bit 9 setting (dither enable). It will still restrict dithering only -// to Gouraud-shaded or texture-blended polys. static inline bool ForcedDitheringEnabled() { - return false; + return gpu_unai.config.force_dithering; } static inline bool ProgressiveInterlaceEnabled() diff --git a/plugins/gpu_unai/gpulib_if.cpp b/plugins/gpu_unai/gpulib_if.cpp index 40c7fd95..5fbb7f52 100644 --- a/plugins/gpu_unai/gpulib_if.cpp +++ b/plugins/gpu_unai/gpulib_if.cpp @@ -883,8 +883,9 @@ void renderer_set_config(const struct rearmed_cbs *cbs) gpu_unai.config.lighting = cbs->gpu_unai.lighting; gpu_unai.config.fast_lighting = cbs->gpu_unai.fast_lighting; gpu_unai.config.blending = cbs->gpu_unai.blending; - gpu_unai.config.dithering = cbs->gpu_unai.dithering; gpu_unai.config.scale_hires = cbs->gpu_unai.scale_hires; + gpu_unai.config.dithering = cbs->dithering != 0; + gpu_unai.config.force_dithering = cbs->dithering >> 1; gpu.state.downscale_enable = gpu_unai.config.scale_hires; if (gpu_unai.config.scale_hires) {