Compare commits

..

9 Commits

7 changed files with 43 additions and 264 deletions

View File

@ -8,8 +8,8 @@ option(BUILD_SHARED_LIBS "Build shared library" ON)
# Version
SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "2")
SET(LIB_REVISION "1")
SET(LIB_MINOR_VERSION "3")
SET(LIB_REVISION "0")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
# Build Type

View File

@ -55,8 +55,8 @@ extern "C" {
/* Version API */
#define REFRESH_MAJOR_VERSION 1
#define REFRESH_MINOR_VERSION 2
#define REFRESH_PATCH_VERSION 1
#define REFRESH_MINOR_VERSION 3
#define REFRESH_PATCH_VERSION 0
#define REFRESH_COMPILED_VERSION ( \
(REFRESH_MAJOR_VERSION * 100 * 100) + \
@ -107,15 +107,6 @@ typedef enum Refresh_StoreOp
REFRESH_STOREOP_DONT_CARE
} 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
{
REFRESH_INDEXELEMENTSIZE_16BIT,
@ -607,30 +598,6 @@ REFRESHAPI void Refresh_DestroyDevice(Refresh_Device *device);
/* 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.
*
* baseVertex: The starting offset to read from the vertex buffer.
@ -1136,17 +1103,22 @@ REFRESHAPI Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
/* Acquires a texture to use for presentation.
* May return NULL under certain conditions.
* If NULL, the user must ensure to not present.
* 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:
* It is not recommended to hold a reference to this texture long term.
*
* pWidth: A pointer to a uint32 that will be filled with the texture width.
* pHeight: A pointer to a uint32 that will be filled with the texture height.
*/
REFRESHAPI Refresh_Texture* Refresh_AcquireSwapchainTexture(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
);
/* Returns the format of the swapchain for the given window. */

View File

@ -173,27 +173,6 @@ void Refresh_DestroyDevice(Refresh_Device *device)
device->DestroyDevice(device);
}
void Refresh_Clear(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *clearRect,
Refresh_ClearOptions options,
Refresh_Vec4 *colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
) {
NULL_RETURN(device);
device->Clear(
device->driverData,
commandBuffer,
clearRect,
options,
colors,
colorCount,
depthStencil
);
}
void Refresh_DrawIndexedPrimitives(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
@ -755,13 +734,17 @@ Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
Refresh_Texture* Refresh_AcquireSwapchainTexture(
Refresh_Device *device,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
) {
NULL_RETURN_NULL(device);
return device->AcquireSwapchainTexture(
device->driverData,
commandBuffer,
windowHandle
windowHandle,
pWidth,
pHeight
);
}

View File

@ -168,16 +168,6 @@ struct Refresh_Device
/* 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)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
@ -451,7 +441,9 @@ struct Refresh_Device
Refresh_Texture* (*AcquireSwapchainTexture)(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
);
Refresh_TextureFormat (*GetSwapchainFormat)(
@ -477,7 +469,6 @@ struct Refresh_Device
result->func = name##_##func;
#define ASSIGN_DRIVER(name) \
ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
ASSIGN_DRIVER_FUNC(Clear, name) \
ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
ASSIGN_DRIVER_FUNC(DrawInstancedPrimitives, name) \
ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \

View File

@ -310,7 +310,7 @@ typedef struct D3D11Renderer
IDXGIAdapter1* adapter;
void *d3d11_dll;
void *dxgi_dll;
SDL_mutex *immediateContextMutex;
SDL_mutex *contextLock;
D3D11CommandBufferPool *commandBufferPool;
SDL_mutex *commandBufferAcquisitionMutex;
@ -629,65 +629,6 @@ static void D3D11_DestroyDevice(
/* Drawing */
static void D3D11_Clear(
Refresh_Renderer* driverData,
Refresh_CommandBuffer* commandBuffer,
Refresh_Rect* clearRect,
Refresh_ClearOptions options,
Refresh_Vec4* colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
) {
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
D3D11_CLEAR_FLAG dsClearFlags;
float clearColors[4];
uint32_t i;
/* FIXME: What should we do about clearRect? */
/* FIXME: Do we need to use colorCount or is it always the number of bound RTs? */
if (options & REFRESH_CLEAROPTIONS_COLOR)
{
/* Clear color attachments */
for (i = 0; i < cmdbuf->numBoundColorAttachments; i += 1)
{
clearColors[0] = colors[i].x;
clearColors[1] = colors[i].y;
clearColors[2] = colors[i].z;
clearColors[3] = colors[i].w;
ID3D11DeviceContext_ClearRenderTargetView(
cmdbuf->context,
cmdbuf->rtViews[i],
clearColors
);
}
}
/* Check which of depth/stencil need to be cleared (if either) */
dsClearFlags = 0;
if (options & REFRESH_CLEAROPTIONS_DEPTH)
{
dsClearFlags |= D3D11_CLEAR_DEPTH;
}
if (options & REFRESH_CLEAROPTIONS_STENCIL)
{
dsClearFlags |= D3D11_CLEAR_STENCIL;
}
if (dsClearFlags != 0)
{
ID3D11DeviceContext_ClearDepthStencilView(
cmdbuf->context,
cmdbuf->dsView,
dsClearFlags,
depthStencil.depth,
(uint8_t) depthStencil.stencil
);
}
}
static void D3D11_DrawInstancedPrimitives(
Refresh_Renderer* driverData,
Refresh_CommandBuffer* commandBuffer,
@ -1202,10 +1143,12 @@ static D3D11SwapchainData* D3D11_INTERNAL_FetchSwapchainData(
return swapchainData;
}
Refresh_Texture* D3D11_AcquireSwapchainTexture(
static Refresh_Texture* D3D11_AcquireSwapchainTexture(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
) {
D3D11Renderer *renderer = (D3D11Renderer*) driverData;
D3D11CommandBuffer *cmdbuf = (D3D11CommandBuffer*) commandBuffer;
@ -1241,6 +1184,10 @@ Refresh_Texture* D3D11_AcquireSwapchainTexture(
/* Let the command buffer know it's associated with this swapchain. */
cmdbuf->swapchainData = swapchainData;
/* Send the dimensions to the out parameters. */
*pWidth = swapchainData->refreshTexture.twod.width;
*pHeight = swapchainData->refreshTexture.twod.height;
/* Return the swapchain texture */
return (Refresh_Texture*) &swapchainData->refreshTexture;
}
@ -1285,13 +1232,13 @@ static void D3D11_Submit(
}
/* Submit the command list to the immediate context */
SDL_LockMutex(renderer->immediateContextMutex);
SDL_LockMutex(renderer->contextLock);
ID3D11DeviceContext_ExecuteCommandList(
renderer->immediateContext,
commandList,
0
);
SDL_UnlockMutex(renderer->immediateContextMutex);
SDL_UnlockMutex(renderer->contextLock);
/* Now that we're done, either save the command list or release it. */
if (commandBuffer->fixed)
@ -1309,11 +1256,13 @@ static void D3D11_Submit(
/* Present, if applicable */
if (commandBuffer->swapchainData)
{
SDL_LockMutex(renderer->contextLock);
IDXGISwapChain_Present(
commandBuffer->swapchainData->swapchain,
1, /* FIXME: Assumes vsync! */
0
);
SDL_UnlockMutex(renderer->contextLock);
}
}
}
@ -1458,7 +1407,7 @@ tryCreateDevice:
SDL_memset(renderer->commandBufferPool, 0, sizeof(D3D11CommandBufferPool));
/* Create mutexes */
renderer->immediateContextMutex = SDL_CreateMutex();
renderer->contextLock = SDL_CreateMutex();
renderer->commandBufferAcquisitionMutex = SDL_CreateMutex();
/* Initialize miscellaneous renderer members */

View File

@ -236,18 +236,6 @@ static void TEMPLATE_DestroyDevice(
/* Drawing */
static void TEMPLATE_Clear(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *clearRect,
Refresh_ClearOptions options,
Refresh_Vec4 *colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
) {
NOT_IMPLEMENTED
}
static void TEMPLATE_DrawInstancedPrimitives(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
@ -598,7 +586,9 @@ static Refresh_CommandBuffer* TEMPLATE_AcquireCommandBuffer(
Refresh_Texture* TEMPLATE_AcquireSwapchainTexture(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
) {
NOT_IMPLEMENTED
}

View File

@ -4798,117 +4798,6 @@ static void VULKAN_DestroyDevice(
SDL_free(device);
}
static void VULKAN_Clear(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
Refresh_Rect *clearRect,
Refresh_ClearOptions options,
Refresh_Vec4 *colors,
uint32_t colorCount,
Refresh_DepthStencilValue depthStencil
) {
VulkanRenderer* renderer = (VulkanRenderer*) driverData;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
uint32_t attachmentCount, i;
VkClearAttachment clearAttachments[MAX_COLOR_TARGET_BINDINGS + 1];
VkClearRect vulkanClearRect;
VkClearValue clearValues[4];
uint8_t shouldClearColor = options & REFRESH_CLEAROPTIONS_COLOR;
uint8_t shouldClearDepth = options & REFRESH_CLEAROPTIONS_DEPTH;
uint8_t shouldClearStencil = options & REFRESH_CLEAROPTIONS_STENCIL;
uint8_t shouldClearDepthStencil = (
(shouldClearDepth || shouldClearStencil)
);
if (!shouldClearColor && !shouldClearDepthStencil)
{
return;
}
vulkanClearRect.baseArrayLayer = 0;
vulkanClearRect.layerCount = 1;
vulkanClearRect.rect.offset.x = clearRect->x;
vulkanClearRect.rect.offset.y = clearRect->y;
vulkanClearRect.rect.extent.width = clearRect->w;
vulkanClearRect.rect.extent.height = clearRect->h;
attachmentCount = 0;
if (shouldClearColor)
{
for (i = 0; i < colorCount; i += 1)
{
clearValues[i].color.float32[0] = colors[i].x;
clearValues[i].color.float32[1] = colors[i].y;
clearValues[i].color.float32[2] = colors[i].z;
clearValues[i].color.float32[3] = colors[i].w;
}
for (i = 0; i < colorCount; i += 1)
{
clearAttachments[attachmentCount].aspectMask =
VK_IMAGE_ASPECT_COLOR_BIT;
clearAttachments[attachmentCount].colorAttachment =
attachmentCount;
clearAttachments[attachmentCount].clearValue =
clearValues[attachmentCount];
attachmentCount += 1;
/* Do NOT clear the multisample image here!
* Vulkan treats them both as the same color attachment.
* Vulkan is a very good and not confusing at all API.
*/
}
}
if (shouldClearDepthStencil)
{
clearAttachments[attachmentCount].aspectMask = 0;
clearAttachments[attachmentCount].colorAttachment = 0;
if (shouldClearDepth)
{
if (depthStencil.depth < 0.0f)
{
depthStencil.depth = 0.0f;
}
else if (depthStencil.depth > 1.0f)
{
depthStencil.depth = 1.0f;
}
clearAttachments[attachmentCount].aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
clearAttachments[attachmentCount].clearValue.depthStencil.depth = depthStencil.depth;
}
else
{
clearAttachments[attachmentCount].clearValue.depthStencil.depth = 0.0f;
}
if (shouldClearStencil)
{
clearAttachments[attachmentCount].aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
clearAttachments[attachmentCount].clearValue.depthStencil.stencil = depthStencil.stencil;
}
else
{
clearAttachments[attachmentCount].clearValue.depthStencil.stencil = 0;
}
attachmentCount += 1;
}
renderer->vkCmdClearAttachments(
vulkanCommandBuffer->commandBuffer,
attachmentCount,
clearAttachments,
1,
&vulkanClearRect
);
}
static void VULKAN_DrawInstancedPrimitives(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
@ -8954,7 +8843,9 @@ static VulkanSwapchainData* VULKAN_INTERNAL_FetchSwapchainData(
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer,
void *windowHandle
void *windowHandle,
uint32_t *pWidth,
uint32_t *pHeight
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
@ -9066,6 +8957,9 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
vulkanCommandBuffer->signalSemaphores[vulkanCommandBuffer->signalSemaphoreCount] = swapchainData->renderFinishedSemaphore;
vulkanCommandBuffer->signalSemaphoreCount += 1;
*pWidth = swapchainData->extent.width;
*pHeight = swapchainData->extent.height;
return (Refresh_Texture*) swapchainTexture;
}