Merge pull request #10968 from libretro/vitashark

[VITA] Add support for provided runtime shader compiler
This commit is contained in:
Francisco José García García 2020-07-05 12:16:36 +02:00 committed by GitHub
commit 1af9fb9247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 2086 additions and 486 deletions

View File

@ -2158,8 +2158,14 @@ ifeq ($(HAVE_MATH_NEON), 1)
endif endif
ifeq ($(HAVE_VITAGL), 1) ifeq ($(HAVE_VITAGL), 1)
DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING INCLUDE_DIRS += -I$(DEPS_DIR)/vitaShaRK/source
INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source SOURCES := $(DEPS_DIR)/vitaShaRK/source
OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif
ifeq ($(HAVE_VITAGL), 1)
DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING -DHAVE_SHARK
INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source -I$(DEPS_DIR)/vitaShaRK/include
SOURCES := $(DEPS_DIR)/vitaGL/source $(DEPS_DIR)/vitaGL/source/utils SOURCES := $(DEPS_DIR)/vitaGL/source $(DEPS_DIR)/vitaGL/source/utils
OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))) OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)))
endif endif

View File

@ -132,7 +132,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
VITA_LIBS := -lSceDisplay_stub -lSceGxm_stub -lSceNet_stub -lSceNetCtl_stub -lSceAppUtil_stub \ VITA_LIBS := -lSceDisplay_stub -lSceGxm_stub -lSceNet_stub -lSceNetCtl_stub -lSceAppUtil_stub \
-lSceSysmodule_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub -lSceAudio_stub \ -lSceSysmodule_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub -lSceAudio_stub \
-lScePower_stub -lSceRtc_stub -lSceCommonDialog_stub -lScePgf_stub -lSceMotion_stub \ -lScePower_stub -lSceRtc_stub -lSceCommonDialog_stub -lScePgf_stub -lSceMotion_stub \
-lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz -lSceFiber_stub -lSceMotion_stub -lSceAppMgr_stub -lstdc++ -lpthread -lpng -lz -lSceShaccCg_stub
LIBS := $(WHOLE_START) -lretro_vita $(WHOLE_END) $(VITA_LIBS) -lm -lc LIBS := $(WHOLE_START) -lretro_vita $(WHOLE_END) $(VITA_LIBS) -lm -lc
@ -165,7 +165,13 @@ all: $(TARGETS)
%.depend: ; %.depend: ;
$(TARGET).elf: $(OBJ) libretro_vita.a libSceShaccCg_stub.a:
mkdir -p deps/vitaShaRK/SceShaccCg
vita-libs-gen deps/vitaShaRK/SceShaccCg.yml deps/vitaShaRK/SceShaccCg
make -C deps/vitaShaRK/SceShaccCg ARCH=arm-vita-eabi
cp deps/vitaShaRK/SceShaccCg/libSceShaccCg_stub.a .
$(TARGET).elf: $(OBJ) libretro_vita.a libSceShaccCg_stub.a
$(LD) $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ $(LD) $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@
%.velf: %.elf %.velf: %.elf
@ -181,7 +187,7 @@ $(TARGET).elf: $(OBJ) libretro_vita.a
vita-pack-vpk -s param.sfo -b $< $@ vita-pack-vpk -s param.sfo -b $< $@
clean: clean:
rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk rm -f $(OBJ) $(TARGET).elf $(TARGET).elf.unstripped.elf $(TARGET).velf $(TARGET).self param.sfo $(TARGET).vpk libSceShaccCg_stub.a deps/vitaShaRK/SceShaccCg
rm -f $(OBJ:.o=.depend) rm -f $(OBJ:.o=.depend)
# Useful for developers # Useful for developers

1
deps/vitaGL/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
patreon: Rinnegatamante

12
deps/vitaGL/Makefile vendored
View File

@ -7,20 +7,25 @@ SOURCES += source/hacks
endif endif
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
ASMFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S))
CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg)) CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg))
HEADERS := $(CGFILES:.cg=.h) HEADERS := $(CGFILES:.cg=.h)
OBJS := $(CFILES:.c=.o) OBJS := $(CFILES:.c=.o) $(ASMFILES:.S=.o)
PREFIX = arm-vita-eabi PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc CC = $(PREFIX)-gcc
AR = $(PREFIX)-gcc-ar AR = $(PREFIX)-gcc-ar
CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -flto -ftree-vectorize -DSTB_DXT_IMPLEMENTATION CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -ftree-vectorize -DSTB_DXT_IMPLEMENTATION
ASFLAGS = $(CFLAGS) ASFLAGS = $(CFLAGS)
ifeq ($(NO_DEBUG),1) ifeq ($(NO_DEBUG),1)
CFLAGS += -DSKIP_ERROR_HANDLING CFLAGS += -DSKIP_ERROR_HANDLING
endif endif
ifeq ($(HAVE_SHARK),1)
CFLAGS += -DHAVE_SHARK
endif
all: $(TARGET).a all: $(TARGET).a
$(TARGET).a: $(OBJS) $(TARGET).a: $(OBJS)
@ -47,6 +52,7 @@ clean:
@make -C samples/sample5 clean @make -C samples/sample5 clean
@make -C samples/sample6 clean @make -C samples/sample6 clean
@make -C samples/sample7 clean @make -C samples/sample7 clean
@make -C samples/sample8 clean
install: $(TARGET).a install: $(TARGET).a
@mkdir -p $(VITASDK)/$(PREFIX)/lib/ @mkdir -p $(VITASDK)/$(PREFIX)/lib/
@ -69,3 +75,5 @@ samples: $(TARGET).a
cp "samples/sample6/vitaGL-Sample006.vpk" . cp "samples/sample6/vitaGL-Sample006.vpk" .
@make -C samples/sample7 @make -C samples/sample7
cp "samples/sample7/vitaGL-Sample007.vpk" . cp "samples/sample7/vitaGL-Sample007.vpk" .
@make -C samples/sample8
cp "samples/sample8/vitaGL-Sample008.vpk" .

View File

@ -20,7 +20,7 @@ Here you can find a list of projects using vitaGL:
Direct OpenGL Usage:<br> Direct OpenGL Usage:<br>
[vitaQuake](https://vitadb.rinnegatamante.it/#/info/10) - Port of Quake I and mission packs<br> [vitaQuake](https://vitadb.rinnegatamante.it/#/info/10) - Port of Quake I and mission packs<br>
[vitaQuakeII](https://vitadb.rinnegatamante.it/#/info/278) -Port of Quake II and mission packs<br> [vitaQuakeII](https://vitadb.rinnegatamante.it/#/info/278) -Port of Quake II and mission packs<br>
[vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena)<br> [vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena, Urban Terror)<br>
[vitaRTCW](https://vitadb.rinnegatamante.it/#/info/459) - Port of iortcw (Return to Castle Wolfenstein)<br> [vitaRTCW](https://vitadb.rinnegatamante.it/#/info/459) - Port of iortcw (Return to Castle Wolfenstein)<br>
[vitaHexenII](https://vitadb.rinnegatamante.it/#/info/196) - Port of Hexen II<br> [vitaHexenII](https://vitadb.rinnegatamante.it/#/info/196) - Port of Hexen II<br>
[vitaXash3D](https://vitadb.rinnegatamante.it/#/info/365) - Port of Xash3D (Half Life, Counter Strike 1.6)<br> [vitaXash3D](https://vitadb.rinnegatamante.it/#/info/365) - Port of Xash3D (Half Life, Counter Strike 1.6)<br>

View File

@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include INCLUDES := include
LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))

View File

@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include INCLUDES := include
LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))

View File

@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include INCLUDES := include
LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lSceAppMgr_stub -lmathneon
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))

View File

