Compare commits

..

2 Commits

Author SHA1 Message Date
cosmonaut bb948846c0 memory fixes 2022-02-18 22:22:45 -08:00
cosmonaut 209b4ae6dd start rework of submission flow 2022-02-18 19:05:18 -08:00
9 changed files with 4281 additions and 5490 deletions

View File

@ -1,13 +0,0 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
[*.{c,h}]
charset = utf-8-bom
max_line_length = 100

View File

@ -7,8 +7,8 @@ project(Refresh C)
option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_SHARED_LIBS "Build shared library" ON)
# Version # Version
SET(LIB_MAJOR_VERSION "1") SET(LIB_MAJOR_VERSION "0")
SET(LIB_MINOR_VERSION "5") SET(LIB_MINOR_VERSION "1")
SET(LIB_REVISION "0") SET(LIB_REVISION "0")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}") SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")

View File

@ -1,4 +1,4 @@
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities /* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
* *
* Copyright (c) 2020 Evan Hemsley * Copyright (c) 2020 Evan Hemsley
* *
@ -52,27 +52,16 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* Version API */
#define REFRESH_MAJOR_VERSION 1
#define REFRESH_MINOR_VERSION 5
#define REFRESH_PATCH_VERSION 0
#define REFRESH_COMPILED_VERSION ( \
(REFRESH_MAJOR_VERSION * 100 * 100) + \
(REFRESH_MINOR_VERSION * 100) + \
(REFRESH_PATCH_VERSION) \
)
REFRESHAPI uint32_t Refresh_LinkedVersion(void);
/* Type Declarations */ /* Type Declarations */
typedef struct Refresh_Device Refresh_Device; typedef struct Refresh_Device Refresh_Device;
typedef struct Refresh_Buffer Refresh_Buffer; typedef struct Refresh_Buffer Refresh_Buffer;
typedef struct Refresh_Texture Refresh_Texture; typedef struct Refresh_Texture Refresh_Texture;
typedef struct Refresh_Sampler Refresh_Sampler; typedef struct Refresh_Sampler Refresh_Sampler;
typedef struct Refresh_RenderTarget Refresh_RenderTarget;
typedef struct Refresh_Framebuffer Refresh_Framebuffer;
typedef struct Refresh_ShaderModule Refresh_ShaderModule; typedef struct Refresh_ShaderModule Refresh_ShaderModule;
typedef struct Refresh_RenderPass Refresh_RenderPass;
typedef struct Refresh_ComputePipeline Refresh_ComputePipeline; typedef struct Refresh_ComputePipeline Refresh_ComputePipeline;
typedef struct Refresh_GraphicsPipeline Refresh_GraphicsPipeline; typedef struct Refresh_GraphicsPipeline Refresh_GraphicsPipeline;
typedef struct Refresh_CommandBuffer Refresh_CommandBuffer; typedef struct Refresh_CommandBuffer Refresh_CommandBuffer;
@ -87,7 +76,7 @@ typedef enum Refresh_PresentMode
typedef enum Refresh_PrimitiveType typedef enum Refresh_PrimitiveType
{ {
REFRESH_PRIMITIVETYPE_POINTLIST, REFRESH_PRIMITIVETYPE_POINTLIST,
REFRESH_PRIMITIVETYPE_LINELIST, REFRESH_PRIMITIVETYPE_LINELIST,
REFRESH_PRIMITIVETYPE_LINESTRIP, REFRESH_PRIMITIVETYPE_LINESTRIP,
REFRESH_PRIMITIVETYPE_TRIANGLELIST, REFRESH_PRIMITIVETYPE_TRIANGLELIST,
@ -96,52 +85,59 @@ typedef enum Refresh_PrimitiveType
typedef enum Refresh_LoadOp typedef enum Refresh_LoadOp
{ {
REFRESH_LOADOP_LOAD, REFRESH_LOADOP_LOAD,
REFRESH_LOADOP_CLEAR, REFRESH_LOADOP_CLEAR,
REFRESH_LOADOP_DONT_CARE REFRESH_LOADOP_DONT_CARE
} Refresh_LoadOp; } Refresh_LoadOp;
typedef enum Refresh_StoreOp typedef enum Refresh_StoreOp
{ {
REFRESH_STOREOP_STORE, REFRESH_STOREOP_STORE,
REFRESH_STOREOP_DONT_CARE REFRESH_STOREOP_DONT_CARE
} Refresh_StoreOp; } Refresh_StoreOp;
typedef enum Refresh_ClearOptionsBits
{
REFRESH_CLEAROPTIONS_COLOR = 0x00000001,
REFRESH_CLEAROPTIONS_DEPTH = 0x00000002,
REFRESH_CLEAROPTIONS_STENCIL = 0x00000004,
} Refresh_ClearOptionsBits;
typedef uint32_t Refresh_ClearOptions;
typedef enum Refresh_IndexElementSize typedef enum Refresh_IndexElementSize
{ {
REFRESH_INDEXELEMENTSIZE_16BIT, REFRESH_INDEXELEMENTSIZE_16BIT,
REFRESH_INDEXELEMENTSIZE_32BIT REFRESH_INDEXELEMENTSIZE_32BIT
} Refresh_IndexElementSize; } Refresh_IndexElementSize;
typedef enum Refresh_TextureFormat typedef enum Refresh_TextureFormat
{ {
/* Color Formats */ /* Color Formats */
REFRESH_TEXTUREFORMAT_R8G8B8A8, REFRESH_TEXTUREFORMAT_R8G8B8A8,
REFRESH_TEXTUREFORMAT_B8G8R8A8, REFRESH_TEXTUREFORMAT_R5G6B5,
REFRESH_TEXTUREFORMAT_R5G6B5, REFRESH_TEXTUREFORMAT_A1R5G5B5,
REFRESH_TEXTUREFORMAT_A1R5G5B5, REFRESH_TEXTUREFORMAT_B4G4R4A4,
REFRESH_TEXTUREFORMAT_B4G4R4A4, REFRESH_TEXTUREFORMAT_BC1,
REFRESH_TEXTUREFORMAT_BC1, REFRESH_TEXTUREFORMAT_BC2,
REFRESH_TEXTUREFORMAT_BC2, REFRESH_TEXTUREFORMAT_BC3,
REFRESH_TEXTUREFORMAT_BC3, REFRESH_TEXTUREFORMAT_R8G8_SNORM,
REFRESH_TEXTUREFORMAT_BC7, REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM,
REFRESH_TEXTUREFORMAT_R8G8_SNORM, REFRESH_TEXTUREFORMAT_A2R10G10B10,
REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM, REFRESH_TEXTUREFORMAT_R16G16,
REFRESH_TEXTUREFORMAT_A2R10G10B10, REFRESH_TEXTUREFORMAT_R16G16B16A16,
REFRESH_TEXTUREFORMAT_R16G16, REFRESH_TEXTUREFORMAT_R8,
REFRESH_TEXTUREFORMAT_R16G16B16A16, REFRESH_TEXTUREFORMAT_R32_SFLOAT,
REFRESH_TEXTUREFORMAT_R8, REFRESH_TEXTUREFORMAT_R32G32_SFLOAT,
REFRESH_TEXTUREFORMAT_R32_SFLOAT, REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT,
REFRESH_TEXTUREFORMAT_R32G32_SFLOAT, REFRESH_TEXTUREFORMAT_R16_SFLOAT,
REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT, REFRESH_TEXTUREFORMAT_R16G16_SFLOAT,
REFRESH_TEXTUREFORMAT_R16_SFLOAT, REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT,
REFRESH_TEXTUREFORMAT_R16G16_SFLOAT,
REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT,
/* Depth Formats */ /* Depth Formats */
REFRESH_TEXTUREFORMAT_D16_UNORM, REFRESH_TEXTUREFORMAT_D16_UNORM,
REFRESH_TEXTUREFORMAT_D32_SFLOAT, REFRESH_TEXTUREFORMAT_D32_SFLOAT,
REFRESH_TEXTUREFORMAT_D16_UNORM_S8_UINT, REFRESH_TEXTUREFORMAT_D16_UNORM_S8_UINT,
REFRESH_TEXTUREFORMAT_D32_SFLOAT_S8_UINT REFRESH_TEXTUREFORMAT_D32_SFLOAT_S8_UINT
} Refresh_TextureFormat; } Refresh_TextureFormat;
typedef enum Refresh_TextureUsageFlagBits typedef enum Refresh_TextureUsageFlagBits
@ -166,12 +162,12 @@ typedef enum Refresh_SampleCount
typedef enum Refresh_CubeMapFace typedef enum Refresh_CubeMapFace
{ {
REFRESH_CUBEMAPFACE_POSITIVEX, REFRESH_CUBEMAPFACE_POSITIVEX,
REFRESH_CUBEMAPFACE_NEGATIVEX, REFRESH_CUBEMAPFACE_NEGATIVEX,
REFRESH_CUBEMAPFACE_POSITIVEY, REFRESH_CUBEMAPFACE_POSITIVEY,
REFRESH_CUBEMAPFACE_NEGATIVEY, REFRESH_CUBEMAPFACE_NEGATIVEY,
REFRESH_CUBEMAPFACE_POSITIVEZ, REFRESH_CUBEMAPFACE_POSITIVEZ,
REFRESH_CUBEMAPFACE_NEGATIVEZ REFRESH_CUBEMAPFACE_NEGATIVEZ
} Refresh_CubeMapFace; } Refresh_CubeMapFace;
typedef enum Refresh_BufferUsageFlagBits typedef enum Refresh_BufferUsageFlagBits
@ -185,8 +181,7 @@ typedef uint32_t Refresh_BufferUsageFlags;
typedef enum Refresh_VertexElementFormat typedef enum Refresh_VertexElementFormat
{ {
REFRESH_VERTEXELEMENTFORMAT_UINT, REFRESH_VERTEXELEMENTFORMAT_SINGLE,
REFRESH_VERTEXELEMENTFORMAT_FLOAT,
REFRESH_VERTEXELEMENTFORMAT_VECTOR2, REFRESH_VERTEXELEMENTFORMAT_VECTOR2,
REFRESH_VERTEXELEMENTFORMAT_VECTOR3, REFRESH_VERTEXELEMENTFORMAT_VECTOR3,
REFRESH_VERTEXELEMENTFORMAT_VECTOR4, REFRESH_VERTEXELEMENTFORMAT_VECTOR4,
@ -209,14 +204,16 @@ typedef enum Refresh_VertexInputRate
typedef enum Refresh_FillMode typedef enum Refresh_FillMode
{ {
REFRESH_FILLMODE_FILL, REFRESH_FILLMODE_FILL,
REFRESH_FILLMODE_LINE REFRESH_FILLMODE_LINE,
REFRESH_FILLMODE_POINT
} Refresh_FillMode; } Refresh_FillMode;
typedef enum Refresh_CullMode typedef enum Refresh_CullMode
{ {
REFRESH_CULLMODE_NONE, REFRESH_CULLMODE_NONE,
REFRESH_CULLMODE_FRONT, REFRESH_CULLMODE_FRONT,
REFRESH_CULLMODE_BACK REFRESH_CULLMODE_BACK,
REFRESH_CULLMODE_FRONT_AND_BACK
} Refresh_CullMode; } Refresh_CullMode;
typedef enum Refresh_FrontFace typedef enum Refresh_FrontFace
@ -258,41 +255,70 @@ typedef enum Refresh_BlendOp
REFRESH_BLENDOP_MAX REFRESH_BLENDOP_MAX
} Refresh_BlendOp; } Refresh_BlendOp;
typedef enum Refresh_LogicOp
{
REFRESH_LOGICOP_CLEAR = 0,
REFRESH_LOGICOP_AND = 1,
REFRESH_LOGICOP_AND_REVERSE = 2,
REFRESH_LOGICOP_COPY = 3,
REFRESH_LOGICOP_AND_INVERTED = 4,
REFRESH_LOGICOP_NO_OP = 5,
REFRESH_LOGICOP_XOR = 6,
REFRESH_LOGICOP_OR = 7,
REFRESH_LOGICOP_NOR = 8,
REFRESH_LOGICOP_EQUIVALENT = 9,
REFRESH_LOGICOP_INVERT = 10,
REFRESH_LOGICOP_OR_REVERSE = 11,
REFRESH_LOGICOP_COPY_INVERTED = 12,
REFRESH_LOGICOP_OR_INVERTED = 13,
REFRESH_LOGICOP_NAND = 14,
REFRESH_LOGICOP_SET = 15
} Refresh_LogicOp;
typedef enum Refresh_BlendFactor typedef enum Refresh_BlendFactor
{ {
REFRESH_BLENDFACTOR_ZERO, REFRESH_BLENDFACTOR_ZERO = 0,
REFRESH_BLENDFACTOR_ONE, REFRESH_BLENDFACTOR_ONE = 1,
REFRESH_BLENDFACTOR_SRC_COLOR, REFRESH_BLENDFACTOR_SRC_COLOR = 2,
REFRESH_BLENDFACTOR_ONE_MINUS_SRC_COLOR, REFRESH_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 3,
REFRESH_BLENDFACTOR_DST_COLOR, REFRESH_BLENDFACTOR_DST_COLOR = 4,
REFRESH_BLENDFACTOR_ONE_MINUS_DST_COLOR, REFRESH_BLENDFACTOR_ONE_MINUS_DST_COLOR = 5,
REFRESH_BLENDFACTOR_SRC_ALPHA, REFRESH_BLENDFACTOR_SRC_ALPHA = 6,
REFRESH_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, REFRESH_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 7,
REFRESH_BLENDFACTOR_DST_ALPHA, REFRESH_BLENDFACTOR_DST_ALPHA = 8,
REFRESH_BLENDFACTOR_ONE_MINUS_DST_ALPHA, REFRESH_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 9,
REFRESH_BLENDFACTOR_CONSTANT_COLOR, REFRESH_BLENDFACTOR_CONSTANT_COLOR = 10,
REFRESH_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR, REFRESH_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR = 11,
REFRESH_BLENDFACTOR_SRC_ALPHA_SATURATE, REFRESH_BLENDFACTOR_CONSTANT_ALPHA = 12,
REFRESH_BLENDFACTOR_SRC1_COLOR, REFRESH_BLENDFACTOR_ONE_MINUS_CONSTANT_ALPHA = 13,
REFRESH_BLENDFACTOR_ONE_MINUS_SRC1_COLOR, REFRESH_BLENDFACTOR_SRC_ALPHA_SATURATE = 14,
REFRESH_BLENDFACTOR_SRC1_ALPHA, REFRESH_BLENDFACTOR_SRC1_COLOR = 15,
REFRESH_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA REFRESH_BLENDFACTOR_ONE_MINUS_SRC1_COLOR = 16,
REFRESH_BLENDFACTOR_SRC1_ALPHA = 17,
REFRESH_BLENDFACTOR_ONE_MINUS_SRC1_ALPHA = 18
} Refresh_BlendFactor; } Refresh_BlendFactor;
typedef enum Refresh_ColorComponentFlagBits typedef enum Refresh_ColorComponentFlagBits
{ {
REFRESH_COLORCOMPONENT_R_BIT = 0x00000001, REFRESH_COLORCOMPONENT_R_BIT = 0x00000001,
REFRESH_COLORCOMPONENT_G_BIT = 0x00000002, REFRESH_COLORCOMPONENT_G_BIT = 0x00000002,
REFRESH_COLORCOMPONENT_B_BIT = 0x00000004, REFRESH_COLORCOMPONENT_B_BIT = 0x00000004,
REFRESH_COLORCOMPONENT_A_BIT = 0x00000008 REFRESH_COLORCOMPONENT_A_BIT = 0x00000008
} Refresh_ColorComponentFlagBits; } Refresh_ColorComponentFlagBits;
typedef uint32_t Refresh_ColorComponentFlags; typedef uint32_t Refresh_ColorComponentFlags;
typedef enum Refresh_ShaderStageType
{
REFRESH_SHADERSTAGE_VERTEX,
REFRESH_SHADERSTAGE_FRAGMENT
} Refresh_ShaderStageType;
typedef enum Refresh_Filter typedef enum Refresh_Filter
{ {
REFRESH_FILTER_NEAREST, REFRESH_FILTER_NEAREST,
REFRESH_FILTER_LINEAR REFRESH_FILTER_LINEAR,
REFRESH_FILTER_CUBIC
} Refresh_Filter; } Refresh_Filter;
typedef enum Refresh_SamplerMipmapMode typedef enum Refresh_SamplerMipmapMode
@ -312,12 +338,12 @@ typedef enum Refresh_SamplerAddressMode
/* FIXME: we should probably make a library-level decision about color types */ /* FIXME: we should probably make a library-level decision about color types */
typedef enum Refresh_BorderColor typedef enum Refresh_BorderColor
{ {
REFRESH_BORDERCOLOR_FLOAT_TRANSPARENT_BLACK, REFRESH_BORDERCOLOR_FLOAT_TRANSPARENT_BLACK = 0,
REFRESH_BORDERCOLOR_INT_TRANSPARENT_BLACK, REFRESH_BORDERCOLOR_INT_TRANSPARENT_BLACK = 1,
REFRESH_BORDERCOLOR_FLOAT_OPAQUE_BLACK, REFRESH_BORDERCOLOR_FLOAT_OPAQUE_BLACK = 2,
REFRESH_BORDERCOLOR_INT_OPAQUE_BLACK, REFRESH_BORDERCOLOR_INT_OPAQUE_BLACK = 3,
REFRESH_BORDERCOLOR_FLOAT_OPAQUE_WHITE, REFRESH_BORDERCOLOR_FLOAT_OPAQUE_WHITE = 4,
REFRESH_BORDERCOLOR_INT_OPAQUE_WHITE REFRESH_BORDERCOLOR_INT_OPAQUE_WHITE = 5
} Refresh_BorderColor; } Refresh_BorderColor;
/* Structures */ /* Structures */
@ -423,7 +449,7 @@ typedef struct Refresh_StencilOpState
uint32_t reference; uint32_t reference;
} Refresh_StencilOpState; } Refresh_StencilOpState;
typedef struct Refresh_ColorAttachmentBlendState typedef struct Refresh_ColorTargetBlendState
{ {
uint8_t blendEnable; uint8_t blendEnable;
Refresh_BlendFactor srcColorBlendFactor; Refresh_BlendFactor srcColorBlendFactor;
@ -433,7 +459,7 @@ typedef struct Refresh_ColorAttachmentBlendState
Refresh_BlendFactor dstAlphaBlendFactor; Refresh_BlendFactor dstAlphaBlendFactor;
Refresh_BlendOp alphaBlendOp; Refresh_BlendOp alphaBlendOp;
Refresh_ColorComponentFlags colorWriteMask; Refresh_ColorComponentFlags colorWriteMask;
} Refresh_ColorAttachmentBlendState; } Refresh_ColorTargetBlendState;
typedef struct Refresh_ComputePipelineLayoutCreateInfo typedef struct Refresh_ComputePipelineLayoutCreateInfo
{ {
@ -441,6 +467,36 @@ typedef struct Refresh_ComputePipelineLayoutCreateInfo
uint32_t imageBindingCount; uint32_t imageBindingCount;
} Refresh_ComputePipelineLayoutCreateInfo; } Refresh_ComputePipelineLayoutCreateInfo;
typedef struct Refresh_GraphicsPipelineLayoutCreateInfo
{
uint32_t vertexSamplerBindingCount;
uint32_t fragmentSamplerBindingCount;
} Refresh_GraphicsPipelineLayoutCreateInfo;
typedef struct Refresh_ColorTargetDescription
{
Refresh_TextureFormat format;
Refresh_SampleCount multisampleCount;
Refresh_LoadOp loadOp;
Refresh_StoreOp storeOp;
} Refresh_ColorTargetDescription;
typedef struct Refresh_DepthStencilTargetDescription
{
Refresh_TextureFormat depthStencilFormat;
Refresh_LoadOp loadOp;
Refresh_StoreOp storeOp;
Refresh_LoadOp stencilLoadOp;
Refresh_StoreOp stencilStoreOp;
} Refresh_DepthStencilTargetDescription;
typedef struct Refresh_RenderPassCreateInfo
{
const Refresh_ColorTargetDescription *colorTargetDescriptions;
uint32_t colorTargetCount;
const Refresh_DepthStencilTargetDescription *depthTargetDescription; /* can be NULL */
} Refresh_RenderPassCreateInfo;
typedef struct Refresh_ShaderModuleCreateInfo typedef struct Refresh_ShaderModuleCreateInfo
{ {
size_t codeSize; size_t codeSize;
@ -461,22 +517,20 @@ typedef struct Refresh_TextureCreateInfo
/* Pipeline state structures */ /* Pipeline state structures */
typedef struct Refresh_GraphicsShaderInfo typedef struct Refresh_ShaderStageState
{ {
Refresh_ShaderModule *shaderModule; Refresh_ShaderModule *shaderModule;
const char* entryPointName; const char* entryPointName;
uint64_t uniformBufferSize; uint64_t uniformBufferSize;
uint32_t samplerBindingCount; } Refresh_ShaderStageState;
} Refresh_GraphicsShaderInfo;
typedef struct Refresh_ComputeShaderInfo typedef struct Refresh_ViewportState
{ {
Refresh_ShaderModule* shaderModule; const Refresh_Viewport *viewports;
const char* entryPointName; uint32_t viewportCount;
uint64_t uniformBufferSize; const Refresh_Rect *scissors;
uint32_t bufferBindingCount; uint32_t scissorCount;
uint32_t imageBindingCount; } Refresh_ViewportState;
} Refresh_ComputeShaderInfo;
typedef struct Refresh_RasterizerState typedef struct Refresh_RasterizerState
{ {
@ -488,6 +542,7 @@ typedef struct Refresh_RasterizerState
float depthBiasConstantFactor; float depthBiasConstantFactor;
float depthBiasClamp; float depthBiasClamp;
float depthBiasSlopeFactor; float depthBiasSlopeFactor;
float lineWidth;
} Refresh_RasterizerState; } Refresh_RasterizerState;
typedef struct Refresh_MultisampleState typedef struct Refresh_MultisampleState
@ -509,60 +564,111 @@ typedef struct Refresh_DepthStencilState
float maxDepthBounds; float maxDepthBounds;
} Refresh_DepthStencilState; } Refresh_DepthStencilState;
typedef struct Refresh_ColorAttachmentDescription typedef struct Refresh_ColorBlendState
{ {
Refresh_TextureFormat format; uint8_t logicOpEnable;
Refresh_SampleCount sampleCount; Refresh_LogicOp logicOp;
Refresh_ColorAttachmentBlendState blendState; const Refresh_ColorTargetBlendState *blendStates;
} Refresh_ColorAttachmentDescription; uint32_t blendStateCount;
float blendConstants[4];
} Refresh_ColorBlendState;
typedef struct Refresh_GraphicsPipelineAttachmentInfo typedef struct Refresh_ComputePipelineCreateInfo
{ {
Refresh_ColorAttachmentDescription *colorAttachmentDescriptions; Refresh_ShaderStageState computeShaderState;
uint32_t colorAttachmentCount; Refresh_ComputePipelineLayoutCreateInfo pipelineLayoutCreateInfo;
uint8_t hasDepthStencilAttachment; } Refresh_ComputePipelineCreateInfo;
Refresh_TextureFormat depthStencilFormat;
} Refresh_GraphicsPipelineAttachmentInfo;
typedef struct Refresh_GraphicsPipelineCreateInfo typedef struct Refresh_GraphicsPipelineCreateInfo
{ {
Refresh_GraphicsShaderInfo vertexShaderInfo; Refresh_ShaderStageState vertexShaderState;
Refresh_GraphicsShaderInfo fragmentShaderInfo; Refresh_ShaderStageState fragmentShaderState;
Refresh_VertexInputState vertexInputState; Refresh_VertexInputState vertexInputState;
Refresh_PrimitiveType primitiveType; Refresh_PrimitiveType primitiveType;
Refresh_ViewportState viewportState;
Refresh_RasterizerState rasterizerState; Refresh_RasterizerState rasterizerState;
Refresh_MultisampleState multisampleState; Refresh_MultisampleState multisampleState;
Refresh_DepthStencilState depthStencilState; Refresh_DepthStencilState depthStencilState;
Refresh_GraphicsPipelineAttachmentInfo attachmentInfo; Refresh_ColorBlendState colorBlendState;
float blendConstants[4]; Refresh_GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo;
Refresh_RenderPass *renderPass;
} Refresh_GraphicsPipelineCreateInfo; } Refresh_GraphicsPipelineCreateInfo;
/* Render pass structures */ typedef struct Refresh_FramebufferCreateInfo
typedef struct Refresh_ColorAttachmentInfo
{ {
Refresh_Texture *texture; /* We can't use TextureSlice because render passes take a single rectangle. */ Refresh_RenderPass *renderPass;
uint32_t depth; Refresh_RenderTarget **pColorTargets;
uint32_t layer; uint32_t colorTargetCount;
uint32_t level; Refresh_RenderTarget *pDepthStencilTarget;
Refresh_SampleCount sampleCount; uint32_t width;
Refresh_Vec4 clearColor; /* Can be ignored by RenderPass */ uint32_t height;
Refresh_LoadOp loadOp; } Refresh_FramebufferCreateInfo;
Refresh_StoreOp storeOp;
} Refresh_ColorAttachmentInfo;
typedef struct Refresh_DepthStencilAttachmentInfo /* Interop Structs */
typedef enum Refresh_SysRendererType
{ {
Refresh_Texture *texture; /* We can't use TextureSlice because render passes take a single rectangle. */ REFRESH_RENDERER_TYPE_VULKAN
uint32_t depth; } Refresh_SysRendererType;
uint32_t layer;
uint32_t level; typedef struct Refresh_SysRenderer
Refresh_DepthStencilValue depthStencilClearValue; /* Can be ignored by RenderPass */ {
Refresh_LoadOp loadOp; Refresh_SysRendererType rendererType;
Refresh_StoreOp storeOp;
Refresh_LoadOp stencilLoadOp; union
Refresh_StoreOp stencilStoreOp; {
} Refresh_DepthStencilAttachmentInfo; #if REFRESH_DRIVER_VULKAN
struct
{
void* instance;
void* physicalDevice;
void* logicalDevice;
uint32_t queueFamilyIndex;
} vulkan;
#endif /* REFRESH_DRIVER_VULKAN */
uint8_t filler[64];
} renderer;
} Refresh_SysRenderer;
typedef struct Refresh_TextureHandles
{
Refresh_SysRendererType rendererType;
union
{
#if REFRESH_DRIVER_VULKAN
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define REFRESH_VULKAN_HANDLE_TYPE void*
#else
#define REFRESH_VULKAN_HANDLE_TYPE uint64_t
#endif
struct
{
REFRESH_VULKAN_HANDLE_TYPE image; /* VkImage */
REFRESH_VULKAN_HANDLE_TYPE view; /* VkImageView */
} vulkan;
#endif /* REFRESH_DRIVER_VULKAN */
uint8_t filler[64];
} texture;
} Refresh_TextureHandles;
/* Version API */
#define REFRESH_ABI_VERSION 0
#define REFRESH_MAJOR_VERSION 0
#define REFRESH_MINOR_VERSION 1
#define REFRESH_PATCH_VERSION 0
#define REFRESH_COMPILED_VERSION ( \
(REFRESH_ABI_VERSION * 100 * 100 * 100) + \
(REFRESH_MAJOR_VERSION * 100 * 100) + \
(REFRESH_MINOR_VERSION * 100) + \
(REFRESH_PATCH_VERSION) \
)
REFRESHAPI uint32_t Refresh_LinkedVersion(void);
/* Functions */ /* Functions */
@ -586,7 +692,8 @@ REFRESHAPI void Refresh_HookLogFunctions(
/* Create a rendering context for use on the calling thread. /* Create a rendering context for use on the calling thread.
* *
* presentationParameters: A window handle and presentation mode. * presentationParameters:
* If the windowHandle is NULL, Refresh will run in headless mode.
* debugMode: Enable debug mode properties. * debugMode: Enable debug mode properties.
*/ */
REFRESHAPI Refresh_Device* Refresh_CreateDevice( REFRESHAPI Refresh_Device* Refresh_CreateDevice(
@ -599,6 +706,30 @@ REFRESHAPI void Refresh_DestroyDevice(Refresh_Device *device);
/* Drawing */ /* Drawing */
/* Clears the targets of the currently bound framebuffer.
* If fewer colors are passed than the number of color targets in the
* framebuffer, this function will clear the first n color targets.
*
* NOTE:
* It is generally recommended to clear in BeginRenderPass
* rather than by calling this function unless necessary.
*
* clearRect: Area to clear.
* options: Bitflags to specify color/depth/stencil buffers for clearing.
* colors: An array of color values for the cleared color buffers.
* colorCount: The number of colors in the above array.
* depthStencil: Depth and stencil values for the cleared depth stencil buffer.
*/
REFRESHAPI void Refresh_Clear(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *clearRect,
Refresh_ClearOptions options,
Refresh_Vec4 *colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
);
/* Draws data from vertex/index buffers with instancing enabled. /* Draws data from vertex/index buffers with instancing enabled.
* *
* baseVertex: The starting offset to read from the vertex buffer. * baseVertex: The starting offset to read from the vertex buffer.
@ -671,10 +802,16 @@ REFRESHAPI void Refresh_DispatchCompute(
/* State Creation */ /* State Creation */
/* Returns an allocated RenderPass* object. */
REFRESHAPI Refresh_RenderPass* Refresh_CreateRenderPass(
Refresh_Device *device,
Refresh_RenderPassCreateInfo *renderPassCreateInfo
);
/* Returns an allocated ComputePipeline* object. */ /* Returns an allocated ComputePipeline* object. */
REFRESHAPI Refresh_ComputePipeline* Refresh_CreateComputePipeline( REFRESHAPI Refresh_ComputePipeline* Refresh_CreateComputePipeline(
Refresh_Device *device, Refresh_Device *device,
Refresh_ComputeShaderInfo *computeShaderInfo Refresh_ComputePipelineCreateInfo *pipelineCreateInfo
); );
/* Returns an allocated GraphicsPipeline* object. */ /* Returns an allocated GraphicsPipeline* object. */
@ -689,6 +826,12 @@ REFRESHAPI Refresh_Sampler* Refresh_CreateSampler(
Refresh_SamplerStateCreateInfo *samplerStateCreateInfo Refresh_SamplerStateCreateInfo *samplerStateCreateInfo
); );
/* Returns an allocated Framebuffer* object. */
REFRESHAPI Refresh_Framebuffer* Refresh_CreateFramebuffer(
Refresh_Device *device,
Refresh_FramebufferCreateInfo *framebufferCreateInfo
);
/* Returns an allocated ShaderModule* object. */ /* Returns an allocated ShaderModule* object. */
REFRESHAPI Refresh_ShaderModule* Refresh_CreateShaderModule( REFRESHAPI Refresh_ShaderModule* Refresh_CreateShaderModule(
Refresh_Device *device, Refresh_Device *device,
@ -703,6 +846,17 @@ REFRESHAPI Refresh_Texture* Refresh_CreateTexture(
Refresh_TextureCreateInfo *textureCreateInfo Refresh_TextureCreateInfo *textureCreateInfo
); );
/* Creates a color target.
*
* textureSlice: The texture slice that the color target will resolve to.
* multisampleCount: The MSAA value for the color target.
*/
REFRESHAPI Refresh_RenderTarget* Refresh_CreateRenderTarget(
Refresh_Device *device,
Refresh_TextureSlice *textureSlice,
Refresh_SampleCount multisampleCount
);
/* Creates a buffer. /* Creates a buffer.
* *
* usageFlags: Specifies how the buffer will be used. * usageFlags: Specifies how the buffer will be used.
@ -884,6 +1038,7 @@ REFRESHAPI void Refresh_GetBufferData(
*/ */
REFRESHAPI void Refresh_QueueDestroyTexture( REFRESHAPI void Refresh_QueueDestroyTexture(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture *texture Refresh_Texture *texture
); );
@ -896,6 +1051,7 @@ REFRESHAPI void Refresh_QueueDestroyTexture(
*/ */
REFRESHAPI void Refresh_QueueDestroySampler( REFRESHAPI void Refresh_QueueDestroySampler(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Sampler *sampler Refresh_Sampler *sampler
); );
@ -908,9 +1064,36 @@ REFRESHAPI void Refresh_QueueDestroySampler(
*/ */
REFRESHAPI void Refresh_QueueDestroyBuffer( REFRESHAPI void Refresh_QueueDestroyBuffer(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer Refresh_Buffer *buffer
); );
/* Sends a color target to be destroyed by the renderer. Note that we call it
* "QueueDestroy" because it may not be immediately destroyed by the renderer if
* this is not called from the main thread (for example, if a garbage collector
* deletes the resource instead of the programmer).
*
* renderTarget: The Refresh_ColorTarget to be destroyed.
*/
REFRESHAPI void Refresh_QueueDestroyRenderTarget(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_RenderTarget *renderTarget
);
/* Sends a framebuffer to be destroyed by the renderer. Note that we call it
* "QueueDestroy" because it may not be immediately destroyed by the renderer if
* this is not called from the main thread (for example, if a garbage collector
* deletes the resource instead of the programmer).
*
* framebuffer: The Refresh_Framebuffer to be destroyed.
*/
REFRESHAPI void Refresh_QueueDestroyFramebuffer(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Framebuffer *frameBuffer
);
/* Sends a shader module to be destroyed by the renderer. Note that we call it /* Sends a shader module to be destroyed by the renderer. Note that we call it
* "QueueDestroy" because it may not be immediately destroyed by the renderer if * "QueueDestroy" because it may not be immediately destroyed by the renderer if
* this is not called from the main thread (for example, if a garbage collector * this is not called from the main thread (for example, if a garbage collector
@ -920,9 +1103,23 @@ REFRESHAPI void Refresh_QueueDestroyBuffer(
*/ */
REFRESHAPI void Refresh_QueueDestroyShaderModule( REFRESHAPI void Refresh_QueueDestroyShaderModule(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_ShaderModule *shaderModule Refresh_ShaderModule *shaderModule
); );
/* Sends a render pass to be destroyed by the renderer. Note that we call it
* "QueueDestroy" because it may not be immediately destroyed by the renderer if
* this is not called from the main thread (for example, if a garbage collector
* deletes the resource instead of the programmer).
*
* renderPass: The Refresh_RenderPass to be destroyed.
*/
REFRESHAPI void Refresh_QueueDestroyRenderPass(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_RenderPass *renderPass
);
/* Sends a compute pipeline to be destroyed by the renderer. Note that we call it /* Sends a compute pipeline to be destroyed by the renderer. Note that we call it
* "QueueDestroy" because it may not be immediately destroyed by the renderer if * "QueueDestroy" because it may not be immediately destroyed by the renderer if
* this is not called from the main thread (for example, if a garbage collector * this is not called from the main thread (for example, if a garbage collector
@ -932,6 +1129,7 @@ REFRESHAPI void Refresh_QueueDestroyShaderModule(
*/ */
REFRESHAPI void Refresh_QueueDestroyComputePipeline( REFRESHAPI void Refresh_QueueDestroyComputePipeline(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_ComputePipeline *computePipeline Refresh_ComputePipeline *computePipeline
); );
@ -944,32 +1142,36 @@ REFRESHAPI void Refresh_QueueDestroyComputePipeline(
*/ */
REFRESHAPI void Refresh_QueueDestroyGraphicsPipeline( REFRESHAPI void Refresh_QueueDestroyGraphicsPipeline(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_GraphicsPipeline *graphicsPipeline Refresh_GraphicsPipeline *graphicsPipeline
); );
/* Graphics State */ /* Graphics State */
/* Begins a render pass. /* Begins a render pass.
* This will also set a default viewport and scissor state.
* *
* renderPass: The renderpass to begin.
* framebuffer: The framebuffer to bind for the render pass.
* renderArea: * renderArea:
* The area affected by the render pass. * The area affected by the render pass.
* All load, store and resolve operations are restricted * All load, store and resolve operations are restricted
* to the given rectangle. * to the given rectangle.
* If NULL, a sensible default will be chosen. * clearValues:
* colorAttachmentInfos: * A pointer to an array of Refresh_Color structures
* A pointer to an array of Refresh_ColorAttachmentInfo structures * that contains clear values for each color target in the
* that contains render targets and clear values. May be NULL. * framebuffer. May be NULL.
* colorAttachmentCount: The amount of structs in the above array. * clearCount: The amount of color structs in the above array.
* depthStencilAttachmentInfo: The depth/stencil render target and clear value. May be NULL. * depthStencilClearValue: The depth/stencil clear value. May be NULL.
*/ */
REFRESHAPI void Refresh_BeginRenderPass( REFRESHAPI void Refresh_BeginRenderPass(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_RenderPass *renderPass,
Refresh_Framebuffer *framebuffer,
Refresh_Rect *renderArea, Refresh_Rect *renderArea,
Refresh_ColorAttachmentInfo *colorAttachmentInfos, Refresh_Vec4 *pColorClearValues,
uint32_t colorAttachmentCount, uint32_t colorClearCount,
Refresh_DepthStencilAttachmentInfo *depthStencilAttachmentInfo Refresh_DepthStencilValue *depthStencilClearValue
); );
/* Ends the current render pass. */ /* Ends the current render pass. */
@ -985,20 +1187,6 @@ REFRESHAPI void Refresh_BindGraphicsPipeline(
Refresh_GraphicsPipeline *graphicsPipeline Refresh_GraphicsPipeline *graphicsPipeline
); );
/* Sets the current viewport state. */
REFRESHAPI void Refresh_SetViewport(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Viewport *viewport
);
/* Sets the current scissor state. */
REFRESHAPI void Refresh_SetScissor(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *scissor
);
/* Binds vertex buffers for use with subsequent draw calls. */ /* Binds vertex buffers for use with subsequent draw calls. */
REFRESHAPI void Refresh_BindVertexBuffers( REFRESHAPI void Refresh_BindVertexBuffers(
Refresh_Device *device, Refresh_Device *device,
@ -1102,29 +1290,23 @@ REFRESHAPI Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
uint8_t fixed uint8_t fixed
); );
/* Acquires a texture to use for presentation. /* Queues an image to be presented to a window.
* May return NULL under certain conditions. * The image will be presented upon the next Refresh_Submit call.
* If NULL, the user must ensure to not use the texture.
* Once a swapchain texture is acquired,
* it will automatically be presented on command buffer submission.
* *
* NOTE: * NOTE:
* It is not recommended to hold a reference to this texture long term. * It is an error to call this function in headless mode.
* *
* pWidth: A pointer to a uint32 that will be filled with the texture width. * textureSlice: The texture slice to present.
* pHeight: A pointer to a uint32 that will be filled with the texture height. * destinationRectangle: The region of the window to update. Can be NULL.
* filter: The filter to use if scaling is required.
* windowHandle: The window to present to.
*/ */
REFRESHAPI Refresh_Texture* Refresh_AcquireSwapchainTexture( REFRESHAPI void Refresh_QueuePresent(
Refresh_Device *device, Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
void *windowHandle, Refresh_TextureSlice *textureSlice,
uint32_t *pWidth, Refresh_Rect *destinationRectangle,
uint32_t *pHeight Refresh_Filter filter,
);
/* Returns the format of the swapchain for the given window. */
REFRESHAPI Refresh_TextureFormat Refresh_GetSwapchainFormat(
Refresh_Device *device,
void *windowHandle void *windowHandle
); );
@ -1135,7 +1317,7 @@ REFRESHAPI void Refresh_Submit(
Refresh_CommandBuffer **pCommandBuffers Refresh_CommandBuffer **pCommandBuffers
); );
/* Waits for all submissions to complete. */ /* Waits for the previous submission to complete. */
REFRESHAPI void Refresh_Wait( REFRESHAPI void Refresh_Wait(
Refresh_Device *device Refresh_Device *device
); );

View File

@ -54,10 +54,10 @@ extern "C" {
* Be sure to free the memory with Refresh_Image_Free after use! * Be sure to free the memory with Refresh_Image_Free after use!
*/ */
REFRESHAPI uint8_t* Refresh_Image_Load( REFRESHAPI uint8_t* Refresh_Image_Load(
char const *filename, char const *filename,
int32_t *w, int32_t *w,
int32_t *h, int32_t *h,
int32_t *numChannels int32_t *numChannels
); );
/* Frees memory returned by Refresh_Image_Load. (Do NOT free the memory yourself!) /* Frees memory returned by Refresh_Image_Load. (Do NOT free the memory yourself!)
@ -68,19 +68,17 @@ REFRESHAPI void Refresh_Image_Free(uint8_t *mem);
/* Image Write API */ /* Image Write API */
/* Encodes 32-bit color data into PNG data. /* Encodes RGBA8 image data into PNG data.
* *
* filename: The filename that the image will be written to. * filename: The filename that the image will be written to.
* w: The width of the PNG data. * w: The width of the PNG data.
* h: The height of the PNG data. * h: The height of the PNG data.
* bgra: Whether the data is in BGRA8 format. Otherwise will assume RBGA8. * data: The raw RGBA8 image data.
* data: The raw color data.
*/ */
REFRESHAPI void Refresh_Image_SavePNG( REFRESHAPI void Refresh_Image_SavePNG(
char const *filename, char const *filename,
int32_t w, int32_t w,
int32_t h, int32_t h,
uint8_t bgra,
uint8_t *data uint8_t *data
); );

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities /* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
* *
* Copyright (c) 2020 Evan Hemsley * Copyright (c) 2020 Evan Hemsley
* *
@ -36,15 +36,9 @@
/* Logging */ /* Logging */
#ifdef __cplusplus extern void Refresh_LogInfo(const char *fmt, ...);
extern "C" { extern void Refresh_LogWarn(const char *fmt, ...);
#endif extern void Refresh_LogError(const char *fmt, ...);
void Refresh_LogInfo(const char *fmt, ...);
void Refresh_LogWarn(const char *fmt, ...);
void Refresh_LogError(const char *fmt, ...);
#ifdef __cplusplus
}
#endif
/* Internal Helper Utilities */ /* Internal Helper Utilities */
@ -57,7 +51,6 @@ static inline uint32_t Texture_GetFormatSize(
return 8; return 8;
case REFRESH_TEXTUREFORMAT_BC2: case REFRESH_TEXTUREFORMAT_BC2:
case REFRESH_TEXTUREFORMAT_BC3: case REFRESH_TEXTUREFORMAT_BC3:
case REFRESH_TEXTUREFORMAT_BC7:
return 16; return 16;
case REFRESH_TEXTUREFORMAT_R8: case REFRESH_TEXTUREFORMAT_R8:
return 1; return 1;
@ -124,8 +117,7 @@ static inline uint32_t BytesPerRow(
if ( format == REFRESH_TEXTUREFORMAT_BC1 || if ( format == REFRESH_TEXTUREFORMAT_BC1 ||
format == REFRESH_TEXTUREFORMAT_BC2 || format == REFRESH_TEXTUREFORMAT_BC2 ||
format == REFRESH_TEXTUREFORMAT_BC3 || format == REFRESH_TEXTUREFORMAT_BC3 )
format == REFRESH_TEXTUREFORMAT_BC7 )
{ {
blocksPerRow = (width + 3) / 4; blocksPerRow = (width + 3) / 4;
} }
@ -143,8 +135,7 @@ static inline int32_t BytesPerImage(
if ( format == REFRESH_TEXTUREFORMAT_BC1 || if ( format == REFRESH_TEXTUREFORMAT_BC1 ||
format == REFRESH_TEXTUREFORMAT_BC2 || format == REFRESH_TEXTUREFORMAT_BC2 ||
format == REFRESH_TEXTUREFORMAT_BC3 || format == REFRESH_TEXTUREFORMAT_BC3 )
format == REFRESH_TEXTUREFORMAT_BC7 )
{ {
blocksPerRow = (width + 3) / 4; blocksPerRow = (width + 3) / 4;
blocksPerColumn = (height + 3) / 4; blocksPerColumn = (height + 3) / 4;
@ -160,10 +151,9 @@ static inline int32_t BytesPerImage(
#define MAX_VERTEXTEXTURE_SAMPLERS 4 #define MAX_VERTEXTEXTURE_SAMPLERS 4
#define MAX_TOTAL_SAMPLERS (MAX_TEXTURE_SAMPLERS + MAX_VERTEXTEXTURE_SAMPLERS) #define MAX_TOTAL_SAMPLERS (MAX_TEXTURE_SAMPLERS + MAX_VERTEXTEXTURE_SAMPLERS)
#define MAX_BUFFER_BINDINGS 16 #define MAX_BUFFER_BINDINGS 16
#define MAX_COLOR_TARGET_BINDINGS 4 #define MAX_COLOR_TARGET_BINDINGS 4
#define MAX_PRESENT_COUNT 16
/* Refresh_Device Definition */ /* Refresh_Device Definition */
@ -177,298 +167,334 @@ struct Refresh_Device
/* Drawing */ /* Drawing */
void (*Clear)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *clearRect,
Refresh_ClearOptions options,
Refresh_Vec4 *colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
);
void (*DrawInstancedPrimitives)( void (*DrawInstancedPrimitives)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t startIndex, uint32_t startIndex,
uint32_t primitiveCount, uint32_t primitiveCount,
uint32_t instanceCount, uint32_t instanceCount,
uint32_t vertexParamOffset, uint32_t vertexParamOffset,
uint32_t fragmentParamOffset uint32_t fragmentParamOffset
); );
void (*DrawIndexedPrimitives)( void (*DrawIndexedPrimitives)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t startIndex, uint32_t startIndex,
uint32_t primitiveCount, uint32_t primitiveCount,
uint32_t vertexParamOffset, uint32_t vertexParamOffset,
uint32_t fragmentParamOffset uint32_t fragmentParamOffset
); );
void (*DrawPrimitives)( void (*DrawPrimitives)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t vertexStart,
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
void (*DispatchCompute)(
Refresh_Renderer *device,
Refresh_CommandBuffer *commandBuffer,
uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ,
uint32_t computeParamOffset
);
/* State Creation */
Refresh_RenderPass* (*CreateRenderPass)(
Refresh_Renderer *driverData,
Refresh_RenderPassCreateInfo *renderPassCreateInfo
);
Refresh_ComputePipeline* (*CreateComputePipeline)(
Refresh_Renderer *driverData,
Refresh_ComputePipelineCreateInfo *pipelineCreateInfo
);
Refresh_GraphicsPipeline* (*CreateGraphicsPipeline)(
Refresh_Renderer *driverData,
Refresh_GraphicsPipelineCreateInfo *pipelineCreateInfo
);
Refresh_Sampler* (*CreateSampler)(
Refresh_Renderer *driverData,
Refresh_SamplerStateCreateInfo *samplerStateCreateInfo
);
Refresh_Framebuffer* (*CreateFramebuffer)(
Refresh_Renderer *driverData,
Refresh_FramebufferCreateInfo *framebufferCreateInfo
);
Refresh_ShaderModule* (*CreateShaderModule)(
Refresh_Renderer *driverData,
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
);
Refresh_Texture* (*CreateTexture)(
Refresh_Renderer *driverData,
Refresh_TextureCreateInfo *textureCreateInfo
);
Refresh_RenderTarget* (*CreateRenderTarget)(
Refresh_Renderer *driverData,
Refresh_TextureSlice *textureSlice,
Refresh_SampleCount multisampleCount
);
Refresh_Buffer* (*CreateBuffer)(
Refresh_Renderer *driverData,
Refresh_BufferUsageFlags usageFlags,
uint32_t sizeInBytes
);
/* Setters */
void(*SetTextureData)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice,
void *data,
uint32_t dataLengthInBytes
);
void(*SetTextureDataYUV)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer* commandBuffer,
Refresh_Texture *y,
Refresh_Texture *u,
Refresh_Texture *v,
uint32_t yWidth,
uint32_t yHeight,
uint32_t uvWidth,
uint32_t uvHeight,
void* data,
uint32_t dataLength
);
void(*CopyTextureToTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *sourceTextureSlice,
Refresh_TextureSlice *destinationTextureSlice,
Refresh_Filter filter
);
void(*CopyTextureToBuffer)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice,
Refresh_Buffer *buffer
);
void(*SetBufferData)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer,
uint32_t offsetInBytes,
void* data,
uint32_t dataLength
);
uint32_t(*PushVertexShaderUniforms)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
);
uint32_t(*PushFragmentShaderUniforms)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
);
uint32_t (*PushComputeShaderUniforms)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
);
void(*BindVertexSamplers)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures,
Refresh_Sampler **pSamplers
);
void(*BindFragmentSamplers)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures,
Refresh_Sampler **pSamplers
);
/* Getters */
void(*GetBufferData)(
Refresh_Renderer *driverData,
Refresh_Buffer *buffer,
void *data,
uint32_t dataLengthInBytes
);
/* Disposal */
void(*QueueDestroyTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
uint32_t vertexStart, Refresh_Texture *texture
uint32_t primitiveCount, );
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
void (*DispatchCompute)( void(*QueueDestroySampler)(
Refresh_Renderer *device, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
uint32_t groupCountX, Refresh_Sampler *sampler
uint32_t groupCountY, );
uint32_t groupCountZ,
uint32_t computeParamOffset
);
/* State Creation */ void(*QueueDestroyBuffer)(
Refresh_Renderer *driverData,
Refresh_ComputePipeline* (*CreateComputePipeline)(
Refresh_Renderer *driverData,
Refresh_ComputeShaderInfo *computeShaderInfo
);
Refresh_GraphicsPipeline* (*CreateGraphicsPipeline)(
Refresh_Renderer *driverData,
Refresh_GraphicsPipelineCreateInfo *pipelineCreateInfo
);
Refresh_Sampler* (*CreateSampler)(
Refresh_Renderer *driverData,
Refresh_SamplerStateCreateInfo *samplerStateCreateInfo
);
Refresh_ShaderModule* (*CreateShaderModule)(
Refresh_Renderer *driverData,
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
);
Refresh_Texture* (*CreateTexture)(
Refresh_Renderer *driverData,
Refresh_TextureCreateInfo *textureCreateInfo
);
Refresh_Buffer* (*CreateBuffer)(
Refresh_Renderer *driverData,
Refresh_BufferUsageFlags usageFlags,
uint32_t sizeInBytes
);
/* Setters */
void(*SetTextureData)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice, Refresh_Buffer *buffer
void *data, );
uint32_t dataLengthInBytes
);
void(*SetTextureDataYUV)( void(*QueueDestroyRenderTarget)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer* commandBuffer,
Refresh_Texture *y,
Refresh_Texture *u,
Refresh_Texture *v,
uint32_t yWidth,
uint32_t yHeight,
uint32_t uvWidth,
uint32_t uvHeight,
void* data,
uint32_t dataLength
);
void(*CopyTextureToTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *sourceTextureSlice, Refresh_RenderTarget *renderTarget
Refresh_TextureSlice *destinationTextureSlice, );
Refresh_Filter filter
);
void(*CopyTextureToBuffer)( void(*QueueDestroyFramebuffer)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice, Refresh_Framebuffer *frameBuffer
Refresh_Buffer *buffer );
);
void(*SetBufferData)( void(*QueueDestroyShaderModule)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer, Refresh_ShaderModule *shaderModule
uint32_t offsetInBytes, );
void* data,
uint32_t dataLength
);
uint32_t(*PushVertexShaderUniforms)( void(*QueueDestroyRenderPass)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
void *data, Refresh_RenderPass *renderPass
uint32_t dataLengthInBytes );
);
uint32_t(*PushFragmentShaderUniforms)( void(*QueueDestroyComputePipeline)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
void *data, Refresh_ComputePipeline *computePipeline
uint32_t dataLengthInBytes );
);
uint32_t (*PushComputeShaderUniforms)( void(*QueueDestroyGraphicsPipeline)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
void *data, Refresh_GraphicsPipeline *graphicsPipeline
uint32_t dataLengthInBytes );
);
void(*BindVertexSamplers)( /* Graphics State */
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures,
Refresh_Sampler **pSamplers
);
void(*BindFragmentSamplers)( void(*BeginRenderPass)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer, Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures, Refresh_RenderPass *renderPass,
Refresh_Sampler **pSamplers Refresh_Framebuffer *framebuffer,
); Refresh_Rect *renderArea,
Refresh_Vec4 *pColorClearValues,
uint32_t colorClearCount,
Refresh_DepthStencilValue *depthStencilClearValue
);
/* Getters */ void(*EndRenderPass)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer
);
void(*GetBufferData)( void(*BindGraphicsPipeline)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_Buffer *buffer, Refresh_CommandBuffer *commandBuffer,
void *data, Refresh_GraphicsPipeline *graphicsPipeline
uint32_t dataLengthInBytes );
);
/* Disposal */ void(*BindVertexBuffers)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t firstBinding,
uint32_t bindingCount,
Refresh_Buffer **pBuffers,
uint64_t *pOffsets
);
void(*QueueDestroyTexture)( void(*BindIndexBuffer)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_Texture *texture Refresh_CommandBuffer *commandBuffer,
); Refresh_Buffer *buffer,
uint64_t offset,
Refresh_IndexElementSize indexElementSize
);
void(*QueueDestroySampler)( void(*BindComputePipeline)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_Sampler *sampler Refresh_CommandBuffer *commandBuffer,
); Refresh_ComputePipeline *computePipeline
);
void(*QueueDestroyBuffer)( void(*BindComputeBuffers)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_Buffer *buffer Refresh_CommandBuffer *commandBuffer,
); Refresh_Buffer **pBuffers
);
void(*QueueDestroyShaderModule)( void(*BindComputeTextures)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_ShaderModule *shaderModule Refresh_CommandBuffer *commandBuffer,
); Refresh_Texture **pTextures
);
void(*QueueDestroyComputePipeline)( Refresh_CommandBuffer* (*AcquireCommandBuffer)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_ComputePipeline *computePipeline uint8_t fixed
); );
void(*QueueDestroyGraphicsPipeline)( void(*QueuePresent)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_GraphicsPipeline *graphicsPipeline Refresh_CommandBuffer *commandBuffer,
); Refresh_TextureSlice *textureSlice,
Refresh_Rect *destinationRectangle,
/* Graphics State */ Refresh_Filter filter,
void(*BeginRenderPass)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *renderArea,
Refresh_ColorAttachmentInfo *colorAttachmentInfos,
uint32_t colorAttachmentCount,
Refresh_DepthStencilAttachmentInfo *depthStencilAttachmentInfo
);
void(*EndRenderPass)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer
);
void(*SetViewport)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Viewport *viewport
);
void(*SetScissor)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *scissor
);
void(*BindGraphicsPipeline)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_GraphicsPipeline *graphicsPipeline
);
void(*BindVertexBuffers)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t firstBinding,
uint32_t bindingCount,
Refresh_Buffer **pBuffers,
uint64_t *pOffsets
);
void(*BindIndexBuffer)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer,
uint64_t offset,
Refresh_IndexElementSize indexElementSize
);
void(*BindComputePipeline)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_ComputePipeline *computePipeline
);
void(*BindComputeBuffers)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer **pBuffers
);
void(*BindComputeTextures)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures
);
Refresh_CommandBuffer* (*AcquireCommandBuffer)(
Refresh_Renderer *driverData,
uint8_t fixed
);
Refresh_Texture* (*AcquireSwapchainTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
);
Refresh_TextureFormat (*GetSwapchainFormat)(
Refresh_Renderer *driverData,
void *windowHandle void *windowHandle
); );
void(*Submit)( void(*Submit)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
uint32_t commandBufferCount, uint32_t commandBufferCount,
Refresh_CommandBuffer **pCommandBuffers Refresh_CommandBuffer **pCommandBuffers
); );
void(*Wait)( void(*Wait)(
Refresh_Renderer *driverData Refresh_Renderer *driverData
); );
/* Opaque pointer for the Driver */ /* Opaque pointer for the Driver */
Refresh_Renderer *driverData; Refresh_Renderer *driverData;
@ -478,60 +504,63 @@ struct Refresh_Device
result->func = name##_##func; result->func = name##_##func;
#define ASSIGN_DRIVER(name) \ #define ASSIGN_DRIVER(name) \
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \ ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
ASSIGN_DRIVER_FUNC(Clear, name) \
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \ ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \ ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \ ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
ASSIGN_DRIVER_FUNC(DispatchCompute, name) \ ASSIGN_DRIVER_FUNC(DispatchCompute, name) \
ASSIGN_DRIVER_FUNC(CreateComputePipeline, name) \ ASSIGN_DRIVER_FUNC(CreateRenderPass, name) \
ASSIGN_DRIVER_FUNC(CreateGraphicsPipeline, name) \ ASSIGN_DRIVER_FUNC(CreateComputePipeline, name) \
ASSIGN_DRIVER_FUNC(CreateSampler, name) \ ASSIGN_DRIVER_FUNC(CreateGraphicsPipeline, name) \
ASSIGN_DRIVER_FUNC(CreateShaderModule, name) \ ASSIGN_DRIVER_FUNC(CreateSampler, name) \
ASSIGN_DRIVER_FUNC(CreateTexture, name) \ ASSIGN_DRIVER_FUNC(CreateFramebuffer, name) \
ASSIGN_DRIVER_FUNC(CreateBuffer, name) \ ASSIGN_DRIVER_FUNC(CreateShaderModule, name) \
ASSIGN_DRIVER_FUNC(SetTextureData, name) \ ASSIGN_DRIVER_FUNC(CreateTexture, name) \
ASSIGN_DRIVER_FUNC(SetTextureDataYUV, name) \ ASSIGN_DRIVER_FUNC(CreateRenderTarget, name) \
ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \ ASSIGN_DRIVER_FUNC(CreateBuffer, name) \
ASSIGN_DRIVER_FUNC(CopyTextureToBuffer, name) \ ASSIGN_DRIVER_FUNC(SetTextureData, name) \
ASSIGN_DRIVER_FUNC(SetBufferData, name) \ ASSIGN_DRIVER_FUNC(SetTextureDataYUV, name) \
ASSIGN_DRIVER_FUNC(PushVertexShaderUniforms, name) \ ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
ASSIGN_DRIVER_FUNC(PushFragmentShaderUniforms, name) \ ASSIGN_DRIVER_FUNC(CopyTextureToBuffer, name) \
ASSIGN_DRIVER_FUNC(PushComputeShaderUniforms, name) \ ASSIGN_DRIVER_FUNC(SetBufferData, name) \
ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \ ASSIGN_DRIVER_FUNC(PushVertexShaderUniforms, name) \
ASSIGN_DRIVER_FUNC(BindFragmentSamplers, name) \ ASSIGN_DRIVER_FUNC(PushFragmentShaderUniforms, name) \
ASSIGN_DRIVER_FUNC(GetBufferData, name) \ ASSIGN_DRIVER_FUNC(PushComputeShaderUniforms, name) \
ASSIGN_DRIVER_FUNC(QueueDestroyTexture, name) \ ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
ASSIGN_DRIVER_FUNC(QueueDestroySampler, name) \ ASSIGN_DRIVER_FUNC(BindFragmentSamplers, name) \
ASSIGN_DRIVER_FUNC(QueueDestroyBuffer, name) \ ASSIGN_DRIVER_FUNC(GetBufferData, name) \
ASSIGN_DRIVER_FUNC(QueueDestroyShaderModule, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyTexture, name) \
ASSIGN_DRIVER_FUNC(QueueDestroyComputePipeline, name) \ ASSIGN_DRIVER_FUNC(QueueDestroySampler, name) \
ASSIGN_DRIVER_FUNC(QueueDestroyGraphicsPipeline, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyBuffer, name) \
ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyRenderTarget, name) \
ASSIGN_DRIVER_FUNC(EndRenderPass, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyFramebuffer, name) \
ASSIGN_DRIVER_FUNC(SetViewport, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyShaderModule, name) \
ASSIGN_DRIVER_FUNC(SetScissor, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyRenderPass, name) \
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyComputePipeline, name) \
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \ ASSIGN_DRIVER_FUNC(QueueDestroyGraphicsPipeline, name) \
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \ ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \
ASSIGN_DRIVER_FUNC(BindComputePipeline, name) \ ASSIGN_DRIVER_FUNC(EndRenderPass, name) \
ASSIGN_DRIVER_FUNC(BindComputeBuffers, name) \ ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
ASSIGN_DRIVER_FUNC(BindComputeTextures, name) \ ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \ ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \ ASSIGN_DRIVER_FUNC(BindComputePipeline, name) \
ASSIGN_DRIVER_FUNC(GetSwapchainFormat, name) \ ASSIGN_DRIVER_FUNC(BindComputeBuffers, name) \
ASSIGN_DRIVER_FUNC(Submit, name) \ ASSIGN_DRIVER_FUNC(BindComputeTextures, name) \
ASSIGN_DRIVER_FUNC(Wait, name) ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \
ASSIGN_DRIVER_FUNC(QueuePresent, name) \
ASSIGN_DRIVER_FUNC(Submit, name) \
ASSIGN_DRIVER_FUNC(Wait, name)
typedef struct Refresh_Driver typedef struct Refresh_Driver
{ {
const char *Name; const char *Name;
Refresh_Device* (*CreateDevice)( Refresh_Device* (*CreateDevice)(
Refresh_PresentationParameters *presentationParameters, Refresh_PresentationParameters *presentationParameters,
uint8_t debugMode uint8_t debugMode
); );
} Refresh_Driver; } Refresh_Driver;
extern Refresh_Driver VulkanDriver; extern Refresh_Driver VulkanDriver;
extern Refresh_Driver PS5Driver;
#endif /* REFRESH_DRIVER_H */ #endif /* REFRESH_DRIVER_H */

