Refactor RenderGraph barrier/state tracking system
Major overhaul of resource barrier and state tracking in RenderGraph: - Introduce ResourceBarrierData for explicit (layout, access, sync) tracking. - Separate aliasing and transition barriers; explicit aliasing support. - Remove BufferHint; infer buffer usage from BufferUsage flags. - Update TextureAccess/BufferAccess to include usage requirements. - Improve enums (BarrierSync, BarrierAccess, BarrierLayout) for D3D12 alignment. - Update D3D12CommandBuffer to use new barrier data and error handling. - Make D3D12DescriptorHeap a class; add ReleaseSampler to IResourceDatabase. - Reset resource pools and aliasing managers each frame. - Batch and flush barriers efficiently per pass. - Update HLSL mesh shader macros to [NumThreads]. - Remove obsolete code and improve documentation. This refactor improves correctness, extensibility, and prepares for advanced features.
This commit is contained in:
@@ -4,41 +4,70 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ghost.Graphics.RenderGraphModule;
|
||||
|
||||
[Flags]
|
||||
internal enum BarrierFlags
|
||||
{
|
||||
None = 0,
|
||||
FirstUsage = 1 << 0,
|
||||
Discard = 1 << 1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a resource barrier that needs to be inserted.
|
||||
/// Represents a resource barrier requirement that needs to be resolved at runtime.
|
||||
/// </summary>
|
||||
internal struct ResourceBarrier
|
||||
{
|
||||
public int PassIndex;
|
||||
public BarrierDesc Desc;
|
||||
public Identifier<RGResource> LogicalResource;
|
||||
public Identifier<RGResource> Resource;
|
||||
public ResourceBarrierData TargetState;
|
||||
public Identifier<RGResource> AliasingPredecessor; // Invalid if not aliasing
|
||||
public BarrierFlags Flags;
|
||||
|
||||
public readonly Identifier<RGResource> Resource => LogicalResource;
|
||||
|
||||
public static ResourceBarrier Create(int passIndex, BarrierDesc desc, Identifier<RGResource> logicalResource)
|
||||
public static ResourceBarrier CreateTransition(int passIndex, Identifier<RGResource> resource, ResourceBarrierData targetState, BarrierFlags flags = BarrierFlags.None)
|
||||
{
|
||||
return new ResourceBarrier
|
||||
{
|
||||
PassIndex = passIndex,
|
||||
Desc = desc,
|
||||
LogicalResource = logicalResource
|
||||
Resource = resource,
|
||||
TargetState = targetState,
|
||||
AliasingPredecessor = Identifier<RGResource>.Invalid,
|
||||
Flags = flags
|
||||
};
|
||||
}
|
||||
|
||||
public static ResourceBarrier CreateAliasing(int passIndex, Identifier<RGResource> resource, Identifier<RGResource> predecessor, ResourceBarrierData targetState)
|
||||
{
|
||||
return new ResourceBarrier
|
||||
{
|
||||
PassIndex = passIndex,
|
||||
Resource = resource,
|
||||
TargetState = targetState,
|
||||
AliasingPredecessor = predecessor,
|
||||
Flags = BarrierFlags.FirstUsage | BarrierFlags.Discard // Aliasing implies starting fresh
|
||||
};
|
||||
}
|
||||
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return AliasingPredecessor.IsValid
|
||||
? $"[Pass {PassIndex}] Aliasing Barrier: {AliasingPredecessor.Value}->{Resource.Value} Target: {TargetState.Layout}"
|
||||
: $"[Pass {PassIndex}] Barrier: {Resource.Value} Target: {TargetState.Layout}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the current state of a resource across passes.
|
||||
/// Tracks the current state of a resource across passes during compilation.
|
||||
/// </summary>
|
||||
internal sealed class ResourceStateTracker
|
||||
{
|
||||
public int resourceIndex;
|
||||
public ResourceState currentState = ResourceState.Common;
|
||||
public ResourceBarrierData currentState;
|
||||
public int lastAccessPass = -1;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
resourceIndex = -1;
|
||||
currentState = ResourceState.Common;
|
||||
currentState = default;
|
||||
lastAccessPass = -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user