render pass pipeline format validation
parent
4d7294f8e0
commit
e94a678ea9
|
@ -12,21 +12,35 @@ namespace MoonWorks.Graphics
|
||||||
public GraphicsDevice Device { get; }
|
public GraphicsDevice Device { get; }
|
||||||
public IntPtr Handle { get; }
|
public IntPtr Handle { get; }
|
||||||
|
|
||||||
// some state for debug validation
|
#if DEBUG
|
||||||
GraphicsPipeline currentGraphicsPipeline;
|
GraphicsPipeline currentGraphicsPipeline;
|
||||||
ComputePipeline currentComputePipeline;
|
ComputePipeline currentComputePipeline;
|
||||||
bool renderPassActive;
|
bool renderPassActive;
|
||||||
SampleCount currentSampleCount;
|
SampleCount currentSampleCount;
|
||||||
|
TextureFormat colorFormatOne;
|
||||||
|
TextureFormat colorFormatTwo;
|
||||||
|
TextureFormat colorFormatThree;
|
||||||
|
TextureFormat colorFormatFour;
|
||||||
|
TextureFormat depthStencilFormat;
|
||||||
|
#endif
|
||||||
|
|
||||||
// called from RefreshDevice
|
// called from RefreshDevice
|
||||||
internal CommandBuffer(GraphicsDevice device, IntPtr handle)
|
internal CommandBuffer(GraphicsDevice device, IntPtr handle)
|
||||||
{
|
{
|
||||||
Device = device;
|
Device = device;
|
||||||
Handle = handle;
|
Handle = handle;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
currentGraphicsPipeline = null;
|
currentGraphicsPipeline = null;
|
||||||
currentComputePipeline = null;
|
currentComputePipeline = null;
|
||||||
renderPassActive = false;
|
renderPassActive = false;
|
||||||
currentSampleCount = SampleCount.One;
|
currentSampleCount = SampleCount.One;
|
||||||
|
colorFormatOne = TextureFormat.R8G8B8A8;
|
||||||
|
colorFormatTwo = TextureFormat.R8G8B8A8;
|
||||||
|
colorFormatThree = TextureFormat.R8G8B8A8;
|
||||||
|
colorFormatFour = TextureFormat.R8G8B8A8;
|
||||||
|
depthStencilFormat = TextureFormat.D16;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -54,7 +68,11 @@ namespace MoonWorks.Graphics
|
||||||
IntPtr.Zero
|
IntPtr.Zero
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfo.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -90,7 +108,12 @@ namespace MoonWorks.Graphics
|
||||||
IntPtr.Zero
|
IntPtr.Zero
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -133,7 +156,13 @@ namespace MoonWorks.Graphics
|
||||||
IntPtr.Zero
|
IntPtr.Zero
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -183,7 +212,14 @@ namespace MoonWorks.Graphics
|
||||||
IntPtr.Zero
|
IntPtr.Zero
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
|
||||||
|
colorFormatFour = colorAttachmentInfoFour.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -209,7 +245,10 @@ namespace MoonWorks.Graphics
|
||||||
&refreshDepthStencilAttachmentInfo
|
&refreshDepthStencilAttachmentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -243,7 +282,12 @@ namespace MoonWorks.Graphics
|
||||||
&refreshDepthStencilAttachmentInfo
|
&refreshDepthStencilAttachmentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfo.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfo.Texture.Format;
|
||||||
|
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -285,7 +329,13 @@ namespace MoonWorks.Graphics
|
||||||
&refreshDepthStencilAttachmentInfo
|
&refreshDepthStencilAttachmentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -334,7 +384,14 @@ namespace MoonWorks.Graphics
|
||||||
&refreshDepthStencilAttachmentInfo
|
&refreshDepthStencilAttachmentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
|
||||||
|
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -390,7 +447,15 @@ namespace MoonWorks.Graphics
|
||||||
&refreshDepthStencilAttachmentInfo
|
&refreshDepthStencilAttachmentInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
renderPassActive = true;
|
renderPassActive = true;
|
||||||
|
currentSampleCount = colorAttachmentInfoOne.SampleCount;
|
||||||
|
colorFormatOne = colorAttachmentInfoOne.Texture.Format;
|
||||||
|
colorFormatTwo = colorAttachmentInfoTwo.Texture.Format;
|
||||||
|
colorFormatThree = colorAttachmentInfoThree.Texture.Format;
|
||||||
|
colorFormatFour = colorAttachmentInfoFour.Texture.Format;
|
||||||
|
depthStencilFormat = depthStencilAttachmentInfo.Texture.Format;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -406,7 +471,9 @@ namespace MoonWorks.Graphics
|
||||||
computePipeline.Handle
|
computePipeline.Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
currentComputePipeline = computePipeline;
|
currentComputePipeline = computePipeline;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -714,6 +781,7 @@ namespace MoonWorks.Graphics
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertRenderPassActive();
|
AssertRenderPassActive();
|
||||||
|
AssertRenderPassPipelineFormatMatch(graphicsPipeline);
|
||||||
|
|
||||||
if (graphicsPipeline.SampleCount != currentSampleCount)
|
if (graphicsPipeline.SampleCount != currentSampleCount)
|
||||||
{
|
{
|
||||||
|
@ -727,7 +795,9 @@ namespace MoonWorks.Graphics
|
||||||
graphicsPipeline.Handle
|
graphicsPipeline.Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
currentGraphicsPipeline = graphicsPipeline;
|
currentGraphicsPipeline = graphicsPipeline;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1530,8 +1600,10 @@ namespace MoonWorks.Graphics
|
||||||
Handle
|
Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
currentGraphicsPipeline = null;
|
currentGraphicsPipeline = null;
|
||||||
renderPassActive = false;
|
renderPassActive = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1845,6 +1917,42 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AssertRenderPassPipelineFormatMatch(GraphicsPipeline graphicsPipeline)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < graphicsPipeline.AttachmentInfo.ColorAttachmentDescriptions.Length; i += 1)
|
||||||
|
{
|
||||||
|
TextureFormat format;
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
format = colorFormatOne;
|
||||||
|
}
|
||||||
|
else if (i == 1)
|
||||||
|
{
|
||||||
|
format = colorFormatTwo;
|
||||||
|
}
|
||||||
|
else if (i == 2)
|
||||||
|
{
|
||||||
|
format = colorFormatThree;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
format = colorFormatFour;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pipelineFormat = graphicsPipeline.AttachmentInfo.ColorAttachmentDescriptions[i].Format;
|
||||||
|
if (pipelineFormat != format)
|
||||||
|
{
|
||||||
|
throw new System.InvalidOperationException($"Color texture format mismatch! Pipeline expects {pipelineFormat}, render pass attachment is {format}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var pipelineDepthFormat = graphicsPipeline.AttachmentInfo.DepthStencilFormat;
|
||||||
|
if (pipelineDepthFormat != depthStencilFormat)
|
||||||
|
{
|
||||||
|
throw new System.InvalidOperationException($"Depth texture format mismatch! Pipeline expects {pipelineDepthFormat}, render pass attachment is {depthStencilFormat}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void AssertVertexSamplerCount(int count)
|
private void AssertVertexSamplerCount(int count)
|
||||||
{
|
{
|
||||||
if (currentGraphicsPipeline.VertexShaderInfo.SamplerBindingCount != count)
|
if (currentGraphicsPipeline.VertexShaderInfo.SamplerBindingCount != count)
|
||||||
|
|
|
@ -14,7 +14,11 @@ namespace MoonWorks.Graphics
|
||||||
|
|
||||||
public GraphicsShaderInfo VertexShaderInfo { get; }
|
public GraphicsShaderInfo VertexShaderInfo { get; }
|
||||||
public GraphicsShaderInfo FragmentShaderInfo { get; }
|
public GraphicsShaderInfo FragmentShaderInfo { get; }
|
||||||
internal SampleCount SampleCount { get; }
|
public SampleCount SampleCount { get; }
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
internal GraphicsPipelineAttachmentInfo AttachmentInfo { get; }
|
||||||
|
#endif
|
||||||
|
|
||||||
public unsafe GraphicsPipeline(
|
public unsafe GraphicsPipeline(
|
||||||
GraphicsDevice device,
|
GraphicsDevice device,
|
||||||
|
@ -113,6 +117,10 @@ namespace MoonWorks.Graphics
|
||||||
VertexShaderInfo = vertexShaderInfo;
|
VertexShaderInfo = vertexShaderInfo;
|
||||||
FragmentShaderInfo = fragmentShaderInfo;
|
FragmentShaderInfo = fragmentShaderInfo;
|
||||||
SampleCount = multisampleState.MultisampleCount;
|
SampleCount = multisampleState.MultisampleCount;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
AttachmentInfo = attachmentInfo;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue