Compare commits

..

No commits in common. "864d381d2ace9af3439881b15cf33040667e1af0" and "329ffab6b8dab0bc736432cc4423373a5c97daa9" have entirely different histories.

5 changed files with 72 additions and 62 deletions

View File

@ -8,7 +8,7 @@ option(BUILD_SHARED_LIBS "Build shared library" ON)
# Version # Version
SET(LIB_MAJOR_VERSION "1") SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "10") SET(LIB_MINOR_VERSION "9")
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

@ -55,7 +55,7 @@ extern "C" {
/* Version API */ /* Version API */
#define REFRESH_MAJOR_VERSION 1 #define REFRESH_MAJOR_VERSION 1
#define REFRESH_MINOR_VERSION 10 #define REFRESH_MINOR_VERSION 9
#define REFRESH_PATCH_VERSION 0 #define REFRESH_PATCH_VERSION 0
#define REFRESH_COMPILED_VERSION ( \ #define REFRESH_COMPILED_VERSION ( \
@ -376,14 +376,6 @@ typedef struct Refresh_TextureSlice
uint32_t level; uint32_t level;
} Refresh_TextureSlice; } Refresh_TextureSlice;
typedef struct Refresh_IndirectDrawCommand
{
uint32_t vertexCount;
uint32_t instanceCount;
uint32_t firstVertex;
uint32_t firstInstance;
} Refresh_IndirectDrawCommand;
/* State structures */ /* State structures */
typedef struct Refresh_SamplerStateCreateInfo typedef struct Refresh_SamplerStateCreateInfo
@ -674,7 +666,6 @@ REFRESHAPI void Refresh_DrawPrimitives(
); );
/* Similar to Refresh_DrawPrimitives, but draw parameters are set from a buffer. /* 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. * buffer: A buffer containing draw parameters.
* offsetInBytes: The offset to start reading from the draw buffer. * offsetInBytes: The offset to start reading from the draw buffer.
@ -1168,9 +1159,15 @@ REFRESHAPI Refresh_TextureFormat Refresh_GetSwapchainFormat(
* A command buffer may only be used on the thread that * A command buffer may only be used on the thread that
* it was acquired on. Using it on any other thread is an error. * 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( REFRESHAPI Refresh_CommandBuffer* Refresh_AcquireCommandBuffer(
Refresh_Device *device Refresh_Device *device,
uint8_t fixed
); );
/* Acquires a texture to use for presentation. /* Acquires a texture to use for presentation.

View File

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

View File

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

View File

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