180 lines
8.4 KiB
C
180 lines
8.4 KiB
C
#pragma once
|
|
|
|
#include <Core/Common/String.h>
|
|
#include <Core/HAL/Display/Display.h>
|
|
#include <Core/Math/Shape.h>
|
|
#include <Graphics/GraphicsBuffer.h>
|
|
#include <Graphics/GraphicsConfig.h>
|
|
#include <Graphics/GraphicsPipeline.h>
|
|
#include <Graphics/RenderPass.h>
|
|
#include <Graphics/Shader.h>
|
|
#include <Juliet.h>
|
|
|
|
// Graphics Interface
|
|
// Opaque types
|
|
typedef struct CommandList CommandList;
|
|
typedef struct GraphicsDevice GraphicsDevice;
|
|
typedef struct Fence Fence;
|
|
|
|
// Parameters of an indirect draw command
|
|
typedef struct IndirectDrawCommand IndirectDrawCommand;
|
|
struct IndirectDrawCommand
|
|
{
|
|
uint32 VertexCount; // Number of vertices to draw
|
|
uint32 InstanceCount; // Number of instanced to draw
|
|
uint32 FirstVertex; // Index of the first vertex to draw
|
|
uint32 FirstInstance; // ID of the first instance to draw
|
|
};
|
|
|
|
// Parameters of an INDEXED indirect draw command
|
|
typedef struct IndexedIndirectDrawCommand IndexedIndirectDrawCommand;
|
|
struct IndexedIndirectDrawCommand
|
|
{
|
|
uint32 VertexCount; // Number of vertices to draw
|
|
uint32 InstanceCount; // Number of instanced to draw
|
|
uint32 FirstIndex; // Base Index within the index buffer
|
|
int32 VertexOffset; // Offset the vertex index into the buffer
|
|
uint32 FirstInstance; // ID of the first instance to draw
|
|
};
|
|
|
|
// Parameters of an INDEXED Indirect Dispatch Command
|
|
typedef struct IndirectDispatchCommand IndirectDispatchCommand;
|
|
struct IndirectDispatchCommand
|
|
{
|
|
uint32 X_WorkGroupCount; // Number of Workgroup to dispatch on dimension X
|
|
uint32 Y_WorkGroupCount; // Number of Workgroup to dispatch on dimension Y
|
|
uint32 Z_WorkGroupCount; // Number of Workgroup to dispatch on dimension Z
|
|
};
|
|
|
|
typedef uint8 QueueType;
|
|
enum QueueType_Enum
|
|
{
|
|
QueueType_Graphics = 0,
|
|
QueueType_Compute,
|
|
QueueType_Copy,
|
|
QueueType_Count
|
|
};
|
|
|
|
typedef uint8 IndexFormat;
|
|
enum IndexFormat_Enum
|
|
{
|
|
IndexFormat_UInt16,
|
|
IndexFormat_UInt32
|
|
};
|
|
|
|
typedef uint8 SwapChainComposition;
|
|
enum SwapChainComposition_Enum
|
|
{
|
|
SwapChainComposition_SDR,
|
|
SwapChainComposition_SDR_LINEAR,
|
|
SwapChainComposition_HDR_EXTENDED_LINEAR,
|
|
SwapChainComposition_HDR10_ST2084
|
|
};
|
|
|
|
// PresentMode from highest to lowest latency
|
|
// Vsync prevents tearing. Enqueue ready images.
|
|
// Mailbox prevents tearing. When image is ready, replace any pending image
|
|
// Immediate replace current image as soon as possible. Can cause tearing
|
|
typedef uint8 PresentMode;
|
|
enum PresentMode_Enum
|
|
{
|
|
PresentMode_VSync,
|
|
PresentMode_Mailbox,
|
|
PresentMode_Immediate
|
|
};
|
|
|
|
typedef struct GraphicsViewPort GraphicsViewPort;
|
|
struct GraphicsViewPort
|
|
{
|
|
float X;
|
|
float Y;
|
|
float Width;
|
|
float Height;
|
|
float MinDepth;
|
|
float MaxDepth;
|
|
};
|
|
|
|
extern JULIET_API GraphicsDevice* CreateGraphicsDevice(GraphicsConfig config);
|
|
extern JULIET_API void DestroyGraphicsDevice(GraphicsDevice* device);
|
|
|
|
// Attach To Window
|
|
extern JULIET_API bool8 AttachToWindow(GraphicsDevice* device, Window* window);
|
|
extern JULIET_API void DetachFromWindow(GraphicsDevice* device, Window* window);
|
|
|
|
// SwapChain
|
|
extern JULIET_API bool8 AcquireSwapChainTexture(CommandList* commandList, Window* window, Texture** swapChainTexture);
|
|
extern JULIET_API bool8 WaitAndAcquireSwapChainTexture(CommandList* commandList, Window* window, Texture** swapChainTexture);
|
|
extern JULIET_API bool8 WaitForSwapchain(GraphicsDevice* device, Window* window);
|
|
extern JULIET_API TextureFormat GetSwapChainTextureFormat(GraphicsDevice* device, Window* window);
|
|
|
|
// Textures
|
|
extern JULIET_API Texture* CreateTexture(GraphicsDevice* device, const TextureCreateInfo* createInfo);
|
|
extern JULIET_API void DestroyTexture(GraphicsDevice* device, Texture* texture);
|
|
|
|
// Command List
|
|
extern JULIET_API CommandList* AcquireCommandList(GraphicsDevice* device, QueueType queueType);
|
|
extern JULIET_API void SubmitCommandLists(CommandList* commandList);
|
|
|
|
// RenderPass
|
|
extern JULIET_API RenderPass* BeginRenderPass(CommandList* commandList, const ColorTargetInfo* colorTargetInfo,
|
|
DepthStencilTargetInfo* depthStencilTargetInfo);
|
|
extern JULIET_API RenderPass* BeginRenderPassTargets(CommandList* commandList,
|
|
const ColorTargetInfo* colorTargetInfos, uint32 colorTargetInfoCount,
|
|
DepthStencilTargetInfo* depthStencilTargetInfo);
|
|
extern JULIET_API void EndRenderPass(RenderPass* renderPass);
|
|
|
|
extern JULIET_API void SetGraphicsViewPort(RenderPass* renderPass, const GraphicsViewPort* viewPort);
|
|
extern JULIET_API void SetScissorRect(RenderPass* renderPass, const struct Rectangle* rectangle);
|
|
extern JULIET_API void SetBlendConstants(RenderPass* renderPass, FColor blendConstants);
|
|
extern JULIET_API void SetStencilReference(RenderPass* renderPass, uint8 reference);
|
|
|
|
extern JULIET_API void BindGraphicsPipeline(RenderPass* renderPass, GraphicsPipeline* graphicsPipeline);
|
|
extern JULIET_API void DrawPrimitives(RenderPass* renderPass, uint32 numVertices, uint32 numInstances,
|
|
uint32 firstVertex, uint32 firstInstance);
|
|
extern JULIET_API void DrawIndexedPrimitives(RenderPass* renderPass, uint32 numIndices, uint32 numInstances,
|
|
uint32 firstIndex, uint32 vertexOffset, uint32 firstInstance);
|
|
|
|
extern JULIET_API void SetIndexBuffer(CommandList* commandList, GraphicsBuffer* buffer,
|
|
IndexFormat format, size_t indexCount, index_t offset);
|
|
|
|
extern JULIET_API void SetPushConstants(CommandList* commandList, ShaderStage stage,
|
|
uint32 rootParameterIndex, uint32 numConstants, const void* constants);
|
|
|
|
// Fences
|
|
extern JULIET_API bool8 WaitUntilGPUIsIdle(GraphicsDevice* device);
|
|
|
|
// Shaders
|
|
extern JULIET_API Shader* CreateShader(GraphicsDevice* device, String filename, ShaderCreateInfo* shaderCreateInfo);
|
|
extern JULIET_API void DestroyShader(GraphicsDevice* device, Shader* shader);
|
|
|
|
// Pipelines
|
|
extern JULIET_API GraphicsPipeline* CreateGraphicsPipeline(GraphicsDevice* device,
|
|
const GraphicsPipelineCreateInfo* createInfo);
|
|
extern JULIET_API void DestroyGraphicsPipeline(GraphicsDevice* device, GraphicsPipeline* graphicsPipeline);
|
|
#if ALLOW_SHADER_HOT_RELOAD
|
|
// Allows updating the graphics pipeline shaders. Can update either one or both shaders.
|
|
extern JULIET_API bool8 UpdateGraphicsPipelineShaders(GraphicsDevice* device, GraphicsPipeline* graphicsPipeline,
|
|
Shader* optional_vertexShader, Shader* optional_fragmentShader);
|
|
#endif
|
|
|
|
// Buffers
|
|
extern JULIET_API GraphicsBuffer* CreateGraphicsBuffer(GraphicsDevice* device, const BufferCreateInfo* createInfo);
|
|
extern JULIET_API GraphicsTransferBuffer* CreateGraphicsTransferBuffer(GraphicsDevice* device,
|
|
const TransferBufferCreateInfo* createInfo);
|
|
extern JULIET_API void* MapGraphicsBuffer(GraphicsDevice* device, GraphicsBuffer* buffer);
|
|
extern JULIET_API void UnmapGraphicsBuffer(GraphicsDevice* device, GraphicsBuffer* buffer);
|
|
extern JULIET_API void* MapGraphicsTransferBuffer(GraphicsDevice* device, GraphicsTransferBuffer* buffer);
|
|
extern JULIET_API void UnmapGraphicsTransferBuffer(GraphicsDevice* device, GraphicsTransferBuffer* buffer);
|
|
extern JULIET_API void CopyBuffer(CommandList* commandList, GraphicsBuffer* dst,
|
|
GraphicsTransferBuffer* src, size_t size, size_t dstOffset,
|
|
size_t srcOffset);
|
|
extern JULIET_API void CopyBufferToTexture(CommandList* commandList, Texture* dst,
|
|
GraphicsTransferBuffer* src);
|
|
|
|
extern JULIET_API void TransitionBufferToReadable(CommandList* commandList, GraphicsBuffer* buffer);
|
|
extern JULIET_API uint32 GetBufferDescriptorIndex(GraphicsDevice* device, GraphicsBuffer* buffer);
|
|
extern JULIET_API uint32 GetTextureDescriptorIndex(GraphicsDevice* device, Texture* texture);
|
|
|
|
extern JULIET_API void DestroyGraphicsBuffer(GraphicsDevice* device, GraphicsBuffer* buffer);
|
|
extern JULIET_API void DestroyGraphicsTransferBuffer(GraphicsDevice* device, GraphicsTransferBuffer* buffer);
|