psx_gpu: 2x sprite fixes and integration
authornotaz <notasas@gmail.com>
Sat, 13 Oct 2012 20:05:42 +0000 (23:05 +0300)
committernotaz <notasas@gmail.com>
Sat, 13 Oct 2012 20:05:42 +0000 (23:05 +0300)
plugins/gpu_neon/psx_gpu/psx_gpu.c
plugins/gpu_neon/psx_gpu/psx_gpu_4x.c
plugins/gpu_neon/psx_gpu/psx_gpu_parse.c
plugins/gpu_neon/psx_gpu/vector_ops.h

index 9b5a64d..2d552aa 100644 (file)
@@ -3574,7 +3574,7 @@ void setup_sprite_16bpp(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
   u32 left_offset = u & 0x7;
   u32 width_rounded = width + left_offset + 7;
 
-  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (s32)(x - left_offset);
+  u16 *fb_ptr = psx_gpu->vram_out_ptr + (y * 1024) + (s32)(x - left_offset);
   u32 right_width = width_rounded & 0x7;
   u32 block_width = width_rounded / 8;
   u32 fb_ptr_pitch = (1024 + 8) - (block_width * 8);
@@ -3696,7 +3696,7 @@ void setup_sprite_untextured(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
 {
   u32 right_width = ((width - 1) & 0x7) + 1;
   u32 right_mask_bits = (0xFF << right_width);
-  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + x;
+  u16 *fb_ptr = psx_gpu->vram_out_ptr + (y * 1024) + x;
   u32 block_width = (width + 7) / 8;
   u32 fb_ptr_pitch = 1024 - ((block_width - 1) * 8);
   u32 blocks_remaining;
@@ -4736,3 +4736,4 @@ void triangle_benchmark(psx_gpu_struct *psx_gpu)
 
 #endif
 
+#include "psx_gpu_4x.c"
index 5e87bea..f8afcf1 100644 (file)
@@ -50,7 +50,7 @@
     tbl_16(texels_high, texels, clut_high);                                    \\r
     zip_8x16b(pixels, texels_low, texels_high);                                \\r
                                                                                \\r
-    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);             \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);    \\r
     block->texels = pixels_wide;                                               \\r
     block->draw_mask_bits = left_mask_bits_a;                                  \\r
     block->fb_ptr = fb_ptr;                                                    \\r
@@ -77,7 +77,7 @@
     tbl_16(texels_high, texels, clut_high);                                    \\r
     zip_8x16b(pixels, texels_low, texels_high);                                \\r
                                                                                \\r
-    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);       \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);    \\r
     block->texels = pixels_wide;                                               \\r
     block->draw_mask_bits = right_mask_bits_a;                                 \\r
     block->fb_ptr = fb_ptr + 16;                                               \\r
 {                                                                              \\r
   vec_8x8u texels_low, texels_high;                                            \\r
   vec_8x16u pixels, pixels_wide;                                               \\r
-  setup_sprite_tile_add_blocks(sub_tile_height);                               \\r
+  setup_sprite_tile_add_blocks_4x(sub_tile_height);                            \\r
   u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF;                            \\r
   u32 edge##_mask_bits_b = edge##_mask_bits >> 8;                              \\r
                                                                                \\r
     tbl_16(texels_high, texels, clut_high);                                    \\r
     zip_8x16b(pixels, texels_low, texels_high);                                \\r
                                                                                \\r
-    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);             \\r
+    zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low);    \\r
     block->texels = pixels_wide;                                               \\r
     block->draw_mask_bits = edge##_mask_bits_a;                                \\r
     block->fb_ptr = fb_ptr;                                                    \\r
                                                                                \\r
     block->r = texels_wide.low;                                                \\r
     block->draw_mask_bits = right_mask_bits_a;                                 \\r
-    block->fb_ptr = fb_ptr + 1024;                                             \\r
+    block->fb_ptr = fb_ptr + 1024 + 16;                                        \\r
     block++;                                                                   \\r
                                                                                \\r
     block->r = texels_wide.high;                                               \\r
     block->draw_mask_bits = right_mask_bits_b;                                 \\r
