Gate TubeField dispatch by valid resource slots
This commit is contained in:
parent
af6da11f07
commit
b5b358245f
4 changed files with 86 additions and 2 deletions
|
|
@ -189,6 +189,60 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
return false;
|
||||
}
|
||||
|
||||
public void MarkStructuredBufferUpload(string resourceKey, int elementOffset, int elementCount)
|
||||
{
|
||||
if (!structuredBuffers.TryGetValue(resourceKey, out var slot) ||
|
||||
elementOffset < 0 ||
|
||||
elementCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var firstFullColumn = (elementOffset + slot.Width - 1) / slot.Width;
|
||||
var endFullColumn = (elementOffset + elementCount) / slot.Width;
|
||||
if (endFullColumn <= firstFullColumn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var validColumns = slot.ValidColumns;
|
||||
for (var column = Math.Max(0, firstFullColumn); column < Math.Min(validColumns.Length, endFullColumn); column++)
|
||||
{
|
||||
validColumns[column] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public int CountContiguousValidColumns(AquariumFieldTubeSplineLowering lowering)
|
||||
{
|
||||
if (!structuredBuffers.TryGetValue(lowering.ResourceKey, out var slot))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var normalized = lowering.Normalized();
|
||||
var validCount = 0;
|
||||
for (var logicalColumn = 0; logicalColumn < normalized.ColumnCount; logicalColumn++)
|
||||
{
|
||||
var physicalColumn = normalized.FirstColumn + logicalColumn * normalized.ColumnStride;
|
||||
if (normalized.RollingModulo > 0)
|
||||
{
|
||||
physicalColumn = PositiveModulo(physicalColumn + normalized.RollingOffset, normalized.RollingModulo);
|
||||
}
|
||||
|
||||
physicalColumn = Math.Min(physicalColumn, slot.ValidColumns.Length - 1);
|
||||
if (physicalColumn < 0 ||
|
||||
physicalColumn >= slot.ValidColumns.Length ||
|
||||
!slot.ValidColumns[physicalColumn])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
validCount++;
|
||||
}
|
||||
|
||||
return validCount;
|
||||
}
|
||||
|
||||
public bool TryGetTexture2D(string resourceKey, out D3D12FieldTexture2D texture)
|
||||
{
|
||||
if (textures.TryGetValue(resourceKey, out var slot))
|
||||
|
|
@ -384,9 +438,12 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
var allowUnorderedAccess = declaration.Access == AquariumFieldShaderAccess.UnorderedAccess;
|
||||
|
||||
var hasExisting = structuredBuffers.TryGetValue(declaration.ResourceKey, out var existing);
|
||||
var width = Math.Max(1, declaration.Width);
|
||||
var columnCount = Math.Max(1, (elementCount + width - 1) / width);
|
||||
if (hasExisting && existing is not null &&
|
||||
existing.ElementCount == elementCount &&
|
||||
existing.StrideBytes == strideBytes &&
|
||||
existing.Width == width &&
|
||||
existing.AllowUnorderedAccess == allowUnorderedAccess)
|
||||
{
|
||||
structuredBuffers[declaration.ResourceKey] = existing with { Version = declaration.Version };
|
||||
|
|
@ -418,6 +475,8 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
structuredBuffers[declaration.ResourceKey] = new StructuredBufferSlot(
|
||||
buffer,
|
||||
elementCount,
|
||||
width,
|
||||
new bool[columnCount],
|
||||
strideBytes,
|
||||
allowUnorderedAccess,
|
||||
declaration.Version);
|
||||
|
|
@ -625,6 +684,12 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
|
||||
private static string RegistryKey(string resourceKey) => RegistryPrefix + resourceKey;
|
||||
|
||||
private static int PositiveModulo(int value, int modulo)
|
||||
{
|
||||
var remainder = value % modulo;
|
||||
return remainder < 0 ? remainder + modulo : remainder;
|
||||
}
|
||||
|
||||
private static D3D12StructuredBuffer? OpenSharedStructuredBuffer(
|
||||
ID3D12Device device,
|
||||
AquariumFieldResourceDeclaration declaration,
|
||||
|
|
@ -659,6 +724,8 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
private sealed record StructuredBufferSlot(
|
||||
D3D12StructuredBuffer Buffer,
|
||||
int ElementCount,
|
||||
int Width,
|
||||
bool[] ValidColumns,
|
||||
int StrideBytes,
|
||||
bool AllowUnorderedAccess,
|
||||
ulong Version);
|
||||
|
|
|
|||
|
|
@ -256,6 +256,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private int activeTubeFieldIndirectDrawCount;
|
||||
private int activeTubeFieldSkippedDrawBatches;
|
||||
private int activeTubeFieldUnplannedLowerings;
|
||||
private int activeTubeFieldInvalidColumns;
|
||||
private int activeFieldResourceUploadCount;
|
||||
private int activeFieldResourceUploadSkippedCount;
|
||||
private Viewport viewport;
|
||||
|
|
@ -553,7 +554,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 requested {activeTubeFieldRequestedSegments} dispatched {activeTubeFieldDispatchedSegments} truncated {activeTubeFieldTruncatedSegments} uploads {activeFieldResourceUploadCount} skipped {activeFieldResourceUploadSkippedCount} unplanned {activeTubeFieldUnplannedLowerings}"
|
||||
? $" / tube requested {activeTubeFieldRequestedSegments} dispatched {activeTubeFieldDispatchedSegments} truncated {activeTubeFieldTruncatedSegments} invalid {activeTubeFieldInvalidColumns} uploads {activeFieldResourceUploadCount} skipped {activeFieldResourceUploadSkippedCount} unplanned {activeTubeFieldUnplannedLowerings}"
|
||||
: string.Empty);
|
||||
}
|
||||
|
||||
|
|
@ -2344,6 +2345,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeTubeFieldIndirectDrawCount = 0;
|
||||
activeTubeFieldSkippedDrawBatches = 0;
|
||||
activeTubeFieldUnplannedLowerings = 0;
|
||||
activeTubeFieldInvalidColumns = 0;
|
||||
activeFieldResourceUploadCount = 0;
|
||||
activeFieldResourceUploadSkippedCount = 0;
|
||||
tubeFieldDrawBatches.Clear();
|
||||
|
|
@ -2383,6 +2385,14 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
|
||||
var normalized = lowering.Normalized();
|
||||
var validColumnCount = fieldResourceRegistry.CountContiguousValidColumns(normalized);
|
||||
activeTubeFieldInvalidColumns += Math.Max(0, normalized.ColumnCount - validColumnCount);
|
||||
if (validColumnCount <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
normalized = normalized with { ColumnCount = validColumnCount };
|
||||
var requestedSegments = checked(Math.Max(0, normalized.Width - 1) * Math.Max(1, normalized.CatmullRomSubdivisions) * Math.Max(1, normalized.ColumnCount));
|
||||
activeTubeFieldRequestedSegments += requestedSegments;
|
||||
var remainingSegments = MaxTubeFieldSegments - segmentBase;
|
||||
|
|
@ -2485,6 +2495,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
|
||||
activeFieldResourceUploadCount++;
|
||||
fieldResourceRegistry.MarkStructuredBufferUpload(upload.ResourceKey, upload.ElementOffset, upload.Float32Data.Count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3137,6 +3148,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
$"indirect draws {activeTubeFieldIndirectDrawCount:N0}; " +
|
||||
$"skipped draw batches {activeTubeFieldSkippedDrawBatches:N0}; " +
|
||||
$"unplanned lowerings {activeTubeFieldUnplannedLowerings:N0}; " +
|
||||
$"invalid columns {activeTubeFieldInvalidColumns:N0}; " +
|
||||
$"resource uploads {activeFieldResourceUploadCount:N0}; " +
|
||||
$"skipped uploads {activeFieldResourceUploadSkippedCount:N0}; " +
|
||||
$"index draw count {activeTubeFieldDrawIndexCount:N0}; " +
|
||||
|
|
|
|||
Loading…
Reference in a new issue