Compare commits

..

7 Commits

13 changed files with 70 additions and 70 deletions

View File

@ -24,4 +24,13 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </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> </Project>

@ -1 +1 @@
Subproject commit 52d3355120cba2025fac67499ee3c669e5347809 Subproject commit 1643061386177f62b516ccaad0ea04607cae2333

View File

@ -71,7 +71,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfo.Texture.SampleCount; currentSampleCount = colorAttachmentInfo.SampleCount;
colorFormatOne = colorAttachmentInfo.Texture.Format; colorFormatOne = colorAttachmentInfo.Texture.Format;
#endif #endif
} }
@ -111,7 +111,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
#endif #endif
@ -159,7 +159,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -215,7 +215,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -285,7 +285,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfo.Texture.SampleCount; currentSampleCount = colorAttachmentInfo.SampleCount;
colorFormatOne = colorAttachmentInfo.Texture.Format; colorFormatOne = colorAttachmentInfo.Texture.Format;
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format; depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
#endif #endif
@ -332,7 +332,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format; depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
@ -387,7 +387,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -450,7 +450,7 @@ namespace MoonWorks.Graphics
#if DEBUG #if DEBUG
renderPassActive = true; renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -1489,6 +1489,7 @@ namespace MoonWorks.Graphics
/// <summary> /// <summary>
/// Draws using instanced rendering. /// Draws using instanced rendering.
/// It is an error to call this method unless two vertex buffers have been bound.
/// </summary> /// </summary>
/// <param name="baseVertex">The starting index offset for the vertex buffer.</param> /// <param name="baseVertex">The starting index offset for the vertex buffer.</param>
/// <param name="startIndex">The starting index offset for the index buffer.</param> /// <param name="startIndex">The starting index offset for the index buffer.</param>
@ -2046,7 +2047,7 @@ namespace MoonWorks.Graphics
private void AssertSameSampleCount(ColorAttachmentInfo a, ColorAttachmentInfo b) private void AssertSameSampleCount(ColorAttachmentInfo a, ColorAttachmentInfo b)
{ {
if (a.Texture.SampleCount != b.Texture.SampleCount) if (a.SampleCount != b.SampleCount)
{ {
throw new System.ArgumentException("All color attachments in a render pass must have the same SampleCount!"); throw new System.ArgumentException("All color attachments in a render pass must have the same SampleCount!");
} }

View File

@ -14,6 +14,8 @@ namespace MoonWorks.Graphics
public SDL2.SDL.SDL_WindowFlags WindowFlags => (SDL2.SDL.SDL_WindowFlags) windowFlags; public SDL2.SDL.SDL_WindowFlags WindowFlags => (SDL2.SDL.SDL_WindowFlags) windowFlags;
// Built-in video pipeline // Built-in video pipeline
private ShaderModule VideoVertexShader { get; }
private ShaderModule VideoFragmentShader { get; }
internal GraphicsPipeline VideoPipeline { get; } internal GraphicsPipeline VideoPipeline { get; }
public bool IsDisposed { get; private set; } public bool IsDisposed { get; private set; }
@ -23,7 +25,8 @@ namespace MoonWorks.Graphics
public GraphicsDevice( public GraphicsDevice(
Backend preferredBackend, Backend preferredBackend,
bool debugMode bool debugMode
) { )
{
Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out windowFlags); Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out windowFlags);
if (Backend == Backend.Invalid) if (Backend == Backend.Invalid)
@ -35,36 +38,19 @@ namespace MoonWorks.Graphics
Conversions.BoolToByte(debugMode) Conversions.BoolToByte(debugMode)
); );
// Check for optional video shaders VideoVertexShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv"));
string basePath = SDL2.SDL.SDL_GetBasePath(); VideoFragmentShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv"));
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( VideoPipeline = new GraphicsPipeline(
this, this,
new GraphicsPipelineCreateInfo new GraphicsPipelineCreateInfo
{ {
AttachmentInfo = new GraphicsPipelineAttachmentInfo( AttachmentInfo = new GraphicsPipelineAttachmentInfo(
new ColorAttachmentDescription( new ColorAttachmentDescription(TextureFormat.R8G8B8A8, ColorAttachmentBlendState.None)
TextureFormat.R8G8B8A8,
ColorAttachmentBlendState.None
)
), ),
DepthStencilState = DepthStencilState.Disable, DepthStencilState = DepthStencilState.Disable,
VertexShaderInfo = GraphicsShaderInfo.Create( VertexShaderInfo = GraphicsShaderInfo.Create(VideoVertexShader, "main", 0),
videoVertShader, FragmentShaderInfo = GraphicsShaderInfo.Create(VideoFragmentShader, "main", 3),
"main",
0
),
FragmentShaderInfo = GraphicsShaderInfo.Create(
videoFragShader,
"main",
3
),
VertexInputState = VertexInputState.Empty, VertexInputState = VertexInputState.Empty,
RasterizerState = RasterizerState.CCW_CullNone, RasterizerState = RasterizerState.CCW_CullNone,
PrimitiveType = PrimitiveType.TriangleList, PrimitiveType = PrimitiveType.TriangleList,
@ -72,7 +58,6 @@ namespace MoonWorks.Graphics
} }
); );
} }
}
public bool ClaimWindow(Window window, PresentMode presentMode) public bool ClaimWindow(Window window, PresentMode presentMode)
{ {
@ -117,7 +102,7 @@ namespace MoonWorks.Graphics
public CommandBuffer AcquireCommandBuffer() public CommandBuffer AcquireCommandBuffer()
{ {
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle)); return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
} }
public unsafe void Submit(CommandBuffer commandBuffer) public unsafe void Submit(CommandBuffer commandBuffer)
@ -229,6 +214,11 @@ namespace MoonWorks.Graphics
} }
} }
private static Stream GetEmbeddedResource(string name)
{
return typeof(GraphicsDevice).Assembly.GetManifestResourceStream(name);
}
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!IsDisposed) if (!IsDisposed)