-    block->fb_ptr = fb_ptr + 24 + 1024;                                        \\r
+    block->fb_ptr = fb_ptr + 24;                                               \\r
     block++;                                                                   \\r
                                                                                \\r
     block->r = texels_wide.high;                                               \\r
 \r
 #define setup_sprite_tile_half_8bpp_4x(edge)                                   \\r
 {                                                                              \\r
-  setup_sprite_tile_add_blocks_4x(sub_tile_height * 2);                        \\r
+  setup_sprite_tile_add_blocks_4x(sub_tile_height);                            \\r
   vec_16x8u texels_wide;                                                       \\r
   u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF;                            \\r
   u32 edge##_mask_bits_b = edge##_mask_bits >> 8;                              \\r
@@ -387,7 +387,7 @@ void setup_sprite_##texture_mode##_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y,   \
   u32 offset_u_right = width_rounded & 0xF;                                    \\r
                                                                                \\r
   u32 left_block_mask = ~(0xFFFFFFFF << (offset_u * 2));                       \\r
-  u32 right_block_mask = 0xFFFFFFFE << (offset_u_right * 2);                   \\r
+  u32 right_block_mask = 0xFFFFFFFC << (offset_u_right * 2);                   \\r
                                                                                \\r
   u32 left_mask_bits;                                                          \\r
   u32 right_mask_bits;                                                         \\r
@@ -404,7 +404,7 @@ void setup_sprite_##texture_mode##_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y,   \
   u32 texture_offset_base = texture_offset;                                    \\r
   u32 control_mask;                                                            \\r
                                                                                \\r
-  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (x - offset_u);               \\r
+  u16 *fb_ptr = psx_gpu->vram_out_ptr + (y * 1024) + (x - offset_u * 2);       \\r
   u32 num_blocks = psx_gpu->num_blocks;                                        \\r
   block_struct *block = psx_gpu->blocks + num_blocks;                          \\r
                                                                                \\r
@@ -416,7 +416,7 @@ void setup_sprite_##texture_mode##_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y,   \
   control_mask = tile_width == 1;                                              \\r
   control_mask |= (tile_height == 1) << 1;                                     \\r
   control_mask |= ((left_block_mask & 0xFFFF) == 0xFFFF) << 2;                 \\r
-  control_mask |= (((right_block_mask >> 8) & 0xFFFF) == 0xFFFF) << 3;         \\r
+  control_mask |= (((right_block_mask >> 16) & 0xFFFF) == 0xFFFF) << 3;        \\r
                                                                                \\r
   sprites_##texture_mode++;                                                    \\r
                                                                                \\r
@@ -514,13 +514,13 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
   u32 left_offset = u & 0x7;\r
   u32 width_rounded = width + left_offset + 7;\r
 \r
-  u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (s32)(x - left_offset);\r
+  u16 *fb_ptr = psx_gpu->vram_out_ptr + (y * 1024) + (s32)(x - left_offset * 2);\r
   u32 right_width = width_rounded & 0x7;\r
   u32 block_width = width_rounded / 8;\r
-  u32 fb_ptr_pitch = (1024 + 8) - (block_width * 8);\r
+  u32 fb_ptr_pitch = (2048 + 16) - (block_width * 16);\r
 \r
   u32 left_mask_bits = ~(0xFFFF << (left_offset * 2));\r
-  u32 right_mask_bits = 0xFE << (right_width * 2);\r
+  u32 right_mask_bits = 0xFFFC << (right_width * 2);\r
 \r
   u32 texture_offset_base = u + (v * 1024);\r
   u32 texture_mask =\r
@@ -563,7 +563,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
 \r
       load_128b(texels, texture_block_ptr);\r
       \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = mask_bits_a;\r
       block->fb_ptr = fb_ptr;          \r
@@ -574,7 +574,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       block->fb_ptr = fb_ptr + 1024;          \r
       block++;\r
       \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = mask_bits_b;\r
       block->fb_ptr = fb_ptr + 8;\r
@@ -613,7 +613,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       if(num_blocks > MAX_BLOCKS)\r
       {\r
         flush_render_block_buffer(psx_gpu);\r
-        num_blocks = block_width;\r
+        num_blocks = block_width * 4;\r
         block = psx_gpu->blocks;\r
       }\r
 \r
@@ -624,7 +624,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       \r
       load_128b(texels, texture_block_ptr);\r
 \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = left_mask_bits_a;\r
       block->fb_ptr = fb_ptr;\r
@@ -635,7 +635,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       block->fb_ptr = fb_ptr + 1024;\r
       block++;      \r
 \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = left_mask_bits_b;\r
       block->fb_ptr = fb_ptr + 8;\r
@@ -654,7 +654,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
         texture_block_ptr = texture_page_ptr + (texture_offset & texture_mask);\r
         load_128b(texels, texture_block_ptr);\r
 \r
-        zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+        zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
         block->texels = texels_wide;\r
         block->draw_mask_bits = 0;\r
         block->fb_ptr = fb_ptr;\r
@@ -665,7 +665,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
         block->fb_ptr = fb_ptr + 1024;\r
         block++;      \r
 \r
-        zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+        zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
         block->texels = texels_wide;\r
         block->draw_mask_bits = 0;\r
         block->fb_ptr = fb_ptr + 8;\r
@@ -677,7 +677,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
         block++;\r
         \r
         texture_offset += 8;\r
-        fb_ptr += 8;\r
+        fb_ptr += 16;\r
 \r
         blocks_remaining--;\r
       }\r