@ -21,13 +21,6 @@ uint16_t indices[] = {
20,21,22,21,22,23 // Bottom 20,21,22,21,22,23 // Bottom
}; };
void init_perspective(float fov, float aspect, float near, float far){
float half_height = near * tanf(((fov * M_PI) / 180.0f) * 0.5f);
float half_width = half_height * aspect;
glFrustum(-half_width, half_width, -half_height, half_height, near, far);
}
int main(){ int main(){
// Initializing graphics device // Initializing graphics device
@ -53,7 +46,7 @@ int main(){
glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
init_perspective(90.0f, 960.f/544.0f, 0.01f, 100.0f); gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube

View File

@ -4,7 +4,7 @@ SOURCES := .
INCLUDES := include INCLUDES := include
LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lmathneon -lSceAppMgr_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))

View File

@ -25,13 +25,6 @@ uint16_t indices[] = {
20,21,22,21,22,23 // Bottom 20,21,22,21,22,23 // Bottom
}; };
void init_perspective(float fov, float aspect, float near, float far){
float half_height = near * tanf(((fov * M_PI) / 180.0f) * 0.5f);
float half_width = half_height * aspect;
glFrustum(-half_width, half_width, -half_height, half_height, near, far);
}
int main(){ int main(){
// Initializing graphics device // Initializing graphics device
@ -67,7 +60,7 @@ int main(){
glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
init_perspective(90.0f, 960.f/544.0f, 0.01f, 100.0f); gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube

37
deps/vitaGL/samples/sample8/Makefile vendored Normal file
View File

@ -0,0 +1,37 @@
SAMPLE_NUM := 008
TARGET := vitaGL-Sample$(SAMPLE_NUM)
SOURCES := .
INCLUDES := include
LIBS = -lvitaGL -lc -lSceCommonDialog_stub -lm -lSceGxm_stub -lSceDisplay_stub -lSceAppMgr_stub -lmathneon
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
ASFLAGS = $(CFLAGS)
all: $(TARGET).vpk
$(TARGET).vpk: eboot.bin
vita-mksfoex -s TITLE_ID=VITAGL$(SAMPLE_NUM) "$(TARGET)" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $@
eboot.bin: $(TARGET).velf
vita-make-fself -at 0x0E -m 0x10000 $< eboot.bin
%.velf: %.elf
vita-elf-create $< $@
$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
clean:
@rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin

76
deps/vitaGL/samples/sample8/main.c vendored Normal file
View File

@ -0,0 +1,76 @@
// Drawing a rotating cube
#include <vitaGL.h>
#include <math.h>
float colors[] = {1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}; // Colors for a face
float vertices_front[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f}; // Front Face
float vertices_back[] = {-0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Back Face
float vertices_left[] = {-0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f}; // Left Face
float vertices_right[] = {0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Right Face
float vertices_top[] = {-0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f}; // Top Face
float vertices_bottom[] = {-0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}; // Bottom Face
uint16_t indices[] = {
0, 1, 2, 1, 2, 3, // Front
4, 5, 6, 5, 6, 7, // Back
8, 9,10, 9,10,11, // Left
12,13,14,13,14,15, // Right
16,17,18,17,18,19, // Top
20,21,22,21,22,23 // Bottom
};
int main(){
// Initializing graphics device
vglSetParamBufferSize(2 * 1024 * 1024);
vglInitWithCustomSizes(0x1000, 960, 544, 16 * 1024 * 1024, 0, 0, SCE_GXM_MULTISAMPLE_4X);
vglWaitVblankStart(GL_TRUE);
// Creating colors array
float color_array[12*6];
int i;
for (i=0;i<12*6;i++){
color_array[i] = colors[i % 12];
}
// Creating vertices array
float vertex_array[12*6];
memcpy(&vertex_array[12*0], &vertices_front[0], sizeof(float) * 12);
memcpy(&vertex_array[12*1], &vertices_back[0], sizeof(float) * 12);
memcpy(&vertex_array[12*2], &vertices_left[0], sizeof(float) * 12);
memcpy(&vertex_array[12*3], &vertices_right[0], sizeof(float) * 12);
memcpy(&vertex_array[12*4], &vertices_top[0], sizeof(float) * 12);
memcpy(&vertex_array[12*5], &vertices_bottom[0], sizeof(float) * 12);
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 960.f/544.0f, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
for (;;){
vglStartRendering();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertex_array);
glColorPointer(3, GL_FLOAT, 0, color_array);
glRotatef(1.0f, 0.0f, 0.0f, 1.0f);
glRotatef(0.5f, 0.0f, 1.0f, 0.0f);
glDrawElements(GL_TRIANGLES, 6*6, GL_UNSIGNED_SHORT, indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
vglStopRendering();
}
vglEnd();
}

View File

@ -23,12 +23,14 @@
#include "shared.h" #include "shared.h"
#define MAX_CUSTOM_SHADERS 32 // Maximum number of linkable custom shaders #define MAX_CUSTOM_SHADERS 64 // Maximum number of linkable custom shaders
#define MAX_SHADER_PARAMS 16 // Maximum number of parameters per custom shader #define MAX_SHADER_PARAMS 8 // Maximum number of parameters per custom shader
// Internal stuffs // Internal stuffs
void *frag_uniforms = NULL; void *frag_uniforms = NULL;
void *vert_uniforms = NULL; void *vert_uniforms = NULL;
uint8_t use_shark = 1; // Flag to check if vitaShaRK should be initialized at vitaGL boot
uint8_t is_shark_online = 0; // Current vitaShaRK status
GLuint cur_program = 0; // Current in use custom program (0 = No custom program) GLuint cur_program = 0; // Current in use custom program (0 = No custom program)
@ -45,6 +47,7 @@ typedef struct shader {
GLboolean valid; GLboolean valid;
SceGxmShaderPatcherId id; SceGxmShaderPatcherId id;
const SceGxmProgram *prog; const SceGxmProgram *prog;
uint32_t size;
} shader; } shader;
// Program struct holding vertex/fragment shader info // Program struct holding vertex/fragment shader info
@ -52,8 +55,8 @@ typedef struct program {
shader *vshader; shader *vshader;
shader *fshader; shader *fshader;
GLboolean valid; GLboolean valid;
SceGxmVertexAttribute attr[16]; SceGxmVertexAttribute attr[MAX_SHADER_PARAMS];
SceGxmVertexStream stream[16]; SceGxmVertexStream stream[MAX_SHADER_PARAMS];
SceGxmVertexProgram *vprog; SceGxmVertexProgram *vprog;
SceGxmFragmentProgram *fprog; SceGxmFragmentProgram *fprog;
GLuint attr_num; GLuint attr_num;
@ -102,8 +105,8 @@ void reloadCustomShader(void) {
} }
void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean implicit_wvp) { void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
program *p = &progs[cur_program - 1];
if (implicit_wvp) { if (implicit_wvp) {
program *p = &progs[cur_program - 1];
if (mvp_modified) { if (mvp_modified) {
matrix4x4_multiply(mvp_matrix, projection_matrix, modelview_matrix); matrix4x4_multiply(mvp_matrix, projection_matrix, modelview_matrix);
mvp_modified = GL_FALSE; mvp_modified = GL_FALSE;
@ -122,6 +125,10 @@ void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean imp
* ------------------------------ * ------------------------------
*/ */
void vglEnableRuntimeShaderCompiler(GLboolean usage) {
use_shark = usage;
}
GLuint glCreateShader(GLenum shaderType) { GLuint glCreateShader(GLenum shaderType) {
// Looking for a free shader slot // Looking for a free shader slot
GLuint i, res = 0; GLuint i, res = 0;
@ -146,6 +153,7 @@ GLuint glCreateShader(GLenum shaderType) {
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; vgl_error = GL_INVALID_ENUM;
return 0;
break; break;
} }
shaders[res - 1].valid = GL_TRUE; shaders[res - 1].valid = GL_TRUE;
@ -153,17 +161,74 @@ GLuint glCreateShader(GLenum shaderType) {
return res; return res;
} }
void glGetShaderiv(GLuint handle, GLenum pname, GLint *params) {
// Grabbing passed shader
shader *s = &shaders[handle - 1];
switch (pname) {
case GL_SHADER_TYPE:
*params = s->type;
break;
case GL_COMPILE_STATUS:
*params = s->prog ? GL_TRUE : GL_FALSE;
break;
default:
SET_GL_ERROR(GL_INVALID_ENUM)
break;
}
}
void glShaderSource(GLuint handle, GLsizei count, const GLchar * const *string, const GLint *length) {
#ifndef SKIP_ERROR_HANDLING
if (count < 0) {
SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif
if (!is_shark_online) {
SET_GL_ERROR(GL_INVALID_OPERATION)
}
// Grabbing passed shader
shader *s = &shaders[handle - 1];
// Temporarily setting prog to point to the shader source
s->prog = (SceGxmProgram *)string;
s->size = *length;
}
void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length) { void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length) {
// Grabbing passed shader // Grabbing passed shader
shader *s = &shaders[handles[0] - 1]; shader *s = &shaders[handles[0] - 1];
// Allocating compiled shader on RAM and registering it into sceGxmShaderPatcher // Allocating compiled shader on RAM and registering it into sceGxmShaderPatcher
s->prog = (SceGxmProgram *)malloc(length); s->prog = (SceGxmProgram *)malloc(length);
memcpy((void *)s->prog, binary, length); memcpy_neon((void *)s->prog, binary, length);
sceGxmShaderPatcherRegisterProgram(gxm_shader_patcher, s->prog, &s->id); sceGxmShaderPatcherRegisterProgram(gxm_shader_patcher, s->prog, &s->id);
s->prog = sceGxmShaderPatcherGetProgramFromId(s->id); s->prog = sceGxmShaderPatcherGetProgramFromId(s->id);
} }
void glCompileShader(GLuint handle) {
// If vitaShaRK is not enabled, we just error out
if (!is_shark_online) {
SET_GL_ERROR(GL_INVALID_OPERATION)
}
#ifdef HAVE_SHARK
// Grabbing passed shader
shader *s = &shaders[handle - 1];
// Compiling shader source
s->prog = shark_compile_shader((const char*)s->prog, &s->size, s->type == GL_FRAGMENT_SHADER ? SHARK_FRAGMENT_SHADER : SHARK_VERTEX_SHADER);
if (s->prog) {
SceGxmProgram *res = (SceGxmProgram *)malloc(s->size);
memcpy_neon((void *)res, (void *)s->prog, s->size);
s->prog = res;
sceGxmShaderPatcherRegisterProgram(gxm_shader_patcher, s->prog, &s->id);
s->prog = sceGxmShaderPatcherGetProgramFromId(s->id);
}
shark_clear_output();
#endif
}
void glDeleteShader(GLuint shad) { void glDeleteShader(GLuint shad) {
// Grabbing passed shader // Grabbing passed shader
shader *s = &shaders[shad - 1]; shader *s = &shaders[shad - 1];
@ -193,8 +258,9 @@ void glAttachShader(GLuint prog, GLuint shad) {
default: default:
break; break;
} }
} else } else {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
}
} }
GLuint glCreateProgram(void) { GLuint glCreateProgram(void) {
@ -335,6 +401,43 @@ void glUniform2fv(GLint location, GLsizei count, const GLfloat *value) {
} }
} }
void glUniform3fv(GLint location, GLsizei count, const GLfloat *value) {
// Grabbing passed uniform
uniform *u = (uniform *)location;
if (u->ptr == NULL)
return;
// Setting passed value to desired uniform
if (u->isVertex) {
if (vert_uniforms == NULL)
sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vert_uniforms);
sceGxmSetUniformDataF(vert_uniforms, u->ptr, 0, 3 * count, value);
} else {
if (frag_uniforms == NULL)
sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &frag_uniforms);
sceGxmSetUniformDataF(frag_uniforms, u->ptr, 0, 3 * count, value);
}
}
void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
// Grabbing passed uniform
uniform *u = (uniform *)location;
if (u->ptr == NULL)
return;
// Setting passed value to desired uniform
float v[4] = {v0, v1, v2, v3};
if (u->isVertex) {
if (vert_uniforms == NULL)
sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vert_uniforms);
sceGxmSetUniformDataF(vert_uniforms, u->ptr, 0, 4, v);
} else {
if (frag_uniforms == NULL)
sceGxmReserveFragmentDefaultUniformBuffer(gxm_context, &frag_uniforms);
sceGxmSetUniformDataF(frag_uniforms, u->ptr, 0, 4, v);
}
}
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) { void glUniform4fv(GLint location, GLsizei count, const GLfloat *value) {
// Grabbing passed uniform // Grabbing passed uniform
uniform *u = (uniform *)location; uniform *u = (uniform *)location;
@ -402,7 +505,7 @@ void vglBindPackedAttribLocation(GLuint prog, GLuint index, const GLchar *name,
bpe = sizeof(uint8_t); bpe = sizeof(uint8_t);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -425,8 +528,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (stride < 0) { if (stride < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -440,7 +542,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
bpe = sizeof(GLshort); bpe = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -449,13 +551,13 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor
// Copying passed data to vitaGL mempool // Copying passed data to vitaGL mempool
if (stride == 0) if (stride == 0)
memcpy(ptr, pointer, count * bpe * size); // Faster if stride == 0 memcpy_neon(ptr, pointer, count * bpe * size); // Faster if stride == 0
else { else {
int i; int i;
uint8_t *dst = (uint8_t *)ptr; uint8_t *dst = (uint8_t *)ptr;
uint8_t *src = (uint8_t *)pointer; uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memcpy(dst, src, bpe * size); memcpy_neon(dst, src, bpe * size);
dst += (bpe * size); dst += (bpe * size);
src += stride; src += stride;
} }

View File

@ -66,8 +66,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) {
int i = 0, j = 0; int i = 0, j = 0;
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
for (i = 0; i < BUFFERS_NUM; i++) { for (i = 0; i < BUFFERS_NUM; i++) {
@ -85,8 +84,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) {
void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) { void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
while (n > 0) { while (n > 0) {
@ -117,7 +115,7 @@ void glBindFramebuffer(GLenum target, GLuint fb) {
active_write_fb = active_read_fb = (framebuffer *)fb; active_write_fb = active_read_fb = (framebuffer *)fb;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -134,7 +132,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint
fb = active_read_fb; fb = active_read_fb;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -178,7 +176,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint
sceGxmCreateRenderTarget(&renderTargetParams, &fb->target); sceGxmCreateRenderTarget(&renderTargetParams, &fb->target);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }

View File

@ -80,7 +80,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params) {
*params = GL_FALSE; *params = GL_FALSE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -98,7 +98,7 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
// Since we use column-major matrices internally, wee need to transpose it before returning it to the application // Since we use column-major matrices internally, wee need to transpose it before returning it to the application
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
data[i*4+j] = modelview_matrix[j][i]; data[i * 4 + j] = modelview_matrix[j][i];
} }
} }
break; break;
@ -106,7 +106,7 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
// Since we use column-major matrices internally, wee need to transpose it before returning it to the application // Since we use column-major matrices internally, wee need to transpose it before returning it to the application
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
data[i*4+j] = projection_matrix[j][i]; data[i * 4 + j] = projection_matrix[j][i];
} }
} }
break; break;
@ -122,8 +122,14 @@ void glGetFloatv(GLenum pname, GLfloat *data) {
case GL_MAX_TEXTURE_STACK_DEPTH: // Max texture stack depth case GL_MAX_TEXTURE_STACK_DEPTH: // Max texture stack depth
*data = GENERIC_STACK_DEPTH; *data = GENERIC_STACK_DEPTH;
break; break;
case GL_DEPTH_BITS:
*data = 32;
break;
case GL_STENCIL_BITS:
*data = 8;
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -155,8 +161,14 @@ void glGetIntegerv(GLenum pname, GLint *data) {
data[2] = gl_viewport.w; data[2] = gl_viewport.w;
data[3] = gl_viewport.h; data[3] = gl_viewport.h;
break; break;
case GL_DEPTH_BITS:
data[0] = 32;
break;
case GL_STENCIL_BITS:
data[0] = 8;
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }

View File

@ -23,6 +23,8 @@
#include "shared.h" #include "shared.h"
static uint32_t gxm_param_buf_size = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE; // Param buffer size for sceGxm
static void *vdm_ring_buffer_addr; // VDM ring buffer memblock starting address static void *vdm_ring_buffer_addr; // VDM ring buffer memblock starting address
static void *vertex_ring_buffer_addr; // vertex ring buffer memblock starting address static void *vertex_ring_buffer_addr; // vertex ring buffer memblock starting address
static void *fragment_ring_buffer_addr; // fragment ring buffer memblock starting address static void *fragment_ring_buffer_addr; // fragment ring buffer memblock starting address
@ -44,6 +46,9 @@ static void *gxm_depth_surface_addr; // Depth surface memblock starting address
static void *gxm_stencil_surface_addr; // Stencil surface memblock starting address static void *gxm_stencil_surface_addr; // Stencil surface memblock starting address
static SceGxmDepthStencilSurface gxm_depth_stencil_surface; // Depth/Stencil surfaces setup for sceGxm static SceGxmDepthStencilSurface gxm_depth_stencil_surface; // Depth/Stencil surfaces setup for sceGxm
static SceUID shared_fb; // In-use hared framebuffer identifier
static SceSharedFbInfo shared_fb_info; // In-use shared framebuffer info struct
SceGxmContext *gxm_context; // sceGxm context instance SceGxmContext *gxm_context; // sceGxm context instance
GLenum vgl_error = GL_NO_ERROR; // Error returned by glGetError GLenum vgl_error = GL_NO_ERROR; // Error returned by glGetError
SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance
@ -58,6 +63,9 @@ int DISPLAY_STRIDE; // Display stride in pixels
float DISPLAY_WIDTH_FLOAT; // Display width in pixels (float) float DISPLAY_WIDTH_FLOAT; // Display width in pixels (float)
float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float) float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float)
uint8_t system_app_mode = 0; // Flag for system app mode usage
static uint8_t gxm_initialized = 0; // Current sceGxm state
// sceDisplay callback data // sceDisplay callback data
struct display_queue_callback_data { struct display_queue_callback_data {
void *addr; void *addr;
@ -95,17 +103,40 @@ static void display_queue_callback(const void *callbackData) {
} }
void initGxm(void) { void initGxm(void) {
if (gxm_initialized)
return;
// Initializing runtime shader compiler
if (use_shark) {
#ifdef HAVE_SHARK
if (shark_init(NULL) >= 0)
is_shark_online = 1;
else
#endif
is_shark_online = 0;
}
// Checking if the running application is a system one
SceAppMgrBudgetInfo info;
info.size = sizeof(SceAppMgrBudgetInfo);
if (!sceAppMgrGetBudgetInfo(&info))
system_app_mode = 1;
// Initializing sceGxm init parameters // Initializing sceGxm init parameters
SceGxmInitializeParams gxm_init_params; SceGxmInitializeParams gxm_init_params;
memset(&gxm_init_params, 0, sizeof(SceGxmInitializeParams)); memset(&gxm_init_params, 0, sizeof(SceGxmInitializeParams));
gxm_init_params.flags = 0; gxm_init_params.flags = system_app_mode ? 0x0A : 0;
gxm_init_params.displayQueueMaxPendingCount = DISPLAY_BUFFER_COUNT - 1; gxm_init_params.displayQueueMaxPendingCount = DISPLAY_BUFFER_COUNT - 1;
gxm_init_params.displayQueueCallback = display_queue_callback; gxm_init_params.displayQueueCallback = display_queue_callback;
gxm_init_params.displayQueueCallbackDataSize = sizeof(struct display_queue_callback_data); gxm_init_params.displayQueueCallbackDataSize = sizeof(struct display_queue_callback_data);
gxm_init_params.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE; gxm_init_params.parameterBufferSize = gxm_param_buf_size;
// Initializing sceGxm // Initializing sceGxm
sceGxmInitialize(&gxm_init_params); if (system_app_mode)
sceGxmVshInitialize(&gxm_init_params);
else
sceGxmInitialize(&gxm_init_params);
gxm_initialized = 1;
} }
void initGxmContext(void) { void initGxmContext(void) {
@ -153,6 +184,17 @@ void termGxmContext(void) {
// Destroying sceGxm context // Destroying sceGxm context
sceGxmDestroyContext(gxm_context); sceGxmDestroyContext(gxm_context);
if (system_app_mode) {
sceSharedFbBegin(shared_fb, &shared_fb_info);
sceGxmUnmapMemory(shared_fb_info.fb_base);
sceSharedFbEnd(shared_fb);
sceSharedFbClose(shared_fb);
}
#ifdef HAVE_SHARK
// Shutting down runtime shader compiler
if (is_shark_online) shark_end();
#endif
} }
void createDisplayRenderTarget(void) { void createDisplayRenderTarget(void) {
@ -177,16 +219,34 @@ void destroyDisplayRenderTarget(void) {
} }
void initDisplayColorSurfaces(void) { void initDisplayColorSurfaces(void) {
// Getting access to the shared framebuffer on system app mode
while (system_app_mode) {
shared_fb = sceSharedFbOpen(1);
memset(&shared_fb_info, 0, sizeof(SceSharedFbInfo));
sceSharedFbGetInfo(shared_fb, &shared_fb_info);
if (shared_fb_info.index == 1)
sceSharedFbClose(shared_fb);
else {
sceGxmMapMemory(shared_fb_info.fb_base, shared_fb_info.fb_size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
gxm_color_surfaces_addr[0] = shared_fb_info.fb_base;
gxm_color_surfaces_addr[1] = shared_fb_info.fb_base2;
memset(&shared_fb_info, 0, sizeof(SceSharedFbInfo));
break;
}
}
vglMemType type = VGL_MEM_VRAM; vglMemType type = VGL_MEM_VRAM;
int i; int i;
for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) { for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) {
// Allocating color surface memblock // Allocating color surface memblock
gxm_color_surfaces_addr[i] = gpu_alloc_mapped( if (!system_app_mode) {
ALIGN(4 * DISPLAY_STRIDE * DISPLAY_HEIGHT, 1 * 1024 * 1024), gxm_color_surfaces_addr[i] = gpu_alloc_mapped(
&type); ALIGN(4 * DISPLAY_STRIDE * DISPLAY_HEIGHT, 1 * 1024 * 1024),
&type);
memset(gxm_color_surfaces_addr[i], 0, DISPLAY_STRIDE * DISPLAY_HEIGHT);
}
// Initializing allocated color surface // Initializing allocated color surface
memset(gxm_color_surfaces_addr[i], 0, DISPLAY_STRIDE * DISPLAY_HEIGHT);
sceGxmColorSurfaceInit(&gxm_color_surfaces[i], sceGxmColorSurfaceInit(&gxm_color_surfaces[i],
SCE_GXM_COLOR_FORMAT_A8B8G8R8, SCE_GXM_COLOR_FORMAT_A8B8G8R8,
SCE_GXM_COLOR_SURFACE_LINEAR, SCE_GXM_COLOR_SURFACE_LINEAR,
@ -206,7 +266,8 @@ void termDisplayColorSurfaces(void) {
// Deallocating display's color surfaces and destroying sync objects // Deallocating display's color surfaces and destroying sync objects
int i; int i;
for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) { for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) {
vgl_mem_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM); if (!system_app_mode)
vgl_mem_free(gxm_color_surfaces_addr[i], VGL_MEM_VRAM);
sceGxmSyncObjectDestroy(gxm_sync_objects[i]); sceGxmSyncObjectDestroy(gxm_sync_objects[i]);
} }
} }
@ -317,9 +378,18 @@ void waitRenderingDone(void) {
* ------------------------------ * ------------------------------
*/ */
void vglSetParamBufferSize(uint32_t size) {
gxm_param_buf_size = size;
}
void vglStartRendering(void) { void vglStartRendering(void) {
// Starting drawing scene // Starting drawing scene
if (active_write_fb == NULL) { // Default framebuffer is used if (active_write_fb == NULL) { // Default framebuffer is used
if (system_app_mode) {
sceSharedFbBegin(shared_fb, &shared_fb_info);
shared_fb_info.vsync = vblank;
gxm_back_buffer_index = (shared_fb_info.index + 1) % 2;
}
sceGxmBeginScene(gxm_context, gxm_scene_flags, gxm_render_target, sceGxmBeginScene(gxm_context, gxm_scene_flags, gxm_render_target,
NULL, NULL, NULL, NULL,
gxm_sync_objects[gxm_back_buffer_index], gxm_sync_objects[gxm_back_buffer_index],
@ -348,18 +418,23 @@ void vglStartRendering(void) {
void vglStopRenderingInit(void) { void vglStopRenderingInit(void) {
// Ending drawing scene // Ending drawing scene
sceGxmEndScene(gxm_context, NULL, NULL); sceGxmEndScene(gxm_context, NULL, NULL);
if (system_app_mode && vblank)
sceDisplayWaitVblankStart();
} }
void vglStopRenderingTerm(void) { void vglStopRenderingTerm(void) {
if (active_write_fb == NULL) { // Default framebuffer is used if (active_write_fb == NULL) { // Default framebuffer is used
// Properly requesting a display update // Properly requesting a display update
struct display_queue_callback_data queue_cb_data; if (system_app_mode)
queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index]; sceSharedFbEnd(shared_fb);
sceGxmDisplayQueueAddEntry(gxm_sync_objects[gxm_front_buffer_index], else {
gxm_sync_objects[gxm_back_buffer_index], &queue_cb_data); struct display_queue_callback_data queue_cb_data;
gxm_front_buffer_index = gxm_back_buffer_index; queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index];
gxm_back_buffer_index = (gxm_back_buffer_index + 1) % DISPLAY_BUFFER_COUNT; sceGxmDisplayQueueAddEntry(gxm_sync_objects[gxm_front_buffer_index],
gxm_sync_objects[gxm_back_buffer_index], &queue_cb_data);
gxm_front_buffer_index = gxm_back_buffer_index;
gxm_back_buffer_index = (gxm_back_buffer_index + 1) % DISPLAY_BUFFER_COUNT;
}
} }
// Resetting vitaGL mempool // Resetting vitaGL mempool

140
deps/vitaGL/source/hacks/memcpy_neon.S vendored Normal file
View File

@ -0,0 +1,140 @@
/*
* NEON code contributed by Siarhei Siamashka <siarhei.siamashka@nokia.com>.
* Origin: http://sourceware.org/ml/libc-ports/2009-07/msg00003.html
*
* The GNU C Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License.
*
* Tweaked for Android by Jim Huang <jserv@0xlab.org>
*/
.arm
.fpu neon
@ void* memcpy_n(void *destination, const void *source, size_t num)
.global memcpy_neon
.type memcpy_neon, %function
/*
* ENABLE_UNALIGNED_MEM_ACCESSES macro can be defined to permit the use
* of unaligned load/store memory accesses supported since ARMv6. This
* will further improve performance, but can purely theoretically cause
* problems if somebody decides to set SCTLR.A bit in the OS kernel
* (to trap each unaligned memory access) or somehow mess with strongly
* ordered/device memory.
*/
#define ENABLE_UNALIGNED_MEM_ACCESSES 1
#define NEON_MAX_PREFETCH_DISTANCE 320
.align 4
memcpy_neon:
.fnstart
mov ip, r0
cmp r2, #16
blt 4f @ Have less than 16 bytes to copy
@ First ensure 16 byte alignment for the destination buffer
tst r0, #0xF
beq 2f
tst r0, #1
ldrneb r3, [r1], #1
strneb r3, [ip], #1
subne r2, r2, #1
tst ip, #2
#ifdef ENABLE_UNALIGNED_MEM_ACCESSES
ldrneh r3, [r1], #2
strneh r3, [ip], #2
#else
ldrneb r3, [r1], #1
strneb r3, [ip], #1
ldrneb r3, [r1], #1
strneb r3, [ip], #1
#endif
subne r2, r2, #2
tst ip, #4
beq 1f
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [ip, :32]!
sub r2, r2, #4
1:
tst ip, #8
beq 2f
vld1.8 {d0}, [r1]!
vst1.8 {d0}, [ip, :64]!
sub r2, r2, #8
2:
subs r2, r2, #32
blt 3f
mov r3, #32
@ Main copy loop, 32 bytes are processed per iteration.
@ ARM instructions are used for doing fine-grained prefetch,
@ increasing prefetch distance progressively up to
@ NEON_MAX_PREFETCH_DISTANCE at runtime
1:
vld1.8 {d0-d3}, [r1]!
cmp r3, #(NEON_MAX_PREFETCH_DISTANCE - 32)
pld [r1, r3]
addle r3, r3, #32
vst1.8 {d0-d3}, [ip, :128]!
sub r2, r2, #32
cmp r2, r3
bge 1b
cmp r2, #0
blt 3f
1: @ Copy the remaining part of the buffer (already prefetched)
vld1.8 {d0-d3}, [r1]!
subs r2, r2, #32
vst1.8 {d0-d3}, [ip, :128]!
bge 1b
3: @ Copy up to 31 remaining bytes
tst r2, #16
beq 4f
vld1.8 {d0, d1}, [r1]!
vst1.8 {d0, d1}, [ip, :128]!
4:
@ Use ARM instructions exclusively for the final trailing part
@ not fully fitting into full 16 byte aligned block in order
@ to avoid "ARM store after NEON store" hazard. Also NEON
@ pipeline will be (mostly) flushed by the time when the
@ control returns to the caller, making the use of NEON mostly
@ transparent (and avoiding hazards in the caller code)
#ifdef ENABLE_UNALIGNED_MEM_ACCESSES
movs r3, r2, lsl #29
ldrcs r3, [r1], #4
strcs r3, [ip], #4
ldrcs r3, [r1], #4
strcs r3, [ip], #4
ldrmi r3, [r1], #4
strmi r3, [ip], #4
movs r2, r2, lsl #31
ldrcsh r3, [r1], #2
strcsh r3, [ip], #2
ldrmib r3, [r1], #1
strmib r3, [ip], #1
#else
movs r3, r2, lsl #29
bcc 1f
.rept 8
ldrcsb r3, [r1], #1
strcsb r3, [ip], #1
.endr
1:
bpl 1f
.rept 4
ldrmib r3, [r1], #1
strmib r3, [ip], #1
.endr
1:
movs r2, r2, lsl #31
ldrcsb r3, [r1], #1
strcsb r3, [ip], #1
ldrcsb r3, [r1], #1
strcsb r3, [ip], #1
ldrmib r3, [r1], #1
strmib r3, [ip], #1
#endif
bx lr
.fnend

View File

@ -87,8 +87,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -107,7 +106,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
last_vert->v.x = x; last_vert->v.x = x;
last_vert->v.y = y; last_vert->v.y = y;
last_vert->v.z = z; last_vert->v.z = z;
memcpy(&last_clr->v, &current_color.r, sizeof(vector4f)); memcpy_neon(&last_clr->v, &current_color.r, sizeof(vector4f));
last_clr->next = last_vert->next = NULL; last_clr->next = last_vert->next = NULL;
// Increasing vertex counter // Increasing vertex counter
@ -118,8 +117,7 @@ void glVertex3fv(const GLfloat *v) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -135,8 +133,8 @@ void glVertex3fv(const GLfloat *v) {
} }
// Properly populating the new element // Properly populating the new element
memcpy(&last_vert->v, v, sizeof(vector3f)); memcpy_neon(&last_vert->v, v, sizeof(vector3f));
memcpy(&last_clr->v, &current_color.r, sizeof(vector4f)); memcpy_neon(&last_clr->v, &current_color.r, sizeof(vector4f));
last_clr->next = last_vert->next = NULL; last_clr->next = last_vert->next = NULL;
// Increasing vertex counter // Increasing vertex counter
@ -157,7 +155,7 @@ void glColor3f(GLfloat red, GLfloat green, GLfloat blue) {
void glColor3fv(const GLfloat *v) { void glColor3fv(const GLfloat *v) {
// Setting current color value // Setting current color value
memcpy(&current_color.r, v, sizeof(vector3f)); memcpy_neon(&current_color.r, v, sizeof(vector3f));
current_color.a = 1.0f; current_color.a = 1.0f;
} }
@ -187,7 +185,7 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
void glColor4fv(const GLfloat *v) { void glColor4fv(const GLfloat *v) {
// Setting current color value // Setting current color value
memcpy(&current_color.r, v, sizeof(vector4f)); memcpy_neon(&current_color.r, v, sizeof(vector4f));
} }
void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) {
@ -209,8 +207,7 @@ void glTexCoord2fv(GLfloat *f) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -232,8 +229,7 @@ void glTexCoord2f(GLfloat s, GLfloat t) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -255,8 +251,7 @@ void glTexCoord2i(GLint s, GLint t) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -278,8 +273,7 @@ void glArrayElement(GLint i) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (i < 0) { if (i < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -309,7 +303,7 @@ void glArrayElement(GLint i) {
last_clr->next = NULL; last_clr->next = NULL;
// Populating new vertex element // Populating new vertex element
memcpy(&last_vert->v, ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&last_vert->v, ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
// Checking if current texture unit has GL_COLOR_ARRAY enabled // Checking if current texture unit has GL_COLOR_ARRAY enabled
if (tex_unit->color_array_state) { if (tex_unit->color_array_state) {
@ -322,11 +316,11 @@ void glArrayElement(GLint i) {
// Populating new color element // Populating new color element
last_clr->v.a = 1.0f; last_clr->v.a = 1.0f;
memcpy(&last_clr->v, ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num); memcpy_neon(&last_clr->v, ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
} else { } else {
// Populating new color element with current color // Populating new color element with current color
memcpy(&last_clr->v, &current_color.r, sizeof(vector4f)); memcpy_neon(&last_clr->v, &current_color.r, sizeof(vector4f));
} }
// Checking if current texture unit has GL_TEXTURE_COORD_ARRAY enabled // Checking if current texture unit has GL_TEXTURE_COORD_ARRAY enabled
@ -347,7 +341,7 @@ void glArrayElement(GLint i) {
} }
// Populating new texcoord element // Populating new texcoord element
memcpy(&last_uv->v, ptr_tex, tex_unit->vertex_array.size * 2); memcpy_neon(&last_uv->v, ptr_tex, tex_unit->vertex_array.size * 2);
last_uv->next = NULL; last_uv->next = NULL;
} }
} }
@ -357,8 +351,7 @@ void glBegin(GLenum mode) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -394,7 +387,7 @@ void glBegin(GLenum mode) {
np = 4; np = 4;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -410,7 +403,7 @@ void glEnd(void) {
// Error handling // Error handling
if (phase != MODEL_CREATION) { if (phase != MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return; return;
} }
#endif #endif
@ -498,8 +491,8 @@ void glEnd(void) {
memset(vertices, 0, (vertex_count * sizeof(vector3f))); memset(vertices, 0, (vertex_count * sizeof(vector3f)));
indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t));
for (i = 0; i < vertex_count; i++) { for (i = 0; i < vertex_count; i++) {
memcpy(&vertices[n], &object->v, sizeof(vector3f)); memcpy_neon(&vertices[n], &object->v, sizeof(vector3f));
memcpy(&uv_map[n], &object_uv->v, sizeof(vector2f)); memcpy_neon(&uv_map[n], &object_uv->v, sizeof(vector2f));
indices[n] = n; indices[n] = n;
object = object->next; object = object->next;
object_uv = object_uv->next; object_uv = object_uv->next;
@ -522,8 +515,8 @@ void glEnd(void) {
indices[i * 6 + 5] = i * 4 + 3; indices[i * 6 + 5] = i * 4 + 3;
} }
for (j = 0; j < vertex_count; j++) { for (j = 0; j < vertex_count; j++) {
memcpy(&vertices[j], &object->v, sizeof(vector3f)); memcpy_neon(&vertices[j], &object->v, sizeof(vector3f));
memcpy(&uv_map[j], &object_uv->v, sizeof(vector2f)); memcpy_neon(&uv_map[j], &object_uv->v, sizeof(vector2f));
object = object->next; object = object->next;
object_uv = object_uv->next; object_uv = object_uv->next;
} }
@ -554,8 +547,8 @@ void glEnd(void) {
memset(vertices, 0, (vertex_count * sizeof(vector3f))); memset(vertices, 0, (vertex_count * sizeof(vector3f)));
indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t));
for (i = 0; i < vertex_count; i++) { for (i = 0; i < vertex_count; i++) {
memcpy(&vertices[n], &object->v, sizeof(vector3f)); memcpy_neon(&vertices[n], &object->v, sizeof(vector3f));
memcpy(&colors[n], &object_clr->v, sizeof(vector4f)); memcpy_neon(&colors[n], &object_clr->v, sizeof(vector4f));
indices[n] = n; indices[n] = n;
object = object->next; object = object->next;
object_clr = object_clr->next; object_clr = object_clr->next;
@ -579,8 +572,8 @@ void glEnd(void) {
indices[i * 6 + 5] = i * 4 + 3; indices[i * 6 + 5] = i * 4 + 3;
} }
for (j = 0; j < vertex_count; j++) { for (j = 0; j < vertex_count; j++) {
memcpy(&vertices[j], &object->v, sizeof(vector3f)); memcpy_neon(&vertices[j], &object->v, sizeof(vector3f));
memcpy(&colors[j], &object_clr->v, sizeof(vector4f)); memcpy_neon(&colors[j], &object_clr->v, sizeof(vector4f));
object = object->next; object = object->next;
object_clr = object_clr->next; object_clr = object_clr->next;
} }

View File

@ -46,7 +46,7 @@ void glMatrixMode(GLenum mode) {
matrix = &projection_matrix; matrix = &projection_matrix;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -55,11 +55,9 @@ void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdou
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} else if ((left == right) || (bottom == top) || (nearVal == farVal)) { } else if ((left == right) || (bottom == top) || (nearVal == farVal)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -72,11 +70,9 @@ void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLd
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} else if ((left == right) || (bottom == top) || (nearVal < 0) || (farVal < 0)) { } else if ((left == right) || (bottom == top) || (nearVal < 0) || (farVal < 0)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -139,8 +135,7 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -162,8 +157,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -171,7 +165,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (modelview_stack_counter >= MODELVIEW_STACK_DEPTH) { if (modelview_stack_counter >= MODELVIEW_STACK_DEPTH) {
vgl_error = GL_STACK_OVERFLOW; SET_GL_ERROR(GL_STACK_OVERFLOW)
} else } else
#endif #endif
// Copying current matrix into the matrix stack and increasing stack counter // Copying current matrix into the matrix stack and increasing stack counter
@ -181,7 +175,7 @@ void glPushMatrix(void) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (projection_stack_counter >= GENERIC_STACK_DEPTH) { if (projection_stack_counter >= GENERIC_STACK_DEPTH) {
vgl_error = GL_STACK_OVERFLOW; SET_GL_ERROR(GL_STACK_OVERFLOW)
} else } else
#endif #endif
// Copying current matrix into the matrix stack and increasing stack counter // Copying current matrix into the matrix stack and increasing stack counter
@ -193,17 +187,16 @@ void glPopMatrix(void) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
if (matrix == &modelview_matrix) { if (matrix == &modelview_matrix) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (modelview_stack_counter == 0) if (modelview_stack_counter == 0) {
vgl_error = GL_STACK_UNDERFLOW; SET_GL_ERROR(GL_STACK_UNDERFLOW)
else } else
#endif #endif
// Copying last matrix on stack into current matrix and decreasing stack counter // Copying last matrix on stack into current matrix and decreasing stack counter
matrix4x4_copy(*matrix, modelview_matrix_stack[--modelview_stack_counter]); matrix4x4_copy(*matrix, modelview_matrix_stack[--modelview_stack_counter]);
@ -211,12 +204,25 @@ void glPopMatrix(void) {
} else if (matrix == &projection_matrix) { } else if (matrix == &projection_matrix) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (projection_stack_counter == 0) if (projection_stack_counter == 0) {
vgl_error = GL_STACK_UNDERFLOW; SET_GL_ERROR(GL_STACK_UNDERFLOW)
else } else
#endif #endif
// Copying last matrix on stack into current matrix and decreasing stack counter // Copying last matrix on stack into current matrix and decreasing stack counter
matrix4x4_copy(*matrix, projection_matrix_stack[--projection_stack_counter]); matrix4x4_copy(*matrix, projection_matrix_stack[--projection_stack_counter]);
} }
mvp_modified = GL_TRUE; mvp_modified = GL_TRUE;
} }
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
#ifndef SKIP_ERROR_HANDLING
// Error handling
if (phase == MODEL_CREATION) {
SET_GL_ERROR(GL_INVALID_OPERATION)
}
#endif
// Initializing frustum matrix with requested parameters
matrix4x4_init_perspective(*matrix, fovy, aspect, zNear, zFar);
mvp_modified = GL_TRUE;
}

View File

@ -119,7 +119,7 @@ void glPolygonMode(GLenum face, GLenum mode) {
new_mode = SCE_GXM_POLYGON_MODE_TRIANGLE_FILL; new_mode = SCE_GXM_POLYGON_MODE_TRIANGLE_FILL;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (face) { switch (face) {
@ -140,7 +140,7 @@ void glPolygonMode(GLenum face, GLenum mode) {
sceGxmSetBackPolygonMode(gxm_context, new_mode); sceGxmSetBackPolygonMode(gxm_context, new_mode);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return; return;
} }
update_polygon_offset(); update_polygon_offset();
@ -167,8 +167,7 @@ void glFrontFace(GLenum mode) {
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((width < 0) || (height < 0)) { if ((width < 0) || (height < 0)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
x_scale = width >> 1; x_scale = width >> 1;
@ -197,8 +196,7 @@ void glDepthRangef(GLfloat nearVal, GLfloat farVal) {
void glEnable(GLenum cap) { void glEnable(GLenum cap) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
switch (cap) { switch (cap) {
@ -250,7 +248,7 @@ void glEnable(GLenum cap) {
clip_plane0 = GL_TRUE; clip_plane0 = GL_TRUE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -258,8 +256,7 @@ void glEnable(GLenum cap) {
void glDisable(GLenum cap) { void glDisable(GLenum cap) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
switch (cap) { switch (cap) {
@ -311,7 +308,7 @@ void glDisable(GLenum cap) {
clip_plane0 = GL_FALSE; clip_plane0 = GL_FALSE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -411,7 +408,7 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
@ -429,12 +426,12 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -443,8 +440,7 @@ void glLineWidth(GLfloat width) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (width <= 0) { if (width <= 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -457,8 +453,7 @@ void glPointSize(GLfloat size) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (size <= 0) { if (size <= 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -483,7 +478,7 @@ void glFogf(GLenum pname, GLfloat param) {
fog_far = param; fog_far = param;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -504,10 +499,10 @@ void glFogfv(GLenum pname, const GLfloat *params) {
fog_far = params[0]; fog_far = params[0];
break; break;
case GL_FOG_COLOR: case GL_FOG_COLOR:
memcpy(&fog_color.r, params, sizeof(vector4f)); memcpy_neon(&fog_color.r, params, sizeof(vector4f));
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -528,7 +523,7 @@ void glFogi(GLenum pname, const GLint param) {
fog_far = param; fog_far = param;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -545,10 +540,10 @@ void glClipPlane(GLenum plane, const GLdouble *equation) {
matrix4x4_transpose(inverted_transposed, inverted); matrix4x4_transpose(inverted_transposed, inverted);
vector4f temp; vector4f temp;
vector4f_matrix4x4_mult(&temp, inverted_transposed, &clip_plane0_eq); vector4f_matrix4x4_mult(&temp, inverted_transposed, &clip_plane0_eq);
memcpy(&clip_plane0_eq.x, &temp.x, sizeof(vector4f)); memcpy_neon(&clip_plane0_eq.x, &temp.x, sizeof(vector4f));
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }

View File

@ -25,81 +25,81 @@
#define _SHADERS_H_ #define _SHADERS_H_
// Disable color buffer shader // Disable color buffer shader
SceGxmShaderPatcherId disable_color_buffer_fragment_id; extern SceGxmShaderPatcherId disable_color_buffer_fragment_id;
const SceGxmProgramParameter *disable_color_buffer_position; extern const SceGxmProgramParameter *disable_color_buffer_position;
SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched; extern SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
const SceGxmProgramParameter *clear_depth; extern const SceGxmProgramParameter *clear_depth;
// Clear shader // Clear shader
SceGxmShaderPatcherId clear_vertex_id; extern SceGxmShaderPatcherId clear_vertex_id;
SceGxmShaderPatcherId clear_fragment_id; extern SceGxmShaderPatcherId clear_fragment_id;
const SceGxmProgramParameter *clear_position; extern const SceGxmProgramParameter *clear_position;
const SceGxmProgramParameter *clear_color; extern const SceGxmProgramParameter *clear_color;
SceGxmVertexProgram *clear_vertex_program_patched; extern SceGxmVertexProgram *clear_vertex_program_patched;
SceGxmFragmentProgram *clear_fragment_program_patched; extern SceGxmFragmentProgram *clear_fragment_program_patched;
// Color (RGBA/RGB) shader // Color (RGBA/RGB) shader
SceGxmShaderPatcherId rgba_vertex_id; extern SceGxmShaderPatcherId rgba_vertex_id;
SceGxmShaderPatcherId rgb_vertex_id; extern SceGxmShaderPatcherId rgb_vertex_id;
SceGxmShaderPatcherId rgba_fragment_id; extern SceGxmShaderPatcherId rgba_fragment_id;
const SceGxmProgramParameter *rgba_position; extern const SceGxmProgramParameter *rgba_position;
const SceGxmProgramParameter *rgba_color; extern const SceGxmProgramParameter *rgba_color;
const SceGxmProgramParameter *rgba_wvp; extern const SceGxmProgramParameter *rgba_wvp;
const SceGxmProgramParameter *rgb_position; extern const SceGxmProgramParameter *rgb_position;
const SceGxmProgramParameter *rgb_color; extern const SceGxmProgramParameter *rgb_color;
const SceGxmProgramParameter *rgb_wvp; extern const SceGxmProgramParameter *rgb_wvp;
SceGxmVertexProgram *rgba_vertex_program_patched; extern SceGxmVertexProgram *rgba_vertex_program_patched;
SceGxmVertexProgram *rgba_u8n_vertex_program_patched; extern SceGxmVertexProgram *rgba_u8n_vertex_program_patched;
SceGxmVertexProgram *rgb_vertex_program_patched; extern SceGxmVertexProgram *rgb_vertex_program_patched;
SceGxmVertexProgram *rgb_u8n_vertex_program_patched; extern SceGxmVertexProgram *rgb_u8n_vertex_program_patched;
SceGxmFragmentProgram *rgba_fragment_program_patched; extern SceGxmFragmentProgram *rgba_fragment_program_patched;
const SceGxmProgram *rgba_fragment_program; extern const SceGxmProgram *rgba_fragment_program;
// Texture2D shader // Texture2D shader
SceGxmShaderPatcherId texture2d_vertex_id; extern SceGxmShaderPatcherId texture2d_vertex_id;
SceGxmShaderPatcherId texture2d_fragment_id; extern SceGxmShaderPatcherId texture2d_fragment_id;
const SceGxmProgramParameter *texture2d_position; extern const SceGxmProgramParameter *texture2d_position;
const SceGxmProgramParameter *texture2d_texcoord; extern const SceGxmProgramParameter *texture2d_texcoord;
const SceGxmProgramParameter *texture2d_wvp; extern const SceGxmProgramParameter *texture2d_wvp;
const SceGxmProgramParameter *texture2d_alpha_cut; extern const SceGxmProgramParameter *texture2d_alpha_cut;
const SceGxmProgramParameter *texture2d_alpha_op; extern const SceGxmProgramParameter *texture2d_alpha_op;
const SceGxmProgramParameter *texture2d_tint_color; extern const SceGxmProgramParameter *texture2d_tint_color;
const SceGxmProgramParameter *texture2d_tex_env; extern const SceGxmProgramParameter *texture2d_tex_env;
const SceGxmProgramParameter *texture2d_clip_plane0; extern const SceGxmProgramParameter *texture2d_clip_plane0;
const SceGxmProgramParameter *texture2d_clip_plane0_eq; extern const SceGxmProgramParameter *texture2d_clip_plane0_eq;
const SceGxmProgramParameter *texture2d_mv; extern const SceGxmProgramParameter *texture2d_mv;
const SceGxmProgramParameter *texture2d_fog_mode; extern const SceGxmProgramParameter *texture2d_fog_mode;
const SceGxmProgramParameter *texture2d_fog_near; extern const SceGxmProgramParameter *texture2d_fog_near;
const SceGxmProgramParameter *texture2d_fog_far; extern const SceGxmProgramParameter *texture2d_fog_far;
const SceGxmProgramParameter *texture2d_fog_density; extern const SceGxmProgramParameter *texture2d_fog_density;
const SceGxmProgramParameter *texture2d_fog_color; extern const SceGxmProgramParameter *texture2d_fog_color;
const SceGxmProgramParameter *texture2d_tex_env_color; extern const SceGxmProgramParameter *texture2d_tex_env_color;
SceGxmVertexProgram *texture2d_vertex_program_patched; extern SceGxmVertexProgram *texture2d_vertex_program_patched;
SceGxmFragmentProgram *texture2d_fragment_program_patched; extern SceGxmFragmentProgram *texture2d_fragment_program_patched;
const SceGxmProgram *texture2d_fragment_program; extern const SceGxmProgram *texture2d_fragment_program;
// Texture2D+RGBA shader // Texture2D+RGBA shader
SceGxmShaderPatcherId texture2d_rgba_vertex_id; extern SceGxmShaderPatcherId texture2d_rgba_vertex_id;
SceGxmShaderPatcherId texture2d_rgba_fragment_id; extern SceGxmShaderPatcherId texture2d_rgba_fragment_id;
const SceGxmProgramParameter *texture2d_rgba_position; extern const SceGxmProgramParameter *texture2d_rgba_position;
const SceGxmProgramParameter *texture2d_rgba_texcoord; extern const SceGxmProgramParameter *texture2d_rgba_texcoord;
const SceGxmProgramParameter *texture2d_rgba_wvp; extern const SceGxmProgramParameter *texture2d_rgba_wvp;
const SceGxmProgramParameter *texture2d_rgba_alpha_cut; extern const SceGxmProgramParameter *texture2d_rgba_alpha_cut;
const SceGxmProgramParameter *texture2d_rgba_alpha_op; extern const SceGxmProgramParameter *texture2d_rgba_alpha_op;
const SceGxmProgramParameter *texture2d_rgba_color; extern const SceGxmProgramParameter *texture2d_rgba_color;
const SceGxmProgramParameter *texture2d_rgba_tex_env; extern const SceGxmProgramParameter *texture2d_rgba_tex_env;
const SceGxmProgramParameter *texture2d_rgba_clip_plane0; extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0;
const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq; extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq;
const SceGxmProgramParameter *texture2d_rgba_mv; extern const SceGxmProgramParameter *texture2d_rgba_mv;
const SceGxmProgramParameter *texture2d_rgba_fog_mode; extern const SceGxmProgramParameter *texture2d_rgba_fog_mode;
const SceGxmProgramParameter *texture2d_rgba_fog_near; extern const SceGxmProgramParameter *texture2d_rgba_fog_near;
const SceGxmProgramParameter *texture2d_rgba_fog_far; extern const SceGxmProgramParameter *texture2d_rgba_fog_far;
const SceGxmProgramParameter *texture2d_rgba_fog_density; extern const SceGxmProgramParameter *texture2d_rgba_fog_density;
const SceGxmProgramParameter *texture2d_rgba_fog_color; extern const SceGxmProgramParameter *texture2d_rgba_fog_color;
const SceGxmProgramParameter *texture2d_rgba_tex_env_color; extern const SceGxmProgramParameter *texture2d_rgba_tex_env_color;
SceGxmVertexProgram *texture2d_rgba_vertex_program_patched; extern SceGxmVertexProgram *texture2d_rgba_vertex_program_patched;
SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched; extern SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched;
SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched; extern SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched;
const SceGxmProgram *texture2d_rgba_fragment_program; extern const SceGxmProgram *texture2d_rgba_fragment_program;
#endif #endif

View File

@ -56,6 +56,8 @@ extern float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float)
#include "state.h" #include "state.h"
#include "texture_callbacks.h" #include "texture_callbacks.h"
#define SET_GL_ERROR(x) vgl_error = x; return;
// Texture environment mode // Texture environment mode
typedef enum texEnvMode { typedef enum texEnvMode {
MODULATE = 0, MODULATE = 0,
@ -107,6 +109,9 @@ void LOG(const char *format, ...);
#define max(a, b) ((a) > (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b))
#endif #endif
extern uint8_t use_shark; // Flag to check if vitaShaRK should be initialized at vitaGL boot
extern uint8_t is_shark_online; // Current vitaShaRK status
// sceGxm viewport setup (NOTE: origin is on center screen) // sceGxm viewport setup (NOTE: origin is on center screen)
extern float x_port; extern float x_port;
extern float y_port; extern float y_port;
@ -126,10 +131,11 @@ extern float fullscreen_z_scale;
extern SceGxmContext *gxm_context; // sceGxm context instance extern SceGxmContext *gxm_context; // sceGxm context instance
extern GLenum vgl_error; // Error returned by glGetError extern GLenum vgl_error; // Error returned by glGetError
extern SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance extern SceGxmShaderPatcher *gxm_shader_patcher; // sceGxmShaderPatcher shader patcher instance
extern uint8_t system_app_mode; // Flag for system app mode usage
matrix4x4 mvp_matrix; // ModelViewProjection Matrix extern matrix4x4 mvp_matrix; // ModelViewProjection Matrix
matrix4x4 projection_matrix; // Projection Matrix extern matrix4x4 projection_matrix; // Projection Matrix
matrix4x4 modelview_matrix; // ModelView Matrix extern matrix4x4 modelview_matrix; // ModelView Matrix
extern GLboolean mvp_modified; // Check if ModelViewProjection matrix needs to be recreated extern GLboolean mvp_modified; // Check if ModelViewProjection matrix needs to be recreated
extern GLuint cur_program; // Current in use custom program (0 = No custom program) extern GLuint cur_program; // Current in use custom program (0 = No custom program)

View File

@ -96,6 +96,7 @@ typedef struct texture_unit {
SceGxmTextureFilter mag_filter; SceGxmTextureFilter mag_filter;
SceGxmTextureAddrMode u_mode; SceGxmTextureAddrMode u_mode;
SceGxmTextureAddrMode v_mode; SceGxmTextureAddrMode v_mode;
uint32_t lod_bias;
} texture_unit; } texture_unit;
// Framebuffer struct // Framebuffer struct

View File

@ -327,8 +327,7 @@ void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if ((width < 0) || (height < 0)) { if ((width < 0) || (height < 0)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -385,8 +384,7 @@ void glDepthMask(GLboolean flag) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (phase == MODEL_CREATION) { if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
return;
} }
#endif #endif
@ -407,36 +405,36 @@ void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass
switch (face) { switch (face) {
case GL_FRONT: case GL_FRONT:
if (!change_stencil_config(&stencil_fail_front, sfail)) if (!change_stencil_config(&stencil_fail_front, sfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_front, dpfail)) if (!change_stencil_config(&depth_fail_front, dpfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass)) if (!change_stencil_config(&depth_pass_front, dppass))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
case GL_BACK: case GL_BACK:
if (!change_stencil_config(&stencil_fail_back, sfail)) if (!change_stencil_config(&stencil_fail_back, sfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_back, dpfail)) if (!change_stencil_config(&depth_fail_back, dpfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass)) if (!change_stencil_config(&depth_pass_front, dppass))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
case GL_FRONT_AND_BACK: case GL_FRONT_AND_BACK:
if (!change_stencil_config(&stencil_fail_front, sfail)) if (!change_stencil_config(&stencil_fail_front, sfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&stencil_fail_back, sfail)) if (!change_stencil_config(&stencil_fail_back, sfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_front, dpfail)) if (!change_stencil_config(&depth_fail_front, dpfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_fail_back, dpfail)) if (!change_stencil_config(&depth_fail_back, dpfail))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_front, dppass)) if (!change_stencil_config(&depth_pass_front, dppass))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_config(&depth_pass_back, dppass)) if (!change_stencil_config(&depth_pass_back, dppass))
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
change_stencil_settings(); change_stencil_settings();
@ -450,27 +448,31 @@ void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) {
// Properly updating stencil test function settings // Properly updating stencil test function settings
switch (face) { switch (face) {
case GL_FRONT: case GL_FRONT:
if (!change_stencil_func_config(&stencil_func_front, func)) if (!change_stencil_func_config(&stencil_func_front, func)) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
}
stencil_mask_front = mask; stencil_mask_front = mask;
stencil_ref_front = ref; stencil_ref_front = ref;
break; break;
case GL_BACK: case GL_BACK:
if (!change_stencil_func_config(&stencil_func_back, func)) if (!change_stencil_func_config(&stencil_func_back, func)) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
}
stencil_mask_back = mask; stencil_mask_back = mask;
stencil_ref_back = ref; stencil_ref_back = ref;
break; break;
case GL_FRONT_AND_BACK: case GL_FRONT_AND_BACK:
if (!change_stencil_func_config(&stencil_func_front, func)) if (!change_stencil_func_config(&stencil_func_front, func)) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
if (!change_stencil_func_config(&stencil_func_back, func)) }
vgl_error = GL_INVALID_ENUM; if (!change_stencil_func_config(&stencil_func_back, func)) {
SET_GL_ERROR(GL_INVALID_ENUM)
}
stencil_mask_front = stencil_mask_back = mask; stencil_mask_front = stencil_mask_back = mask;
stencil_ref_front = stencil_ref_back = ref; stencil_ref_front = stencil_ref_back = ref;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
change_stencil_settings(); change_stencil_settings();
@ -493,7 +495,7 @@ void glStencilMaskSeparate(GLenum face, GLuint mask) {
stencil_mask_front_write = stencil_mask_back_write = mask; stencil_mask_front_write = stencil_mask_back_write = mask;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return; return;
} }
change_stencil_settings(); change_stencil_settings();

View File

@ -24,12 +24,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <vitasdk.h> #include <vitasdk.h>
#include "vitaGL.h"
#include "texture_callbacks.h" #include "texture_callbacks.h"
#define convert_u16_to_u32_cspace(color, lshift, rshift, mask) ((((color << lshift) >> rshift) & mask) * 0xFF) / mask
// Read callback for 32bpp unsigned RGBA format // Read callback for 32bpp unsigned RGBA format
uint32_t readRGBA(void *data) { uint32_t readRGBA(void *data) {
uint32_t res; uint32_t res;
memcpy(&res, data, 4); memcpy_neon(&res, data, 4);
return res; return res;
} }
@ -37,48 +40,71 @@ uint32_t readRGBA(void *data) {
uint32_t readRGBA5551(void *data) { uint32_t readRGBA5551(void *data) {
uint16_t clr; uint16_t clr;
uint32_t r, g, b, a; uint32_t r, g, b, a;
memcpy(&clr, data, 2); memcpy_neon(&clr, data, 2);
r = (((clr >> 11) & 0x1F) * 0xFF) / 0x1F; r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
g = ((((clr << 5) >> 11) & 0x1F) * 0xFF) / 0x1F; g = convert_u16_to_u32_cspace(clr, 5, 11, 0x1F);
b = ((((clr << 10) >> 11) & 0x1F) * 0xFF) / 0x1F; b = convert_u16_to_u32_cspace(clr, 10, 11, 0x1F);
a = (((clr << 15) >> 15) & 0x1) == 1 ? 0xFF : 0x00; a = convert_u16_to_u32_cspace(clr, 15, 15, 0x01);
return ((a << 24) | (b << 16) | (g << 8) | r); return ((a << 24) | (b << 16) | (g << 8) | r);
} }
// Read callback for 16bpp unsigned RGBA4444 format
uint32_t readRGBA4444(void *data) {
uint16_t clr;
uint32_t r, g, b, a;
memcpy_neon(&clr, data, 2);
r = convert_u16_to_u32_cspace(clr, 0, 12, 0x0F);
g = convert_u16_to_u32_cspace(clr, 4, 12, 0x0F);
b = convert_u16_to_u32_cspace(clr, 8, 12, 0x0F);
a = convert_u16_to_u32_cspace(clr, 12, 12, 0x0F);
return ((a << 24) | (b << 16) | (g << 8) | r);
}
// Read callback for 16bpp unsigned RGB565 format
uint32_t readRGB565(void *data) {
uint16_t clr;
uint32_t r, g, b;
memcpy_neon(&clr, data, 2);
r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
g = convert_u16_to_u32_cspace(clr, 5, 11, 0x3F);
b = convert_u16_to_u32_cspace(clr, 11, 11, 0x1F);
return ((0xFF << 24) | (b << 16) | (g << 8) | r);
}
// Read callback for 24bpp unsigned RGB format // Read callback for 24bpp unsigned RGB format
uint32_t readRGB(void *data) { uint32_t readRGB(void *data) {
uint32_t res = 0xFFFFFFFF; uint32_t res = 0xFFFFFFFF;
memcpy(&res, data, 3); memcpy_neon(&res, data, 3);
return res; return res;
} }
// Read callback for 16bpp unsigned RG format // Read callback for 16bpp unsigned RG format
uint32_t readRG(void *data) { uint32_t readRG(void *data) {
uint32_t res = 0xFFFFFFFF; uint32_t res = 0xFFFFFFFF;
memcpy(&res, data, 2); memcpy_neon(&res, data, 2);
return res; return res;
} }
// Read callback for 8bpp unsigned R format // Read callback for 8bpp unsigned R format
uint32_t readR(void *data) { uint32_t readR(void *data) {
uint32_t res = 0xFFFFFFFF; uint32_t res = 0xFFFFFFFF;
memcpy(&res, data, 1); memcpy_neon(&res, data, 1);
return res; return res;
} }
// Write callback for 32bpp unsigned RGBA format // Write callback for 32bpp unsigned RGBA format
void writeRGBA(void *data, uint32_t color) { void writeRGBA(void *data, uint32_t color) {
memcpy(data, &color, 4); memcpy_neon(data, &color, 4);
} }
// Write callback for 24bpp unsigned RGB format // Write callback for 24bpp unsigned RGB format
void writeRGB(void *data, uint32_t color) { void writeRGB(void *data, uint32_t color) {
memcpy(data, &color, 3); memcpy_neon(data, &color, 3);
} }
// Write callback for 16bpp unsigned RG format // Write callback for 16bpp unsigned RG format
void writeRG(void *data, uint32_t color) { void writeRG(void *data, uint32_t color) {
memcpy(data, &color, 2); memcpy_neon(data, &color, 2);
} }
// Write callback for 16bpp unsigned RA format // Write callback for 16bpp unsigned RA format
@ -91,5 +117,5 @@ void writeRA(void *data, uint32_t color) {
// Write callback for 8bpp unsigned R format // Write callback for 8bpp unsigned R format
void writeR(void *data, uint32_t color) { void writeR(void *data, uint32_t color) {
memcpy(data, &color, 1); memcpy_neon(data, &color, 1);
} }

View File

@ -28,8 +28,10 @@
uint32_t readR(void *data); uint32_t readR(void *data);
uint32_t readRG(void *data); uint32_t readRG(void *data);
uint32_t readRGB(void *data); uint32_t readRGB(void *data);
uint32_t readRGB565(void *data);
uint32_t readRGBA(void *data); uint32_t readRGBA(void *data);
uint32_t readRGBA5551(void *data); uint32_t readRGBA5551(void *data);
uint32_t readRGBA4444(void *data);
// Write callbacks // Write callbacks
void writeR(void *data, uint32_t color); void writeR(void *data, uint32_t color);

View File

@ -37,8 +37,7 @@ void glGenTextures(GLsizei n, GLuint *res) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -67,7 +66,7 @@ void glBindTexture(GLenum target, GLuint texture) {
tex_unit->tex_id = texture; tex_unit->tex_id = texture;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -76,8 +75,7 @@ void glDeleteTextures(GLsizei n, const GLuint *gl_textures) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
// Error handling // Error handling
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
@ -138,7 +136,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
data_bpp = 1; data_bpp = 1;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
@ -150,7 +148,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
data_bpp = 2; data_bpp = 2;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
@ -158,11 +156,17 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
switch (type) { switch (type) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
data_bpp = 3; data_bpp = 3;
if (internalFormat == GL_RGB) fast_store = GL_TRUE; if (internalFormat == GL_RGB)
else read_cb = readRGB; fast_store = GL_TRUE;
else
read_cb = readRGB;
break;
case GL_UNSIGNED_SHORT_5_6_5:
data_bpp = 2;
read_cb = readRGB565;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
@ -170,15 +174,21 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
switch (type) { switch (type) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
data_bpp = 4; data_bpp = 4;
if (internalFormat == GL_RGBA) fast_store = GL_TRUE; if (internalFormat == GL_RGBA)
else read_cb = readRGBA; fast_store = GL_TRUE;
else
read_cb = readRGBA;
break; break;
case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_5_5_5_1:
data_bpp = 2; data_bpp = 2;
read_cb = readRGBA5551; read_cb = readRGBA5551;
break; break;
case GL_UNSIGNED_SHORT_4_4_4_4:
data_bpp = 2;
read_cb = readRGBA4444;
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
@ -225,22 +235,23 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
tex_format = SCE_GXM_TEXTURE_FORMAT_P8_ABGR; tex_format = SCE_GXM_TEXTURE_FORMAT_P8_ABGR;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
// Checking if texture is too big for sceGxm // Checking if texture is too big for sceGxm
if (width > GXM_TEX_MAX_SIZE || height > GXM_TEX_MAX_SIZE) { if (width > GXM_TEX_MAX_SIZE || height > GXM_TEX_MAX_SIZE) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
// Allocating texture/mipmaps depending on user call // Allocating texture/mipmaps depending on user call
tex->type = internalFormat; tex->type = internalFormat;
tex->write_cb = write_cb; tex->write_cb = write_cb;
if (level == 0) if (level == 0)
if (tex->write_cb) gpu_alloc_texture(width, height, tex_format, data, tex, data_bpp, read_cb, write_cb, fast_store); if (tex->write_cb)
else gpu_alloc_compressed_texture(width, height, tex_format, data, tex, data_bpp, read_cb); gpu_alloc_texture(width, height, tex_format, data, tex, data_bpp, read_cb, write_cb, fast_store);
else
gpu_alloc_compressed_texture(width, height, tex_format, data, tex, data_bpp, read_cb);
else { else {
gpu_alloc_mipmaps(level, tex); gpu_alloc_mipmaps(level, tex);
sceGxmTextureSetMipFilter(&tex->gxm_tex, SCE_GXM_TEXTURE_MIP_FILTER_ENABLED); sceGxmTextureSetMipFilter(&tex->gxm_tex, SCE_GXM_TEXTURE_MIP_FILTER_ENABLED);
@ -251,6 +262,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode); sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter); sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter);
sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter); sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter);
sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
// Setting palette if the format requests one // Setting palette if the format requests one
if (tex->valid && tex->palette_UID) if (tex->valid && tex->palette_UID)
@ -258,7 +270,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -281,11 +293,9 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
int i, j; int i, j;
if (xoffset + width > orig_w) { if (xoffset + width > orig_w) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} else if (yoffset + height > orig_h) { } else if (yoffset + height > orig_h) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
// Support for legacy GL1.0 format // Support for legacy GL1.0 format
@ -323,8 +333,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 1; data_bpp = 1;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return;
break; break;
} }
break; break;
@ -335,8 +344,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 2; data_bpp = 2;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return;
break; break;
} }
break; break;
@ -346,9 +354,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 3; data_bpp = 3;
read_cb = readRGB; read_cb = readRGB;
break; break;
case GL_UNSIGNED_SHORT_5_6_5:
data_bpp = 2;
read_cb = readRGB565;
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return;
break; break;
} }
break; break;
@ -362,9 +373,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
data_bpp = 2; data_bpp = 2;
read_cb = readRGBA5551; read_cb = readRGBA5551;
break; break;
case GL_UNSIGNED_SHORT_4_4_4_4:
data_bpp = 2;
read_cb = readRGBA4444;
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
return;
break; break;
} }
break; break;
@ -410,7 +424,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -431,12 +445,12 @@ void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum fo
bpp = 4; bpp = 4;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -470,7 +484,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter); sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter);
@ -492,7 +506,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter); sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter);
@ -512,7 +526,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP; tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
sceGxmTextureSetUAddrMode(&tex->gxm_tex, tex_unit->u_mode); sceGxmTextureSetUAddrMode(&tex->gxm_tex, tex_unit->u_mode);
@ -532,18 +546,22 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP; tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode); sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
break; break;
case GL_TEXTURE_LOD_BIAS: // Distant LOD bias
tex_unit->lod_bias = (uint32_t)(param + GL_MAX_TEXTURE_LOD_BIAS);
sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -593,13 +611,17 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {
tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP; // Mirror Clamp tex_unit->u_mode = SCE_GXM_TEXTURE_ADDR_MIRROR_CLAMP; // Mirror Clamp
sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode); sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode);
break; break;
case GL_TEXTURE_LOD_BIAS: // Distant LOD bias
tex_unit->lod_bias = (uint32_t)(param + GL_MAX_TEXTURE_LOD_BIAS);
sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias);
break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -607,9 +629,9 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) {
void glActiveTexture(GLenum texture) { void glActiveTexture(GLenum texture) {
// Changing current in use server texture unit // Changing current in use server texture unit
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
else } else
#endif #endif
server_texture_unit = texture - GL_TEXTURE0; server_texture_unit = texture - GL_TEXTURE0;
} }
@ -641,7 +663,7 @@ void glGenerateMipmap(GLenum target) {
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -667,12 +689,13 @@ void glTexEnvf(GLenum target, GLenum pname, GLfloat param) {
tex_unit->env_mode = ADD; tex_unit->env_mode = ADD;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break;
} }
} }
@ -682,15 +705,16 @@ void glTexEnvfv(GLenum target, GLenum pname, GLfloat *param) {
case GL_TEXTURE_ENV: case GL_TEXTURE_ENV:
switch (pname) { switch (pname) {
case GL_TEXTURE_ENV_COLOR: case GL_TEXTURE_ENV_COLOR:
memcpy(&texenv_color.r, param, sizeof(GLfloat) * 4); memcpy_neon(&texenv_color.r, param, sizeof(GLfloat) * 4);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break;
} }
} }
@ -722,12 +746,12 @@ void glTexEnvi(GLenum target, GLenum pname, GLint param) {
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }

View File

@ -25,8 +25,8 @@
#include "stb_dxt.h" #include "stb_dxt.h"
#ifndef MIN #ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a)<(b))?(b):(a)) #define MAX(a, b) (((a) < (b)) ? (b) : (a))
#endif #endif
// VRAM usage setting // VRAM usage setting
@ -45,27 +45,25 @@ static unsigned int pool_size = 0;
vglMemType frag_usse_type; vglMemType frag_usse_type;
vglMemType vert_usse_type; vglMemType vert_usse_type;
uint64_t morton_1(uint64_t x) uint64_t morton_1(uint64_t x) {
{ x = x & 0x5555555555555555;
x = x & 0x5555555555555555; x = (x | (x >> 1)) & 0x3333333333333333;
x = (x | (x >> 1)) & 0x3333333333333333; x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F;
x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F; x = (x | (x >> 4)) & 0x00FF00FF00FF00FF;
x = (x | (x >> 4)) & 0x00FF00FF00FF00FF; x = (x | (x >> 8)) & 0x0000FFFF0000FFFF;
x = (x | (x >> 8)) & 0x0000FFFF0000FFFF; x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF;
x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF; return x;
return x;
} }
void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) {
{ *x = morton_1(d);
*x = morton_1(d); *y = morton_1(d >> 1);
*y = morton_1(d >> 1);
} }
void extract_block(const uint8_t *src, int width, uint8_t *block) { void extract_block(const uint8_t *src, int width, uint8_t *block) {
int j; int j;
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
memcpy(&block[j * 4 * 4], src, 16); memcpy_neon(&block[j * 4 * 4], src, 16);
src += width * 4; src += width * 4;
} }
} }
@ -77,8 +75,10 @@ void dxt_compress(uint8_t *dst, uint8_t *src, int w, int h, int isdxt5) {
uint64_t d, offs_x, offs_y; uint64_t d, offs_x, offs_y;
for (d = 0; d < num_blocks; d++) { for (d = 0; d < num_blocks; d++) {
d2xy_morton(d, &offs_x, &offs_y); d2xy_morton(d, &offs_x, &offs_y);
if (offs_x * 4 >= h) continue; if (offs_x * 4 >= h)
if (offs_y * 4 >= w) continue; continue;
if (offs_y * 4 >= w)
continue;
extract_block(src + offs_y * 16 + offs_x * w * 16, w, block); extract_block(src + offs_y * 16 + offs_x * w * 16, w, block);
stb_compress_dxt_block(dst, block, isdxt5, STB_DXT_HIGHQUAL); stb_compress_dxt_block(dst, block, isdxt5, STB_DXT_HIGHQUAL);
dst += isdxt5 ? 16 : 8; dst += isdxt5 ? 16 : 8;
@ -239,7 +239,7 @@ palette *gpu_alloc_palette(const void *data, uint32_t w, uint32_t bpe) {
if (data == NULL) if (data == NULL)
memset(texture_palette, 0, 256 * sizeof(uint32_t)); memset(texture_palette, 0, 256 * sizeof(uint32_t));
else if (bpe == 4) else if (bpe == 4)
memcpy(texture_palette, data, w * sizeof(uint32_t)); memcpy_neon(texture_palette, data, w * sizeof(uint32_t));
res->data = texture_palette; res->data = texture_palette;
// Returning palette // Returning palette
@ -274,11 +274,11 @@ void gpu_alloc_texture(uint32_t w, uint32_t h, SceGxmTextureFormat format, const
int i, j; int i, j;
uint8_t *src = (uint8_t *)data; uint8_t *src = (uint8_t *)data;
uint8_t *dst; uint8_t *dst;
if (fast_store) { // Internal Format and Data Format are the same, we can just use memcpy for better performance if (fast_store) { // Internal Format and Data Format are the same, we can just use memcpy_neon for better performance
uint32_t line_size = w * bpp; uint32_t line_size = w * bpp;
for (i = 0; i < h; i++) { for (i = 0; i < h; i++) {
dst = ((uint8_t *)texture_data) + (ALIGN(w, 8) * bpp) * i; dst = ((uint8_t *)texture_data) + (ALIGN(w, 8) * bpp) * i;
memcpy(dst, src, line_size); memcpy_neon(dst, src, line_size);
src += line_size; src += line_size;
} }
} else { // Different internal and data formats, we need to go with slower callbacks system } else { // Different internal and data formats, we need to go with slower callbacks system
@ -317,7 +317,8 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo
// Calculating swizzled compressed texture size on memory // Calculating swizzled compressed texture size on memory
tex->mtype = use_vram ? VGL_MEM_VRAM : VGL_MEM_RAM; tex->mtype = use_vram ? VGL_MEM_VRAM : VGL_MEM_RAM;
int tex_size = w * h; int tex_size = w * h;
if (alignment == 8) tex_size /= 2; if (alignment == 8)
tex_size /= 2;
// Allocating texture data buffer // Allocating texture data buffer
void *texture_data = gpu_alloc_mapped(tex_size, &tex->mtype); void *texture_data = gpu_alloc_mapped(tex_size, &tex->mtype);
@ -340,8 +341,7 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo
}*/ }*/
// Performing swizzling and DXT compression // Performing swizzling and DXT compression
dxt_compress(texture_data, (void*)data, w, h, alignment == 16); dxt_compress(texture_data, (void *)data, w, h, alignment == 16);
//swizzle(texture_data, tmp2, w, h, alignment << 3); //swizzle(texture_data, tmp2, w, h, alignment << 3);
//free(tmp); //free(tmp);
@ -418,7 +418,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) {
has_temp_buffer = GL_FALSE; has_temp_buffer = GL_FALSE;
temp = sceGxmTextureGetData(&tex->gxm_tex); temp = sceGxmTextureGetData(&tex->gxm_tex);
} else { } else {
memcpy(temp, sceGxmTextureGetData(&tex->gxm_tex), stride * orig_h * bpp); memcpy_neon(temp, sceGxmTextureGetData(&tex->gxm_tex), stride * orig_h * bpp);
gpu_free_texture(tex); gpu_free_texture(tex);
} }
@ -427,7 +427,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) {
void *texture_data = gpu_alloc_mapped(size, &tex->mtype); void *texture_data = gpu_alloc_mapped(size, &tex->mtype);
// Moving back old texture data from heap to texture memblock // Moving back old texture data from heap to texture memblock
memcpy(texture_data, temp, stride * orig_h * bpp); memcpy_neon(texture_data, temp, stride * orig_h * bpp);
if (has_temp_buffer) if (has_temp_buffer)
free(temp); free(temp);
else else

View File

@ -36,7 +36,7 @@ void matrix4x4_identity(matrix4x4 m) {
} }
void matrix4x4_copy(matrix4x4 dst, const matrix4x4 src) { void matrix4x4_copy(matrix4x4 dst, const matrix4x4 src) {
memcpy(dst, src, sizeof(matrix4x4)); memcpy_neon(dst, src, sizeof(matrix4x4));
} }
void matrix4x4_multiply(matrix4x4 dst, const matrix4x4 src1, const matrix4x4 src2) { void matrix4x4_multiply(matrix4x4 dst, const matrix4x4 src1, const matrix4x4 src2) {

View File

@ -272,25 +272,31 @@ int vgl_mem_init(size_t size_ram, size_t size_cdram, size_t size_phycont) {
if (mempool_addr[0] != NULL) if (mempool_addr[0] != NULL)
vgl_mem_term(); vgl_mem_term();
mempool_size[0] = ALIGN(size_cdram, 256 * 1024); mempool_size[VGL_MEM_VRAM - 1] = ALIGN(size_cdram, 256 * 1024);
mempool_size[1] = ALIGN(size_ram, 4 * 1024); mempool_size[VGL_MEM_RAM - 1] = ALIGN(size_ram, 4 * 1024);
mempool_size[2] = ALIGN(size_phycont, 256 * 1024); mempool_size[VGL_MEM_SLOW - 1] = ALIGN(size_phycont, 256 * 1024);
mempool_id[0] = sceKernelAllocMemBlock("cdram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, mempool_size[0], NULL); if (size_cdram)
mempool_id[1] = sceKernelAllocMemBlock("ram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, mempool_size[1], NULL); mempool_id[VGL_MEM_VRAM - 1] = sceKernelAllocMemBlock("cdram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, mempool_size[VGL_MEM_VRAM - 1], NULL);
mempool_id[2] = sceKernelAllocMemBlock("phycont_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW, mempool_size[2], NULL); mempool_id[VGL_MEM_RAM - 1] = sceKernelAllocMemBlock("ram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, mempool_size[VGL_MEM_RAM - 1], NULL);
if (size_phycont)
mempool_id[VGL_MEM_SLOW - 1] = sceKernelAllocMemBlock("phycont_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW, mempool_size[VGL_MEM_SLOW - 1], NULL);
for (int i = 0; i < VGL_MEM_TYPE_COUNT - 2; i++) { for (int i = 0; i < VGL_MEM_TYPE_COUNT - 2; i++) {
sceKernelGetMemBlockBase(mempool_id[i], &mempool_addr[i]); if (mempool_size[i]) {
sceGxmMapMemory(mempool_addr[i], mempool_size[i], SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); sceKernelGetMemBlockBase(mempool_id[i], &mempool_addr[i]);
sceGxmMapMemory(mempool_addr[i], mempool_size[i], SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
}
} }
// Initialize heap // Initialize heap
heap_init(); heap_init();
// Add memblocks to heap // Add memblocks to heap
heap_extend(VGL_MEM_VRAM, mempool_addr[0], mempool_size[0]); if (size_cdram)
heap_extend(VGL_MEM_VRAM, mempool_addr[0], mempool_size[0]);
heap_extend(VGL_MEM_RAM, mempool_addr[1], mempool_size[1]); heap_extend(VGL_MEM_RAM, mempool_addr[1], mempool_size[1]);
heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]); if (size_phycont)
heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]);
return 1; return 1;
} }

View File

@ -684,7 +684,7 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a
dest += 8; dest += 8;
// make a new copy of the data in which alpha is opaque, // make a new copy of the data in which alpha is opaque,
// because code uses a fast test for color constancy // because code uses a fast test for color constancy
memcpy(data, src, 4*16); memcpy_neon(data, src, 4*16);
for (i=0; i < 16; ++i) for (i=0; i < 16; ++i)
data[i][3] = 255; data[i][3] = 255;
src = &data[0][0]; src = &data[0][0];

View File

@ -36,6 +36,84 @@
#include "shaders/texture2d_rgba_v.h" #include "shaders/texture2d_rgba_v.h"
#include "shaders/texture2d_v.h" #include "shaders/texture2d_v.h"
// Disable color buffer shader
SceGxmShaderPatcherId disable_color_buffer_fragment_id;
const SceGxmProgramParameter *disable_color_buffer_position;
SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched;
const SceGxmProgramParameter *clear_depth;
// Clear shader
SceGxmShaderPatcherId clear_vertex_id;
SceGxmShaderPatcherId clear_fragment_id;
const SceGxmProgramParameter *clear_position;
const SceGxmProgramParameter *clear_color;
SceGxmVertexProgram *clear_vertex_program_patched;
SceGxmFragmentProgram *clear_fragment_program_patched;
// Color (RGBA/RGB) shader
SceGxmShaderPatcherId rgba_vertex_id;
SceGxmShaderPatcherId rgb_vertex_id;
SceGxmShaderPatcherId rgba_fragment_id;
const SceGxmProgramParameter *rgba_position;
const SceGxmProgramParameter *rgba_color;
const SceGxmProgramParameter *rgba_wvp;
const SceGxmProgramParameter *rgb_position;
const SceGxmProgramParameter *rgb_color;
const SceGxmProgramParameter *rgb_wvp;
SceGxmVertexProgram *rgba_vertex_program_patched;
SceGxmVertexProgram *rgba_u8n_vertex_program_patched;
SceGxmVertexProgram *rgb_vertex_program_patched;
SceGxmVertexProgram *rgb_u8n_vertex_program_patched;
SceGxmFragmentProgram *rgba_fragment_program_patched;
const SceGxmProgram *rgba_fragment_program;
// Texture2D shader
SceGxmShaderPatcherId texture2d_vertex_id;
SceGxmShaderPatcherId texture2d_fragment_id;
const SceGxmProgramParameter *texture2d_position;
const SceGxmProgramParameter *texture2d_texcoord;
const SceGxmProgramParameter *texture2d_wvp;
const SceGxmProgramParameter *texture2d_alpha_cut;
const SceGxmProgramParameter *texture2d_alpha_op;
const SceGxmProgramParameter *texture2d_tint_color;
const SceGxmProgramParameter *texture2d_tex_env;
const SceGxmProgramParameter *texture2d_clip_plane0;
const SceGxmProgramParameter *texture2d_clip_plane0_eq;
const SceGxmProgramParameter *texture2d_mv;
const SceGxmProgramParameter *texture2d_fog_mode;
const SceGxmProgramParameter *texture2d_fog_near;
const SceGxmProgramParameter *texture2d_fog_far;
const SceGxmProgramParameter *texture2d_fog_density;
const SceGxmProgramParameter *texture2d_fog_color;
const SceGxmProgramParameter *texture2d_tex_env_color;
SceGxmVertexProgram *texture2d_vertex_program_patched;
SceGxmFragmentProgram *texture2d_fragment_program_patched;
const SceGxmProgram *texture2d_fragment_program;
// Texture2D+RGBA shader
SceGxmShaderPatcherId texture2d_rgba_vertex_id;
SceGxmShaderPatcherId texture2d_rgba_fragment_id;
const SceGxmProgramParameter *texture2d_rgba_position;
const SceGxmProgramParameter *texture2d_rgba_texcoord;
const SceGxmProgramParameter *texture2d_rgba_wvp;
const SceGxmProgramParameter *texture2d_rgba_alpha_cut;
const SceGxmProgramParameter *texture2d_rgba_alpha_op;
const SceGxmProgramParameter *texture2d_rgba_color;
const SceGxmProgramParameter *texture2d_rgba_tex_env;
const SceGxmProgramParameter *texture2d_rgba_clip_plane0;
const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq;
const SceGxmProgramParameter *texture2d_rgba_mv;
const SceGxmProgramParameter *texture2d_rgba_fog_mode;
const SceGxmProgramParameter *texture2d_rgba_fog_near;
const SceGxmProgramParameter *texture2d_rgba_fog_far;
const SceGxmProgramParameter *texture2d_rgba_fog_density;
const SceGxmProgramParameter *texture2d_rgba_fog_color;
const SceGxmProgramParameter *texture2d_rgba_tex_env_color;
SceGxmVertexProgram *texture2d_rgba_vertex_program_patched;
SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched;
SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched;
const SceGxmProgram *texture2d_rgba_fragment_program;
typedef struct gpubuffer { typedef struct gpubuffer {
void *ptr; void *ptr;
} gpubuffer; } gpubuffer;
@ -203,7 +281,7 @@ void vglUseVramForUSSE(GLboolean usage) {
use_vram_for_usse = usage; use_vram_for_usse = usage;
} }
void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa) { void vglInitWithCustomSizes(uint32_t gpu_pool_size, int width, int height, int ram_pool_size, int cdram_pool_size, int phycont_pool_size, SceGxmMultisampleMode msaa) {
// Setting our display size // Setting our display size
msaa_mode = msaa; msaa_mode = msaa;
DISPLAY_WIDTH = width; DISPLAY_WIDTH = width;
@ -231,13 +309,8 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
// Initializing sceGxm // Initializing sceGxm
initGxm(); initGxm();
// Getting max allocatable CDRAM and RAM memory
SceKernelFreeMemorySizeInfo info;
info.size = sizeof(SceKernelFreeMemorySizeInfo);
sceKernelGetFreeMemorySize(&info);
// Initializing memory heap for CDRAM and RAM memory // Initializing memory heap for CDRAM and RAM memory
vgl_mem_init(info.size_user > ram_threshold ? info.size_user - ram_threshold : info.size_user, info.size_cdram - 256 * 1024, info.size_phycont - 1 * 1024 * 1024); // leave some just in case mem_init(ram_pool_size, cdram_pool_size, phycont_pool_size);
// Initializing sceGxm context // Initializing sceGxm context
initGxmContext(); initGxmContext();
@ -608,11 +681,12 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
} }
texture_units[i].env_mode = MODULATE; texture_units[i].env_mode = MODULATE;
texture_units[i].tex_id = 0; texture_units[i].tex_id = 0;
texture_units[i].enabled = 0; texture_units[i].enabled = GL_FALSE;
texture_units[i].min_filter = SCE_GXM_TEXTURE_FILTER_LINEAR; texture_units[i].min_filter = SCE_GXM_TEXTURE_FILTER_LINEAR;
texture_units[i].mag_filter = SCE_GXM_TEXTURE_FILTER_LINEAR; texture_units[i].mag_filter = SCE_GXM_TEXTURE_FILTER_LINEAR;
texture_units[i].u_mode = SCE_GXM_TEXTURE_ADDR_REPEAT; texture_units[i].u_mode = SCE_GXM_TEXTURE_ADDR_REPEAT;
texture_units[i].v_mode = SCE_GXM_TEXTURE_ADDR_REPEAT; texture_units[i].v_mode = SCE_GXM_TEXTURE_ADDR_REPEAT;
texture_units[i].lod_bias = GL_MAX_TEXTURE_LOD_BIAS; // sceGxm range is 0 - (GL_MAX_TEXTURE_LOD_BIAS*2 + 1)
} }
// Init custom shaders // Init custom shaders
@ -635,6 +709,24 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre
sceGxmMapMemory(addr, _newlib_heap_size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); sceGxmMapMemory(addr, _newlib_heap_size, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
} }
void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa) {
// Initializing sceGxm
initGxm();
// Getting max allocatable CDRAM and RAM memory
if (system_app_mode) {
SceAppMgrBudgetInfo info;
info.size = sizeof(SceAppMgrBudgetInfo);
sceAppMgrGetBudgetInfo(&info);
vglInitWithCustomSizes(gpu_pool_size, width, height, info.free_user_rw > ram_threshold ? info.free_user_rw - ram_threshold : info.free_user_rw, 0, 0, msaa);
} else {
SceKernelFreeMemorySizeInfo info;
info.size = sizeof(SceKernelFreeMemorySizeInfo);
sceKernelGetFreeMemorySize(&info);
vglInitWithCustomSizes(gpu_pool_size, width, height, info.size_user > ram_threshold ? info.size_user - ram_threshold : info.size_user, info.size_cdram - 256 * 1024, info.size_phycont - 1 * 1024 * 1024, msaa);
}
}
void vglInit(uint32_t gpu_pool_size) { void vglInit(uint32_t gpu_pool_size) {
vglInitExtended(gpu_pool_size, DISPLAY_WIDTH_DEF, DISPLAY_HEIGHT_DEF, 0x1000000, SCE_GXM_MULTISAMPLE_NONE); vglInitExtended(gpu_pool_size, DISPLAY_WIDTH_DEF, DISPLAY_HEIGHT_DEF, 0x1000000, SCE_GXM_MULTISAMPLE_NONE);
} }
@ -699,8 +791,7 @@ void glGenBuffers(GLsizei n, GLuint *res) {
int i = 0, j = 0; int i = 0, j = 0;
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
for (i = 0; i < BUFFERS_NUM; i++) { for (i = 0; i < BUFFERS_NUM; i++) {
@ -716,8 +807,7 @@ void glGenBuffers(GLsizei n, GLuint *res) {
void glBindBuffer(GLenum target, GLuint buffer) { void glBindBuffer(GLenum target, GLuint buffer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((buffer != 0x0000) && ((buffer >= BUFFERS_ADDR + BUFFERS_NUM) || (buffer < BUFFERS_ADDR))) { if ((buffer != 0x0000) && ((buffer >= BUFFERS_ADDR + BUFFERS_NUM) || (buffer < BUFFERS_ADDR))) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
switch (target) { switch (target) {
@ -728,7 +818,7 @@ void glBindBuffer(GLenum target, GLuint buffer) {
index_array_unit = buffer - BUFFERS_ADDR; index_array_unit = buffer - BUFFERS_ADDR;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -736,7 +826,7 @@ void glBindBuffer(GLenum target, GLuint buffer) {
void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) { void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (n < 0) { if (n < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return; return;
} }
#endif #endif
@ -756,8 +846,7 @@ void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) {
void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage) { void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (size < 0) { if (size < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
int idx = 0; int idx = 0;
@ -769,12 +858,12 @@ void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage)
idx = index_array_unit; idx = index_array_unit;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
vglMemType type = VGL_MEM_VRAM; vglMemType type = VGL_MEM_VRAM;
gpu_buffers[idx].ptr = gpu_alloc_mapped(size, &type); gpu_buffers[idx].ptr = gpu_alloc_mapped(size, &type);
memcpy(gpu_buffers[idx].ptr, data, size); memcpy_neon(gpu_buffers[idx].ptr, data, size);
} }
void glBlendFunc(GLenum sfactor, GLenum dfactor) { void glBlendFunc(GLenum sfactor, GLenum dfactor) {
@ -813,7 +902,7 @@ void glBlendFunc(GLenum sfactor, GLenum dfactor) {
blend_sfactor_rgb = blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_sfactor_rgb = blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (dfactor) { switch (dfactor) {
@ -851,7 +940,7 @@ void glBlendFunc(GLenum sfactor, GLenum dfactor) {
blend_dfactor_rgb = blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_dfactor_rgb = blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (blend_state) if (blend_state)
@ -894,7 +983,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_sfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_sfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (dstRGB) { switch (dstRGB) {
@ -932,7 +1021,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_dfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_dfactor_rgb = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (srcAlpha) { switch (srcAlpha) {
@ -970,7 +1059,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (dstAlpha) { switch (dstAlpha) {
@ -1008,7 +1097,7 @@ void glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum d
blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; blend_dfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (blend_state) if (blend_state)
@ -1033,7 +1122,7 @@ void glBlendEquation(GLenum mode) {
blend_func_rgb = blend_func_a = SCE_GXM_BLEND_FUNC_MAX; blend_func_rgb = blend_func_a = SCE_GXM_BLEND_FUNC_MAX;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (blend_state) if (blend_state)
@ -1058,7 +1147,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
blend_func_rgb = SCE_GXM_BLEND_FUNC_MAX; blend_func_rgb = SCE_GXM_BLEND_FUNC_MAX;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
switch (modeAlpha) { switch (modeAlpha) {
@ -1078,7 +1167,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
blend_func_a = SCE_GXM_BLEND_FUNC_MAX; blend_func_a = SCE_GXM_BLEND_FUNC_MAX;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (blend_state) if (blend_state)
@ -1104,8 +1193,7 @@ void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) { if ((stride < 0) || (size < 2) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1117,7 +1205,7 @@ void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *poin
tex_unit->vertex_array.size = sizeof(GLshort); tex_unit->vertex_array.size = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -1129,8 +1217,7 @@ void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *poin
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 3) || (size > 4)) { if ((stride < 0) || (size < 3) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1142,7 +1229,7 @@ void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *point
tex_unit->color_array.size = sizeof(GLshort); tex_unit->color_array.size = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -1154,8 +1241,7 @@ void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *point
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) { if ((stride < 0) || (size < 2) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1167,7 +1253,7 @@ void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *po
tex_unit->texture_array.size = sizeof(GLshort); tex_unit->texture_array.size = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
@ -1209,7 +1295,7 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
skip_draw = GL_TRUE; skip_draw = GL_TRUE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (!skip_draw) { if (!skip_draw) {
@ -1319,20 +1405,20 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0, tex_set = 0, clr_set = 0; uint8_t vec_set = 0, tex_set = 0, clr_set = 0;
if (tex_unit->vertex_array.stride == 0) { if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.num * tex_unit->vertex_array.size)); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.num * tex_unit->vertex_array.size));
memcpy(&vertices[0], ptr, count * sizeof(vector3f)); memcpy_neon(&vertices[0], ptr, count * sizeof(vector3f));
vec_set = 1; vec_set = 1;
} else } else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * tex_unit->vertex_array.stride); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * tex_unit->vertex_array.stride);
if (tex_unit->texture_array.stride == 0) { if (tex_unit->texture_array.stride == 0) {
ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * (tex_unit->texture_array.num * tex_unit->texture_array.size)); ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * (tex_unit->texture_array.num * tex_unit->texture_array.size));
memcpy(&uv_map[0], ptr_tex, count * sizeof(vector2f)); memcpy_neon(&uv_map[0], ptr_tex, count * sizeof(vector2f));
tex_set = 1; tex_set = 1;
} else } else
ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * tex_unit->texture_array.stride); ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer) + (first * tex_unit->texture_array.stride);
if (tex_unit->color_array_state) { if (tex_unit->color_array_state) {
if (tex_unit->color_array.stride == 0) { if (tex_unit->color_array.stride == 0) {
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * sizeof(vector4f)); ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * sizeof(vector4f));
memcpy(&colors[0], ptr_clr, count * sizeof(vector4f)); memcpy_neon(&colors[0], ptr_clr, count * sizeof(vector4f));
clr_set = 1; clr_set = 1;
} else } else
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.stride); ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.stride);
@ -1340,15 +1426,15 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
if (!vec_set) { if (!vec_set) {
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
} }
if (!tex_set) { if (!tex_set) {
memcpy(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num); memcpy_neon(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
ptr_tex += tex_unit->texture_array.stride; ptr_tex += tex_unit->texture_array.stride;
} }
if (tex_unit->color_array_state && (!clr_set)) { if (tex_unit->color_array_state && (!clr_set)) {
memcpy(&colors[n], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num); memcpy_neon(&colors[n], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr_clr += tex_unit->color_array.stride; ptr_clr += tex_unit->color_array.stride;
} }
indices[n] = n; indices[n] = n;
@ -1390,24 +1476,24 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0, clr_set = 0; uint8_t vec_set = 0, clr_set = 0;
if (tex_unit->vertex_array.stride == 0) { if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size))); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size)));
memcpy(&vertices[n], ptr, count * sizeof(vector3f)); memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f));
vec_set = 1; vec_set = 1;
} else } else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride)); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride));
if (tex_unit->color_array.stride == 0) { if (tex_unit->color_array.stride == 0) {
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * ((tex_unit->color_array.num * tex_unit->color_array.size))); ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * ((tex_unit->color_array.num * tex_unit->color_array.size)));
memcpy(&colors[n], ptr_clr, count * tex_unit->color_array.num * tex_unit->color_array.size); memcpy_neon(&colors[n], ptr_clr, count * tex_unit->color_array.num * tex_unit->color_array.size);
clr_set = 1; clr_set = 1;
} else } else
ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.size); ptr_clr = ((uint8_t *)tex_unit->color_array.pointer) + (first * tex_unit->color_array.size);
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
if (!vec_set) { if (!vec_set) {
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
} }
if (!clr_set) { if (!clr_set) {
memcpy(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num); memcpy_neon(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr_clr += tex_unit->color_array.stride; ptr_clr += tex_unit->color_array.stride;
} }
indices[n] = n; indices[n] = n;
@ -1430,7 +1516,7 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f)); colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f));
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
memcpy(&colors[n], &current_color.r, sizeof(vector4f)); memcpy_neon(&colors[n], &current_color.r, sizeof(vector4f));
indices[n] = n; indices[n] = n;
} }
} else { } else {
@ -1441,17 +1527,17 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
uint8_t vec_set = 0; uint8_t vec_set = 0;
if (tex_unit->vertex_array.stride == 0) { if (tex_unit->vertex_array.stride == 0) {
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size))); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * ((tex_unit->vertex_array.num * tex_unit->vertex_array.size)));
memcpy(&vertices[n], ptr, count * sizeof(vector3f)); memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f));
vec_set = 1; vec_set = 1;
} else } else
ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride)); ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride));
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
if (!vec_set) { if (!vec_set) {
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
} }
memcpy(&colors[n], &current_color.r, sizeof(vector4f)); memcpy_neon(&colors[n], &current_color.r, sizeof(vector4f));
indices[n] = n; indices[n] = n;
} }
} }
@ -1470,12 +1556,13 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
if (tex_unit->vertex_array_state) { if (tex_unit->vertex_array_state) {
GLboolean skip_draw = GL_FALSE; GLboolean skip_draw = GL_FALSE;
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (type != GL_UNSIGNED_SHORT) if (type != GL_UNSIGNED_SHORT) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
else if (phase == MODEL_CREATION) } else if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
else if (count < 0) } else if (count < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif #endif
switch (mode) { switch (mode) {
case GL_POINTS: case GL_POINTS:
@ -1500,7 +1587,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
skip_draw = GL_TRUE; skip_draw = GL_TRUE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (!skip_draw) { if (!skip_draw) {
@ -1582,7 +1669,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices); indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else { else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
memcpy(indices, gl_indices, sizeof(uint16_t) * count); memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
} }
if (vertex_array_unit >= 0) { if (vertex_array_unit >= 0) {
vertices = (vector3f *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->vertex_array.pointer); vertices = (vector3f *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->vertex_array.pointer);
@ -1602,11 +1689,11 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uv_map = (vector2f *)gpu_pool_memalign(vertex_count_int * sizeof(vector2f), sizeof(vector2f)); uv_map = (vector2f *)gpu_pool_memalign(vertex_count_int * sizeof(vector2f), sizeof(vector2f));
colors = (vector4f *)gpu_pool_memalign(vertex_count_int * sizeof(vector4f), sizeof(vector4f)); colors = (vector4f *)gpu_pool_memalign(vertex_count_int * sizeof(vector4f), sizeof(vector4f));
if (tex_unit->vertex_array.stride == 0) if (tex_unit->vertex_array.stride == 0)
memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num)); memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if (tex_unit->texture_array.stride == 0) if (tex_unit->texture_array.stride == 0)
memcpy(uv_map, tex_unit->texture_array.pointer, vertex_count_int * (tex_unit->texture_array.size * tex_unit->texture_array.num)); memcpy_neon(uv_map, tex_unit->texture_array.pointer, vertex_count_int * (tex_unit->texture_array.size * tex_unit->texture_array.num));
if (tex_unit->color_array_state && (tex_unit->color_array.stride == 0)) if (tex_unit->color_array_state && (tex_unit->color_array.stride == 0))
memcpy(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num)); memcpy_neon(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
if ((tex_unit->vertex_array.stride != 0) || (tex_unit->texture_array.stride != 0)) { if ((tex_unit->vertex_array.stride != 0) || (tex_unit->texture_array.stride != 0)) {
if (tex_unit->vertex_array.stride != 0) if (tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex))); memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
@ -1614,9 +1701,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uint8_t *ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer); uint8_t *ptr_tex = ((uint8_t *)tex_unit->texture_array.pointer);
for (n = 0; n < vertex_count_int; n++) { for (n = 0; n < vertex_count_int; n++) {
if (tex_unit->vertex_array.stride != 0) if (tex_unit->vertex_array.stride != 0)
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
if (tex_unit->texture_array.stride != 0) if (tex_unit->texture_array.stride != 0)
memcpy(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num); memcpy_neon(&uv_map[n], ptr_tex, tex_unit->texture_array.size * tex_unit->texture_array.num);
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
ptr_tex += tex_unit->texture_array.stride; ptr_tex += tex_unit->texture_array.stride;
} }
@ -1639,7 +1726,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices); indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else { else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
memcpy(indices, gl_indices, sizeof(uint16_t) * count); memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
} }
if (vertex_array_unit >= 0) { if (vertex_array_unit >= 0) {
colors = (uint8_t *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->color_array.pointer); colors = (uint8_t *)((uint32_t)gpu_buffers[vertex_array_unit].ptr + (uint32_t)tex_unit->color_array.pointer);
@ -1656,9 +1743,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f)); vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f));
colors = (uint8_t *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size); colors = (uint8_t *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size);
if (tex_unit->vertex_array.stride == 0) if (tex_unit->vertex_array.stride == 0)
memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num)); memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if (tex_unit->color_array.stride == 0) if (tex_unit->color_array.stride == 0)
memcpy(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num)); memcpy_neon(colors, tex_unit->color_array.pointer, vertex_count_int * (tex_unit->color_array.size * tex_unit->color_array.num));
if ((tex_unit->vertex_array.stride != 0) || (tex_unit->color_array.stride != 0)) { if ((tex_unit->vertex_array.stride != 0) || (tex_unit->color_array.stride != 0)) {
if (tex_unit->vertex_array.stride != 0) if (tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex))); memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
@ -1666,9 +1753,9 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
uint8_t *ptr_clr = ((uint8_t *)tex_unit->color_array.pointer); uint8_t *ptr_clr = ((uint8_t *)tex_unit->color_array.pointer);
for (n = 0; n < vertex_count_int; n++) { for (n = 0; n < vertex_count_int; n++) {
if (tex_unit->vertex_array.stride != 0) if (tex_unit->vertex_array.stride != 0)
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
if (tex_unit->color_array.stride != 0) if (tex_unit->color_array.stride != 0)
memcpy(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num); memcpy_neon(&colors[n * tex_unit->color_array.num * tex_unit->color_array.size], ptr_clr, tex_unit->color_array.size * tex_unit->color_array.num);
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
ptr_clr += tex_unit->color_array.stride; ptr_clr += tex_unit->color_array.stride;
} }
@ -1686,7 +1773,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices); indices = (uint16_t *)((uint32_t)gpu_buffers[index_array_unit].ptr + (uint32_t)gl_indices);
else { else {
indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t));
memcpy(indices, gl_indices, sizeof(uint16_t) * count); memcpy_neon(indices, gl_indices, sizeof(uint16_t) * count);
} }
int n = 0, j = 0; int n = 0, j = 0;
uint64_t vertex_count_int = 0; uint64_t vertex_count_int = 0;
@ -1702,14 +1789,14 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in
vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f)); vertices = (vector3f *)gpu_pool_memalign(vertex_count_int * sizeof(vector3f), sizeof(vector3f));
colors = (vector4f *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size); colors = (vector4f *)gpu_pool_memalign(vertex_count_int * tex_unit->color_array.num * tex_unit->color_array.size, tex_unit->color_array.num * tex_unit->color_array.size);
if ((!vertex_array_unit) && tex_unit->vertex_array.stride == 0) if ((!vertex_array_unit) && tex_unit->vertex_array.stride == 0)
memcpy(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num)); memcpy_neon(vertices, tex_unit->vertex_array.pointer, vertex_count_int * (tex_unit->vertex_array.size * tex_unit->vertex_array.num));
if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0) if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0)
memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex))); memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex)));
uint8_t *ptr = ((uint8_t *)tex_unit->vertex_array.pointer); uint8_t *ptr = ((uint8_t *)tex_unit->vertex_array.pointer);
for (n = 0; n < vertex_count_int; n++) { for (n = 0; n < vertex_count_int; n++) {
if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0) if ((!vertex_array_unit) && tex_unit->vertex_array.stride != 0)
memcpy(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num);
memcpy(&colors[n], &current_color.r, sizeof(vector4f)); memcpy_neon(&colors[n], &current_color.r, sizeof(vector4f));
if (!vertex_array_unit) if (!vertex_array_unit)
ptr += tex_unit->vertex_array.stride; ptr += tex_unit->vertex_array.stride;
} }
@ -1734,7 +1821,7 @@ void glEnableClientState(GLenum array) {
tex_unit->texture_array_state = GL_TRUE; tex_unit->texture_array_state = GL_TRUE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
@ -1752,16 +1839,16 @@ void glDisableClientState(GLenum array) {
tex_unit->texture_array_state = GL_FALSE; tex_unit->texture_array_state = GL_FALSE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
} }
void glClientActiveTexture(GLenum texture) { void glClientActiveTexture(GLenum texture) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) {
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
else } else
#endif #endif
client_texture_unit = texture - GL_TEXTURE0; client_texture_unit = texture - GL_TEXTURE0;
} }
@ -1771,8 +1858,7 @@ void glClientActiveTexture(GLenum texture) {
void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) { void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) { if ((stride < 0) || (size < 2) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1785,18 +1871,18 @@ void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, con
bpe = sizeof(GLshort); bpe = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
tex_unit->vertex_object = gpu_pool_memalign(count * bpe * size, bpe * size); tex_unit->vertex_object = gpu_pool_memalign(count * bpe * size, bpe * size);
if (stride == 0) if (stride == 0)
memcpy(tex_unit->vertex_object, pointer, count * bpe * size); memcpy_neon(tex_unit->vertex_object, pointer, count * bpe * size);
else { else {
int i; int i;
uint8_t *dst = (uint8_t *)tex_unit->vertex_object; uint8_t *dst = (uint8_t *)tex_unit->vertex_object;
uint8_t *src = (uint8_t *)pointer; uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memcpy(dst, src, bpe * size); memcpy_neon(dst, src, bpe * size);
dst += (bpe * size); dst += (bpe * size);
src += stride; src += stride;
} }
@ -1806,8 +1892,7 @@ void vglVertexPointer(GLint size, GLenum type, GLsizei stride, GLuint count, con
void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) { void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 3) || (size > 4)) { if ((stride < 0) || (size < 3) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1823,19 +1908,19 @@ void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, cons
bpe = sizeof(uint8_t); bpe = sizeof(uint8_t);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
tex_unit->color_object = gpu_pool_memalign(count * bpe * size, bpe * size); tex_unit->color_object = gpu_pool_memalign(count * bpe * size, bpe * size);
tex_unit->color_object_type = type; tex_unit->color_object_type = type;
if (stride == 0) if (stride == 0)
memcpy(tex_unit->color_object, pointer, count * bpe * size); memcpy_neon(tex_unit->color_object, pointer, count * bpe * size);
else { else {
int i; int i;
uint8_t *dst = (uint8_t *)tex_unit->color_object; uint8_t *dst = (uint8_t *)tex_unit->color_object;
uint8_t *src = (uint8_t *)pointer; uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memcpy(dst, src, bpe * size); memcpy_neon(dst, src, bpe * size);
dst += (bpe * size); dst += (bpe * size);
src += stride; src += stride;
} }
@ -1845,8 +1930,7 @@ void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, cons
void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) { void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if ((stride < 0) || (size < 2) || (size > 4)) { if ((stride < 0) || (size < 2) || (size > 4)) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1859,18 +1943,18 @@ void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, c
bpe = sizeof(GLshort); bpe = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
tex_unit->texture_object = gpu_pool_memalign(count * bpe * size, bpe * size); tex_unit->texture_object = gpu_pool_memalign(count * bpe * size, bpe * size);
if (stride == 0) if (stride == 0)
memcpy(tex_unit->texture_object, pointer, count * bpe * size); memcpy_neon(tex_unit->texture_object, pointer, count * bpe * size);
else { else {
int i; int i;
uint8_t *dst = (uint8_t *)tex_unit->texture_object; uint8_t *dst = (uint8_t *)tex_unit->texture_object;
uint8_t *src = (uint8_t *)pointer; uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memcpy(dst, src, bpe * size); memcpy_neon(dst, src, bpe * size);
dst += (bpe * size); dst += (bpe * size);
src += stride; src += stride;
} }
@ -1880,8 +1964,7 @@ void vglTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLuint count, c
void vglIndexPointer(GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) { void vglIndexPointer(GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer) {
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (stride < 0) { if (stride < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
return;
} }
#endif #endif
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
@ -1894,18 +1977,18 @@ void vglIndexPointer(GLenum type, GLsizei stride, GLuint count, const GLvoid *po
bpe = sizeof(GLshort); bpe = sizeof(GLshort);
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
tex_unit->index_object = gpu_pool_memalign(count * bpe, bpe); tex_unit->index_object = gpu_pool_memalign(count * bpe, bpe);
if (stride == 0) if (stride == 0)
memcpy(tex_unit->index_object, pointer, count * bpe); memcpy_neon(tex_unit->index_object, pointer, count * bpe);
else { else {
int i; int i;
uint8_t *dst = (uint8_t *)tex_unit->index_object; uint8_t *dst = (uint8_t *)tex_unit->index_object;
uint8_t *src = (uint8_t *)pointer; uint8_t *src = (uint8_t *)pointer;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memcpy(dst, src, bpe); memcpy_neon(dst, src, bpe);
dst += bpe; dst += bpe;
src += stride; src += stride;
} }
@ -1938,10 +2021,11 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
texture_unit *tex_unit = &texture_units[client_texture_unit]; texture_unit *tex_unit = &texture_units[client_texture_unit];
int texture2d_idx = tex_unit->tex_id; int texture2d_idx = tex_unit->tex_id;
#ifndef SKIP_ERROR_HANDLING #ifndef SKIP_ERROR_HANDLING
if (phase == MODEL_CREATION) if (phase == MODEL_CREATION) {
vgl_error = GL_INVALID_OPERATION; SET_GL_ERROR(GL_INVALID_OPERATION)
else if (count < 0) } else if (count < 0) {
vgl_error = GL_INVALID_VALUE; SET_GL_ERROR(GL_INVALID_VALUE)
}
#endif #endif
GLboolean skip_draw = GL_FALSE; GLboolean skip_draw = GL_FALSE;
switch (mode) { switch (mode) {
@ -1967,7 +2051,7 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
skip_draw = GL_TRUE; skip_draw = GL_TRUE;
break; break;
default: default:
vgl_error = GL_INVALID_ENUM; SET_GL_ERROR(GL_INVALID_ENUM)
break; break;
} }
if (!skip_draw) { if (!skip_draw) {
@ -2074,7 +2158,7 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) {
vector4f *colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f)); vector4f *colors = (vector4f *)gpu_pool_memalign(count * sizeof(vector4f), sizeof(vector4f));
int n; int n;
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
memcpy(&colors[n], &current_color.r, sizeof(vector4f)); memcpy_neon(&colors[n], &current_color.r, sizeof(vector4f));
} }
sceGxmSetVertexStream(gxm_context, 0, tex_unit->vertex_object); sceGxmSetVertexStream(gxm_context, 0, tex_unit->vertex_object);
sceGxmSetVertexStream(gxm_context, 1, colors); sceGxmSetVertexStream(gxm_context, 1, colors);

View File

@ -24,20 +24,32 @@ extern "C" {
#endif #endif
#include <vitasdk.h> #include <vitasdk.h>
#ifdef HAVE_SHARK
#include <vitashark.h>
#endif
// clang-format off // clang-format off
#define GLfloat float
#define GLint int32_t
#define GLdouble double
#define GLshort int16_t
#define GLuint uint32_t
#define GLsizei int32_t
#define GLenum uint16_t
#define GLubyte uint8_t
#define GLvoid void
#define GLbyte int8_t
#define GLboolean uint8_t #define GLboolean uint8_t
#define GLbyte int8_t
#define GLubyte uint8_t
#define GLchar char #define GLchar char
#define GLshort int16_t
#define GLushort uint16_t
#define GLint int32_t
#define GLuint uint32_t
#define GLfixed int32_t
#define GLint64 int64_t
#define GLuint64 uint64_t
#define GLsizei int32_t
#define GLenum uint32_t
#define GLintptr int32_t
#define GLsizeiptr uint32_t
#define GLsync int32_t
#define GLfloat float
#define GLclampf float
#define GLdouble double
#define GLclampd double
#define GLvoid void
#define GL_FALSE 0 #define GL_FALSE 0
#define GL_TRUE 1 #define GL_TRUE 1
@ -47,6 +59,8 @@ extern "C" {
#define GL_ZERO 0 #define GL_ZERO 0
#define GL_ONE 1 #define GL_ONE 1
#define GL_NONE 0
#define GL_POINTS 0x0000 #define GL_POINTS 0x0000
#define GL_LINES 0x0001 #define GL_LINES 0x0001
#define GL_LINE_LOOP 0x0002 #define GL_LINE_LOOP 0x0002
@ -108,6 +122,8 @@ extern "C" {
#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 #define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 #define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 #define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
#define GL_DEPTH_BITS 0x0D56
#define GL_STENCIL_BITS 0x0D57
#define GL_TEXTURE_2D 0x0DE1 #define GL_TEXTURE_2D 0x0DE1
#define GL_BYTE 0x1400 #define GL_BYTE 0x1400
#define GL_UNSIGNED_BYTE 0x1401 #define GL_UNSIGNED_BYTE 0x1401
@ -218,6 +234,7 @@ extern "C" {
#define GL_TEXTURE30 0x84DE #define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF #define GL_TEXTURE31 0x84DF
#define GL_ACTIVE_TEXTURE 0x84E0 #define GL_ACTIVE_TEXTURE 0x84E0
#define GL_TEXTURE_LOD_BIAS 0x8501
#define GL_INCR_WRAP 0x8507 #define GL_INCR_WRAP 0x8507
#define GL_MIRROR_CLAMP_EXT 0x8742 #define GL_MIRROR_CLAMP_EXT 0x8742
#define GL_DECR_WRAP 0x8508 #define GL_DECR_WRAP 0x8508
@ -234,12 +251,15 @@ extern "C" {
#define GL_DYNAMIC_COPY 0x88EA #define GL_DYNAMIC_COPY 0x88EA
#define GL_FRAGMENT_SHADER 0x8B30 #define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31 #define GL_VERTEX_SHADER 0x8B31
#define GL_SHADER_TYPE 0x8B4F
#define GL_COMPILE_STATUS 0x8B81
#define GL_READ_FRAMEBUFFER 0x8CA8 #define GL_READ_FRAMEBUFFER 0x8CA8
#define GL_DRAW_FRAMEBUFFER 0x8CA9 #define GL_DRAW_FRAMEBUFFER 0x8CA9
#define GL_COLOR_ATTACHMENT0 0x8CE0 #define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_FRAMEBUFFER 0x8D40 #define GL_FRAMEBUFFER 0x8D40
#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 32 #define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 32
#define GL_MAX_TEXTURE_LOD_BIAS 31
// Aliases // Aliases
#define GL_CLAMP GL_CLAMP_TO_EDGE #define GL_CLAMP GL_CLAMP_TO_EDGE
@ -282,6 +302,7 @@ void glColor4ubv(const GLubyte *v);
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *data); void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *data);
void glCompileShader(GLuint shader);
GLuint glCreateProgram(void); GLuint glCreateProgram(void);
GLuint glCreateShader(GLenum shaderType); GLuint glCreateShader(GLenum shaderType);
void glCullFace(GLenum mode); void glCullFace(GLenum mode);
@ -316,6 +337,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params);
void glGetFloatv(GLenum pname, GLfloat *data); void glGetFloatv(GLenum pname, GLfloat *data);
GLenum glGetError(void); GLenum glGetError(void);
void glGetIntegerv(GLenum pname, GLint *data); void glGetIntegerv(GLenum pname, GLint *data);
void glGetShaderiv(GLuint handle, GLenum pname, GLint *params);
const GLubyte *glGetString(GLenum name); const GLubyte *glGetString(GLenum name);
GLint glGetUniformLocation(GLuint prog, const GLchar *name); GLint glGetUniformLocation(GLuint prog, const GLchar *name);
GLboolean glIsEnabled(GLenum cap); GLboolean glIsEnabled(GLenum cap);
@ -336,6 +358,7 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
void glScalef(GLfloat x, GLfloat y, GLfloat z); void glScalef(GLfloat x, GLfloat y, GLfloat z);
void glScissor(GLint x, GLint y, GLsizei width, GLsizei height); void glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length); // NOTE: Uses GXP shaders void glShaderBinary(GLsizei count, const GLuint *handles, GLenum binaryFormat, const void *binary, GLsizei length); // NOTE: Uses GXP shaders
void glShaderSource(GLuint handle, GLsizei count, const GLchar * const *string, const GLint *length); // NOTE: Uses CG shader sources
void glStencilFunc(GLenum func, GLint ref, GLuint mask); void glStencilFunc(GLenum func, GLint ref, GLuint mask);
void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
void glStencilMask(GLuint mask); void glStencilMask(GLuint mask);
@ -357,6 +380,8 @@ void glTranslatef(GLfloat x, GLfloat y, GLfloat z);
void glUniform1f(GLint location, GLfloat v0); void glUniform1f(GLint location, GLfloat v0);
void glUniform1i(GLint location, GLint v0); void glUniform1i(GLint location, GLint v0);
void glUniform2fv(GLint location, GLsizei count, const GLfloat *value); void glUniform2fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform3fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value); void glUniform4fv(GLint location, GLsizei count, const GLfloat *value);
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void glUseProgram(GLuint program); void glUseProgram(GLuint program);
@ -366,6 +391,9 @@ void glVertex3fv(const GLfloat *v);
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
// glu*
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
// VGL_EXT_gpu_objects_array extension // VGL_EXT_gpu_objects_array extension
void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer); void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer);
void vglColorPointerMapped(GLenum type, const GLvoid *pointer); void vglColorPointerMapped(GLenum type, const GLvoid *pointer);
@ -394,12 +422,15 @@ typedef enum {
// vgl* // vgl*
void *vglAlloc(uint32_t size, vglMemType type); void *vglAlloc(uint32_t size, vglMemType type);
void vglEnableRuntimeShaderCompiler(GLboolean usage);
void vglEnd(void); void vglEnd(void);
void vglFree(void *addr); void vglFree(void *addr);
void *vglGetTexDataPointer(GLenum target); void *vglGetTexDataPointer(GLenum target);
void vglInit(uint32_t gpu_pool_size); void vglInit(uint32_t gpu_pool_size);
void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa); void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_threshold, SceGxmMultisampleMode msaa);
void vglInitWithCustomSizes(uint32_t gpu_pool_size, int width, int height, int ram_pool_size, int cdram_pool_size, int phycont_pool_size, SceGxmMultisampleMode msaa);
size_t vglMemFree(vglMemType type); size_t vglMemFree(vglMemType type);
void vglSetParamBufferSize(uint32_t size);
void vglStartRendering(); void vglStartRendering();
void vglStopRendering(); void vglStopRendering();
void vglStopRenderingInit(); void vglStopRenderingInit();
@ -410,6 +441,9 @@ void vglUseVramForUSSE(GLboolean usage);
void vglUseExtraMem(GLboolean usage); void vglUseExtraMem(GLboolean usage);
void vglWaitVblankStart(GLboolean enable); void vglWaitVblankStart(GLboolean enable);
// NEON optimized memcpy
void *memcpy_neon(void *destination, const void *source, size_t num);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

2
deps/vitaShaRK/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

1
deps/vitaShaRK/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
patreon: Rinnegatamante

59
deps/vitaShaRK/.gitignore vendored Normal file
View File

@ -0,0 +1,59 @@
*.vpk
*.elf
*.velf
*.bin
*.sfo
*.S
*.wo
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Vita build stuffs
*.a
*.o

165
deps/vitaShaRK/LICENSE vendored Normal file
View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

37
deps/vitaShaRK/Makefile vendored Normal file
View File

@ -0,0 +1,37 @@
TARGET := libvitashark
SOURCES := source
SHADERS := shaders
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
ASMFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S))
CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg))
HEADERS := $(CGFILES:.cg=.h)
OBJS := $(CFILES:.c=.o) $(ASMFILES:.S=.o)
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
AR = $(PREFIX)-gcc-ar
CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -ftree-vectorize
ASFLAGS = $(CFLAGS)
all: $(TARGET).a
$(TARGET).a: $(OBJS)
$(AR) -rc $@ $^
clean:
@rm -rf $(TARGET).a $(TARGET).elf $(OBJS)
@make -C samples/sample1 clean
@make -C samples/sample2 clean
install: $(TARGET).a
@mkdir -p $(VITASDK)/$(PREFIX)/lib/
cp $(TARGET).a $(VITASDK)/$(PREFIX)/lib/
@mkdir -p $(VITASDK)/$(PREFIX)/include/
cp source/vitashark.h $(VITASDK)/$(PREFIX)/include/
samples: $(TARGET).a
@make -C samples/sample1
cp "samples/sample1/vitaShaRK-Sample001.vpk" .
@make -C samples/sample2
cp "samples/sample1/vitaShaRK-Sample002.vpk" .