View File

@ -181,6 +181,7 @@ namespace MoonWorks.Graphics
public uint Depth; public uint Depth;
public uint Layer; public uint Layer;
public uint Level; public uint Level;
public SampleCount SampleCount;
public Color ClearColor; public Color ClearColor;
public LoadOp LoadOp; public LoadOp LoadOp;
public StoreOp StoreOp; public StoreOp StoreOp;
@ -188,12 +189,15 @@ namespace MoonWorks.Graphics
public ColorAttachmentInfo( public ColorAttachmentInfo(
Texture texture, Texture texture,
Color clearColor, Color clearColor,
SampleCount sampleCount = SampleCount.One,
StoreOp storeOp = StoreOp.Store StoreOp storeOp = StoreOp.Store
) { )
{
Texture = texture; Texture = texture;
Depth = 0; Depth = 0;
Layer = 0; Layer = 0;
Level = 0; Level = 0;
SampleCount = sampleCount;
ClearColor = clearColor; ClearColor = clearColor;
LoadOp = LoadOp.Clear; LoadOp = LoadOp.Clear;
StoreOp = storeOp; StoreOp = storeOp;
@ -202,12 +206,15 @@ namespace MoonWorks.Graphics
public ColorAttachmentInfo( public ColorAttachmentInfo(
Texture texture, Texture texture,
LoadOp loadOp = LoadOp.DontCare, LoadOp loadOp = LoadOp.DontCare,
SampleCount sampleCount = SampleCount.One,
StoreOp storeOp = StoreOp.Store StoreOp storeOp = StoreOp.Store
) { )
{
Texture = texture; Texture = texture;
Depth = 0; Depth = 0;
Layer = 0; Layer = 0;
Level = 0; Level = 0;
SampleCount = sampleCount;
ClearColor = Color.White; ClearColor = Color.White;
LoadOp = loadOp; LoadOp = loadOp;
StoreOp = storeOp; StoreOp = storeOp;
@ -221,6 +228,7 @@ namespace MoonWorks.Graphics
depth = Depth, depth = Depth,
layer = Layer, layer = Layer,
level = Level, level = Level,
sampleCount = (Refresh.SampleCount) SampleCount,
clearColor = new Refresh.Vec4 clearColor = new Refresh.Vec4
{ {
x = ClearColor.R / 255f, x = ClearColor.R / 255f,

View File

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

View File

@ -15,7 +15,6 @@ namespace MoonWorks.Graphics
public TextureFormat Format { get; internal set; } public TextureFormat Format { get; internal set; }
public bool IsCube { get; } public bool IsCube { get; }
public uint LevelCount { get; } public uint LevelCount { get; }
public SampleCount SampleCount { get; }
public TextureUsageFlags UsageFlags { get; } public TextureUsageFlags UsageFlags { get; }
// FIXME: this allocates a delegate instance // FIXME: this allocates a delegate instance
@ -40,14 +39,13 @@ namespace MoonWorks.Graphics
var byteCount = (uint) (width * height * channels); var byteCount = (uint) (width * height * channels);
TextureCreateInfo textureCreateInfo = new TextureCreateInfo(); TextureCreateInfo textureCreateInfo;
textureCreateInfo.Width = (uint) width; textureCreateInfo.Width = (uint) width;
textureCreateInfo.Height = (uint) height; textureCreateInfo.Height = (uint) height;
textureCreateInfo.Depth = 1; textureCreateInfo.Depth = 1;
textureCreateInfo.Format = TextureFormat.R8G8B8A8; textureCreateInfo.Format = TextureFormat.R8G8B8A8;
textureCreateInfo.IsCube = false; textureCreateInfo.IsCube = false;
textureCreateInfo.LevelCount = 1; textureCreateInfo.LevelCount = 1;
textureCreateInfo.SampleCount = SampleCount.One;
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler; textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
var texture = new Texture(device, textureCreateInfo); var texture = new Texture(device, textureCreateInfo);
@ -132,9 +130,9 @@ namespace MoonWorks.Graphics
uint height, uint height,
TextureFormat format, TextureFormat format,
TextureUsageFlags usageFlags, TextureUsageFlags usageFlags,
uint levelCount = 1, uint levelCount = 1
SampleCount sampleCount = SampleCount.One )
) { {
var textureCreateInfo = new TextureCreateInfo var textureCreateInfo = new TextureCreateInfo
{ {
Width = width, Width = width,
@ -142,7 +140,6 @@ namespace MoonWorks.Graphics
Depth = 1, Depth = 1,
IsCube = false, IsCube = false,
LevelCount = levelCount, LevelCount = levelCount,
SampleCount = sampleCount,
Format = format, Format = format,
UsageFlags = usageFlags UsageFlags = usageFlags
}; };
@ -168,7 +165,8 @@ namespace MoonWorks.Graphics
TextureFormat format, TextureFormat format,
TextureUsageFlags usageFlags, TextureUsageFlags usageFlags,
uint levelCount = 1 uint levelCount = 1
) { )
{
var textureCreateInfo = new TextureCreateInfo var textureCreateInfo = new TextureCreateInfo
{ {
Width = width, Width = width,
@ -197,7 +195,8 @@ namespace MoonWorks.Graphics
TextureFormat format, TextureFormat format,
TextureUsageFlags usageFlags, TextureUsageFlags usageFlags,
uint levelCount = 1 uint levelCount = 1
) { )
{
var textureCreateInfo = new TextureCreateInfo var textureCreateInfo = new TextureCreateInfo
{ {
Width = size, Width = size,
@ -233,7 +232,6 @@ namespace MoonWorks.Graphics
Depth = textureCreateInfo.Depth; Depth = textureCreateInfo.Depth;
IsCube = textureCreateInfo.IsCube; IsCube = textureCreateInfo.IsCube;
LevelCount = textureCreateInfo.LevelCount; LevelCount = textureCreateInfo.LevelCount;
SampleCount = textureCreateInfo.SampleCount;
UsageFlags = textureCreateInfo.UsageFlags; UsageFlags = textureCreateInfo.UsageFlags;
} }
@ -257,7 +255,6 @@ namespace MoonWorks.Graphics
Depth = 1; Depth = 1;
IsCube = false; IsCube = false;
LevelCount = 1; LevelCount = 1;
SampleCount = SampleCount.One;
UsageFlags = TextureUsageFlags.ColorTarget; UsageFlags = TextureUsageFlags.ColorTarget;
} }
@ -275,12 +272,14 @@ namespace MoonWorks.Graphics
const uint DDS_MAGIC = 0x20534444; const uint DDS_MAGIC = 0x20534444;
const uint DDS_HEADERSIZE = 124; const uint DDS_HEADERSIZE = 124;
const uint DDS_PIXFMTSIZE = 32; const uint DDS_PIXFMTSIZE = 32;
const uint DDSD_CAPS = 0x1;
const uint DDSD_HEIGHT = 0x2; const uint DDSD_HEIGHT = 0x2;
const uint DDSD_WIDTH = 0x4; const uint DDSD_WIDTH = 0x4;
const uint DDSD_PITCH = 0x8; const uint DDSD_PITCH = 0x8;
const uint DDSD_FMT = 0x1000;
const uint DDSD_LINEARSIZE = 0x80000; const uint DDSD_LINEARSIZE = 0x80000;
const uint DDSD_REQ = ( const uint DDSD_REQ = (
DDSD_HEIGHT | DDSD_WIDTH DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_FMT
); );
const uint DDSCAPS_MIPMAP = 0x400000; const uint DDSCAPS_MIPMAP = 0x400000;
const uint DDSCAPS_TEXTURE = 0x1000; const uint DDSCAPS_TEXTURE = 0x1000;

View File

@ -9,7 +9,6 @@ namespace MoonWorks.Graphics
public uint Depth; public uint Depth;
public bool IsCube; public bool IsCube;
public uint LevelCount; public uint LevelCount;
public SampleCount SampleCount;
public TextureFormat Format; public TextureFormat Format;
public TextureUsageFlags UsageFlags; public TextureUsageFlags UsageFlags;
@ -22,7 +21,6 @@ namespace MoonWorks.Graphics
depth = Depth, depth = Depth,
isCube = Conversions.BoolToByte(IsCube), isCube = Conversions.BoolToByte(IsCube),
levelCount = LevelCount, levelCount = LevelCount,
sampleCount = (Refresh.SampleCount) SampleCount,
format = (Refresh.TextureFormat) Format, format = (Refresh.TextureFormat) Format,
usageFlags = (Refresh.TextureUsageFlags) UsageFlags usageFlags = (Refresh.TextureUsageFlags) UsageFlags
}; };

Binary file not shown.

Binary file not shown.

View File

@ -50,11 +50,6 @@ namespace MoonWorks.Video
public VideoPlayer(GraphicsDevice graphicsDevice, AudioDevice audioDevice) public VideoPlayer(GraphicsDevice graphicsDevice, AudioDevice audioDevice)
{ {
GraphicsDevice = graphicsDevice; GraphicsDevice = graphicsDevice;
if (GraphicsDevice.VideoPipeline == null)
{
throw new InvalidOperationException("Missing video shaders!");
}
AudioDevice = audioDevice; AudioDevice = audioDevice;
LinearSampler = new Sampler(graphicsDevice, SamplerCreateInfo.LinearClamp); LinearSampler = new Sampler(graphicsDevice, SamplerCreateInfo.LinearClamp);