remove Clear and add pWidth and pHeight to AcquireSwapchainTexture

main
cosmonaut 2022-03-10 10:21:49 -08:00
parent 7a0b0f5709
commit 3820d458fe
5 changed files with 25 additions and 195 deletions

View File

@ -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

@ -147,27 +147,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,
@ -729,13 +708,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

@ -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;
}