From 5709a063ae8fca59b8bab24c20621522fd1f686a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 18 Sep 2023 23:28:32 -0700 Subject: [PATCH] update examples to use WaitForFences --- BasicCompute/BasicComputeGame.cs | 5 +++-- CopyTexture/CopyTextureGame.cs | 5 +++-- GetBufferData/GetBufferDataGame.cs | 15 +++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/BasicCompute/BasicComputeGame.cs b/BasicCompute/BasicComputeGame.cs index bb73377..a14e108 100644 --- a/BasicCompute/BasicComputeGame.cs +++ b/BasicCompute/BasicComputeGame.cs @@ -106,8 +106,9 @@ namespace MoonWorks.Test cmdbuf.BindComputeBuffers(squaresBuffer); cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1, 0); - GraphicsDevice.Submit(cmdbuf); - GraphicsDevice.Wait(); + var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); // Print the squares! squaresBuffer.GetData(squares); diff --git a/CopyTexture/CopyTextureGame.cs b/CopyTexture/CopyTextureGame.cs index 7f1a69e..0c9f3b2 100644 --- a/CopyTexture/CopyTextureGame.cs +++ b/CopyTexture/CopyTextureGame.cs @@ -127,8 +127,9 @@ namespace MoonWorks.Test Buffer compareBuffer = Buffer.Create(GraphicsDevice, 0, (uint) byteCount); cmdbuf.CopyTextureToBuffer(new TextureSlice(originalTexture), compareBuffer); - GraphicsDevice.Submit(cmdbuf); - GraphicsDevice.Wait(); + var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); // Compare the original bytes to the copied bytes. var copiedBytes = NativeMemory.Alloc((nuint) byteCount); diff --git a/GetBufferData/GetBufferDataGame.cs b/GetBufferData/GetBufferDataGame.cs index 8194fc1..dfc5338 100644 --- a/GetBufferData/GetBufferDataGame.cs +++ b/GetBufferData/GetBufferDataGame.cs @@ -38,10 +38,11 @@ namespace MoonWorks.Test CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); cmdbuf.SetBufferData(vertexBuffer, vertices); - GraphicsDevice.Submit(cmdbuf); + var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); // Wait for the vertices to finish uploading... - GraphicsDevice.Wait(); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); // Read back and print out the vertex values PositionVertex[] readbackVertices = new PositionVertex[vertices.Length]; @@ -54,8 +55,9 @@ namespace MoonWorks.Test // Change the first three vertices cmdbuf = GraphicsDevice.AcquireCommandBuffer(); cmdbuf.SetBufferData(vertexBuffer, otherVerts); - GraphicsDevice.Submit(cmdbuf); - GraphicsDevice.Wait(); + fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); // Read the updated buffer vertexBuffer.GetData(readbackVertices); @@ -74,8 +76,9 @@ namespace MoonWorks.Test 1, 2 ); - GraphicsDevice.Submit(cmdbuf); - GraphicsDevice.Wait(); + fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); + GraphicsDevice.WaitForFences(fence); + GraphicsDevice.ReleaseFence(fence); // Read the updated buffer vertexBuffer.GetData(readbackVertices);