From d0ffcb24d2dda36402cdc2d6951763aa525c91b1 Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Sun, 11 Oct 2026 19:01:25 +0300 Subject: [PATCH] [Presenter] Write the bound mip statistics in stream order on the render thread --- .../VulkanVideoPresenter.LodStatistics.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.LodStatistics.cs b/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.LodStatistics.cs index 7901d88..b7bd0b6 100644 --- a/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.LodStatistics.cs +++ b/src/SharpEmu.Libs/VideoOut/VulkanVideoPresenter.LodStatistics.cs @@ -39,7 +39,18 @@ internal static unsafe partial class VulkanVideoPresenter bool Gpu.GpuCommands.ICommandStreamHost.TryRecordLodStatistics(ulong destination, uint size) { - if (!ResourceMaterializer.RecordMipStatistics || size < MipStatistics.ReportBytes) + if (!ResourceMaterializer.RecordMipStatistics) + { + if (!OnCommandThread) + { + return false; + } + + _commandThread!.PostRange(() => WriteBindingLodStatistics(destination, size), destination, size); + return true; + } + + if (size < MipStatistics.ReportBytes) { return false; } @@ -62,6 +73,16 @@ internal static unsafe partial class VulkanVideoPresenter LodStatistics().Record(destination, size); } + private void WriteBindingLodStatistics(ulong destination, uint size) + { + var report = new byte[size]; + MipStatistics.Shared.WriteReport(report); + if (!((Gpu.GpuCommands.ICommandStreamHost)this).Memory.TryWrite(destination, report)) + { + throw SubmissionScheduler.Fatal($"The LOD statistics report could not be written: address=0x{destination:X16} size={report.Length}."); + } + } + private void PublishLodStatistics() { if (_lodStatistics is not { } recorder)