X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fgpulib%2Fgpu.c;h=b61bff607d32b84add3269a5f7ec716deaae2f22;hp=70847abea074a82d1145c5e2434cf482d3c07ab6;hb=06bc35c833797ce9f6f3287abf954f037bb12319;hpb=aafcb4ddc257478d613611adcae7cb13fd716577 diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 70847abe..b61bff60 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -24,7 +24,7 @@ //#define log_anomaly gpu_log #define log_anomaly(...) -struct psx_gpu gpu __attribute__((aligned(2048))); +struct psx_gpu gpu; static noinline int do_cmd_buffer(uint32_t *data, int count); static void finish_vram_transfer(int is_read); @@ -92,6 +92,12 @@ static noinline void decide_frameskip(void) gpu.frameskip.active = 1; else gpu.frameskip.active = 0; + + if (!gpu.frameskip.active && gpu.frameskip.pending_fill[0] != 0) { + int dummy; + do_cmd_list(gpu.frameskip.pending_fill, 3, &dummy); + gpu.frameskip.pending_fill[0] = 0; + } } static noinline int decide_frameskip_allow(uint32_t cmd_e3) @@ -127,6 +133,22 @@ static noinline void get_gpu_info(uint32_t data) } } +// double, for overdraw guard +#define VRAM_SIZE (1024 * 512 * 2 * 2) + +static int map_vram(void) +{ + gpu.vram = gpu.mmap(VRAM_SIZE); + if (gpu.vram != NULL) { + gpu.vram += 4096 / 2; + return 0; + } + else { + fprintf(stderr, "could not map vram, expect crashes\n"); + return -1; + } +} + long GPUinit(void) { int ret; @@ -139,12 +161,26 @@ long GPUinit(void) gpu.cmd_len = 0; do_reset(); + if (gpu.mmap != NULL) { + if (map_vram() != 0) + ret = -1; + } return ret; } long GPUshutdown(void) { - return vout_finish(); + long ret; + + renderer_finish(); + ret = vout_finish(); + if (gpu.vram != NULL) { + gpu.vram -= 4096 / 2; + gpu.munmap(gpu.vram, VRAM_SIZE); + } + gpu.vram = NULL; + + return ret; } void GPUwriteStatus(uint32_t data) @@ -201,6 +237,7 @@ void GPUwriteStatus(uint32_t data) gpu.screen.vres = vres[(gpu.status.reg >> 19) & 3]; update_width(); update_height(); + renderer_notify_res_change(); break; default: if ((cmd & 0xf0) == 0x10) @@ -333,6 +370,8 @@ static noinline int do_cmd_list_skip(uint32_t *data, int count, int *last_cmd) int cmd = 0, pos = 0, len, dummy; int skip = 1; + gpu.frameskip.pending_fill[0] = 0; + // XXX: polylines are not properly handled while (pos < count && skip) { uint32_t *list = data + pos; @@ -342,7 +381,9 @@ static noinline int do_cmd_list_skip(uint32_t *data, int count, int *last_cmd) if (cmd == 0x02) { if ((list[2] & 0x3ff) > gpu.screen.w || ((list[2] >> 16) & 0x1ff) > gpu.screen.h) // clearing something large, don't skip - do_cmd_list(data + pos, 3, &dummy); + do_cmd_list(list, 3, &dummy); + else + memcpy(gpu.frameskip.pending_fill, list, 3 * 4); } else if ((cmd & 0xf4) == 0x24) { // flat textured prim @@ -572,13 +613,13 @@ long GPUfreeze(uint32_t type, struct GPUFreeze *freeze) case 1: // save if (gpu.cmd_len > 0) flush_cmd_buffer(); - memcpy(freeze->psxVRam, gpu.vram, sizeof(gpu.vram)); + memcpy(freeze->psxVRam, gpu.vram, 1024 * 512 * 2); memcpy(freeze->ulControl, gpu.regs, sizeof(gpu.regs)); memcpy(freeze->ulControl + 0xe0, gpu.ex_regs, sizeof(gpu.ex_regs)); freeze->ulStatus = gpu.status.reg; break; case 0: // load - memcpy(gpu.vram, freeze->psxVRam, sizeof(gpu.vram)); + memcpy(gpu.vram, freeze->psxVRam, 1024 * 512 * 2); memcpy(gpu.regs, freeze->ulControl, sizeof(gpu.regs)); memcpy(gpu.ex_regs, freeze->ulControl + 0xe0, sizeof(gpu.ex_regs)); gpu.status.reg = freeze->ulStatus; @@ -659,6 +700,14 @@ void GPUrearmedCallbacks(const struct rearmed_cbs *cbs) gpu.state.hcnt = cbs->gpu_hcnt; gpu.state.frame_count = cbs->gpu_frame_count; gpu.state.allow_interlace = cbs->gpu_neon.allow_interlace; + gpu.state.enhancement_enable = cbs->gpu_neon.enhancement_enable; + + gpu.mmap = cbs->mmap; + gpu.munmap = cbs->munmap; + + // delayed vram mmap + if (gpu.vram == NULL) + map_vram(); if (cbs->pl_vout_set_raw_vram) cbs->pl_vout_set_raw_vram(gpu.vram);