Skip to content

Commit

Permalink
gpu_neon: make enh. res. texturing hack optional
Browse files Browse the repository at this point in the history
until something better is figured out, if ever
libretro/pcsx_rearmed#815
  • Loading branch information
notaz committed Jan 3, 2024
1 parent a706d36 commit 6ab6ab9
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
17 changes: 14 additions & 3 deletions frontend/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions frontend/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions frontend/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
};

Expand Down
1 change: 1 addition & 0 deletions frontend/plugin_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion plugins/gpu_neon/psx_gpu/psx_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 6 additions & 5 deletions plugins/gpu_neon/psx_gpu/psx_gpu_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion plugins/gpu_neon/psx_gpu_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6ab6ab9

Please sign in to comment.