gpu: allow to force-enable dithering
authornotaz <notasas@gmail.com>
Mon, 9 Dec 2024 00:17:13 +0000 (02:17 +0200)
committernotaz <notasas@gmail.com>
Mon, 9 Dec 2024 00:21:08 +0000 (02:21 +0200)
libretro/pcsx_rearmed#853

12 files changed:
frontend/libretro.c
frontend/libretro_core_options.h
frontend/main.c
frontend/menu.c
frontend/plugin_lib.h
plugins/dfxvideo/gpulib_if.c
plugins/gpu_neon/psx_gpu/psx_gpu.h
plugins/gpu_neon/psx_gpu/psx_gpu_parse.c
plugins/gpu_neon/psx_gpu_if.c
plugins/gpu_unai/gpu.h
plugins/gpu_unai/gpu_unai.h
plugins/gpu_unai/gpulib_if.cpp

index 3f66568..07b108c 100644 (file)
@@ -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;
index 220df0f..a07491b 100644 (file)
@@ -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)
index 42a90d4..2dd5ca4 100644 (file)
@@ -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;
index 438d2cf..773ad60 100644 (file)
@@ -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
index 6fee70b..420f89f 100644 (file)
@@ -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 {
index 8a3f2f9..2c0a483 100644 (file)
@@ -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);
index 2d0f7b1..1ea3917 100644 (file)
@@ -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)))
index 1fa06a1..03d055d 100644 (file)
@@ -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;
index 0210458..5b6a335 100644 (file)
@@ -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;
index 17f80eb..009cdfc 100644 (file)
@@ -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
index 6fe00bb..ce2dac4 100644 (file)
@@ -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()
index 40c7fd9..5fbb7f5 100644 (file)
@@ -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) {