Compare commits

..

7 Commits

13 changed files with 70 additions and 70 deletions

View File

@ -24,4 +24,13 @@
<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>

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

View File

@ -71,7 +71,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfo.Texture.SampleCount;
currentSampleCount = colorAttachmentInfo.SampleCount;
colorFormatOne = colorAttachmentInfo.Texture.Format;
#endif
}
@ -111,7 +111,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
#endif
@ -159,7 +159,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -215,7 +215,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -285,7 +285,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfo.Texture.SampleCount;
currentSampleCount = colorAttachmentInfo.SampleCount;
colorFormatOne = colorAttachmentInfo.Texture.Format;
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
#endif
@ -332,7 +332,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
@ -387,7 +387,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -450,7 +450,7 @@ namespace MoonWorks.Graphics
#if DEBUG
renderPassActive = true;
currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount;
currentSampleCount = colorAttachmentInfoOne.SampleCount;
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
@ -1489,6 +1489,7 @@ namespace MoonWorks.Graphics
/// <summary>
/// Draws using instanced rendering.
/// It is an error to call this method unless two vertex buffers have been bound.
/// </summary>
/// <param name="baseVertex">The starting index offset for the vertex 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)
{
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!");
}

View File

@ -14,6 +14,8 @@ 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; }
@ -23,7 +25,8 @@ namespace MoonWorks.Graphics
public GraphicsDevice(
Backend preferredBackend,
bool debugMode
) {
)
{
Backend = (Backend) Refresh.Refresh_SelectBackend((Refresh.Backend) preferredBackend, out windowFlags);
if (Backend == Backend.Invalid)
@ -35,43 +38,25 @@ namespace MoonWorks.Graphics
Conversions.BoolToByte(debugMode)
);
// 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);
VideoVertexShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.FullscreenVert.spv"));
VideoFragmentShader = new ShaderModule(this, GetEmbeddedResource("MoonWorks.Shaders.YUV2RGBAFrag.spv"));
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
}
);
}
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
}
);
}
public bool ClaimWindow(Window window, PresentMode presentMode)
@ -117,7 +102,7 @@ namespace MoonWorks.Graphics
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)
@ -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)
{
if (!IsDisposed)

View File

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

View File

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

View File

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

View File

@ -9,7 +9,6 @@ namespace MoonWorks.Graphics
public uint Depth;
public bool IsCube;
public uint LevelCount;
public SampleCount SampleCount;
public TextureFormat Format;
public TextureUsageFlags UsageFlags;
@ -22,7 +21,6 @@ namespace MoonWorks.Graphics
depth = Depth,
isCube = Conversions.BoolToByte(IsCube),
levelCount = LevelCount,
sampleCount = (Refresh.SampleCount) SampleCount,
format = (Refresh.TextureFormat) Format,
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)
{
GraphicsDevice = graphicsDevice;
if (GraphicsDevice.VideoPipeline == null)
{
throw new InvalidOperationException("Missing video shaders!");
}
AudioDevice = audioDevice;
LinearSampler = new Sampler(graphicsDevice, SamplerCreateInfo.LinearClamp);