gpu: improve timings of clipped sprites
[pcsx_rearmed.git] / plugins / gpu_unai / gpulib_if.cpp
index 191108b..45c73a7 100644 (file)
@@ -666,9 +666,9 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0x62:
       case 0x63: {          // Monochrome rectangle (variable size)
         PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1];
-        gpuDrawT(packet, driver);
-        cpu_cycles += gput_sprite(le16_to_u16(packet.U2[4]) & 0x3ff,
-                         le16_to_u16(packet.U2[5]) & 0x1ff);
+        s32 w = 0, h = 0;
+        gpuDrawT(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
       case 0x64:
@@ -677,6 +677,7 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0x67: {          // Textured rectangle (variable size)
         gpuSetCLUT    (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
         u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1);
+        s32 w = 0, h = 0;
 
         //senquack - Only color 808080h-878787h allows skipping lighting calculation:
         // This fixes Silent Hill running animation on loading screens:
@@ -695,9 +696,8 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
         if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080))
           driver_idx |= Lighting;
         PS driver = gpuSpriteSpanDrivers[driver_idx];
-        gpuDrawS(packet, driver);
-        cpu_cycles += gput_sprite(le16_to_u16(packet.U2[6]) & 0x3ff,
-                         le16_to_u16(packet.U2[7]) & 0x1ff);
+        gpuDrawS(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
       case 0x68:
@@ -706,7 +706,8 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0x6B: {          // Monochrome rectangle (1x1 dot)
         gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00010001);
         PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1];
-        gpuDrawT(packet, driver);
+        s32 w = 0, h = 0;
+        gpuDrawT(packet, driver, &w, &h);
         cpu_cycles += gput_sprite(1, 1);
       } break;
 
@@ -716,8 +717,9 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0x73: {          // Monochrome rectangle (8x8)
         gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00080008);
         PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1];
-        gpuDrawT(packet, driver);
-        cpu_cycles += gput_sprite(8, 8);
+        s32 w = 0, h = 0;
+        gpuDrawT(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
       case 0x74:
@@ -727,6 +729,7 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
         gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00080008);
         gpuSetCLUT    (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
         u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1);
+        s32 w = 0, h = 0;
 
         //senquack - Only color 808080h-878787h allows skipping lighting calculation:
         //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))
@@ -734,8 +737,8 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
         if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080))
           driver_idx |= Lighting;
         PS driver = gpuSpriteSpanDrivers[driver_idx];
-        gpuDrawS(packet, driver);
-        cpu_cycles += gput_sprite(8, 8);
+        gpuDrawS(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
       case 0x78:
@@ -744,8 +747,9 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0x7B: {          // Monochrome rectangle (16x16)
         gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00100010);
         PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1];
-        gpuDrawT(packet, driver);
-        cpu_cycles += gput_sprite(16, 16);
+        s32 w = 0, h = 0;
+        gpuDrawT(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
       case 0x7C:
@@ -753,9 +757,10 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
 #ifdef __arm__
         if ((gpu_unai.GPU_GP1 & 0x180) == 0 && (gpu_unai.Masking | gpu_unai.PixelMSB) == 0)
         {
-          gpuSetCLUT    (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
-          gpuDrawS16(packet);
-          cpu_cycles += gput_sprite(16, 16);
+          s32 w = 0, h = 0;
+          gpuSetCLUT(le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
+          gpuDrawS16(packet, &w, &h);
+          cpu_cycles += gput_sprite(w, h);
           break;
         }
         // fallthrough
@@ -765,14 +770,15 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
         gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00100010);
         gpuSetCLUT    (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16);
         u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1);
+        s32 w = 0, h = 0;
         //senquack - Only color 808080h-878787h allows skipping lighting calculation:
         //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))
         // Strip lower 3 bits of each color and determine if lighting should be used:
         if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080))
           driver_idx |= Lighting;
         PS driver = gpuSpriteSpanDrivers[driver_idx];
-        gpuDrawS(packet, driver);
-        cpu_cycles += gput_sprite(16, 16);
+        gpuDrawS(packet, driver, &w, &h);
+        cpu_cycles += gput_sprite(w, h);
       } break;
 
 #ifdef TEST
@@ -792,6 +798,7 @@ int do_cmd_list(u32 *_list, int list_len, int *cpu_cycles_out, int *last_cmd)
       case 0xC0:
         break;
 #else
+      case 0x1F:                   //  irq?
       case 0x80 ... 0x9F:          //  vid -> vid
       case 0xA0 ... 0xBF:          //  sys -> vid
       case 0xC0 ... 0xDF:          //  vid -> sys