From: notaz Date: Sun, 1 Oct 2023 21:37:45 +0000 (+0300) Subject: gpulib: use mmap on linux like before X-Git-Tag: r24l~153 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e34ef5ac7dbcc2d96abef8f16ac17b156c86df53;p=pcsx_rearmed.git gpulib: use mmap on linux like before negativeExponent made it heap alloc as default in 12367ad02, why? --- diff --git a/Makefile.libretro b/Makefile.libretro index 831964f5..ca5feca3 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -529,7 +529,7 @@ else ifeq ($(platform), miyoo) TARGET := $(TARGET_NAME)_libretro.so fpic := -fPIC CFLAGS += -mcpu=arm926ej-s -fsingle-precision-constant - CFLAGS += -DGPULIB_USE_MMAP -DGPU_UNAI_USE_INT_DIV_MULTINV -D_MIYOO + CFLAGS += -DGPU_UNAI_USE_INT_DIV_MULTINV -D_MIYOO ARCH = arm BUILTIN_GPU = unai DYNAREC = ari64 diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 49d63eeb..30ded94d 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -228,15 +228,25 @@ static noinline void get_gpu_info(uint32_t data) // vram ptr received from mmap/malloc/alloc (will deallocate using this) static uint16_t *vram_ptr_orig = NULL; -#ifdef GPULIB_USE_MMAP +#ifndef GPULIB_USE_MMAP +# ifdef __linux__ +# define GPULIB_USE_MMAP 1 +# else +# define GPULIB_USE_MMAP 0 +# endif +#endif static int map_vram(void) { +#if GPULIB_USE_MMAP gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE + (VRAM_ALIGN-1)); - if (gpu.vram != NULL) { - // 4kb guard in front +#else + gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE + (VRAM_ALIGN-1), 1); +#endif + if (gpu.vram != NULL && gpu.vram != (void *)(intptr_t)-1) { + // 4kb guard in front gpu.vram += (4096 / 2); - // Align - gpu.vram = (uint16_t*)(((uintptr_t)gpu.vram + (VRAM_ALIGN-1)) & ~(VRAM_ALIGN-1)); + // Align + gpu.vram = (uint16_t*)(((uintptr_t)gpu.vram + (VRAM_ALIGN-1)) & ~(VRAM_ALIGN-1)); return 0; } else { @@ -244,54 +254,9 @@ static int map_vram(void) return -1; } } -#else -static int map_vram(void) -{ - gpu.vram = vram_ptr_orig = (uint16_t*)calloc(VRAM_SIZE + (VRAM_ALIGN-1), 1); - if (gpu.vram != NULL) { - // 4kb guard in front - gpu.vram += (4096 / 2); - // Align - gpu.vram = (uint16_t*)(((uintptr_t)gpu.vram + (VRAM_ALIGN-1)) & ~(VRAM_ALIGN-1)); - return 0; - } else { - fprintf(stderr, "could not allocate vram, expect crashes\n"); - return -1; - } -} - -static int allocate_vram(void) -{ - gpu.vram = vram_ptr_orig = (uint16_t*)calloc(VRAM_SIZE + (VRAM_ALIGN-1), 1); - if (gpu.vram != NULL) { - // 4kb guard in front - gpu.vram += (4096 / 2); - // Align - gpu.vram = (uint16_t*)(((uintptr_t)gpu.vram + (VRAM_ALIGN-1)) & ~(VRAM_ALIGN-1)); - return 0; - } else { - fprintf(stderr, "could not allocate vram, expect crashes\n"); - return -1; - } -} -#endif long GPUinit(void) { -#ifndef GPULIB_USE_MMAP - if (gpu.vram == NULL) { - if (allocate_vram() != 0) { - printf("ERROR: could not allocate VRAM, exiting..\n"); - exit(1); - } - } -#endif - - //extern uint32_t hSyncCount; // in psxcounters.cpp - //extern uint32_t frame_counter; // in psxcounters.cpp - //gpu.state.hcnt = &hSyncCount; - //gpu.state.frame_count = &frame_counter; - int ret; ret = vout_init(); ret |= renderer_init(); @@ -319,7 +284,7 @@ long GPUshutdown(void) ret = vout_finish(); if (vram_ptr_orig != NULL) { -#ifdef GPULIB_USE_MMAP +#if GPULIB_USE_MMAP gpu.munmap(vram_ptr_orig, VRAM_SIZE); #else free(vram_ptr_orig);