From c370afd861192600fcc33f5d9214c0c351d4a1f3 Mon Sep 17 00:00:00 2001 From: aliaspider Date: Sat, 16 Apr 2016 20:26:05 +0100 Subject: [PATCH] (3DS) start porting shaders to the picasso format. --- Makefile.ctr | 16 +++---- gfx/drivers/ctr_gfx.c | 5 +- gfx/drivers/ctr_sprite.gsh | 65 ++++++++++++++++++++++++++ gfx/drivers/ctr_sprite.shader | 86 ----------------------------------- gfx/drivers/ctr_sprite.vsh | 27 +++++++++++ 5 files changed, 103 insertions(+), 96 deletions(-) create mode 100644 gfx/drivers/ctr_sprite.gsh delete mode 100644 gfx/drivers/ctr_sprite.shader create mode 100644 gfx/drivers/ctr_sprite.vsh diff --git a/Makefile.ctr b/Makefile.ctr index 923bd7c715..e6d6a36a5a 100644 --- a/Makefile.ctr +++ b/Makefile.ctr @@ -352,14 +352,15 @@ else BANNERTOOL = ctr/tools/bannertool.exe endif -%.o: %.shader - python $(AEMSTRO)/aemstro_as.py $< $(notdir $<).shbin - $(DEVKITARM)/bin/bin2s $(notdir $<).shbin | $(PREFIX)as -o $@ - echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h - echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h - echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h - rm $(notdir $<).shbin +%.o: %.vsh %.gsh + $(DEVKITARM)/bin/picasso $^ -o $*.shbin + $(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@ + rm $*.shbin +%.o: %.vsh + $(DEVKITARM)/bin/picasso $^ -o $*.shbin + $(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@ + rm $*.shbin %.o: %.cpp $(CXX) -c -o $@ $< $(CXXFLAGS) $(INCDIRS) @@ -415,7 +416,6 @@ clean: rm -f $(TARGET).smdh rm -f $(TARGET).bnr rm -f $(TARGET).icn - rm -f *_shader_shbin.h rm -f ctr/ctr_config_*.o rm -f ctr/3dsx_custom_crt0.o diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 4315ee2d67..c602898f1e 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -22,7 +22,6 @@ #include #include "ctr_gu.h" -#include "ctr_sprite_shader_shbin.h" #include "../../command_event.h" #include "../../general.h" @@ -36,6 +35,8 @@ #define CTR_GPU_FRAMEBUFFER ((void*)0x1F119400) #define CTR_GPU_DEPTHBUFFER ((void*)0x1F370800) +extern const u8 ctr_sprite_shbin[]; +extern const u32 ctr_sprite_shbin_size; typedef struct { @@ -306,7 +307,7 @@ static void* ctr_init(const video_info_t* video, CTR_TOP_FRAMEBUFFER_WIDTH, CTR_TOP_FRAMEBUFFER_HEIGHT, ctr->menu.texture_width, ctr->menu.texture_height); - ctr->dvlb = DVLB_ParseFile((u32*)ctr_sprite_shader_shbin, ctr_sprite_shader_shbin_size); + ctr->dvlb = DVLB_ParseFile((u32*)ctr_sprite_shbin, ctr_sprite_shbin_size); ctrGuSetVshGsh(&ctr->shader, ctr->dvlb, 2, 2); shaderProgramUse(&ctr->shader); diff --git a/gfx/drivers/ctr_sprite.gsh b/gfx/drivers/ctr_sprite.gsh new file mode 100644 index 0000000000..4750f79872 --- /dev/null +++ b/gfx/drivers/ctr_sprite.gsh @@ -0,0 +1,65 @@ +; Uniforms +;.fvec scale_vector +;.alias viewport_scale scale_vector.yxyx +;.alias texture_scale scale_vector.zwzw +.gsh +.fvec c0_ + +.constf c20_(1.0, 1.0, 1.0, 1.0) +.constf c21_(0.0, 0.0, 0.0, 0.0) +.constf c22_(0.0, 1.0, 0.0, 1.0) +.constf c23_(0.0, 0.0, -1.0, 1.0) + +; Inputs +.alias sprite_coords v0 +.alias tex_size v1 + +.out o0_ position +.out o1_ color +.out o2_ texcoord0 + +.entry main_gsh +.proc main_gsh + setemit 0 + mov o0_.xy, v0 + + mov o0_.zw, c23_.zwzw + mov o1_, c20_ + + mov o2_, v1 + emit + + setemit 1 + mov o0_.x, v0 + mov o0_.y, v0.zwzw + + mov o0_.zw, c23_.zwzw + mov o1_, c20_ + + mov o2_.x, v1.zwzw + mov o2_.yzw, v1.xyxy + emit + + setemit 2, prim inv + mov o0_.xy, v0.zw + + mov o0_.zw, c23_.zwzw + mov o1_, c20_ + + mov o2_, v1_.zwzw + emit + + setemit 1, prim + mov o0_.x, v0.zwzw + mov o0_.y, v0 + + mov o0_.zw, c23_.zwzw + mov o1_, c20_ + + mov o2_.x, v1 + mov o2_.yzw, v1.zwzw + emit + + + end +.end diff --git a/gfx/drivers/ctr_sprite.shader b/gfx/drivers/ctr_sprite.shader deleted file mode 100644 index 75b2a361f2..0000000000 --- a/gfx/drivers/ctr_sprite.shader +++ /dev/null @@ -1,86 +0,0 @@ - .const c20, 1.0, 1.0, 1.0, 1.0 - .const c21, 0.0, 0.0, 0.0, 0.0 - .const c22, 0.0, 1.0, 0.0, 1.0 - .const c23, 0.0, 0.0, -1.0, 1.0 - - -; .in v0, x0,y0,x1,y1 -; .in v1, tex_w,tex_h - - .out o0, result.position, 0xF - .out o1, result.color, 0xF - .out o2, result.texcoord0, 0x3 - -; .uniform c0, c0, scale_vector - - .vsh main_vsh, endmain_vsh - .gsh main_gsh, endmain_gsh - - main_vsh: - mul r0, c0, v0 (0x1) - add o0, c20, r0 (0x0) - mul r1, c0, v1 (0x2) - mov r1, c21 (0x3) - add o1, c22, r1 (0x0) - nop - end - endmain_vsh: - - main_gsh: - setemit vtx0, false, false - mov o0, v0 (0x3) - - mov o0, c23 (0x2) - mov o1, c20 (0x0) - - mov o2, v1 (0x0) - emit - - setemit vtx1, false, false - mov o0, v0 (0x4) - mov o0, v0 (0x8) - - mov o0, c23 (0x2) - mov o1, c20 (0x0) - - mov o2, v1 (0x7) - mov o2, v1 (0x9) - emit - - setemit vtx2, true, true - mov o0, v0 (0x6) - - mov o0, c23 (0x2) - mov o1, c20 (0x0) - - mov o2, v1 (0xB) - emit - - setemit vtx1, true, false - mov o0, v0 (0x7) - mov o0, v0 (0x5) - - mov o0, c23 (0x2) - mov o1, c20 (0x0) - - mov o2, v1 (0x4) - mov o2, v1 (0xA) - emit - - nop - end - endmain_gsh: - -; operand descriptors - .opdesc xyzw, xyzw, xyzw ; 0x0 - .opdesc xyzw, yxyx, yxwz ; 0x1 - .opdesc __zw, zwzw, xyxy ; 0x2 - .opdesc xy__, xyzw, xyzw ; 0x3 - .opdesc x___, xyzw, xyzw ; 0x4 - .opdesc _y__, xyzw, xyzw ; 0x5 - .opdesc xy__, zwzw, zwzw ; 0x6 - .opdesc x___, zwzw, zwzw ; 0x7 - .opdesc _y__, zwzw, zwzw ; 0x8 - .opdesc _yzw, xyxy, xyxy ; 0x9 - .opdesc _yzw, zwzw, zwzw ; 0xA - .opdesc xyzw, zwzw, zwzw ; 0xB diff --git a/gfx/drivers/ctr_sprite.vsh b/gfx/drivers/ctr_sprite.vsh new file mode 100644 index 0000000000..0fd1113098 --- /dev/null +++ b/gfx/drivers/ctr_sprite.vsh @@ -0,0 +1,27 @@ +; Uniforms +;.fvec scale_vector +;.alias viewport_scale scale_vector.yxyx +;.alias texture_scale scale_vector.zwzw +.fvec c0_ + +.constf c20_(1.0, 1.0, 1.0, 1.0) +.constf c21_(0.0, 0.0, 0.0, 0.0) +.constf c22_(0.0, 1.0, 0.0, 1.0) +.constf c23_(0.0, 0.0, -1.0, 1.0) + +; Inputs +;.alias pos v0 +;.alias tex_coord v1 + +.out o0_ position +.out o1_ texcoord0 + +.entry main_vsh +.proc main_vsh + mul r0, c0_.yxyx, v0.yxwz + add o0_, c20_, r0 + mul r1.zw, c0_.zwzw, v1.xyxy + mov r1.xy, c21_ + add o1_, c22_, r1 + end +.end