feat(rhi): refactor resource & barrier management for D3D12
Modernizes resource and barrier management for the D3D12 backend. Key changes: - Simplifies BarrierDesc by removing nullable "before" states; now inferred from resource database. - Adds IsAliasing flag to BarrierDesc for aliasing transitions. - Replaces ResourceMemoryType with HeapType in BufferDesc and related APIs. - Enhances ResourceViewGroup with usage inference methods. - Adds D3D12 utility helpers for heap/flag conversions and resource description extraction. - Optimizes command buffer barrier emission, skipping redundant barriers. - Refactors Material and RenderContext to use new APIs and state tracking. - Updates ResourceManager pooling to use HeapType and standard Queue. - Simplifies RenderGraphExecutor barrier logic and aliasing handling. - Improves RenderSystem frame synchronization and resource retirement. - Cleans up obsolete code and improves debug output. BREAKING CHANGE: Updates to resource and barrier APIs require changes to all code interfacing with resource creation, barriers, and memory types.
This commit is contained in:
@@ -556,31 +556,16 @@ public struct BarrierDesc
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierSync? SyncBefore
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierSync SyncAfter
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierAccess? AccessBefore
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierAccess AccessAfter
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierLayout? LayoutBefore
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public BarrierLayout LayoutAfter
|
||||
{
|
||||
get; set;
|
||||
@@ -601,45 +586,45 @@ public struct BarrierDesc
|
||||
get; set;
|
||||
}
|
||||
|
||||
public static BarrierDesc Global(BarrierSync syncBefore, BarrierSync syncAfter, BarrierAccess accessBefore, BarrierAccess accessAfter)
|
||||
public bool IsAliasing
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public static BarrierDesc Global(BarrierSync syncAfter, BarrierAccess accessAfter)
|
||||
{
|
||||
return new BarrierDesc
|
||||
{
|
||||
Type = BarrierType.Global,
|
||||
SyncBefore = syncBefore,
|
||||
SyncAfter = syncAfter,
|
||||
AccessBefore = accessBefore,
|
||||
AccessAfter = accessAfter
|
||||
};
|
||||
}
|
||||
|
||||
public static BarrierDesc Buffer(Handle<GPUResource> resource, BarrierSync? syncBefore, BarrierSync syncAfter, BarrierAccess? accessBefore, BarrierAccess accessAfter)
|
||||
public static BarrierDesc Buffer(Handle<GPUResource> resource, BarrierSync syncAfter, BarrierAccess accessAfter, bool isAliasing = false)
|
||||
{
|
||||
return new BarrierDesc
|
||||
{
|
||||
Type = BarrierType.Buffer,
|
||||
Resource = resource,
|
||||
SyncBefore = syncBefore,
|
||||
SyncAfter = syncAfter,
|
||||
AccessBefore = accessBefore,
|
||||
AccessAfter = accessAfter
|
||||
AccessAfter = accessAfter,
|
||||
IsAliasing = isAliasing
|
||||
};
|
||||
}
|
||||
|
||||
public static BarrierDesc Texture(Handle<GPUResource> resource, BarrierSync? syncBefore, BarrierSync syncAfter, BarrierAccess? accessBefore, BarrierAccess accessAfter, BarrierLayout? layoutBefore, BarrierLayout layoutAfter, BarrierSubresourceRange subresources = default, bool discard = false)
|
||||
public static BarrierDesc Texture(Handle<GPUResource> resource, BarrierSync syncAfter, BarrierAccess accessAfter, BarrierLayout layoutAfter, BarrierSubresourceRange subresources = default, bool discard = false, bool isAliasing = false)
|
||||
{
|
||||
return new BarrierDesc
|
||||
{
|
||||
Type = BarrierType.Texture,
|
||||
Resource = resource,
|
||||
SyncBefore = syncBefore,
|
||||
SyncAfter = syncAfter,
|
||||
AccessBefore = accessBefore,
|
||||
AccessAfter = accessAfter,
|
||||
LayoutBefore = layoutBefore,
|
||||
LayoutAfter = layoutAfter,
|
||||
Subresources = subresources,
|
||||
Discard = discard
|
||||
Discard = discard,
|
||||
IsAliasing = isAliasing
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -724,6 +709,16 @@ public record struct ResourceDesc
|
||||
_ => throw new InvalidOperationException($"Unknown resource type: {Type}")
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Type switch
|
||||
{
|
||||
ResourceType.Texture => $"Texture: {TextureDescription}",
|
||||
ResourceType.Buffer => $"Buffer: {BufferDescription}",
|
||||
_ => $"Unknown resource type: {Type}"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -998,7 +993,7 @@ public record struct BufferDesc
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ResourceMemoryType MemoryType
|
||||
public HeapType HeapType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
@@ -1255,13 +1250,6 @@ public enum RenderTargetCreationFlags
|
||||
GenerateMips = 1 << 3
|
||||
}
|
||||
|
||||
public enum ResourceMemoryType
|
||||
{
|
||||
Default, // GPU memory
|
||||
Upload, // CPU-to-GPU memory
|
||||
Readback // GPU-to-CPU memory
|
||||
}
|
||||
|
||||
public enum ResourceType
|
||||
{
|
||||
Texture,
|
||||
|
||||
Reference in New Issue
Block a user