穴の周りの区画だけ小領域の数え上げを行う

・小さな領域を周りで埋める処理を高速化-M
このコミットが含まれているのは:
routersys committed 2026-10-19 02:22:59 +09:00
1 親 9b66307b8c
コミット 3a2b10a387
3ファイル変更
+50 -4

検索条件に一致するファイルはありません

+27 -2
ファイルの表示
@@ -353,9 +353,34 @@ public sealed class MangaScreentoneShaderTests
[InlineData(45, 31, 13, 0u)]
[InlineData(14, 11, 39, 1u)]
public void SmallRegionsOfTheTargetLevelAreFilledFromTheirSurroundingsAndTheRestStays(int width, int height, int size, uint target)
{
AssertSmallRegionsFilled(Levels(width, height, 0x42u), width, height, size, target);
}
[Theory]
[InlineData(5)]
[InlineData(13)]
[InlineData(21)]
public void SmallRegionsFarApartAreFilledWhileTheGroupsBetweenThemHaveNoHolesToCount(int size)
{
const int width = 130;
const int height = 100;
var levels = Enumerable.Repeat(3u, width * height).ToArray();
foreach (var (left, top, regionWidth, regionHeight) in new[] { (9, 7, 3, 3), (118, 90, 2, 4), (64, 2, 1, 1), (3, 60, 4, 2) })
{
for (var y = top; y < top + regionHeight; y++)
{
for (var x = left; x < left + regionWidth; x++)
levels[y * width + x] = 1u;
}
}
AssertSmallRegionsFilled(levels, width, height, size, 1u);
}
static void AssertSmallRegionsFilled(uint[] levels, int width, int height, int size, uint target)
{
var device = Device();
var levels = Levels(width, height, 0x42u);
var components = MangaScreentoneReference.Label(levels.Select(level => level == target ? 0u : MangaScreentoneSettings.InactiveClass).ToArray(), width, height, false);
const float minimumRegion = 24f;
var expectedMedian = MangaScreentoneReference.Median(levels, width, height, size, index => levels[index] == target && components.Area[components.Labels[index]] < minimumRegion);
@@ -378,7 +403,7 @@ public sealed class MangaScreentoneShaderTests
device.For(ThreadGroupAlignment.AlignX<ComponentAreaShader>(width), ThreadGroupAlignment.AlignY<ComponentAreaShader>(height), new ComponentAreaShader(classBuffer, labels, area, width, height));
device.For(width, height, new HoleMarkShader(levelBuffer, labels, area, classBuffer, width, height, target, minimumRegion));
device.For(width, height, new HoleCountShader(classBuffer, low, high, width, height, size / 2));
device.For(ThreadGroupAlignment.AlignX<HoleCountShader>(width), ThreadGroupAlignment.AlignY<HoleCountShader>(height), new HoleCountShader(classBuffer, low, high, width, height, size / 2));
device.For(width, height, new HoleResolveShader(levelBuffer, classBuffer, low, high, output, width, height, size / 2));
Assert.Equal(expected, Download(output));
+1 -1
ファイルの表示
@@ -469,7 +469,7 @@ internal sealed partial class MangaScreentonePipelineHost
RecordComponents(in context, grid, grid.Classes, width, height, false, ComponentStatistic.Area);
context.For(width, height, new HoleMarkShader(current, grid.Labels, grid.StatA, grid.Classes, width, height, target, derived.PlanMinRegion));
context.Barrier(grid.Classes);
context.For(width, height, new HoleCountShader(grid.Classes, grid.StatB, grid.StatC, width, height, fillRadius));
ForAligned(in context, width, height, new HoleCountShader(grid.Classes, grid.StatB, grid.StatC, width, height, fillRadius));
context.Barrier(grid.StatB);
context.Barrier(grid.StatC);
context.For(width, height, new HoleResolveShader(current, grid.Classes, grid.StatB, grid.StatC, next, width, height, fillRadius));
+22 -1
ファイルの表示
@@ -336,7 +336,7 @@ internal readonly partial struct HoleMarkShader(
}
}
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
[ThreadGroupSize(MangaScreentoneSettings.BlurGroupSize, MangaScreentoneSettings.BlurGroupSize, 1)]
[GeneratedComputeShaderDescriptor]
internal readonly partial struct HoleCountShader(
ReadWriteBuffer<uint> marked,
@@ -353,8 +353,29 @@ internal readonly partial struct HoleCountShader(
private readonly int height = height;
private readonly int radius = radius;
[GroupShared(1)]
private static readonly int[] holeNearby = null!;
public void Execute()
{
if (GroupIds.Index == 0)
holeNearby[0] = 0;
Hlsl.GroupMemoryBarrierWithGroupSync();
var left = ThreadIds.X - GroupIds.X;
var top = ThreadIds.Y - GroupIds.Y;
var span = MangaScreentoneSettings.BlurGroupSize + 2 * radius;
for (var cell = GroupIds.Index; cell < MangaScreentoneSettings.BlurGroupSize * span; cell += MangaScreentoneSettings.BlurGroupSize * MangaScreentoneSettings.BlurGroupSize)
{
var column = left + cell % MangaScreentoneSettings.BlurGroupSize;
var line = top - radius + cell / MangaScreentoneSettings.BlurGroupSize;
if (column < width && line >= 0 && line < height && marked[line * width + column] == MangaScreentoneSettings.HoleMarker)
Hlsl.InterlockedOr(ref holeNearby[0], 1);
}
Hlsl.GroupMemoryBarrierWithGroupSync();
if (holeNearby[0] == 0)
return;
var x = ThreadIds.X;
var y = ThreadIds.Y;
if (x >= width || y >= height)