From a112001886c765812966655668b054a483ffb781 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 20 Apr 2020 02:14:45 +0100 Subject: [PATCH] Add complete shader sources --- .../WiiU/shader sources/fragmentshader.frag | 8 +++ .../WiiU/shader sources/fragmentshader.psh | 18 +++++++ .../WiiU/{ => shader sources}/newshader.gsh | Bin .../WiiU/shader sources/vertexshader.vert | 9 ++++ .../WiiU/shader sources/vertexshader.vsh | 27 ++++++++++ .../WiiU/shader sources/wtf is this.txt | 47 ++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 src/Backends/WiiU/shader sources/fragmentshader.frag create mode 100644 src/Backends/WiiU/shader sources/fragmentshader.psh rename src/Backends/WiiU/{ => shader sources}/newshader.gsh (100%) create mode 100644 src/Backends/WiiU/shader sources/vertexshader.vert create mode 100644 src/Backends/WiiU/shader sources/vertexshader.vsh create mode 100644 src/Backends/WiiU/shader sources/wtf is this.txt diff --git a/src/Backends/WiiU/shader sources/fragmentshader.frag b/src/Backends/WiiU/shader sources/fragmentshader.frag new file mode 100644 index 00000000..ebddb478 --- /dev/null +++ b/src/Backends/WiiU/shader sources/fragmentshader.frag @@ -0,0 +1,8 @@ +#version 150 core +layout(location = 0) uniform sampler2D tex; +in vec2 texture_coordinates; +out vec4 fragment; +void main() +{ + fragment = texture(tex, texture_coordinates); +} \ No newline at end of file diff --git a/src/Backends/WiiU/shader sources/fragmentshader.psh b/src/Backends/WiiU/shader sources/fragmentshader.psh new file mode 100644 index 00000000..4724c360 --- /dev/null +++ b/src/Backends/WiiU/shader sources/fragmentshader.psh @@ -0,0 +1,18 @@ +; $MODE = "UniformRegister" +; $SAMPLER_VARS[0].name= "tex" +; $SAMPLER_VARS[0].type= "sampler2D" +; $SAMPLER_VARS[0].location = 0 +; $NUM_SPI_PS_INPUT_CNTL = 1 +; $SPI_PS_INPUT_CNTL[0].semantic = 0 +; $SPI_PS_INPUT_CNTL[0].default_val = 1 +; $UNIFORM_VARS[0].name = "texture_coordinates" +; $UNIFORM_VARS[0].type = "vec2" +; $UNIFORM_VARS[0].count = 1 +; $UNIFORM_VARS[0].offset = 0 +; $UNIFORM_VARS[0].block = -1 + +00 TEX: ADDR(32) CNT(1) VALID_PIX + 0 SAMPLE R0, R0.xy0x, t0, s0 +01 EXP_DONE: PIX0, R0 +END_OF_PROGRAM + diff --git a/src/Backends/WiiU/newshader.gsh b/src/Backends/WiiU/shader sources/newshader.gsh similarity index 100% rename from src/Backends/WiiU/newshader.gsh rename to src/Backends/WiiU/shader sources/newshader.gsh diff --git a/src/Backends/WiiU/shader sources/vertexshader.vert b/src/Backends/WiiU/shader sources/vertexshader.vert new file mode 100644 index 00000000..3e7d817e --- /dev/null +++ b/src/Backends/WiiU/shader sources/vertexshader.vert @@ -0,0 +1,9 @@ +#version 150 core +layout(location = 0) in vec4 input_vertex_coordinates; +layout(location = 1) in vec2 input_texture_coordinates; +out vec2 texture_coordinates; +void main() +{ + gl_Position = input_vertex_coordinates; + texture_coordinates = input_texture_coordinates; +} diff --git a/src/Backends/WiiU/shader sources/vertexshader.vsh b/src/Backends/WiiU/shader sources/vertexshader.vsh new file mode 100644 index 00000000..4d6da880 --- /dev/null +++ b/src/Backends/WiiU/shader sources/vertexshader.vsh @@ -0,0 +1,27 @@ +; $MODE = "UniformRegister" +; $ATTRIB_VARS[0].name = "input_texture_coordinates" +; $ATTRIB_VARS[0].type = "vec2" +; $ATTRIB_VARS[0].location = 1 +; $ATTRIB_VARS[1].name = "input_vertex_coordinates" +; $ATTRIB_VARS[1].type = "vec2" +; $ATTRIB_VARS[1].location = 0 +; $NUM_SPI_VS_OUT_ID = 1 +; $SPI_VS_OUT_ID[0].SEMANTIC_0 = 0 + +00 CALL_FS NO_BARRIER +01 ALU: ADDR(32) CNT(2) + 0 x: MOV R1.x, R1.x + y: MOV R1.y, R1.y +02 EXP_DONE: POS0, R2 +03 EXP_DONE: PARAM0, R1.xyzz NO_BARRIER +04 ALU: ADDR(34) CNT(1) + 1 x: NOP ____ +05 NOP NO_BARRIER +END_OF_PROGRAM + + + + + + + diff --git a/src/Backends/WiiU/shader sources/wtf is this.txt b/src/Backends/WiiU/shader sources/wtf is this.txt new file mode 100644 index 00000000..01c93fa9 --- /dev/null +++ b/src/Backends/WiiU/shader sources/wtf is this.txt @@ -0,0 +1,47 @@ +I'mma give it to you straight: compiling shaders for the Wii U is an absolute +nightmare. + +You see, there are three major steps: +* Compile the GLSL to assembly +* Fill in a header by-hand +* Assemble the assembly + header + +To compile, you need AMD's 'GPU ShaderAnalyzer', which is Windows-only: +https://gpuopen.com/archive/gpu-shaderanalyzer/ + +You then need to compile for the RV730. + +After that, you need to fill-in a header. The only way I was able to figure out +what little I did was by finding examples on the internet: +https://github.com/snickerbockers/gx2gl/tree/master/src/shaders +https://github.com/yawut/SDL/tree/wiiu-2.0.9/src/video/wiiu/shaders +https://github.com/devkitPro/wut/tree/master/samples/cmake/content + +Even now, I don't have a complete idea of exactly what everything means. + +Anyway, once you have *that* out of the way, you still need to assemble your +shaders. For that, you'll need `latte-assembler` - a tool that comes with the +Decaf emulator. + +For me, I needed to clone the entire source tree (and its dependencies) in order +to build the tool successfully, which is a royal pain in the ass. + +For compilation, I used MSYS2+MinGW-w64. There were a couple of compilation +errors I had to address, but nothing too hard to solve. + +Eventually you'll have the assembler built. With it, you can link your `.psh` +and `.vsh` files into the final `.gsh` blob. + +Oh, right. I should warn you - the devs changed latte-assembler's syntax at some +point, so all the example `.psh`/`.vsh` files I could fine online were +incompatible. That sucked. The main change was that stuff like 'float2' and +'float4' were changed to 'vec2' and 'vec4'. Just keep that in mind, and you +should be okay. + +Also, latte-assembler's 'assemble' command was originally named 'compile', and +the other 'compile' option didn't exist. Keep that in mind if you ever find any +documentation on how to use the tool. + +latte-assembler does have an option to convert straight from GLSL to `.gsh`, but +this feature is woefully incomplete (it doesn't support `sampler2D`), and not +worth using.