2022-03-02 19:22:52 +00:00
|
|
|
|
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
|
2020-12-17 00:27:14 +00:00
|
|
|
|
*
|
|
|
|
|
* 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>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef REFRESH_DRIVER_H
|
|
|
|
|
#define REFRESH_DRIVER_H
|
|
|
|
|
|
|
|
|
|
#include "Refresh.h"
|
|
|
|
|
|
|
|
|
|
/* Windows/Visual Studio cruft */
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define inline __inline
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-12-17 02:38:22 +00:00
|
|
|
|
/* Logging */
|
|
|
|
|
|
2022-08-14 20:45:24 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
void Refresh_LogInfo(const char *fmt, ...);
|
|
|
|
|
void Refresh_LogWarn(const char *fmt, ...);
|
|
|
|
|
void Refresh_LogError(const char *fmt, ...);
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-12-17 02:38:22 +00:00
|
|
|
|
|
2020-12-17 00:27:14 +00:00
|
|
|
|
/* Internal Helper Utilities */
|
|
|
|
|
|
|
|
|
|
static inline uint32_t Texture_GetFormatSize(
|
2021-01-27 02:57:46 +00:00
|
|
|
|
Refresh_TextureFormat format
|
2020-12-17 00:27:14 +00:00
|
|
|
|
) {
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_BC1:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 8;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_BC2:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_BC3:
|
2022-05-12 04:16:24 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_BC7:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 16;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8:
|
2022-09-13 20:51:41 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8_UINT:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 1;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R5G6B5:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_B4G4R4A4:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_A1R5G5B5:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16_SFLOAT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8G8_SNORM:
|
2022-09-13 20:51:41 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8G8_UINT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16_UINT:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 2;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8G8B8A8:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R32_SFLOAT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16G16_SFLOAT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_A2R10G10B10:
|
2022-09-13 20:51:41 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R8G8B8A8_UINT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16G16_UINT:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 4;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16G16B16A16:
|
|
|
|
|
case REFRESH_TEXTUREFORMAT_R32G32_SFLOAT:
|
2022-09-13 20:51:41 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R16G16B16A16_UINT:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 8;
|
2021-01-27 02:57:46 +00:00
|
|
|
|
case REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT:
|
2020-12-17 00:27:14 +00:00
|
|
|
|
return 16;
|
|
|
|
|
default:
|
2021-01-05 23:00:51 +00:00
|
|
|
|
Refresh_LogError(
|
2020-12-17 00:27:14 +00:00
|
|
|
|
"Unrecognized SurfaceFormat!"
|
|
|
|
|
);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t PrimitiveVerts(
|
2021-01-05 23:00:51 +00:00
|
|
|
|
Refresh_PrimitiveType primitiveType,
|
2020-12-17 00:27:14 +00:00
|
|
|
|
uint32_t primitiveCount
|
|
|
|
|
) {
|
|
|
|
|
switch (primitiveType)
|
|
|
|
|
{
|
|
|
|
|
case REFRESH_PRIMITIVETYPE_TRIANGLELIST:
|
|
|
|
|
return primitiveCount * 3;
|
|
|
|
|
case REFRESH_PRIMITIVETYPE_TRIANGLESTRIP:
|
|
|
|
|
return primitiveCount + 2;
|
|
|
|
|
case REFRESH_PRIMITIVETYPE_LINELIST:
|
|
|
|
|
return primitiveCount * 2;
|
|
|
|
|
case REFRESH_PRIMITIVETYPE_LINESTRIP:
|
|
|
|
|
return primitiveCount + 1;
|
|
|
|
|
case REFRESH_PRIMITIVETYPE_POINTLIST:
|
|
|
|
|
return primitiveCount;
|
|
|
|
|
default:
|
2021-01-05 23:00:51 +00:00
|
|
|
|
Refresh_LogError(
|
2020-12-17 00:27:14 +00:00
|
|
|
|
"Unrecognized primitive type!"
|
|
|
|
|
);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
static inline uint32_t IndexSize(Refresh_IndexElementSize size)
|
2020-12-17 00:27:14 +00:00
|
|
|
|
{
|
2020-12-17 02:12:20 +00:00
|
|
|
|
return (size == REFRESH_INDEXELEMENTSIZE_16BIT) ? 2 : 4;
|
2020-12-17 00:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t BytesPerRow(
|
|
|
|
|
int32_t width,
|
2021-01-27 02:57:46 +00:00
|
|
|
|
Refresh_TextureFormat format
|
2020-12-17 00:27:14 +00:00
|
|
|
|
) {
|
|
|
|
|
uint32_t blocksPerRow = width;
|
|
|
|
|
|
2021-01-27 02:57:46 +00:00
|
|
|
|
if ( format == REFRESH_TEXTUREFORMAT_BC1 ||
|
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC2 ||
|
2022-05-12 04:16:24 +00:00
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC3 ||
|
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC7 )
|
2020-12-17 00:27:14 +00:00
|
|
|
|
{
|
|
|
|
|
blocksPerRow = (width + 3) / 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return blocksPerRow * Texture_GetFormatSize(format);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int32_t BytesPerImage(
|
|
|
|
|
uint32_t width,
|
|
|
|
|
uint32_t height,
|
2021-01-27 02:57:46 +00:00
|
|
|
|
Refresh_TextureFormat format
|
2020-12-17 00:27:14 +00:00
|
|
|
|
) {
|
|
|
|
|
uint32_t blocksPerRow = width;
|
|
|
|
|
uint32_t blocksPerColumn = height;
|
|
|
|
|
|
2021-01-27 02:57:46 +00:00
|
|
|
|
if ( format == REFRESH_TEXTUREFORMAT_BC1 ||
|
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC2 ||
|
2022-05-12 04:16:24 +00:00
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC3 ||
|
2022-09-13 20:51:41 +00:00
|
|
|
|
format == REFRESH_TEXTUREFORMAT_BC7 )
|
2020-12-17 00:27:14 +00:00
|
|
|
|
{
|
|
|
|
|
blocksPerRow = (width + 3) / 4;
|
|
|
|
|
blocksPerColumn = (height + 3) / 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return blocksPerRow * blocksPerColumn * Texture_GetFormatSize(format);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XNA GraphicsDevice Limits */
|
|
|
|
|
/* TODO: can these be adjusted for modern low-end? */
|
|
|
|
|
|
|
|
|
|
#define MAX_TEXTURE_SAMPLERS 16
|
|
|
|
|
#define MAX_VERTEXTEXTURE_SAMPLERS 4
|
|
|
|
|
#define MAX_TOTAL_SAMPLERS (MAX_TEXTURE_SAMPLERS + MAX_VERTEXTEXTURE_SAMPLERS)
|
|
|
|
|
|
2022-02-25 21:42:11 +00:00
|
|
|
|
#define MAX_BUFFER_BINDINGS 16
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2020-12-23 07:17:09 +00:00
|
|
|
|
#define MAX_COLOR_TARGET_BINDINGS 4
|
2022-03-02 06:33:57 +00:00
|
|
|
|
#define MAX_PRESENT_COUNT 16
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
/* Refresh_Device Definition */
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
typedef struct Refresh_Renderer Refresh_Renderer;
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
struct Refresh_Device
|
2020-12-17 00:27:14 +00:00
|
|
|
|
{
|
|
|
|
|
/* Quit */
|
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
void (*DestroyDevice)(Refresh_Device *device);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
|
|
|
|
/* Drawing */
|
|
|
|
|
|
2020-12-20 09:29:15 +00:00
|
|
|
|
void (*DrawInstancedPrimitives)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
uint32_t baseVertex,
|
|
|
|
|
uint32_t startIndex,
|
|
|
|
|
uint32_t primitiveCount,
|
|
|
|
|
uint32_t instanceCount,
|
|
|
|
|
uint32_t vertexParamOffset,
|
|
|
|
|
uint32_t fragmentParamOffset
|
2020-12-17 00:27:14 +00:00
|
|
|
|
);
|
2020-12-20 09:29:15 +00:00
|
|
|
|
|
|
|
|
|
void (*DrawIndexedPrimitives)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
uint32_t baseVertex,
|
|
|
|
|
uint32_t startIndex,
|
|
|
|
|
uint32_t primitiveCount,
|
|
|
|
|
uint32_t vertexParamOffset,
|
|
|
|
|
uint32_t fragmentParamOffset
|
2020-12-17 00:27:14 +00:00
|
|
|
|
);
|
2020-12-20 09:29:15 +00:00
|
|
|
|
|
2020-12-17 00:27:14 +00:00
|
|
|
|
void (*DrawPrimitives)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
uint32_t vertexStart,
|
|
|
|
|
uint32_t primitiveCount,
|
|
|
|
|
uint32_t vertexParamOffset,
|
|
|
|
|
uint32_t fragmentParamOffset
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2022-08-25 19:21:49 +00:00
|
|
|
|
void (*DrawPrimitivesIndirect)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Buffer *buffer,
|
|
|
|
|
uint32_t offsetInBytes,
|
|
|
|
|
uint32_t drawCount,
|
|
|
|
|
uint32_t stride,
|
|
|
|
|
uint32_t vertexParamOffset,
|
|
|
|
|
uint32_t fragmentParamOffset
|
|
|
|
|
);
|
|
|
|
|
|
2022-02-25 21:42:11 +00:00
|
|
|
|
void (*DispatchCompute)(
|
|
|
|
|
Refresh_Renderer *device,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
uint32_t groupCountX,
|
|
|
|
|
uint32_t groupCountY,
|
|
|
|
|
uint32_t groupCountZ,
|
|
|
|
|
uint32_t computeParamOffset
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* State Creation */
|
|
|
|
|
|
|
|
|
|
Refresh_ComputePipeline* (*CreateComputePipeline)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
2022-03-02 19:22:52 +00:00
|
|
|
|
Refresh_ComputeShaderInfo *computeShaderInfo
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Refresh_GraphicsPipeline* (*CreateGraphicsPipeline)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_GraphicsPipelineCreateInfo *pipelineCreateInfo
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Refresh_Sampler* (*CreateSampler)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_SamplerStateCreateInfo *samplerStateCreateInfo
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2022-02-25 21:42:11 +00:00
|
|
|
|
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 */
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*SetTextureData)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_TextureSlice *textureSlice,
|
|
|
|
|
void *data,
|
|
|
|
|
uint32_t dataLengthInBytes
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*SetTextureDataYUV)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
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,
|
2023-06-07 20:59:55 +00:00
|
|
|
|
void *yDataPtr,
|
|
|
|
|
void *uDataPtr,
|
|
|
|
|
void *vDataPtr,
|
|
|
|
|
uint32_t yDataLength,
|
|
|
|
|
uint32_t uvDataLength,
|
|
|
|
|
uint32_t yStride,
|
|
|
|
|
uint32_t uvStride
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*CopyTextureToTexture)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_TextureSlice *sourceTextureSlice,
|
|
|
|
|
Refresh_TextureSlice *destinationTextureSlice,
|
|
|
|
|
Refresh_Filter filter
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*CopyTextureToBuffer)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_TextureSlice *textureSlice,
|
|
|
|
|
Refresh_Buffer *buffer
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*SetBufferData)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Buffer *buffer,
|
|
|
|
|
uint32_t offsetInBytes,
|
|
|
|
|
void* data,
|
|
|
|
|
uint32_t dataLength
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
uint32_t (*PushVertexShaderUniforms)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
void *data,
|
|
|
|
|
uint32_t dataLengthInBytes
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
uint32_t (*PushFragmentShaderUniforms)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
void *data,
|
|
|
|
|
uint32_t dataLengthInBytes
|
|
|
|
|
);
|
2020-12-29 22:52:24 +00:00
|
|
|
|
|
2022-02-25 21:42:11 +00:00
|
|
|
|
uint32_t (*PushComputeShaderUniforms)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-23 00:49:45 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-02-25 21:42:11 +00:00
|
|
|
|
void *data,
|
|
|
|
|
uint32_t dataLengthInBytes
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindVertexSamplers)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Texture **pTextures,
|
|
|
|
|
Refresh_Sampler **pSamplers
|
|
|
|
|
);
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindFragmentSamplers)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Texture **pTextures,
|
|
|
|
|
Refresh_Sampler **pSamplers
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* Getters */
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*GetBufferData)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Buffer *buffer,
|
|
|
|
|
void *data,
|
|
|
|
|
uint32_t dataLengthInBytes
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* Disposal */
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroyTexture)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Texture *texture
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroySampler)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Sampler *sampler
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroyBuffer)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Buffer *buffer
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroyShaderModule)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_ShaderModule *shaderModule
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroyComputePipeline)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_ComputePipeline *computePipeline
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*QueueDestroyGraphicsPipeline)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_GraphicsPipeline *graphicsPipeline
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* Graphics State */
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BeginRenderPass)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-24 22:01:37 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_ColorAttachmentInfo *colorAttachmentInfos,
|
|
|
|
|
uint32_t colorAttachmentCount,
|
|
|
|
|
Refresh_DepthStencilAttachmentInfo *depthStencilAttachmentInfo
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*EndRenderPass)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*SetViewport)(
|
2022-03-04 20:30:33 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Viewport *viewport
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*SetScissor)(
|
2022-03-04 20:30:33 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Rect *scissor
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindGraphicsPipeline)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_GraphicsPipeline *graphicsPipeline
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindVertexBuffers)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
uint32_t firstBinding,
|
|
|
|
|
uint32_t bindingCount,
|
|
|
|
|
Refresh_Buffer **pBuffers,
|
|
|
|
|
uint64_t *pOffsets
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindIndexBuffer)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Buffer *buffer,
|
|
|
|
|
uint64_t offset,
|
|
|
|
|
Refresh_IndexElementSize indexElementSize
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindComputePipeline)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_ComputePipeline *computePipeline
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindComputeBuffers)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Buffer **pBuffers
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*BindComputeTextures)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
|
|
|
|
Refresh_Texture **pTextures
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-29 21:11:25 +00:00
|
|
|
|
uint8_t (*ClaimWindow)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
void *windowHandle,
|
|
|
|
|
Refresh_PresentMode presentMode
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*UnclaimWindow)(
|
2022-09-29 21:11:25 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
void *windowHandle
|
|
|
|
|
);
|
|
|
|
|
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_CommandBuffer* (*AcquireCommandBuffer)(
|
2023-01-14 18:03:58 +00:00
|
|
|
|
Refresh_Renderer *driverData
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
|
|
|
|
|
2022-03-02 06:33:57 +00:00
|
|
|
|
Refresh_Texture* (*AcquireSwapchainTexture)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer,
|
2022-03-10 18:21:49 +00:00
|
|
|
|
void *windowHandle,
|
|
|
|
|
uint32_t *pWidth,
|
|
|
|
|
uint32_t *pHeight
|
2022-03-02 06:33:57 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Refresh_TextureFormat (*GetSwapchainFormat)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
2022-02-09 01:16:11 +00:00
|
|
|
|
void *windowHandle
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
2020-12-17 04:19:11 +00:00
|
|
|
|
|
2022-09-29 21:11:25 +00:00
|
|
|
|
void (*SetSwapchainPresentMode)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
void *windowHandle,
|
|
|
|
|
Refresh_PresentMode presentMode
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*Submit)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData,
|
2023-09-19 06:11:20 +00:00
|
|
|
|
Refresh_CommandBuffer *commandBuffer
|
2022-02-25 21:42:11 +00:00
|
|
|
|
);
|
2020-12-21 23:44:43 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
Refresh_Fence* (*SubmitAndAcquireFence)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_CommandBuffer *commandBuffer
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void (*Wait)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
Refresh_Renderer *driverData
|
|
|
|
|
);
|
2021-01-03 05:07:51 +00:00
|
|
|
|
|
2023-09-19 06:11:20 +00:00
|
|
|
|
void (*WaitForFences)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
uint8_t waitAll,
|
|
|
|
|
uint32_t fenceCount,
|
|
|
|
|
Refresh_Fence **pFences
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
int (*QueryFence)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Fence *fence
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void (*ReleaseFence)(
|
|
|
|
|
Refresh_Renderer *driverData,
|
|
|
|
|
Refresh_Fence *fence
|
|
|
|
|
);
|
|
|
|
|
|
2020-12-17 00:27:14 +00:00
|
|
|
|
/* Opaque pointer for the Driver */
|
2021-01-05 23:00:51 +00:00
|
|
|
|
Refresh_Renderer *driverData;
|
2020-12-17 00:27:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define ASSIGN_DRIVER_FUNC(func, name) \
|
|
|
|
|
result->func = name##_##func;
|
|
|
|
|
#define ASSIGN_DRIVER(name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
|
2022-08-25 19:21:49 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(DrawPrimitivesIndirect, name) \
|
2022-02-25 21:42:11 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(DispatchCompute, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateComputePipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateGraphicsPipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateSampler, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateShaderModule, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateTexture, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CreateBuffer, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(SetTextureData, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(SetTextureDataYUV, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(CopyTextureToBuffer, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(SetBufferData, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(PushVertexShaderUniforms, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(PushFragmentShaderUniforms, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(PushComputeShaderUniforms, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindFragmentSamplers, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(GetBufferData, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroyTexture, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroySampler, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroyBuffer, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroyShaderModule, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroyComputePipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueueDestroyGraphicsPipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(EndRenderPass, name) \
|
2022-03-04 20:47:36 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(SetViewport, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(SetScissor, name) \
|
2022-02-25 21:42:11 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindComputePipeline, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindComputeBuffers, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(BindComputeTextures, name) \
|
2022-09-29 21:11:25 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(ClaimWindow, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(UnclaimWindow, name) \
|
2022-02-25 21:42:11 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \
|
2022-03-02 06:33:57 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(GetSwapchainFormat, name) \
|
2022-09-29 21:11:25 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(SetSwapchainPresentMode, name) \
|
2022-02-25 21:42:11 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(Submit, name) \
|
2023-09-19 06:11:20 +00:00
|
|
|
|
ASSIGN_DRIVER_FUNC(SubmitAndAcquireFence, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(Wait, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(WaitForFences, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(QueryFence, name) \
|
|
|
|
|
ASSIGN_DRIVER_FUNC(ReleaseFence, name)
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
typedef struct Refresh_Driver
|
2020-12-17 00:27:14 +00:00
|
|
|
|
{
|
|
|
|
|
const char *Name;
|
2022-09-29 21:11:25 +00:00
|
|
|
|
uint8_t (*PrepareDriver)(uint32_t *flags);
|
2021-01-05 23:00:51 +00:00
|
|
|
|
Refresh_Device* (*CreateDevice)(
|
2022-02-25 21:42:11 +00:00
|
|
|
|
uint8_t debugMode
|
2020-12-17 00:27:14 +00:00
|
|
|
|
);
|
2021-01-05 23:00:51 +00:00
|
|
|
|
} Refresh_Driver;
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2021-01-05 23:00:51 +00:00
|
|
|
|
extern Refresh_Driver VulkanDriver;
|
2022-08-14 20:45:24 +00:00
|
|
|
|
extern Refresh_Driver PS5Driver;
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
2020-12-17 19:44:34 +00:00
|
|
|
|
#endif /* REFRESH_DRIVER_H */
|
2020-12-17 00:27:14 +00:00
|
|
|
|
|
|
|
|
|
/* vim: set noexpandtab shiftwidth=8 tabstop=8: */
|