Render graph integration and resource management refactor

Introduces a full-featured render graph system with pass culling, resource aliasing, and automatic barrier generation. Refactors resource and barrier APIs, improves error handling, and unifies result types. Renderer and render passes now use the new graph-based workflow. Updates shader includes, adds a blit shader, and improves HLSL parsing. Removes dynamic descriptor heaps in favor of persistent ones. Project file now includes the render graph module. Lays the foundation for advanced rendering features and improved memory efficiency.
This commit is contained in:
2026-01-21 18:32:03 +09:00
parent 1c155f962c
commit 92b966fe0d
62 changed files with 4843 additions and 621 deletions

View File

@@ -294,28 +294,41 @@ public struct PassDepthStencilDesc
}
[StructLayout(LayoutKind.Explicit)]
public struct BarrierDesc
{
public Handle<GPUResource> Resource
public struct barrierdesc_transition
{
get; set;
public Handle<GPUResource> resource;
public ResourceState stateBefore;
public ResourceState stateAfter;
}
public ResourceState StateBefore
public struct barrierdesc_aliasing
{
get; set;
public Handle<GPUResource> resourceBefore;
public Handle<GPUResource> resourceAfter;
}
public ResourceState StateAfter
public struct barrierdesc_uav
{
get; set;
public Handle<GPUResource> resource;
}
[FieldOffset(0)]
public BarrierType type;
[FieldOffset(4)]
public barrierdesc_transition transition;
[FieldOffset(4)]
public barrierdesc_aliasing aliasing;
[FieldOffset(4)]
public barrierdesc_uav uav;
}
public struct ResourceDesc
{
[StructLayout(LayoutKind.Explicit)]
private struct resource_union
internal struct resource_union
{
[FieldOffset(0)]
public TextureDesc textureDescription;
@@ -323,7 +336,7 @@ public struct ResourceDesc
public BufferDesc bufferDescription;
}
private resource_union _desc;
internal resource_union _desc;
public TextureDesc TextureDescription
{
@@ -774,9 +787,17 @@ public enum SwapChainTargetType
}
[Flags]
public enum ResourceState
public enum BarrierType : int
{
Transition,
Aliasing,
UAV
}
[Flags]
public enum ResourceState : int
{
Auto = -1,
Common = 0,
VertexAndConstantBuffer = 1 << 0,
IndexBuffer = 1 << 1,

View File

@@ -66,6 +66,10 @@ public interface ICommandBuffer : IDisposable
/// <param name="depthTarget">A handle to the texture to be used as the depth Target. Specify a invalid handle if no depth Target is required.</param>
void SetRenderTargets(ReadOnlySpan<Handle<Texture>> renderTargets, Handle<Texture> depthTarget);
void ClearRenderTargetView(Handle<Texture> renderTarget, Color128 clearColor);
void ClearDepthStencilView(Handle<Texture> depthStencil, bool inlcudeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0);
/// <summary>
/// Begins a render pass with the specified render Target
/// </summary>
@@ -79,8 +83,10 @@ public interface ICommandBuffer : IDisposable
/// </summary>
void EndRenderPass();
// TODO: Enhanced barriers.
/// <summary>
/// Inserts multiple resource barriers for state transitions.
/// Inserts multiple resource barriers.
/// </summary>
/// <param name="barrierDescs">Resource barrier descriptions</param>
void ResourceBarrier(ReadOnlySpan<BarrierDesc> barrierDescs);
@@ -91,14 +97,21 @@ public interface ICommandBuffer : IDisposable
/// <param name="resource">A handle to the GPU resource to transition.</param>
/// <param name="stateBefore">The current state of the resource before the transition.</param>
/// <param name="stateAfter">The desired state of the resource after the transition.</param>
void ResourceBarrier(Handle<GPUResource> resource, ResourceState stateBefore, ResourceState stateAfter);
void TransitionBarrier(Handle<GPUResource> resource, ResourceState stateBefore, ResourceState stateAfter);
/// <summary>
/// Inserts a resource barrier for state transitions. The current state is tracked internally.
/// </summary>
/// <param name="resource">A handle to the GPU resource to transition.</param>
/// <param name="stateAfter">The desired state of the resource after the transition.</param>
void ResourceBarrier(Handle<GPUResource> resource, ResourceState stateAfter);
void TransitionBarrier(Handle<GPUResource> resource, ResourceState stateAfter);
/// <summary>
/// Inserts a barrier to ensure correct aliasing transitions between two GPU resources.
/// </summary>
/// <param name="resourceBefore">A handle to the GPU resource representing the state before the aliasing transition</param>
/// <param name="resourceAfter">A handle to the GPU resource representing the state after the aliasing transition</param>
void AliasBarrier(Handle<GPUResource> resourceBefore, Handle<GPUResource> resourceAfter);
/// <summary>
/// Sets the pipeline state object
@@ -207,8 +220,8 @@ public interface ICommandBuffer : IDisposable
/// <summary>
/// Copies a specified number of bytes from the source graphics buffer to the destination graphics buffer.
/// </summary>
/// <param name="dest">The handle to the destination graphics buffer where data will be written. Cannot be null.</param>
/// <param name="src">The handle to the source graphics buffer from which data will be read. Cannot be null.</param>
/// <param name="dest">The handle to the destination graphics buffer where data will be written.</param>
/// <param name="src">The handle to the source graphics buffer from which data will be read.</param>
/// <param name="destOffset">The byte Offset in the destination buffer at which to begin writing. Must be zero or greater.</param>
/// <param name="srcOffset">The byte Offset in the source buffer at which to begin reading. Must be zero or greater.</param>
/// <param name="numBytes">The number of bytes to copy. If zero, copies the remaining bytes from the source buffer starting at <paramref name="srcOffset"/>.</param>

View File

@@ -3,17 +3,6 @@ using Ghost.Graphics.Contracts;
namespace Ghost.Graphics.RHI;
public interface IShaderPipeline
{
/// <summary>
/// Pipeline space
/// </summary>
PipelineType Type
{
get;
}
}
public interface IPipelineLibrary : IDisposable
{
/// <summary>

View File

@@ -9,7 +9,7 @@ public enum ResourceAllocationType
{
Default,
Temporary,
RenderGraphTransient,
Suballocation,
}
public struct CreationOptions

View File

@@ -46,7 +46,8 @@ public interface IResourceDatabase : IDisposable
/// </summary>
/// <param name="handle">The handle that identifies the resource whose state will be updated.</param>
/// <param name="state">The new state to assign to the resource represented by <paramref name="handle"/>.</param>
void SetResourceState(Handle<GPUResource> handle, ResourceState state);
/// <returns>An ErrorStatus indicating the success or failure of the operation.</returns>
ErrorStatus SetResourceState(Handle<GPUResource> handle, ResourceState state);
/// <summary>
/// Retrieves the description of a GPU resource associated with the specified handle.
@@ -113,8 +114,8 @@ public interface IResourceDatabase : IDisposable
/// Returns a reference to the mesh associated with the specified handle.
/// </summary>
/// <param name="handle">The handle of the mesh to retrieve. Must refer to a valid mesh; otherwise, the behavior is undefined.</param>
/// <returns>A reference to the mesh corresponding to the specified handle.</returns>
ref Mesh GetMeshReference(Handle<Mesh> handle);
/// <returns>A result containing a reference to the mesh corresponding to the specified handle, or an error status if the handle is invalid.</returns>
RefResult<Mesh, ErrorStatus> GetMeshReference(Handle<Mesh> handle);
/// <summary>
/// Releases the mesh resource associated with the specified handle, freeing any resources held by it. Includes both CPU and GPU resources.
@@ -140,8 +141,8 @@ public interface IResourceDatabase : IDisposable
/// Gets a reference to the material associated with the specified handle.
/// </summary>
/// <param name="handle">The handle of the material to retrieve. Must refer to a valid material.</param>
/// <returns>A reference to the material corresponding to the specified handle.</returns>
ref Material GetMaterialReference(Handle<Material> handle);
/// <returns>A result containing a reference to the material corresponding to the specified handle, or an error status if the handle is invalid.</returns>
RefResult<Material, ErrorStatus> GetMaterialReference(Handle<Material> handle);
/// <summary>
/// Releases the material associated with the specified handle, making it available for reuse or disposal.
@@ -167,8 +168,8 @@ public interface IResourceDatabase : IDisposable
/// Returns a reference to the shader associated with the specified identifier.
/// </summary>
/// <param name="id">The identifier of the shader to retrieve. Must refer to a valid shader.</param>
/// <returns>A reference to the shader corresponding to the specified identifier.</returns>
ref Shader GetShaderReference(Identifier<Shader> id);
/// <returns>A result containing a reference to the shader corresponding to the specified identifier, or an error status if the identifier is invalid.</returns>
RefResult<Shader, ErrorStatus> GetShaderReference(Identifier<Shader> id);
/// <summary>
/// Releases the shader associated with the specified identifier, freeing any resources allocated to it.

View File

@@ -9,6 +9,8 @@ namespace Ghost.Graphics.RHI;
internal static class RHIUtility
{
public const int MAX_RENDER_TARGETS = 8;
public static uint GetBytesPerPixel(this TextureFormat format)
{
return format switch