@@ -685,7 +685,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       texture_block_ptr = texture_page_ptr + (texture_offset & texture_mask);\r
       load_128b(texels, texture_block_ptr);\r
       \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = right_mask_bits_a;\r
       block->fb_ptr = fb_ptr;\r
@@ -696,7 +696,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
       block->fb_ptr = fb_ptr + 1024;\r
       block++;      \r
 \r
-      zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
+      zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high);\r
       block->texels = texels_wide;\r
       block->draw_mask_bits = right_mask_bits_b;\r
       block->fb_ptr = fb_ptr + 8;\r
@@ -717,11 +717,17 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u,
 \r
 #endif\r
 \r
+static void setup_sprite_untextured_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y,\r
+ s32 u, s32 v, s32 width, s32 height, u32 color)\r
+{\r
+  setup_sprite_untextured(psx_gpu, x, y, u, v, width * 2, height * 2, color);\r
+}\r
+\r
 #define setup_sprite_blocks_switch_textured_4x(texture_mode)                   \\r
   setup_sprite_##texture_mode##_4x                                             \\r
 \r
 #define setup_sprite_blocks_switch_untextured_4x(texture_mode)                 \\r
-  setup_sprite_untextured                                                      \\r
+  setup_sprite_untextured_4x                                                   \\r
 \r
 #define setup_sprite_blocks_switch_4x(texturing, texture_mode)                 \\r
   setup_sprite_blocks_switch_##texturing##_4x(texture_mode)                    \\r
@@ -802,9 +808,6 @@ render_block_handler_struct render_sprite_block_handlers_4x[] =
 void render_sprite_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, u32 u, u32 v,\r
  s32 width, s32 height, u32 flags, u32 color)\r
 {\r
-  x *= 2;\r
-  y *= 2;\r
-\r
   s32 x_right = x + width - 1;\r
   s32 y_bottom = y + height - 1;\r
 \r
@@ -837,6 +840,9 @@ void render_sprite_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, u32 u, u32 v,
   if((width <= 0) || (height <= 0))\r
     return;\r
 \r
+  x *= 2;\r
+  y *= 2;\r
+\r
 #ifdef PROFILE\r
   span_pixels += width * height;\r
   spans += height;\r
index f920c73..4260bc7 100644 (file)
@@ -760,6 +760,8 @@ breakloop:
   return list - list_start;
 }
 
