From 0cbf877de366526227751be8acb80d24f431bf9f Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 27 Feb 2024 10:35:05 -0800 Subject: [PATCH] Refresh2 changes --- CopyMoonlibs.targets | 6 ++-- lib/MoonWorks | 2 +- moonlibs/x64/Refresh.dll | 4 +-- src/MoonWorksDearImGuiScaffoldGame.cs | 52 +++++++++++++-------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/CopyMoonlibs.targets b/CopyMoonlibs.targets index 8998eba..3c89bae 100644 --- a/CopyMoonlibs.targets +++ b/CopyMoonlibs.targets @@ -8,19 +8,19 @@ %(RecursiveDir)%(Filename)%(Extension) - PreserveNewest + Always %(RecursiveDir)%(Filename)%(Extension) - PreserveNewest + Always %(RecursiveDir)%(Filename)%(Extension) - PreserveNewest + Always diff --git a/lib/MoonWorks b/lib/MoonWorks index 4dbd5a2..178a5ea 160000 --- a/lib/MoonWorks +++ b/lib/MoonWorks @@ -1 +1 @@ -Subproject commit 4dbd5a2cbeab38f78274644f3b44fe1fa727f304 +Subproject commit 178a5ea3cfa4ce4ccbcd9e0b6726a8cda791c810 diff --git a/moonlibs/x64/Refresh.dll b/moonlibs/x64/Refresh.dll index 18c4da4..83ac3e9 100644 --- a/moonlibs/x64/Refresh.dll +++ b/moonlibs/x64/Refresh.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dfd3a79a93788ce81f4d261835f46e522000aed7e03d76a5a10d270ef9c178df -size 241857 +oid sha256:a83bbfe1deea0aca2dc52ce54b2f28836d5a7629e41cd34df190814c04e5548c +size 134144 diff --git a/src/MoonWorksDearImGuiScaffoldGame.cs b/src/MoonWorksDearImGuiScaffoldGame.cs index 8ee9a81..c5948bb 100644 --- a/src/MoonWorksDearImGuiScaffoldGame.cs +++ b/src/MoonWorksDearImGuiScaffoldGame.cs @@ -19,11 +19,13 @@ class MoonWorksDearImGuiScaffoldGame : Game private uint VertexCount = 0; private uint IndexCount = 0; - private MoonWorks.Graphics.Buffer ImGuiVertexBuffer = null; - private MoonWorks.Graphics.Buffer ImGuiIndexBuffer = null; + private GpuBuffer ImGuiVertexBuffer = null; + private GpuBuffer ImGuiIndexBuffer = null; private TextureStorage TextureStorage; + private ResourceUploader ResourceUploader; + public MoonWorksDearImGuiScaffoldGame( WindowCreateInfo windowCreateInfo, FrameLimiterSettings frameLimiterSettings, @@ -31,6 +33,7 @@ class MoonWorksDearImGuiScaffoldGame : Game ) : base(windowCreateInfo, frameLimiterSettings, 60, debugMode) { TextureStorage = new TextureStorage(); + ResourceUploader = new ResourceUploader(GraphicsDevice); ImGui.CreateContext(); @@ -177,7 +180,7 @@ class MoonWorksDearImGuiScaffoldGame : Game ImGuiVertexBuffer?.Dispose(); VertexCount = (uint)(drawDataPtr.TotalVtxCount * 1.5f); - ImGuiVertexBuffer = MoonWorks.Graphics.Buffer.Create( + ImGuiVertexBuffer = GpuBuffer.Create( GraphicsDevice, BufferUsageFlags.Vertex, VertexCount @@ -189,7 +192,7 @@ class MoonWorksDearImGuiScaffoldGame : Game ImGuiIndexBuffer?.Dispose(); IndexCount = (uint)(drawDataPtr.TotalIdxCount * 1.5f); - ImGuiIndexBuffer = MoonWorks.Graphics.Buffer.Create( + ImGuiIndexBuffer = GpuBuffer.Create( GraphicsDevice, BufferUsageFlags.Index, IndexCount @@ -203,24 +206,24 @@ class MoonWorksDearImGuiScaffoldGame : Game { var cmdList = drawDataPtr.CmdLists[n]; - commandBuffer.SetBufferData( + ResourceUploader.SetBufferData( ImGuiVertexBuffer, - cmdList.VtxBuffer.Data, vertexOffset, - (uint)cmdList.VtxBuffer.Size + new Span((void*) cmdList.VtxBuffer.Data, cmdList.VtxBuffer.Size) ); - commandBuffer.SetBufferData( + ResourceUploader.SetBufferData( ImGuiIndexBuffer, - cmdList.IdxBuffer.Data, indexOffset, - (uint)cmdList.IdxBuffer.Size + new Span((void*) cmdList.IdxBuffer.Data, cmdList.IdxBuffer.Size) ); - vertexOffset += (uint)cmdList.VtxBuffer.Size; - indexOffset += (uint)cmdList.IdxBuffer.Size; + vertexOffset += (uint) cmdList.VtxBuffer.Size; + indexOffset += (uint) cmdList.IdxBuffer.Size; } + ResourceUploader.Upload(); + GraphicsDevice.Submit(commandBuffer); } @@ -249,7 +252,7 @@ class MoonWorksDearImGuiScaffoldGame : Game commandBuffer.BindGraphicsPipeline(ImGuiPipeline); - var vertexUniformOffset = commandBuffer.PushVertexShaderUniforms( + commandBuffer.PushVertexShaderUniforms( Matrix4x4.CreateOrthographicOffCenter(0, ioPtr.DisplaySize.X, ioPtr.DisplaySize.Y, 0, -1, 1) ); @@ -294,9 +297,7 @@ class MoonWorksDearImGuiScaffoldGame : Game commandBuffer.DrawIndexedPrimitives( vertexOffset, indexOffset, - drawCmd.ElemCount / 3, - vertexUniformOffset, - 0 + drawCmd.ElemCount / 3 ); indexOffset += drawCmd.ElemCount; @@ -308,9 +309,9 @@ class MoonWorksDearImGuiScaffoldGame : Game commandBuffer.EndRenderPass(); } - private void BuildFontAtlas() + private unsafe void BuildFontAtlas() { - var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); + var resourceUploader = new ResourceUploader(GraphicsDevice); var io = ImGui.GetIO(); @@ -321,17 +322,14 @@ class MoonWorksDearImGuiScaffoldGame : Game out int bytesPerPixel ); - var fontTexture = Texture.CreateTexture2D( - GraphicsDevice, - (uint)width, - (uint)height, - TextureFormat.R8G8B8A8, - TextureUsageFlags.Sampler + var fontTexture = resourceUploader.CreateTexture2D( + new Span((void*) pixelData, width * height * bytesPerPixel), + (uint) width, + (uint) height ); - commandBuffer.SetTextureData(fontTexture, pixelData, (uint)(width * height * bytesPerPixel)); - - GraphicsDevice.Submit(commandBuffer); + resourceUploader.Upload(); + resourceUploader.Dispose(); io.Fonts.SetTexID(fontTexture.Handle); io.Fonts.ClearTexData();