Merge branch 'cxx_impl'

Merge the new video code, which fixes many long-standing issues.
This also implements Video 4 effects and mosaic effect.
This commit is contained in:
David Guillen Fandos 2023-08-26 12:16:49 +02:00
commit ff4e1da1f3
9 changed files with 2375 additions and 4592 deletions

View File

@ -109,13 +109,10 @@ else ifeq ($(platform), osx)
ifeq ($(CROSS_COMPILE),1)
TARGET_RULE = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
CFLAGS += $(TARGET_RULE)
CPPFLAGS += $(TARGET_RULE)
CXXFLAGS += $(TARGET_RULE)
LDFLAGS += $(TARGET_RULE)
endif
CFLAGS += $(ARCHFLAGS)
CXXFLAGS += $(ARCHFLAGS)
LDFLAGS += $(ARCHFLAGS)
# iOS
@ -180,6 +177,7 @@ else ifeq ($(platform), qnx)
CPU_ARCH := arm
CC = qcc -Vgcc_ntoarmv7le
CXX = qcc -Vgcc_ntoarmv7le
AR = qcc -Vgcc_ntoarmv7le
CFLAGS += -D__BLACKBERRY_QNX_
HAVE_DYNAREC := 1
@ -188,6 +186,7 @@ else ifeq ($(platform), qnx)
else ifeq ($(platform), psl1ght)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
CXX = $(PS3DEV)/ppu/bin/ppu-g++$(EXE_EXT)
AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
CFLAGS += -DMSB_FIRST -D__ppc__
STATIC_LINKING = 1
@ -203,6 +202,7 @@ else ifeq ($(platform), switch)
else ifneq (,$(filter $(platform), ngc wii wiiu))
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
CFLAGS += -DGEKKO -mcpu=750 -meabi -mhard-float -DHAVE_STRTOF_L
STATIC_LINKING = 1
@ -211,6 +211,7 @@ else ifneq (,$(filter $(platform), ngc wii wiiu))
else ifeq ($(platform), psp1)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = psp-gcc$(EXE_EXT)
CXX = psp-g++$(EXE_EXT)
AR = psp-ar$(EXE_EXT)
CFLAGS += -DPSP -G0 -DUSE_BGR_FORMAT -DMIPS_HAS_R2_INSTS -DSMALL_TRANSLATION_CACHE
CFLAGS += -I$(shell psp-config --pspsdk-path)/include
@ -225,6 +226,7 @@ else ifeq ($(platform), psp1)
else ifeq ($(platform), vita)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = arm-vita-eabi-gcc$(EXE_EXT)
CXX = arm-vita-eabi-g++$(EXE_EXT)
AR = arm-vita-eabi-ar$(EXE_EXT)
CFLAGS += -DVITA -DOVERCLOCK_60FPS
CFLAGS += -marm -mcpu=cortex-a9 -mfloat-abi=hard
@ -247,7 +249,6 @@ else ifeq ($(platform), ctr)
CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard
CFLAGS += -Wall -mword-relocations
CFLAGS += -fomit-frame-pointer -ffast-math
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CPU_ARCH := arm
HAVE_DYNAREC = 1
STATIC_LINKING = 1
@ -259,7 +260,6 @@ else ifeq ($(platform), rpi3)
SHARED := -shared -Wl,--version-script=link.T -Wl,--no-undefined
CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
CFLAGS += -fomit-frame-pointer -ffast-math
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CPU_ARCH := arm
MMAP_JIT_CACHE = 1
HAVE_DYNAREC = 1
@ -271,7 +271,6 @@ else ifeq ($(platform), rpi2)
SHARED := -shared -Wl,--version-script=link.T -Wl,--no-undefined
CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
CFLAGS += -fomit-frame-pointer -ffast-math
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CPU_ARCH := arm
MMAP_JIT_CACHE = 1
HAVE_DYNAREC = 1
@ -284,7 +283,6 @@ else ifeq ($(platform), rpi1)
CFLAGS += -DARM11
CFLAGS += -marm -mfpu=vfp -mfloat-abi=hard -march=armv6j
CFLAGS += -fomit-frame-pointer -ffast-math
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
CPU_ARCH := arm
MMAP_JIT_CACHE = 1
HAVE_DYNAREC = 1
@ -307,8 +305,6 @@ else ifeq ($(platform), classic_armv7_a7)
-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
-fmerge-all-constants -fno-math-errno \
-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
CXXFLAGS = $(CFLAGS) -std=gnu++11
CPPFLAGS += $(CFLAGS)
ASFLAGS += $(CFLAGS)
HAVE_NEON = 1
ARCH = arm
@ -331,6 +327,7 @@ else ifeq ($(platform), classic_armv7_a7)
else ifeq ($(platform), xenon)
TARGET := $(TARGET_NAME)_libretro_xenon360.a
CC = xenon-gcc$(EXE_EXT)
CXX = xenon-g++$(EXE_EXT)
AR = xenon-ar$(EXE_EXT)
CFLAGS += -D__LIBXENON__ -m32 -D__ppc__
STATIC_LINKING = 1
@ -339,6 +336,7 @@ else ifeq ($(platform), xenon)
else ifeq ($(platform), ngc)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -DMSB_FIRST -D__ppc__
STATIC_LINKING = 1
@ -347,6 +345,7 @@ else ifeq ($(platform), ngc)
else ifeq ($(platform), wii)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -DMSB_FIRST -D__ppc__
STATIC_LINKING = 1
@ -420,6 +419,7 @@ else ifeq ($(platform), mips64n32)
else ifeq ($(platform), ps2)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = mips64r5900el-ps2-elf-gcc$(EXE_EXT)
CXX = mips64r5900el-ps2-elf-g++$(EXE_EXT)
AR = mips64r5900el-ps2-elf-ar$(EXE_EXT)
CFLAGS += -fomit-frame-pointer -ffast-math
CFLAGS += -DPS2 -DUSE_XBGR1555_FORMAT -DSMALL_TRANSLATION_CACHE -DROM_BUFFER_SIZE=16
@ -488,6 +488,7 @@ else ifeq ($(platform), miyoo)
else
TARGET := $(TARGET_NAME)_libretro.dll
CC ?= gcc
CXX ?= g++
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=link.T
CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__
@ -528,7 +529,7 @@ endif
include Makefile.common
OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_ASM:.S=.o)
OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_ASM:.S=.o) $(SOURCES_CC:.cc=.o)
WARNINGS_DEFINES =
CODE_DEFINES =
@ -555,15 +556,18 @@ CFLAGS += -I$(CTRULIB)/include
endif
endif
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11
ifeq ($(platform), theos_ios)
COMMON_FLAGS := -DIOS $(COMMON_DEFINES) $(INCFLAGS) -I$(THEOS_INCLUDE_PATH) -Wno-error
$(LIBRARY_NAME)_CFLAGS += $(COMMON_FLAGS) $(CFLAGS)
${LIBRARY_NAME}_FILES = $(SOURCES_C) $(SOURCES_ASM)
${LIBRARY_NAME}_FILES = $(SOURCES_C) $(SOURCES_ASM) $(SOURCES_CC)
include $(THEOS_MAKE_PATH)/library.mk
else
all: $(TARGET)
# Linking with gcc on purpose, we do not use any libstdc++ dependencies at all, only libc is required.
$(TARGET): $(OBJECTS)
ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJECTS)
@ -580,7 +584,7 @@ cpu_threaded.o: cpu_threaded.c
%.o: %.c
$(CC) $(INCFLAGS) $(CFLAGS) $(OPTIMIZE) -c -o $@ $<
%.o: %.cpp
%.o: %.cc
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(OPTIMIZE) -c -o $@ $<
clean-objs:

