Make video shaders optional and search for them in the root output directory ()

Whenever the video shaders change, they can be rebuilt with refreshc and distributed alongside the moonlibs.

Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com>
Reviewed-on: 
Co-authored-by: TheSpydog <thespydog@noreply.example.org>
Co-committed-by: TheSpydog <thespydog@noreply.example.org>
instancing-comment
TheSpydog 2023-01-21 23:37:01 +00:00 committed by cosmonaut
parent b1d30a9e6c
commit 05de9a4066
8 changed files with 43 additions and 37 deletions

View File

@ -24,13 +24,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="src\Video\Shaders\Compiled\FullscreenVert.spv">
<LogicalName>MoonWorks.Shaders.FullscreenVert.spv</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="src\Video\Shaders\Compiled\YUV2RGBAFrag.spv">
<LogicalName>MoonWorks.Shaders.YUV2RGBAFrag.spv</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -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,19 +35,36 @@ 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)
new ColorAttachmentDescription(
TextureFormat.R8G8B8A8,
ColorAttachmentBlendState.None
)
),
DepthStencilState = DepthStencilState.Disable,
VertexShaderInfo = GraphicsShaderInfo.Create(VideoVertexShader, "main", 0),
FragmentShaderInfo = GraphicsShaderInfo.Create(VideoFragmentShader, "main", 3),
VertexShaderInfo = GraphicsShaderInfo.Create(
videoVertShader,
"main",
0
),
FragmentShaderInfo = GraphicsShaderInfo.Create(
videoFragShader,
"main",
3
),
VertexInputState = VertexInputState.Empty,
RasterizerState = RasterizerState.CCW_CullNone,
PrimitiveType = PrimitiveType.TriangleList,
@ -58,6 +72,7 @@ namespace MoonWorks.Graphics
}
);
}
}
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)

View File

@ -5,7 +5,7 @@ using System.IO;
namespace MoonWorks.Graphics
{
/// <summary>
/// Shader modules expect input in SPIR-V bytecode format.
/// Shader modules expect input in Refresh bytecode format.
/// </summary>
public class ShaderModule : GraphicsResource
{

View File

@ -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);