using Ghost.Graphics.D3D12; using Ghost.Graphics.Data; using Misaki.HighPerformance.LowLevel.Utilities; using System.Drawing; namespace Ghost.Graphics.RHI; /// /// D3D12-style command buffer interface for recording rendering commands /// public interface ICommandBuffer : IDisposable { public CommandBufferType Type { get; } /// /// Begins recording commands into this command buffer /// public void Begin(); /// /// Ends recording commands and prepares for submission /// public void End(); /// /// Begins a render pass with the specified render target /// /// Render target to render into /// Color to clear the render target with public void BeginRenderPass(IRenderTarget renderTarget, Color128 clearColor); /// /// Ends the current render pass /// public void EndRenderPass(); /// /// Sets the viewport for rendering /// /// Viewport to set public void SetViewport(ViewportDesc viewport); /// /// Sets the scissor rectangle /// /// Scissor rectangle to set public void SetScissorRect(RectDesc rect); /// /// Inserts a resource barrier for state transitions /// /// Resource to transition /// Current resource state /// Target resource state public void ResourceBarrier(IResource resource, ResourceState before, ResourceState after); /// /// Sets the graphics root signature /// /// Root signature to set public void SetGraphicsRootSignature(IRootSignature rootSignature); /// /// Sets the pipeline state object /// /// Pipeline state to set public void SetPipelineState(IPipelineStateController pipelineState); /// /// Renders the specified mesh using the provided material. /// /// The mesh to be drawn. Must not be null. /// The material to use for rendering the mesh. Must not be null. public void DrawMesh(MeshClass mesh, MaterialClass material); /// /// Dispatches compute threads /// /// Thread groups in X dimension /// Thread groups in Y dimension /// Thread groups in Z dimension public void Dispatch(uint threadGroupCountX, uint threadGroupCountY = 1, uint threadGroupCountZ = 1); /// /// Uploads the specified data to the buffer represented by the given handle. /// /// The unmanaged value type of the elements to upload to the buffer. /// A handle to the buffer that will receive the uploaded data. /// A read-only span containing the data to upload to the buffer. The span must contain elements of type /// . public void Upload(BufferHandle buffer, ReadOnlySpan data) where T : unmanaged; /// /// Uploads texture data to the specified texture resource starting at the given subresource index. /// /// The texture resource to which the subresource data will be uploaded. Must be a valid, initialized texture handle. /// The index of the first subresource in the texture to receive data. Must be less than the total number of subresources in the texture. /// A reference to the structure containing the subresource data to upload. The data must match the format and layout expected by the texture. /// The number of subresources to upload, starting from . /// Must be greater than zero and not exceed the remaining subresources in the texture. public void Upload(TextureHandle texture, uint firstSubresource, ref SubResourceData subresources, uint numSubresources); } /// /// Viewport description /// public struct ViewportDesc { public float x; public float y; public float width; public float height; public float minDepth; public float maxDepth; public ViewportDesc(float width, float height) { x = 0; y = 0; this.width = width; this.height = height; minDepth = 0.0f; maxDepth = 1.0f; } } /// /// Rectangle description /// public struct RectDesc { public int Left; public int Top; public int Right; public int Bottom; public RectDesc(int left, int top, int right, int bottom) { Left = left; Top = top; Right = right; Bottom = bottom; } } /// /// Resource states /// [Flags] public enum ResourceState { Common = 0, VertexAndConstantBuffer = 1 << 0, IndexBuffer = 1 << 1, RenderTarget = 1 << 2, UnorderedAccess = 1 << 3, DepthWrite = 1 << 4, DepthRead = 1 << 5, PixelShaderResource = 1 << 6, CopyDest = 1 << 7, CopySource = 1 << 8, GenericRead = 1 << 9, IndirectArgument = 1 << 10, Present = 0, } public struct SubResourceData { public unsafe void* pData; public nint rowPitch; public nint slicePitch; }