3ds: some random tuning

saves some memory
This commit is contained in:
notaz 2024-09-30 21:08:28 +03:00
parent 1cc933ce99
commit 29b549f7bf
4 changed files with 64 additions and 26 deletions

View File

@ -318,7 +318,8 @@ else ifeq ($(platform), ctr)
CFLAGS += -DARM11 -D_3DS -DNO_DYLIB -DGPU_UNAI_USE_FLOATMATH -DGPU_UNAI_USE_FLOAT_DIV_MULTINV
CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -marm -mfpu=vfp -mtp=soft
CFLAGS += -Wall -mword-relocations
CFLAGS += -fomit-frame-pointer -ffast-math -funroll-loops
CFLAGS += -fomit-frame-pointer
# CFLAGS += -funroll-loops # ~500K of bloat
CFLAGS += -Ifrontend/3ds -I$(CTRULIB)/include
CFLAGS += -Werror=implicit-function-declaration
CFLAGS += -DHAVE_UNISTD_H
@ -334,6 +335,7 @@ else ifeq ($(platform), ctr)
HAVE_NEON = 0
STATIC_LINKING = 1
NO_POSIX_MEMALIGN := 1
NO_MMAP := 1 # for psxmem
HAVE_PHYSICAL_CDROM = 0
# Xbox 360

View File

@ -6,10 +6,7 @@ extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <malloc.h>
#include "3ds_utils.h"
@ -22,6 +19,9 @@ extern "C" {
#define MAP_FAILED ((void *)-1)
void SysPrintf(const char *fmt, ...);
#if 0 // not used
static void* dynarec_cache = NULL;
static void* dynarec_cache_mapping = NULL;
@ -47,7 +47,7 @@ static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, of
}
svcDuplicateHandle(&currentHandle, 0xFFFF8001);
svcControlProcessMemory(currentHandle, addr, dynarec_cache,
svcControlProcessMemory(currentHandle, (uintptr_t)addr, (uintptr_t)dynarec_cache,
len, MEMOP_MAP, prot);
svcCloseHandle(currentHandle);
dynarec_cache_mapping = addr;
@ -70,22 +70,6 @@ static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, of
return addr_out;
}
static inline int mprotect(void *addr, size_t len, int prot)
{
if(__ctr_svchax)
{
uint32_t currentHandle;
svcDuplicateHandle(&currentHandle, 0xFFFF8001);
svcControlProcessMemory(currentHandle, addr, NULL,
len, MEMOP_PROT, prot);
svcCloseHandle(currentHandle);
return 0;
}
printf("mprotect called without svcControlProcessMemory access !\n");
return -1;
}
static inline int munmap(void *addr, size_t len)
{
if((addr == dynarec_cache_mapping) && __ctr_svchax)
@ -93,7 +77,7 @@ static inline int munmap(void *addr, size_t len)
uint32_t currentHandle;
svcDuplicateHandle(&currentHandle, 0xFFFF8001);
svcControlProcessMemory(currentHandle,
dynarec_cache, dynarec_cache_mapping,
(uintptr_t)dynarec_cache, (uintptr_t)dynarec_cache_mapping,
len, MEMOP_UNMAP, 0b111);
svcCloseHandle(currentHandle);
dynarec_cache_mapping = NULL;
@ -104,6 +88,29 @@ static inline int munmap(void *addr, size_t len)
return 0;
}
#endif
static inline int mprotect(void *addr, size_t len, int prot)
{
if (__ctr_svchax)
{
uint32_t currentHandle = 0;
int r;
svcDuplicateHandle(&currentHandle, 0xFFFF8001);
r = svcControlProcessMemory(currentHandle, (uintptr_t)addr, 0,
len, MEMOP_PROT, prot);
svcCloseHandle(currentHandle);
if (r < 0) {
SysPrintf("svcControlProcessMemory failed for %p %u %x: %d\n",
addr, len, prot, r);
return -1;
}
return 0;
}
SysPrintf("mprotect called without svcControlProcessMemory access!\n");
return -1;
}
#ifdef __cplusplus
};

View File

@ -179,7 +179,11 @@ static int negcon_linearity = 1;
static bool axis_bounds_modifier;
/* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
#ifdef GPU_NEON
#define VOUT_MAX_WIDTH 1024
#else
#define VOUT_MAX_WIDTH 640
#endif
#define VOUT_MAX_HEIGHT 512
//Dummy functions
@ -556,6 +560,21 @@ void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag)
}
#endif
static void log_mem_usage(void)
{
#ifdef _3DS
extern u32 __heap_size, __linear_heap_size, __stacksize__;
extern char __end__; // 3dsx.ld
u32 app_memory = *((volatile u32 *)0x1FF80040);
s64 mem_used = 0;
if (__ctr_svchax)
svcGetSystemInfo(&mem_used, 0, 1);
SysPrintf("mem: %d/%d heap: %d linear: %d stack: %d exe: %d\n", (int)mem_used, app_memory,
__heap_size, __linear_heap_size, __stacksize__, (int)&__end__ - 0x100000);
#endif
}
static void *pl_mmap(unsigned int size)
{
return psxMap(0, size, 0, MAP_TAG_VRAM);
@ -1954,8 +1973,7 @@ bool retro_load_game(const struct retro_game_info *info)
{
size_t i;
unsigned int cd_index = 0;
bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
bool is_exe = (strcasestr(info->path, ".exe") != NULL);
bool is_m3u, is_exe;
int ret;
struct retro_input_descriptor desc[] = {
@ -2015,6 +2033,8 @@ bool retro_load_game(const struct retro_game_info *info)
LogErr("info->path required\n");
return false;
}
is_m3u = (strcasestr(info->path, ".m3u") != NULL);
is_exe = (strcasestr(info->path, ".exe") != NULL);
update_variables(false);
@ -2192,6 +2212,7 @@ bool retro_load_game(const struct retro_game_info *info)
set_retro_memmap();
retro_set_audio_buff_status_cb();
log_mem_usage();
if (check_unsatisfied_libcrypt())
show_notification("LibCrypt protected game with missing SBI detected", 3000, 3);
@ -3729,6 +3750,8 @@ void retro_init(void)
struct retro_rumble_interface rumble;
int ret;
log_mem_usage();
msg_interface_version = 0;
environ_cb(RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION, &msg_interface_version);
@ -3766,12 +3789,17 @@ void retro_init(void)
vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && P_HAVE_POSIX_MEMALIGN
if (posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2) != 0)
vout_buf = (void *) 0;
vout_buf = NULL;
else
memset(vout_buf, 0, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
#else
vout_buf = calloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT, 2);
#endif
if (vout_buf == NULL)
{
LogErr("OOM for vout_buf.\n");
exit(1);
}
vout_buf_ptr = vout_buf;

View File

@ -39,7 +39,8 @@ extern "C" {
#define LE16TOH(x) (x)
#endif
#define BIT(x) (1 << (x))
#undef BIT
#define BIT(x) (1u << (x))
#define PSX_GPU_STATUS_DHEIGHT BIT(19)
#define PSX_GPU_STATUS_PAL BIT(20)