From bdefc589178fa3dc7eb1ff0204ed565fe8ad342d Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 9 Oct 2026 21:52:55 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E5=8E=9F=E8=89=B2=E3=81=AE=E3=82=B9?= =?UTF-8?q?=E3=83=9A=E3=82=AF=E3=83=88=E3=83=AB=E3=81=AE=E8=BB=A2=E9=80=81?= =?UTF-8?q?=E7=94=A8=E3=81=AE=E8=A4=87=E8=A3=BD=E3=82=92=E5=85=B1=E6=9C=89?= =?UTF-8?q?=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・三原色のスペクトルの転送用メモリをエフェクト間で共有して、使用メモリを削減-M --- .../SpectralConvolution/GpuTileConvolver.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs b/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs index fb3210f..5e4eb51 100644 --- a/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs +++ b/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs @@ -36,17 +36,23 @@ internal readonly record struct GpuTileJob( public GpuTileLayout Layout => new(Plan.GroupCount, SampleCount, KernelArea); } +internal sealed class SpectrumStaging +{ + public Float2[] Values = []; +} + internal sealed class GpuTileConvolver : IDisposable { public const int MaximumSamples = 16; public const int SampleTilesPerWord = 32; public const int WordsPerSampleEntry = 2; + static readonly ScratchPool Staging = new(Environment.ProcessorCount); + readonly GraphicsDevice device; readonly ReadWriteBuffer spare; ReadOnlyBuffer samples; Int2[] sampleStaging = []; - Float2[] chromaticStaging = []; ReadWriteBuffer? tiles; ReadOnlyBuffer? twiddles; ReadOnlyBuffer? spectrum; @@ -98,11 +104,13 @@ internal sealed class GpuTileConvolver : IDisposable var length = ChromaticKernelSpectrum.ChannelCount * kernelSpectrum.HalfColumns * kernelSpectrum.Size; EnsureSpectrumBuffers(kernelSpectrum.Size, length, true); - if (chromaticStaging.Length < length) - chromaticStaging = new Float2[length]; - kernelSpectrum.CopyHalfSpectra(chromaticStaging); + using var lease = Staging.Rent(); + var staging = lease.Value; + if (staging.Values.Length < length) + staging.Values = new Float2[length]; + kernelSpectrum.CopyHalfSpectra(staging.Values); twiddles!.CopyFrom(kernelSpectrum.Twiddles); - spectrum!.CopyFrom(chromaticStaging.AsSpan(0, length)); + spectrum!.CopyFrom(staging.Values.AsSpan(0, length)); spectrumRadius = kernelSpectrum.Radius; }