From 05de9a40664688ba56ccffe79bb1965ad14153a0 Mon Sep 17 00:00:00 2001 From: TheSpydog Date: Sat, 21 Jan 2023 23:37:01 +0000 Subject: [PATCH] Make video shaders optional and search for them in the root output directory (#42) Whenever the video shaders change, they can be rebuilt with refreshc and distributed alongside the moonlibs. Co-authored-by: Caleb Cornett Reviewed-on: https://gitea.moonside.games/MoonsideGames/MoonWorks/pulls/42 Co-authored-by: TheSpydog Co-committed-by: TheSpydog --- MoonWorks.csproj | 9 --- src/Graphics/GraphicsDevice.cs | 64 ++++++++++-------- src/Graphics/Resources/ShaderModule.cs | 2 +- src/Video/Shaders/Compiled/FullscreenVert.spv | Bin 1164 -> 0 bytes src/Video/Shaders/Compiled/YUV2RGBAFrag.spv | Bin 1644 -> 0 bytes .../Fullscreen.vert => video_fullscreen.vert} | 0 .../YUV2RGBA.frag => video_yuv2rgba.frag} | 0 src/Video/VideoPlayer.cs | 5 ++ 8 files changed, 43 insertions(+), 37 deletions(-) delete mode 100644 src/Video/Shaders/Compiled/FullscreenVert.spv delete mode 100644 src/Video/Shaders/Compiled/YUV2RGBAFrag.spv rename src/Video/Shaders/{Source/Fullscreen.vert => video_fullscreen.vert} (100%) rename src/Video/Shaders/{Source/YUV2RGBA.frag => video_yuv2rgba.frag} (100%) diff --git a/MoonWorks.csproj b/MoonWorks.csproj index ccbd6509..2b68c6d7 100644 --- a/MoonWorks.csproj +++ b/MoonWorks.csproj @@ -24,13 +24,4 @@ PreserveNewest - - - - MoonWorks.Shaders.FullscreenVert.spv - - - MoonWorks.Shaders.YUV2RGBAFrag.spv - - diff --git a/src/Graphics/GraphicsDevice.cs b/src/Graphics/GraphicsDevice.cs index 0508e7fe..5e56e1e6 100644 --- a/src/Graphics/GraphicsDevice.cs +++ b/src/Graphics/GraphicsDevice.cs @@ -14,8 +14,6 @@ namespace MoonWorks.Graphics public SDL2.SDL.SDL_WindowFlags WindowFlags => (SDL2.SDL.SDL_WindowFlags) windowFlags; // Built-in video pipeline - private ShaderModule VideoVertexShader { get; } - private ShaderModule VideoFragmentShader { get; } internal GraphicsPipeline VideoPipeline { get; } public bool IsDisposed { get; private set; } @@ -25,8 +23,7 @@ namespace MoonWorks.Graphics public GraphicsDevice( Backend preferredBackend, bool debugMode - ) - { + ) { Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out windowFlags); if (Backend == Backend.Invalid) @@ -38,25 +35,43 @@ namespace MoonWorks.Graphics Conversions.BoolToByte(debugMode) ); - VideoVertexShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv")); - VideoFragmentShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv")); + // Check for optional video shaders + string basePath = SDL2.SDL.SDL_GetBasePath(); + string videoVertPath = Path.Combine(basePath, "video_fullscreen.refresh"); + string videoFragPath = Path.Combine(basePath, "video_yuv2rgba.refresh"); + if (File.Exists(videoVertPath) && File.Exists(videoFragPath)) + { + ShaderModule videoVertShader = new ShaderModule(this, videoVertPath); + ShaderModule videoFragShader = new ShaderModule(this, videoFragPath); - VideoPipeline = new GraphicsPipeline( - this, - new GraphicsPipelineCreateInfo - { - AttachmentInfo = new GraphicsPipelineAttachmentInfo( - new ColorAttachmentDescription(TextureFormat.R8G8B8A8, ColorAttachmentBlendState.None) - ), - DepthStencilState = DepthStencilState.Disable, - VertexShaderInfo = GraphicsShaderInfo.Create(VideoVertexShader, "main", 0), - FragmentShaderInfo = GraphicsShaderInfo.Create(VideoFragmentShader, "main", 3), - VertexInputState = VertexInputState.Empty, - RasterizerState = RasterizerState.CCW_CullNone, - PrimitiveType = PrimitiveType.TriangleList, - MultisampleState = MultisampleState.None - } - ); + VideoPipeline = new GraphicsPipeline( + this, + new GraphicsPipelineCreateInfo + { + AttachmentInfo = new GraphicsPipelineAttachmentInfo( + new ColorAttachmentDescription( + TextureFormat.R8G8B8A8, + ColorAttachmentBlendState.None + ) + ), + DepthStencilState = DepthStencilState.Disable, + VertexShaderInfo = GraphicsShaderInfo.Create( + videoVertShader, + "main", + 0 + ), + FragmentShaderInfo = GraphicsShaderInfo.Create( + videoFragShader, + "main", + 3 + ), + VertexInputState = VertexInputState.Empty, + RasterizerState = RasterizerState.CCW_CullNone, + PrimitiveType = PrimitiveType.TriangleList, + MultisampleState = MultisampleState.None + } + ); + } } public bool ClaimWindow(Window window, PresentMode presentMode) @@ -214,11 +229,6 @@ namespace MoonWorks.Graphics } } - private static Stream GetEmbeddedResource(string name) - { - return typeof(GraphicsDevice).Assembly.GetManifestResourceStream(name); - } - protected virtual void Dispose(bool disposing) { if (!IsDisposed) diff --git a/src/Graphics/Resources/ShaderModule.cs b/src/Graphics/Resources/ShaderModule.cs index f2c88d43..01b86220 100644 --- a/src/Graphics/Resources/ShaderModule.cs +++ b/src/Graphics/Resources/ShaderModule.cs @@ -5,7 +5,7 @@ using System.IO; namespace MoonWorks.Graphics { /// - /// Shader modules expect input in SPIR-V bytecode format. + /// Shader modules expect input in Refresh bytecode format. /// public class ShaderModule : GraphicsResource { diff --git a/src/Video/Shaders/Compiled/FullscreenVert.spv b/src/Video/Shaders/Compiled/FullscreenVert.spv deleted file mode 100644 index ffc57de4aad5b75ae64168b06875645c4b611764..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1164 zcmZ9KTWb_S5QW=accY0W#+bxQjFZG`0>K9rLA()R74onl;;V%0AOq`+>`q|uN$}kt zC4zs+7s2nFnNEVe)K;BSr>m>0r`_6^3gJwc4(GyFsMmaG!Gtgqx|Q$k?(c4o%fa@e z#}8G^hIS=XGsiyHS?u#cmK&ePE?_sYHoq4BC*lsO)4C3f+Ty5upH6m)Vl;s1R(n4U zKYmC@WjcA657LQyyWs{}_c!qqZmZGH{)aDtJwESS-q8Da2bcUGm=69qth2d@IhS9s z;<<)%HoqHgzTuru(e!kgSU%QSAhu52bA?#$^qxhqe4o0$;}T{a`4@EOd&*hU{4GrG zN26bBxC9?-Y!EvS?R%rUO{~`39-K40i^;npcaK=kH|%qwGrNzeHRoKd`{K2tN%-dr`SI%Z%D2H diff --git a/src/Video/Shaders/Compiled/YUV2RGBAFrag.spv b/src/Video/Shaders/Compiled/YUV2RGBAFrag.spv deleted file mode 100644 index c9fbf324eb9aadc03e7947d6af078c753e429c93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1644 zcmZ9L$xc*J5QY!kHngA&A|Qg=fO8{GfG9Gy%7%@>A-W@h7!$BfJ4AQ#4m^enUqDTK z7vI2z8xp_oc9*%~B-N+>zy4EoPTlHaVWK0Yw$z!*>0xTFzEprosVlW-``Y@(`qaDk zTT|0BH&k?|VkT76lRDB7c5Qd_^&10y*c8@_PM!jIMY5*!i$f*YyuL*2D6!8UJ`yXX z##V5rah@L1jln%T#CexTjm=lJ`cB=1YgD(!IOZDy zd)6hk-q{Q_v9sK7XfviKh_e-&9|^Ua9OX1-F)6leJ{JYGCc6;jmtt0l^$VDE9{LjJuQsA3lSKwRt?R&qMqRwrwXVe+9&J4Rby=R=8!~Z(^ z@<-si;BSrc|NGtpn@63o&@JK@svXNwZwahU-kPCX#it+Hz5O0F%sb5T53+B5E0^3~ zm=e1^aJKya*|P<(Gt!MYA7W?V1m^dD&MA9$5>q4p7|wSNVe+mOIKTNYW^QL;k;-Cq zQD+3-Ify!=`1v|#z-r{9j{hThSJbKCTgMr)j#ypP8OL{?qRs?;dtS)lg z!O!QI2g^B6k>ftTIif#eb&+EMKc8bci>2hOMUEAGbHv-l%UHx8;2W=DzE!-69q_N7 G!~OxAcvYnU diff --git a/src/Video/Shaders/Source/Fullscreen.vert b/src/Video/Shaders/video_fullscreen.vert similarity index 100% rename from src/Video/Shaders/Source/Fullscreen.vert rename to src/Video/Shaders/video_fullscreen.vert diff --git a/src/Video/Shaders/Source/YUV2RGBA.frag b/src/Video/Shaders/video_yuv2rgba.frag similarity index 100% rename from src/Video/Shaders/Source/YUV2RGBA.frag rename to src/Video/Shaders/video_yuv2rgba.frag diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index 5622b6db..b0405428 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -50,6 +50,11 @@ namespace MoonWorks.Video public VideoPlayer(GraphicsDevice graphicsDevice, AudioDevice audioDevice) { GraphicsDevice = graphicsDevice; + if (GraphicsDevice.VideoPipeline == null) + { + throw new InvalidOperationException("Missing video shaders!"); + } + AudioDevice = audioDevice; LinearSampler = new Sampler(graphicsDevice, SamplerCreateInfo.LinearClamp);