18
deps/vitaShaRK/README.md vendored Normal file
View File

@ -0,0 +1,18 @@
# vitaShaRK
**vita** **Sha**ders **R**untime **K**ompiler is a runtime shader compiler library for PSVITA/PSTV using the SceShaccCg module contained inside the PSM runtime.
# Build Instructions
In order to build vitaShaRK, you'll first need to build SceShaccCg stubs. This is a full list of commands you can use to install this library and the required stubs:
```
vita-libs-gen SceShaccCg.yml build
cd build
make install
cd ..
cp shacccg.h $VITASDK/arm-vita-eabi/psp2/shacccg.h
make install
```
# Credits
**frangarcj** for the original vita2d shader compiler source used as base to build up this library.

43
deps/vitaShaRK/SceShaccCg.yml vendored Normal file
View File

@ -0,0 +1,43 @@
version: 2
firmware: 3.60
modules:
SceShaccCg:
nid: 0xB3B90A35
libraries:
SceShaccCg:
kernel: false
nid: 0xA05BBEBB
functions:
SceShaccCg_0205DE96: 0x0205DE96
SceShaccCg_07DDFC78: 0x07DDFC78
SceShaccCg_0E1285A6: 0x0E1285A6
SceShaccCg_152971B1: 0x152971B1
SceShaccCg_17223BEB: 0x17223BEB
SceShaccCg_2654E73A: 0x2654E73A
SceShaccCg_268FAEE9: 0x268FAEE9
sceShaccCgInitializeCompileOptions: 0x3B58AFA0
SceShaccCg_4595A388: 0x4595A388
SceShaccCg_46FA0303: 0x46FA0303
SceShaccCg_56BFA825: 0x56BFA825
SceShaccCg_648739F3: 0x648739F3
sceShaccCgCompileProgram: 0x66814F35
SceShaccCg_6BB58825: 0x6BB58825
sceShaccCgSetDefaultAllocator: 0x6F01D573
SceShaccCg_6FB40CA9: 0x6FB40CA9
SceShaccCg_7B2CF324: 0x7B2CF324
SceShaccCg_7BC25091: 0x7BC25091
SceShaccCg_7F430CCD: 0x7F430CCD
SceShaccCg_95F57A23: 0x95F57A23
SceShaccCg_A067C481: 0xA067C481
SceShaccCg_A13A8A1E: 0xA13A8A1E
SceShaccCg_A56B1A5B: 0xA56B1A5B
SceShaccCg_A7930FF6: 0xA7930FF6
sceShaccCgInitializeCallbackList: 0xA8C2C1C8
sceShaccCgDestroyCompileOutput: 0xAA82EF0C
SceShaccCg_B4AC9943: 0xB4AC9943
SceShaccCg_BB703EE1: 0xBB703EE1
SceShaccCg_D4378DB1: 0xD4378DB1
SceShaccCg_DAD4AAE4: 0xDAD4AAE4
SceShaccCg_DF3DDCFD: 0xDF3DDCFD
SceShaccCg_EF8D59D6: 0xEF8D59D6
SceShaccCg_F4BAB902: 0xF4BAB902

