X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fgpu_neon%2Fpsx_gpu_if.c;h=ad017614b527758764a22177704643556063f358;hp=ca76fe2498af08e9b80b1cee4548e82cadb99eff;hb=6f6fe96900374d8744473ce240279e66d1260191;hpb=50f9355a2338111d940ed408f52fe1defe4df23e diff --git a/plugins/gpu_neon/psx_gpu_if.c b/plugins/gpu_neon/psx_gpu_if.c index ca76fe24..ad017614 100644 --- a/plugins/gpu_neon/psx_gpu_if.c +++ b/plugins/gpu_neon/psx_gpu_if.c @@ -15,6 +15,7 @@ extern const unsigned char cmd_lengths[256]; #define command_lengths cmd_lengths static unsigned int *ex_regs; +static int initialized; #define PCSX #define SET_Ex(r, v) \ @@ -40,66 +41,87 @@ int do_cmd_list(uint32_t *list, int count, int *last_cmd) return ret; } -#define ENHANCEMENT_BUF_SIZE (1024 * 1024 * 2 * 4 + 4096) +#define ENHANCEMENT_BUF_SIZE (1024 * 1024 * 2 * 4 + 4096 * 2) -int renderer_init(void) +static uint16_t *get_enhancement_bufer(int *x, int *y, int *w, int *h, + int *vram_h) { - initialize_psx_gpu(&egpu, gpu.vram); - ex_regs = gpu.ex_regs; + uint16_t *ret = select_enhancement_buf_ptr(&egpu, *x); + + *x *= 2; + *y *= 2; + *w = *w * 2; + *h = *h * 2; + *vram_h = 1024; + return ret; +} - if (gpu.enhancement_bufer == NULL) { - // currently we use 4x 1024*1024 buffers instead of single 2048*1024 - // to be able to reuse 1024-width code better (triangle setup, - // dithering phase, lines). - gpu.enhancement_bufer = mmap(NULL, ENHANCEMENT_BUF_SIZE, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (gpu.enhancement_bufer == MAP_FAILED) { - printf("OOM for enhancement buffer\n"); - gpu.enhancement_bufer = NULL; - } +static void map_enhancement_buffer(void) +{ + // currently we use 4x 1024*1024 buffers instead of single 2048*1024 + // to be able to reuse 1024-width code better (triangle setup, + // dithering phase, lines). + egpu.enhancement_buf_ptr = gpu.mmap(ENHANCEMENT_BUF_SIZE); + if (egpu.enhancement_buf_ptr == NULL) { + fprintf(stderr, "failed to map enhancement buffer\n"); + gpu.get_enhancement_bufer = NULL; + } + else { + egpu.enhancement_buf_ptr += 4096 / 2; + gpu.get_enhancement_bufer = get_enhancement_bufer; + } +} + +int renderer_init(void) +{ + if (gpu.vram != NULL) { + initialize_psx_gpu(&egpu, gpu.vram); + initialized = 1; } - egpu.enhancement_buf_ptr = gpu.enhancement_bufer; + if (gpu.mmap != NULL && egpu.enhancement_buf_ptr == NULL) + map_enhancement_buffer(); + + ex_regs = gpu.ex_regs; return 0; } void renderer_finish(void) { - if (gpu.enhancement_bufer != NULL) - munmap(gpu.enhancement_bufer, ENHANCEMENT_BUF_SIZE); - gpu.enhancement_bufer = NULL; + if (egpu.enhancement_buf_ptr != NULL) { + egpu.enhancement_buf_ptr -= 4096 / 2; + gpu.munmap(egpu.enhancement_buf_ptr, ENHANCEMENT_BUF_SIZE); + } egpu.enhancement_buf_ptr = NULL; + egpu.enhancement_current_buf_ptr = NULL; + initialized = 0; } static __attribute__((noinline)) void sync_enhancement_buffers(int x, int y, int w, int h) { - int xt = egpu.enhancement_x_threshold; + const int step_x = 1024 / sizeof(egpu.enhancement_buf_by_x16); u16 *src, *dst; - int wb, i; + int w1, fb_index; - w += x & 7; - x &= ~7; - w = (w + 7) & ~7; + w += x & (step_x - 1); + x &= ~(step_x - 1); + w = (w + step_x - 1) & ~(step_x - 1); if (y + h > 512) h = 512 - y; - for (i = 0; i < 4 && w > 0; i++) { - if (x < 512) { - wb = w; - if (x + w > 512) - wb = 512 - x; - src = gpu.vram + xt * i + y * 1024 + x; - dst = egpu.enhancement_buf_ptr + - (1024*1024 + xt * 2) * i + (y * 1024 + x) * 2; - scale2x_tiles8(dst, src, wb / 8, h); - } - - x -= xt; - if (x < 0) { - w += x; - x = 0; - } + while (w > 0) { + fb_index = egpu.enhancement_buf_by_x16[x / step_x]; + for (w1 = 0; w > 0; w1++, w -= step_x) + if (fb_index != egpu.enhancement_buf_by_x16[x / step_x + w1]) + break; + + src = gpu.vram + y * 1024 + x; + dst = select_enhancement_buf_ptr(&egpu, x); + dst += (y * 1024 + x) * 2; + scale2x_tiles8(dst, src, w1 * step_x / 8, h); + + x += w1 * step_x; } } @@ -132,7 +154,11 @@ void renderer_set_interlace(int enable, int is_odd) void renderer_notify_res_change(void) { // note: must keep it multiple of 8 - egpu.enhancement_x_threshold = gpu.screen.hres; + if (egpu.enhancement_x_threshold != gpu.screen.hres) + { + egpu.enhancement_x_threshold = gpu.screen.hres; + update_enhancement_buf_table_from_hres(&egpu); + } } #include "../../frontend/plugin_lib.h" @@ -148,4 +174,14 @@ void renderer_set_config(const struct rearmed_cbs *cbs) sync_enhancement_buffers(0, 0, 1024, 512); } enhancement_was_on = cbs->gpu_neon.enhancement_enable; + + if (!initialized) { + initialize_psx_gpu(&egpu, gpu.vram); + initialized = 1; + } + + if (gpu.mmap != NULL && egpu.enhancement_buf_ptr == NULL) + map_enhancement_buffer(); + if (cbs->pl_set_gpu_caps) + cbs->pl_set_gpu_caps(GPU_CAP_SUPPORTS_2X); }