using Ghost.Core;
using Ghost.Core.Graphics;
namespace Ghost.Graphics.RHI;
///
/// D3D12-style command buffer interface for recording rendering commands
///
public interface ICommandBuffer : IRHIObject
{
///
/// Gets the space of the command buffer.
///
CommandBufferType Type
{
get;
}
///
/// Indicates whether the command buffer contains any recorded commands.
///
bool IsEmpty
{
get;
}
///
/// Begins recording commands into this command buffer
///
void Begin(ICommandAllocator allocator);
///
/// Ends recording commands and prepares for submission
///
Result End();
///
/// Sets the viewport for rendering
///
/// Viewport to set
void SetViewport(ViewportDesc viewport);
///
/// Sets the scissor rectangle
///
/// Scissor rectangle to set
void SetScissorRect(ScissorRectDesc rect);
///
/// Sets the optional render targets and optional depth Target for subsequent rendering operations.
///
///
/// To specify no render targets, provide an empty span for .
/// Use for if no depth Target is required.
///
/// A read-only span of handles to textures that will be used as render targets.
/// The order of handles determines the order in which render targets are bound.
/// A handle to the texture to be used as the depth Target. Specify a invalid handle if no depth Target is required.
void SetRenderTargets(ReadOnlySpan> renderTargets, Handle depthTarget);
///
/// Clears the specified render target to a given color.
///
/// A handle to the render target texture to be cleared. Must reference a valid render target.
/// The color value used to clear the render target. Specifies the RGBA components to fill the target.
void ClearRenderTargetView(Handle renderTarget, Color128 clearColor);
///
/// Clears the specified depth-stencil view by resetting its depth and/or stencil values.
///
/// A handle to the depth-stencil texture to be cleared. Must reference a valid depth-stencil resource.
/// A value indicating whether the depth component should be cleared.
/// A value indicating whether the stencil component should be cleared.
/// The value to which the depth buffer will be set. Typically ranges from 0.0f (nearest) to 1.0f (farthest).
/// The value to which the stencil buffer will be set. Must be a valid stencil value supported by the format.
void ClearDepthStencilView(Handle depthStencil, bool inlcludeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0);
///
/// Begins a render pass with the specified render Target
///
/// Render Target descriptions
/// Depth stencil description
/// Whether UAV writes are allowed during the render pass
void BeginRenderPass(ReadOnlySpan rtDescs, ref readonly PassDepthStencilDesc depthDesc, bool allowUAVWrites = false);
///
/// Ends the current render pass
///
void EndRenderPass();
///
/// Inserts multiple resource barriers.
///
/// Resource barrier descriptions
void Barrier(params ReadOnlySpan barrierDescs);
///
/// Sets the pipeline state object
///
/// Pipeline state to set
void SetPipelineState(Key128 pipelineKey);
///
/// Sets the constant buffer view for the specified slot in the graphics pipeline.
///
/// The zero-based index of the slot to bind the constant buffer view to.
/// A graphics buffer to use as the constant buffer view.
void SetConstantBufferView(uint slot, Handle buffer);
///
/// Binds a vertex buffer to the specified slot for subsequent draw calls.
///
/// The vertex buffer slot to bind to.
/// The handle to the graphics buffer containing vertex data.
/// The Offset in bytes from the start of the buffer.
void SetVertexBuffer(uint slot, Handle buffer, ulong offset = 0);
///
/// Binds an index buffer for indexed drawing.
///
/// The handle to the graphics buffer containing index data.
/// The space of indices (e.g., 16-bit or 32-bit).
/// The Offset in bytes from the start of the buffer.
void SetIndexBuffer(Handle buffer, IndexType type, ulong offset = 0);
///
/// Sets the primitive topology to be used for subsequent drawing operations.
///
/// The primitive topology that determines how the input vertices are interpreted during rendering.
void SetPrimitiveTopology(PrimitiveTopology topology);
///
/// Sets a 32-bit constant value in the graphics root signature at the specified index.
///
/// The zero-based index of the root parameter in the graphics root signature to set the constant for.
/// A read-only span containing the 32-bit constant values to set.
/// The Offset, in 32-bit values, from the start of the root parameter where the constants will be set.
void SetGraphicsRoot32Constants(uint rootIndex, ReadOnlySpan constantBuffer, uint offsetIn32Bits = 0);
void SetProgram(ref readonly SetProgramDesc desc);
///
/// Issues a non-indexed draw call.
///
/// Number of vertices to draw.
/// Number of instances to draw.
/// Index of the first vertex to draw.
/// Index of the first instance to draw.
void Draw(uint vertexCount, uint instanceCount = 1, uint startVertex = 0, uint startInstance = 0);
///
/// Issues an indexed draw call.
///
/// Number of indices to draw.
/// Number of instances to draw.
/// Index of the first index to draw.
/// Value added to each index before indexing the vertex buffer.
/// Index of the first instance to draw.
void DrawIndexed(uint indexCount, uint instanceCount = 1, uint startIndex = 0, int baseVertex = 0, uint startInstance = 0);
///
/// Dispatches compute threads
///
/// Thread groups in X dimension
/// Thread groups in Y dimension
/// Thread groups in Z dimension
void DispatchCompute(uint threadGroupCountX, uint threadGroupCountY, uint threadGroupCountZ);
///
/// Dispatches mesh shader threads
///
/// Thread groups in X dimension
/// Thread groups in Y dimension
/// Thread groups in Z dimension
void DispatchMesh(uint threadGroupCountX, uint threadGroupCountY, uint threadGroupCountZ);
///
/// Dispatches ray tracing threads
///
void DispatchRay();
void DispatchGraph(ref readonly DispatchGraphDesc desc);
///
/// Executes a sequence of GPU commands indirectly using the specified command signature and argument buffers.
///
/// The command signature that defines the layout and type of commands to execute.
/// A handle to the GPU buffer containing the arguments for each command.
/// The byte offset within the argument buffer at which to begin reading command arguments.
/// A handle to the GPU buffer that specifies the number of commands to execute.
/// The byte offset within the count buffer at which to read the command count.
void ExecuteIndirect(ICommandSignature commandSignature, Handle argumentBuffer, ulong argumentOffset, Handle countBuffer, ulong countBufferOffset);
///
/// Copies a specified number of bytes from the source graphics buffer to the destination graphics buffer.
///
/// The handle to the destination graphics buffer where data will be written.
/// The handle to the source graphics buffer from which data will be read.
/// The byte Offset in the destination buffer at which to begin writing. Must be zero or greater.
/// The byte Offset in the source buffer at which to begin reading. Must be zero or greater.
/// The number of bytes to copy. If zero, copies the remaining bytes from the source buffer starting at .
void CopyBuffer(Handle dest, Handle src, ulong destOffset = 0, ulong srcOffset = 0, ulong numBytes = 0);
///
/// Copies a region of a source texture to a destination texture. The source and destination regions can be specified to copy a subset of the textures, or the entire textures if the regions are null.
///
/// The handle to the destination texture where data will be written.
/// The region of the destination texture to copy to. If null, the entire texture will be used.
/// The handle to the source texture from which data will be read.
/// The region of the source texture to copy from. If null, the entire texture will be used.
void CopyTexture(Handle dst, TextureRegion? dstRegion, Handle src, TextureRegion? srcRegion);
///
/// Updates the subresources of a GPU resource using data from the specified intermediate resource and subresource data spans.
///
/// A handle to the destination GPU resource whose subresources will be updated.
/// A handle to an intermediate GPU resource used to stage the subresource data before copying to the destination resource.
/// A span containing the data for each subresource to update. Each element represents a subresource and its associated data.
void UpdateSubResources(Handle resource, Handle intermediate, params ReadOnlySpan subResources);
}