From fc6cef7d739c850a10bca2a19855654aa78897a8 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 13 Oct 2012 23:05:42 +0300 Subject: [PATCH] psx_gpu: 2x sprite fixes and integration --- plugins/gpu_neon/psx_gpu/psx_gpu.c | 5 +- plugins/gpu_neon/psx_gpu/psx_gpu_4x.c | 60 +++++++++++++----------- plugins/gpu_neon/psx_gpu/psx_gpu_parse.c | 38 ++++++++++----- plugins/gpu_neon/psx_gpu/vector_ops.h | 2 +- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu.c b/plugins/gpu_neon/psx_gpu/psx_gpu.c index 9b5a64d7..2d552aac 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu.c @@ -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" diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c b/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c index 5e87bea0..f8afcf1f 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu_4x.c @@ -50,7 +50,7 @@ tbl_16(texels_high, texels, clut_high); \ zip_8x16b(pixels, texels_low, texels_high); \ \ - zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ + zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ block->texels = pixels_wide; \ block->draw_mask_bits = left_mask_bits_a; \ block->fb_ptr = fb_ptr; \ @@ -77,7 +77,7 @@ tbl_16(texels_high, texels, clut_high); \ zip_8x16b(pixels, texels_low, texels_high); \ \ - zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ + zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ block->texels = pixels_wide; \ block->draw_mask_bits = right_mask_bits_a; \ block->fb_ptr = fb_ptr + 16; \ @@ -111,7 +111,7 @@ { \ vec_8x8u texels_low, texels_high; \ vec_8x16u pixels, pixels_wide; \ - setup_sprite_tile_add_blocks(sub_tile_height); \ + setup_sprite_tile_add_blocks_4x(sub_tile_height); \ u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF; \ u32 edge##_mask_bits_b = edge##_mask_bits >> 8; \ \ @@ -122,7 +122,7 @@ tbl_16(texels_high, texels, clut_high); \ zip_8x16b(pixels, texels_low, texels_high); \ \ - zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ + zip_4x32b(vector_cast(vec_4x32u, pixels_wide), pixels.low, pixels.low); \ block->texels = pixels_wide; \ block->draw_mask_bits = edge##_mask_bits_a; \ block->fb_ptr = fb_ptr; \ @@ -195,12 +195,12 @@ \ block->r = texels_wide.low; \ block->draw_mask_bits = right_mask_bits_a; \ - block->fb_ptr = fb_ptr + 1024; \ + block->fb_ptr = fb_ptr + 1024 + 16; \ block++; \ \ block->r = texels_wide.high; \ block->draw_mask_bits = right_mask_bits_b; \ - block->fb_ptr = fb_ptr + 24 + 1024; \ + block->fb_ptr = fb_ptr + 24; \ block++; \ \ block->r = texels_wide.high; \ @@ -218,7 +218,7 @@ #define setup_sprite_tile_half_8bpp_4x(edge) \ { \ - setup_sprite_tile_add_blocks_4x(sub_tile_height * 2); \ + setup_sprite_tile_add_blocks_4x(sub_tile_height); \ vec_16x8u texels_wide; \ u32 edge##_mask_bits_a = edge##_mask_bits & 0xFF; \ u32 edge##_mask_bits_b = edge##_mask_bits >> 8; \ @@ -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; \ \ u32 left_block_mask = ~(0xFFFFFFFF << (offset_u * 2)); \ - u32 right_block_mask = 0xFFFFFFFE << (offset_u_right * 2); \ + u32 right_block_mask = 0xFFFFFFFC << (offset_u_right * 2); \ \ u32 left_mask_bits; \ u32 right_mask_bits; \ @@ -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; \ u32 control_mask; \ \ - u16 *fb_ptr = psx_gpu->vram_ptr + (y * 1024) + (x - offset_u); \ + u16 *fb_ptr = psx_gpu->vram_out_ptr + (y * 1024) + (x - offset_u * 2); \ u32 num_blocks = psx_gpu->num_blocks; \ block_struct *block = psx_gpu->blocks + num_blocks; \ \ @@ -416,7 +416,7 @@ void setup_sprite_##texture_mode##_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, \ control_mask = tile_width == 1; \ control_mask |= (tile_height == 1) << 1; \ control_mask |= ((left_block_mask & 0xFFFF) == 0xFFFF) << 2; \ - control_mask |= (((right_block_mask >> 8) & 0xFFFF) == 0xFFFF) << 3; \ + control_mask |= (((right_block_mask >> 16) & 0xFFFF) == 0xFFFF) << 3; \ \ sprites_##texture_mode++; \ \ @@ -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; 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 * 2); u32 right_width = width_rounded & 0x7; u32 block_width = width_rounded / 8; - u32 fb_ptr_pitch = (1024 + 8) - (block_width * 8); + u32 fb_ptr_pitch = (2048 + 16) - (block_width * 16); u32 left_mask_bits = ~(0xFFFF << (left_offset * 2)); - u32 right_mask_bits = 0xFE << (right_width * 2); + u32 right_mask_bits = 0xFFFC << (right_width * 2); u32 texture_offset_base = u + (v * 1024); u32 texture_mask = @@ -563,7 +563,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, load_128b(texels, texture_block_ptr); - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); block->texels = texels_wide; block->draw_mask_bits = mask_bits_a; block->fb_ptr = fb_ptr; @@ -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; block++; - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); block->texels = texels_wide; block->draw_mask_bits = mask_bits_b; block->fb_ptr = fb_ptr + 8; @@ -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) { flush_render_block_buffer(psx_gpu); - num_blocks = block_width; + num_blocks = block_width * 4; block = psx_gpu->blocks; } @@ -624,7 +624,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, load_128b(texels, texture_block_ptr); - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); block->texels = texels_wide; block->draw_mask_bits = left_mask_bits_a; block->fb_ptr = fb_ptr; @@ -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; block++; - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); block->texels = texels_wide; block->draw_mask_bits = left_mask_bits_b; block->fb_ptr = fb_ptr + 8; @@ -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); load_128b(texels, texture_block_ptr); - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); block->texels = texels_wide; block->draw_mask_bits = 0; block->fb_ptr = fb_ptr; @@ -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; block++; - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); block->texels = texels_wide; block->draw_mask_bits = 0; block->fb_ptr = fb_ptr + 8; @@ -677,7 +677,7 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, block++; texture_offset += 8; - fb_ptr += 8; + fb_ptr += 16; blocks_remaining--; } @@ -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); load_128b(texels, texture_block_ptr); - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.low, texels.low); block->texels = texels_wide; block->draw_mask_bits = right_mask_bits_a; block->fb_ptr = fb_ptr; @@ -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; block++; - zip4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); + zip_4x32b(vector_cast(vec_4x32u, texels_wide), texels.high, texels.high); block->texels = texels_wide; block->draw_mask_bits = right_mask_bits_b; block->fb_ptr = fb_ptr + 8; @@ -717,11 +717,17 @@ void setup_sprite_16bpp_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, s32 u, #endif +static void setup_sprite_untextured_4x(psx_gpu_struct *psx_gpu, s32 x, s32 y, + s32 u, s32 v, s32 width, s32 height, u32 color) +{ + setup_sprite_untextured(psx_gpu, x, y, u, v, width * 2, height * 2, color); +} + #define setup_sprite_blocks_switch_textured_4x(texture_mode) \ setup_sprite_##texture_mode##_4x \ #define setup_sprite_blocks_switch_untextured_4x(texture_mode) \ - setup_sprite_untextured \ + setup_sprite_untextured_4x \ #define setup_sprite_blocks_switch_4x(texturing, texture_mode) \ setup_sprite_blocks_switch_##texturing##_4x(texture_mode) \ @@ -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, s32 width, s32 height, u32 flags, u32 color) { - x *= 2; - y *= 2; - s32 x_right = x + width - 1; s32 y_bottom = y + height - 1; @@ -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)) return; + x *= 2; + y *= 2; + #ifdef PROFILE span_pixels += width * height; spans += height; diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c index f920c73e..4260bc70 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c @@ -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 diff --git a/plugins/gpu_neon/psx_gpu/vector_ops.h b/plugins/gpu_neon/psx_gpu/vector_ops.h index b58b1908..c91e7d95 100644 --- a/plugins/gpu_neon/psx_gpu/vector_ops.h +++ b/plugins/gpu_neon/psx_gpu/vector_ops.h @@ -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] = \ -- 2.39.5