浸透の各ステップを到達範囲の外接矩形だけに発行する
このコミットが含まれているのは:
4ファイル変更
+79
-24
検索条件に一致するファイルはありません
@@ -104,6 +104,10 @@ internal readonly partial struct MaskHashResetShader(
|
||||
{
|
||||
if (ThreadIds.X != 0)
|
||||
return;
|
||||
scratch[2] = int.MaxValue;
|
||||
scratch[3] = int.MaxValue;
|
||||
scratch[4] = int.MinValue;
|
||||
scratch[5] = int.MinValue;
|
||||
scratch[6] = 0;
|
||||
scratch[7] = 0;
|
||||
}
|
||||
@@ -130,7 +134,15 @@ internal readonly partial struct MaskHashShader(
|
||||
return;
|
||||
|
||||
var index = gy * gridWidth + gx;
|
||||
var quantized = (int)(deposit[index] * 255f + 0.5f);
|
||||
var value = deposit[index];
|
||||
if (value != 0f)
|
||||
{
|
||||
Hlsl.InterlockedMin(ref scratch[2], gx);
|
||||
Hlsl.InterlockedMin(ref scratch[3], gy);
|
||||
Hlsl.InterlockedMax(ref scratch[4], gx);
|
||||
Hlsl.InterlockedMax(ref scratch[5], gy);
|
||||
}
|
||||
var quantized = (int)(value * 255f + 0.5f);
|
||||
if (quantized <= 0)
|
||||
return;
|
||||
|
||||
@@ -339,6 +351,8 @@ internal readonly partial struct SupplyShader(
|
||||
ReadWriteBuffer<float> density,
|
||||
ReadWriteBuffer<int> reachMask,
|
||||
ReadWriteBuffer<float> deposit,
|
||||
int regionX,
|
||||
int regionY,
|
||||
int gridWidth,
|
||||
int gridHeight) : IComputeShader
|
||||
{
|
||||
@@ -348,13 +362,15 @@ internal readonly partial struct SupplyShader(
|
||||
private readonly ReadWriteBuffer<float> density = density;
|
||||
private readonly ReadWriteBuffer<int> reachMask = reachMask;
|
||||
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||
private readonly int regionX = regionX;
|
||||
private readonly int regionY = regionY;
|
||||
private readonly int gridWidth = gridWidth;
|
||||
private readonly int gridHeight = gridHeight;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var gx = ThreadIds.X;
|
||||
var gy = ThreadIds.Y;
|
||||
var gx = ThreadIds.X + regionX;
|
||||
var gy = ThreadIds.Y + regionY;
|
||||
if (gx >= gridWidth || gy >= gridHeight)
|
||||
return;
|
||||
|
||||
@@ -390,6 +406,8 @@ internal readonly partial struct KappaShader(
|
||||
ReadWriteBuffer<float> alumField,
|
||||
ReadWriteBuffer<float> pinField,
|
||||
ReadWriteBuffer<float> kappa,
|
||||
int regionX,
|
||||
int regionY,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
float fiber,
|
||||
@@ -404,6 +422,8 @@ internal readonly partial struct KappaShader(
|
||||
private readonly ReadWriteBuffer<float> alumField = alumField;
|
||||
private readonly ReadWriteBuffer<float> pinField = pinField;
|
||||
private readonly ReadWriteBuffer<float> kappa = kappa;
|
||||
private readonly int regionX = regionX;
|
||||
private readonly int regionY = regionY;
|
||||
private readonly int gridWidth = gridWidth;
|
||||
private readonly int gridHeight = gridHeight;
|
||||
private readonly float fiber = fiber;
|
||||
@@ -413,8 +433,8 @@ internal readonly partial struct KappaShader(
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var gx = ThreadIds.X;
|
||||
var gy = ThreadIds.Y;
|
||||
var gx = ThreadIds.X + regionX;
|
||||
var gy = ThreadIds.Y + regionY;
|
||||
if (gx >= gridWidth || gy >= gridHeight)
|
||||
return;
|
||||
|
||||
@@ -467,6 +487,8 @@ internal readonly partial struct StreamCollideShader(
|
||||
ReadWriteBuffer<float> deposit,
|
||||
ReadWriteBuffer<float> densityOut,
|
||||
ReadWriteBuffer<Float2> velocity,
|
||||
int regionX,
|
||||
int regionY,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
float omega,
|
||||
@@ -479,6 +501,8 @@ internal readonly partial struct StreamCollideShader(
|
||||
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||
private readonly ReadWriteBuffer<float> densityOut = densityOut;
|
||||
private readonly ReadWriteBuffer<Float2> velocity = velocity;
|
||||
private readonly int regionX = regionX;
|
||||
private readonly int regionY = regionY;
|
||||
private readonly int gridWidth = gridWidth;
|
||||
private readonly int gridHeight = gridHeight;
|
||||
private readonly float omega = omega;
|
||||
@@ -486,8 +510,8 @@ internal readonly partial struct StreamCollideShader(
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var gx = ThreadIds.X;
|
||||
var gy = ThreadIds.Y;
|
||||
var gx = ThreadIds.X + regionX;
|
||||
var gy = ThreadIds.Y + regionY;
|
||||
if (gx >= gridWidth || gy >= gridHeight)
|
||||
return;
|
||||
|
||||
@@ -599,6 +623,8 @@ internal readonly partial struct PigmentShader(
|
||||
ReadWriteBuffer<float> deposit,
|
||||
ReadWriteBuffer<float> fiberField,
|
||||
ReadWriteBuffer<int> scratch,
|
||||
int regionX,
|
||||
int regionY,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
int step,
|
||||
@@ -618,6 +644,8 @@ internal readonly partial struct PigmentShader(
|
||||
private readonly ReadWriteBuffer<float> deposit = deposit;
|
||||
private readonly ReadWriteBuffer<float> fiberField = fiberField;
|
||||
private readonly ReadWriteBuffer<int> scratch = scratch;
|
||||
private readonly int regionX = regionX;
|
||||
private readonly int regionY = regionY;
|
||||
private readonly int gridWidth = gridWidth;
|
||||
private readonly int gridHeight = gridHeight;
|
||||
private readonly int step = step;
|
||||
@@ -626,8 +654,8 @@ internal readonly partial struct PigmentShader(
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var gx = ThreadIds.X;
|
||||
var gy = ThreadIds.Y;
|
||||
var gx = ThreadIds.X + regionX;
|
||||
var gy = ThreadIds.Y + regionY;
|
||||
if (gx >= gridWidth || gy >= gridHeight)
|
||||
return;
|
||||
|
||||
|
||||
@@ -148,8 +148,8 @@ internal sealed class InkDispersionPipeline : IDisposable
|
||||
_scratchReadBack.CopyFrom(_scratch);
|
||||
var hashed = _scratchReadBack.Span;
|
||||
var key = new StructureKey(
|
||||
hashed[6],
|
||||
hashed[7],
|
||||
hashed[InkDispersionSettings.ScratchMaskHashSum],
|
||||
hashed[InkDispersionSettings.ScratchMaskHashMix],
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
parameters.Quality,
|
||||
@@ -163,13 +163,19 @@ internal sealed class InkDispersionPipeline : IDisposable
|
||||
if (_structureKey == key)
|
||||
return false;
|
||||
|
||||
_host.RecordFlow(_scratch, _inkStep!, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||
var region = GetFlowRegion(
|
||||
hashed[InkDispersionSettings.ScratchBoundsMinX],
|
||||
hashed[InkDispersionSettings.ScratchBoundsMinY],
|
||||
hashed[InkDispersionSettings.ScratchBoundsMaxX],
|
||||
hashed[InkDispersionSettings.ScratchBoundsMaxY],
|
||||
in derived);
|
||||
_host.RecordFlow(_scratch, _inkStep!, in region, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||
_scratchReadBack.CopyFrom(_scratch);
|
||||
var wetStepReadBack = _inkStepReadBack!;
|
||||
wetStepReadBack.CopyFrom(_inkStep!);
|
||||
var scratch = _scratchReadBack.Span;
|
||||
_cachedInkCount = scratch[0];
|
||||
_cachedMaxInkStep = scratch[1];
|
||||
_cachedInkCount = scratch[InkDispersionSettings.ScratchWetCount];
|
||||
_cachedMaxInkStep = scratch[InkDispersionSettings.ScratchMaxWetStep];
|
||||
wetStepReadBack.Span.CopyTo(_cachedInkStep!);
|
||||
BuildBoundsPrefix();
|
||||
_structureKey = key;
|
||||
@@ -239,6 +245,19 @@ internal sealed class InkDispersionPipeline : IDisposable
|
||||
return _host.RecordFullPipeline(source, output, _scratch, _inkStep!, width, height, _gridWidth, _gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
private CellRect GetFlowRegion(int minX, int minY, int maxX, int maxY, in DerivedValues derived)
|
||||
{
|
||||
if (minX > maxX || minY > maxY)
|
||||
return new CellRect(0, 0, _gridWidth, _gridHeight);
|
||||
|
||||
var dilation = (int)MathF.Ceiling(derived.ReachPixels / derived.CellSize);
|
||||
var left = Math.Max(minX - dilation, 0);
|
||||
var top = Math.Max(minY - dilation, 0);
|
||||
var right = Math.Min(maxX + dilation + 1, _gridWidth);
|
||||
var bottom = Math.Min(maxY + dilation + 1, _gridHeight);
|
||||
return new CellRect(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
private void BuildBoundsPrefix()
|
||||
{
|
||||
var maxWetStep = Math.Clamp(_cachedMaxInkStep, -1, InkDispersionSettings.MaximumStepCount);
|
||||
@@ -390,6 +409,8 @@ internal sealed class InkDispersionPipeline : IDisposable
|
||||
|
||||
internal readonly record struct PixelRect(int X, int Y, int Width, int Height);
|
||||
|
||||
internal readonly record struct CellRect(int X, int Y, int Width, int Height);
|
||||
|
||||
private readonly record struct StructureKey(
|
||||
int MaskHashSum,
|
||||
int MaskHashMix,
|
||||
|
||||
@@ -86,7 +86,7 @@ internal sealed partial class InkDispersionPipelineHost
|
||||
_ = _device;
|
||||
|
||||
RecordSilhouetteStage(in context, grid, source, 0, 0, width, height, gridWidth, gridHeight, in derived);
|
||||
RecordFlowStage(in context, grid, scratch, inkStep, gridWidth, gridHeight, in derived, in parameters);
|
||||
RecordFlowStage(in context, grid, scratch, inkStep, new InkDispersionPipeline.CellRect(0, 0, gridWidth, gridHeight), gridWidth, gridHeight, in derived, in parameters);
|
||||
RecordRenderStage(in context, grid, output, scratch, inkStep, new InkDispersionPipeline.PixelRect(0, 0, width, height), gridWidth, gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ internal sealed partial class InkDispersionPipelineHost
|
||||
[ComputeOwnedResource(nameof(_grid))] InkDispersionGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> inkStep,
|
||||
in InkDispersionPipeline.CellRect region,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in InkDispersionPipeline.DerivedValues derived,
|
||||
@@ -163,7 +164,7 @@ internal sealed partial class InkDispersionPipelineHost
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordFlowStage(in context, grid, scratch, inkStep, gridWidth, gridHeight, in derived, in parameters);
|
||||
RecordFlowStage(in context, grid, scratch, inkStep, region, gridWidth, gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
@@ -219,6 +220,7 @@ internal sealed partial class InkDispersionPipelineHost
|
||||
InkDispersionGridResources grid,
|
||||
ReadWriteBuffer<int> scratch,
|
||||
ReadWriteBuffer<int> inkStep,
|
||||
in InkDispersionPipeline.CellRect region,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in InkDispersionPipeline.DerivedValues derived,
|
||||
@@ -271,26 +273,26 @@ internal sealed partial class InkDispersionPipelineHost
|
||||
var pigmentOut = grid.FlowPigmentB;
|
||||
for (var step = 0; step < derived.Steps; step++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new SupplyShader(
|
||||
distributionsIn, grid.Surface, pigmentIn, grid.DensityA, grid.ReachMask, grid.Deposit, gridWidth, gridHeight));
|
||||
context.For(region.Width, region.Height, new SupplyShader(
|
||||
distributionsIn, grid.Surface, pigmentIn, grid.DensityA, grid.ReachMask, grid.Deposit, region.X, region.Y, gridWidth, gridHeight));
|
||||
context.Barrier(distributionsIn);
|
||||
context.Barrier(grid.Surface);
|
||||
context.Barrier(pigmentIn);
|
||||
context.Barrier(grid.DensityA);
|
||||
context.For(gridWidth, gridHeight, new KappaShader(
|
||||
grid.DensityA, grid.FixedPigment, grid.ReachMask, grid.FiberField, grid.AlumField, grid.PinField, grid.Kappa, gridWidth, gridHeight,
|
||||
context.For(region.Width, region.Height, new KappaShader(
|
||||
grid.DensityA, grid.FixedPigment, grid.ReachMask, grid.FiberField, grid.AlumField, grid.PinField, grid.Kappa, region.X, region.Y, gridWidth, gridHeight,
|
||||
derived.Fiber, derived.Sizing, derived.Viscosity, derived.Sigma));
|
||||
context.Barrier(grid.Kappa);
|
||||
context.For(gridWidth, gridHeight, new StreamCollideShader(
|
||||
context.For(region.Width, region.Height, new StreamCollideShader(
|
||||
distributionsIn, distributionsOut, grid.Kappa, grid.ReachMask, grid.Deposit, grid.DensityB, grid.Velocity,
|
||||
gridWidth, gridHeight, derived.Omega, derived.SurfaceEvaporation));
|
||||
region.X, region.Y, gridWidth, gridHeight, derived.Omega, derived.SurfaceEvaporation));
|
||||
context.Barrier(distributionsOut);
|
||||
context.Barrier(grid.DensityB);
|
||||
context.Barrier(grid.Velocity);
|
||||
context.For(gridWidth, gridHeight, new PigmentShader(
|
||||
context.For(region.Width, region.Height, new PigmentShader(
|
||||
distributionsOut, grid.DensityA, grid.DensityB, grid.Velocity, pigmentIn, pigmentOut,
|
||||
grid.FixedPigment, grid.Wetness, inkStep, grid.ReachMask, grid.Deposit, grid.FiberField, scratch,
|
||||
gridWidth, gridHeight, step, derived.Fiber, derived.Viscosity));
|
||||
region.X, region.Y, gridWidth, gridHeight, step, derived.Fiber, derived.Viscosity));
|
||||
context.Barrier(pigmentOut);
|
||||
context.Barrier(grid.FixedPigment);
|
||||
context.Barrier(grid.Wetness);
|
||||
|
||||
@@ -46,6 +46,10 @@ internal static class InkDispersionSettings
|
||||
public const int ScratchLength = 8;
|
||||
public const int ScratchWetCount = 0;
|
||||
public const int ScratchMaxWetStep = 1;
|
||||
public const int ScratchBoundsMinX = 2;
|
||||
public const int ScratchBoundsMinY = 3;
|
||||
public const int ScratchBoundsMaxX = 4;
|
||||
public const int ScratchBoundsMaxY = 5;
|
||||
public const int ScratchMaskHashSum = 6;
|
||||
public const int ScratchMaskHashMix = 7;
|
||||
public const int MaximumPendingSubmissions = 32;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする