gpu_unai: can't do some optimizations with dithering
authornotaz <notasas@gmail.com>
Fri, 9 Jan 2026 22:53:32 +0000 (00:53 +0200)
committernotaz <notasas@gmail.com>
Wed, 14 Jan 2026 00:26:14 +0000 (02:26 +0200)
notaz/pcsx_rearmed#401

plugins/gpu_unai/gpulib_if.cpp

index 2a8ae75..05f5fbf 100644 (file)
@@ -321,9 +321,11 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
       case 0x2D:
       case 0x2E:
       case 0x2F: {          // Textured 4-pt poly
+        u32 dithering = Dithering;
         u32 simplified_count;
         gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16);
-        if ((simplified_count = prim_try_simplify_quad_t(gpu_unai.PacketBuffer.U4,
+        if (!dithering &&
+            (simplified_count = prim_try_simplify_quad_t(gpu_unai.PacketBuffer.U4,
               gpu_unai.PacketBuffer.U4)))
         {
           for (i = 0;; ) {
@@ -337,7 +339,7 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
         gpuSetCLUT(le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
 
         u32 driver_idx =
-          Dithering |
+          dithering |
           Blending_Mode | gpu_unai.TEXT_MODE |
           gpu_unai.Masking | Blending | gpu_unai.PixelMSB;
 
@@ -357,18 +359,21 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
       case 0x31:
       case 0x32:
       case 0x33: {          // Gouraud-shaded 3-pt poly
+        u32 dithering = Dithering;
         //NOTE: The '129' here is CF_GOURAUD | CF_LIGHT, however
         // this is an untextured poly, so CF_LIGHT (texture blend)
         // shouldn't apply. Until the original array of template
         // instantiation ptrs is fixed, we're stuck with this. (TODO)
         u8 gouraud = 129;
-        u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]);
-        for (i = 1; i < 3; i++)
-          xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]);
-        if ((xor_ & HTOLE32(0xf8f8f8)) == 0)
-          gouraud = 0;
+        if (!dithering) {
+          u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]);
+          for (i = 1; i < 3; i++)
+            xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]);
+          if ((xor_ & HTOLE32(0xf8f8f8)) == 0)
+            gouraud = 0;
+        }
         PP driver = gpuPolySpanDrivers[
-          Dithering |
+          dithering |
           Blending_Mode |
           gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB
         ];
@@ -385,6 +390,7 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
       case 0x37: {          // Gouraud-shaded, textured 3-pt poly
         gpuSetCLUT    (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
         gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16);
+        u32 dithering = Dithering;
         u8 lighting = Lighting;
         u8 gouraud = lighting ? (1<<7) : 0;
         if (lighting) {
@@ -393,12 +399,12 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
             xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 3]);
           if ((xor_ & HTOLE32(0xf8f8f8)) == 0) {
             gouraud = 0;
-            if (!need_lighting(rgb0))
+            if (!dithering && !need_lighting(rgb0))
               lighting = 0;
           }
         }
         PP driver = gpuPolySpanDrivers[
-          Dithering |
+          dithering |
           Blending_Mode | gpu_unai.TEXT_MODE |
           gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB
         ];
@@ -413,15 +419,18 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
       case 0x39:
       case 0x3A:
       case 0x3B: {          // Gouraud-shaded 4-pt poly
+        u32 dithering = Dithering;
         // See notes regarding '129' for 0x30..0x33 further above -senquack
         u8 gouraud = 129;
-        u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]);
-        for (i = 1; i < 4; i++)
-          xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]);
-        if ((xor_ & HTOLE32(0xf8f8f8)) == 0)
-          gouraud = 0;
+        if (!dithering) {
+          u32 xor_ = 0, rgb0 = le32_raw(gpu_unai.PacketBuffer.U4[0]);
+          for (i = 1; i < 4; i++)
+            xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 2]);
+          if ((xor_ & HTOLE32(0xf8f8f8)) == 0)
+            gouraud = 0;
+        }
         PP driver = gpuPolySpanDrivers[
-          Dithering |
+          dithering |
           Blending_Mode |
           gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB
         ];
@@ -436,9 +445,11 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
       case 0x3D:
       case 0x3E:
       case 0x3F: {          // Gouraud-shaded, textured 4-pt poly
+        u32 dithering = Dithering;
         u32 simplified_count;
         gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16);
-        if ((simplified_count = prim_try_simplify_quad_gt(gpu_unai.PacketBuffer.U4,
+        if (!dithering &&
+             (simplified_count = prim_try_simplify_quad_gt(gpu_unai.PacketBuffer.U4,
               gpu_unai.PacketBuffer.U4)))
         {
           for (i = 0;; ) {
@@ -458,12 +469,12 @@ int renderer_do_cmd_list(u32 *list_, int list_len, uint32_t *ex_regs,
             xor_ |= rgb0 ^ le32_raw(gpu_unai.PacketBuffer.U4[i * 3]);
           if ((xor_ & HTOLE32(0xf8f8f8)) == 0) {
             gouraud = 0;
-            if (!need_lighting(rgb0))
+            if (!dithering && !need_lighting(rgb0))
               lighting = 0;
           }
         }
         PP driver = gpuPolySpanDrivers[
-          Dithering |
+          dithering |
           Blending_Mode | gpu_unai.TEXT_MODE |
           gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB
         ];