View File

@ -4,11 +4,12 @@ INCFLAGS := -I$(CORE_DIR)/libretro -I$(LIBRETRO_COMM_DIR)/include -I$(CORE_DI
SOURCES_ASM := $(CORE_DIR)/bios_data.S
SOURCES_CC := $(CORE_DIR)/video.cc
SOURCES_C := $(CORE_DIR)/main.c \
$(CORE_DIR)/cpu.c \
$(CORE_DIR)/gba_memory.c \
$(CORE_DIR)/savestate.c \
$(CORE_DIR)/video.c \
$(CORE_DIR)/input.c \
$(CORE_DIR)/sound.c \
$(CORE_DIR)/cheats.c \

View File

@ -93,6 +93,11 @@
#define GBA_SCREEN_HEIGHT (160)
#define GBA_SCREEN_PITCH (240)
// The buffer is 16 bit color depth.
// We reserve extra memory at the end for extra effects (winobj rendering).
#define GBA_SCREEN_BUFFER_SIZE \
(GBA_SCREEN_PITCH * (GBA_SCREEN_HEIGHT + 1) * sizeof(uint16_t))
typedef u32 fixed16_16;
typedef u32 fixed8_24;

View File

@ -106,6 +106,7 @@ typedef enum
REG_WIN1V = 0x23,
REG_WININ = 0x24,
REG_WINOUT = 0x25,
REG_MOSAIC = 0x26,
REG_BLDCNT = 0x28,
REG_BLDALPHA = 0x29,
REG_BLDY = 0x2A,
@ -171,7 +172,16 @@ typedef enum
REG_HALTCNT = 0x180
} hardware_register;
#define REG_BGxCNT(n) (REG_BG0CNT + (n))
// Some useful macros to avoid reg math
#define REG_BGxCNT(n) (REG_BG0CNT + (n))
#define REG_WINxH(n) (REG_WIN0H + (n))
#define REG_WINxV(n) (REG_WIN0V + (n))
#define REG_BGxHOFS(n) (REG_BG0HOFS + ((n) * 2))
#define REG_BGxVOFS(n) (REG_BG0VOFS + ((n) * 2))
#define REG_BGxPA(n) (REG_BG2PA + ((n)-2)*8)
#define REG_BGxPB(n) (REG_BG2PB + ((n)-2)*8)
#define REG_BGxPC(n) (REG_BG2PC + ((n)-2)*8)
#define REG_BGxPD(n) (REG_BG2PD + ((n)-2)*8)
#define FLASH_DEVICE_UNDEFINED 0x00
#define FLASH_DEVICE_MACRONIX_64KB 0x1C

