├── .github └── FUNDING.yml ├── .gitattributes ├── README.md ├── .gitignore ├── samples ├── sample1 │ ├── Makefile │ └── main.c ├── sample2 │ ├── Makefile │ └── main.c └── sample3 │ ├── Makefile │ └── main.c ├── Makefile ├── source ├── vitashark.h └── vitashark.c ├── LICENSE └── vitashark.svg /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: Rinnegatamante 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vitaShaRK 2 | ![vitaShaRK](./vitashark.svg) 3 | **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. 4 | 5 | # Note 6 | In order to use vitaShaRK, you need to install also [SceShaccCgExt](https://github.com/bythos14/SceShaccCgExt). 7 | 8 | # Credits 9 | 10 | **frangarcj** for the original vita2d shader compiler source used as base to build up this library.
11 | **Bythos** for SceShaccCgExt.
12 | **S1ngyy** for the awesome logo. 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.vpk 2 | *.elf 3 | *.velf 4 | *.bin 5 | *.sfo 6 | *.S 7 | *.wo 8 | 9 | # Windows image file caches 10 | Thumbs.db 11 | ehthumbs.db 12 | 13 | # Folder config file 14 | Desktop.ini 15 | 16 | # Recycle Bin used on file shares 17 | $RECYCLE.BIN/ 18 | 19 | # Windows Installer files 20 | *.cab 21 | *.msi 22 | *.msm 23 | *.msp 24 | 25 | # Windows shortcuts 26 | *.lnk 27 | 28 | # ========================= 29 | # Operating System Files 30 | # ========================= 31 | 32 | # OSX 33 | # ========================= 34 | 35 | .DS_Store 36 | .AppleDouble 37 | .LSOverride 38 | 39 | # Thumbnails 40 | ._* 41 | 42 | # Files that might appear in the root of a volume 43 | .DocumentRevisions-V100 44 | .fseventsd 45 | .Spotlight-V100 46 | .TemporaryItems 47 | .Trashes 48 | .VolumeIcon.icns 49 | 50 | # Directories potentially created on remote AFP share 51 | .AppleDB 52 | .AppleDesktop 53 | Network Trash Folder 54 | Temporary Items 55 | .apdisk 56 | 57 | # Vita build stuffs 58 | *.a 59 | *.o 60 | -------------------------------------------------------------------------------- /samples/sample1/Makefile: -------------------------------------------------------------------------------- 1 | SAMPLE_NUM := 001 2 | TARGET := vitaShaRK-Sample$(SAMPLE_NUM) 3 | SOURCES := . 4 | 5 | INCLUDES := include 6 | 7 | LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub 8 | 9 | CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) 10 | CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) 11 | BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin)) 12 | OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 13 | 14 | PREFIX = arm-vita-eabi 15 | CC = $(PREFIX)-gcc 16 | CXX = $(PREFIX)-g++ 17 | CFLAGS = -g -Wl,-q -O2 -ftree-vectorize 18 | CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive 19 | ASFLAGS = $(CFLAGS) 20 | 21 | all: $(TARGET).vpk 22 | 23 | $(TARGET).vpk: eboot.bin 24 | vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo 25 | vita-pack-vpk -s param.sfo -b eboot.bin $@ 26 | 27 | eboot.bin: $(TARGET).velf 28 | vita-make-fself -s $< eboot.bin 29 | 30 | %.velf: %.elf 31 | vita-elf-create $< $@ 32 | 33 | $(TARGET).elf: $(OBJS) 34 | $(CC) $(CFLAGS) $^ $(LIBS) -o $@ 35 | 36 | clean: 37 | @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin 38 | -------------------------------------------------------------------------------- /samples/sample2/Makefile: -------------------------------------------------------------------------------- 1 | SAMPLE_NUM := 002 2 | TARGET := vitaShaRK-Sample$(SAMPLE_NUM) 3 | SOURCES := . 4 | 5 | INCLUDES := include 6 | 7 | LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub 8 | 9 | CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) 10 | CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) 11 | BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin)) 12 | OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 13 | 14 | PREFIX = arm-vita-eabi 15 | CC = $(PREFIX)-gcc 16 | CXX = $(PREFIX)-g++ 17 | CFLAGS = -g -Wl,-q -O2 -ftree-vectorize 18 | CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive 19 | ASFLAGS = $(CFLAGS) 20 | 21 | all: $(TARGET).vpk 22 | 23 | $(TARGET).vpk: eboot.bin 24 | vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo 25 | vita-pack-vpk -s param.sfo -b eboot.bin $@ 26 | 27 | eboot.bin: $(TARGET).velf 28 | vita-make-fself -s $< eboot.bin 29 | 30 | %.velf: %.elf 31 | vita-elf-create $< $@ 32 | 33 | $(TARGET).elf: $(OBJS) 34 | $(CC) $(CFLAGS) $^ $(LIBS) -o $@ 35 | 36 | clean: 37 | @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin 38 | -------------------------------------------------------------------------------- /samples/sample3/Makefile: -------------------------------------------------------------------------------- 1 | SAMPLE_NUM := 003 2 | TARGET := vitaShaRK-Sample$(SAMPLE_NUM) 3 | SOURCES := . 4 | 5 | INCLUDES := include 6 | 7 | LIBS = -lvitashark -lSceLibKernel_stub -lSceShaccCg_stub -lSceIofilemgr_stub 8 | 9 | CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) 10 | CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) 11 | BINFILES := $(foreach dir,$(DATA), $(wildcard $(dir)/*.bin)) 12 | OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) 13 | 14 | PREFIX = arm-vita-eabi 15 | CC = $(PREFIX)-gcc 16 | CXX = $(PREFIX)-g++ 17 | CFLAGS = -g -Wl,-q -O2 -ftree-vectorize 18 | CXXFLAGS = $(CFLAGS) -fno-exceptions -std=gnu++11 -fpermissive 19 | ASFLAGS = $(CFLAGS) 20 | 21 | all: $(TARGET).vpk 22 | 23 | $(TARGET).vpk: eboot.bin 24 | vita-mksfoex -s TITLE_ID=VSHARK$(SAMPLE_NUM) "$(TARGET)" param.sfo 25 | vita-pack-vpk -s param.sfo -b eboot.bin $@ 26 | 27 | eboot.bin: $(TARGET).velf 28 | vita-make-fself -s $< eboot.bin 29 | 30 | %.velf: %.elf 31 | vita-elf-create $< $@ 32 | 33 | $(TARGET).elf: $(OBJS) 34 | $(CC) $(CFLAGS) $^ $(LIBS) -o $@ 35 | 36 | clean: 37 | @rm -rf *.velf *.elf *.vpk $(OBJS) param.sfo eboot.bin 38 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET := libvitashark 2 | SOURCES := source 3 | SHADERS := shaders 4 | 5 | CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) 6 | ASMFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S)) 7 | CGFILES := $(foreach dir,$(SHADERS), $(wildcard $(dir)/*.cg)) 8 | HEADERS := $(CGFILES:.cg=.h) 9 | OBJS := $(CFILES:.c=.o) $(ASMFILES:.S=.o) 10 | 11 | PREFIX = arm-vita-eabi 12 | CC = $(PREFIX)-gcc 13 | AR = $(PREFIX)-gcc-ar 14 | CFLAGS = -g -Wl,-q -O2 -ffast-math -mtune=cortex-a9 -mfpu=neon -ftree-vectorize 15 | ASFLAGS = $(CFLAGS) 16 | 17 | all: $(TARGET).a 18 | 19 | $(TARGET).a: $(OBJS) 20 | $(AR) -rc $@ $^ 21 | 22 | clean: 23 | @rm -rf $(TARGET).a $(TARGET).elf $(OBJS) 24 | @make -C samples/sample1 clean 25 | @make -C samples/sample2 clean 26 | 27 | install: $(TARGET).a 28 | @mkdir -p $(VITASDK)/$(PREFIX)/lib/ 29 | cp $(TARGET).a $(VITASDK)/$(PREFIX)/lib/ 30 | @mkdir -p $(VITASDK)/$(PREFIX)/include/ 31 | cp source/vitashark.h $(VITASDK)/$(PREFIX)/include/ 32 | 33 | samples: $(TARGET).a 34 | @make -C samples/sample1 35 | cp "samples/sample1/vitaShaRK-Sample001.vpk" . 36 | @make -C samples/sample2 37 | cp "samples/sample1/vitaShaRK-Sample002.vpk" . 38 | -------------------------------------------------------------------------------- /samples/sample1/main.c: -------------------------------------------------------------------------------- 1 | // Simple compiler with no logging 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | const char fragment_shader[] = 8 | "float4 main(uniform float4 u_clear_color) : COLOR\n" 9 | "{\n" 10 | " return u_clear_color;\n" 11 | "}" 12 | ; 13 | 14 | const char vertex_shader[] = 15 | "void main(\n" 16 | "float3 aPosition,\n" 17 | "float3 aColor,\n" 18 | "uniform float4x4 wvp,\n" 19 | "float4 out vPosition: POSITION,\n" 20 | "float4 out vColor: COLOR)\n" 21 | "{\n" 22 | " vPosition = mul(float4(aPosition, 1.f), wvp);\n" 23 | " vColor = float4(aColor, 1.f);\n" 24 | "}" 25 | ; 26 | 27 | void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) { 28 | FILE *f = fopen(fname, "wb"); 29 | fwrite(p, 1, size, f); 30 | fclose(f); 31 | } 32 | 33 | int main() { 34 | // Initializing vitaShaRK 35 | if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data 36 | return -1; 37 | 38 | // Compiling fragment shader 39 | uint32_t size = sizeof(fragment_shader) - 1; 40 | SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER); 41 | 42 | // Saving compiled GXP file on SD 43 | if (p) saveGXP(p, size, "ux0:data/clear_f.gxp"); 44 | 45 | shark_clear_output(); 46 | 47 | // Compiling vertex shader 48 | size = sizeof(vertex_shader) - 1; 49 | p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER); 50 | 51 | // Saving compiled GXP file on SD 52 | if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp"); 53 | 54 | shark_clear_output(); 55 | 56 | shark_end(); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /samples/sample3/main.c: -------------------------------------------------------------------------------- 1 | // Compiling all shaders in a given directory 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define SHADERS_PATH "ux0:data/shaders" 9 | char out_dir[256]; 10 | 11 | void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) { 12 | FILE *f = fopen(fname, "wb"); 13 | fwrite(p, 1, size, f); 14 | fclose(f); 15 | } 16 | 17 | void compileShader(const char *fname, int type) { 18 | // Reading the shader from file 19 | char full_name[256], out_name[256]; 20 | sprintf(full_name, "%s/%s", SHADERS_PATH, fname); 21 | FILE *f = fopen(full_name, "rb"); 22 | fseek(f, 0, SEEK_END); 23 | uint32_t size = ftell(f); 24 | fseek(f, 0, SEEK_SET); 25 | char *buf = (char*)malloc(size); 26 | fread(buf, 1, size, f); 27 | fclose(f); 28 | 29 | // Compiling and saving the resulting GXP file 30 | SceGxmProgram *p = shark_compile_shader(buf, &size, type); 31 | if (p) { 32 | char extless_name[256]; 33 | strncpy(extless_name, fname, strstr(fname, ".cg") - fname); 34 | extless_name[strstr(fname, ".cg") - fname] = 0; 35 | sprintf(out_name, "%s/%s.gxp", out_dir, extless_name); 36 | saveGXP(p, size, out_name); 37 | } 38 | 39 | shark_clear_output(); 40 | free(buf); 41 | } 42 | 43 | int main() { 44 | // Initializing vitaShaRK 45 | if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data 46 | return -1; 47 | 48 | // Creating dir for gxp output files 49 | sprintf(out_dir, "%s/gxp", SHADERS_PATH); 50 | sceIoMkdir(out_dir, 0777); 51 | 52 | // Scanning input folder 53 | SceIoDirent g_dir; 54 | int fd = sceIoDopen(SHADERS_PATH); 55 | while (sceIoDread(fd, &g_dir) > 0) { 56 | if (!SCE_S_ISDIR(g_dir.d_stat.st_mode)) { 57 | if (strstr(g_dir.d_name, "_v.cg")) { 58 | compileShader(g_dir.d_name, SHARK_VERTEX_SHADER); 59 | } else if (strstr(g_dir.d_name, "_f.cg")) { 60 | compileShader(g_dir.d_name, SHARK_FRAGMENT_SHADER); 61 | } 62 | } 63 | } 64 | 65 | shark_end(); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /samples/sample2/main.c: -------------------------------------------------------------------------------- 1 | // Simple compiler with file logging 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | const char fragment_shader[] = 8 | "float4 main(uniform float4 u_clear_color) : COLOR\n" 9 | "{\n" 10 | " return u_clear_color;\n" 11 | "}" 12 | ; 13 | 14 | const char vertex_shader[] = 15 | "void main(\n" 16 | "float3 aPosition,\n" 17 | "float3 aColor,\n" 18 | "uniform float4x4 wvp,\n" 19 | "float4 out vPosition: POSITION,\n" 20 | "float4 out vColor: COLOR)\n" 21 | "{\n" 22 | " vPosition = mul(float4(aPosition, 1.f), wvp);\n" 23 | " vColor = float4(aColor, 1.f);\n" 24 | "}" 25 | ; 26 | 27 | char curr_compilation[256]; 28 | 29 | void log_cb(const char *msg, shark_log_level msg_level, int line) { 30 | FILE *f = fopen("ux0:/data/shark.log", "a+"); 31 | switch (msg_level) { 32 | case SHARK_LOG_INFO: 33 | fprintf(f, "%s) INFO: %s at line %d\n", curr_compilation, msg, line); 34 | break; 35 | case SHARK_LOG_WARNING: 36 | fprintf(f, "%s) WARNING: %s at line %d\n", curr_compilation, msg, line); 37 | break; 38 | case SHARK_LOG_ERROR: 39 | fprintf(f, "%s) ERROR: %s at line %d\n", curr_compilation, msg, line); 40 | break; 41 | default: 42 | break; 43 | } 44 | fclose(f); 45 | } 46 | 47 | void saveGXP(SceGxmProgram *p, uint32_t size, const char *fname) { 48 | FILE *f = fopen(fname, "wb"); 49 | fwrite(p, 1, size, f); 50 | fclose(f); 51 | } 52 | 53 | int main() { 54 | // Initializing vitaShaRK 55 | if (shark_init(NULL) < 0) // NOTE: libshacccg.suprx will need to be placed in ur0:data 56 | return -1; 57 | 58 | // Setting up logger 59 | shark_install_log_cb(log_cb); 60 | shark_set_warnings_level(SHARK_WARN_MAX); 61 | 62 | // Compiling fragment shader 63 | sprintf(curr_compilation, "clear_f.gxp"); 64 | uint32_t size = sizeof(fragment_shader) - 1; 65 | SceGxmProgram *p = shark_compile_shader(fragment_shader, &size, SHARK_FRAGMENT_SHADER); 66 | 67 | // Saving compiled GXP file on SD 68 | if (p) saveGXP(p, size, "ux0:data/clear_f.gxp"); 69 | 70 | shark_clear_output(); 71 | 72 | // Compiling vertex shader 73 | sprintf(curr_compilation, "rgb_v.gxp"); 74 | size = sizeof(vertex_shader) - 1; 75 | p = shark_compile_shader(vertex_shader, &size, SHARK_VERTEX_SHADER); 76 | 77 | // Saving compiled GXP file on SD 78 | if (p) saveGXP(p, size, "ux0:data/rgb_v.gxp"); 79 | 80 | shark_clear_output(); 81 | 82 | shark_end(); 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /source/vitashark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of vitaShaRK 3 | * Copyright 2017, 2018, 2019, 2020 Rinnegatamante 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published 7 | * by the Free Software Foundation, version 3 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _VITASHARK_H_ 20 | #define _VITASHARK_H_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | typedef enum shark_opt { 30 | SHARK_OPT_SLOW, //!< Equivalent to O0 31 | SHARK_OPT_SAFE, //!< Equivalent to O1 32 | SHARK_OPT_DEFAULT, //!< Equivalent to O2 33 | SHARK_OPT_FAST, //!< Equivalent to O3 34 | SHARK_OPT_UNSAFE //!< Equivalent to Ofast 35 | } shark_opt; 36 | 37 | typedef enum shark_type { 38 | SHARK_VERTEX_SHADER, 39 | SHARK_FRAGMENT_SHADER 40 | } shark_type; 41 | 42 | typedef enum shark_locale { 43 | SHARK_LOCALE_ENGLISH, 44 | SHARK_LOCALE_JAPANESE 45 | } shark_locale; 46 | 47 | typedef enum shark_log_level { 48 | SHARK_LOG_INFO, 49 | SHARK_LOG_WARNING, 50 | SHARK_LOG_ERROR 51 | } shark_log_level; 52 | 53 | typedef enum shark_warn_level { 54 | SHARK_WARN_SILENT, 55 | SHARK_WARN_LOW, 56 | SHARK_WARN_MEDIUM, 57 | SHARK_WARN_HIGH, 58 | SHARK_WARN_MAX 59 | } shark_warn_level; 60 | 61 | #define SHARK_DISABLE 0 62 | #define SHARK_ENABLE 1 63 | 64 | // Init/term routines 65 | int shark_init(const char *path); //!< Initializes runtime shader compiler 66 | void shark_end(); //!< Terminates runtime shader compiler and frees used memory 67 | void shark_set_allocators(void *(*malloc_func)(size_t size), void (*free_func)(void *ptr)); // Sets custom allocators used by the shader compiler 68 | 69 | // Compiling routines 70 | 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 71 | SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type); //!< Compiles a shader 72 | void shark_clear_output(); //!< Clears output of a compilation attempt 73 | const SceShaccCgCompileOutput *shark_get_internal_compile_output(); //!< Returns the internal SceShaccCgCompileOutput struct from latest compilation attempt 74 | 75 | // Logging routines 76 | 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 77 | void shark_set_warnings_level(shark_warn_level level); //!< Sets warnings level for logging 78 | 79 | // Misc routines 80 | void shark_set_locale(shark_locale locale); //!< Set locale for warnings/errors. Default is SHARK_LOCALE_ENGLISH 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /source/vitashark.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of vitaShaRK 3 | * Copyright 2017, 2018, 2019, 2020 Rinnegatamante 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published 7 | * by the Free Software Foundation, version 3 of the License, or (at your 8 | * option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "vitashark.h" 20 | #include 21 | #include 22 | 23 | // Settings 24 | //#define DISABLE_SHACCCG_EXTENSIONS // Uncomment this to make vitaShaRK not depend on SceShaccCgExt 25 | #ifndef DISABLE_SHACCCG_EXTENSIONS 26 | #include 27 | #endif 28 | 29 | // Default path for SceShaccCg module location 30 | #define DEFAULT_SHACCCG_PATH "ur0:/data/libshacccg.suprx" 31 | 32 | static void (*shark_log_cb)(const char *msg, shark_log_level msg_level, int line) = NULL; 33 | static shark_warn_level shark_warnings_level = SHARK_WARN_SILENT; 34 | 35 | static SceUID shark_module_id = 0; 36 | static uint8_t shark_initialized = 0; 37 | static const SceShaccCgCompileOutput *shark_output = NULL; 38 | static SceShaccCgSourceFile shark_input; 39 | static SceShaccCgCallbackList shark_callbacks; 40 | static SceShaccCgCompileOptions shark_options; 41 | static SceShaccCgLocale shark_locale_mode = SCE_SHACCCG_ENGLISH; 42 | 43 | static void *(*shark_malloc)(size_t size) = malloc; 44 | static void (*shark_free)(void *ptr) = free; 45 | 46 | // Dummy Open File callback 47 | static SceShaccCgSourceFile *shark_open_file_cb(const char *fileName, 48 | const SceShaccCgSourceLocation *includedFrom, 49 | const SceShaccCgCompileOptions *compileOptions, 50 | const char **errorString) 51 | { 52 | return &shark_input; 53 | } 54 | 55 | void shark_set_allocators(void *(*malloc_func)(size_t size), void (*free_func)(void *ptr)) { 56 | shark_malloc = malloc_func; 57 | shark_free = free_func; 58 | } 59 | 60 | int shark_init(const char *path) { 61 | // Initializing sceShaccCg module 62 | if (!shark_initialized) { 63 | shark_module_id = sceKernelLoadStartModule(path ? path : DEFAULT_SHACCCG_PATH, 0, NULL, 0, NULL, NULL); 64 | if (shark_module_id < 0) return shark_module_id; 65 | #ifndef DISABLE_SHACCCG_EXTENSIONS 66 | sceShaccCgExtEnableExtensions(); 67 | #endif 68 | sceShaccCgSetDefaultAllocator(shark_malloc, shark_free); 69 | sceShaccCgInitializeCallbackList(&shark_callbacks, SCE_SHACCCG_TRIVIAL); 70 | shark_callbacks.openFile = shark_open_file_cb; 71 | shark_initialized = 1; 72 | } 73 | return 0; 74 | } 75 | 76 | void shark_end() { 77 | if (!shark_initialized) return; 78 | 79 | // Terminating sceShaccCg module 80 | sceShaccCgReleaseCompiler(); 81 | #ifndef DISABLE_SHACCCG_EXTENSIONS 82 | sceShaccCgExtDisableExtensions(); 83 | #endif 84 | sceKernelStopUnloadModule(shark_module_id, 0, NULL, 0, NULL, NULL); 85 | shark_initialized = 0; 86 | } 87 | 88 | void shark_install_log_cb(void (*cb)(const char *msg, shark_log_level msg_level, int line)) { 89 | shark_log_cb = cb; 90 | } 91 | 92 | void shark_set_warnings_level(shark_warn_level level) { 93 | // Changing current warnings level 94 | shark_warnings_level = level; 95 | } 96 | 97 | void shark_clear_output() { 98 | // Clearing sceShaccCg output 99 | if (shark_output) { 100 | sceShaccCgDestroyCompileOutput(shark_output); 101 | shark_output = NULL; 102 | } 103 | } 104 | 105 | void shark_set_locale(shark_locale locale) { 106 | // Changing current locale 107 | shark_locale_mode = (SceShaccCgLocale)locale; 108 | } 109 | 110 | 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) { 111 | if (!shark_initialized) return NULL; 112 | 113 | // Forcing usage for memory source for the shader to compile 114 | shark_input.fileName = ""; 115 | shark_input.text = src; 116 | shark_input.size = *size; 117 | 118 | // Properly configuring SceShaccCg with requested settings 119 | sceShaccCgInitializeCompileOptions(&shark_options); 120 | shark_options.mainSourceFile = shark_input.fileName; 121 | shark_options.targetProfile = type; 122 | shark_options.entryFunctionName = "main"; 123 | shark_options.macroDefinitions = NULL; 124 | shark_options.useFx = 1; 125 | shark_options.locale = shark_locale_mode; 126 | shark_options.warningLevel = shark_warnings_level; 127 | shark_options.optimizationLevel = opt; 128 | shark_options.useFastmath = use_fastmath; 129 | shark_options.useFastint = use_fastint; 130 | shark_options.useFastprecision = use_fastprecision; 131 | shark_options.pedantic = shark_warnings_level == SHARK_WARN_MAX ? SHARK_ENABLE : SHARK_DISABLE; 132 | shark_options.performanceWarnings = shark_warnings_level > SHARK_WARN_SILENT ? SHARK_ENABLE : SHARK_DISABLE; 133 | 134 | shark_output = sceShaccCgCompileProgram(&shark_options, &shark_callbacks, 0); 135 | // Executing logging 136 | if (shark_log_cb) { 137 | for (int i = 0; i < shark_output->diagnosticCount; ++i) { 138 | const SceShaccCgDiagnosticMessage *log = &shark_output->diagnostics[i]; 139 | shark_log_cb(log->message, log->level, log->location ? log->location->lineNumber : -1); 140 | } 141 | } 142 | 143 | // Returning output 144 | if (shark_output->programData) *size = shark_output->programSize; 145 | return (SceGxmProgram *)shark_output->programData; 146 | } 147 | 148 | SceGxmProgram *shark_compile_shader(const char *src, uint32_t *size, shark_type type) { 149 | return shark_compile_shader_extended(src, size, type, SHARK_OPT_DEFAULT, SHARK_DISABLE, SHARK_DISABLE, SHARK_DISABLE); 150 | } 151 | 152 | const SceShaccCgCompileOutput *shark_get_internal_compile_output() { 153 | return shark_output; 154 | } 155 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /vitashark.svg: -------------------------------------------------------------------------------- 1 | Artboard 1vitaSharK2 --------------------------------------------------------------------------------