From: notaz Date: Fri, 27 Oct 2023 20:56:06 +0000 (+0300) Subject: adjust vita's mappings to more resemble other platforms X-Git-Tag: r24l~94 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bd33f52586479b4e4b96418522ceeb330df87f2;p=pcsx_rearmed.git adjust vita's mappings to more resemble other platforms --- diff --git a/frontend/libretro.c b/frontend/libretro.c index 5a44e43e..26f36d42 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -377,7 +377,7 @@ psx_map_t custom_psx_maps[] = { { NULL, 0x12800000, 0x010000, MAP_TAG_OTHER }, // 0x1f800000 { NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER }, // 0x1fc00000 { NULL, 0x11000000, 0x800000, MAP_TAG_LUTS }, // 0x08000000 - { NULL, 0x12000000, 0x200000, MAP_TAG_VRAM }, // 0x00000000 + { NULL, 0x12000000, 0x201000, MAP_TAG_VRAM }, // 0x00000000 }; void *pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed, @@ -446,19 +446,20 @@ void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) typedef struct { void *buffer; - uint32_t target_map; size_t size; enum psxMapTag tag; + int used; } psx_map_t; -void *addr = NULL; +static void *addr = NULL; psx_map_t custom_psx_maps[] = { - { NULL, NULL, 0x210000, MAP_TAG_RAM }, // 0x80000000 - { NULL, NULL, 0x010000, MAP_TAG_OTHER }, // 0x1f800000 - { NULL, NULL, 0x080000, MAP_TAG_OTHER }, // 0x1fc00000 - { NULL, NULL, 0x800000, MAP_TAG_LUTS }, // 0x08000000 - { NULL, NULL, 0x200000, MAP_TAG_VRAM }, // 0x00000000 + { NULL, 0x800000, MAP_TAG_LUTS }, + { NULL, 0x080000, MAP_TAG_OTHER }, + { NULL, 0x010000, MAP_TAG_OTHER }, + { NULL, 0x201000, MAP_TAG_VRAM }, + { NULL, 0x802000, MAP_TAG_VRAM }, // enhanced renderer + { NULL, 0x210000, MAP_TAG_RAM }, }; int init_vita_mmap() @@ -468,12 +469,13 @@ int init_vita_mmap() addr = malloc(64 * 1024 * 1024); if (addr == NULL) return -1; - tmpaddr = ((u32)(addr + 0xFFFFFF)) & ~0xFFFFFF; - custom_psx_maps[0].buffer = tmpaddr + 0x2000000; - custom_psx_maps[1].buffer = tmpaddr + 0x1800000; - custom_psx_maps[2].buffer = tmpaddr + 0x1c00000; - custom_psx_maps[3].buffer = tmpaddr + 0x0000000; + tmpaddr = (void *)(((size_t)addr + 0xFFFFFF) & ~0xFFFFFF); + custom_psx_maps[0].buffer = tmpaddr + 0x0000000; + custom_psx_maps[1].buffer = tmpaddr + 0x0800000; + custom_psx_maps[2].buffer = tmpaddr + 0x0880000; + custom_psx_maps[3].buffer = tmpaddr + 0x0900000; custom_psx_maps[4].buffer = tmpaddr + 0x1000000; + custom_psx_maps[5].buffer = tmpaddr + 0x2000000; #if 0 for(n = 0; n < 5; n++){ sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer); @@ -484,6 +486,11 @@ int init_vita_mmap() void deinit_vita_mmap() { + size_t i; + for (i = 0; i < sizeof(custom_psx_maps) / sizeof(custom_psx_maps[0]); i++) { + custom_psx_maps[i].buffer = NULL; + custom_psx_maps[i].used = 0; + } free(addr); } @@ -497,8 +504,9 @@ void *pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, for (; custom_map->size; custom_map++) { - if ((custom_map->size == size) && (custom_map->tag == tag)) + if (custom_map->size == size && custom_map->tag == tag && !custom_map->used) { + custom_map->used = 1; return custom_map->buffer; } } @@ -516,6 +524,7 @@ void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag) { if ((custom_map->buffer == ptr)) { + custom_map->used = 0; return; } } diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 65958062..24fbf3bf 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -222,8 +222,9 @@ static noinline void get_gpu_info(uint32_t data) } } -// double, for overdraw guard -#define VRAM_SIZE ((1024 * 512 * 2 * 2) + 4096) +#ifndef max +#define max(a, b) (((a) > (b)) ? (a) : (b)) +#endif // Minimum 16-byte VRAM alignment needed by gpu_unai's pixel-skipping // renderer/downscaler it uses in high res modes: @@ -235,6 +236,9 @@ static noinline void get_gpu_info(uint32_t data) #define VRAM_ALIGN 16 #endif +// double, for overdraw guard + at least 1 page before +#define VRAM_SIZE ((1024 * 512 * 2 * 2) + max(VRAM_ALIGN, 4096)) + // vram ptr received from mmap/malloc/alloc (will deallocate using this) static uint16_t *vram_ptr_orig = NULL; @@ -248,9 +252,9 @@ static uint16_t *vram_ptr_orig = NULL; static int map_vram(void) { #if GPULIB_USE_MMAP - gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE + (VRAM_ALIGN-1)); + gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE); #else - gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE + (VRAM_ALIGN-1), 1); + gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE, 1); #endif if (gpu.vram != NULL && gpu.vram != (void *)(intptr_t)-1) { // 4kb guard in front