Compare commits

...

5 Commits

Author SHA1 Message Date
Caleb Cornett 864d381d2a Remove fixed command buffers + minor cleanup 2023-01-13 20:33:07 -05:00
cosmonaut 903192cb4c Descriptor validation fix (#32)
The validator layer was complaining about us updating bound descriptor sets, this is technically a bug in the validator layer but resetting the command buffer in Cleanup makes more sense anyway. Also changed the wait for timeout call to a fence status query to make it easier to understand.

Reviewed-on: MoonsideGames/Refresh#32
2023-01-11 02:41:30 +00:00
cosmonaut 4cdd6a497a Fix transfer buffer alignment (#31)
Reviewed-on: MoonsideGames/Refresh#31
2023-01-07 05:24:58 +00:00
cosmonaut 28b4253fdf 1.10.0 2023-01-04 11:18:37 -08:00
TheSpydog e4215efe5e Enable multiDrawIndirect feature, add indirect command struct (#30)
Fixes a validation error when attempting to draw multiple primitives via an indirect draw call. Adds some documentation for how indirect draw buffers should be set up.

Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com>
Reviewed-on: MoonsideGames/Refresh#30
Co-authored-by: TheSpydog <thespydog@noreply.example.org>
Co-committed-by: TheSpydog <thespydog@noreply.example.org>
2023-01-04 18:44:02 +00:00
5 changed files with 62 additions and 72 deletions

View File

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

View File

@ -55,7 +55,7 @@ extern "C" {
/* Version API */
#define REFRESH_MAJOR_VERSION 1
#define REFRESH_MINOR_VERSION 9
#define REFRESH_MINOR_VERSION 10
#define REFRESH_PATCH_VERSION 0
#define REFRESH_COMPILED_VERSION ( \
@ -376,6 +376,14 @@ typedef struct Refresh_TextureSlice
uint32_t level;
} Refresh_TextureSlice;
typedef struct Refresh_IndirectDrawCommand
{
uint32_t vertexCount;
uint32_t instanceCount;
uint32_t firstVertex;
uint32_t firstInstance;
} Refresh_IndirectDrawCommand;
/* State structures */
typedef struct Refresh_SamplerStateCreateInfo
@ -666,6 +674,7 @@ REFRESHAPI void Refresh_DrawPrimitives(
);
/* Similar to Refresh_DrawPrimitives, but draw parameters are set from a buffer.
* The buffer layout should match the layout of Refresh_IndirectDrawCommand.
*
* buffer: A buffer containing draw parameters.
* offsetInBytes: The offset to start reading from the draw buffer.
@ -750,7 +759,7 @@ REFRESHAPI Refresh_Buffer* Refresh_CreateBuffer(
/* Uploads image data to a texture object.
*
* NOTE:
* NOTE:
* DO NOT expect this to execute in sequence relative to other commands!
* Calling SetTextureData in a command buffer that also references the
* texture may result in undefined behavior.
@ -1159,15 +1168,9 @@ REFRESHAPI Refresh_TextureFormat Refresh_GetSwapchainFormat(
* A command buffer may only be used on the thread that
* it was acquired on. Using it on any other thread is an error.
*
* fixed:
* If a command buffer is designated as fixed, it can be
* acquired once, have commands recorded into it, and
* be re-submitted indefinitely.
*
*/
REFRESHAPI Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
Refresh_Device *device,
uint8_t fixed
Refresh_Device *device
);
/* Acquires a texture to use for presentation.

View File

@ -789,13 +789,11 @@ void Refresh_UnclaimWindow(
}
Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
Refresh_Device *device,
uint8_t fixed
Refresh_Device *device
) {
NULL_RETURN_NULL(device);
return device->AcquireCommandBuffer(
device->driverData,
fixed
device->driverData
);
}

View File

@ -470,8 +470,7 @@ struct Refresh_Device
);
Refresh_CommandBuffer* (*AcquireCommandBuffer)(
Refresh_Renderer *driverData,
uint8_t fixed
Refresh_Renderer *driverData
);
Refresh_Texture* (*AcquireSwapchainTexture)(

View File

@ -1500,10 +1500,6 @@ typedef struct VulkanCommandPool VulkanCommandPool;
typedef struct VulkanCommandBuffer
{
VkCommandBuffer commandBuffer;
uint8_t fixed;
uint8_t submitted;
uint8_t renderPassInProgress;
VulkanCommandPool *commandPool;
VulkanPresentData *presentDatas;
@ -4662,11 +4658,7 @@ static void VULKAN_INTERNAL_BeginCommandBuffer(
beginInfo.pNext = NULL;
beginInfo.flags = 0;
beginInfo.pInheritanceInfo = NULL;
if (!commandBuffer->fixed)
{
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
}
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
result = renderer->vkBeginCommandBuffer(
commandBuffer->commandBuffer,
@ -6734,9 +6726,11 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer,
VkDeviceSize requiredSize
VkDeviceSize requiredSize,
VkDeviceSize alignment
) {
VkDeviceSize size;
VkDeviceSize offset;
uint32_t i;
VulkanTransferBuffer *transferBuffer;
@ -6745,9 +6739,11 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
for (i = 0; i < commandBuffer->transferBufferCount; i += 1)
{
transferBuffer = commandBuffer->transferBuffers[i];
offset = transferBuffer->offset + alignment - (transferBuffer->offset % alignment);
if (transferBuffer->offset + requiredSize <= transferBuffer->buffer->size)
if (offset + requiredSize <= transferBuffer->buffer->size)
{
transferBuffer->offset = offset;
return transferBuffer;
}
}
@ -6759,8 +6755,9 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
for (i = 0; i < renderer->transferBufferPool.availableBufferCount; i += 1)
{
transferBuffer = renderer->transferBufferPool.availableBuffers[i];
offset = transferBuffer->offset + alignment - (transferBuffer->offset % alignment);
if (transferBuffer->offset + requiredSize <= transferBuffer->buffer->size)
if (offset + requiredSize <= transferBuffer->buffer->size)
{
if (commandBuffer->transferBufferCount == commandBuffer->transferBufferCapacity)
{
@ -6778,6 +6775,7 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
renderer->transferBufferPool.availableBufferCount -= 1;
SDL_UnlockMutex(renderer->transferBufferPool.lock);
transferBuffer->offset = offset;
return transferBuffer;
}
}
@ -6847,7 +6845,8 @@ static void VULKAN_SetTextureData(
textureSlice->rectangle.w,
textureSlice->rectangle.h,
vulkanTexture->format
)
),
VULKAN_INTERNAL_BytesPerPixel(vulkanTexture->format)
);
if (transferBuffer == NULL)
@ -6944,7 +6943,7 @@ static void VULKAN_SetTextureDataYUV(
uint32_t dataLength
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanTexture *tex;
VulkanTexture *tex = (VulkanTexture*) y;
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*)commandBuffer;
VulkanTransferBuffer *transferBuffer;
@ -6957,7 +6956,8 @@ static void VULKAN_SetTextureDataYUV(
transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer(
renderer,
vulkanCommandBuffer,
yDataLength + uvDataLength
yDataLength + uvDataLength,
VULKAN_INTERNAL_BytesPerPixel(tex->format)
);
if (transferBuffer == NULL)
@ -6983,8 +6983,6 @@ static void VULKAN_SetTextureDataYUV(
/* Y */
tex = (VulkanTexture*) y;
SDL_memcpy(
stagingBufferPointer,
dataPtr,
@ -7336,7 +7334,8 @@ static void VULKAN_SetBufferData(
transferBuffer = VULKAN_INTERNAL_AcquireTransferBuffer(
renderer,
vulkanCommandBuffer,
dataLength
dataLength,
renderer->physicalDeviceProperties.properties.limits.optimalBufferCopyOffsetAlignment
);
if (transferBuffer == NULL)
@ -8477,8 +8476,6 @@ static void VULKAN_BeginRenderPass(
VK_SUBPASS_CONTENTS_INLINE
);
vulkanCommandBuffer->renderPassInProgress = 1;
SDL_stack_free(clearValues);
for (i = 0; i < colorAttachmentCount; i += 1)
@ -8615,7 +8612,6 @@ static void VULKAN_EndRenderPass(
vulkanCommandBuffer->renderPassDepthTexture = NULL;
vulkanCommandBuffer->currentGraphicsPipeline = NULL;
vulkanCommandBuffer->renderPassInProgress = 0;
}
static void VULKAN_BindGraphicsPipeline(
@ -9190,8 +9186,7 @@ static VulkanCommandBuffer* VULKAN_INTERNAL_GetInactiveCommandBufferFromPool(
}
static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
Refresh_Renderer *driverData,
uint8_t fixed
Refresh_Renderer *driverData
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VkResult result;
@ -9214,33 +9209,8 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
commandBuffer->fragmentUniformBuffer = NULL;
commandBuffer->computeUniformBuffer = NULL;
commandBuffer->fixed = fixed;
commandBuffer->submitted = 0;
commandBuffer->renderPassInProgress = 0;
commandBuffer->renderPassColorTargetCount = 0;
result = renderer->vkResetCommandBuffer(
commandBuffer->commandBuffer,
VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT
);
if (result != VK_SUCCESS)
{
LogVulkanResultAsError("vkResetCommandBuffer", result);
}
result = renderer->vkResetFences(
renderer->logicalDevice,
1,
&commandBuffer->inFlightFence
);
if (result != VK_SUCCESS)
{
LogVulkanResultAsError("vkResetFences", result);
}
VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer);
return (Refresh_CommandBuffer*) commandBuffer;
@ -9644,6 +9614,7 @@ static void VULKAN_INTERNAL_CleanCommandBuffer(
uint32_t i;
VulkanUniformBuffer *uniformBuffer;
DescriptorSetData *descriptorSetData;
VkResult result;
/* Bound uniform buffers are now available */
@ -9773,12 +9744,35 @@ static void VULKAN_INTERNAL_CleanCommandBuffer(
SDL_UnlockMutex(renderer->acquireCommandBufferLock);
/* Resent presentation data */
/* Reset presentation data */
commandBuffer->presentDataCount = 0;
commandBuffer->waitSemaphoreCount = 0;
commandBuffer->signalSemaphoreCount = 0;
/* Reset Vulkan state */
result = renderer->vkResetCommandBuffer(
commandBuffer->commandBuffer,
VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT
);
if (result != VK_SUCCESS)
{
LogVulkanResultAsError("vkResetCommandBuffer", result);
}
result = renderer->vkResetFences(
renderer->logicalDevice,
1,
&commandBuffer->inFlightFence
);
if (result != VK_SUCCESS)
{
LogVulkanResultAsError("vkResetFences", result);
}
/* Remove this command buffer from the submitted list */
for (i = 0; i < renderer->submittedCommandBufferCount; i += 1)
{
@ -9910,7 +9904,6 @@ static void VULKAN_Submit(
);
}
((VulkanCommandBuffer*)pCommandBuffers[i])->submitted = 1;
renderer->submittedCommandBuffers[renderer->submittedCommandBufferCount] = (VulkanCommandBuffer*) pCommandBuffers[i];
renderer->submittedCommandBufferCount += 1;
@ -9948,13 +9941,9 @@ static void VULKAN_Submit(
for (i = renderer->submittedCommandBufferCount - 1; i >= 0; i -= 1)
{
/* If we set a timeout of 0, we can query the command buffer state */
vulkanResult = renderer->vkWaitForFences(
vulkanResult = renderer->vkGetFenceStatus(
renderer->logicalDevice,
1,
&renderer->submittedCommandBuffers[i]->inFlightFence,
VK_TRUE,
0
renderer->submittedCommandBuffers[i]->inFlightFence
);
if (vulkanResult == VK_SUCCESS)
@ -10537,6 +10526,7 @@ static uint8_t VULKAN_INTERNAL_CreateLogicalDevice(
SDL_zero(deviceFeatures);
deviceFeatures.fillModeNonSolid = VK_TRUE;
deviceFeatures.samplerAnisotropy = VK_TRUE;
deviceFeatures.multiDrawIndirect = VK_TRUE;
/* creating the logical device */