From ad025e177789b5ba1cd1b0c525812575d5ed088f Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 5 Jun 2024 22:01:12 -0700 Subject: [PATCH] refactor built-in shader pipelines --- MoonWorks.csproj | 19 ++++------ src/Graphics/GraphicsDevice.cs | 35 ++---------------- .../StockShaders/Binary/blit.frag.refresh | Bin 1262 -> 0 bytes .../Binary/fullscreen.vert.refresh | Bin 2038 -> 0 bytes .../StockShaders/Binary/fullscreen.vert.spv | Bin 0 -> 1164 bytes ...t_msdf.frag.refresh => text_msdf.frag.spv} | Bin 4335 -> 2616 bytes .../Binary/text_transform.vert.refresh | Bin 2642 -> 0 bytes .../Binary/text_transform.vert.spv | Bin 0 -> 1448 bytes .../Binary/video_yuv2rgba.frag.refresh | Bin 3034 -> 0 bytes .../Binary/video_yuv2rgba.frag.spv | Bin 0 -> 1644 bytes src/Graphics/StockShaders/Source/blit.frag | 12 ------ .../StockShaders/Source/text_msdf.frag | 6 +-- .../StockShaders/Source/text_transform.vert | 2 +- .../StockShaders/Source/video_yuv2rgba.frag | 6 +-- src/Window.cs | 13 ++++++- 15 files changed, 31 insertions(+), 62 deletions(-) delete mode 100644 src/Graphics/StockShaders/Binary/blit.frag.refresh delete mode 100644 src/Graphics/StockShaders/Binary/fullscreen.vert.refresh create mode 100644 src/Graphics/StockShaders/Binary/fullscreen.vert.spv rename src/Graphics/StockShaders/Binary/{text_msdf.frag.refresh => text_msdf.frag.spv} (53%) delete mode 100644 src/Graphics/StockShaders/Binary/text_transform.vert.refresh create mode 100644 src/Graphics/StockShaders/Binary/text_transform.vert.spv delete mode 100644 src/Graphics/StockShaders/Binary/video_yuv2rgba.frag.refresh create mode 100644 src/Graphics/StockShaders/Binary/video_yuv2rgba.frag.spv delete mode 100644 src/Graphics/StockShaders/Source/blit.frag diff --git a/MoonWorks.csproj b/MoonWorks.csproj index 589de8b..658c8a9 100644 --- a/MoonWorks.csproj +++ b/MoonWorks.csproj @@ -25,20 +25,17 @@ - - MoonWorks.Graphics.StockShaders.Fullscreen.vert.refresh + + MoonWorks.Graphics.StockShaders.Fullscreen.vert.spv - - MoonWorks.Graphics.StockShaders.VideoYUV2RGBA.frag.refresh + + MoonWorks.Graphics.StockShaders.VideoYUV2RGBA.frag.spv - - MoonWorks.Graphics.StockShaders.TextTransform.vert.refresh + + MoonWorks.Graphics.StockShaders.TextTransform.vert.spv - - MoonWorks.Graphics.StockShaders.TextMSDF.frag.refresh - - - MoonWorks.Graphics.StockShaders.Blit.frag.refresh + + MoonWorks.Graphics.StockShaders.TextMSDF.frag.spv diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index 0c6e538..ec4add3 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -67,7 +67,6 @@ namespace MoonWorks.Graphics string textFragPath = Path.Combine(basePath, "text_msdf.frag.refresh"); string videoFragPath = Path.Combine(basePath, "video_yuv2rgba.frag.refresh"); - string blitFragPath = Path.Combine(basePath, "blit.frag.refresh"); Shader fullscreenVertShader; @@ -75,7 +74,6 @@ namespace MoonWorks.Graphics Shader textFragShader; Shader videoFragShader; - Shader blitFragShader; if (File.Exists(fullscreenVertPath)) { @@ -91,7 +89,7 @@ namespace MoonWorks.Graphics { // use defaults var assembly = typeof(GraphicsDevice).Assembly; - using var vertStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.Fullscreen.vert.refresh"); + using var vertStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.Fullscreen.vert.spv"); fullscreenVertShader = new Shader( this, vertStream, @@ -115,7 +113,7 @@ namespace MoonWorks.Graphics { // use defaults var assembly = typeof(GraphicsDevice).Assembly; - using var fragStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.VideoYUV2RGBA.frag.refresh"); + using var fragStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.VideoYUV2RGBA.frag.spv"); videoFragShader = new Shader( this, fragStream, @@ -148,8 +146,8 @@ namespace MoonWorks.Graphics // use defaults var assembly = typeof(GraphicsDevice).Assembly; - using var vertStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.TextTransform.vert.refresh"); - using var fragStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.TextMSDF.frag.refresh"); + using var vertStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.TextTransform.vert.spv"); + using var fragStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.TextMSDF.frag.spv"); textVertShader = new Shader( this, @@ -168,31 +166,6 @@ namespace MoonWorks.Graphics ); } - if (File.Exists(blitFragPath)) - { - blitFragShader = new Shader( - this, - blitFragPath, - "main", - ShaderStage.Fragment, - ShaderFormat.SECRET - ); - } - else - { - // use defaults - var assembly = typeof(GraphicsDevice).Assembly; - - using var fragStream = assembly.GetManifestResourceStream("MoonWorks.Graphics.StockShaders.Blit.frag.refresh"); - blitFragShader = new Shader( - this, - fragStream, - "main", - ShaderStage.Fragment, - ShaderFormat.SPIRV - ); - } - VideoPipeline = new GraphicsPipeline( this, new GraphicsPipelineCreateInfo diff --git a/src/Graphics/StockShaders/Binary/blit.frag.refresh b/src/Graphics/StockShaders/Binary/blit.frag.refresh deleted file mode 100644 index 5ca4059570182e35b4b66268de37c45f598e4197..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1262 zcmZ`&U279T6rChZTeogMtSBPLR9{jkA(SX$ZC}zh76OrMsJ@NMW*Qc@*|0k)iuTX> zt9%hWXR_HHPzP@A+%sp+{g}<@GWbvvSU>7QH0rN5gs6!v;fu!vvGznAhyb>3eSZ)P z+PRsuyRSPu-xduzd$uDs#2WUr+c2IHe*oKq?Se-f39xHGRfwMuUK5_^4^)3R><=zf zG@q;7d`q-S;+a;HIMb1d?=*Rv4lkZX$ztLXnqatjo1$rRUuNO7mnLb3e8hbCvHlu_ zxAQ~;B*yxH_0lw(U@Q7iV%;woU@_*smoUy^6(3;F#h4l^{yw^6e+RZxVfRn4Uk4^( zPr>IL7_(-H-%WTlyqKJ&Y46+Z`a3kT#;?_ohAMm@&tfs6Tf;Hk$t z$=`*i7IE?!vnOJ2FeCCB~E8Z|Lq0v%ROqDMm*S(S3 z8@`u=97l2~FUyYuYVOG~^V-h=2RzCak&(g2tI@UUWoe$PtJ!>EeDAyONh~W@T|(mV z#pm8|I6Ch@;QoIi!-e@vrCSvRnc!ND!)&TerE{0Y6M2KLTJbN|IxLGQn~|r^*xJh} zwf-@mqq0j*^PZi$EiS8*Hj9hf)+NR@)hgx~suEUHLj}%xdj%tlomN$Rfw=NT+U5P! ZPN-nHP}}Xc+!w@5<13mKC6p3q@DGc@`vd?0 diff --git a/src/Graphics/StockShaders/Binary/fullscreen.vert.refresh b/src/Graphics/StockShaders/Binary/fullscreen.vert.refresh deleted file mode 100644 index 750264a8d25eb37fe6789d84cb2f83e19841d45c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2038 zcmZ`(YflqF6dfKdSS$|_@PRmpV#}i`4H_fVM*s^+lU7QI-!`OO$R_J<)9#X@F){JG zKgyW+2mCR9G4Y()opvZV zEUE5NxmM1#gGO%iS)P<}F{GH}Oo&mXBb4}f;&?P}KyE@FK!)%)i2Db~!y+Y0Wvf)F zl*)Tnz1g(d!G&vEuH)HO!)e*|z&W?c8#Q>2S9imPNl1WU=1Yi#%ISx}k=@zx{Z<1= zQq^$gTE})Pusa7{!|n)$-$y;bt9C1L!2~-gi1X0rx1GT8J)k2BXRiu(yrAZMLX~_b z^07boc3h{q>$HOtuWomJoD_Yb>vnw!%!ISyDWMb2Ye89&&Do7XRv`PRSl302M`O{B zxV;|6TF7Hw&7)3?Gb_Qvc;rpvKkr3gnAn? zJB3?9SQGioOPx6RwAmlA)tEotXHUXrKIWgp&3afn)M+dA-?VUSLJPNyVJcr~beDQm|% z%Pzuv`Cq6?7?`oH)__n)dmnZxmBZaUf-vFL2BUoX3)and?mG>6j&GsG?{p^HE!pT% z7NdBDj0&5{Tpo|y-j*9#xhxCWwTReHpeq|!X3Sj2-OOanY%8*m%b#ZDy4=8>>vYy+ z9?F_BuL+a8K%jLaZtjBZaWUpbqA^Ot&%m!@7=aj<4AFdh&H>*+JOy;wHN}F`|DRfnKlx diff --git a/src/Graphics/StockShaders/Binary/fullscreen.vert.spv b/src/Graphics/StockShaders/Binary/fullscreen.vert.spv new file mode 100644 index 0000000000000000000000000000000000000000..59eae92098db66007157b220e5dabe23bbd84bbd GIT binary patch literal 1164 zcmZ9KO=}cE5Qf`bccVrVV@%>lj1!|#69^tu1o4XqtB}J=Laq|rK?c^Duseapli=MS zC4zs+i{SIjOeeu!YOCJ2-mb2$o_1?(Dugp(I-Coep#bKcP0(QtU2>u?wEB)WBYZ}WHU&AMu%l+c(nDv&yH}LA^R*1Z7tYJ>GuVuVFo3}4< z{hgik72m{j;!Kdej`$8Bgm14RzE|P8{zGExd-hY_(EE4?m;4`?4*mtKv$=#hmtU~r z*@kmAzZ-6@;hj&>^mK(-KGvBhwocr0m00fdo&~UcpSr%|B4!==mvrZQ%30I=ZA|V* zqhD>f1Rrax5jzj~o?sdw{7m=UlD(h8oUw1M{tX NANv)n|4W5u*gr7yNUs0@ literal 0 HcmV?d00001 diff --git a/src/Graphics/StockShaders/Binary/text_msdf.frag.refresh b/src/Graphics/StockShaders/Binary/text_msdf.frag.spv similarity index 53% rename from src/Graphics/StockShaders/Binary/text_msdf.frag.refresh rename to src/Graphics/StockShaders/Binary/text_msdf.frag.spv index c28ff6c71e954c0cc6a5674593c837b01d573195..91aef3b80b63a87527c3415bc9e8651071d62c9e 100644 GIT binary patch delta 30 mcmaE_xI=`SnMs+Qfq{{Mn}K7ZMCrz>Cm0!-HqT>v&kg`;O9$it delta 1762 zcmZux&2G~`5OzvMQL5ZHa9qS?1I8qw2ni?$k`gLaN|ls~3tBn$I;^nQ)_NVBB4l2H zM?qY81)ip_z^r%ulctf9*z@zv%r`%O?_WQBFn_=J(6Qk2vujy*_8uKrR>w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graphics/StockShaders/Binary/text_transform.vert.spv new file mode 100644 index 0000000000000000000000000000000000000000..6e1063d0196094d7a38e44c36b7553e1c6e76d4c GIT binary patch literal 1448 zcmYk4+fEcg5Qdw>0-iub4l3dQlgPKDywJXcTtn_4o5+1+3z^_Ij{d{N1~*3UH0WieFWpa_taq682H6=d zXoYJVEBpB%FALD=nC}b`&x^r9{xdT##q33_-Oazh%lm_);y4?|+`!mrw>ykAn9tcg z+Vkj-Z};OJZO>tz{pj?{ui0@NBjzoDpMEamPVSu-jEQdWlY{bf@F6>Emu2rHVserf zLnvZ$L|(h>mOV_c$;eq=RM0L+#kB8IorG0yE9t^m9&q_g&f>UHj0)|Xc?<5z3je0N+%JF~rwub{^e zaqsKPyO^_>djkpK*K6}zSl)FW>usRTN&RkP8yB~pzV9aH{kv#ur?~!RjhSzK-!bJs zsAKjsuJ5~A;~C$WedWdDoxdP{lW+KU_eDfL$~@L#GT)B$6Z!y3^l}V z)|h=$p5K~xouLCG&Ug#)zWK)G?l*OfH4%H8<9zPAj`%G&-zzrIZz9enNB0oUFO~Sd@t*B8PDH0VnREH(J2Pj_c)Rtu@x_?J_-#t5iSfJB zN{y-WDzDb*#JH@+;Zg8S>AAkq*s%La+b#wU;}_HfCmp+}rqwy2Zw4B|MJkkYc!u8bfXxm_Hl39(NV3}i`(LR56agkaI^63obd5X zkK^WEt=H|5u#W7^aR>14TQEsAIIn0cYLChicEv!6`0C8OZb_$|zF|}C(4(7Xv znS9(A@s}`@i+qArXy$fB=B>7oG4#9s2o%|A? zWe`K+pFrpSXft;KqSVj7i#?}p_2&Yj%=HYQ38sZpZo&YmBxldVFf&RY?||`=~*&Cm{pzmLJCNZ-H>@B`O)@%tjd*lLy z{Xv^O@D7Cc{|#2Lc2^<9(Ek;DJm(Dv{TvVB3mAMs=mN8Z|l-EOa$6qhaeskiQ1akSUzCsABToVmq(F8v*EB+VqULcxXo;itjG z_ceZ$TRsmaHgQL}1$Qd9#*cE#XXZ6-Z#Ixi>hZ2~9qLqEc z5MeAHv=XcF<&&+Quon0F{qV{D!63=!e#+-8j1zR&==S=zwav|~H3tOG&LY_yBqJQ}Tk{1q)g>@$z}Z?4I;N z+r6ZKLodi$*LF)q2g5J=zUP$#znXG^6pXH2u6k9BidXUdO3Cw`VyRLNcIQUIu+0HU0pmL z_>@!q0D2c8l=B%o-E8q;cUrp3Ouue@3-4tw3OjrTuUb&v6IhM7E$;NvjOI-}CViTA fxW1=fNQyFDc6Rf~mFX!kj_}L3pKc+ezybdQXn6Mu diff --git a/src/Graphics/StockShaders/Binary/video_yuv2rgba.frag.spv b/src/Graphics/StockShaders/Binary/video_yuv2rgba.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..68346e20f08ec745dd1d7dfc3b2daaa47b956134 GIT binary patch literal 1644 zcmZ9L%T7~K6oxm&LKWpA0wO2{ych8Xh$7djOqdwFL}yJP#ssXXm*`C1fyZ#*3#f_j z;u|<{LgM$Gc9|1)vbxv*um7xnpLKTI3zMBGwWY39N)J38q9 zre|hvsOV1ZnNUqn>P$!2josSoHx~McX`&aMJO*U#bWQ0O4;5ka`XaTX)INXsNUfMo zkiXch?Y`aFZjff2J)dlUs@Cg`t>Dg(JUyfvhkJI2^DK`VwO7^pPThvk{jCE<;VMS6(kx&+BA*^L$-wM1Ri^{rX|$$Fr$4HG||GaAjf$e`h9k(q(XoUCtP0 zTF2O}w-Najc!VdrD5&%K<1LZgLJK zCR~*k9&Ey_-)ZuAr|@@%uF#K>+dt~#7FkihNbdQ>dS50|`tm*Sl?~yo>6s$%Xzpx!ithhBM@H-YGr3M{|UCG-fDP7d`Hf z=X)%G<-AYP<371PVm@MZ(PNQ3-(w}KrQ}_U9;@W`h<6vS5K(_XZoNwQuHrS~fPeKo F@ei?}RjB{~ literal 0 HcmV?d00001 diff --git a/src/Graphics/StockShaders/Source/blit.frag b/src/Graphics/StockShaders/Source/blit.frag deleted file mode 100644 index de32fd1..0000000 --- a/src/Graphics/StockShaders/Source/blit.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 - -layout (location = 0) in vec2 TexCoord; - -layout (location = 0) out vec4 FragColor; - -layout (binding = 0, set = 1) uniform sampler2D TexSampler; - -void main() -{ - FragColor = texture(TexSampler, TexCoord); -} diff --git a/src/Graphics/StockShaders/Source/text_msdf.frag b/src/Graphics/StockShaders/Source/text_msdf.frag index 046682e..e3a5f55 100644 --- a/src/Graphics/StockShaders/Source/text_msdf.frag +++ b/src/Graphics/StockShaders/Source/text_msdf.frag @@ -1,13 +1,13 @@ #version 450 -layout(set = 1, binding = 0) uniform sampler2D msdf; - layout(location = 0) in vec2 inTexCoord; layout(location = 1) in vec4 inColor; layout(location = 0) out vec4 outColor; -layout(binding = 0, set = 3) uniform UBO +layout(set = 2, binding = 0) uniform sampler2D msdf; + +layout(set = 3, binding = 0) uniform UBO { float pxRange; } ubo; diff --git a/src/Graphics/StockShaders/Source/text_transform.vert b/src/Graphics/StockShaders/Source/text_transform.vert index f64037c..42f7827 100644 --- a/src/Graphics/StockShaders/Source/text_transform.vert +++ b/src/Graphics/StockShaders/Source/text_transform.vert @@ -7,7 +7,7 @@ layout(location = 2) in vec4 inColor; layout(location = 0) out vec2 outTexCoord; layout(location = 1) out vec4 outColor; -layout(binding = 0, set = 2) uniform UBO +layout(set = 1, binding = 0) uniform UBO { mat4 ViewProjection; } ubo; diff --git a/src/Graphics/StockShaders/Source/video_yuv2rgba.frag b/src/Graphics/StockShaders/Source/video_yuv2rgba.frag index fe2b5a1..d0d5510 100644 --- a/src/Graphics/StockShaders/Source/video_yuv2rgba.frag +++ b/src/Graphics/StockShaders/Source/video_yuv2rgba.frag @@ -9,9 +9,9 @@ layout(location = 0) in vec2 TexCoord; layout(location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler2D YSampler; -layout(binding = 1, set = 1) uniform sampler2D USampler; -layout(binding = 2, set = 1) uniform sampler2D VSampler; +layout(set = 2, binding = 0) uniform sampler2D YSampler; +layout(set = 2, binding = 1) uniform sampler2D USampler; +layout(set = 2, binding = 2) uniform sampler2D VSampler; /* More info about colorspace conversion: * http://www.equasys.de/colorconversion.html diff --git a/src/Window.cs b/src/Window.cs index 74d270e..e0c1ff3 100644 --- a/src/Window.cs +++ b/src/Window.cs @@ -31,6 +31,8 @@ namespace MoonWorks } } + public string Title { get; private set;} + private bool IsDisposed; private static Dictionary idLookup = new Dictionary(); @@ -111,7 +113,7 @@ namespace MoonWorks /// /// /// - public void SetWindowSize(uint width, uint height) + public void SetSize(uint width, uint height) { SDL.SDL_SetWindowSize(Handle, (int) width, (int) height); Width = width; @@ -131,6 +133,15 @@ namespace MoonWorks SDL.SDL_SetWindowPosition(Handle, x, y); } + /// + /// Sets the window title. + /// + public void SetTitle(string title) + { + SDL.SDL_SetWindowTitle(Handle, title); + Title = title; + } + internal static Window Lookup(uint windowID) { return idLookup.ContainsKey(windowID) ? idLookup[windowID] : null;