From 6f2ee2becb1eb33cac685594f13468cef4d09684 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 19 Nov 2011 22:25:59 +0200 Subject: [PATCH] gpu_neon: support unai as rendering backend --- plugins/gpu_neon/Makefile | 33 +++-- plugins/gpu_neon/gpu.h | 8 ++ plugins/gpu_neon/unai_if.cpp | 252 +++++++++++++++++++++++++++++++++++ plugins/gpu_neon/vout_fb.c | 5 +- plugins/gpu_neon/vout_sdl.c | 2 +- 5 files changed, 283 insertions(+), 17 deletions(-) create mode 100644 plugins/gpu_neon/unai_if.cpp diff --git a/plugins/gpu_neon/Makefile b/plugins/gpu_neon/Makefile index adb50970..07787546 100644 --- a/plugins/gpu_neon/Makefile +++ b/plugins/gpu_neon/Makefile @@ -1,33 +1,38 @@ CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ +CC_ = $(CC) ARCH = $(shell $(CC) -v 2>&1 | grep -i 'target:' | awk '{print $$2}' | awk -F '-' '{print $$1}') CFLAGS += -ggdb -Wall -fPIC -O2 CFLAGS += -fno-strict-aliasing -LDFLAGS += -shared -Wl,-soname,$(TARGET) SRC += gpu.c ifeq "$(ARCH)" "arm" -TARGET = gpu_neon.so CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp SRC += vout_fb.c ../../frontend/cspace_neon.s -else -TARGET = gpu_neon.so.x86 +EXT = so +endif +ifeq "$(ARCH)" "x86_64" CFLAGS += `sdl-config --cflags` -m32 LDFLAGS += `sdl-config --libs` SRC += vout_sdl.c +EXT = so.x86 endif -PEOPS=1 -ifndef PEOPS -SRC += psx_gpu_if.c -else -SRC += peops_if.c -endif -all: $(TARGET) +TARGETS = gpu_neon.$(EXT) gpu_peops.$(EXT) gpu_unai.$(EXT) + +gpu_neon.$(EXT): SRC += psx_gpu_if.c +gpu_neon.$(EXT): CFLAGS += -fno-strict-aliasing +gpu_peops.$(EXT): SRC += peops_if.c +gpu_peops.$(EXT): CFLAGS += -fno-strict-aliasing +gpu_unai.$(EXT): SRC += unai_if.cpp +gpu_unai.$(EXT): CC_ = $(CXX) + +all: $(TARGETS) -$(TARGET): $(SRC) - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) +$(TARGETS): $(SRC) + $(CC_) -o $@ $(SRC) $(CFLAGS) $(LDFLAGS) -shared -Wl,-soname,$@ clean: - $(RM) $(TARGET) + $(RM) $(TARGETS) diff --git a/plugins/gpu_neon/gpu.h b/plugins/gpu_neon/gpu.h index 04f69ab8..c3e13bb2 100644 --- a/plugins/gpu_neon/gpu.h +++ b/plugins/gpu_neon/gpu.h @@ -10,6 +10,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define CMD_BUFFER_LEN 1024 struct psx_gpu { @@ -92,3 +96,7 @@ void renderer_flush_queues(void); int vout_init(void); int vout_finish(void); + +#ifdef __cplusplus +} +#endif diff --git a/plugins/gpu_neon/unai_if.cpp b/plugins/gpu_neon/unai_if.cpp new file mode 100644 index 00000000..2b524d92 --- /dev/null +++ b/plugins/gpu_neon/unai_if.cpp @@ -0,0 +1,252 @@ +/*************************************************************************** +* Copyright (C) 2010 PCSX4ALL Team * +* Copyright (C) 2010 Unai * +* Copyright (C) 2011 notaz * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. * +***************************************************************************/ + +#include +#include +#include +#include "gpu.h" + +#define u8 uint8_t +#define s8 int8_t +#define u16 uint16_t +#define s16 int16_t +#define u32 uint32_t +#define s32 int32_t +#define s64 int64_t + +#define INLINE + +#define FRAME_BUFFER_SIZE (1024*512*2) +#define FRAME_WIDTH 1024 +#define FRAME_HEIGHT 512 +#define FRAME_OFFSET(x,y) (((y)<<10)+(x)) + +//#define VIDEO_WIDTH 320 + +static bool isSkip = false; /* skip frame (info coming from GPU) */ +static int linesInterlace = 0; /* internal lines interlace */ + +#define alt_fps 0 + +static bool light = true; /* lighting */ +static bool blend = true; /* blending */ +static bool FrameToRead = false; /* load image in progress */ +static bool FrameToWrite = false; /* store image in progress */ + +static bool enableAbbeyHack = false; /* Abe's Odyssey hack */ + +static u8 BLEND_MODE; +static u8 TEXT_MODE; +static u8 Masking; + +static u16 PixelMSB; +static u16 PixelData; + +/////////////////////////////////////////////////////////////////////////////// +// GPU Global data +/////////////////////////////////////////////////////////////////////////////// + +// Dma Transfers info +static s32 px,py; +static s32 x_end,y_end; +static u16* pvram; + +static s32 PacketCount; +static s32 PacketIndex; + +// Rasterizer status +static u32 TextureWindow [4]; +static u32 DrawingArea [4]; +static u32 DrawingOffset [2]; + +static u16* TBA; +static u16* CBA; + +// Inner Loops +static s32 u4, du4; +static s32 v4, dv4; +static s32 r4, dr4; +static s32 g4, dg4; +static s32 b4, db4; +static u32 lInc; +static u32 tInc, tMsk; + +union GPUPacket +{ + u32 *U4; + s32 *S4; + u16 *U2; + s16 *S2; + u8 *U1; + s8 *S1; +}; + +static GPUPacket PacketBuffer; +static u16 *GPU_FrameBuffer; +static u32 GPU_GP1; + +/////////////////////////////////////////////////////////////////////////////// + +#include "../gpu_unai/gpu_fixedpoint.h" + +// Inner loop driver instanciation file +#include "../gpu_unai/gpu_inner.h" + +// GPU Raster Macros +#define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3)) + +#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20) +//#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21) +#define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21) + +//#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; } +#define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; } + +#define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);} + +// GPU internal image drawing functions +#include "../gpu_unai/gpu_raster_image.h" + +// GPU internal line drawing functions +#include "../gpu_unai/gpu_raster_line.h" + +// GPU internal polygon drawing functions +#include "../gpu_unai/gpu_raster_polygon.h" + +// GPU internal sprite drawing functions +#include "../gpu_unai/gpu_raster_sprite.h" + +// GPU command buffer execution/store +#include "../gpu_unai/gpu_command.h" + +#define unai_do_prim(cmd, list) \ + PacketBuffer.U4 = list; \ + gpuSendPacketFunction(cmd) + +///////////////////////////////////////////////////////////////////////////// + +int renderer_init(void) +{ + GPU_FrameBuffer = (u16 *)gpu.vram; + + // s_invTable + for(int i=1;i<=(1<>1); + #else + v *= double(0x80000000); + #endif + s_invTable[i-1]=s32(v); + } + + return 0; +} + +extern const unsigned char cmd_lengths[256]; + +void do_cmd_list(unsigned int *list, int list_len) +{ + unsigned int cmd, len; + + unsigned int *list_end = list + list_len; + + for (; list < list_end; list += 1 + len) + { + short *slist = (short *)list; + cmd = *list >> 24; + len = cmd_lengths[cmd]; + + unai_do_prim(cmd, list); + + switch(cmd) + { + case 0x48 ... 0x4F: + { + u32 num_vertexes = 1; + u32 *list_position = &(list[2]); + + while(1) + { + if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end) + break; + + list_position++; + num_vertexes++; + } + + if(num_vertexes > 2) + len += (num_vertexes - 2); + + break; + } + + case 0x58 ... 0x5F: + { + u32 num_vertexes = 1; + u32 *list_position = &(list[2]); + + while(1) + { + if((*list_position & 0xf000f000) == 0x50005000 || list_position >= list_end) + break; + + list_position += 2; + num_vertexes++; + } + + if(num_vertexes > 2) + len += ((num_vertexes * 2) - 2); + + break; + } + + case 0xA0: // sys -> vid + { + u32 load_width = slist[4]; + u32 load_height = slist[5]; + u32 load_size = load_width * load_height; + + len += load_size / 2; + break; + } + } + } +} + +void renderer_sync_ecmds(uint32_t *ecmds) +{ + unai_do_prim(0xe1, &ecmds[1]); + unai_do_prim(0xe2, &ecmds[2]); + unai_do_prim(0xe3, &ecmds[3]); + unai_do_prim(0xe4, &ecmds[4]); + unai_do_prim(0xe5, &ecmds[5]); + unai_do_prim(0xe6, &ecmds[6]); +} + +void renderer_invalidate_caches(int x, int y, int w, int h) +{ +} + +void renderer_flush_queues(void) +{ +} diff --git a/plugins/gpu_neon/vout_fb.c b/plugins/gpu_neon/vout_fb.c index 5b54bd1c..7da4ae26 100644 --- a/plugins/gpu_neon/vout_fb.c +++ b/plugins/gpu_neon/vout_fb.c @@ -27,7 +27,8 @@ int vout_finish(void) static void blit(void) { - static uint32_t old_status, old_h; + static uint32_t old_status; + static int old_h; int x = gpu.screen.x & ~1; // alignment needed by blitter int y = gpu.screen.y; int w = gpu.screen.w; @@ -46,7 +47,7 @@ static void blit(void) screen_buf = cbs->pl_vout_set_mode(stride, h, gpu.status.rgb24 ? 24 : 16); } - dest = screen_buf; + dest = (uint8_t *)screen_buf; // only do centering, at least for now doffs = (stride - w) / 2 & ~1; diff --git a/plugins/gpu_neon/vout_sdl.c b/plugins/gpu_neon/vout_sdl.c index 3152c321..ad3931fa 100644 --- a/plugins/gpu_neon/vout_sdl.c +++ b/plugins/gpu_neon/vout_sdl.c @@ -68,7 +68,7 @@ static void blit(void) else { uint16_t *s = gpu.vram; - d = screen->pixels; + d = (uint32_t *)screen->pixels; for (i = 0; i < 1024 * 512; i++) d[i] = (((uint32_t)s[i] << 19) & 0xf80000) | ((s[i] << 6) & 0xf800) | ((s[i] >> 7) & 0xf8); -- 2.39.5