+#ifdef PCSX
+
 static void *select_enhancement_buf_ptr(psx_gpu_struct *psx_gpu, u32 x)
 {
   u32 b;
@@ -864,6 +866,8 @@ static void do_quad_enhanced(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
   }
 }
 
+#if 0
+
 #define fill_vertex(i, x_, y_, u_, v_, rgb_) \
   vertexes[i].x = x_; \
   vertexes[i].y = y_; \
@@ -873,7 +877,7 @@ static void do_quad_enhanced(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
   vertexes[i].g = (rgb_) >> 8; \
   vertexes[i].b = (rgb_) >> 16
 
-static void do_esprite_in_triangles(psx_gpu_struct *psx_gpu, int x, int y,
+static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
  u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
 {
   vertex_struct *vertex_ptrs[3];
@@ -928,6 +932,17 @@ static void do_esprite_in_triangles(psx_gpu_struct *psx_gpu, int x, int y,
 
   psx_gpu->render_state_base = render_state_base_saved;
 }
+#else
+static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
+ u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
+{
+  u32 flags = (cmd_rgb >> 24);
+  u32 color = cmd_rgb & 0xffffff;
+
+  psx_gpu->vram_out_ptr = psx_gpu->enhancement_current_buf_ptr;
+  render_sprite_4x(psx_gpu, x, y, u, v, w, h, flags, color);
+}
+#endif
 
 u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_command)
 {
@@ -1216,7 +1231,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         u32 height = list_s16[5] & 0x1FF;
 
         render_sprite(psx_gpu, x, y, 0, 0, width, height, current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, 0, 0, width, height, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, 0, 0, width, height, list[0]);
         break;
       }
   
@@ -1233,7 +1248,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
 
         render_sprite(psx_gpu, x, y, u, v, width, height,
          current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, u, v, width, height, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, u, v, width, height, list[0]);
         break;
       }
   
@@ -1246,7 +1261,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
 
         render_sprite(psx_gpu, x, y, 0, 0, 1, 1, current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, 0, 0, 1, 1, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, 0, 0, 1, 1, list[0]);
         break;
       }
   
@@ -1259,7 +1274,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
 
         render_sprite(psx_gpu, x, y, 0, 0, 8, 8, current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, 0, 0, 8, 8, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, 0, 0, 8, 8, list[0]);
         break;
       }
   
@@ -1277,7 +1292,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
 
         render_sprite(psx_gpu, x, y, u, v, 8, 8,
          current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, u, v, 8, 8, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, u, v, 8, 8, list[0]);
         break;
       }
   
@@ -1290,7 +1305,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
 
         render_sprite(psx_gpu, x, y, 0, 0, 16, 16, current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, 0, 0, 16, 16, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, 0, 0, 16, 16, list[0]);
         break;
       }
   
@@ -1307,7 +1322,7 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
         set_clut(psx_gpu, list_s16[5]);
 
         render_sprite(psx_gpu, x, y, u, v, 16, 16, current_command, list[0]);
-        do_esprite_in_triangles(psx_gpu, x, y, u, v, 16, 16, list[0]);
+        do_sprite_enhanced(psx_gpu, x, y, u, v, 16, 16, list[0]);
         break;
       }
   
@@ -1454,13 +1469,14 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_c
     }
   }
 
-#ifdef PCSX
+  enhancement_disable();
+
 breakloop:
-#endif
-enhancement_disable();
   if (last_command != NULL)
     *last_command = current_command;
   return list - list_start;
 }
 
+#endif /* PCSX */
+
 // vim:shiftwidth=2:expandtab
index b58b190..c91e7d9 100644 (file)
@@ -396,7 +396,7 @@ build_vector_types(s);
 
 #define zip_4x32b(dest, source_a, source_b)                                    \
   foreach_element(4, (dest).e[_i] =                                            \
-   (u8)(source_a).e[_i] | ((u8)(source_b).e[_i] << 16))                        \
+   (u16)(source_a).e[_i] | ((u16)(source_b).e[_i] << 16))                      \
 
 #define zip_2x64b(dest, source_a, source_b)                                    \
   foreach_element(2, (dest).e[_i] =                                            \