47
deps/vitaShaRK/SceShaccCg/Makefile vendored Normal file
View File

@ -0,0 +1,47 @@
ifdef VITASDK
PREFIX = $(VITASDK)/bin/
endif
ARCH ?= $(PREFIX)arm-vita-eabi
AS = $(ARCH)-as
AR = $(ARCH)-ar
RANLIB = $(ARCH)-ranlib
TARGETS = libSceShaccCg_stub.a
TARGETS_WEAK = libSceShaccCg_stub_weak.a
SceShaccCg_OBJS = SceShaccCg_SceShaccCg_SceShaccCg_0205DE96.o SceShaccCg_SceShaccCg_SceShaccCg_07DDFC78.o SceShaccCg_SceShaccCg_SceShaccCg_0E1285A6.o SceShaccCg_SceShaccCg_SceShaccCg_152971B1.o SceShaccCg_SceShaccCg_SceShaccCg_17223BEB.o SceShaccCg_SceShaccCg_SceShaccCg_2654E73A.o SceShaccCg_SceShaccCg_SceShaccCg_268FAEE9.o SceShaccCg_SceShaccCg_sceShaccCgInitializeCompileOptions.o SceShaccCg_SceShaccCg_SceShaccCg_4595A388.o SceShaccCg_SceShaccCg_SceShaccCg_46FA0303.o SceShaccCg_SceShaccCg_SceShaccCg_56BFA825.o SceShaccCg_SceShaccCg_SceShaccCg_648739F3.o SceShaccCg_SceShaccCg_sceShaccCgCompileProgram.o SceShaccCg_SceShaccCg_SceShaccCg_6BB58825.o SceShaccCg_SceShaccCg_sceShaccCgSetDefaultAllocator.o SceShaccCg_SceShaccCg_SceShaccCg_6FB40CA9.o SceShaccCg_SceShaccCg_SceShaccCg_7B2CF324.o SceShaccCg_SceShaccCg_SceShaccCg_7BC25091.o SceShaccCg_SceShaccCg_SceShaccCg_7F430CCD.o SceShaccCg_SceShaccCg_SceShaccCg_95F57A23.o SceShaccCg_SceShaccCg_SceShaccCg_A067C481.o SceShaccCg_SceShaccCg_SceShaccCg_A13A8A1E.o SceShaccCg_SceShaccCg_SceShaccCg_A56B1A5B.o SceShaccCg_SceShaccCg_SceShaccCg_A7930FF6.o SceShaccCg_SceShaccCg_sceShaccCgInitializeCallbackList.o SceShaccCg_SceShaccCg_sceShaccCgDestroyCompileOutput.o SceShaccCg_SceShaccCg_SceShaccCg_B4AC9943.o SceShaccCg_SceShaccCg_SceShaccCg_BB703EE1.o SceShaccCg_SceShaccCg_SceShaccCg_D4378DB1.o SceShaccCg_SceShaccCg_SceShaccCg_DAD4AAE4.o SceShaccCg_SceShaccCg_SceShaccCg_DF3DDCFD.o SceShaccCg_SceShaccCg_SceShaccCg_EF8D59D6.o SceShaccCg_SceShaccCg_SceShaccCg_F4BAB902.o
SceShaccCg_weak_OBJS = SceShaccCg_SceShaccCg_SceShaccCg_0205DE96.wo SceShaccCg_SceShaccCg_SceShaccCg_07DDFC78.wo SceShaccCg_SceShaccCg_SceShaccCg_0E1285A6.wo SceShaccCg_SceShaccCg_SceShaccCg_152971B1.wo SceShaccCg_SceShaccCg_SceShaccCg_17223BEB.wo SceShaccCg_SceShaccCg_SceShaccCg_2654E73A.wo SceShaccCg_SceShaccCg_SceShaccCg_268FAEE9.wo SceShaccCg_SceShaccCg_sceShaccCgInitializeCompileOptions.wo SceShaccCg_SceShaccCg_SceShaccCg_4595A388.wo SceShaccCg_SceShaccCg_SceShaccCg_46FA0303.wo SceShaccCg_SceShaccCg_SceShaccCg_56BFA825.wo SceShaccCg_SceShaccCg_SceShaccCg_648739F3.wo SceShaccCg_SceShaccCg_sceShaccCgCompileProgram.wo SceShaccCg_SceShaccCg_SceShaccCg_6BB58825.wo SceShaccCg_SceShaccCg_sceShaccCgSetDefaultAllocator.wo SceShaccCg_SceShaccCg_SceShaccCg_6FB40CA9.wo SceShaccCg_SceShaccCg_SceShaccCg_7B2CF324.wo SceShaccCg_SceShaccCg_SceShaccCg_7BC25091.wo SceShaccCg_SceShaccCg_SceShaccCg_7F430CCD.wo SceShaccCg_SceShaccCg_SceShaccCg_95F57A23.wo SceShaccCg_SceShaccCg_SceShaccCg_A067C481.wo SceShaccCg_SceShaccCg_SceShaccCg_A13A8A1E.wo SceShaccCg_SceShaccCg_SceShaccCg_A56B1A5B.wo SceShaccCg_SceShaccCg_SceShaccCg_A7930FF6.wo SceShaccCg_SceShaccCg_sceShaccCgInitializeCallbackList.wo SceShaccCg_SceShaccCg_sceShaccCgDestroyCompileOutput.wo SceShaccCg_SceShaccCg_SceShaccCg_B4AC9943.wo SceShaccCg_SceShaccCg_SceShaccCg_BB703EE1.wo SceShaccCg_SceShaccCg_SceShaccCg_D4378DB1.wo SceShaccCg_SceShaccCg_SceShaccCg_DAD4AAE4.wo SceShaccCg_SceShaccCg_SceShaccCg_DF3DDCFD.wo SceShaccCg_SceShaccCg_SceShaccCg_EF8D59D6.wo SceShaccCg_SceShaccCg_SceShaccCg_F4BAB902.wo
SceKernel_OBJS =
ALL_OBJS=
all: $(TARGETS) $(TARGETS_WEAK)
define LIBRARY_template
$(1): $$($(1:lib%_stub.a=%)_OBJS)
ALL_OBJS += $$($(1:lib%_stub.a=%)_OBJS)
endef
define LIBRARY_WEAK_template
$(1): $$($(1:lib%_stub_weak.a=%)_weak_OBJS)
ALL_OBJS += $$($(1:lib%_stub_weak.a=%)_weak_OBJS)
endef
$(foreach library,$(TARGETS),$(eval $(call LIBRARY_template,$(library))))
$(foreach library,$(TARGETS_WEAK),$(eval $(call LIBRARY_WEAK_template,$(library))))
install: $(TARGETS) $(TARGETS_WEAK)
cp $(TARGETS) $(VITASDK)/arm-vita-eabi/lib
cp $(TARGETS_WEAK) $(VITASDK)/arm-vita-eabi/lib
clean:
rm -f $(TARGETS) $(TARGETS_WEAK) $(ALL_OBJS)
$(TARGETS) $(TARGETS_WEAK):
$(AR) cru $@ $?
$(RANLIB) $@
%.o: %.S
$(AS) --defsym GEN_WEAK_EXPORTS=0 $< -o $@
%.wo: %.S
$(AS) --defsym GEN_WEAK_EXPORTS=1 $< -o $@

