Cut TubeField local tile reservoir path
This commit is contained in:
parent
026d5a0002
commit
e6dac642ee
5 changed files with 102 additions and 1263 deletions
|
|
@ -124,8 +124,10 @@ For opaque Form fields, local candidate generation owns primary visibility
|
|||
discovery before reservoir reuse. It may be deterministic when sparse stochastic
|
||||
sampling would leave holes in the visible surface. This is not a fallback to a
|
||||
private renderer; it is the producer side of the shared reservoir contract.
|
||||
TubeField's bounded tile-local candidate enumeration is the current concrete
|
||||
example.
|
||||
TubeField's current concrete example is raster proxy candidate discovery:
|
||||
compute emits conservative segment envelopes, the fixed-function pipeline
|
||||
finds covered pixels, and the proxy pixel shader evaluates the tube SDF before
|
||||
writing candidates into the shared reservoir inlet.
|
||||
|
||||
Every evidence sample should state its layer and encoding before lowering:
|
||||
Form, Appearance, or Transport; then SDF, height, density, extinction,
|
||||
|
|
|
|||
|
|
@ -39,13 +39,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int GpuSensorSamplesPerTexture = 131_072;
|
||||
private const int MaxTemporalGaussianCount = 1_048_576;
|
||||
private const int MaxVisibleFractalSplatCount = 524_288;
|
||||
private const int MaxTubeFieldColumns = 65_536;
|
||||
private const int MaxTubeFieldVertices = MaxTubeFieldColumns * 4;
|
||||
private const int MaxTubeFieldIndices = MaxTubeFieldColumns * 6;
|
||||
private const int MaxTubeFieldSegments = 65_536;
|
||||
private const int MaxTubeFieldVertices = MaxTubeFieldSegments * 4;
|
||||
private const int MaxTubeFieldIndices = MaxTubeFieldSegments * 6;
|
||||
private const int MaxTubeFieldDrawBatches = 4_096;
|
||||
private const int TubeFieldRestirTileSize = 16;
|
||||
private const int TubeFieldRestirMaxTileSegments = 128;
|
||||
private const int TubeFieldReservoirStrideBytes = 112;
|
||||
private const int FieldReservoirSlotsPerPixel = 4;
|
||||
private const int FieldReservoirCandidateStrideBytes = 64;
|
||||
private const int FieldReservoirHistoryStrideBytes = 64;
|
||||
|
|
@ -117,20 +114,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int RootTubeFieldRenderBlueNoise = 4;
|
||||
private const int RootTubeFieldRenderReservoirCandidates = 5;
|
||||
private const int RootTubeFieldRenderReservoirLocks = 6;
|
||||
private const int RootTubeFieldRestirFrameConstants = 0;
|
||||
private const int RootTubeFieldRestirConstants = 1;
|
||||
private const int RootTubeFieldRestirSegments = 2;
|
||||
private const int RootTubeFieldRestirTileSegmentsRead = 3;
|
||||
private const int RootTubeFieldRestirPreviousReservoirs = 4;
|
||||
private const int RootTubeFieldRestirReadReservoirs = 5;
|
||||
private const int RootTubeFieldRestirTileCounts = 6;
|
||||
private const int RootTubeFieldRestirTileSegments = 7;
|
||||
private const int RootTubeFieldRestirInitialReservoirs = 8;
|
||||
private const int RootTubeFieldRestirWriteReservoirs = 9;
|
||||
private const int RootTubeFieldRestirFieldCandidates = 10;
|
||||
private const int RootTubeFieldRestirTileCountsRead = 11;
|
||||
private const int RootTubeFieldRestirRamp = 12;
|
||||
private const int RootTubeFieldRestirSource = 13;
|
||||
private static readonly DebugUi.DebugUiOption[] RenderDebugOptions =
|
||||
[
|
||||
new(0, "Final"),
|
||||
|
|
@ -176,7 +159,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private readonly ID3D12RootSignature gpuSensorFusionRootSignature;
|
||||
private readonly ID3D12RootSignature fractalReservoirRootSignature;
|
||||
private readonly ID3D12RootSignature tubeFieldRootSignature;
|
||||
private readonly ID3D12RootSignature tubeFieldRestirRootSignature;
|
||||
private readonly ID3D12RootSignature tubeFieldRenderRootSignature;
|
||||
private readonly ID3D12CommandSignature generatedMeshDrawCommandSignature;
|
||||
private readonly D3D12BlueNoiseTexture blueNoiseTexture;
|
||||
|
|
@ -194,12 +176,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private ID3D12PipelineState? fractalPbrReservoirPipelineState;
|
||||
private ID3D12PipelineState? fractalRadiosityReservoirPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldComputePipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirClearTilesPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirClearReservoirsPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirBinSegmentsPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirInitialPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirTemporalPipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRestirSpatialResolvePipelineState;
|
||||
private ID3D12PipelineState? tubeFieldRenderPipelineState;
|
||||
private ID3D12PipelineState? fieldReservoirResolvePipelineState;
|
||||
private ID3D12PipelineState?[] sdfProxyPipelineStates = [];
|
||||
|
|
@ -261,12 +237,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private D3D12StructuredBuffer? bufferFieldTextureSampleBuffer;
|
||||
private readonly D3D12StructuredBuffer tubeFieldVertexBuffer;
|
||||
private readonly D3D12StructuredBuffer tubeFieldIndexBuffer;
|
||||
private readonly D3D12StructuredBuffer tubeFieldColumnBuffer;
|
||||
private D3D12StructuredBuffer tubeFieldRestirTileCountBuffer = null!;
|
||||
private D3D12StructuredBuffer tubeFieldRestirTileSegmentBuffer = null!;
|
||||
private D3D12StructuredBuffer tubeFieldRestirScratchReservoirBuffer = null!;
|
||||
private D3D12StructuredBuffer[] tubeFieldRestirReservoirBuffers = [];
|
||||
private bool tubeFieldRestirReservoirsInitialized;
|
||||
private readonly D3D12StructuredBuffer tubeFieldSegmentBuffer;
|
||||
private readonly D3D12StructuredBuffer tubeFieldStatsBuffer;
|
||||
private readonly D3D12StructuredBuffer tubeFieldDrawArgumentBuffer;
|
||||
private D3D12StructuredBuffer fieldReservoirCandidateBuffer = null!;
|
||||
|
|
@ -316,9 +287,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private AquariumFieldLoweringPlan activeFieldLoweringPlan = AquariumFieldLoweringPlan.Empty;
|
||||
private D3D12FieldResourceStats activeFieldResourceStats = D3D12FieldResourceStats.Empty;
|
||||
private int activeTubeFieldDrawIndexCount;
|
||||
private int activeTubeFieldDispatchedColumns;
|
||||
private int activeTubeFieldRequestedColumns;
|
||||
private int activeTubeFieldTruncatedColumns;
|
||||
private int activeTubeFieldDispatchedSegments;
|
||||
private int activeTubeFieldRequestedSegments;
|
||||
private int activeTubeFieldTruncatedSegments;
|
||||
private int activeTubeFieldIndirectDrawCount;
|
||||
private int activeTubeFieldSkippedDrawBatches;
|
||||
private int activeTubeFieldUnplannedLowerings;
|
||||
|
|
@ -455,10 +426,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
temporalGaussianBuffer = new D3D12StructuredBuffer(device, MaxTemporalGaussianCount, Marshal.SizeOf<D3D12TemporalGaussianPacket>(), "Aquarium D3D12 Temporal Gaussian Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldVertexBuffer = new D3D12StructuredBuffer(device, MaxTubeFieldVertices, Marshal.SizeOf<D3D12TubeFieldVertex>(), "Aquarium D3D12 TubeField Vertex Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldIndexBuffer = new D3D12StructuredBuffer(device, MaxTubeFieldIndices, Marshal.SizeOf<uint>(), "Aquarium D3D12 TubeField Index Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldColumnBuffer = new D3D12StructuredBuffer(device, MaxTubeFieldColumns, Marshal.SizeOf<D3D12TubeFieldColumn>(), "Aquarium D3D12 TubeField Column Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldSegmentBuffer = new D3D12StructuredBuffer(device, MaxTubeFieldSegments, Marshal.SizeOf<D3D12TubeFieldSegment>(), "Aquarium D3D12 TubeField Segment Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldStatsBuffer = new D3D12StructuredBuffer(device, 4, Marshal.SizeOf<uint>(), "Aquarium D3D12 TubeField Stats Buffer", allowUnorderedAccess: true);
|
||||
tubeFieldDrawArgumentBuffer = new D3D12StructuredBuffer(device, MaxTubeFieldDrawBatches * GeneratedMeshDrawArgumentUIntCount, Marshal.SizeOf<uint>(), "Aquarium D3D12 TubeField Indirect Draw Arguments", allowUnorderedAccess: true);
|
||||
CreateTubeFieldRestirBuffers();
|
||||
CreateFieldReservoirBuffers();
|
||||
resourceRegistry.Add("sdf-light-buffer", sdfLightBuffer);
|
||||
resourceRegistry.Add("sdf-object-buffer", sdfObjectBuffer);
|
||||
|
|
@ -469,7 +439,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
resourceRegistry.Add("temporal-gaussian-buffer", temporalGaussianBuffer);
|
||||
resourceRegistry.Add("tube-field-vertex-buffer", tubeFieldVertexBuffer);
|
||||
resourceRegistry.Add("tube-field-index-buffer", tubeFieldIndexBuffer);
|
||||
resourceRegistry.Add("tube-field-column-buffer", tubeFieldColumnBuffer);
|
||||
resourceRegistry.Add("tube-field-segment-buffer", tubeFieldSegmentBuffer);
|
||||
resourceRegistry.Add("tube-field-stats-buffer", tubeFieldStatsBuffer);
|
||||
resourceRegistry.Add("tube-field-indirect-draw-arguments", tubeFieldDrawArgumentBuffer);
|
||||
commandList = device.CreateCommandList<ID3D12GraphicsCommandList>(0, CommandListType.Direct, frames[frameIndex].CommandAllocator, null);
|
||||
|
|
@ -503,8 +473,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalReservoirRootSignature.Name = "Aquarium D3D12 Fractal Reservoir Root Signature";
|
||||
tubeFieldRootSignature = CreateTubeFieldRootSignature();
|
||||
tubeFieldRootSignature.Name = "Aquarium D3D12 TubeField Root Signature";
|
||||
tubeFieldRestirRootSignature = CreateTubeFieldRestirRootSignature();
|
||||
tubeFieldRestirRootSignature.Name = "Aquarium D3D12 TubeField ReSTIR Root Signature";
|
||||
tubeFieldRenderRootSignature = CreateTubeFieldRenderRootSignature();
|
||||
tubeFieldRenderRootSignature.Name = "Aquarium D3D12 TubeField Render Root Signature";
|
||||
generatedMeshDrawCommandSignature = CreateGeneratedMeshDrawCommandSignature();
|
||||
|
|
@ -650,7 +618,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
$"candidates {activeFieldEvidenceFrame.Candidates.Count} / packets {activeFieldEvidenceFrame.BackendPackets.Count} / " +
|
||||
$"planned {activeFieldLoweringPlan.Packets.Count} / deferred {activeFieldLoweringPlan.DeferredRequests.Count} / errors {errorCount}" +
|
||||
(activeFieldEvidenceFrame.TubeSplineLowerings.Count > 0
|
||||
? $" / tube columns requested {activeTubeFieldRequestedColumns} dispatched {activeTubeFieldDispatchedColumns} truncated {activeTubeFieldTruncatedColumns} invalid {activeTubeFieldInvalidColumns} uploads {activeFieldResourceUploadCount} skipped {activeFieldResourceUploadSkippedCount} unplanned {activeTubeFieldUnplannedLowerings}"
|
||||
? $" / tube segments requested {activeTubeFieldRequestedSegments} dispatched {activeTubeFieldDispatchedSegments} truncated {activeTubeFieldTruncatedSegments} invalid {activeTubeFieldInvalidColumns} uploads {activeFieldResourceUploadCount} skipped {activeFieldResourceUploadSkippedCount} unplanned {activeTubeFieldUnplannedLowerings}"
|
||||
: string.Empty);
|
||||
}
|
||||
|
||||
|
|
@ -1166,12 +1134,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
&& fractalPbrReservoirPipelineState is not null
|
||||
&& fractalRadiosityReservoirPipelineState is not null
|
||||
&& tubeFieldComputePipelineState is not null
|
||||
&& tubeFieldRestirClearTilesPipelineState is not null
|
||||
&& tubeFieldRestirClearReservoirsPipelineState is not null
|
||||
&& tubeFieldRestirBinSegmentsPipelineState is not null
|
||||
&& tubeFieldRestirInitialPipelineState is not null
|
||||
&& tubeFieldRestirTemporalPipelineState is not null
|
||||
&& tubeFieldRestirSpatialResolvePipelineState is not null
|
||||
&& tubeFieldRenderPipelineState is not null
|
||||
&& fieldReservoirResolvePipelineState is not null
|
||||
&& sdfProxyPipelineStates.All(pipeline => pipeline is not null)
|
||||
|
|
@ -1226,10 +1188,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
DisposeFractalReservoirBuffers();
|
||||
bufferFieldTextureSplineProgramBuffer?.Dispose();
|
||||
bufferFieldTextureSampleBuffer?.Dispose();
|
||||
DisposeTubeFieldRestirBuffers();
|
||||
tubeFieldStatsBuffer.Dispose();
|
||||
tubeFieldDrawArgumentBuffer.Dispose();
|
||||
tubeFieldColumnBuffer.Dispose();
|
||||
tubeFieldSegmentBuffer.Dispose();
|
||||
tubeFieldIndexBuffer.Dispose();
|
||||
tubeFieldVertexBuffer.Dispose();
|
||||
fieldReservoirLockBuffer.Dispose();
|
||||
|
|
@ -1857,18 +1818,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalRadiosityReservoir.Name = "Aquarium D3D12 Fractal Radiosity Reservoir Compute Pipeline";
|
||||
var tubeFieldCompute = CreateTubeFieldComputePipelineState(paths.TubeField);
|
||||
tubeFieldCompute.Name = "Aquarium D3D12 TubeField Compute Pipeline";
|
||||
var tubeFieldRestirClearTiles = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirClearTilesCS");
|
||||
tubeFieldRestirClearTiles.Name = "Aquarium D3D12 TubeField ReSTIR Clear Tiles Pipeline";
|
||||
var tubeFieldRestirClearReservoirs = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirClearReservoirsCS");
|
||||
tubeFieldRestirClearReservoirs.Name = "Aquarium D3D12 TubeField ReSTIR Clear Reservoirs Pipeline";
|
||||
var tubeFieldRestirBinSegments = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirBinSegmentsCS");
|
||||
tubeFieldRestirBinSegments.Name = "Aquarium D3D12 TubeField ReSTIR Bin Segments Pipeline";
|
||||
var tubeFieldRestirInitial = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirInitialCS");
|
||||
tubeFieldRestirInitial.Name = "Aquarium D3D12 TubeField ReSTIR Initial Pipeline";
|
||||
var tubeFieldRestirTemporal = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirTemporalCS");
|
||||
tubeFieldRestirTemporal.Name = "Aquarium D3D12 TubeField ReSTIR Temporal Pipeline";
|
||||
var tubeFieldRestirSpatialResolve = CreateTubeFieldRestirPipelineState(paths.TubeField, "D3D12TubeFieldRestirSpatialResolveCS");
|
||||
tubeFieldRestirSpatialResolve.Name = "Aquarium D3D12 TubeField ReSTIR Spatial Resolve Pipeline";
|
||||
var tubeFieldRender = CreateTubeFieldRenderPipelineState(paths.TubeField);
|
||||
tubeFieldRender.Name = "Aquarium D3D12 TubeField Render Pipeline";
|
||||
var fieldReservoirResolve = CreateFieldReservoirResolvePipelineState(paths.Post);
|
||||
|
|
@ -1907,12 +1856,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalPbrReservoir,
|
||||
fractalRadiosityReservoir,
|
||||
tubeFieldCompute,
|
||||
tubeFieldRestirClearTiles,
|
||||
tubeFieldRestirClearReservoirs,
|
||||
tubeFieldRestirBinSegments,
|
||||
tubeFieldRestirInitial,
|
||||
tubeFieldRestirTemporal,
|
||||
tubeFieldRestirSpatialResolve,
|
||||
tubeFieldRender,
|
||||
fieldReservoirResolve,
|
||||
sdfProxies,
|
||||
|
|
@ -1994,8 +1937,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
sceneCandidateControlRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-candidate-control-target", "Aquarium D3D12 Scene Candidate Control Target");
|
||||
sceneCandidateReservoirGuideRenderTarget = CreateSceneAuxiliaryRenderTarget("scene-candidate-reservoir-guide-target", "Aquarium D3D12 Scene Candidate Reservoir Guide Target");
|
||||
reservoirResolvedRenderTarget = CreateReservoirResolvedRenderTarget();
|
||||
DisposeTubeFieldRestirBuffers();
|
||||
CreateTubeFieldRestirBuffers();
|
||||
CreateFieldReservoirBuffers();
|
||||
sceneDepthStencilView = depthStencilViewArena.Allocate();
|
||||
sceneDepthTarget = CreateSceneDepthTarget(sceneDepthStencilView);
|
||||
|
|
@ -2081,66 +2022,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return checked(Math.Max(1, width) * Math.Max(1, height) * FieldReservoirSlotsPerPixel);
|
||||
}
|
||||
|
||||
private void CreateTubeFieldRestirBuffers()
|
||||
{
|
||||
var pixelCount = checked(Math.Max(1, width) * Math.Max(1, height));
|
||||
var tileCount = TubeFieldRestirTileCount();
|
||||
tubeFieldRestirTileCountBuffer = new D3D12StructuredBuffer(
|
||||
device,
|
||||
tileCount,
|
||||
sizeof(uint),
|
||||
"Aquarium D3D12 TubeField ReSTIR Tile Count Buffer",
|
||||
allowUnorderedAccess: true);
|
||||
tubeFieldRestirTileSegmentBuffer = new D3D12StructuredBuffer(
|
||||
device,
|
||||
checked(tileCount * TubeFieldRestirMaxTileSegments),
|
||||
sizeof(uint),
|
||||
"Aquarium D3D12 TubeField ReSTIR Tile Segment Buffer",
|
||||
allowUnorderedAccess: true);
|
||||
tubeFieldRestirScratchReservoirBuffer = new D3D12StructuredBuffer(
|
||||
device,
|
||||
pixelCount,
|
||||
TubeFieldReservoirStrideBytes,
|
||||
"Aquarium D3D12 TubeField ReSTIR Scratch Reservoir Buffer",
|
||||
allowUnorderedAccess: true);
|
||||
tubeFieldRestirReservoirBuffers =
|
||||
[
|
||||
new D3D12StructuredBuffer(
|
||||
device,
|
||||
pixelCount,
|
||||
TubeFieldReservoirStrideBytes,
|
||||
"Aquarium D3D12 TubeField ReSTIR Reservoir Buffer 0",
|
||||
allowUnorderedAccess: true),
|
||||
new D3D12StructuredBuffer(
|
||||
device,
|
||||
pixelCount,
|
||||
TubeFieldReservoirStrideBytes,
|
||||
"Aquarium D3D12 TubeField ReSTIR Reservoir Buffer 1",
|
||||
allowUnorderedAccess: true),
|
||||
];
|
||||
tubeFieldRestirReservoirsInitialized = false;
|
||||
}
|
||||
|
||||
private void DisposeTubeFieldRestirBuffers()
|
||||
{
|
||||
tubeFieldRestirTileCountBuffer?.Dispose();
|
||||
tubeFieldRestirTileSegmentBuffer?.Dispose();
|
||||
tubeFieldRestirScratchReservoirBuffer?.Dispose();
|
||||
foreach (var reservoirBuffer in tubeFieldRestirReservoirBuffers)
|
||||
{
|
||||
reservoirBuffer.Dispose();
|
||||
}
|
||||
|
||||
tubeFieldRestirReservoirBuffers = [];
|
||||
}
|
||||
|
||||
private int TubeFieldRestirTileCount()
|
||||
{
|
||||
var tilesX = Math.Max(1, (width + TubeFieldRestirTileSize - 1) / TubeFieldRestirTileSize);
|
||||
var tilesY = Math.Max(1, (height + TubeFieldRestirTileSize - 1) / TubeFieldRestirTileSize);
|
||||
return checked(tilesX * tilesY);
|
||||
}
|
||||
|
||||
private D3D12StructuredBuffer CreateFieldReservoirCandidateBuffer()
|
||||
{
|
||||
var elementCount = FieldReservoirElementCount();
|
||||
|
|
@ -2551,7 +2432,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.DrawInstanced(6, (uint)visibleFractalSplatCount, 0, 0);
|
||||
}
|
||||
|
||||
DispatchTubeFieldRestir(context.CommandList, frameResources);
|
||||
RenderTubeFields(context.CommandList, frameResources);
|
||||
RenderSplineSurfaceClaims(context.CommandList, frameResources);
|
||||
}
|
||||
finally
|
||||
|
|
@ -2758,126 +2639,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(fieldReservoirLockBuffer.Resource));
|
||||
}
|
||||
|
||||
private void DispatchTubeFieldRestir(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
{
|
||||
if (activeTubeFieldDispatchedColumns <= 0 ||
|
||||
tubeFieldDrawBatches.Count == 0 ||
|
||||
tubeFieldRestirClearTilesPipelineState is null ||
|
||||
tubeFieldRestirClearReservoirsPipelineState is null ||
|
||||
tubeFieldRestirBinSegmentsPipelineState is null ||
|
||||
tubeFieldRestirInitialPipelineState is null ||
|
||||
tubeFieldRestirTemporalPipelineState is null ||
|
||||
tubeFieldRestirSpatialResolvePipelineState is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentReservoir = tubeFieldRestirReservoirBuffers[temporalFrameIndex & 1];
|
||||
var previousReservoir = tubeFieldRestirReservoirBuffers[(temporalFrameIndex + 1) & 1];
|
||||
var pixelCount = checked(Math.Max(1, width) * Math.Max(1, height));
|
||||
var tileCount = TubeFieldRestirTileCount();
|
||||
activeCommandList.SetComputeRootSignature(tubeFieldRestirRootSignature);
|
||||
activeCommandList.SetComputeRootDescriptorTable(RootTubeFieldRestirFrameConstants, frameResources.FrameConstantsDescriptor.Gpu);
|
||||
var restirRamp = ResolveTubeFieldRamp(activeCommandList, tubeFieldDrawBatches[0].RampResourceKey);
|
||||
restirRamp.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
var restirRampDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
restirRamp.CreateShaderResourceView(device, restirRampDescriptor);
|
||||
activeCommandList.SetComputeRootDescriptorTable(RootTubeFieldRestirRamp, restirRampDescriptor.Gpu);
|
||||
tubeFieldDrawBatches[0].Source.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirSource, tubeFieldDrawBatches[0].Source.Resource.GPUVirtualAddress);
|
||||
BindTubeFieldRestirCommon(activeCommandList, previousReservoir, tubeFieldRestirScratchReservoirBuffer, currentReservoir, currentReservoir);
|
||||
|
||||
currentReservoir.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirClearReservoirsPipelineState);
|
||||
activeCommandList.Dispatch((uint)((pixelCount + 255) / 256), 1, 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(currentReservoir.Resource));
|
||||
if (!tubeFieldRestirReservoirsInitialized)
|
||||
{
|
||||
previousReservoir.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirInitialReservoirs, previousReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.Dispatch((uint)((pixelCount + 255) / 256), 1, 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(previousReservoir.Resource));
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirInitialReservoirs, currentReservoir.Resource.GPUVirtualAddress);
|
||||
tubeFieldRestirReservoirsInitialized = true;
|
||||
}
|
||||
|
||||
var restirConstants = new D3D12TubeFieldConstants(
|
||||
Vector4.Zero,
|
||||
Vector4.Zero,
|
||||
Vector4.Zero,
|
||||
Vector4.Zero,
|
||||
new Vector4(0.0f, 0.0f, 0.0f, activeTubeFieldDispatchedColumns),
|
||||
Vector4.Zero,
|
||||
Vector3.Zero,
|
||||
0.0f,
|
||||
Vector3.Zero,
|
||||
0.0f,
|
||||
Vector3.Zero,
|
||||
0.0f);
|
||||
var restirConstantsUpload = frameResources.UploadRing.WriteConstant(restirConstants);
|
||||
activeCommandList.SetComputeRootConstantBufferView(RootTubeFieldRestirConstants, restirConstantsUpload.GpuVirtualAddress);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirClearTilesPipelineState);
|
||||
tubeFieldRestirTileCountBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
tubeFieldRestirTileSegmentBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
var tileSegmentSlotCount = checked(tileCount * TubeFieldRestirMaxTileSegments);
|
||||
activeCommandList.Dispatch((uint)((Math.Max(tileCount, tileSegmentSlotCount) + 255) / 256), 1, 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldRestirTileCountBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldRestirTileSegmentBuffer.Resource));
|
||||
|
||||
tubeFieldColumnBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirBinSegmentsPipelineState);
|
||||
activeCommandList.Dispatch((uint)((activeTubeFieldDispatchedColumns + 255) / 256), 1, 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldRestirTileCountBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldRestirTileSegmentBuffer.Resource));
|
||||
|
||||
tubeFieldRestirTileCountBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
tubeFieldRestirTileSegmentBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
currentReservoir.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirInitialPipelineState);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirTileCountsRead, tubeFieldRestirTileCountBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.Dispatch((uint)((width + 7) / 8), (uint)((height + 7) / 8), 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(currentReservoir.Resource));
|
||||
|
||||
previousReservoir.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
currentReservoir.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
tubeFieldRestirScratchReservoirBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirInitialReservoirs, currentReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirReadReservoirs, previousReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirWriteReservoirs, tubeFieldRestirScratchReservoirBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirTemporalPipelineState);
|
||||
activeCommandList.Dispatch((uint)((width + 7) / 8), (uint)((height + 7) / 8), 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldRestirScratchReservoirBuffer.Resource));
|
||||
|
||||
tubeFieldRestirScratchReservoirBuffer.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
currentReservoir.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
fieldReservoirCandidateBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirReadReservoirs, tubeFieldRestirScratchReservoirBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirWriteReservoirs, currentReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirFieldCandidates, fieldReservoirCandidateBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetPipelineState(tubeFieldRestirSpatialResolvePipelineState);
|
||||
activeCommandList.Dispatch((uint)((width + 7) / 8), (uint)((height + 7) / 8), 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(currentReservoir.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(fieldReservoirCandidateBuffer.Resource));
|
||||
}
|
||||
|
||||
private void BindTubeFieldRestirCommon(
|
||||
ID3D12GraphicsCommandList activeCommandList,
|
||||
D3D12StructuredBuffer previousReservoir,
|
||||
D3D12StructuredBuffer readReservoir,
|
||||
D3D12StructuredBuffer initialReservoir,
|
||||
D3D12StructuredBuffer writeReservoir)
|
||||
{
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirSegments, tubeFieldColumnBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirTileSegmentsRead, tubeFieldRestirTileSegmentBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirPreviousReservoirs, previousReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootShaderResourceView(RootTubeFieldRestirReadReservoirs, readReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirTileCounts, tubeFieldRestirTileCountBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirTileSegments, tubeFieldRestirTileSegmentBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirInitialReservoirs, initialReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirWriteReservoirs, writeReservoir.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldRestirFieldCandidates, fieldReservoirCandidateBuffer.Resource.GPUVirtualAddress);
|
||||
}
|
||||
|
||||
private void BindPipelinePrivateGeneratedMesh(
|
||||
ID3D12GraphicsCommandList activeCommandList,
|
||||
D3D12PipelinePrivateGeneratedMesh generatedMesh)
|
||||
|
|
@ -3317,9 +3078,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private void DispatchTubeFields(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources)
|
||||
{
|
||||
activeTubeFieldDrawIndexCount = 0;
|
||||
activeTubeFieldDispatchedColumns = 0;
|
||||
activeTubeFieldRequestedColumns = 0;
|
||||
activeTubeFieldTruncatedColumns = 0;
|
||||
activeTubeFieldDispatchedSegments = 0;
|
||||
activeTubeFieldRequestedSegments = 0;
|
||||
activeTubeFieldTruncatedSegments = 0;
|
||||
activeTubeFieldIndirectDrawCount = 0;
|
||||
activeTubeFieldSkippedDrawBatches = 0;
|
||||
activeTubeFieldUnplannedLowerings = 0;
|
||||
|
|
@ -3371,22 +3132,24 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
|
||||
normalized = normalized with { ColumnCount = validColumnCount };
|
||||
var requestedColumns = Math.Max(1, normalized.ColumnCount);
|
||||
activeTubeFieldRequestedColumns += requestedColumns;
|
||||
var remainingColumns = MaxTubeFieldColumns - segmentBase;
|
||||
if (remainingColumns <= 0)
|
||||
var subdivisions = Math.Max(1, normalized.CatmullRomSubdivisions);
|
||||
var piecesPerColumn = checked(Math.Max(1, normalized.Width - 1) * subdivisions);
|
||||
var requestedSegments = checked(piecesPerColumn * Math.Max(1, normalized.ColumnCount));
|
||||
activeTubeFieldRequestedSegments += requestedSegments;
|
||||
var remainingSegments = MaxTubeFieldSegments - segmentBase;
|
||||
if (remainingSegments <= 0)
|
||||
{
|
||||
activeTubeFieldTruncatedColumns += requestedColumns;
|
||||
activeTubeFieldTruncatedSegments += requestedSegments;
|
||||
continue;
|
||||
}
|
||||
|
||||
var dispatchColumns = Math.Min(requestedColumns, remainingColumns);
|
||||
if (dispatchColumns <= 0)
|
||||
var dispatchSegments = Math.Min(requestedSegments, remainingSegments);
|
||||
if (dispatchSegments <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
activeTubeFieldTruncatedColumns += requestedColumns - dispatchColumns;
|
||||
activeTubeFieldTruncatedSegments += requestedSegments - dispatchSegments;
|
||||
var startIndex = segmentBase * 6;
|
||||
var fieldId = StableFieldId(lowering.ClaimKey, 5100.0f, 4096);
|
||||
var constants = new D3D12TubeFieldConstants(
|
||||
|
|
@ -3394,7 +3157,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
new Vector4(normalized.ColumnCount, normalized.ColumnStride, normalized.RollingModulo, normalized.RollingOffset),
|
||||
new Vector4(normalized.AmplitudePower, normalized.AmplitudeScale, normalized.NormalizeMin, normalized.NormalizeMax),
|
||||
new Vector4(normalized.BaseRadius, normalized.RadiusScale, normalized.Alpha, normalized.Feather),
|
||||
new Vector4(normalized.EmissionScale, normalized.CatmullRomSubdivisions, segmentBase, dispatchColumns),
|
||||
new Vector4(normalized.EmissionScale, subdivisions, segmentBase, dispatchSegments),
|
||||
new Vector4(tubeFieldDrawBatches.Count * GeneratedMeshDrawArgumentUIntCount, startIndex, fieldId, 0.0f),
|
||||
normalized.Origin,
|
||||
0.0f,
|
||||
|
|
@ -3417,22 +3180,22 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldIndices, tubeFieldIndexBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldStats, tubeFieldStatsBuffer.Resource.GPUVirtualAddress);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldDrawArguments, tubeFieldDrawArgumentBuffer.Resource.GPUVirtualAddress);
|
||||
tubeFieldColumnBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldSegments, tubeFieldColumnBuffer.Resource.GPUVirtualAddress);
|
||||
tubeFieldSegmentBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess);
|
||||
activeCommandList.SetComputeRootUnorderedAccessView(RootTubeFieldSegments, tubeFieldSegmentBuffer.Resource.GPUVirtualAddress);
|
||||
var ramp = ResolveTubeFieldRamp(activeCommandList, normalized.RampResourceKey);
|
||||
ramp.Transition(activeCommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource);
|
||||
var rampDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
ramp.CreateShaderResourceView(device, rampDescriptor);
|
||||
activeCommandList.SetComputeRootDescriptorTable(RootTubeFieldRamp, rampDescriptor.Gpu);
|
||||
activeCommandList.Dispatch((uint)((dispatchColumns + 255) / 256), 1, 1);
|
||||
activeCommandList.Dispatch((uint)((dispatchSegments + 255) / 256), 1, 1);
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldVertexBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldIndexBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldColumnBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldSegmentBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldStatsBuffer.Resource));
|
||||
activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(tubeFieldDrawArgumentBuffer.Resource));
|
||||
|
||||
segmentBase += dispatchColumns;
|
||||
activeTubeFieldDispatchedColumns += dispatchColumns;
|
||||
segmentBase += dispatchSegments;
|
||||
activeTubeFieldDispatchedSegments += dispatchSegments;
|
||||
activeTubeFieldIndirectDrawCount++;
|
||||
tubeFieldDrawBatches.Add(new D3D12TubeFieldDrawBatch(
|
||||
sourceBuffer,
|
||||
|
|
@ -3441,7 +3204,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
tubeFieldDrawBatches.Count * GeneratedMeshDrawArgumentBytes));
|
||||
}
|
||||
|
||||
activeTubeFieldDrawIndexCount = 0;
|
||||
activeTubeFieldDrawIndexCount = activeTubeFieldDispatchedSegments * 6;
|
||||
}
|
||||
|
||||
private HashSet<string> PlannedTubeFieldClaimKeys()
|
||||
|
|
@ -4168,9 +3931,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
{
|
||||
Console.WriteLine(
|
||||
$"D3D12 tube fields: lowerings {activeFieldEvidenceFrame.TubeSplineLowerings.Count:N0}; " +
|
||||
$"columns requested {activeTubeFieldRequestedColumns:N0}; " +
|
||||
$"dispatched {activeTubeFieldDispatchedColumns:N0}; " +
|
||||
$"truncated {activeTubeFieldTruncatedColumns:N0}; " +
|
||||
$"segments requested {activeTubeFieldRequestedSegments:N0}; " +
|
||||
$"dispatched {activeTubeFieldDispatchedSegments:N0}; " +
|
||||
$"truncated {activeTubeFieldTruncatedSegments:N0}; " +
|
||||
$"indirect draws {activeTubeFieldIndirectDrawCount:N0}; " +
|
||||
$"skipped draw batches {activeTubeFieldSkippedDrawBatches:N0}; " +
|
||||
$"unplanned lowerings {activeTubeFieldUnplannedLowerings:N0}; " +
|
||||
|
|
@ -4178,7 +3941,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
$"resource uploads {activeFieldResourceUploadCount:N0}; " +
|
||||
$"skipped uploads {activeFieldResourceUploadSkippedCount:N0}; " +
|
||||
$"index draw count {activeTubeFieldDrawIndexCount:N0}; " +
|
||||
$"budget {MaxTubeFieldColumns:N0}");
|
||||
$"segment budget {MaxTubeFieldSegments:N0}");
|
||||
}
|
||||
|
||||
if (accumulatedTimingFrames > 0)
|
||||
|
|
@ -4378,12 +4141,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalPbrReservoirPipelineState!,
|
||||
fractalRadiosityReservoirPipelineState!,
|
||||
tubeFieldComputePipelineState!,
|
||||
tubeFieldRestirClearTilesPipelineState!,
|
||||
tubeFieldRestirClearReservoirsPipelineState!,
|
||||
tubeFieldRestirBinSegmentsPipelineState!,
|
||||
tubeFieldRestirInitialPipelineState!,
|
||||
tubeFieldRestirTemporalPipelineState!,
|
||||
tubeFieldRestirSpatialResolvePipelineState!,
|
||||
tubeFieldRenderPipelineState!,
|
||||
fieldReservoirResolvePipelineState!,
|
||||
sdfProxyPipelineStates.Select(pipeline => pipeline!).ToArray(),
|
||||
|
|
@ -4411,12 +4168,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalPbrReservoirPipelineState = pipelines.FractalPbrReservoir;
|
||||
fractalRadiosityReservoirPipelineState = pipelines.FractalRadiosityReservoir;
|
||||
tubeFieldComputePipelineState = pipelines.TubeFieldCompute;
|
||||
tubeFieldRestirClearTilesPipelineState = pipelines.TubeFieldRestirClearTiles;
|
||||
tubeFieldRestirClearReservoirsPipelineState = pipelines.TubeFieldRestirClearReservoirs;
|
||||
tubeFieldRestirBinSegmentsPipelineState = pipelines.TubeFieldRestirBinSegments;
|
||||
tubeFieldRestirInitialPipelineState = pipelines.TubeFieldRestirInitial;
|
||||
tubeFieldRestirTemporalPipelineState = pipelines.TubeFieldRestirTemporal;
|
||||
tubeFieldRestirSpatialResolvePipelineState = pipelines.TubeFieldRestirSpatialResolve;
|
||||
tubeFieldRenderPipelineState = pipelines.TubeFieldRender;
|
||||
fieldReservoirResolvePipelineState = pipelines.FieldReservoirResolve;
|
||||
for (var index = 0; index < sdfProxyPipelineStates.Length; index++)
|
||||
|
|
@ -4446,12 +4197,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
fractalPbrReservoirPipelineState = null;
|
||||
fractalRadiosityReservoirPipelineState = null;
|
||||
tubeFieldComputePipelineState = null;
|
||||
tubeFieldRestirClearTilesPipelineState = null;
|
||||
tubeFieldRestirClearReservoirsPipelineState = null;
|
||||
tubeFieldRestirBinSegmentsPipelineState = null;
|
||||
tubeFieldRestirInitialPipelineState = null;
|
||||
tubeFieldRestirTemporalPipelineState = null;
|
||||
tubeFieldRestirSpatialResolvePipelineState = null;
|
||||
tubeFieldRenderPipelineState = null;
|
||||
Array.Clear(sdfProxyPipelineStates);
|
||||
bloomPrefilterPipelineState = null;
|
||||
|
|
@ -4789,61 +4534,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return device.CreateRootSignature(0, in description, RootSignatureVersion.Version1);
|
||||
}
|
||||
|
||||
private ID3D12RootSignature CreateTubeFieldRestirRootSignature()
|
||||
{
|
||||
var frameConstants = new DescriptorRange(
|
||||
DescriptorRangeType.ConstantBufferView,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var rampTexture = new DescriptorRange(
|
||||
DescriptorRangeType.ShaderResourceView,
|
||||
1,
|
||||
43,
|
||||
0,
|
||||
D3D12.DescriptorRangeOffsetAppend);
|
||||
var rootParameters = new[]
|
||||
{
|
||||
new RootParameter(new RootDescriptorTable([frameConstants]), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ConstantBufferView, new RootDescriptor(3, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(46, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(47, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(48, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(49, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(17, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(18, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(19, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(20, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(21, 0), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(50, 0), ShaderVisibility.All),
|
||||
new RootParameter(new RootDescriptorTable([rampTexture]), ShaderVisibility.All),
|
||||
new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(42, 0), ShaderVisibility.All),
|
||||
};
|
||||
var staticSamplers = new[]
|
||||
{
|
||||
new StaticSamplerDescription(
|
||||
0,
|
||||
Filter.MinMagMipLinear,
|
||||
TextureAddressMode.Clamp,
|
||||
TextureAddressMode.Clamp,
|
||||
TextureAddressMode.Clamp,
|
||||
0.0f,
|
||||
1,
|
||||
ComparisonFunction.Never,
|
||||
StaticBorderColor.TransparentBlack,
|
||||
0.0f,
|
||||
float.MaxValue,
|
||||
ShaderVisibility.All,
|
||||
0),
|
||||
};
|
||||
var description = new RootSignatureDescription(
|
||||
RootSignatureFlags.None,
|
||||
rootParameters,
|
||||
staticSamplers);
|
||||
return device.CreateRootSignature(0, in description, RootSignatureVersion.Version1);
|
||||
}
|
||||
|
||||
private ID3D12CommandSignature CreateGeneratedMeshDrawCommandSignature()
|
||||
{
|
||||
var arguments = new[]
|
||||
|
|
@ -5057,17 +4747,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return device.CreateComputePipelineState(description);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateTubeFieldRestirPipelineState(string path, string entryPoint)
|
||||
{
|
||||
var computeShader = CompileShader(path, entryPoint, "cs_5_0", skipOptimizationInDebug: false);
|
||||
var description = new ComputePipelineStateDescription
|
||||
{
|
||||
RootSignature = tubeFieldRestirRootSignature,
|
||||
ComputeShader = computeShader,
|
||||
};
|
||||
return device.CreateComputePipelineState(description);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateTubeFieldRenderPipelineState(string path)
|
||||
{
|
||||
var vertexShader = CompileShader(path, "D3D12TubeFieldVS", "vs_5_0");
|
||||
|
|
@ -5406,15 +5085,15 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
Vector4 TubeData);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private readonly record struct D3D12TubeFieldColumn(
|
||||
Vector4 Shape,
|
||||
Vector4 Columns,
|
||||
Vector4 Amplitude,
|
||||
private readonly record struct D3D12TubeFieldSegment(
|
||||
Vector4 PreviousRadius,
|
||||
Vector4 StartRadius,
|
||||
Vector4 EndFeather,
|
||||
Vector4 NextAlpha,
|
||||
Vector4 Color0,
|
||||
Vector4 Color1,
|
||||
Vector4 Material,
|
||||
Vector4 DispatchDraw,
|
||||
Vector4 OriginField,
|
||||
Vector4 AxisStepEmission,
|
||||
Vector4 ColumnStep);
|
||||
Vector4 TubeData);
|
||||
|
||||
private readonly record struct D3D12TubeFieldDrawBatch(
|
||||
D3D12StructuredBuffer Source,
|
||||
|
|
@ -5501,12 +5180,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
ID3D12PipelineState FractalPbrReservoir,
|
||||
ID3D12PipelineState FractalRadiosityReservoir,
|
||||
ID3D12PipelineState TubeFieldCompute,
|
||||
ID3D12PipelineState TubeFieldRestirClearTiles,
|
||||
ID3D12PipelineState TubeFieldRestirClearReservoirs,
|
||||
ID3D12PipelineState TubeFieldRestirBinSegments,
|
||||
ID3D12PipelineState TubeFieldRestirInitial,
|
||||
ID3D12PipelineState TubeFieldRestirTemporal,
|
||||
ID3D12PipelineState TubeFieldRestirSpatialResolve,
|
||||
ID3D12PipelineState TubeFieldRender,
|
||||
ID3D12PipelineState FieldReservoirResolve,
|
||||
IReadOnlyList<ID3D12PipelineState> SdfProxies,
|
||||
|
|
@ -5528,12 +5201,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
FieldReservoirResolve.Dispose();
|
||||
FractalRadiosityReservoir.Dispose();
|
||||
TubeFieldRender.Dispose();
|
||||
TubeFieldRestirSpatialResolve.Dispose();
|
||||
TubeFieldRestirTemporal.Dispose();
|
||||
TubeFieldRestirInitial.Dispose();
|
||||
TubeFieldRestirBinSegments.Dispose();
|
||||
TubeFieldRestirClearReservoirs.Dispose();
|
||||
TubeFieldRestirClearTiles.Dispose();
|
||||
TubeFieldCompute.Dispose();
|
||||
FractalPbrReservoir.Dispose();
|
||||
FractalSdfReservoir.Dispose();
|
||||
|
|
|
|||
|
|
@ -24,18 +24,6 @@ struct TubeFieldSegment
|
|||
float4 tubeData;
|
||||
};
|
||||
|
||||
struct TubeFieldColumn
|
||||
{
|
||||
float4 shape;
|
||||
float4 columns;
|
||||
float4 amplitude;
|
||||
float4 material;
|
||||
float4 dispatchDraw;
|
||||
float4 originField;
|
||||
float4 axisStepEmission;
|
||||
float4 columnStep;
|
||||
};
|
||||
|
||||
struct FieldReservoirCandidate
|
||||
{
|
||||
float4 colorTravel;
|
||||
|
|
@ -44,17 +32,6 @@ struct FieldReservoirCandidate
|
|||
float4 reservoirGuide;
|
||||
};
|
||||
|
||||
struct TubeFieldReservoir
|
||||
{
|
||||
float4 colorTravel;
|
||||
float4 metadata;
|
||||
float4 control;
|
||||
float4 reservoirGuide;
|
||||
float4 statistics;
|
||||
float4 sampleData;
|
||||
uint4 sampleKey;
|
||||
};
|
||||
|
||||
cbuffer AquariumFrame : register(b0)
|
||||
{
|
||||
float2 resolution;
|
||||
|
|
@ -108,25 +85,7 @@ RWStructuredBuffer<TubeFieldVertex> TubeFieldVertices : register(u10);
|
|||
RWStructuredBuffer<uint> TubeFieldIndices : register(u11);
|
||||
RWStructuredBuffer<uint> TubeFieldStats : register(u12);
|
||||
RWStructuredBuffer<uint> TubeFieldDrawArguments : register(u13);
|
||||
RWStructuredBuffer<TubeFieldColumn> TubeFieldColumns : register(u16);
|
||||
|
||||
StructuredBuffer<TubeFieldColumn> RestirColumns : register(t46);
|
||||
StructuredBuffer<uint> RestirTileSegmentsRead : register(t47);
|
||||
StructuredBuffer<TubeFieldReservoir> RestirPreviousReservoirs : register(t48);
|
||||
StructuredBuffer<TubeFieldReservoir> RestirReadReservoirs : register(t49);
|
||||
StructuredBuffer<uint> RestirTileCountsRead : register(t50);
|
||||
RWStructuredBuffer<uint> RestirTileCounts : register(u17);
|
||||
RWStructuredBuffer<uint> RestirTileSegments : register(u18);
|
||||
RWStructuredBuffer<TubeFieldReservoir> RestirInitialReservoirs : register(u19);
|
||||
RWStructuredBuffer<TubeFieldReservoir> RestirWriteReservoirs : register(u20);
|
||||
RWStructuredBuffer<FieldReservoirCandidate> RestirFieldReservoirCandidates : register(u21);
|
||||
|
||||
static const uint TubeFieldRestirTileSize = 16u;
|
||||
static const uint TubeFieldRestirMaxTileSegments = 128u;
|
||||
static const uint TubeFieldRestirSpatialTileLanes = 16u;
|
||||
static const uint TubeFieldRestirDepthLanesPerSpatialLane = 4u;
|
||||
static const uint TubeFieldRestirResidentTileCandidates = TubeFieldRestirSpatialTileLanes * TubeFieldRestirDepthLanesPerSpatialLane;
|
||||
static const uint TubeFieldRestirSpatialCandidateCount = 4u;
|
||||
RWStructuredBuffer<TubeFieldSegment> TubeFieldSegments : register(u16);
|
||||
static const uint FieldReservoirSlotsPerPixel = 4u;
|
||||
|
||||
RWStructuredBuffer<FieldReservoirCandidate> FieldReservoirCandidates : register(u14);
|
||||
|
|
@ -158,25 +117,6 @@ uint SampleAddress(uint logicalColumn, uint sampleIndex)
|
|||
return (physicalColumn * width + min(sampleIndex, width - 1u)) * strideBytes;
|
||||
}
|
||||
|
||||
uint ColumnSampleAddress(TubeFieldColumn column, uint sampleIndex)
|
||||
{
|
||||
uint width = max((uint)round(column.shape.x), 1u);
|
||||
uint height = max((uint)round(column.shape.y), 1u);
|
||||
uint firstColumn = (uint)max(round(column.shape.w), 0.0);
|
||||
uint columnStride = max((uint)round(column.columns.y), 1u);
|
||||
uint rollingModulo = (uint)max(round(column.columns.z), 0.0);
|
||||
int rollingOffset = (int)round(column.columns.w);
|
||||
uint logicalColumn = (uint)max(round(column.dispatchDraw.x), 0.0);
|
||||
uint physicalColumn = firstColumn + logicalColumn * columnStride;
|
||||
if (rollingModulo > 0u)
|
||||
{
|
||||
physicalColumn = PositiveModulo((int)physicalColumn + rollingOffset, rollingModulo);
|
||||
}
|
||||
|
||||
physicalColumn = min(physicalColumn, height - 1u);
|
||||
uint strideBytes = max((uint)round(column.shape.z), 4u);
|
||||
return (physicalColumn * width + min(sampleIndex, width - 1u)) * strideBytes;
|
||||
}
|
||||
|
||||
float RawSample(uint logicalColumn, int sampleIndex)
|
||||
{
|
||||
|
|
@ -185,12 +125,6 @@ float RawSample(uint logicalColumn, int sampleIndex)
|
|||
return asfloat(TubeFieldSamples.Load(SampleAddress(logicalColumn, clamped)));
|
||||
}
|
||||
|
||||
float RawColumnSample(TubeFieldColumn column, int sampleIndex)
|
||||
{
|
||||
uint width = max((uint)round(column.shape.x), 1u);
|
||||
uint clamped = (uint)clamp(sampleIndex, 0, (int)width - 1);
|
||||
return asfloat(TubeFieldSamples.Load(ColumnSampleAddress(column, clamped)));
|
||||
}
|
||||
|
||||
float FilteredSample(uint logicalColumn, float x)
|
||||
{
|
||||
|
|
@ -203,16 +137,6 @@ float FilteredSample(uint logicalColumn, float x)
|
|||
return (s0 + s4 + 4.0 * (s1 + s3) + 6.0 * s2) / 16.0;
|
||||
}
|
||||
|
||||
float FilteredColumnSample(TubeFieldColumn column, float x)
|
||||
{
|
||||
int center = (int)floor(x + 0.5);
|
||||
float s0 = RawColumnSample(column, center - 2);
|
||||
float s1 = RawColumnSample(column, center - 1);
|
||||
float s2 = RawColumnSample(column, center);
|
||||
float s3 = RawColumnSample(column, center + 1);
|
||||
float s4 = RawColumnSample(column, center + 2);
|
||||
return (s0 + s4 + 4.0 * (s1 + s3) + 6.0 * s2) / 16.0;
|
||||
}
|
||||
|
||||
float NormalizedSample(uint logicalColumn, float x)
|
||||
{
|
||||
|
|
@ -220,11 +144,6 @@ float NormalizedSample(uint logicalColumn, float x)
|
|||
return saturate((value - tubeAmplitude.z) / max(tubeAmplitude.w - tubeAmplitude.z, 0.0001));
|
||||
}
|
||||
|
||||
float NormalizedColumnSample(TubeFieldColumn column, float x)
|
||||
{
|
||||
float value = FilteredColumnSample(column, x);
|
||||
return saturate((value - column.amplitude.z) / max(column.amplitude.w - column.amplitude.z, 0.0001));
|
||||
}
|
||||
|
||||
float Catmull(float p0, float p1, float p2, float p3, float t)
|
||||
{
|
||||
|
|
@ -247,26 +166,12 @@ float SampleCurve(uint logicalColumn, float x)
|
|||
return saturate(Catmull(p0, p1, p2, p3, t));
|
||||
}
|
||||
|
||||
float SampleColumnCurve(TubeFieldColumn column, float x)
|
||||
{
|
||||
int i1 = (int)floor(x);
|
||||
float t = frac(x);
|
||||
float p0 = NormalizedColumnSample(column, (float)(i1 - 1));
|
||||
float p1 = NormalizedColumnSample(column, (float)i1);
|
||||
float p2 = NormalizedColumnSample(column, (float)(i1 + 1));
|
||||
float p3 = NormalizedColumnSample(column, (float)(i1 + 2));
|
||||
return saturate(Catmull(p0, p1, p2, p3, t));
|
||||
}
|
||||
|
||||
float SampleAmplitudeCurve(uint logicalColumn, float x)
|
||||
{
|
||||
return pow(SampleCurve(logicalColumn, x), max(tubeAmplitude.x, 0.0001));
|
||||
}
|
||||
|
||||
float SampleColumnAmplitudeCurve(TubeFieldColumn column, float x)
|
||||
{
|
||||
return pow(SampleColumnCurve(column, x), max(column.amplitude.x, 0.0001));
|
||||
}
|
||||
|
||||
float3 TubePoint(uint logicalColumn, float x)
|
||||
{
|
||||
|
|
@ -277,13 +182,6 @@ float3 TubePoint(uint logicalColumn, float x)
|
|||
float3(0.0, value * tubeAmplitude.y, 0.0);
|
||||
}
|
||||
|
||||
float3 TubeColumnPoint(TubeFieldColumn column, float x)
|
||||
{
|
||||
float value = SampleColumnAmplitudeCurve(column, x);
|
||||
return column.originField.xyz +
|
||||
column.axisStepEmission.xyz * x +
|
||||
float3(0.0, value * column.amplitude.y, 0.0);
|
||||
}
|
||||
|
||||
TubeFieldVertex MakeTubeVertex(float3 position, float3 previous, float3 start, float3 end, float3 next, float side, float endpointT, float capSign, float v0, float v1, float3 rampColor, uint logicalColumn, float x0, float x1)
|
||||
{
|
||||
|
|
@ -322,35 +220,60 @@ TubeFieldSegment MakeTubeSegment(float3 previous, float3 start, float3 end, floa
|
|||
[numthreads(256, 1, 1)]
|
||||
void D3D12TubeFieldExpandCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint localColumn = dispatchThreadId.x;
|
||||
uint dispatchColumns = (uint)round(tubeDispatch.w);
|
||||
if (localColumn == 0u)
|
||||
uint localSegment = dispatchThreadId.x;
|
||||
uint dispatchSegments = (uint)round(tubeDispatch.w);
|
||||
if (localSegment == 0u)
|
||||
{
|
||||
uint argumentBase = (uint)round(tubeDraw.x);
|
||||
TubeFieldDrawArguments[argumentBase + 0u] = 0u;
|
||||
TubeFieldDrawArguments[argumentBase + 0u] = dispatchSegments * 6u;
|
||||
TubeFieldDrawArguments[argumentBase + 1u] = 1u;
|
||||
TubeFieldDrawArguments[argumentBase + 2u] = (uint)round(tubeDraw.y);
|
||||
TubeFieldDrawArguments[argumentBase + 3u] = 0u;
|
||||
TubeFieldDrawArguments[argumentBase + 4u] = 0u;
|
||||
}
|
||||
|
||||
if (localColumn >= dispatchColumns)
|
||||
if (localSegment >= dispatchSegments)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint globalColumn = (uint)round(tubeDispatch.z) + localColumn;
|
||||
TubeFieldColumn column;
|
||||
column.shape = tubeShape;
|
||||
column.columns = tubeColumns;
|
||||
column.amplitude = tubeAmplitude;
|
||||
column.material = tubeMaterial;
|
||||
column.dispatchDraw = float4((float)localColumn, max(tubeDispatch.x, 0.0), tubeDraw.z, tubeDispatch.y);
|
||||
column.originField = float4(tubeOrigin + tubeColumnStep * (float)localColumn, tubeDraw.z);
|
||||
column.axisStepEmission = float4(tubeAxisStep, max(tubeDispatch.x, 0.0));
|
||||
column.columnStep = float4(tubeColumnStep, 0.0);
|
||||
TubeFieldColumns[globalColumn] = column;
|
||||
TubeFieldStats[0] = globalColumn + 1u;
|
||||
uint width = max((uint)round(tubeShape.x), 2u);
|
||||
uint subdivisions = max((uint)round(tubeDispatch.y), 1u);
|
||||
uint piecesPerColumn = (width - 1u) * subdivisions;
|
||||
uint logicalColumn = localSegment / max(piecesPerColumn, 1u);
|
||||
uint pieceInColumn = localSegment % max(piecesPerColumn, 1u);
|
||||
uint sourceSegment = pieceInColumn / subdivisions;
|
||||
uint subdivision = pieceInColumn % subdivisions;
|
||||
float t0 = (float)subdivision / (float)subdivisions;
|
||||
float t1 = (float)(subdivision + 1u) / (float)subdivisions;
|
||||
float x0 = (float)sourceSegment + t0;
|
||||
float x1 = (float)sourceSegment + t1;
|
||||
float xPrev = max(0.0, x0 - 1.0 / (float)subdivisions);
|
||||
float xNext = min((float)(width - 1u), x1 + 1.0 / (float)subdivisions);
|
||||
float v0 = SampleCurve(logicalColumn, x0);
|
||||
float v1 = SampleCurve(logicalColumn, x1);
|
||||
float3 rampColor0 = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(saturate(v0), 0.5), 0.0).rgb;
|
||||
float3 rampColor1 = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(saturate(v1), 0.5), 0.0).rgb;
|
||||
float3 previous = TubePoint(logicalColumn, xPrev);
|
||||
float3 start = TubePoint(logicalColumn, x0);
|
||||
float3 end = TubePoint(logicalColumn, x1);
|
||||
float3 next = TubePoint(logicalColumn, xNext);
|
||||
|
||||
uint globalSegment = (uint)round(tubeDispatch.z) + localSegment;
|
||||
uint vertexBase = globalSegment * 4u;
|
||||
uint indexBase = globalSegment * 6u;
|
||||
TubeFieldSegments[globalSegment] = MakeTubeSegment(previous, start, end, next, v0, v1, rampColor0, rampColor1, logicalColumn, x0, x1);
|
||||
TubeFieldVertices[vertexBase + 0u] = MakeTubeVertex(start, previous, start, end, next, -1.0, 0.0, -1.0, v0, v1, rampColor0, logicalColumn, x0, x1);
|
||||
TubeFieldVertices[vertexBase + 1u] = MakeTubeVertex(start, previous, start, end, next, 1.0, 0.0, -1.0, v0, v1, rampColor0, logicalColumn, x0, x1);
|
||||
TubeFieldVertices[vertexBase + 2u] = MakeTubeVertex(end, previous, start, end, next, -1.0, 1.0, 1.0, v0, v1, rampColor1, logicalColumn, x0, x1);
|
||||
TubeFieldVertices[vertexBase + 3u] = MakeTubeVertex(end, previous, start, end, next, 1.0, 1.0, 1.0, v0, v1, rampColor1, logicalColumn, x0, x1);
|
||||
TubeFieldIndices[indexBase + 0u] = vertexBase + 0u;
|
||||
TubeFieldIndices[indexBase + 1u] = vertexBase + 1u;
|
||||
TubeFieldIndices[indexBase + 2u] = vertexBase + 2u;
|
||||
TubeFieldIndices[indexBase + 3u] = vertexBase + 2u;
|
||||
TubeFieldIndices[indexBase + 4u] = vertexBase + 1u;
|
||||
TubeFieldIndices[indexBase + 5u] = vertexBase + 3u;
|
||||
TubeFieldStats[0] = globalSegment + 1u;
|
||||
}
|
||||
|
||||
struct TubeFieldVertexIn
|
||||
|
|
@ -595,755 +518,6 @@ void nearestTubeDistancePx(
|
|||
}
|
||||
}
|
||||
|
||||
uint restirPixelCount()
|
||||
{
|
||||
return (uint)max(resolution.x, 1.0) * (uint)max(resolution.y, 1.0);
|
||||
}
|
||||
|
||||
uint2 restirTileDimensions()
|
||||
{
|
||||
return ((uint2)max(resolution, float2(1.0, 1.0)) + TubeFieldRestirTileSize - 1u) / TubeFieldRestirTileSize;
|
||||
}
|
||||
|
||||
uint wangHash(uint value)
|
||||
{
|
||||
value = (value ^ 61u) ^ (value >> 16);
|
||||
value *= 9u;
|
||||
value = value ^ (value >> 4);
|
||||
value *= 0x27d4eb2du;
|
||||
value = value ^ (value >> 15);
|
||||
return value;
|
||||
}
|
||||
|
||||
float restirRandom01(uint seed)
|
||||
{
|
||||
return (float)(wangHash(seed) & 0x00ffffffu) / 16777216.0;
|
||||
}
|
||||
|
||||
uint restirTileCandidateSlot(uint pixelIndex, uint tileIndex, uint count, uint sampleIndex, uint salt)
|
||||
{
|
||||
if (count <= 1u)
|
||||
{
|
||||
return 0u;
|
||||
}
|
||||
|
||||
uint seed = pixelIndex * 2246822519u ^
|
||||
tileIndex * 3266489917u ^
|
||||
sampleIndex * 668265263u ^
|
||||
(uint)frameIndex * 374761393u ^
|
||||
salt;
|
||||
return wangHash(seed) % count;
|
||||
}
|
||||
|
||||
uint packRestirTileSegment(uint segmentIndex, float travel)
|
||||
{
|
||||
uint depthKey = (uint)round(saturate(travel / max(farDistance, 0.0001)) * 65534.0);
|
||||
return (depthKey << 16) | (segmentIndex & 0xffffu);
|
||||
}
|
||||
|
||||
bool unpackRestirTileSegment(uint packed, out uint segmentIndex)
|
||||
{
|
||||
segmentIndex = packed & 0xffffu;
|
||||
return packed != 0xffffffffu;
|
||||
}
|
||||
|
||||
void insertRestirTileSegment(uint tileIndex, uint spatialLane, uint packed)
|
||||
{
|
||||
uint candidate = packed;
|
||||
[unroll]
|
||||
for (uint depthLane = 0u; depthLane < TubeFieldRestirDepthLanesPerSpatialLane; depthLane++)
|
||||
{
|
||||
uint slotIndex = tileIndex * TubeFieldRestirMaxTileSegments +
|
||||
spatialLane * TubeFieldRestirDepthLanesPerSpatialLane +
|
||||
depthLane;
|
||||
uint previous;
|
||||
InterlockedMin(RestirTileSegments[slotIndex], candidate, previous);
|
||||
if (candidate == previous)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (candidate > previous)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (previous == 0xffffffffu)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
candidate = previous;
|
||||
}
|
||||
}
|
||||
|
||||
bool finite1(float value)
|
||||
{
|
||||
return !isnan(value) && !isinf(value);
|
||||
}
|
||||
|
||||
bool finite2(float2 value)
|
||||
{
|
||||
return all(!isnan(value)) && all(!isinf(value));
|
||||
}
|
||||
|
||||
bool finite3(float3 value)
|
||||
{
|
||||
return all(!isnan(value)) && all(!isinf(value));
|
||||
}
|
||||
|
||||
bool finite4(float4 value)
|
||||
{
|
||||
return all(!isnan(value)) && all(!isinf(value));
|
||||
}
|
||||
|
||||
TubeFieldReservoir emptyTubeFieldReservoir()
|
||||
{
|
||||
TubeFieldReservoir reservoir;
|
||||
reservoir.colorTravel = float4(0.0, 0.0, 0.0, farDistance + 1.0);
|
||||
reservoir.metadata = 0.0;
|
||||
reservoir.control = 0.0;
|
||||
reservoir.reservoirGuide = float4(1.0, 0.0, 0.0, 0.0);
|
||||
reservoir.statistics = 0.0;
|
||||
reservoir.sampleData = 0.0;
|
||||
reservoir.sampleKey = 0xffffffffu;
|
||||
return reservoir;
|
||||
}
|
||||
|
||||
bool restirReservoirValid(TubeFieldReservoir reservoir)
|
||||
{
|
||||
uint segmentBase = (uint)round(tubeDispatch.z);
|
||||
uint dispatchSegments = (uint)round(tubeDispatch.w);
|
||||
return reservoir.sampleKey.x != 0xffffffffu &&
|
||||
reservoir.sampleKey.x >= segmentBase &&
|
||||
reservoir.sampleKey.x < segmentBase + dispatchSegments &&
|
||||
reservoir.statistics.x > 0.0 &&
|
||||
reservoir.statistics.y > 0.0 &&
|
||||
reservoir.metadata.x > 0.5 &&
|
||||
reservoir.colorTravel.w <= farDistance;
|
||||
}
|
||||
|
||||
void restirStreamCandidate(
|
||||
inout TubeFieldReservoir reservoir,
|
||||
TubeFieldReservoir candidate,
|
||||
float targetPdf,
|
||||
float invSourcePdf,
|
||||
float randomValue)
|
||||
{
|
||||
if (!restirReservoirValid(candidate) || targetPdf <= 0.0 || invSourcePdf <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float risWeight = targetPdf * invSourcePdf;
|
||||
reservoir.statistics.x += risWeight;
|
||||
reservoir.statistics.z += 1.0;
|
||||
if (randomValue * max(reservoir.statistics.x, 0.000001) < risWeight)
|
||||
{
|
||||
reservoir.colorTravel = candidate.colorTravel;
|
||||
reservoir.metadata = candidate.metadata;
|
||||
reservoir.control = candidate.control;
|
||||
reservoir.reservoirGuide = candidate.reservoirGuide;
|
||||
reservoir.statistics.y = targetPdf;
|
||||
reservoir.sampleData = candidate.sampleData;
|
||||
reservoir.sampleKey = candidate.sampleKey;
|
||||
}
|
||||
}
|
||||
|
||||
void restirCombineReservoir(
|
||||
inout TubeFieldReservoir reservoir,
|
||||
TubeFieldReservoir candidate,
|
||||
float targetPdf,
|
||||
float randomValue)
|
||||
{
|
||||
if (!restirReservoirValid(candidate) || targetPdf <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float sourceM = max(candidate.statistics.z, 1.0);
|
||||
float risWeight = targetPdf * max(candidate.statistics.x, 0.0) * sourceM;
|
||||
reservoir.statistics.x += risWeight;
|
||||
reservoir.statistics.z += sourceM;
|
||||
if (randomValue * max(reservoir.statistics.x, 0.000001) < risWeight)
|
||||
{
|
||||
reservoir.colorTravel = candidate.colorTravel;
|
||||
reservoir.metadata = candidate.metadata;
|
||||
reservoir.control = candidate.control;
|
||||
reservoir.reservoirGuide = candidate.reservoirGuide;
|
||||
reservoir.statistics.y = targetPdf;
|
||||
reservoir.sampleData = candidate.sampleData;
|
||||
reservoir.sampleKey = candidate.sampleKey;
|
||||
}
|
||||
}
|
||||
|
||||
void restirFinalize(inout TubeFieldReservoir reservoir)
|
||||
{
|
||||
float denominator = reservoir.statistics.y * max(reservoir.statistics.z, 1.0);
|
||||
reservoir.statistics.w = denominator > 0.0 ? reservoir.statistics.x / denominator : 0.0;
|
||||
}
|
||||
|
||||
bool restirSameField(TubeFieldReservoir a, TubeFieldReservoir b)
|
||||
{
|
||||
return abs(a.metadata.x - b.metadata.x) < 0.001;
|
||||
}
|
||||
|
||||
bool restirCompatibleOpaqueShift(TubeFieldReservoir center, TubeFieldReservoir shifted)
|
||||
{
|
||||
if (!restirReservoirValid(center) || !restirReservoirValid(shifted) || !restirSameField(center, shifted))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float centerCoverage = saturate(center.control.x);
|
||||
float shiftedCoverage = saturate(shifted.control.x);
|
||||
if (shiftedCoverage <= 0.004)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float depthTolerance = max(0.025, center.control.z * 0.25);
|
||||
bool sameSurface = abs(center.colorTravel.w - shifted.colorTravel.w) <= depthTolerance;
|
||||
bool closerSurface = shifted.colorTravel.w <= center.colorTravel.w + depthTolerance;
|
||||
return sameSurface || (closerSurface && shiftedCoverage >= centerCoverage * 0.25);
|
||||
}
|
||||
|
||||
float4 projectWorldToPixelAndDepth(float3 worldPoint)
|
||||
{
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(cameraPosition, cameraTarget, forward, right, up);
|
||||
float3 view = worldToCameraSpace(worldPoint, right, up, forward);
|
||||
float4 projected = projectCameraSpace(view);
|
||||
return float4(ndcToPixel(projected.xy), projected.z, view.z);
|
||||
}
|
||||
|
||||
bool evaluateTubeFieldColumnCandidate(uint columnIndex, float2 pixel, out TubeFieldReservoir candidate, out float targetPdf)
|
||||
{
|
||||
candidate = emptyTubeFieldReservoir();
|
||||
targetPdf = 0.0;
|
||||
TubeFieldColumn column = RestirColumns[columnIndex];
|
||||
uint width = max((uint)round(column.shape.x), 2u);
|
||||
float xMax = (float)(width - 1u);
|
||||
float4 startProjected = projectWorldToPixelAndDepth(TubeColumnPoint(column, 0.0));
|
||||
float4 endProjected = projectWorldToPixelAndDepth(TubeColumnPoint(column, xMax));
|
||||
if (!finite4(startProjected) || !finite4(endProjected))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float sdf;
|
||||
float closestT;
|
||||
float radiusPx;
|
||||
float2 normalPx;
|
||||
float2 axisPx = endProjected.xy - startProjected.xy;
|
||||
float axisLength2 = max(dot(axisPx, axisPx), 0.0001);
|
||||
float xCenter = saturate(dot(pixel - startProjected.xy, axisPx) / axisLength2) * xMax;
|
||||
float sampleStep = max(0.5, xMax / 32.0);
|
||||
float x0 = clamp(xCenter - sampleStep, 0.0, xMax);
|
||||
float x1 = clamp(xCenter + sampleStep, 0.0, xMax);
|
||||
float v0 = SampleColumnCurve(column, x0);
|
||||
float v1 = SampleColumnCurve(column, x1);
|
||||
float3 p0 = TubeColumnPoint(column, x0);
|
||||
float3 p1 = TubeColumnPoint(column, x1);
|
||||
float4 projected0 = projectWorldToPixelAndDepth(p0);
|
||||
float4 projected1 = projectWorldToPixelAndDepth(p1);
|
||||
if (!finite4(projected0) || !finite4(projected1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float r0 = splineRadiusToPixels(max(column.material.x + v0 * column.material.y, 0.0001), projected0.w);
|
||||
float r1 = splineRadiusToPixels(max(column.material.x + v1 * column.material.y, 0.0001), projected1.w);
|
||||
float localT;
|
||||
capsuleDistancePx(pixel, projected0.xy, projected1.xy, r0, r1, sdf, localT, radiusPx, normalPx);
|
||||
closestT = saturate(lerp(x0, x1, localT) / max(xMax, 0.0001));
|
||||
|
||||
float aa = max(0.75, radiusPx * max(column.material.w, 0.0));
|
||||
float coverage = 1.0 - smoothstep(0.0, aa, sdf);
|
||||
float alpha = saturate(column.material.z * coverage);
|
||||
if (!finite1(sdf) || !finite1(radiusPx) || !finite2(normalPx) || alpha <= 0.004)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float x = closestT * xMax;
|
||||
float value = SampleColumnCurve(column, x);
|
||||
float3 emissionColor = TubeFieldRamp.SampleLevel(TubeFieldRampSampler, float2(saturate(value), 0.5), 0.0).rgb;
|
||||
float3 ray = rayDirectionForPixel(pixel, float2(0.0, 0.0), cameraPosition, cameraTarget);
|
||||
float3 forward;
|
||||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(cameraPosition, cameraTarget, forward, right, up);
|
||||
float rimBlend = saturate((sdf + radiusPx) / max(radiusPx, 0.0001));
|
||||
float frontBlend = sqrt(saturate(1.0 - rimBlend * rimBlend));
|
||||
float3 tubeNormal = normalize(((right * normalPx.x) - (up * normalPx.y)) * rimBlend - ray * frontBlend);
|
||||
float normalFacing = saturate(-dot(ray, tubeNormal));
|
||||
float glowFacing = pow(normalFacing, 4.0);
|
||||
float alphaFacing = 1.0;
|
||||
float claimCoverage = saturate(alpha * alphaFacing);
|
||||
if (claimCoverage <= 0.004)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float emission = value * value * max(column.dispatchDraw.y, 0.0);
|
||||
float3 color = emissionColor * emission * glowFacing * claimCoverage;
|
||||
float3 worldPosition = TubeColumnPoint(column, x);
|
||||
float travel = distance(cameraPosition, worldPosition);
|
||||
if (!finite3(color) || !finite3(worldPosition) || !finite1(travel) || !finite3(tubeNormal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
candidate.colorTravel = float4(color, min(travel, farDistance + 1.0));
|
||||
candidate.metadata = float4(column.originField.w, tubeNormal);
|
||||
candidate.control = float4(claimCoverage, coverage, saturate(radiusPx / 32.0), value);
|
||||
candidate.reservoirGuide = float4(claimCoverage, 0.0, coverage, value);
|
||||
candidate.statistics = float4(1.0, 1.0, 1.0, 0.0);
|
||||
candidate.sampleData = float4(worldPosition, closestT);
|
||||
candidate.sampleKey = uint4(columnIndex, 0u, 0u, 0u);
|
||||
targetPdf = max(0.0001, claimCoverage * (0.05 + dot(color, float3(0.2126, 0.7152, 0.0722))));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool shiftTubeFieldReservoirToPixel(
|
||||
TubeFieldReservoir source,
|
||||
float2 pixel,
|
||||
out TubeFieldReservoir shifted,
|
||||
out float shiftedTargetPdf)
|
||||
{
|
||||
shifted = emptyTubeFieldReservoir();
|
||||
shiftedTargetPdf = 0.0;
|
||||
if (!restirReservoirValid(source))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!evaluateTubeFieldColumnCandidate(source.sampleKey.x, pixel + 0.5 + jitterPixels, shifted, shiftedTargetPdf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
shifted.statistics = source.statistics;
|
||||
shifted.statistics.y = shiftedTargetPdf;
|
||||
shifted.reservoirGuide.y = max(source.reservoirGuide.y, shifted.reservoirGuide.y);
|
||||
return restirReservoirValid(shifted);
|
||||
}
|
||||
|
||||
void writeFieldReservoirCandidateSlot(uint baseIndex, uint slot, TubeFieldReservoir reservoir)
|
||||
{
|
||||
if (slot >= FieldReservoirSlotsPerPixel || !restirReservoirValid(reservoir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RestirFieldReservoirCandidates[baseIndex + slot].colorTravel = reservoir.colorTravel;
|
||||
RestirFieldReservoirCandidates[baseIndex + slot].metadata = reservoir.metadata;
|
||||
RestirFieldReservoirCandidates[baseIndex + slot].control = reservoir.control;
|
||||
RestirFieldReservoirCandidates[baseIndex + slot].reservoirGuide = reservoir.reservoirGuide;
|
||||
}
|
||||
|
||||
bool reservoirDuplicateSample(TubeFieldReservoir a, TubeFieldReservoir b)
|
||||
{
|
||||
return restirReservoirValid(a) &&
|
||||
restirReservoirValid(b) &&
|
||||
a.sampleKey.x == b.sampleKey.x &&
|
||||
abs(a.sampleData.w - b.sampleData.w) < 0.002;
|
||||
}
|
||||
|
||||
float tubeFieldReservoirPriority(TubeFieldReservoir reservoir)
|
||||
{
|
||||
if (!restirReservoirValid(reservoir))
|
||||
{
|
||||
return 1.0e20;
|
||||
}
|
||||
|
||||
return reservoir.colorTravel.w - saturate(reservoir.control.x) * 0.025;
|
||||
}
|
||||
|
||||
void insertTubeFieldExportCandidate(
|
||||
TubeFieldReservoir candidate,
|
||||
inout TubeFieldReservoir slot0,
|
||||
inout TubeFieldReservoir slot1,
|
||||
inout TubeFieldReservoir slot2,
|
||||
inout TubeFieldReservoir slot3,
|
||||
inout float priority0,
|
||||
inout float priority1,
|
||||
inout float priority2,
|
||||
inout float priority3)
|
||||
{
|
||||
float priority = tubeFieldReservoirPriority(candidate);
|
||||
if (priority >= 1.0e19 ||
|
||||
reservoirDuplicateSample(candidate, slot0) ||
|
||||
reservoirDuplicateSample(candidate, slot1) ||
|
||||
reservoirDuplicateSample(candidate, slot2) ||
|
||||
reservoirDuplicateSample(candidate, slot3))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (priority < priority0)
|
||||
{
|
||||
slot3 = slot2;
|
||||
priority3 = priority2;
|
||||
slot2 = slot1;
|
||||
priority2 = priority1;
|
||||
slot1 = slot0;
|
||||
priority1 = priority0;
|
||||
slot0 = candidate;
|
||||
priority0 = priority;
|
||||
}
|
||||
else if (priority < priority1)
|
||||
{
|
||||
slot3 = slot2;
|
||||
priority3 = priority2;
|
||||
slot2 = slot1;
|
||||
priority2 = priority1;
|
||||
slot1 = candidate;
|
||||
priority1 = priority;
|
||||
}
|
||||
else if (priority < priority2)
|
||||
{
|
||||
slot3 = slot2;
|
||||
priority3 = priority2;
|
||||
slot2 = candidate;
|
||||
priority2 = priority;
|
||||
}
|
||||
else if (priority < priority3)
|
||||
{
|
||||
slot3 = candidate;
|
||||
priority3 = priority;
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void D3D12TubeFieldRestirClearTilesCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 tiles = restirTileDimensions();
|
||||
uint tileCount = tiles.x * tiles.y;
|
||||
if (dispatchThreadId.x < tileCount)
|
||||
{
|
||||
RestirTileCounts[dispatchThreadId.x] = 0u;
|
||||
}
|
||||
|
||||
uint tileSegmentCount = tileCount * TubeFieldRestirMaxTileSegments;
|
||||
if (dispatchThreadId.x < tileSegmentCount)
|
||||
{
|
||||
RestirTileSegments[dispatchThreadId.x] = 0xffffffffu;
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void D3D12TubeFieldRestirClearReservoirsCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint pixelCount = restirPixelCount();
|
||||
if (dispatchThreadId.x < pixelCount)
|
||||
{
|
||||
RestirInitialReservoirs[dispatchThreadId.x] = emptyTubeFieldReservoir();
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void D3D12TubeFieldRestirBinSegmentsCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint localColumn = dispatchThreadId.x;
|
||||
uint dispatchColumns = (uint)round(tubeDispatch.w);
|
||||
if (localColumn >= dispatchColumns)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint columnIndex = (uint)round(tubeDispatch.z) + localColumn;
|
||||
TubeFieldColumn column = RestirColumns[columnIndex];
|
||||
uint width = max((uint)round(column.shape.x), 2u);
|
||||
float xMax = (float)(width - 1u);
|
||||
float4 startProjected = projectWorldToPixelAndDepth(TubeColumnPoint(column, 0.0));
|
||||
float4 endProjected = projectWorldToPixelAndDepth(TubeColumnPoint(column, xMax));
|
||||
if (!finite4(startProjected) || !finite4(endProjected))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (startProjected.w <= 0.0 && endProjected.w <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float startValue = SampleColumnCurve(column, 0.0);
|
||||
float endValue = SampleColumnCurve(column, xMax);
|
||||
float radiusPx = max(
|
||||
splineRadiusToPixels(max(column.material.x + startValue * column.material.y, 0.0001), startProjected.w),
|
||||
splineRadiusToPixels(max(column.material.x + endValue * column.material.y, 0.0001), endProjected.w));
|
||||
float2 minProjected = min(startProjected.xy, endProjected.xy);
|
||||
float2 maxProjected = max(startProjected.xy, endProjected.xy);
|
||||
radiusPx = min(radiusPx, 256.0);
|
||||
float segmentTravel = min(startProjected.w, endProjected.w);
|
||||
if (!finite1(radiusPx) || !finite1(segmentTravel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float2 minPx = floor((minProjected - radiusPx * 1.5) / TubeFieldRestirTileSize);
|
||||
float2 maxPx = floor((maxProjected + radiusPx * 1.5) / TubeFieldRestirTileSize);
|
||||
if (!finite2(minPx) || !finite2(maxPx))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint2 tileDims = restirTileDimensions();
|
||||
float2 tileLimit = (float2)tileDims;
|
||||
if (maxPx.x < 0.0 || maxPx.y < 0.0 || minPx.x >= tileLimit.x || minPx.y >= tileLimit.y)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint2 tileMin = min((uint2)max(minPx, float2(0.0, 0.0)), tileDims - 1u);
|
||||
uint2 tileMax = min((uint2)max(maxPx, float2(0.0, 0.0)), tileDims - 1u);
|
||||
uint2 tileSpan = tileMax - tileMin + 1u;
|
||||
if (tileSpan.x * tileSpan.y > 256u)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint tileY = tileMin.y; tileY <= tileMax.y; tileY++)
|
||||
{
|
||||
for (uint tileX = tileMin.x; tileX <= tileMax.x; tileX++)
|
||||
{
|
||||
uint tileIndex = tileY * tileDims.x + tileX;
|
||||
uint slot;
|
||||
InterlockedAdd(RestirTileCounts[tileIndex], 1u, slot);
|
||||
uint packed = packRestirTileSegment(columnIndex, segmentTravel);
|
||||
[unroll(4)]
|
||||
for (uint laneY = 0u; laneY < 4u; laneY++)
|
||||
{
|
||||
[unroll(4)]
|
||||
for (uint laneX = 0u; laneX < 4u; laneX++)
|
||||
{
|
||||
insertRestirTileSegment(tileIndex, laneY * 4u + laneX, packed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void D3D12TubeFieldRestirInitialCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 pixel = dispatchThreadId.xy;
|
||||
uint2 dimensions = (uint2)max(resolution, float2(1.0, 1.0));
|
||||
if (any(pixel >= dimensions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint pixelIndex = pixel.y * dimensions.x + pixel.x;
|
||||
uint2 tileDims = restirTileDimensions();
|
||||
uint2 tile = min(pixel / TubeFieldRestirTileSize, tileDims - 1u);
|
||||
uint tileIndex = tile.y * tileDims.x + tile.x;
|
||||
TubeFieldReservoir reservoir = RestirInitialReservoirs[pixelIndex];
|
||||
uint touchedSegmentCount = RestirTileCountsRead[tileIndex];
|
||||
if (touchedSegmentCount == 0u)
|
||||
{
|
||||
RestirInitialReservoirs[pixelIndex] = reservoir;
|
||||
return;
|
||||
}
|
||||
|
||||
uint2 localPixelInTile = pixel - tile * TubeFieldRestirTileSize;
|
||||
uint laneX = min(localPixelInTile.x / 4u, 3u);
|
||||
uint laneY = min(localPixelInTile.y / 4u, 3u);
|
||||
uint spatialLane = laneY * 4u + laneX;
|
||||
[unroll(4)]
|
||||
for (uint depthLane = 0u; depthLane < TubeFieldRestirDepthLanesPerSpatialLane; depthLane++)
|
||||
{
|
||||
uint candidateSlot = spatialLane * TubeFieldRestirDepthLanesPerSpatialLane + depthLane;
|
||||
uint columnIndex;
|
||||
if (unpackRestirTileSegment(RestirTileSegmentsRead[tileIndex * TubeFieldRestirMaxTileSegments + candidateSlot], columnIndex))
|
||||
{
|
||||
TubeFieldReservoir candidate;
|
||||
float targetPdf;
|
||||
if (evaluateTubeFieldColumnCandidate(columnIndex, (float2)pixel + 0.5 + jitterPixels, candidate, targetPdf))
|
||||
{
|
||||
float randomValue = restirRandom01(pixelIndex * 1664525u + depthLane * 1013904223u + (uint)frameIndex * 977u);
|
||||
restirStreamCandidate(reservoir, candidate, targetPdf, (float)TubeFieldRestirDepthLanesPerSpatialLane, randomValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
restirFinalize(reservoir);
|
||||
RestirInitialReservoirs[pixelIndex] = reservoir;
|
||||
}
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void D3D12TubeFieldRestirTemporalCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 pixel = dispatchThreadId.xy;
|
||||
uint2 dimensions = (uint2)max(resolution, float2(1.0, 1.0));
|
||||
if (any(pixel >= dimensions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint pixelIndex = pixel.y * dimensions.x + pixel.x;
|
||||
TubeFieldReservoir reservoir = RestirInitialReservoirs[pixelIndex];
|
||||
TubeFieldReservoir previousReservoir = RestirPreviousReservoirs[pixelIndex];
|
||||
TubeFieldReservoir shiftedPreviousReservoir;
|
||||
float shiftedPreviousTargetPdf;
|
||||
if (shiftTubeFieldReservoirToPixel(
|
||||
previousReservoir,
|
||||
(float2)pixel,
|
||||
shiftedPreviousReservoir,
|
||||
shiftedPreviousTargetPdf))
|
||||
{
|
||||
if (!restirReservoirValid(reservoir))
|
||||
{
|
||||
reservoir = shiftedPreviousReservoir;
|
||||
reservoir.statistics.y = max(shiftedPreviousTargetPdf, 0.0001);
|
||||
restirFinalize(reservoir);
|
||||
}
|
||||
else if (restirCompatibleOpaqueShift(reservoir, shiftedPreviousReservoir))
|
||||
{
|
||||
float randomValue = restirRandom01(pixelIndex * 747796405u + (uint)frameIndex * 2891336453u);
|
||||
restirCombineReservoir(reservoir, shiftedPreviousReservoir, max(shiftedPreviousTargetPdf, 0.0001), randomValue);
|
||||
restirFinalize(reservoir);
|
||||
}
|
||||
}
|
||||
|
||||
RestirWriteReservoirs[pixelIndex] = reservoir;
|
||||
}
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void D3D12TubeFieldRestirSpatialResolveCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 pixel = dispatchThreadId.xy;
|
||||
uint2 dimensions = (uint2)max(resolution, float2(1.0, 1.0));
|
||||
if (any(pixel >= dimensions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint pixelIndex = pixel.y * dimensions.x + pixel.x;
|
||||
TubeFieldReservoir reservoir = RestirReadReservoirs[pixelIndex];
|
||||
|
||||
static const int2 spatialOffsets[16] =
|
||||
{
|
||||
int2(-1, 0),
|
||||
int2(1, 0),
|
||||
int2(0, -1),
|
||||
int2(0, 1),
|
||||
int2(-2, -1),
|
||||
int2(2, 1),
|
||||
int2(-1, 2),
|
||||
int2(1, -2),
|
||||
int2(-3, 1),
|
||||
int2(3, -1),
|
||||
int2(-1, -3),
|
||||
int2(1, 3),
|
||||
int2(-4, 2),
|
||||
int2(4, -2),
|
||||
int2(-2, 4),
|
||||
int2(2, -4)
|
||||
};
|
||||
|
||||
[unroll(4)]
|
||||
for (uint sampleIndex = 0u; sampleIndex < TubeFieldRestirSpatialCandidateCount; sampleIndex++)
|
||||
{
|
||||
uint offsetIndex = wangHash(pixelIndex * 9781u + sampleIndex * 6271u + (uint)frameIndex * 1709u) & 15u;
|
||||
int2 offset = spatialOffsets[offsetIndex];
|
||||
uint2 neighbor = min((uint2)max(int2(pixel) + offset, int2(0, 0)), dimensions - 1u);
|
||||
uint neighborIndex = neighbor.y * dimensions.x + neighbor.x;
|
||||
TubeFieldReservoir neighborReservoir = RestirReadReservoirs[neighborIndex];
|
||||
TubeFieldReservoir shiftedNeighborReservoir;
|
||||
float shiftedNeighborTargetPdf;
|
||||
if (shiftTubeFieldReservoirToPixel(
|
||||
neighborReservoir,
|
||||
(float2)pixel,
|
||||
shiftedNeighborReservoir,
|
||||
shiftedNeighborTargetPdf))
|
||||
{
|
||||
if (!restirReservoirValid(reservoir))
|
||||
{
|
||||
reservoir = shiftedNeighborReservoir;
|
||||
reservoir.statistics.y = max(shiftedNeighborTargetPdf, 0.0001);
|
||||
}
|
||||
else if (restirCompatibleOpaqueShift(reservoir, shiftedNeighborReservoir))
|
||||
{
|
||||
float randomValue = restirRandom01(pixelIndex * 89173u + sampleIndex * 19349663u + (uint)frameIndex * 83492791u);
|
||||
restirCombineReservoir(reservoir, shiftedNeighborReservoir, max(shiftedNeighborTargetPdf, 0.0001), randomValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
restirFinalize(reservoir);
|
||||
RestirWriteReservoirs[pixelIndex] = reservoir;
|
||||
uint baseIndex = pixelIndex * FieldReservoirSlotsPerPixel;
|
||||
|
||||
TubeFieldReservoir export0 = emptyTubeFieldReservoir();
|
||||
TubeFieldReservoir export1 = emptyTubeFieldReservoir();
|
||||
TubeFieldReservoir export2 = emptyTubeFieldReservoir();
|
||||
TubeFieldReservoir export3 = emptyTubeFieldReservoir();
|
||||
float priority0 = 1.0e20;
|
||||
float priority1 = 1.0e20;
|
||||
float priority2 = 1.0e20;
|
||||
float priority3 = 1.0e20;
|
||||
|
||||
uint2 tileDims = restirTileDimensions();
|
||||
uint2 tile = min(pixel / TubeFieldRestirTileSize, tileDims - 1u);
|
||||
uint tileIndex = tile.y * tileDims.x + tile.x;
|
||||
uint touchedSegmentCount = RestirTileCountsRead[tileIndex];
|
||||
if (touchedSegmentCount > 0u)
|
||||
{
|
||||
uint2 localPixelInTile = pixel - tile * TubeFieldRestirTileSize;
|
||||
uint laneX = min(localPixelInTile.x / 4u, 3u);
|
||||
uint laneY = min(localPixelInTile.y / 4u, 3u);
|
||||
uint spatialLane = laneY * 4u + laneX;
|
||||
[unroll(4)]
|
||||
for (uint depthLane = 0u; depthLane < TubeFieldRestirDepthLanesPerSpatialLane; depthLane++)
|
||||
{
|
||||
uint candidateSlot = spatialLane * TubeFieldRestirDepthLanesPerSpatialLane + depthLane;
|
||||
uint columnIndex;
|
||||
if (unpackRestirTileSegment(RestirTileSegmentsRead[tileIndex * TubeFieldRestirMaxTileSegments + candidateSlot], columnIndex))
|
||||
{
|
||||
TubeFieldReservoir candidate;
|
||||
float targetPdf;
|
||||
if (evaluateTubeFieldColumnCandidate(columnIndex, (float2)pixel + 0.5 + jitterPixels, candidate, targetPdf))
|
||||
{
|
||||
insertTubeFieldExportCandidate(
|
||||
candidate,
|
||||
export0,
|
||||
export1,
|
||||
export2,
|
||||
export3,
|
||||
priority0,
|
||||
priority1,
|
||||
priority2,
|
||||
priority3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tubeFieldReservoirPriority(reservoir) < priority3)
|
||||
{
|
||||
insertTubeFieldExportCandidate(
|
||||
reservoir,
|
||||
export0,
|
||||
export1,
|
||||
export2,
|
||||
export3,
|
||||
priority0,
|
||||
priority1,
|
||||
priority2,
|
||||
priority3);
|
||||
}
|
||||
|
||||
writeFieldReservoirCandidateSlot(baseIndex, 0u, export0);
|
||||
writeFieldReservoirCandidateSlot(baseIndex, 1u, export1);
|
||||
writeFieldReservoirCandidateSlot(baseIndex, 2u, export2);
|
||||
writeFieldReservoirCandidateSlot(baseIndex, 3u, export3);
|
||||
}
|
||||
|
||||
TubeFieldVertexOut D3D12TubeFieldVS(TubeFieldVertexIn input)
|
||||
{
|
||||
float3 forward;
|
||||
|
|
|
|||
|
|
@ -278,3 +278,4 @@
|
|||
{"lesson":"The many-spline TubeField quality path stays on cheap segmented proxies. Segment continuity now fixes data ownership inside that model: every generated proxy vertex carries the same start/end radius pair, and the compute segment packet stores true start/end radii plus feather/alpha separately. ReSTIR candidate evaluation and tile binning now use the true end radius instead of silently reusing the start radius, reducing join disagreement without spline-wide SDF evaluation. Verified with Fensalir/Mimir builds, --mimir-spectrum-upload-smoke, and headless capture artifacts/runtime/tubefield-cheap-continuity-spectrum.png.","timestamp":"2026-05-28T17:55:00+01:00","files":["src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","state/map.yaml","state/evidence.jsonl"],"source":"user chose many-hundreds-splines cheap segment continuity path","topic":"tubefield-cheap-segment-continuity"}
|
||||
{"lesson":"TubeField candidate authority has moved from generated segment packets to rolling-buffer column packets. D3D12TubeFieldExpandCS now emits one GPU-resident TubeFieldColumn per logical spectrum column and zeroes generated-mesh draw args; ReSTIR tile binning and candidate evaluation sample the source buffer directly as Catmull-Rom spline SDF evidence, with ramp sampling bound in the ReSTIR root signature. Debug builds compile TubeField ReSTIR shaders with optimization enabled because SkipOptimization can make the compiler unroll the column evaluator into failure. Verified with Mimir.App build and headless synthetic spectrum capture artifacts/runtime/mimir-column-packet-final-headless.png at about 60 FPS after warmup.","timestamp":"2026-05-29T01:46:00+01:00","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","state/map.yaml","state/evidence.jsonl"],"source":"user selected spline/column packets as TubeField reservoir authority","topic":"tubefield-column-packet-restir-authority"}
|
||||
{"lesson":"The first column-packet TubeField ReSTIR pass still skipped visible splines because tile admission kept only one depth candidate per 4x4 spatial lane. That made overlapping spectrum columns evict each other before the pixel reservoir could choose. TubeField tile lanes now keep four sorted depth candidates per spatial lane, and initial/export passes evaluate those depth lanes for the receiving pixel. Verified with Mimir.App headless capture artifacts/runtime/mimir-column-depth4-headless.png; visual fill improves substantially while headless timing remains around 60 FPS after warmup.","timestamp":"2026-05-29T02:14:00+01:00","files":["src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","state/evidence.jsonl"],"source":"user observed skipped splines in column-packet spectrum capture","topic":"tubefield-column-tile-depth-lanes"}
|
||||
{"timestamp":"2026-05-29T11:22:43.7565366Z","type":"decision","status":"ok","note":"Cut the TubeField-local compute ReSTIR/tile-bin path. Authorized TubeField path is compute-generated conservative segment proxy geometry, raster proxy SDF evaluation, and pixel-shader candidate injection into the shared field reservoir; shared reservoir/history remains the only final visibility authority."}
|
||||
|
|
|
|||
|
|
@ -208,20 +208,15 @@ next_actions:
|
|||
fullscreen resolve writes canonical scene color/travel/metadata/control/
|
||||
reservoir-guide lanes. A shared compute pass then updates ping-ponged
|
||||
structured reservoir history, emits the resolved HDR field texture, and
|
||||
bloom/presentation consume that texture without owning history. The
|
||||
remaining coherence cut is to make every non-debug contributor inject
|
||||
explicit field candidates instead of entering as the single legacy
|
||||
scene-candidate input.
|
||||
TubeField reservoir ownership now uses spline/column packets as the
|
||||
candidate authority rather than generated mesh segments. TubeField expansion
|
||||
writes one GPU-resident column packet per rolling-buffer column, tile binning
|
||||
files those columns into screen-space lanes, pixel-owned reservoirs evaluate
|
||||
a local Catmull-Rom SDF sample directly from the source buffer, temporal
|
||||
reuse reprojects previous column samples, and spatial reuse re-evaluates the
|
||||
selected column at the receiving pixel before combination. The shared field
|
||||
reservoir remains the only final contribution path. Generated vertex/index
|
||||
output is currently zeroed for the live path and retained only as a
|
||||
diagnostic/generated-mesh reference.
|
||||
bloom/presentation consume that texture without owning history. TubeField
|
||||
candidate discovery is the fixed-function raster path: compute emits
|
||||
conservative GPU-resident segment proxy geometry and indirect draw packets,
|
||||
the proxy pixel shader evaluates the sampled Catmull-Rom tube SDF against
|
||||
the rolling source buffer, and that shader writes candidates directly into
|
||||
the shared field reservoir inlet. The deleted TubeField-local compute
|
||||
ReSTIR/tile-bin path is not a live authority, fallback, or hidden mode. Any
|
||||
future temporal/spatial reuse for tubes must extend the shared reservoir
|
||||
organ rather than resurrecting a payload-local reservoir renderer.
|
||||
- Move any remaining client-only Epiphany state found here back to `E:\Projects\Aquarium-Engine`.
|
||||
- Keep Mimir app/adapters out of this repo; Fensalir may expose generic sensor-fusion contracts only.
|
||||
- Package contracts/host deliberately before replacing sibling source references in client repos.
|
||||
|
|
|
|||
Loading…
Reference in a new issue