Permalink
Browse files

Merge pull request #89 from m4xw/dynarec_nx

Libnx Initial dynarec support, potential black textures fix, depth shader improvements
  • Loading branch information...
m4xw committed Jan 8, 2019
2 parents d799342 + c691ad6 commit 501d2987be8ee7a58186581597e1a64175f82bad
@@ -28,11 +28,17 @@ void Config::resetToDefaults()

texture.maxAnisotropy = 0;
texture.bilinearMode = BILINEAR_STANDARD;
texture.maxBytes = 500 * gc_uMegabyte;
texture.screenShotFormat = 0;

#ifndef HAVE_LIBNX
texture.maxBytes = 500 * gc_uMegabyte;
generalEmulation.enableLOD = 1;
generalEmulation.enableNoise = 1;
#else
texture.maxBytes = 1500 * gc_uMegabyte;
generalEmulation.enableLOD = 0;
generalEmulation.enableNoise = 0;
#endif
generalEmulation.enableHWLighting = 0;
generalEmulation.enableCustomSettings = 1;
generalEmulation.enableShadersStorage = 1;
@@ -567,15 +567,15 @@ static const char* depth_compare_shader_float =
#else
"layout(binding = 2, rgba32f) highp uniform coherent image2D uDepthImage;\n"
#endif
//"uniform int uEnableDepth; \n"
"uniform int uEnableDepth; \n"
"uniform lowp int uDepthMode; \n"
"uniform lowp int uDepthSource; \n"
"uniform lowp int uEnableDepthCompare; \n"
"uniform lowp int uEnableDepthUpdate; \n"
"uniform mediump float uDeltaZ; \n"
"bool depth_compare() \n"
"{ \n"
//" if (uEnableDepth == 0) return true; \n"
" if (uEnableDepth == 0) return true; \n"
" ivec2 coord = ivec2(gl_FragCoord.xy); \n"
" highp vec4 depth = imageLoad(uDepthImage,coord); \n"
" highp float bufZ = depth.r; \n"
@@ -528,6 +528,8 @@ void TextureCache::_checkCacheSize()
{
#if defined(VC) || defined(CLASSIC)
const size_t maxCacheSize = 15000;
#elif defined(HAVE_LIBNX)
const size_t maxCacheSize = 4500;
#else
const size_t maxCacheSize = 16384;
#endif
@@ -159,17 +159,15 @@ else ifeq ($(platform), classic_armv7_a7)
# Nintendo Switch
else ifeq ($(platform), libnx)
include $(DEVKITPRO)/libnx/switch_rules
PIC = 1
PIC ?= 1
WITH_DYNAREC := aarch64
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CPUOPTS := -g -march=armv8-a -mtune=cortex-a57 -mtp=soft -mcpu=cortex-a57+crc+fp+simd
PLATCFLAGS = -O3 -ffast-math -funsafe-math-optimizations -fPIE -I$(PORTLIBS)/include/ -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec -specs=$(LIBNX)/switch.specs
PLATCFLAGS = -O3 -I$(PORTLIBS)/include/ -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec -specs=$(LIBNX)/switch.specs
PLATCFLAGS += $(INCLUDE) -D__SWITCH__=1 -DSWITCH -DHAVE_LIBNX -D_GLIBCXX_USE_C99_MATH_TR1 -D_LDBL_EQ_DBL -funroll-loops
SOURCES_C += $(CORE_DIR)/src/r4300/empty_dynarec.c
CXXFLAGS += -fno-rtti -std=gnu++11
COREFLAGS += -DOS_LINUX
COREFLAGS += -DOS_LINUX -DUSE_DEPTH_RENDERBUFFER
GLES = 0
WITH_DYNAREC =
DYNAREC_USED = 0
STATIC_LINKING = 1

# ODROIDs
@@ -6,6 +6,10 @@
#include "libretro_private.h"
#include "GLideN64_libretro.h"

#ifdef HAVE_LIBNX
#include <switch.h>
#endif

#include <libco.h>

#include <glsm/glsmsym.h>
@@ -128,7 +132,11 @@ static void setup_variables(void)
struct retro_variable variables[] = {
{ "mupen64plus-cpucore",
#ifdef DYNAREC
#ifdef HAVE_LIBNX
"CPU Core; cached_interpreter|pure_interpreter|dynamic_recompiler" },
#else
"CPU Core; dynamic_recompiler|cached_interpreter|pure_interpreter" },
#endif
#else
"CPU Core; cached_interpreter|pure_interpreter" },
#endif
@@ -893,8 +901,26 @@ bool retro_load_game(const struct retro_game_info *game)
return true;
}

#ifdef HAVE_LIBNX
extern Jit dynarec_jit;
extern void *jit_rw_buffer;
extern void *jit_old_addr;
#endif
void retro_unload_game(void)
{
#if defined(HAVE_LIBNX) && defined(DYNAREC)
jitTransitionToWritable(&dynarec_jit);
if(jit_old_addr != 0)
dynarec_jit.rx_addr = jit_old_addr;
jit_old_addr = 0;
jitClose(&dynarec_jit);

if(jit_rw_buffer != 0)
free(jit_rw_buffer);

jit_rw_buffer = 0;
#endif

CoreDoCommand(M64CMD_ROM_CLOSE, 0, NULL);
emu_initialized = false;
}
@@ -40,6 +40,7 @@ typedef enum {
static void *dynamic_linker(void * src, u_int vaddr);
static void *dynamic_linker_ds(void * src, u_int vaddr);
static void invalidate_addr(u_int addr);
static void emit_read_ptr(intptr_t addr, int rt);

static unsigned int needs_clear_cache[1<<(TARGET_SIZE_2-17)];

@@ -315,6 +316,7 @@ static void *dynamic_linker(void * src, u_int vaddr)
int *ptr=(int*)src;
assert(((*ptr&0xfc000000)==0x14000000)||((*ptr&0xff000000)==0x54000000)); //b or b.cond
//TOBEDONE: Avoid disabling link between blocks for conditional branches
#ifndef HAVE_LIBNX
if((*ptr&0xfc000000)==0x14000000) { //b
int offset=((signed int)(*ptr<<6)>>6)<<2;
u_int *ptr2=(u_int*)((intptr_t)ptr+offset);
@@ -327,6 +329,7 @@ static void *dynamic_linker(void * src, u_int vaddr)
set_jump_target((intptr_t)ptr, (uintptr_t)head->addr);
__clear_cache((void*)ptr, (void*)((uintptr_t)ptr+4));
}
#endif
#ifdef NEW_DYNAREC_DEBUG
print_debug_info(vaddr);
#endif
@@ -389,7 +392,10 @@ static void *dynamic_linker(void * src, u_int vaddr)
}

int r=new_recompile_block(vaddr);
if(r==0) return dynamic_linker(src, vaddr);
if(r==0) {
void* link_res = dynamic_linker(src, vaddr);
return link_res;
}
// Execute in unmapped page, generate pagefault exception
g_cp0_regs[CP0_STATUS_REG]|=2;
g_cp0_regs[CP0_CAUSE_REG]=0x8;
@@ -2424,18 +2430,19 @@ static void emit_set_if_carry64_32(int u1, int l1, int u2, int l2, int rt)
emit_cmovb_imm(1,rt);
}

static void emit_call(intptr_t a)
static void emit_jmp(intptr_t a)
{
assem_debug("bl %x (%x+%x)",a,(intptr_t)out,a-(intptr_t)out);
u_int offset=genjmp(a);
output_w32(0x94000000|offset);
assem_debug("b %x (%x+%x)",a,(intptr_t)out,a-(intptr_t)out);
u_int off=genjmp(a);
output_w32(0x14000000|off);
}

static void emit_jmp(intptr_t a)
static void emit_call(intptr_t a)
{
assem_debug("b %x (%x+%x)",a,(intptr_t)out,a-(intptr_t)out);
u_int offset=genjmp(a);
output_w32(0x14000000|offset);
intptr_t offset=a-(intptr_t)out;
assem_debug("bl %x (%x+%x)",a,(intptr_t)out,a-(intptr_t)out);
u_int off=genjmp(a);
output_w32(0x94000000|off);
}

static void emit_jne(intptr_t a)
@@ -3455,15 +3462,15 @@ static void emit_adr(intptr_t addr, int rt)

static void emit_read_ptr(intptr_t addr, int rt)
{
int offset=addr-(intptr_t)out;
intptr_t offset=addr-(intptr_t)out;
if(offset>=-1048576&&offset<1048576){
assem_debug("adr %d,#%d",regname64[rt],offset);
assem_debug("adr %s,#%d",regname64[rt],offset);
output_w32(0x10000000|((u_int)offset&0x3)<<29|(((u_int)offset>>2)&0x7ffff)<<5|rt);
}
else{
offset=((addr&(intptr_t)~0xfff)-((intptr_t)out&(intptr_t)~0xfff))>>12;
assert((((intptr_t)out&(intptr_t)~0xfff)+(offset<<12))==(addr&(intptr_t)~0xfff));
assem_debug("adrp %d,#%d",regname64[rt],offset);
assem_debug("adrp %s,#%d",regname64[rt],offset);
output_w32(0x90000000|((u_int)offset&0x3)<<29|(((u_int)offset>>2)&0x7ffff)<<5|rt);
if((addr&(intptr_t)0xfff)!=0)
assem_debug("add %s, %s, #%d",regname64[rt],regname64[rt],addr&0xfff);
@@ -6686,7 +6693,9 @@ static void do_clear_cache(void)
end+=4096;
j++;
}else{
#ifndef HAVE_LIBNX
__clear_cache((char *)start,(char *)end);
#endif
//cacheflush((void *)start,(void *)end,0);
break;
}
Oops, something went wrong.

0 comments on commit 501d298

Please sign in to comment.