View File

@ -1,629 +0,0 @@
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
*
* Copyright (c) 2020 Evan Hemsley
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Evan "cosmonaut" Hemsley <evan@moonside.games>
*
*/
#if REFRESH_DRIVER_TEMPLATE
#include "Refresh_Driver.h"
#include <SDL.h>
#define NOT_IMPLEMENTED SDL_assert(0 && "Not implemented!");
/* Conversions */
static TEMPLATE_SURFACE_FORMAT_TYPE RefreshToTEMPLATE_SurfaceFormat[] =
{
0, /* R8G8B8A8 */
0, /* B8G8R8A8 */
0, /* R5G6B5 */
0, /* A1R5G5B5 */
0, /* B4G4R4A4 */
0, /* BC1 */
0, /* BC3 */
0, /* BC5 */
0, /* R8G8_SNORM */
0, /* R8G8B8A8_SNORM */
0, /* A2R10G10B10 */
0, /* R16G16 */
0, /* R16G16B16A16 */
0, /* R8 */
0, /* R32_SFLOAT */
0, /* R32G32_SFLOAT */
0, /* R32G32B32A32_SFLOAT */
0, /* R16_SFLOAT */
0, /* R16G16_SFLOAT */
0, /* R16G16B16A16_SFLOAT */
0, /* D16 */
0, /* D32 */
0, /* D16S8 */
0 /* D32S8 */
};
static TEMPLATE_VERTEX_FORMAT_TYPE RefreshToTEMPLATE_VertexFormat[] =
{
0, /* SINGLE */
0, /* VECTOR2 */
0, /* VECTOR3 */
0, /* VECTOR4 */
0, /* COLOR */
0, /* BYTE4 */
0, /* SHORT2 */
0, /* SHORT4 */
0, /* NORMALIZEDSHORT2 */
0, /* NORMALIZEDSHORT4 */
0, /* HALFVECTOR2 */
0 /* HALFVECTOR4 */
};
static TEMPLATE_INDEX_TYPE RefreshToTEMPLATE_IndexType[] =
{
0, /* 16BIT */
0 /* 32BIT */
};
static TEMPLATE_PRIMITIVE_TYPE RefreshToTEMPLATE_PrimitiveType[] =
{
0, /* POINTLIST */
0, /* LINELIST */
0, /* LINESTRIP */
0, /* TRIANGLELIST */
0 /* TRIANGLESTRIP */
};
static TEMPLATE_POLYGON_MODE_TYPE RefreshToTEMPLATE_PolygonMode[] =
{
0, /* FILL */
0, /* LINE */
};
static TEMPLATE_CULL_MODE_TYPE RefreshToTEMPLATE_CullMode[] =
{
0, /* NONE */
0, /* FRONT */
0, /* BACK */
};
static TEMPLATE_FRONT_FACE_TYPE RefreshToTEMPLATE_FrontFace[] =
{
0, /* COUNTER_CLOCKWISE */
0 /* CLOCKWISE */
};
static TEMPLATE_BLEND_FACTOR_TYPE RefreshToTEMPLATE_BlendFactor[] =
{
0, /* ZERO */
0, /* ONE */
0, /* SRC_COLOR */
0, /* ONE_MINUS_SRC_COLOR */
0, /* DST_COLOR */
0, /* ONE_MINUS_DST_COLOR */
0, /* SRC_ALPHA */
0, /* ONE_MINUS_SRC_ALPHA */
0, /* DST_ALPHA */
0, /* ONE_MINUS_DST_ALPHA */
0, /* CONSTANT_COLOR */
0, /* ONE_MINUS_CONSTANT_COLOR */
0, /* SRC_ALPHA_SATURATE */
0, /* SRC1_COLOR */
0, /* ONE_MINUS_SRC1_COLOR */
0, /* SRC1_ALPHA */
0 /* ONE_MINUS_SRC1_ALPHA */
};
static TEMPLATE_BLEND_OP_TYPE RefreshToTEMPLATE_BlendOp[] =
{
0, /* ADD */
0, /* SUBTRACT */
0, /* REVERSE_SUBTRACT */
0, /* MIN */
0 /* MAX */
};
static TEMPLATE_COMPARE_OP_TYPE RefreshToTEMPLATE_CompareOp[] =
{
0, /* NEVER */
0, /* LESS */
0, /* EQUAL */
0, /* LESS_OR_EQUAL */
0, /* GREATER */
0, /* NOT_EQUAL */
0, /* GREATER_OR_EQUAL */
0 /* ALWAYS */
};
static TEMPLATE_STENCIL_OP_TYPE RefreshToTEMPLATE_StencilOp[] =
{
0, /* KEEP */
0, /* ZERO */
0, /* REPLACE */
0, /* INCREMENT_AND_CLAMP */
0, /* DECREMENT_AND_CLAMP */
0, /* INVERT */
0, /* INCREMENT_AND_WRAP */
0 /* DECREMENT_AND_WRAP */
};
static TEMPLATE_ATTACHMENT_LOAD_OP_TYPE RefreshToTEMPLATE_LoadOp[] =
{
0, /* LOAD */
0, /* CLEAR */
0 /* DONT_CARE */
};
static TEMPLATE_ATTACHMENT_STORE_OP_TYPE RefreshToTEMPLATE_StoreOp[] =
{
0, /* STORE */
0 /* DONT_CARE */
};
static TEMPLATE_SAMPLE_COUNT_TYPE RefreshToTEMPLATE_SampleCount[] =
{
0, /* 1 */
0, /* 2 */
0, /* 4 */
0, /* 8 */
0, /* 16 */
0, /* 32 */
0 /* 64 */
};
static TEMPLATE_VERTEX_INPUT_RATE_TYPE RefreshToTEMPLATE_VertexInputRate[] =
{
0, /* VERTEX */
0 /* INSTANCE */
};
static TEMPLATE_FILTER_TYPE RefreshToTEMPLATE_Filter[] =
{
0, /* NEAREST */
0, /* LINEAR */
};
static TEMPLATE_SAMPLER_MIPMAP_MODE_TYPE RefreshToTEMPLATE_SamplerMipmapMode[] =
{
0, /* NEAREST */
0 /* LINEAR */
};
static TEMPLATE_SAMPLER_ADDRESS_MODE_TYPE RefreshToTEMPLATE_SamplerAddressMode[] =
{
0, /* REPEAT */
0, /* MIRRORED_REPEAT */
0, /* CLAMP_TO_EDGE */
0 /* CLAMP_TO_BORDER */
};
static TEMPLATE_BORDER_COLOR_TYPE RefreshToTEMPLATE_BorderColor[] =
{
0, /* FLOAT_TRANSPARENT_BLACK */
0, /* INT_TRANSPARENT_BLACK */
0, /* FLOAT_OPAQUE_BLACK */
0, /* INT_OPAQUE_BLACK */
0, /* FLOAT_OPAQUE_WHITE */
0 /* INT_OPAQUE_WHITE */
};
/* Quit */
static void TEMPLATE_DestroyDevice(
Refresh_Device *device
) {
NOT_IMPLEMENTED
}
/* Drawing */
static void TEMPLATE_DrawInstancedPrimitives(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t baseVertex,
uint32_t startIndex,
uint32_t primitiveCount,
uint32_t instanceCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_DrawIndexedPrimitives(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t baseVertex,
uint32_t startIndex,
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_DrawPrimitives(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t vertexStart,
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_DispatchCompute(
Refresh_Renderer *device,
Refresh_CommandBuffer *commandBuffer,
uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ,
uint32_t computeParamOffset
) {
NOT_IMPLEMENTED
}
/* State Creation */
static Refresh_ComputePipeline* TEMPLATE_CreateComputePipeline(
Refresh_Renderer *driverData,
Refresh_ComputeShaderInfo *computeShaderInfo
) {
NOT_IMPLEMENTED
}
static Refresh_GraphicsPipeline* TEMPLATE_CreateGraphicsPipeline(
Refresh_Renderer *driverData,
Refresh_GraphicsPipelineCreateInfo *pipelineCreateInfo
) {
NOT_IMPLEMENTED
}
static Refresh_Sampler* TEMPLATE_CreateSampler(
Refresh_Renderer *driverData,
Refresh_SamplerStateCreateInfo *samplerStateCreateInfo
) {
NOT_IMPLEMENTED
}
static Refresh_ShaderModule* TEMPLATE_CreateShaderModule(
Refresh_Renderer *driverData,
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
) {
NOT_IMPLEMENTED
}
static Refresh_Texture* TEMPLATE_CreateTexture(
Refresh_Renderer *driverData,
Refresh_TextureCreateInfo *textureCreateInfo
) {
NOT_IMPLEMENTED
}
static Refresh_Buffer* TEMPLATE_CreateBuffer(
Refresh_Renderer *driverData,
Refresh_BufferUsageFlags usageFlags,
uint32_t sizeInBytes
) {
NOT_IMPLEMENTED
}
/* Setters */
static void TEMPLATE_SetTextureData(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice,
void *data,
uint32_t dataLengthInBytes
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_SetTextureDataYUV(
Refresh_Renderer *driverData,
Refresh_CommandBuffer* commandBuffer,
Refresh_Texture *y,
Refresh_Texture *u,
Refresh_Texture *v,
uint32_t yWidth,
uint32_t yHeight,
uint32_t uvWidth,
uint32_t uvHeight,
void* data,
uint32_t dataLength
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_CopyTextureToTexture(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *sourceTextureSlice,
Refresh_TextureSlice *destinationTextureSlice,
Refresh_Filter filter
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_CopyTextureToBuffer(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_TextureSlice *textureSlice,
Refresh_Buffer *buffer
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_SetBufferData(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer,
uint32_t offsetInBytes,
void* data,
uint32_t dataLength
) {
NOT_IMPLEMENTED
}
static uint32_t TEMPLATE_PushVertexShaderUniforms(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
) {
NOT_IMPLEMENTED
}
static uint32_t TEMPLATE_PushFragmentShaderUniforms(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
) {
NOT_IMPLEMENTED
}
static uint32_t TEMPLATE_PushComputeShaderUniforms(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *data,
uint32_t dataLengthInBytes
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindVertexSamplers(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures,
Refresh_Sampler **pSamplers
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindFragmentSamplers(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures,
Refresh_Sampler **pSamplers
) {
NOT_IMPLEMENTED
}
/* Getters */
static void TEMPLATE_GetBufferData(
Refresh_Renderer *driverData,
Refresh_Buffer *buffer,
void *data,
uint32_t dataLengthInBytes
) {
NOT_IMPLEMENTED
}
/* Disposal */
static void TEMPLATE_QueueDestroyTexture(
Refresh_Renderer *driverData,
Refresh_Texture *texture
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_QueueDestroySampler(
Refresh_Renderer *driverData,
Refresh_Sampler *sampler
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_QueueDestroyBuffer(
Refresh_Renderer *driverData,
Refresh_Buffer *buffer
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_QueueDestroyShaderModule(
Refresh_Renderer *driverData,
Refresh_ShaderModule *shaderModule
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_QueueDestroyComputePipeline(
Refresh_Renderer *driverData,
Refresh_ComputePipeline *computePipeline
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_QueueDestroyGraphicsPipeline(
Refresh_Renderer *driverData,
Refresh_GraphicsPipeline *graphicsPipeline
) {
NOT_IMPLEMENTED
}
/* Graphics State */
static void TEMPLATE_BeginRenderPass(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *renderArea,
Refresh_ColorAttachmentInfo *colorAttachmentInfos,
uint32_t colorAttachmentCount,
Refresh_DepthStencilAttachmentInfo *depthStencilAttachmentInfo
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_EndRenderPass(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindGraphicsPipeline(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_GraphicsPipeline *graphicsPipeline
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_SetViewport(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Viewport *viewport
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_SetScissor(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *scissor
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindVertexBuffers(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
uint32_t firstBinding,
uint32_t bindingCount,
Refresh_Buffer **pBuffers,
uint64_t *pOffsets
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindIndexBuffer(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer *buffer,
uint64_t offset,
Refresh_IndexElementSize indexElementSize
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindComputePipeline(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_ComputePipeline *computePipeline
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindComputeBuffers(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Buffer **pBuffers
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_BindComputeTextures(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Texture **pTextures
) {
NOT_IMPLEMENTED
}
static Refresh_CommandBuffer* TEMPLATE_AcquireCommandBuffer(
Refresh_Renderer *driverData,
uint8_t fixed
) {
NOT_IMPLEMENTED
}
Refresh_Texture* TEMPLATE_AcquireSwapchainTexture(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
) {
NOT_IMPLEMENTED
}
Refresh_TextureFormat TEMPLATE_GetSwapchainFormat(
Refresh_Renderer *driverData,
void *windowHandle
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_Submit(
Refresh_Renderer *driverData,
uint32_t commandBufferCount,
Refresh_CommandBuffer **pCommandBuffers
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_Wait(
Refresh_Renderer *driverData
) {
NOT_IMPLEMENTED
}
static Refresh_Device* TEMPLATE_CreateDevice(
Refresh_PresentationParameters *presentationParameters,
uint8_t debugMode
) {
NOT_IMPLEMENTED
}
Refresh_Driver TEMPLATEDriver = {
"TEMPLATE",
TEMPLATE_CreateDevice
};
#endif //REFRESH_DRIVER_TEMPLATE

File diff suppressed because it is too large Load Diff

View File

@ -89,53 +89,53 @@
static void * static void *
SDL_SIMDRealloc(void *mem, const size_t len) SDL_SIMDRealloc(void *mem, const size_t len)
{ {
const size_t alignment = SDL_SIMDGetAlignment(); const size_t alignment = SDL_SIMDGetAlignment();
const size_t padding = alignment - (len % alignment); const size_t padding = alignment - (len % alignment);
const size_t padded = (padding != alignment) ? (len + padding) : len; const size_t padded = (padding != alignment) ? (len + padding) : len;
Uint8 *retval = (Uint8*) mem; Uint8 *retval = (Uint8*) mem;
void *oldmem = mem; void *oldmem = mem;
size_t memdiff, ptrdiff; size_t memdiff, ptrdiff;
Uint8 *ptr; Uint8 *ptr;
if (mem) { if (mem) {
void **realptr = (void **) mem; void **realptr = (void **) mem;
realptr--; realptr--;
mem = *(((void **) mem) - 1); mem = *(((void **) mem) - 1);
/* Check the delta between the real pointer and user pointer */ /* Check the delta between the real pointer and user pointer */
memdiff = ((size_t) oldmem) - ((size_t) mem); memdiff = ((size_t) oldmem) - ((size_t) mem);
} }
ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *)); ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
if (ptr == mem) { if (ptr == mem) {
return retval; /* Pointer didn't change, nothing to do */ return retval; /* Pointer didn't change, nothing to do */
} }
if (ptr == NULL) { if (ptr == NULL) {
return NULL; /* Out of memory, bail! */ return NULL; /* Out of memory, bail! */
} }
/* Store the actual malloc pointer right before our aligned pointer. */ /* Store the actual malloc pointer right before our aligned pointer. */
retval = ptr + sizeof (void *); retval = ptr + sizeof (void *);
retval += alignment - (((size_t) retval) % alignment); retval += alignment - (((size_t) retval) % alignment);
/* Make sure the delta is the same! */ /* Make sure the delta is the same! */
if (mem) { if (mem) {
ptrdiff = ((size_t) retval) - ((size_t) ptr); ptrdiff = ((size_t) retval) - ((size_t) ptr);
if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */ if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
oldmem = (void*) (((size_t) ptr) + memdiff); oldmem = (void*) (((size_t) ptr) + memdiff);
/* Even though the data past the old `len` is undefined, this is the /* Even though the data past the old `len` is undefined, this is the
* only length value we have, and it guarantees that we copy all the * only length value we have, and it guarantees that we copy all the
* previous memory anyhow. * previous memory anyhow.
*/ */
SDL_memmove(retval, oldmem, len); SDL_memmove(retval, oldmem, len);
} }
} }
/* Actually store the malloc pointer, finally. */ /* Actually store the malloc pointer, finally. */
*(((void **) retval) - 1) = ptr; *(((void **) retval) - 1) = ptr;
return retval; return retval;
} }
#endif #endif
@ -190,51 +190,28 @@ static unsigned char* dgibson_stbi_zlib_compress(
/* Image Read API */ /* Image Read API */
uint8_t* Refresh_Image_Load( uint8_t* Refresh_Image_Load(
char const *filename, char const *filename,
int32_t *w, int32_t *w,
int32_t *h, int32_t *h,
int32_t *numChannels int32_t *numChannels
) { ) {
return stbi_load(filename, w, h, numChannels, STBI_rgb_alpha); return stbi_load(filename, w, h, numChannels, STBI_rgb_alpha);
} }
void Refresh_Image_Free(uint8_t *mem) void Refresh_Image_Free(uint8_t *mem)
{ {
stbi_image_free(mem); stbi_image_free(mem);
} }
/* Image Write API */ /* Image Write API */
void Refresh_Image_SavePNG( void Refresh_Image_SavePNG(
const char *filename, const char *filename,
int32_t w, int32_t w,
int32_t h, int32_t h,
uint8_t bgra,
uint8_t *data uint8_t *data
) { ) {
uint32_t i; stbi_write_png(filename, w, h, 4, data, w * 4);
uint8_t *bgraData;
if (bgra)
{
bgraData = SDL_malloc(w * h * 4);
for (i = 0; i < w * h * 4; i += 4)
{
bgraData[i] = data[i + 2];
bgraData[i + 1] = data[i + 1];
bgraData[i + 2] = data[i];
bgraData[i + 3] = data[i + 3];
}
stbi_write_png(filename, w, h, 4, bgraData, w * 4);
SDL_free(bgraData);
}
else
{
stbi_write_png(filename, w, h, 4, data, w * 4);
}
} }
/* vim: set noexpandtab shiftwidth=8 tabstop=8: */ /* vim: set noexpandtab shiftwidth=8 tabstop=8: */