diff options
author | notaz | 2012-11-02 03:07:05 +0200 |
---|---|---|
committer | notaz | 2012-11-02 03:07:05 +0200 |
commit | 2857d72e4ca743bba3cf55e298949e24d97dff02 (patch) | |
tree | 3742f3cd7cb1c10fc42fc4b581fff9c4ead3d9ce /plugins/gpulib | |
parent | 0e53ec55691229fee1cbb7c23b305be6a59431c4 (diff) | |
parent | bcb62992749a7f66e9a16a8022e090ff334c4424 (diff) | |
download | pcsx_rearmed-2857d72e4ca743bba3cf55e298949e24d97dff02.tar.gz pcsx_rearmed-2857d72e4ca743bba3cf55e298949e24d97dff02.tar.bz2 pcsx_rearmed-2857d72e4ca743bba3cf55e298949e24d97dff02.zip |
Merge branch 'enhancement'
Conflicts:
frontend/libretro.c
Diffstat (limited to 'plugins/gpulib')
-rw-r--r-- | plugins/gpulib/gpu.c | 47 | ||||
-rw-r--r-- | plugins/gpulib/gpu.h | 11 | ||||
-rw-r--r-- | plugins/gpulib/vout_pl.c | 95 |
3 files changed, 91 insertions, 62 deletions
diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 46e92d1..b61bff6 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); @@ -133,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; @@ -145,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) @@ -207,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) @@ -582,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; @@ -669,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); diff --git a/plugins/gpulib/gpu.h b/plugins/gpulib/gpu.h index 1cbe38c..d11f991 100644 --- a/plugins/gpulib/gpu.h +++ b/plugins/gpulib/gpu.h @@ -17,10 +17,9 @@ extern "C" { #define CMD_BUFFER_LEN 1024 struct psx_gpu { - uint16_t vram[1024 * 512]; - uint16_t guard[1024 * 512]; // overdraw guard uint32_t cmd_buffer[CMD_BUFFER_LEN]; uint32_t regs[16]; + uint16_t *vram; union { uint32_t reg; struct { @@ -67,6 +66,8 @@ struct psx_gpu { uint32_t old_interlace:1; uint32_t allow_interlace:2; uint32_t blanked:1; + uint32_t enhancement_enable:1; + uint32_t enhancement_active:1; uint32_t *frame_count; uint32_t *hcnt; /* hsync count */ struct { @@ -87,6 +88,10 @@ struct psx_gpu { uint32_t last_flip_frame; uint32_t pending_fill[3]; } frameskip; + uint16_t *(*get_enhancement_bufer) + (int *x, int *y, int *w, int *h, int *vram_h); + void *(*mmap)(unsigned int size); + void (*munmap)(void *ptr, unsigned int size); }; extern struct psx_gpu gpu; @@ -98,11 +103,13 @@ int do_cmd_list(uint32_t *list, int count, int *last_cmd); struct rearmed_cbs; int renderer_init(void); +void renderer_finish(void); void renderer_sync_ecmds(uint32_t * ecmds); void renderer_update_caches(int x, int y, int w, int h); void renderer_flush_queues(void); void renderer_set_interlace(int enable, int is_odd); void renderer_set_config(const struct rearmed_cbs *config); +void renderer_notify_res_change(void); int vout_init(void); int vout_finish(void); diff --git a/plugins/gpulib/vout_pl.c b/plugins/gpulib/vout_pl.c index 0bd1ecf..11307e2 100644 --- a/plugins/gpulib/vout_pl.c +++ b/plugins/gpulib/vout_pl.c @@ -15,7 +15,6 @@ #include "../../frontend/plugin_lib.h" static const struct rearmed_cbs *cbs; -static void *screen_buf; int vout_init(void) { @@ -27,90 +26,74 @@ int vout_finish(void) return 0; } -static void check_mode_change(void) +static void check_mode_change(int force) { static uint32_t old_status; static int old_h; + int w = gpu.screen.hres; + int h = gpu.screen.h; + + gpu.state.enhancement_active = + gpu.get_enhancement_bufer != NULL && gpu.state.enhancement_enable + && w <= 512 && h <= 256 && !gpu.status.rgb24; + + if (gpu.state.enhancement_active) { + w *= 2; + h *= 2; + } // width|rgb24 change? - if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || gpu.screen.h != old_h) + if (force || (gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h) { old_status = gpu.status.reg; - old_h = gpu.screen.h; - screen_buf = cbs->pl_vout_set_mode(gpu.screen.hres, gpu.screen.h, + old_h = h; + + cbs->pl_vout_set_mode(w, h, (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16); } } -static void blit(void) +void vout_update(void) { int x = gpu.screen.x & ~1; // alignment needed by blitter int y = gpu.screen.y; int w = gpu.screen.w; int h = gpu.screen.h; uint16_t *vram = gpu.vram; - int stride = gpu.screen.hres; - int fb_offs, doffs; - uint8_t *dest; + int vram_h = 512; - dest = (uint8_t *)screen_buf; - if (dest == NULL) + if (w == 0 || h == 0) return; - fb_offs = y * 1024 + x; + check_mode_change(0); + if (gpu.state.enhancement_active) + vram = gpu.get_enhancement_bufer(&x, &y, &w, &h, &vram_h); - // only do centering, at least for now - doffs = (stride - w) / 2 & ~1; - - if (gpu.status.rgb24) - { - if (cbs->only_16bpp) { - dest += doffs * 2; - for (; h-- > 0; dest += stride * 2, fb_offs += 1024) - { - fb_offs &= 1024*512-1; - bgr888_to_rgb565(dest, vram + fb_offs, w * 3); - } - } - else { - dest += (doffs / 8) * 24; - for (; h-- > 0; dest += stride * 3, fb_offs += 1024) - { - fb_offs &= 1024*512-1; - bgr888_to_rgb888(dest, vram + fb_offs, w * 3); - } - } - } - else - { - dest += doffs * 2; - for (; h-- > 0; dest += stride * 2, fb_offs += 1024) - { - fb_offs &= 1024*512-1; - bgr555_to_rgb565(dest, vram + fb_offs, w * 2); + if (y + h > vram_h) { + if (y + h - vram_h > h / 2) { + // wrap + y = 0; + h -= vram_h - y; } + else + // clip + h = vram_h - y; } - screen_buf = cbs->pl_vout_flip(); -} + vram += y * 1024 + x; -void vout_update(void) -{ - check_mode_change(); - if (cbs->pl_vout_raw_flip) - cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y); - else - blit(); + cbs->pl_vout_flip(vram, 1024, gpu.status.rgb24, w, h); } void vout_blank(void) { - check_mode_change(); - if (cbs->pl_vout_raw_flip == NULL) { - int bytespp = gpu.status.rgb24 ? 3 : 2; - memset(screen_buf, 0, gpu.screen.hres * gpu.screen.h * bytespp); - screen_buf = cbs->pl_vout_flip(); + int w = gpu.screen.hres; + int h = gpu.screen.h; + if (gpu.state.enhancement_active) { + w *= 2; + h *= 2; } + cbs->pl_vout_flip(NULL, 1024, gpu.status.rgb24, w, h); } long GPUopen(void **unused) @@ -119,7 +102,7 @@ long GPUopen(void **unused) gpu.frameskip.frame_ready = 1; cbs->pl_vout_open(); - screen_buf = cbs->pl_vout_flip(); + check_mode_change(1); return 0; } |