using Ghost.Core;
namespace Ghost.RenderGraph.Concept;
///
/// Mock command buffer for recording GPU commands.
/// In a real implementation, this would wrap D3D12 command lists.
///
internal sealed class MockCommandBuffer
{
public void SetRenderTarget(Identifier texture)
{
#if DEBUG
Console.WriteLine(nameof(SetRenderTarget) + ": " + texture);
#endif
}
public void SetDepthStencil(Identifier texture)
{
#if DEBUG
Console.WriteLine(nameof(SetDepthStencil) + ": " + texture);
#endif
}
public void ClearRenderTarget(Identifier texture, float r, float g, float b, float a)
{
#if DEBUG
Console.WriteLine(nameof(ClearRenderTarget) + ": " + texture);
#endif
}
public void ClearDepth(Identifier texture, float depth)
{
#if DEBUG
Console.WriteLine(nameof(ClearDepth) + ": " + texture);
#endif
}
public void Draw(int vertexCount)
{
#if DEBUG
Console.WriteLine(nameof(Draw) + ": " + vertexCount);
#endif
}
public void BindShaderResource(Identifier resource, int slot)
{
#if DEBUG
Console.WriteLine(nameof(BindShaderResource) + ": " + resource + ", slot " + slot);
#endif
}
public void BindUnorderedAccess(Identifier resource, int slot)
{
#if DEBUG
Console.WriteLine(nameof(BindUnorderedAccess) + ": " + resource + ", slot " + slot);
#endif
}
public void Dispatch(int x, int y, int z)
{
#if DEBUG
Console.WriteLine(nameof(Dispatch) + ": " + x + ", " + y + ", " + z);
#endif
}
public void ResourceBarrier(Identifier resource, ResourceState stateBefore, ResourceState stateAfter)
{
#if DEBUG
Console.WriteLine(nameof(ResourceBarrier) + ": " + resource + " from " + stateBefore + " to " + stateAfter);
#endif
}
public void AliasBarrier(Identifier resourceBefore, Identifier resourceAfter)
{
#if DEBUG
Console.WriteLine(nameof(AliasBarrier) + ": " + resourceBefore + " to " + resourceAfter);
#endif
}
public void BeginRenderPass(int nativePassIndex, int colorAttachmentCount, bool hasDepth)
{
#if DEBUG
Console.WriteLine($"\n=== BeginRenderPass (Native Pass {nativePassIndex}) ===");
Console.WriteLine($" Color attachments: {colorAttachmentCount}, Depth: {hasDepth}");
#endif
}
public void EndRenderPass()
{
#if DEBUG
Console.WriteLine("=== EndRenderPass ===\n");
#endif
}
}
///
/// Context for raster rendering passes.
/// Directly exposes command buffer methods.
///
public readonly struct RasterRenderContext
{
private readonly MockCommandBuffer _cmd;
internal RasterRenderContext(MockCommandBuffer cmd)
{
_cmd = cmd;
}
// Expose command buffer methods directly
public void SetRenderTarget(Identifier texture) => _cmd.SetRenderTarget(texture);
public void SetDepthStencil(Identifier texture) => _cmd.SetDepthStencil(texture);
public void ClearRenderTarget(Identifier texture, float r, float g, float b, float a) => _cmd.ClearRenderTarget(texture, r, g, b, a);
public void ClearDepth(Identifier texture, float depth) => _cmd.ClearDepth(texture, depth);
public void Draw(int vertexCount) => _cmd.Draw(vertexCount);
public void BindShaderResource(Identifier resource, int slot) => _cmd.BindShaderResource(resource, slot);
}
///
/// Context for compute rendering passes.
/// Directly exposes command buffer methods.
///
public readonly struct ComputeRenderContext
{
private readonly MockCommandBuffer _cmd;
internal ComputeRenderContext(MockCommandBuffer cmd)
{
_cmd = cmd;
}
// Expose command buffer methods directly
public void BindShaderResource(Identifier resource, int slot) => _cmd.BindShaderResource(resource, slot);
public void BindUnorderedAccess(Identifier resource, int slot) => _cmd.BindUnorderedAccess(resource, slot);
public void Dispatch(int x, int y, int z) => _cmd.Dispatch(x, y, z);
}
///
/// Unified render context containing both raster and compute contexts.
///
internal readonly struct RenderContext
{
public readonly RasterRenderContext RasterContext;
public readonly ComputeRenderContext ComputeContext;
public RenderContext(MockCommandBuffer cmd)
{
RasterContext = new RasterRenderContext(cmd);
ComputeContext = new ComputeRenderContext(cmd);
}
}