From 6ab6ab973403d7232ce056c0f233c89a6456b403 Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 3 Jan 2024 02:36:58 +0200 Subject: [PATCH] gpu_neon: make enh. res. texturing hack optional until something better is figured out, if ever libretro/pcsx_rearmed#815 --- frontend/libretro.c | 17 ++++++++++++++--- frontend/libretro_core_options.h | 14 ++++++++++++++ frontend/menu.c | 2 ++ frontend/plugin_lib.h | 1 + plugins/gpu_neon/psx_gpu/psx_gpu.h | 5 ++++- plugins/gpu_neon/psx_gpu/psx_gpu_parse.c | 11 ++++++----- plugins/gpu_neon/psx_gpu_if.c | 3 ++- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index d361be15..7b29a23a 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -2101,10 +2101,21 @@ static void update_variables(bool in_flight) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "disabled") == 0) - pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; - else if (strcmp(var.value, "enabled") == 0) + if (strcmp(var.value, "enabled") == 0) pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1; + else + pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; + } + + var.value = NULL; + var.key = "pcsx_rearmed_neon_enhancement_tex_adj"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + pl_rearmed_cbs.gpu_neon.enhancement_tex_adj = 1; + else + pl_rearmed_cbs.gpu_neon.enhancement_tex_adj = 0; } #endif diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 25b2da4c..02f65c73 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -510,6 +510,20 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "disabled", }, + { + "pcsx_rearmed_neon_enhancement_tex_adj", + "(GPU) Enhanced Resolution Texture Adjustment", + "Enhanced Resolution Texture Adjustment", + "(Hack) Attempts to solve some texturing issues is some games, but causes new ones in others.", + NULL, + "gpu_neon", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, #endif /* GPU_NEON */ #ifdef GPU_PEOPS { diff --git a/frontend/menu.c b/frontend/menu.c index e6c15402..51cb3771 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -450,6 +450,7 @@ static const struct { CE_INTVAL_P(gpu_neon.allow_interlace), CE_INTVAL_P(gpu_neon.enhancement_enable), CE_INTVAL_P(gpu_neon.enhancement_no_main), + CE_INTVAL_P(gpu_neon.enhancement_tex_adj), CE_INTVAL_P(gpu_peopsgl.bDrawDither), CE_INTVAL_P(gpu_peopsgl.iFilterType), CE_INTVAL_P(gpu_peopsgl.iFrameTexType), @@ -1414,6 +1415,7 @@ static menu_entry e_menu_plugin_gpu_neon[] = mee_enum ("Enable interlace mode", 0, pl_rearmed_cbs.gpu_neon.allow_interlace, men_gpu_interlace), mee_onoff_h ("Enhanced resolution", 0, pl_rearmed_cbs.gpu_neon.enhancement_enable, 1, h_gpu_neon_enhanced), mee_onoff_h ("Enhanced res. speed hack", 0, pl_rearmed_cbs.gpu_neon.enhancement_no_main, 1, h_gpu_neon_enhanced_hack), + mee_onoff ("Enh. res. texture adjust", 0, pl_rearmed_cbs.gpu_neon.enhancement_tex_adj, 1), mee_end, }; diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index 4e5ad8b0..7879e70b 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -81,6 +81,7 @@ struct rearmed_cbs { int allow_interlace; // 0 off, 1 on, 2 guess int enhancement_enable; int enhancement_no_main; + int enhancement_tex_adj; } gpu_neon; struct { int iUseDither; diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu.h b/plugins/gpu_neon/psx_gpu/psx_gpu.h index 687715a5..2539521b 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu.h +++ b/plugins/gpu_neon/psx_gpu/psx_gpu.h @@ -200,9 +200,12 @@ typedef struct u16 enhancement_scanout_eselect; // eviction selector u16 enhancement_current_buf; + u32 hack_disable_main:1; + u32 hack_texture_adj:1; + // Align up to 64 byte boundary to keep the upcoming buffers cache line // aligned, also make reachable with single immediate addition - u8 reserved_a[188 + 9*4 - 9*sizeof(void *)]; + u8 reserved_a[184 + 9*4 - 9*sizeof(void *)]; // 8KB block_struct blocks[MAX_BLOCKS_PER_ROW]; diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c index 44fce93a..d81b7078 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c @@ -1018,8 +1018,6 @@ void scale2x_tiles8(void *dst, const void *src, int w8, int h) } #endif -static int disable_main_render; - // simple check for a case where no clipping is used // - now handled by adjusting the viewport static int check_enhanced_range(psx_gpu_struct *psx_gpu, int x, int y) @@ -1065,6 +1063,7 @@ static void patch_v(vertex_struct *vertex_ptrs, int count, int old, int new) vertex_ptrs[i].v = new; } +// this sometimes does more harm than good, like in PE2 static void uv_hack(vertex_struct *vertex_ptrs, int vertex_count) { int i, u[4], v[4]; @@ -1103,7 +1102,7 @@ static void do_triangle_enhanced(psx_gpu_struct *psx_gpu, if (!prepare_triangle(psx_gpu, vertexes, vertex_ptrs)) return; - if (!disable_main_render) + if (!psx_gpu->hack_disable_main) render_triangle_p(psx_gpu, vertex_ptrs, current_command); if (!check_enhanced_range(psx_gpu, vertex_ptrs[0]->x, vertex_ptrs[2]->x)) @@ -1322,7 +1321,8 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, get_vertex_data_xy_uv(2, 10); get_vertex_data_xy_uv(3, 14); - uv_hack(vertexes, 4); + if (psx_gpu->hack_texture_adj) + uv_hack(vertexes, 4); do_quad_enhanced(psx_gpu, vertexes, current_command); gput_sum(cpu_cycles_sum, cpu_cycles, gput_quad_base_t()); break; @@ -1375,7 +1375,8 @@ u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size, get_vertex_data_xy_uv_rgb(2, 12); get_vertex_data_xy_uv_rgb(3, 18); - uv_hack(vertexes, 4); + if (psx_gpu->hack_texture_adj) + uv_hack(vertexes, 4); do_quad_enhanced(psx_gpu, vertexes, current_command); gput_sum(cpu_cycles_sum, cpu_cycles, gput_quad_base_gt()); break; diff --git a/plugins/gpu_neon/psx_gpu_if.c b/plugins/gpu_neon/psx_gpu_if.c index 81eadfe9..84fa9322 100644 --- a/plugins/gpu_neon/psx_gpu_if.c +++ b/plugins/gpu_neon/psx_gpu_if.c @@ -223,7 +223,8 @@ void renderer_set_config(const struct rearmed_cbs *cbs) if (cbs->pl_set_gpu_caps) cbs->pl_set_gpu_caps(GPU_CAP_SUPPORTS_2X); - disable_main_render = cbs->gpu_neon.enhancement_no_main; + egpu.hack_disable_main = cbs->gpu_neon.enhancement_no_main; + egpu.hack_texture_adj = cbs->gpu_neon.enhancement_tex_adj; if (gpu.state.enhancement_enable) { if (gpu.mmap != NULL && egpu.enhancement_buf_ptr == NULL) map_enhancement_buffer(); -- 2.39.2