185
deps/vitaShaRK/include/shacccg.h vendored Normal file
View File

@ -0,0 +1,185 @@
#ifndef _PSP2_SHACCCG_H
#define _PSP2_SHACCCG_H
#ifdef __cplusplus
extern "C" {
#endif // def __cplusplus
typedef struct SceShaccCgCompileOptions SceShaccCgCompileOptions;
typedef struct SceShaccCgSourceFile SceShaccCgSourceFile;
typedef struct SceShaccCgSourceLocation SceShaccCgSourceLocation;
typedef void const *SceShaccCgParameter;
typedef SceShaccCgSourceFile* (*SceShaccCgCallbackOpenFile)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
const char **errorString);
typedef void (*SceShaccCgCallbackReleaseFile)(
const SceShaccCgSourceFile *file,
const SceShaccCgCompileOptions *compileOptions);
typedef const char* (*SceShaccCgCallbackLocateFile)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
uint32_t searchPathCount,
const char *const*searchPaths,
const SceShaccCgCompileOptions *compileOptions,
const char **errorString);
typedef const char* (*SceShaccCgCallbackAbsolutePath)(
const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions);
typedef void (*SceShaccCgCallbackReleaseFileName)(
const char *fileName,
const SceShaccCgCompileOptions *compileOptions);
typedef int32_t (*SceShaccCgCallbackFileDate)(
const SceShaccCgSourceFile *file,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
int64_t *timeLastStatusChange,
int64_t *timeLastModified);
typedef enum SceShaccCgDiagnosticLevel {
SCE_SHACCCG_DIAGNOSTIC_LEVEL_INFO,
SCE_SHACCCG_DIAGNOSTIC_LEVEL_WARNING,
SCE_SHACCCG_DIAGNOSTIC_LEVEL_ERROR
} SceShaccCgDiagnosticLevel;
typedef enum SceShaccCgTargetProfile {
SCE_SHACCCG_PROFILE_VP,
SCE_SHACCCG_PROFILE_FP
} SceShaccCgTargetProfile;
typedef enum SceShaccCgCallbackDefaults {
SCE_SHACCCG_SYSTEM_FILES,
SCE_SHACCCG_TRIVIAL
} SceShaccCgCallbackDefaults;
typedef enum SceShaccCgLocale {
SCE_SHACCCG_ENGLISH,
SCE_SHACCCG_JAPANESE
} SceShaccCgLocale;
typedef struct SceShaccCgSourceFile {
const char *fileName;
const char *text;
uint32_t size;
} SceShaccCgSourceFile;
typedef struct SceShaccCgSourceLocation {
const SceShaccCgSourceFile *file;
uint32_t lineNumber;
uint32_t columnNumber;
} SceShaccCgSourceLocation;
typedef struct SceShaccCgCallbackList {
SceShaccCgCallbackOpenFile openFile;
SceShaccCgCallbackReleaseFile releaseFile;
SceShaccCgCallbackLocateFile locateFile;
SceShaccCgCallbackAbsolutePath absolutePath;
SceShaccCgCallbackReleaseFileName releaseFileName;
SceShaccCgCallbackFileDate fileDate;
} SceShaccCgCallbackList;
typedef struct SceShaccCgCompileOptions {
const char *mainSourceFile;
SceShaccCgTargetProfile targetProfile;
const char *entryFunctionName;
uint32_t searchPathCount;
const char* const *searchPaths;
uint32_t macroDefinitionCount;
const char* const *macroDefinitions;
uint32_t includeFileCount;
const char* const *includeFiles;
uint32_t suppressedWarningsCount;
const uint32_t *suppressedWarnings;
SceShaccCgLocale locale;
int32_t useFx;
int32_t noStdlib;
int32_t optimizationLevel;
int32_t useFastmath;
int32_t useFastprecision;
int32_t useFastint;
int32_t warningsAsErrors;
int32_t performanceWarnings;
int32_t warningLevel;
int32_t pedantic;
int32_t pedanticError;
int field_5C;
int field_60;
int field_64;
} SceShaccCgCompileOptions;
typedef struct SceShaccCgDiagnosticMessage {
SceShaccCgDiagnosticLevel level;
uint32_t code;
const SceShaccCgSourceLocation *location;
const char *message;
} SceShaccCgDiagnosticMessage;
typedef struct SceShaccCgCompileOutput {
const uint8_t *programData;
uint32_t programSize;
int32_t diagnosticCount;
const SceShaccCgDiagnosticMessage *diagnostics;
} SceShaccCgCompileOutput;
int SceShaccCg_0205DE96(int);
int SceShaccCg_07DDFC78(int);
int SceShaccCg_0E1285A6(int);
int SceShaccCg_152971B1(int);
int SceShaccCg_17223BEB(int);
int SceShaccCg_2654E73A(int);
int SceShaccCg_268FAEE9(int);
int sceShaccCgInitializeCompileOptions(
SceShaccCgCompileOptions *options);
int SceShaccCg_4595A388(int);
int SceShaccCg_46FA0303(int);
int SceShaccCg_56BFA825(int);
int SceShaccCg_648739F3(int);
SceShaccCgCompileOutput const *sceShaccCgCompileProgram(
const SceShaccCgCompileOptions *options,
const SceShaccCgCallbackList *callbacks,
int unk);
int SceShaccCg_6BB58825(int);
int sceShaccCgSetDefaultAllocator(void *(*malloc_cb)(unsigned int), void (*free_cb)(void *));
int SceShaccCg_6FB40CA9(int);
int SceShaccCg_7B2CF324(int);
int SceShaccCg_7BC25091(int);
int SceShaccCg_7F430CCD(int);
int SceShaccCg_95F57A23(int);
int SceShaccCg_A067C481(int);
int SceShaccCg_A13A8A1E(int);
int SceShaccCg_A56B1A5B(int);
int SceShaccCg_A7930FF6(int);
void sceShaccCgInitializeCallbackList(
SceShaccCgCallbackList *callbacks,
SceShaccCgCallbackDefaults defaults);
void sceShaccCgDestroyCompileOutput(
SceShaccCgCompileOutput const *output);
int SceShaccCg_B4AC9943(int);
int SceShaccCg_BB703EE1(int);
int SceShaccCg_D4378DB1(int);
int SceShaccCg_DAD4AAE4(int);
int SceShaccCg_DF3DDCFD(int);
int SceShaccCg_EF8D59D6(int);
int SceShaccCg_F4BAB902(int);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _PSP2_SHACCCG_H */

