From f96298f9917a4b052d6f656f7fae50dc14a5f4ba Mon Sep 17 00:00:00 2001 From: TheSpydog Date: Thu, 29 Dec 2022 03:18:36 +0000 Subject: [PATCH] Add validation checks for AcquireSwapchainTexture and BindVertexBuffers (#37) This replaces the Refresh-side check for window claim status in AcquireSwapchainTexture, and adds validation to ensure that BindVertexBuffers is not called before BindGraphicsPipeline. Co-authored-by: Caleb Cornett Reviewed-on: https://gitea.moonside.games/MoonsideGames/MoonWorks/pulls/37 Co-authored-by: TheSpydog Co-committed-by: TheSpydog --- src/Graphics/CommandBuffer.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 84e794b7..6cce4725 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -847,6 +847,10 @@ namespace MoonWorks.Graphics in BufferBinding bufferBinding, uint firstBinding = 0 ) { +#if DEBUG + AssertGraphicsPipelineBound(); +#endif + var bufferPtrs = stackalloc IntPtr[1]; var offsets = stackalloc ulong[1]; @@ -874,6 +878,10 @@ namespace MoonWorks.Graphics in BufferBinding bufferBindingTwo, uint firstBinding = 0 ) { +#if DEBUG + AssertGraphicsPipelineBound(); +#endif + var bufferPtrs = stackalloc IntPtr[2]; var offsets = stackalloc ulong[2]; @@ -906,6 +914,10 @@ namespace MoonWorks.Graphics in BufferBinding bufferBindingThree, uint firstBinding = 0 ) { +#if DEBUG + AssertGraphicsPipelineBound(); +#endif + var bufferPtrs = stackalloc IntPtr[3]; var offsets = stackalloc ulong[3]; @@ -942,6 +954,10 @@ namespace MoonWorks.Graphics in BufferBinding bufferBindingFour, uint firstBinding = 0 ) { +#if DEBUG + AssertGraphicsPipelineBound(); +#endif + var bufferPtrs = stackalloc IntPtr[4]; var offsets = stackalloc ulong[4]; @@ -974,6 +990,10 @@ namespace MoonWorks.Graphics in Span bufferBindings, uint firstBinding = 0 ) { +#if DEBUG + AssertGraphicsPipelineBound(); +#endif + var bufferPtrs = stackalloc IntPtr[bufferBindings.Length]; var offsets = stackalloc ulong[bufferBindings.Length]; @@ -1623,6 +1643,13 @@ namespace MoonWorks.Graphics public Texture AcquireSwapchainTexture( Window window ) { +#if DEBUG + if (!window.Claimed) + { + throw new System.InvalidOperationException("Cannot acquire swapchain texture, window has not been claimed!"); + } +#endif + var texturePtr = Refresh.Refresh_AcquireSwapchainTexture( Device.Handle, Handle,