diff --git a/Makefile.common b/Makefile.common index ff04e7a9ed..42c142c8b6 100644 --- a/Makefile.common +++ b/Makefile.common @@ -2158,8 +2158,14 @@ ifeq ($(HAVE_MATH_NEON), 1) endif ifeq ($(HAVE_VITAGL), 1) - DEFINES += -DHAVE_VITAGL -DSTB_DXT_IMPLEMENTATION -DSKIP_ERROR_HANDLING - INCLUDE_DIRS += -I$(DEPS_DIR)/vitaGL/source + INCLUDE_DIRS += -I$(DEPS_DIR)/vitaShaRK/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 OBJ += $(patsubst %.c,%.o,$(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))) endif diff --git a/Makefile.vita b/Makefile.vita index bf04ff89f5..e2e2faa3b2 100644 --- a/Makefile.vita +++ b/Makefile.vita @@ -132,7 +132,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions VITA_LIBS := -lSceDisplay_stub -lSceGxm_stub -lSceNet_stub -lSceNetCtl_stub -lSceAppUtil_stub \ -lSceSysmodule_stub -lSceCtrl_stub -lSceHid_stub -lSceTouch_stub -lSceAudio_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 @@ -165,7 +165,13 @@ all: $(TARGETS) %.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 $@ %.velf: %.elf @@ -181,7 +187,7 @@ $(TARGET).elf: $(OBJ) libretro_vita.a vita-pack-vpk -s param.sfo -b $< $@ 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) # Useful for developers diff --git a/deps/vitaGL/.github/FUNDING.yml b/deps/vitaGL/.github/FUNDING.yml new file mode 100644 index 0000000000..dbd470e946 --- /dev/null +++ b/deps/vitaGL/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: Rinnegatamante diff --git a/deps/vitaGL/Makefile b/deps/vitaGL/Makefile index e4b82ce5fa..e508bbc4b3 100644 --- a/deps/vitaGL/Makefile +++ b/deps/vitaGL/Makefile @@ -7,20 +7,25 @@ SOURCES += source/hacks endif 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) +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 -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) ifeq ($(NO_DEBUG),1) CFLAGS += -DSKIP_ERROR_HANDLING endif +ifeq ($(HAVE_SHARK),1) +CFLAGS += -DHAVE_SHARK +endif + all: $(TARGET).a $(TARGET).a: $(OBJS) @@ -47,6 +52,7 @@ clean: @make -C samples/sample5 clean @make -C samples/sample6 clean @make -C samples/sample7 clean + @make -C samples/sample8 clean install: $(TARGET).a @mkdir -p $(VITASDK)/$(PREFIX)/lib/ @@ -69,3 +75,5 @@ samples: $(TARGET).a cp "samples/sample6/vitaGL-Sample006.vpk" . @make -C samples/sample7 cp "samples/sample7/vitaGL-Sample007.vpk" . + @make -C samples/sample8 + cp "samples/sample8/vitaGL-Sample008.vpk" . diff --git a/deps/vitaGL/README.md b/deps/vitaGL/README.md index 5accb88b97..a4b3d9597f 100644 --- a/deps/vitaGL/README.md +++ b/deps/vitaGL/README.md @@ -20,7 +20,7 @@ Here you can find a list of projects using vitaGL: Direct OpenGL Usage:
[vitaQuake](https://vitadb.rinnegatamante.it/#/info/10) - Port of Quake I and mission packs
[vitaQuakeII](https://vitadb.rinnegatamante.it/#/info/278) -Port of Quake II and mission packs
-[vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena)
+[vitaQuakeIII](https://vitadb.rinnegatamante.it/#/info/375) - Port of ioquake3 (Quake III: Arena, Quake III: Team Arena, OpenArena, Urban Terror)
[vitaRTCW](https://vitadb.rinnegatamante.it/#/info/459) - Port of iortcw (Return to Castle Wolfenstein)
[vitaHexenII](https://vitadb.rinnegatamante.it/#/info/196) - Port of Hexen II
[vitaXash3D](https://vitadb.rinnegatamante.it/#/info/365) - Port of Xash3D (Half Life, Counter Strike 1.6)
diff --git a/deps/vitaGL/samples/sample2/Makefile b/deps/vitaGL/samples/sample2/Makefile index bdbdbd8e39..9a385a0fda 100644 --- a/deps/vitaGL/samples/sample2/Makefile +++ b/deps/vitaGL/samples/sample2/Makefile @@ -4,7 +4,7 @@ SOURCES := . 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)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) diff --git a/deps/vitaGL/samples/sample4/Makefile b/deps/vitaGL/samples/sample4/Makefile index 5a2d34a73b..16fdc27ac7 100644 --- a/deps/vitaGL/samples/sample4/Makefile +++ b/deps/vitaGL/samples/sample4/Makefile @@ -4,7 +4,7 @@ SOURCES := . 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)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) diff --git a/deps/vitaGL/samples/sample5/Makefile b/deps/vitaGL/samples/sample5/Makefile index 32f94c96c5..964bd24cce 100644 --- a/deps/vitaGL/samples/sample5/Makefile +++ b/deps/vitaGL/samples/sample5/Makefile @@ -4,7 +4,7 @@ SOURCES := . 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)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) diff --git a/deps/vitaGL/samples/sample5/main.c b/deps/vitaGL/samples/sample5/main.c index 5d8f35edc3..6b4389c403 100644 --- a/deps/vitaGL/samples/sample5/main.c +++ b/deps/vitaGL/samples/sample5/main.c @@ -21,13 +21,6 @@ uint16_t indices[] = { 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(){ // Initializing graphics device @@ -53,7 +46,7 @@ int main(){ glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); 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); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube diff --git a/deps/vitaGL/samples/sample6/Makefile b/deps/vitaGL/samples/sample6/Makefile index bc0a5fe656..eaf8e9f488 100644 --- a/deps/vitaGL/samples/sample6/Makefile +++ b/deps/vitaGL/samples/sample6/Makefile @@ -4,7 +4,7 @@ SOURCES := . 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)) CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) diff --git a/deps/vitaGL/samples/sample6/main.c b/deps/vitaGL/samples/sample6/main.c index 464c0be430..817eeecf05 100644 --- a/deps/vitaGL/samples/sample6/main.c +++ b/deps/vitaGL/samples/sample6/main.c @@ -25,13 +25,6 @@ uint16_t indices[] = { 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(){ // Initializing graphics device @@ -67,7 +60,7 @@ int main(){ glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glMatrixMode(GL_PROJECTION); 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); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -3.0f); // Centering the cube diff --git a/deps/vitaGL/samples/sample8/Makefile b/deps/vitaGL/samples/sample8/Makefile new file mode 100644 index 0000000000..68a1481bd6 --- /dev/null +++ b/deps/vitaGL/samples/sample8/Makefile @@ -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 diff --git a/deps/vitaGL/samples/sample8/main.c b/deps/vitaGL/samples/sample8/main.c new file mode 100644 index 0000000000..9a7feee685 --- /dev/null +++ b/deps/vitaGL/samples/sample8/main.c @@ -0,0 +1,76 @@ +// Drawing a rotating cube + +#include +#include + +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(); + +} \ No newline at end of file diff --git a/deps/vitaGL/source/custom_shaders.c b/deps/vitaGL/source/custom_shaders.c index f199a70c20..e3cd811435 100644 --- a/deps/vitaGL/source/custom_shaders.c +++ b/deps/vitaGL/source/custom_shaders.c @@ -23,12 +23,14 @@ #include "shared.h" -#define MAX_CUSTOM_SHADERS 32 // Maximum number of linkable custom shaders -#define MAX_SHADER_PARAMS 16 // Maximum number of parameters per custom shader +#define MAX_CUSTOM_SHADERS 64 // Maximum number of linkable custom shaders +#define MAX_SHADER_PARAMS 8 // Maximum number of parameters per custom shader // Internal stuffs void *frag_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) @@ -45,6 +47,7 @@ typedef struct shader { GLboolean valid; SceGxmShaderPatcherId id; const SceGxmProgram *prog; + uint32_t size; } shader; // Program struct holding vertex/fragment shader info @@ -52,8 +55,8 @@ typedef struct program { shader *vshader; shader *fshader; GLboolean valid; - SceGxmVertexAttribute attr[16]; - SceGxmVertexStream stream[16]; + SceGxmVertexAttribute attr[MAX_SHADER_PARAMS]; + SceGxmVertexStream stream[MAX_SHADER_PARAMS]; SceGxmVertexProgram *vprog; SceGxmFragmentProgram *fprog; GLuint attr_num; @@ -102,8 +105,8 @@ void reloadCustomShader(void) { } void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean implicit_wvp) { - program *p = &progs[cur_program - 1]; if (implicit_wvp) { + program *p = &progs[cur_program - 1]; if (mvp_modified) { matrix4x4_multiply(mvp_matrix, projection_matrix, modelview_matrix); mvp_modified = GL_FALSE; @@ -121,6 +124,10 @@ void _vglDrawObjects_CustomShadersIMPL(GLenum mode, GLsizei count, GLboolean imp * - IMPLEMENTATION STARTS HERE - * ------------------------------ */ + +void vglEnableRuntimeShaderCompiler(GLboolean usage) { + use_shark = usage; +} GLuint glCreateShader(GLenum shaderType) { // Looking for a free shader slot @@ -146,6 +153,7 @@ GLuint glCreateShader(GLenum shaderType) { break; default: vgl_error = GL_INVALID_ENUM; + return 0; break; } shaders[res - 1].valid = GL_TRUE; @@ -153,17 +161,74 @@ GLuint glCreateShader(GLenum shaderType) { 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) { // Grabbing passed shader shader *s = &shaders[handles[0] - 1]; // Allocating compiled shader on RAM and registering it into sceGxmShaderPatcher 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); 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) { // Grabbing passed shader shader *s = &shaders[shad - 1]; @@ -193,8 +258,9 @@ void glAttachShader(GLuint prog, GLuint shad) { default: break; } - } else - vgl_error = GL_INVALID_VALUE; + } else { + SET_GL_ERROR(GL_INVALID_VALUE) + } } 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) { // Grabbing passed uniform uniform *u = (uniform *)location; @@ -402,7 +505,7 @@ void vglBindPackedAttribLocation(GLuint prog, GLuint index, const GLchar *name, bpe = sizeof(uint8_t); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -425,8 +528,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor #ifndef SKIP_ERROR_HANDLING // Error handling if (stride < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -440,7 +542,7 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor bpe = sizeof(GLshort); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -449,13 +551,13 @@ void vglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean nor // Copying passed data to vitaGL mempool 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 { int i; uint8_t *dst = (uint8_t *)ptr; uint8_t *src = (uint8_t *)pointer; for (i = 0; i < count; i++) { - memcpy(dst, src, bpe * size); + memcpy_neon(dst, src, bpe * size); dst += (bpe * size); src += stride; } diff --git a/deps/vitaGL/source/framebuffers.c b/deps/vitaGL/source/framebuffers.c index bf6258b60e..3e67e28df1 100644 --- a/deps/vitaGL/source/framebuffers.c +++ b/deps/vitaGL/source/framebuffers.c @@ -66,8 +66,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) { int i = 0, j = 0; #ifndef SKIP_ERROR_HANDLING if (n < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif for (i = 0; i < BUFFERS_NUM; i++) { @@ -85,8 +84,7 @@ void glGenFramebuffers(GLsizei n, GLuint *ids) { void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) { #ifndef SKIP_ERROR_HANDLING if (n < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif while (n > 0) { @@ -117,7 +115,7 @@ void glBindFramebuffer(GLenum target, GLuint fb) { active_write_fb = active_read_fb = (framebuffer *)fb; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -134,7 +132,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint fb = active_read_fb; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -178,7 +176,7 @@ void glFramebufferTexture(GLenum target, GLenum attachment, GLuint tex_id, GLint sceGxmCreateRenderTarget(&renderTargetParams, &fb->target); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } diff --git a/deps/vitaGL/source/get_info.c b/deps/vitaGL/source/get_info.c index 314d0aa5aa..36bb0f8db5 100644 --- a/deps/vitaGL/source/get_info.c +++ b/deps/vitaGL/source/get_info.c @@ -80,7 +80,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params) { *params = GL_FALSE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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 for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { - data[i*4+j] = modelview_matrix[j][i]; + data[i * 4 + j] = modelview_matrix[j][i]; } } 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 for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { - data[i*4+j] = projection_matrix[j][i]; + data[i * 4 + j] = projection_matrix[j][i]; } } break; @@ -122,8 +122,14 @@ void glGetFloatv(GLenum pname, GLfloat *data) { case GL_MAX_TEXTURE_STACK_DEPTH: // Max texture stack depth *data = GENERIC_STACK_DEPTH; break; + case GL_DEPTH_BITS: + *data = 32; + break; + case GL_STENCIL_BITS: + *data = 8; + break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -155,8 +161,14 @@ void glGetIntegerv(GLenum pname, GLint *data) { data[2] = gl_viewport.w; data[3] = gl_viewport.h; break; + case GL_DEPTH_BITS: + data[0] = 32; + break; + case GL_STENCIL_BITS: + data[0] = 8; + break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } diff --git a/deps/vitaGL/source/gxm.c b/deps/vitaGL/source/gxm.c index 66b58f371d..53bd49b4c6 100644 --- a/deps/vitaGL/source/gxm.c +++ b/deps/vitaGL/source/gxm.c @@ -23,6 +23,8 @@ #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 *vertex_ring_buffer_addr; // vertex 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 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 GLenum vgl_error = GL_NO_ERROR; // Error returned by glGetError 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_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 struct display_queue_callback_data { void *addr; @@ -95,17 +103,40 @@ static void display_queue_callback(const void *callbackData) { } 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 SceGxmInitializeParams gxm_init_params; 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.displayQueueCallback = display_queue_callback; 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 - sceGxmInitialize(&gxm_init_params); + if (system_app_mode) + sceGxmVshInitialize(&gxm_init_params); + else + sceGxmInitialize(&gxm_init_params); + gxm_initialized = 1; } void initGxmContext(void) { @@ -153,6 +184,17 @@ void termGxmContext(void) { // Destroying sceGxm 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) { @@ -177,16 +219,34 @@ void destroyDisplayRenderTarget(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; int i; for (i = 0; i < DISPLAY_BUFFER_COUNT; i++) { // Allocating color surface memblock - gxm_color_surfaces_addr[i] = gpu_alloc_mapped( - ALIGN(4 * DISPLAY_STRIDE * DISPLAY_HEIGHT, 1 * 1024 * 1024), - &type); + if (!system_app_mode) { + gxm_color_surfaces_addr[i] = gpu_alloc_mapped( + 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 - memset(gxm_color_surfaces_addr[i], 0, DISPLAY_STRIDE * DISPLAY_HEIGHT); sceGxmColorSurfaceInit(&gxm_color_surfaces[i], SCE_GXM_COLOR_FORMAT_A8B8G8R8, SCE_GXM_COLOR_SURFACE_LINEAR, @@ -206,7 +266,8 @@ void termDisplayColorSurfaces(void) { // Deallocating display's color surfaces and destroying sync objects int 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]); } } @@ -317,9 +378,18 @@ void waitRenderingDone(void) { * ------------------------------ */ +void vglSetParamBufferSize(uint32_t size) { + gxm_param_buf_size = size; +} + void vglStartRendering(void) { // Starting drawing scene 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, NULL, NULL, gxm_sync_objects[gxm_back_buffer_index], @@ -338,7 +408,7 @@ void vglStartRendering(void) { // Setting back current viewport if enabled cause sceGxm will reset it at sceGxmEndScene call sceGxmSetViewport(gxm_context, x_port, x_scale, y_port, y_scale, z_port, z_scale); - + if (scissor_test_state) sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, region.x, region.y, region.x + region.w - 1, region.y + region.h - 1); else @@ -348,18 +418,23 @@ void vglStartRendering(void) { void vglStopRenderingInit(void) { // Ending drawing scene sceGxmEndScene(gxm_context, NULL, NULL); + if (system_app_mode && vblank) + sceDisplayWaitVblankStart(); } void vglStopRenderingTerm(void) { if (active_write_fb == NULL) { // Default framebuffer is used - // Properly requesting a display update - struct display_queue_callback_data queue_cb_data; - queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index]; - 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; + if (system_app_mode) + sceSharedFbEnd(shared_fb); + else { + struct display_queue_callback_data queue_cb_data; + queue_cb_data.addr = gxm_color_surfaces_addr[gxm_back_buffer_index]; + 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 diff --git a/deps/vitaGL/source/hacks/memcpy_neon.S b/deps/vitaGL/source/hacks/memcpy_neon.S new file mode 100644 index 0000000000..2f1d33ebb7 --- /dev/null +++ b/deps/vitaGL/source/hacks/memcpy_neon.S @@ -0,0 +1,140 @@ +/* + * NEON code contributed by Siarhei Siamashka . + * 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 + */ + +.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 diff --git a/deps/vitaGL/source/legacy.c b/deps/vitaGL/source/legacy.c index 1b14001e1c..1b7340c402 100644 --- a/deps/vitaGL/source/legacy.c +++ b/deps/vitaGL/source/legacy.c @@ -87,8 +87,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -107,7 +106,7 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) { last_vert->v.x = x; last_vert->v.y = y; last_vert->v.z = z; - memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f)); last_clr->next = last_vert->next = NULL; // Increasing vertex counter @@ -118,8 +117,7 @@ void glVertex3fv(const GLfloat *v) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -135,8 +133,8 @@ void glVertex3fv(const GLfloat *v) { } // Properly populating the new element - memcpy(&last_vert->v, v, sizeof(vector3f)); - memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&last_vert->v, v, sizeof(vector3f)); + memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f)); last_clr->next = last_vert->next = NULL; // Increasing vertex counter @@ -157,7 +155,7 @@ void glColor3f(GLfloat red, GLfloat green, GLfloat blue) { void glColor3fv(const GLfloat *v) { // Setting current color value - memcpy(¤t_color.r, v, sizeof(vector3f)); + memcpy_neon(¤t_color.r, v, sizeof(vector3f)); current_color.a = 1.0f; } @@ -187,7 +185,7 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { void glColor4fv(const GLfloat *v) { // Setting current color value - memcpy(¤t_color.r, v, sizeof(vector4f)); + memcpy_neon(¤t_color.r, v, sizeof(vector4f)); } void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { @@ -209,8 +207,7 @@ void glTexCoord2fv(GLfloat *f) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -232,8 +229,7 @@ void glTexCoord2f(GLfloat s, GLfloat t) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -255,8 +251,7 @@ void glTexCoord2i(GLint s, GLint t) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -278,8 +273,7 @@ void glArrayElement(GLint i) { #ifndef SKIP_ERROR_HANDLING // Error handling if (i < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -309,7 +303,7 @@ void glArrayElement(GLint i) { last_clr->next = NULL; // 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 if (tex_unit->color_array_state) { @@ -322,11 +316,11 @@ void glArrayElement(GLint i) { // Populating new color element 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 { // Populating new color element with current color - memcpy(&last_clr->v, ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&last_clr->v, ¤t_color.r, sizeof(vector4f)); } // Checking if current texture unit has GL_TEXTURE_COORD_ARRAY enabled @@ -347,7 +341,7 @@ void glArrayElement(GLint i) { } // 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; } } @@ -357,8 +351,7 @@ void glBegin(GLenum mode) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -394,7 +387,7 @@ void glBegin(GLenum mode) { np = 4; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -410,7 +403,7 @@ void glEnd(void) { // Error handling if (phase != MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; + SET_GL_ERROR(GL_INVALID_OPERATION) return; } #endif @@ -498,8 +491,8 @@ void glEnd(void) { memset(vertices, 0, (vertex_count * sizeof(vector3f))); indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t)); for (i = 0; i < vertex_count; i++) { - memcpy(&vertices[n], &object->v, sizeof(vector3f)); - memcpy(&uv_map[n], &object_uv->v, sizeof(vector2f)); + memcpy_neon(&vertices[n], &object->v, sizeof(vector3f)); + memcpy_neon(&uv_map[n], &object_uv->v, sizeof(vector2f)); indices[n] = n; object = object->next; object_uv = object_uv->next; @@ -522,8 +515,8 @@ void glEnd(void) { indices[i * 6 + 5] = i * 4 + 3; } for (j = 0; j < vertex_count; j++) { - memcpy(&vertices[j], &object->v, sizeof(vector3f)); - memcpy(&uv_map[j], &object_uv->v, sizeof(vector2f)); + memcpy_neon(&vertices[j], &object->v, sizeof(vector3f)); + memcpy_neon(&uv_map[j], &object_uv->v, sizeof(vector2f)); object = object->next; object_uv = object_uv->next; } @@ -554,8 +547,8 @@ void glEnd(void) { memset(vertices, 0, (vertex_count * sizeof(vector3f))); indices = (uint16_t *)gpu_pool_memalign(idx_count * sizeof(uint16_t), sizeof(uint16_t)); for (i = 0; i < vertex_count; i++) { - memcpy(&vertices[n], &object->v, sizeof(vector3f)); - memcpy(&colors[n], &object_clr->v, sizeof(vector4f)); + memcpy_neon(&vertices[n], &object->v, sizeof(vector3f)); + memcpy_neon(&colors[n], &object_clr->v, sizeof(vector4f)); indices[n] = n; object = object->next; object_clr = object_clr->next; @@ -579,8 +572,8 @@ void glEnd(void) { indices[i * 6 + 5] = i * 4 + 3; } for (j = 0; j < vertex_count; j++) { - memcpy(&vertices[j], &object->v, sizeof(vector3f)); - memcpy(&colors[j], &object_clr->v, sizeof(vector4f)); + memcpy_neon(&vertices[j], &object->v, sizeof(vector3f)); + memcpy_neon(&colors[j], &object_clr->v, sizeof(vector4f)); object = object->next; object_clr = object_clr->next; } diff --git a/deps/vitaGL/source/matrices.c b/deps/vitaGL/source/matrices.c index 26c40226fa..50a65e536f 100644 --- a/deps/vitaGL/source/matrices.c +++ b/deps/vitaGL/source/matrices.c @@ -46,7 +46,7 @@ void glMatrixMode(GLenum mode) { matrix = &projection_matrix; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -55,11 +55,9 @@ void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdou #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } else if ((left == right) || (bottom == top) || (nearVal == farVal)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -72,11 +70,9 @@ void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLd #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } else if ((left == right) || (bottom == top) || (nearVal < 0) || (farVal < 0)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -102,7 +98,7 @@ void glMultMatrixf(const GLfloat *m) { tmp[i][j] = m[j * 4 + i]; } } - + // Multiplicating passed matrix with in use one matrix4x4_multiply(res, *matrix, tmp); @@ -139,8 +135,7 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -162,8 +157,7 @@ void glPushMatrix(void) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -171,7 +165,7 @@ void glPushMatrix(void) { #ifndef SKIP_ERROR_HANDLING // Error handling if (modelview_stack_counter >= MODELVIEW_STACK_DEPTH) { - vgl_error = GL_STACK_OVERFLOW; + SET_GL_ERROR(GL_STACK_OVERFLOW) } else #endif // Copying current matrix into the matrix stack and increasing stack counter @@ -181,7 +175,7 @@ void glPushMatrix(void) { #ifndef SKIP_ERROR_HANDLING // Error handling if (projection_stack_counter >= GENERIC_STACK_DEPTH) { - vgl_error = GL_STACK_OVERFLOW; + SET_GL_ERROR(GL_STACK_OVERFLOW) } else #endif // Copying current matrix into the matrix stack and increasing stack counter @@ -193,17 +187,16 @@ void glPopMatrix(void) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif if (matrix == &modelview_matrix) { #ifndef SKIP_ERROR_HANDLING // Error handling - if (modelview_stack_counter == 0) - vgl_error = GL_STACK_UNDERFLOW; - else + if (modelview_stack_counter == 0) { + SET_GL_ERROR(GL_STACK_UNDERFLOW) + } else #endif // Copying last matrix on stack into current matrix and decreasing stack counter matrix4x4_copy(*matrix, modelview_matrix_stack[--modelview_stack_counter]); @@ -211,12 +204,25 @@ void glPopMatrix(void) { } else if (matrix == &projection_matrix) { #ifndef SKIP_ERROR_HANDLING // Error handling - if (projection_stack_counter == 0) - vgl_error = GL_STACK_UNDERFLOW; - else + if (projection_stack_counter == 0) { + SET_GL_ERROR(GL_STACK_UNDERFLOW) + } else #endif // Copying last matrix on stack into current matrix and decreasing stack counter matrix4x4_copy(*matrix, projection_matrix_stack[--projection_stack_counter]); } 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; +} diff --git a/deps/vitaGL/source/misc.c b/deps/vitaGL/source/misc.c index 69116f437e..b5e71277c2 100644 --- a/deps/vitaGL/source/misc.c +++ b/deps/vitaGL/source/misc.c @@ -119,7 +119,7 @@ void glPolygonMode(GLenum face, GLenum mode) { new_mode = SCE_GXM_POLYGON_MODE_TRIANGLE_FILL; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } switch (face) { @@ -140,7 +140,7 @@ void glPolygonMode(GLenum face, GLenum mode) { sceGxmSetBackPolygonMode(gxm_context, new_mode); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) return; } update_polygon_offset(); @@ -167,8 +167,7 @@ void glFrontFace(GLenum mode) { void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { #ifndef SKIP_ERROR_HANDLING if ((width < 0) || (height < 0)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif x_scale = width >> 1; @@ -197,8 +196,7 @@ void glDepthRangef(GLfloat nearVal, GLfloat farVal) { void glEnable(GLenum cap) { #ifndef SKIP_ERROR_HANDLING if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif switch (cap) { @@ -250,7 +248,7 @@ void glEnable(GLenum cap) { clip_plane0 = GL_TRUE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -258,8 +256,7 @@ void glEnable(GLenum cap) { void glDisable(GLenum cap) { #ifndef SKIP_ERROR_HANDLING if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif switch (cap) { @@ -311,7 +308,7 @@ void glDisable(GLenum cap) { clip_plane0 = GL_FALSE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -411,7 +408,7 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -429,12 +426,12 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -443,8 +440,7 @@ void glLineWidth(GLfloat width) { #ifndef SKIP_ERROR_HANDLING // Error handling if (width <= 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -457,8 +453,7 @@ void glPointSize(GLfloat size) { #ifndef SKIP_ERROR_HANDLING // Error handling if (size <= 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -483,7 +478,7 @@ void glFogf(GLenum pname, GLfloat param) { fog_far = param; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -504,10 +499,10 @@ void glFogfv(GLenum pname, const GLfloat *params) { fog_far = params[0]; break; case GL_FOG_COLOR: - memcpy(&fog_color.r, params, sizeof(vector4f)); + memcpy_neon(&fog_color.r, params, sizeof(vector4f)); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -528,7 +523,7 @@ void glFogi(GLenum pname, const GLint param) { fog_far = param; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -545,10 +540,10 @@ void glClipPlane(GLenum plane, const GLdouble *equation) { matrix4x4_transpose(inverted_transposed, inverted); vector4f temp; 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; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } diff --git a/deps/vitaGL/source/shaders.h b/deps/vitaGL/source/shaders.h index 24a9db1c13..705ec6f04d 100644 --- a/deps/vitaGL/source/shaders.h +++ b/deps/vitaGL/source/shaders.h @@ -25,81 +25,81 @@ #define _SHADERS_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; +extern SceGxmShaderPatcherId disable_color_buffer_fragment_id; +extern const SceGxmProgramParameter *disable_color_buffer_position; +extern SceGxmFragmentProgram *disable_color_buffer_fragment_program_patched; +extern 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; +extern SceGxmShaderPatcherId clear_vertex_id; +extern SceGxmShaderPatcherId clear_fragment_id; +extern const SceGxmProgramParameter *clear_position; +extern const SceGxmProgramParameter *clear_color; +extern SceGxmVertexProgram *clear_vertex_program_patched; +extern 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; +extern SceGxmShaderPatcherId rgba_vertex_id; +extern SceGxmShaderPatcherId rgb_vertex_id; +extern SceGxmShaderPatcherId rgba_fragment_id; +extern const SceGxmProgramParameter *rgba_position; +extern const SceGxmProgramParameter *rgba_color; +extern const SceGxmProgramParameter *rgba_wvp; +extern const SceGxmProgramParameter *rgb_position; +extern const SceGxmProgramParameter *rgb_color; +extern const SceGxmProgramParameter *rgb_wvp; +extern SceGxmVertexProgram *rgba_vertex_program_patched; +extern SceGxmVertexProgram *rgba_u8n_vertex_program_patched; +extern SceGxmVertexProgram *rgb_vertex_program_patched; +extern SceGxmVertexProgram *rgb_u8n_vertex_program_patched; +extern SceGxmFragmentProgram *rgba_fragment_program_patched; +extern 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; +extern SceGxmShaderPatcherId texture2d_vertex_id; +extern SceGxmShaderPatcherId texture2d_fragment_id; +extern const SceGxmProgramParameter *texture2d_position; +extern const SceGxmProgramParameter *texture2d_texcoord; +extern const SceGxmProgramParameter *texture2d_wvp; +extern const SceGxmProgramParameter *texture2d_alpha_cut; +extern const SceGxmProgramParameter *texture2d_alpha_op; +extern const SceGxmProgramParameter *texture2d_tint_color; +extern const SceGxmProgramParameter *texture2d_tex_env; +extern const SceGxmProgramParameter *texture2d_clip_plane0; +extern const SceGxmProgramParameter *texture2d_clip_plane0_eq; +extern const SceGxmProgramParameter *texture2d_mv; +extern const SceGxmProgramParameter *texture2d_fog_mode; +extern const SceGxmProgramParameter *texture2d_fog_near; +extern const SceGxmProgramParameter *texture2d_fog_far; +extern const SceGxmProgramParameter *texture2d_fog_density; +extern const SceGxmProgramParameter *texture2d_fog_color; +extern const SceGxmProgramParameter *texture2d_tex_env_color; +extern SceGxmVertexProgram *texture2d_vertex_program_patched; +extern SceGxmFragmentProgram *texture2d_fragment_program_patched; +extern 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; +extern SceGxmShaderPatcherId texture2d_rgba_vertex_id; +extern SceGxmShaderPatcherId texture2d_rgba_fragment_id; +extern const SceGxmProgramParameter *texture2d_rgba_position; +extern const SceGxmProgramParameter *texture2d_rgba_texcoord; +extern const SceGxmProgramParameter *texture2d_rgba_wvp; +extern const SceGxmProgramParameter *texture2d_rgba_alpha_cut; +extern const SceGxmProgramParameter *texture2d_rgba_alpha_op; +extern const SceGxmProgramParameter *texture2d_rgba_color; +extern const SceGxmProgramParameter *texture2d_rgba_tex_env; +extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0; +extern const SceGxmProgramParameter *texture2d_rgba_clip_plane0_eq; +extern const SceGxmProgramParameter *texture2d_rgba_mv; +extern const SceGxmProgramParameter *texture2d_rgba_fog_mode; +extern const SceGxmProgramParameter *texture2d_rgba_fog_near; +extern const SceGxmProgramParameter *texture2d_rgba_fog_far; +extern const SceGxmProgramParameter *texture2d_rgba_fog_density; +extern const SceGxmProgramParameter *texture2d_rgba_fog_color; +extern const SceGxmProgramParameter *texture2d_rgba_tex_env_color; +extern SceGxmVertexProgram *texture2d_rgba_vertex_program_patched; +extern SceGxmVertexProgram *texture2d_rgba_u8n_vertex_program_patched; +extern SceGxmFragmentProgram *texture2d_rgba_fragment_program_patched; +extern const SceGxmProgram *texture2d_rgba_fragment_program; #endif diff --git a/deps/vitaGL/source/shared.h b/deps/vitaGL/source/shared.h index 6be0eb7723..021434883e 100644 --- a/deps/vitaGL/source/shared.h +++ b/deps/vitaGL/source/shared.h @@ -56,6 +56,8 @@ extern float DISPLAY_HEIGHT_FLOAT; // Display height in pixels (float) #include "state.h" #include "texture_callbacks.h" +#define SET_GL_ERROR(x) vgl_error = x; return; + // Texture environment mode typedef enum texEnvMode { MODULATE = 0, @@ -107,6 +109,9 @@ void LOG(const char *format, ...); #define max(a, b) ((a) > (b) ? (a) : (b)) #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) extern float x_port; extern float y_port; @@ -126,10 +131,11 @@ extern float fullscreen_z_scale; extern SceGxmContext *gxm_context; // sceGxm context instance extern GLenum vgl_error; // Error returned by glGetError 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 -matrix4x4 projection_matrix; // Projection Matrix -matrix4x4 modelview_matrix; // ModelView Matrix +extern matrix4x4 mvp_matrix; // ModelViewProjection Matrix +extern matrix4x4 projection_matrix; // Projection Matrix +extern matrix4x4 modelview_matrix; // ModelView Matrix 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) diff --git a/deps/vitaGL/source/state.h b/deps/vitaGL/source/state.h index fea6184987..3b9f21c0e5 100644 --- a/deps/vitaGL/source/state.h +++ b/deps/vitaGL/source/state.h @@ -96,6 +96,7 @@ typedef struct texture_unit { SceGxmTextureFilter mag_filter; SceGxmTextureAddrMode u_mode; SceGxmTextureAddrMode v_mode; + uint32_t lod_bias; } texture_unit; // Framebuffer struct diff --git a/deps/vitaGL/source/tests.c b/deps/vitaGL/source/tests.c index cce5dd5800..8e0251412a 100644 --- a/deps/vitaGL/source/tests.c +++ b/deps/vitaGL/source/tests.c @@ -246,21 +246,21 @@ void update_scissor_test() { // Setting current vertex program to clear screen one and fragment program to scissor test one sceGxmSetVertexProgram(gxm_context, clear_vertex_program_patched); sceGxmSetFragmentProgram(gxm_context, scissor_test_fragment_program); - + // Invalidating viewport invalidate_viewport(); - + // Invalidating internal tile based region clip sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1); - + if (scissor_test_state) { // Calculating scissor test region vertices vector4f_convert_to_local_space(scissor_test_vertices, region.x, region.y, region.w, region.h); - + void *vertex_buffer; sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vertex_buffer); sceGxmSetUniformDataF(vertex_buffer, clear_position, 0, 4, &clear_vertices->x); - + // Cleaning stencil surface mask update bit on the whole screen sceGxmSetFrontStencilFunc(gxm_context, SCE_GXM_STENCIL_FUNC_NEVER, @@ -290,7 +290,7 @@ void update_scissor_test() { SCE_GXM_STENCIL_OP_KEEP, SCE_GXM_STENCIL_OP_KEEP, 0, 0); - + void *vertex_buffer; sceGxmReserveVertexDefaultUniformBuffer(gxm_context, &vertex_buffer); if (scissor_test_state) @@ -298,14 +298,14 @@ void update_scissor_test() { else sceGxmSetUniformDataF(vertex_buffer, clear_position, 0, 4, &clear_vertices->x); sceGxmDraw(gxm_context, SCE_GXM_PRIMITIVE_TRIANGLE_FAN, SCE_GXM_INDEX_FORMAT_U16, depth_clear_indices, 4); - + // Restoring viewport validate_viewport(); - + // Reducing GPU workload by performing tile granularity clipping if (scissor_test_state) sceGxmSetRegionClip(gxm_context, SCE_GXM_REGION_CLIP_OUTSIDE, region.x, region.y, region.x + region.w - 1, region.y + region.h - 1); - + // Restoring original stencil test settings change_stencil_settings(); } @@ -327,8 +327,7 @@ void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { #ifndef SKIP_ERROR_HANDLING // Error handling if ((width < 0) || (height < 0)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -385,8 +384,7 @@ void glDepthMask(GLboolean flag) { #ifndef SKIP_ERROR_HANDLING // Error handling if (phase == MODEL_CREATION) { - vgl_error = GL_INVALID_OPERATION; - return; + SET_GL_ERROR(GL_INVALID_OPERATION) } #endif @@ -407,36 +405,36 @@ void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass switch (face) { case GL_FRONT: 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)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) if (!change_stencil_config(&depth_pass_front, dppass)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; case GL_BACK: 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)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) if (!change_stencil_config(&depth_pass_front, dppass)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; case GL_FRONT_AND_BACK: 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)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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)) - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } change_stencil_settings(); @@ -450,27 +448,31 @@ void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) { // Properly updating stencil test function settings switch (face) { case GL_FRONT: - if (!change_stencil_func_config(&stencil_func_front, func)) - vgl_error = GL_INVALID_ENUM; + if (!change_stencil_func_config(&stencil_func_front, func)) { + SET_GL_ERROR(GL_INVALID_ENUM) + } stencil_mask_front = mask; stencil_ref_front = ref; break; case GL_BACK: - 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_back = mask; stencil_ref_back = ref; break; case GL_FRONT_AND_BACK: - if (!change_stencil_func_config(&stencil_func_front, func)) - vgl_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_front, func)) { + SET_GL_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_ref_front = stencil_ref_back = ref; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } change_stencil_settings(); @@ -493,7 +495,7 @@ void glStencilMaskSeparate(GLenum face, GLuint mask) { stencil_mask_front_write = stencil_mask_back_write = mask; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) return; } change_stencil_settings(); diff --git a/deps/vitaGL/source/texture_callbacks.c b/deps/vitaGL/source/texture_callbacks.c index 08039147e4..48f42cbafd 100644 --- a/deps/vitaGL/source/texture_callbacks.c +++ b/deps/vitaGL/source/texture_callbacks.c @@ -24,12 +24,15 @@ #include #include +#include "vitaGL.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 uint32_t readRGBA(void *data) { uint32_t res; - memcpy(&res, data, 4); + memcpy_neon(&res, data, 4); return res; } @@ -37,48 +40,71 @@ uint32_t readRGBA(void *data) { uint32_t readRGBA5551(void *data) { uint16_t clr; uint32_t r, g, b, a; - memcpy(&clr, data, 2); - r = (((clr >> 11) & 0x1F) * 0xFF) / 0x1F; - g = ((((clr << 5) >> 11) & 0x1F) * 0xFF) / 0x1F; - b = ((((clr << 10) >> 11) & 0x1F) * 0xFF) / 0x1F; - a = (((clr << 15) >> 15) & 0x1) == 1 ? 0xFF : 0x00; + memcpy_neon(&clr, data, 2); + r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F); + g = convert_u16_to_u32_cspace(clr, 5, 11, 0x1F); + b = convert_u16_to_u32_cspace(clr, 10, 11, 0x1F); + a = convert_u16_to_u32_cspace(clr, 15, 15, 0x01); 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 uint32_t readRGB(void *data) { uint32_t res = 0xFFFFFFFF; - memcpy(&res, data, 3); + memcpy_neon(&res, data, 3); return res; } // Read callback for 16bpp unsigned RG format uint32_t readRG(void *data) { uint32_t res = 0xFFFFFFFF; - memcpy(&res, data, 2); + memcpy_neon(&res, data, 2); return res; } // Read callback for 8bpp unsigned R format uint32_t readR(void *data) { uint32_t res = 0xFFFFFFFF; - memcpy(&res, data, 1); + memcpy_neon(&res, data, 1); return res; } // Write callback for 32bpp unsigned RGBA format void writeRGBA(void *data, uint32_t color) { - memcpy(data, &color, 4); + memcpy_neon(data, &color, 4); } // Write callback for 24bpp unsigned RGB format void writeRGB(void *data, uint32_t color) { - memcpy(data, &color, 3); + memcpy_neon(data, &color, 3); } // Write callback for 16bpp unsigned RG format void writeRG(void *data, uint32_t color) { - memcpy(data, &color, 2); + memcpy_neon(data, &color, 2); } // 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 void writeR(void *data, uint32_t color) { - memcpy(data, &color, 1); + memcpy_neon(data, &color, 1); } \ No newline at end of file diff --git a/deps/vitaGL/source/texture_callbacks.h b/deps/vitaGL/source/texture_callbacks.h index e9177ac78c..dd038b5bc2 100644 --- a/deps/vitaGL/source/texture_callbacks.h +++ b/deps/vitaGL/source/texture_callbacks.h @@ -28,8 +28,10 @@ uint32_t readR(void *data); uint32_t readRG(void *data); uint32_t readRGB(void *data); +uint32_t readRGB565(void *data); uint32_t readRGBA(void *data); uint32_t readRGBA5551(void *data); +uint32_t readRGBA4444(void *data); // Write callbacks void writeR(void *data, uint32_t color); diff --git a/deps/vitaGL/source/textures.c b/deps/vitaGL/source/textures.c index 8d7295926c..2a74bc6231 100644 --- a/deps/vitaGL/source/textures.c +++ b/deps/vitaGL/source/textures.c @@ -37,8 +37,7 @@ void glGenTextures(GLsizei n, GLuint *res) { #ifndef SKIP_ERROR_HANDLING // Error handling if (n < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -67,7 +66,7 @@ void glBindTexture(GLenum target, GLuint texture) { tex_unit->tex_id = texture; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -76,8 +75,7 @@ void glDeleteTextures(GLsizei n, const GLuint *gl_textures) { #ifndef SKIP_ERROR_HANDLING // Error handling if (n < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif @@ -138,7 +136,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt data_bpp = 1; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -150,7 +148,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt data_bpp = 2; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -158,11 +156,17 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt switch (type) { case GL_UNSIGNED_BYTE: data_bpp = 3; - if (internalFormat == GL_RGB) fast_store = GL_TRUE; - else read_cb = readRGB; + if (internalFormat == GL_RGB) + fast_store = GL_TRUE; + else + read_cb = readRGB; + break; + case GL_UNSIGNED_SHORT_5_6_5: + data_bpp = 2; + read_cb = readRGB565; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -170,15 +174,21 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt switch (type) { case GL_UNSIGNED_BYTE: data_bpp = 4; - if (internalFormat == GL_RGBA) fast_store = GL_TRUE; - else read_cb = readRGBA; + if (internalFormat == GL_RGBA) + fast_store = GL_TRUE; + else + read_cb = readRGBA; break; case GL_UNSIGNED_SHORT_5_5_5_1: data_bpp = 2; read_cb = readRGBA5551; break; + case GL_UNSIGNED_SHORT_4_4_4_4: + data_bpp = 2; + read_cb = readRGBA4444; + break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -225,22 +235,23 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt tex_format = SCE_GXM_TEXTURE_FORMAT_P8_ABGR; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } // Checking if texture is too big for sceGxm if (width > GXM_TEX_MAX_SIZE || height > GXM_TEX_MAX_SIZE) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } // Allocating texture/mipmaps depending on user call tex->type = internalFormat; tex->write_cb = write_cb; if (level == 0) - if (tex->write_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); + if (tex->write_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 { gpu_alloc_mipmaps(level, tex); 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); sceGxmTextureSetMinFilter(&tex->gxm_tex, tex_unit->min_filter); sceGxmTextureSetMagFilter(&tex->gxm_tex, tex_unit->mag_filter); + sceGxmTextureSetLodBias(&tex->gxm_tex, tex_unit->lod_bias); // Setting palette if the format requests one if (tex->valid && tex->palette_UID) @@ -258,7 +270,7 @@ void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei widt break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -281,13 +293,11 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G int i, j; if (xoffset + width > orig_w) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } else if (yoffset + height > orig_h) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } - + // Support for legacy GL1.0 format switch (format) { case 1: @@ -303,7 +313,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G format = GL_RGBA; break; } - + /* * Callbacks are actually used to just perform down/up-sampling * between U8 texture formats. Reads are expected to give as result @@ -323,8 +333,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G data_bpp = 1; break; default: - vgl_error = GL_INVALID_ENUM; - return; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -335,8 +344,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G data_bpp = 2; break; default: - vgl_error = GL_INVALID_ENUM; - return; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -346,9 +354,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G data_bpp = 3; read_cb = readRGB; break; + case GL_UNSIGNED_SHORT_5_6_5: + data_bpp = 2; + read_cb = readRGB565; + break; default: - vgl_error = GL_INVALID_ENUM; - return; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -362,9 +373,12 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G data_bpp = 2; read_cb = readRGBA5551; break; + case GL_UNSIGNED_SHORT_4_4_4_4: + data_bpp = 2; + read_cb = readRGBA4444; + break; default: - vgl_error = GL_INVALID_ENUM; - return; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; @@ -410,7 +424,7 @@ void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, G break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -431,12 +445,12 @@ void glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum fo bpp = 4; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -470,7 +484,7 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) { case GL_LINEAR_MIPMAP_LINEAR: // TODO: Implement this break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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 break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode); 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: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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 sceGxmTextureSetVAddrMode(&tex->gxm_tex, tex_unit->v_mode); 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: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -607,9 +629,9 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) { void glActiveTexture(GLenum texture) { // Changing current in use server texture unit #ifndef SKIP_ERROR_HANDLING - if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) - vgl_error = GL_INVALID_ENUM; - else + if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) { + SET_GL_ERROR(GL_INVALID_ENUM) + } else #endif server_texture_unit = texture - GL_TEXTURE0; } @@ -641,7 +663,7 @@ void glGenerateMipmap(GLenum target) { break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -667,12 +689,13 @@ void glTexEnvf(GLenum target, GLenum pname, GLfloat param) { tex_unit->env_mode = ADD; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; 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: switch (pname) { case GL_TEXTURE_ENV_COLOR: - memcpy(&texenv_color.r, param, sizeof(GLfloat) * 4); + memcpy_neon(&texenv_color.r, param, sizeof(GLfloat) * 4); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; 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; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } diff --git a/deps/vitaGL/source/utils/gpu_utils.c b/deps/vitaGL/source/utils/gpu_utils.c index cdda870475..6097b1deb3 100644 --- a/deps/vitaGL/source/utils/gpu_utils.c +++ b/deps/vitaGL/source/utils/gpu_utils.c @@ -25,8 +25,8 @@ #include "stb_dxt.h" #ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)<(b))?(b):(a)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) < (b)) ? (b) : (a)) #endif // VRAM usage setting @@ -45,29 +45,27 @@ static unsigned int pool_size = 0; vglMemType frag_usse_type; vglMemType vert_usse_type; -uint64_t morton_1(uint64_t x) -{ - x = x & 0x5555555555555555; - x = (x | (x >> 1)) & 0x3333333333333333; - x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F; - x = (x | (x >> 4)) & 0x00FF00FF00FF00FF; - x = (x | (x >> 8)) & 0x0000FFFF0000FFFF; - x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF; - return x; +uint64_t morton_1(uint64_t x) { + x = x & 0x5555555555555555; + x = (x | (x >> 1)) & 0x3333333333333333; + x = (x | (x >> 2)) & 0x0F0F0F0F0F0F0F0F; + x = (x | (x >> 4)) & 0x00FF00FF00FF00FF; + x = (x | (x >> 8)) & 0x0000FFFF0000FFFF; + x = (x | (x >> 16)) & 0xFFFFFFFFFFFFFFFF; + return x; } -void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) -{ - *x = morton_1(d); - *y = morton_1(d >> 1); +void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) { + *x = morton_1(d); + *y = morton_1(d >> 1); } void extract_block(const uint8_t *src, int width, uint8_t *block) { int 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; - } + } } void dxt_compress(uint8_t *dst, uint8_t *src, int w, int h, int isdxt5) { @@ -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; for (d = 0; d < num_blocks; d++) { d2xy_morton(d, &offs_x, &offs_y); - if (offs_x * 4 >= h) continue; - if (offs_y * 4 >= w) continue; + if (offs_x * 4 >= h) + continue; + if (offs_y * 4 >= w) + continue; extract_block(src + offs_y * 16 + offs_x * w * 16, w, block); stb_compress_dxt_block(dst, block, isdxt5, STB_DXT_HIGHQUAL); dst += isdxt5 ? 16 : 8; @@ -239,7 +239,7 @@ palette *gpu_alloc_palette(const void *data, uint32_t w, uint32_t bpe) { if (data == NULL) memset(texture_palette, 0, 256 * sizeof(uint32_t)); 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; // Returning palette @@ -274,11 +274,11 @@ void gpu_alloc_texture(uint32_t w, uint32_t h, SceGxmTextureFormat format, const int i, j; uint8_t *src = (uint8_t *)data; 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; for (i = 0; i < h; 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; } } else { // Different internal and data formats, we need to go with slower callbacks system @@ -310,20 +310,21 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo // If there's already a texture in passed texture object we first dealloc it if (tex->valid) gpu_free_texture(tex); - + // Getting texture format alignment uint8_t alignment = tex_format_to_alignment(format); - + // Calculating swizzled compressed texture size on memory tex->mtype = use_vram ? VGL_MEM_VRAM : VGL_MEM_RAM; int tex_size = w * h; - if (alignment == 8) tex_size /= 2; - + if (alignment == 8) + tex_size /= 2; + // Allocating texture data buffer void *texture_data = gpu_alloc_mapped(tex_size, &tex->mtype); - + // NOTE: Supports only GL_RGBA source format for now - + // Initializing texture data buffer if (texture_data != NULL) { // Initializing texture data buffer @@ -338,11 +339,10 @@ void gpu_alloc_compressed_texture(uint32_t w, uint32_t h, SceGxmTextureFormat fo writeRGBA(dst++, src); src += src_bpp; }*/ - + // 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); //free(tmp); //free(tmp2); @@ -418,7 +418,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) { has_temp_buffer = GL_FALSE; temp = sceGxmTextureGetData(&tex->gxm_tex); } 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); } @@ -427,7 +427,7 @@ void gpu_alloc_mipmaps(int level, texture *tex) { void *texture_data = gpu_alloc_mapped(size, &tex->mtype); // 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) free(temp); else diff --git a/deps/vitaGL/source/utils/math_utils.c b/deps/vitaGL/source/utils/math_utils.c index 3b2ab113c8..ef9390781e 100644 --- a/deps/vitaGL/source/utils/math_utils.c +++ b/deps/vitaGL/source/utils/math_utils.c @@ -36,7 +36,7 @@ void matrix4x4_identity(matrix4x4 m) { } 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) { diff --git a/deps/vitaGL/source/utils/mem_utils.c b/deps/vitaGL/source/utils/mem_utils.c index 0a46a312eb..3d23d96871 100644 --- a/deps/vitaGL/source/utils/mem_utils.c +++ b/deps/vitaGL/source/utils/mem_utils.c @@ -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) vgl_mem_term(); - mempool_size[0] = ALIGN(size_cdram, 256 * 1024); - mempool_size[1] = ALIGN(size_ram, 4 * 1024); - mempool_size[2] = ALIGN(size_phycont, 256 * 1024); - mempool_id[0] = sceKernelAllocMemBlock("cdram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, mempool_size[0], NULL); - mempool_id[1] = sceKernelAllocMemBlock("ram_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, mempool_size[1], NULL); - mempool_id[2] = sceKernelAllocMemBlock("phycont_mempool", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_RW, mempool_size[2], NULL); + mempool_size[VGL_MEM_VRAM - 1] = ALIGN(size_cdram, 256 * 1024); + mempool_size[VGL_MEM_RAM - 1] = ALIGN(size_ram, 4 * 1024); + mempool_size[VGL_MEM_SLOW - 1] = ALIGN(size_phycont, 256 * 1024); + if (size_cdram) + 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[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++) { - sceKernelGetMemBlockBase(mempool_id[i], &mempool_addr[i]); - sceGxmMapMemory(mempool_addr[i], mempool_size[i], SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE); + if (mempool_size[i]) { + 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 heap_init(); // 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_SLOW, mempool_addr[2], mempool_size[2]); + if (size_phycont) + heap_extend(VGL_MEM_SLOW, mempool_addr[2], mempool_size[2]); return 1; } diff --git a/deps/vitaGL/source/utils/stb_dxt.h b/deps/vitaGL/source/utils/stb_dxt.h index 9f7a4295a8..7441bede63 100644 --- a/deps/vitaGL/source/utils/stb_dxt.h +++ b/deps/vitaGL/source/utils/stb_dxt.h @@ -684,7 +684,7 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a dest += 8; // make a new copy of the data in which alpha is opaque, // 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) data[i][3] = 255; src = &data[0][0]; diff --git a/deps/vitaGL/source/vitaGL.c b/deps/vitaGL/source/vitaGL.c index 925cd12948..58b176c611 100644 --- a/deps/vitaGL/source/vitaGL.c +++ b/deps/vitaGL/source/vitaGL.c @@ -36,6 +36,84 @@ #include "shaders/texture2d_rgba_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 { void *ptr; } gpubuffer; @@ -203,7 +281,7 @@ void vglUseVramForUSSE(GLboolean 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 msaa_mode = msaa; DISPLAY_WIDTH = width; @@ -231,13 +309,8 @@ void vglInitExtended(uint32_t gpu_pool_size, int width, int height, int ram_thre // Initializing sceGxm initGxm(); - // Getting max allocatable CDRAM and RAM memory - SceKernelFreeMemorySizeInfo info; - info.size = sizeof(SceKernelFreeMemorySizeInfo); - sceKernelGetFreeMemorySize(&info); - // 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 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].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].mag_filter = SCE_GXM_TEXTURE_FILTER_LINEAR; texture_units[i].u_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 @@ -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); } +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) { 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; #ifndef SKIP_ERROR_HANDLING if (n < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif for (i = 0; i < BUFFERS_NUM; i++) { @@ -716,8 +807,7 @@ void glGenBuffers(GLsizei n, GLuint *res) { void glBindBuffer(GLenum target, GLuint buffer) { #ifndef SKIP_ERROR_HANDLING if ((buffer != 0x0000) && ((buffer >= BUFFERS_ADDR + BUFFERS_NUM) || (buffer < BUFFERS_ADDR))) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif switch (target) { @@ -728,7 +818,7 @@ void glBindBuffer(GLenum target, GLuint buffer) { index_array_unit = buffer - BUFFERS_ADDR; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -736,7 +826,7 @@ void glBindBuffer(GLenum target, GLuint buffer) { void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) { #ifndef SKIP_ERROR_HANDLING if (n < 0) { - vgl_error = GL_INVALID_VALUE; + SET_GL_ERROR(GL_INVALID_VALUE) return; } #endif @@ -756,8 +846,7 @@ void glDeleteBuffers(GLsizei n, const GLuint *gl_buffers) { void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage) { #ifndef SKIP_ERROR_HANDLING if (size < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif int idx = 0; @@ -769,12 +858,12 @@ void glBufferData(GLenum target, GLsizei size, const GLvoid *data, GLenum usage) idx = index_array_unit; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } vglMemType type = VGL_MEM_VRAM; 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) { @@ -813,7 +902,7 @@ void glBlendFunc(GLenum sfactor, GLenum dfactor) { blend_sfactor_rgb = blend_sfactor_a = SCE_GXM_BLEND_FACTOR_SRC_ALPHA_SATURATE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } if (blend_state) @@ -1033,7 +1122,7 @@ void glBlendEquation(GLenum mode) { blend_func_rgb = blend_func_a = SCE_GXM_BLEND_FUNC_MAX; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } if (blend_state) @@ -1058,7 +1147,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) { blend_func_rgb = SCE_GXM_BLEND_FUNC_MAX; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } switch (modeAlpha) { @@ -1078,7 +1167,7 @@ void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) { blend_func_a = SCE_GXM_BLEND_FUNC_MAX; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 2) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 3) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 2) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } @@ -1209,7 +1295,7 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { skip_draw = GL_TRUE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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; 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)); - memcpy(&vertices[0], ptr, count * sizeof(vector3f)); + memcpy_neon(&vertices[0], ptr, count * sizeof(vector3f)); vec_set = 1; } else ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * tex_unit->vertex_array.stride); 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)); - memcpy(&uv_map[0], ptr_tex, count * sizeof(vector2f)); + memcpy_neon(&uv_map[0], ptr_tex, count * sizeof(vector2f)); tex_set = 1; } else 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.stride == 0) { 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; } else 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)); for (n = 0; n < count; n++) { 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; } 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; } 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; } indices[n] = n; @@ -1390,24 +1476,24 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { uint8_t vec_set = 0, clr_set = 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))); - memcpy(&vertices[n], ptr, count * sizeof(vector3f)); + memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f)); vec_set = 1; } else ptr = ((uint8_t *)tex_unit->vertex_array.pointer) + (first * (tex_unit->vertex_array.stride)); 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))); - 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; } else 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)); for (n = 0; n < count; n++) { 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; } 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; } 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)); indices = (uint16_t *)gpu_pool_memalign(count * sizeof(uint16_t), sizeof(uint16_t)); for (n = 0; n < count; n++) { - memcpy(&colors[n], ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f)); indices[n] = n; } } else { @@ -1441,17 +1527,17 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { uint8_t vec_set = 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))); - memcpy(&vertices[n], ptr, count * sizeof(vector3f)); + memcpy_neon(&vertices[n], ptr, count * sizeof(vector3f)); vec_set = 1; } else 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)); for (n = 0; n < count; n++) { 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; } - memcpy(&colors[n], ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f)); 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) { GLboolean skip_draw = GL_FALSE; #ifndef SKIP_ERROR_HANDLING - if (type != GL_UNSIGNED_SHORT) - vgl_error = GL_INVALID_ENUM; - else if (phase == MODEL_CREATION) - vgl_error = GL_INVALID_OPERATION; - else if (count < 0) - vgl_error = GL_INVALID_VALUE; + if (type != GL_UNSIGNED_SHORT) { + SET_GL_ERROR(GL_INVALID_ENUM) + } else if (phase == MODEL_CREATION) { + SET_GL_ERROR(GL_INVALID_OPERATION) + } else if (count < 0) { + SET_GL_ERROR(GL_INVALID_VALUE) + } #endif switch (mode) { case GL_POINTS: @@ -1500,7 +1587,7 @@ void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *gl_in skip_draw = GL_TRUE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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); else { 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) { 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)); colors = (vector4f *)gpu_pool_memalign(vertex_count_int * sizeof(vector4f), sizeof(vector4f)); 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) - 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)) - 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) 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); for (n = 0; n < vertex_count_int; n++) { 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) - 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 += 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); else { 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) { 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)); 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) - 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) - 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) 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); for (n = 0; n < vertex_count_int; n++) { 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) - 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_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); else { 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; 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)); 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) - 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) memset(vertices, 0, (vertex_count_int * sizeof(texture2d_vertex))); uint8_t *ptr = ((uint8_t *)tex_unit->vertex_array.pointer); for (n = 0; n < vertex_count_int; n++) { 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(&colors[n], ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&vertices[n], ptr, tex_unit->vertex_array.size * tex_unit->vertex_array.num); + memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f)); if (!vertex_array_unit) ptr += tex_unit->vertex_array.stride; } @@ -1734,7 +1821,7 @@ void glEnableClientState(GLenum array) { tex_unit->texture_array_state = GL_TRUE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } @@ -1752,16 +1839,16 @@ void glDisableClientState(GLenum array) { tex_unit->texture_array_state = GL_FALSE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } } void glClientActiveTexture(GLenum texture) { #ifndef SKIP_ERROR_HANDLING - if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) - vgl_error = GL_INVALID_ENUM; - else + if ((texture < GL_TEXTURE0) && (texture > GL_TEXTURE31)) { + SET_GL_ERROR(GL_INVALID_ENUM) + } else #endif 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 2) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } tex_unit->vertex_object = gpu_pool_memalign(count * bpe * size, bpe * size); if (stride == 0) - memcpy(tex_unit->vertex_object, pointer, count * bpe * size); + memcpy_neon(tex_unit->vertex_object, pointer, count * bpe * size); else { int i; uint8_t *dst = (uint8_t *)tex_unit->vertex_object; uint8_t *src = (uint8_t *)pointer; for (i = 0; i < count; i++) { - memcpy(dst, src, bpe * size); + memcpy_neon(dst, src, bpe * size); dst += (bpe * size); 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 3) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } tex_unit->color_object = gpu_pool_memalign(count * bpe * size, bpe * size); tex_unit->color_object_type = type; if (stride == 0) - memcpy(tex_unit->color_object, pointer, count * bpe * size); + memcpy_neon(tex_unit->color_object, pointer, count * bpe * size); else { int i; uint8_t *dst = (uint8_t *)tex_unit->color_object; uint8_t *src = (uint8_t *)pointer; for (i = 0; i < count; i++) { - memcpy(dst, src, bpe * size); + memcpy_neon(dst, src, bpe * size); dst += (bpe * size); 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) { #ifndef SKIP_ERROR_HANDLING if ((stride < 0) || (size < 2) || (size > 4)) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } tex_unit->texture_object = gpu_pool_memalign(count * bpe * size, bpe * size); if (stride == 0) - memcpy(tex_unit->texture_object, pointer, count * bpe * size); + memcpy_neon(tex_unit->texture_object, pointer, count * bpe * size); else { int i; uint8_t *dst = (uint8_t *)tex_unit->texture_object; uint8_t *src = (uint8_t *)pointer; for (i = 0; i < count; i++) { - memcpy(dst, src, bpe * size); + memcpy_neon(dst, src, bpe * size); dst += (bpe * size); 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) { #ifndef SKIP_ERROR_HANDLING if (stride < 0) { - vgl_error = GL_INVALID_VALUE; - return; + SET_GL_ERROR(GL_INVALID_VALUE) } #endif 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); break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } tex_unit->index_object = gpu_pool_memalign(count * bpe, bpe); if (stride == 0) - memcpy(tex_unit->index_object, pointer, count * bpe); + memcpy_neon(tex_unit->index_object, pointer, count * bpe); else { int i; uint8_t *dst = (uint8_t *)tex_unit->index_object; uint8_t *src = (uint8_t *)pointer; for (i = 0; i < count; i++) { - memcpy(dst, src, bpe); + memcpy_neon(dst, src, bpe); dst += bpe; src += stride; } @@ -1938,10 +2021,11 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) { texture_unit *tex_unit = &texture_units[client_texture_unit]; int texture2d_idx = tex_unit->tex_id; #ifndef SKIP_ERROR_HANDLING - if (phase == MODEL_CREATION) - vgl_error = GL_INVALID_OPERATION; - else if (count < 0) - vgl_error = GL_INVALID_VALUE; + if (phase == MODEL_CREATION) { + SET_GL_ERROR(GL_INVALID_OPERATION) + } else if (count < 0) { + SET_GL_ERROR(GL_INVALID_VALUE) + } #endif GLboolean skip_draw = GL_FALSE; switch (mode) { @@ -1967,7 +2051,7 @@ void vglDrawObjects(GLenum mode, GLsizei count, GLboolean implicit_wvp) { skip_draw = GL_TRUE; break; default: - vgl_error = GL_INVALID_ENUM; + SET_GL_ERROR(GL_INVALID_ENUM) break; } 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)); int n; for (n = 0; n < count; n++) { - memcpy(&colors[n], ¤t_color.r, sizeof(vector4f)); + memcpy_neon(&colors[n], ¤t_color.r, sizeof(vector4f)); } sceGxmSetVertexStream(gxm_context, 0, tex_unit->vertex_object); sceGxmSetVertexStream(gxm_context, 1, colors); diff --git a/deps/vitaGL/source/vitaGL.h b/deps/vitaGL/source/vitaGL.h index fd252b844d..4072661241 100644 --- a/deps/vitaGL/source/vitaGL.h +++ b/deps/vitaGL/source/vitaGL.h @@ -24,20 +24,32 @@ extern "C" { #endif #include +#ifdef HAVE_SHARK +#include +#endif // 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 GLbyte int8_t +#define GLubyte uint8_t #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_TRUE 1 @@ -47,6 +59,8 @@ extern "C" { #define GL_ZERO 0 #define GL_ONE 1 +#define GL_NONE 0 + #define GL_POINTS 0x0000 #define GL_LINES 0x0001 #define GL_LINE_LOOP 0x0002 @@ -108,6 +122,8 @@ extern "C" { #define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 #define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 #define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 #define GL_TEXTURE_2D 0x0DE1 #define GL_BYTE 0x1400 #define GL_UNSIGNED_BYTE 0x1401 @@ -218,6 +234,7 @@ extern "C" { #define GL_TEXTURE30 0x84DE #define GL_TEXTURE31 0x84DF #define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_TEXTURE_LOD_BIAS 0x8501 #define GL_INCR_WRAP 0x8507 #define GL_MIRROR_CLAMP_EXT 0x8742 #define GL_DECR_WRAP 0x8508 @@ -234,12 +251,15 @@ extern "C" { #define GL_DYNAMIC_COPY 0x88EA #define GL_FRAGMENT_SHADER 0x8B30 #define GL_VERTEX_SHADER 0x8B31 +#define GL_SHADER_TYPE 0x8B4F +#define GL_COMPILE_STATUS 0x8B81 #define GL_READ_FRAMEBUFFER 0x8CA8 #define GL_DRAW_FRAMEBUFFER 0x8CA9 #define GL_COLOR_ATTACHMENT0 0x8CE0 #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 #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 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 glCompileShader(GLuint shader); GLuint glCreateProgram(void); GLuint glCreateShader(GLenum shaderType); void glCullFace(GLenum mode); @@ -316,6 +337,7 @@ void glGetBooleanv(GLenum pname, GLboolean *params); void glGetFloatv(GLenum pname, GLfloat *data); GLenum glGetError(void); void glGetIntegerv(GLenum pname, GLint *data); +void glGetShaderiv(GLuint handle, GLenum pname, GLint *params); const GLubyte *glGetString(GLenum name); GLint glGetUniformLocation(GLuint prog, const GLchar *name); 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 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 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 glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, 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 glUniform1i(GLint location, GLint v0); 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 glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 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 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 void vglColorPointer(GLint size, GLenum type, GLsizei stride, GLuint count, const GLvoid *pointer); void vglColorPointerMapped(GLenum type, const GLvoid *pointer); @@ -394,12 +422,15 @@ typedef enum { // vgl* void *vglAlloc(uint32_t size, vglMemType type); +void vglEnableRuntimeShaderCompiler(GLboolean usage); void vglEnd(void); void vglFree(void *addr); void *vglGetTexDataPointer(GLenum target); void vglInit(uint32_t gpu_pool_size); 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); +void vglSetParamBufferSize(uint32_t size); void vglStartRendering(); void vglStopRendering(); void vglStopRenderingInit(); @@ -410,6 +441,9 @@ void vglUseVramForUSSE(GLboolean usage); void vglUseExtraMem(GLboolean usage); void vglWaitVblankStart(GLboolean enable); +// NEON optimized memcpy +void *memcpy_neon(void *destination, const void *source, size_t num); + #ifdef __cplusplus } #endif diff --git a/deps/vitaShaRK/.gitattributes b/deps/vitaShaRK/.gitattributes new file mode 100644 index 0000000000..dfe0770424 --- /dev/null +++ b/deps/vitaShaRK/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/deps/vitaShaRK/.github/FUNDING.yml b/deps/vitaShaRK/.github/FUNDING.yml new file mode 100644 index 0000000000..dbd470e946 --- /dev/null +++ b/deps/vitaShaRK/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: Rinnegatamante diff --git a/deps/vitaShaRK/.gitignore b/deps/vitaShaRK/.gitignore new file mode 100644 index 0000000000..4a072bdd8b --- /dev/null +++ b/deps/vitaShaRK/.gitignore @@ -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 diff --git a/deps/vitaShaRK/LICENSE b/deps/vitaShaRK/LICENSE new file mode 100644 index 0000000000..8805d0dfad --- /dev/null +++ b/deps/vitaShaRK/LICENSE @@ -0,0 +1,165 @@ +GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. diff --git a/deps/vitaShaRK/Makefile b/deps/vitaShaRK/Makefile new file mode 100644 index 0000000000..58ce7401e2 --- /dev/null +++ b/deps/vitaShaRK/Makefile @@ -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" . diff --git a/deps/vitaShaRK/README.md b/deps/vitaShaRK/README.md new file mode 100644 index 0000000000..53d4cd9d4b --- /dev/null +++ b/deps/vitaShaRK/README.md @@ -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. diff --git a/deps/vitaShaRK/SceShaccCg.yml b/deps/vitaShaRK/SceShaccCg.yml new file mode 100644 index 0000000000..d20eae44a5 --- /dev/null +++ b/deps/vitaShaRK/SceShaccCg.yml @@ -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 diff --git a/deps/vitaShaRK/SceShaccCg/Makefile b/deps/vitaShaRK/SceShaccCg/Makefile new file mode 100644 index 0000000000..495b32a861 --- /dev/null +++ b/deps/vitaShaRK/SceShaccCg/Makefile @@ -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 $@ diff --git a/deps/vitaShaRK/include/shacccg.h b/deps/vitaShaRK/include/shacccg.h new file mode 100644 index 0000000000..aa9f6f06eb --- /dev/null +++ b/deps/vitaShaRK/include/shacccg.h @@ -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 */ diff --git a/deps/vitaShaRK/samples/sample1/Makefile b/deps/vitaShaRK/samples/sample1/Makefile new file mode 100644 index 0000000000..0202cf37cc --- /dev/null +++ b/deps/vitaShaRK/samples/sample1/Makefile @@ -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 diff --git a/deps/vitaShaRK/samples/sample1/main.c b/deps/vitaShaRK/samples/sample1/main.c new file mode 100644 index 0000000000..1e312c51a7 --- /dev/null +++ b/deps/vitaShaRK/samples/sample1/main.c @@ -0,0 +1,59 @@ +// Simple compiler with no logging + +#include +#include +#include + +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; +} diff --git a/deps/vitaShaRK/samples/sample2/Makefile b/deps/vitaShaRK/samples/sample2/Makefile new file mode 100644 index 0000000000..e41643545a --- /dev/null +++ b/deps/vitaShaRK/samples/sample2/Makefile @@ -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 diff --git a/deps/vitaShaRK/samples/sample2/main.c b/deps/vitaShaRK/samples/sample2/main.c new file mode 100644 index 0000000000..0d585e0201 --- /dev/null +++ b/deps/vitaShaRK/samples/sample2/main.c @@ -0,0 +1,85 @@ +// Simple compiler with file logging + +#include +#include +#include + +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; +} diff --git a/deps/vitaShaRK/source/vitashark.c b/deps/vitaShaRK/source/vitashark.c new file mode 100644 index 0000000000..96a6c719aa --- /dev/null +++ b/deps/vitaShaRK/source/vitashark.c @@ -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 . + */ + +#include "vitashark.h" +#include +#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 = ""; + 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); +} diff --git a/deps/vitaShaRK/source/vitashark.h b/deps/vitaShaRK/source/vitashark.h new file mode 100644 index 0000000000..61d1966084 --- /dev/null +++ b/deps/vitaShaRK/source/vitashark.h @@ -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 . + */ + +#ifndef _VITASHARK_H_ +#define _VITASHARK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +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