37
deps/vitaShaRK/samples/sample1/Makefile vendored Normal file
View File

@ -0,0 +1,37 @@
SAMPLE_NUM := 001
TARGET := vitaShaRK-Sample$(SAMPLE_NUM)
SOURCES := .
INCLUDES := include
LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
ASFLAGS = $(CFLAGS)
all: $(TARGET).vpk
$(TARGET).vpk: eboot.bin
vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $@
eboot.bin: $(TARGET).velf
vita-make-fself -s $< eboot.bin
%.velf: %.elf
vita-elf-create $< $@
$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
clean:
@rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin

59
deps/vitaShaRK/samples/sample1/main.c vendored Normal file
View File

@ -0,0 +1,59 @@
// Simple compiler with no logging
#include <vitashark.h>
#include <stdlib.h>
#include <stdio.h>
const char fragment_shader[] =
"float4 main(uniform float4 u_clear_color) : COLOR\n"
"{\n"
" return u_clear_color;\n"
"}"
;
const char vertex_shader[] =
"void main(\n"
"float3 aPosition,\n"
"float3 aColor,\n"
"uniform float4x4 wvp,\n"
"float4 out vPosition: POSITION,\n"
"float4 out vColor: COLOR)\n"
"{\n"
" vPosition = mul(float4(aPosition, 1.f), wvp);\n"
" vColor = float4(aColor, 1.f);\n"
"}"
;
void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) {
FILE *f = fopen(fname, "wb");
fwrite(p, 1, size, f);
fclose(f);
}
int main() {
// Initializing vitaShaRK
if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data
return -1;
// Compiling fragment shader
uint32_t size = sizeof(fragment_shader) - 1;
SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER);
// Saving compiled GXP file on SD
if (p) saveGXP(p, size, "ux0:data/clear_f.gxp");
shark_clear_output();
// Compiling vertex shader
size = sizeof(vertex_shader) - 1;
p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER);
// Saving compiled GXP file on SD
if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp");
shark_clear_output();
shark_end();
return 0;
}