View File

@ -37,12 +37,14 @@ ifneq ($(GIT_VERSION)," unknown")
COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
# We do not use the stdlib++ on purpose, disable it to reduce dependencies.
include $(CLEAR_VARS)
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_MODULE := retro
LOCAL_SRC_FILES := $(SOURCES_C) $(SOURCES_ASM)
LOCAL_SRC_FILES := $(SOURCES_C) $(SOURCES_ASM) $(SOURCES_CC)
LOCAL_CFLAGS := $(COREFLAGS) $(INCFLAGS)
LOCAL_LDFLAGS := -Wl,-version-script=$(CORE_DIR)/link.T
LOCAL_LDFLAGS := -Wl,-version-script=$(CORE_DIR)/link.T -nostdlib++
LOCAL_LDLIBS := $(CORE_LDLIBS)
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)

View File

@ -303,8 +303,6 @@ static void video_post_process_cc_mix(void)
static void init_post_processing(void)
{
size_t buf_size = GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT * sizeof(u16);
video_post_process = NULL;
/* If post processing is disabled, return
@ -317,27 +315,27 @@ static void init_post_processing(void)
(post_process_cc || post_process_mix))
{
#ifdef _3DS
gba_processed_pixels = (u16*)linearMemAlign(buf_size, 128);
gba_processed_pixels = (u16*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
#else
gba_processed_pixels = (u16*)malloc(buf_size);
gba_processed_pixels = (u16*)malloc(GBA_SCREEN_BUFFER_SIZE);
#endif
if (!gba_processed_pixels)
return;
memset(gba_processed_pixels, 0xFFFF, buf_size);
memset(gba_processed_pixels, 0xFFFF, GBA_SCREEN_BUFFER_SIZE);
}
/* Initialise 'history' buffer, if required */
if (!gba_screen_pixels_prev &&
post_process_mix)
{
gba_screen_pixels_prev = (u16*)malloc(buf_size);
gba_screen_pixels_prev = (u16*)malloc(GBA_SCREEN_BUFFER_SIZE);
if (!gba_screen_pixels_prev)
return;
memset(gba_screen_pixels_prev, 0xFFFF, buf_size);
memset(gba_screen_pixels_prev, 0xFFFF, GBA_SCREEN_BUFFER_SIZE);
}
/* Assign post processing function */
@ -570,9 +568,9 @@ void retro_init(void)
if(!gba_screen_pixels)
#ifdef _3DS
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT * sizeof(uint16_t), 128);
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
#else
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT * sizeof(uint16_t));
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_BUFFER_SIZE);
#endif
libretro_supports_bitmasks = false;

4540
video.c

File diff suppressed because it is too large Load Diff

2330
video.cc Normal file

File diff suppressed because it is too large Load Diff

27
video.h
View File

@ -26,33 +26,6 @@ void video_reload_counters(void);
extern s32 affine_reference_x[2];
extern s32 affine_reference_y[2];
typedef void (* tile_render_function)(u32 layer_number, u32 start, u32 end,
void *dest_ptr);
typedef void (* bitmap_render_function)(u32 start, u32 end, void *dest_ptr);
typedef struct
{
tile_render_function normal_render_base;
tile_render_function normal_render_transparent;
tile_render_function alpha_render_base;
tile_render_function alpha_render_transparent;
tile_render_function color16_render_base;
tile_render_function color16_render_transparent;
tile_render_function color32_render_base;
tile_render_function color32_render_transparent;
} tile_layer_render_struct;
typedef struct
{
bitmap_render_function normal_render;
} bitmap_layer_render_struct;
typedef enum
{
filter_nearest,
filter_bilinear
} video_filter_type;
extern u16* gba_screen_pixels;
#endif