From cdb6b92c4e5741d3cee63ec35bec15cf573f9bb8 Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 20 Oct 2026 19:28:26 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A3=9C=E6=AD=A3=E3=81=AE=E5=86=85=E7=A9=8D?= =?UTF-8?q?=E3=82=92=E6=B1=82=E3=82=81=E3=82=8B=E5=87=A6=E7=90=86=E3=81=AE?= =?UTF-8?q?=E3=82=B9=E3=83=AC=E3=83=83=E3=83=89=E3=82=B0=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=97=E3=82=92=E6=A8=AA=E9=95=B7=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inflate/InflateGpuShaders.cs | 25 ++++++++++++++----------- Inflate/InflateSettings.cs | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Inflate/InflateGpuShaders.cs b/Inflate/InflateGpuShaders.cs index 72a4a93..ddfc765 100644 --- a/Inflate/InflateGpuShaders.cs +++ b/Inflate/InflateGpuShaders.cs @@ -477,7 +477,7 @@ internal readonly partial struct ProlongShader( } } -[ThreadGroupSize(InflateSettings.CorrectionGroupSize, InflateSettings.CorrectionGroupSize, 1)] +[ThreadGroupSize(InflateSettings.CorrectionGroupWidth, InflateSettings.CorrectionGroupSize, 1)] [GeneratedComputeShaderDescriptor] internal readonly partial struct CorrectionDotShader( ReadWriteBuffer potential, @@ -502,12 +502,14 @@ internal readonly partial struct CorrectionDotShader( private readonly int fineHeight = fineHeight; private readonly int groupsX = groupsX; - [GroupShared(2 * InflateSettings.CorrectionGroupThreads)] + [GroupShared(2 * InflateSettings.CorrectionTilesPerGroup * InflateSettings.CorrectionGroupThreads)] private static readonly float[] sums = null!; public void Execute() { - var local = GroupIds.Index; + var tile = GroupIds.X / InflateSettings.CorrectionGroupSize; + var local = GroupIds.Y * InflateSettings.CorrectionGroupSize + GroupIds.X % InflateSettings.CorrectionGroupSize; + var tileBase = tile * 2 * InflateSettings.CorrectionGroupThreads; var x = ThreadIds.X; var y = ThreadIds.Y; var residualDot = 0f; @@ -534,25 +536,26 @@ internal readonly partial struct CorrectionDotShader( } } } - sums[local] = residualDot; - sums[InflateSettings.CorrectionGroupThreads + local] = energy; + sums[tileBase + local] = residualDot; + sums[tileBase + InflateSettings.CorrectionGroupThreads + local] = energy; Hlsl.GroupMemoryBarrierWithGroupSync(); for (var stride = InflateSettings.CorrectionGroupThreads / 2; stride > 0; stride /= 2) { if (local < stride) { - sums[local] += sums[local + stride]; - sums[InflateSettings.CorrectionGroupThreads + local] += sums[InflateSettings.CorrectionGroupThreads + local + stride]; + sums[tileBase + local] += sums[tileBase + local + stride]; + sums[tileBase + InflateSettings.CorrectionGroupThreads + local] += sums[tileBase + InflateSettings.CorrectionGroupThreads + local + stride]; } Hlsl.GroupMemoryBarrierWithGroupSync(); } - if (local == 0) + var column = GridIds.X * InflateSettings.CorrectionTilesPerGroup + tile; + if (local == 0 && column < groupsX) { - var group = GridIds.Y * groupsX + GridIds.X; - partial[2 * group] = sums[0]; - partial[2 * group + 1] = sums[InflateSettings.CorrectionGroupThreads]; + var group = GridIds.Y * groupsX + column; + partial[2 * group] = sums[tileBase]; + partial[2 * group + 1] = sums[tileBase + InflateSettings.CorrectionGroupThreads]; } } diff --git a/Inflate/InflateSettings.cs b/Inflate/InflateSettings.cs index 4fe4e2c..55dac4f 100644 --- a/Inflate/InflateSettings.cs +++ b/Inflate/InflateSettings.cs @@ -14,6 +14,8 @@ internal static class InflateSettings public const int RowGroupHeight = 2; public const int CorrectionGroupSize = 8; public const int CorrectionGroupThreads = CorrectionGroupSize * CorrectionGroupSize; + public const int CorrectionTilesPerGroup = 4; + public const int CorrectionGroupWidth = CorrectionGroupSize * CorrectionTilesPerGroup; public const int CorrectionReduceThreads = 256; public const float MaximumCorrectionScale = 4f; public const float MinimumInterpolationWeight = 1e-6f;