37
deps/vitaShaRK/samples/sample2/Makefile vendored Normal file
View File

@ -0,0 +1,37 @@
SAMPLE_NUM := 002
TARGET := vitaShaRK-Sample$(SAMPLE_NUM)
SOURCES := .
INCLUDES := include
LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub
CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin))
OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
PREFIX = arm-vita-eabi
CC = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
CFLAGS = -g -Wl,-q -O2 -ftree-vectorize
CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive
ASFLAGS = $(CFLAGS)
all: $(TARGET).vpk
$(TARGET).vpk: eboot.bin
vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $@
eboot.bin: $(TARGET).velf
vita-make-fself -s $< eboot.bin
%.velf: %.elf
vita-elf-create $< $@
$(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) $^ $(LIBS) -o $@
clean:
@rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin

85
deps/vitaShaRK/samples/sample2/main.c vendored Normal file
View File

@ -0,0 +1,85 @@
// Simple compiler with file logging
#include <vitashark.h>
#include <stdlib.h>
#include <stdio.h>
const char fragment_shader[] =
"float4 main(uniform float4 u_clear_color) : COLOR\n"
"{\n"
" return u_clear_color;\n"
"}"
;
const char vertex_shader[] =
"void main(\n"
"float3 aPosition,\n"
"float3 aColor,\n"
"uniform float4x4 wvp,\n"
"float4 out vPosition: POSITION,\n"
"float4 out vColor: COLOR)\n"
"{\n"
" vPosition = mul(float4(aPosition, 1.f), wvp);\n"
" vColor = float4(aColor, 1.f);\n"
"}"
;
char curr_compilation[256];
void log_cb(const char *msg, shark_log_level msg_level, int line) {
FILE *f = fopen("ux0:/data/shark.log", "a+");
switch (msg_level) {
case SHARK_LOG_INFO:
fprintf(f, "%s) INFO: %s at line %d\n", curr_compilation, msg, line);
break;
case SHARK_LOG_WARNING:
fprintf(f, "%s) WARNING: %s at line %d\n", curr_compilation, msg, line);
break;
case SHARK_LOG_ERROR:
fprintf(f, "%s) ERROR: %s at line %d\n", curr_compilation, msg, line);
break;
default:
break;
}
fclose(f);
}
void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) {
FILE *f = fopen(fname, "wb");
fwrite(p, 1, size, f);
fclose(f);
}
int main() {
// Initializing vitaShaRK
if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data
return -1;
// Setting up logger
shark_install_log_cb(log_cb);
shark_set_warnings_level(SHARK_WARN_MAX);
// Compiling fragment shader
sprintf(curr_compilation, "clear_f.gxp");
uint32_t size = sizeof(fragment_shader) - 1;
SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER);
// Saving compiled GXP file on SD
if (p) saveGXP(p, size, "ux0:data/clear_f.gxp");
shark_clear_output();
// Compiling vertex shader
sprintf(curr_compilation, "rgb_v.gxp");
size = sizeof(vertex_shader) - 1;
p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER);
// Saving compiled GXP file on SD
if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp");
shark_clear_output();
shark_end();
return 0;
}

124
deps/vitaShaRK/source/vitashark.c vendored Normal file
View File

@ -0,0 +1,124 @@
/*
* This file is part of vitaGL
* Copyright 2017, 2018, 2019, 2020 Rinnegatamante
* Copyright 2020 Asakura Reiko
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "vitashark.h"
#include <stdlib.h>
#include "shacccg.h"
// Default path for SceShaccCg module location
#define DEFAULT_SHACCCG_PATH "ur0:/data/libshacccg.suprx"
static void (*shark_log_cb)(const char *msg, shark_log_level msg_level, int line) = NULL;
static shark_warn_level shark_warnings_level = SHARK_WARN_SILENT;
static SceUID shark_module_id = 0;
static uint8_t shark_initialized = 0;
static SceShaccCgCompileOutput *shark_output = NULL;
static SceShaccCgSourceFile shark_input;
// Dummy Open File callback
static SceShaccCgSourceFile *shark_open_file_cb(const char *fileName,
const SceShaccCgSourceLocation *includedFrom,
const SceShaccCgCompileOptions *compileOptions,
const char **errorString)
{
return &shark_input;
}
int shark_init(const char *path) {
// Initializing sceShaccCg module
if (!shark_initialized) {
shark_module_id = sceKernelLoadStartModule(path ? path : DEFAULT_SHACCCG_PATH, 0, NULL, 0, NULL, NULL);
if (shark_module_id < 0) return -1;
sceShaccCgSetDefaultAllocator(malloc, free);
shark_initialized = 1;
}
return 0;
}
void shark_end() {
if (!shark_initialized) return;
// Terminating sceShaccCg module
sceKernelStopUnloadModule(shark_module_id, 0, NULL, 0, NULL, NULL);
shark_initialized = 0;
}
void shark_install_log_cb(void (*cb)(const char *msg, shark_log_level msg_level, int line)) {
shark_log_cb = cb;
}
void shark_set_warnings_level(shark_warn_level level) {
// Changing current warnings level
shark_warnings_level = level;
}
void shark_clear_output() {
// Clearing sceShaccCg output
if (shark_output) {
sceShaccCgDestroyCompileOutput(shark_output);
shark_output = NULL;
}
}
SceGxmProgram *shark_compile_shader_extended(const char *src, uint32_t *size, shark_type type, shark_opt opt, int32_t use_fastmath, int32_t use_fastprecision, int32_t use_fastint) {
if (!shark_initialized) return NULL;
// Forcing usage for memory source for the shader to compile
shark_input.fileName = "<built-in>";
shark_input.text = src;
shark_input.size = *size;
// Properly configuring SceShaccCg with requqested settings
SceShaccCgCompileOptions options = {0};
options.mainSourceFile = shark_input.fileName;
options.targetProfile = type;
options.entryFunctionName = "main";
options.macroDefinitions = NULL;
options.useFx = 1;
options.warningLevel = shark_warnings_level;
options.optimizationLevel = opt;
options.useFastmath = use_fastmath;
options.useFastint = use_fastint;
options.useFastprecision = use_fastprecision;
options.pedantic = shark_warnings_level > SHARK_WARN_MEDIUM ? SHARK_ENABLE : SHARK_DISABLE;
options.performanceWarnings = shark_warnings_level > SHARK_WARN_SILENT ? SHARK_ENABLE : SHARK_DISABLE;
// Executing shader compilation
SceShaccCgCallbackList callbacks = {0};
sceShaccCgInitializeCallbackList(&callbacks, SCE_SHACCCG_TRIVIAL);
callbacks.openFile = shark_open_file_cb;
const SceShaccCgCompileOutput *shark_output = sceShaccCgCompileProgram(&options, &callbacks, 0);
// Executing logging
if (shark_log_cb) {
for (int i = 0; i < shark_output->diagnosticCount; ++i) {
const SceShaccCgDiagnosticMessage *log = &shark_output->diagnostics[i];
shark_log_cb(log->message, log->level, log->location->lineNumber);
}
}
// Returning output
if (shark_output->programData) *size = shark_output->programSize;
return (SceGxmProgram *)shark_output->programData;
}
SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type) {
return shark_compile_shader_extended(src, size, type, SHARK_OPT_DEFAULT, SHARK_DISABLE, SHARK_DISABLE, SHARK_DISABLE);
}

75
deps/vitaShaRK/source/vitashark.h vendored Normal file
View File

@ -0,0 +1,75 @@
/*
* This file is part of vitaShaRK
* Copyright 2017, 2018, 2019, 2020 Rinnegatamante
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _VITASHARK_H_
#define _VITASHARK_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <vitasdk.h>
typedef enum shark_opt {
SHARK_OPT_SLOW, //!< Equivalent to O0
SHARK_OPT_SAFE, //!< Equivalent to O1
SHARK_OPT_DEFAULT, //!< Equivalent to O2
SHARK_OPT_FAST, //!< Equivalent to O3
SHARK_OPT_UNSAFE //!< Equivalent to Ofast
} shark_opt;
typedef enum shark_type {
SHARK_VERTEX_SHADER,
SHARK_FRAGMENT_SHADER
} shark_type;
typedef enum shark_log_level {
SHARK_LOG_INFO,
SHARK_LOG_WARNING,
SHARK_LOG_ERROR
} shark_log_level;
typedef enum shark_warn_level {
SHARK_WARN_SILENT,
SHARK_WARN_LOW,
SHARK_WARN_MEDIUM,
SHARK_WARN_HIGH,
SHARK_WARN_MAX
} shark_warn_level;
#define SHARK_DISABLE 0
#define SHARK_ENABLE 1
// Init/term routines
int shark_init(const char *path); //!< Initializes runtime shader compiler
void shark_end(); //!< Terminates runtime shader compiler and frees used memory
// Compiling routines
SceGxmProgram *shark_compile_shader_extended(const char *src, uint32_t *size, shark_type type, shark_opt opt, int32_t use_fastmath, int32_t use_fastprecision, int32_t use_fastint); //!< Compiles a shader with extended settings
SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type); //!< Compiles a shader
void shark_clear_output(); //!< Clears output of a compilation attempt
// Logging routines
void shark_install_log_cb(void (*cb)(const char *msg, shark_log_level msg_level, int line)); //!< Installs a log function for info, warnings and errors
void shark_set_warnings_level(shark_warn_level level); //!< Sets warnings level for logging
#ifdef __cplusplus
}
#endif
#endif