fix transfer buffer record keeping
parent
159115cbfa
commit
81d04201d2
|
@ -1175,9 +1175,13 @@ typedef struct VulkanTransferBuffer
|
|||
|
||||
typedef struct VulkanTransferBufferPool
|
||||
{
|
||||
VulkanTransferBuffer **buffers;
|
||||
uint32_t bufferCount;
|
||||
uint32_t bufferCapacity;
|
||||
VulkanTransferBuffer **availableBuffers;
|
||||
uint32_t availableBufferCount;
|
||||
uint32_t availableBufferCapacity;
|
||||
|
||||
VulkanTransferBuffer **submittedBuffers;
|
||||
uint32_t submittedBufferCount;
|
||||
uint32_t submittedBufferCapacity;
|
||||
} VulkanTransferBufferPool;
|
||||
|
||||
typedef struct VulkanCommandPool VulkanCommandPool;
|
||||
|
@ -3928,6 +3932,23 @@ static void VULKAN_INTERNAL_PostWorkCleanup(VulkanRenderer* renderer)
|
|||
VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->fragmentUniformBufferPool);
|
||||
VULKAN_INTERNAL_RotateBoundUniformBuffers(renderer->computeUniformBufferPool);
|
||||
|
||||
if (renderer->transferBufferPool.submittedBufferCount + renderer->transferBufferPool.availableBufferCount > renderer->transferBufferPool.availableBufferCapacity)
|
||||
{
|
||||
renderer->transferBufferPool.availableBufferCapacity = renderer->transferBufferPool.submittedBufferCount + renderer->transferBufferPool.availableBufferCount;
|
||||
renderer->transferBufferPool.availableBuffers = SDL_realloc(
|
||||
renderer->transferBufferPool.availableBuffers,
|
||||
renderer->transferBufferPool.availableBufferCapacity * sizeof(VulkanTransferBuffer*)
|
||||
);
|
||||
}
|
||||
|
||||
for (i = 0; i < renderer->transferBufferPool.submittedBufferCount; i += 1)
|
||||
{
|
||||
renderer->transferBufferPool.submittedBuffers[i]->offset = 0;
|
||||
renderer->transferBufferPool.availableBuffers[renderer->transferBufferPool.availableBufferCount] = renderer->transferBufferPool.submittedBuffers[i];
|
||||
renderer->transferBufferPool.availableBufferCount += 1;
|
||||
}
|
||||
renderer->transferBufferPool.submittedBufferCount = 0;
|
||||
|
||||
/* Reset descriptor set data */
|
||||
VULKAN_INTERNAL_ResetDescriptorSetData(renderer);
|
||||
}
|
||||
|
@ -6283,9 +6304,9 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
|
|||
|
||||
/* Nothing fits, so let's get a transfer buffer from the pool */
|
||||
|
||||
for (i = 0; i < renderer->transferBufferPool.bufferCount; i += 1)
|
||||
for (i = 0; i < renderer->transferBufferPool.availableBufferCount; i += 1)
|
||||
{
|
||||
transferBuffer = renderer->transferBufferPool.buffers[i];
|
||||
transferBuffer = renderer->transferBufferPool.availableBuffers[i];
|
||||
|
||||
if (transferBuffer->offset + requiredSize <= transferBuffer->buffer->size)
|
||||
{
|
||||
|
@ -6296,8 +6317,8 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
|
|||
commandBuffer->transferBuffers[commandBuffer->transferBufferCount] = transferBuffer;
|
||||
commandBuffer->transferBufferCount += 1;
|
||||
|
||||
renderer->transferBufferPool.buffers[i] = renderer->transferBufferPool.buffers[renderer->transferBufferPool.bufferCount - 1];
|
||||
renderer->transferBufferPool.bufferCount -= 1;
|
||||
renderer->transferBufferPool.availableBuffers[i] = renderer->transferBufferPool.availableBuffers[renderer->transferBufferPool.availableBufferCount - 1];
|
||||
renderer->transferBufferPool.availableBufferCount -= 1;
|
||||
|
||||
return transferBuffer;
|
||||
}
|
||||
|
@ -8429,19 +8450,19 @@ static void VULKAN_INTERNAL_ResetCommandBuffer(
|
|||
}
|
||||
|
||||
/* Return transfer buffers to the pool */
|
||||
if (renderer->transferBufferPool.bufferCount + commandBuffer->transferBufferCount > renderer->transferBufferPool.bufferCapacity)
|
||||
if (renderer->transferBufferPool.submittedBufferCount + commandBuffer->transferBufferCount > renderer->transferBufferPool.submittedBufferCapacity)
|
||||
{
|
||||
renderer->transferBufferPool.bufferCapacity = renderer->transferBufferPool.bufferCount + commandBuffer->transferBufferCount;
|
||||
renderer->transferBufferPool.buffers = SDL_realloc(
|
||||
renderer->transferBufferPool.buffers,
|
||||
renderer->transferBufferPool.bufferCapacity * sizeof(VulkanTransferBuffer*)
|
||||
renderer->transferBufferPool.submittedBufferCapacity = renderer->transferBufferPool.submittedBufferCount + commandBuffer->transferBufferCount;
|
||||
renderer->transferBufferPool.submittedBuffers = SDL_realloc(
|
||||
renderer->transferBufferPool.submittedBuffers,
|
||||
renderer->transferBufferPool.submittedBufferCapacity * sizeof(VulkanTransferBuffer*)
|
||||
);
|
||||
}
|
||||
|
||||
for (i = 0; i < commandBuffer->transferBufferCount; i+= 1)
|
||||
{
|
||||
renderer->transferBufferPool.buffers[renderer->transferBufferPool.bufferCount] = commandBuffer->transferBuffers[i];
|
||||
renderer->transferBufferPool.bufferCount += 1;
|
||||
renderer->transferBufferPool.submittedBuffers[renderer->transferBufferPool.submittedBufferCount] = commandBuffer->transferBuffers[i];
|
||||
renderer->transferBufferPool.submittedBufferCount += 1;
|
||||
}
|
||||
|
||||
SDL_free(commandBuffer->transferBuffers);
|
||||
|
@ -9820,9 +9841,13 @@ static Refresh_Device* VULKAN_INTERNAL_CreateDevice(
|
|||
|
||||
/* Initialize transfer buffer pool */
|
||||
|
||||
renderer->transferBufferPool.bufferCapacity = 4;
|
||||
renderer->transferBufferPool.bufferCount = 0;
|
||||
renderer->transferBufferPool.buffers = SDL_malloc(renderer->transferBufferPool.bufferCapacity * sizeof(VulkanTransferBuffer*));
|
||||
renderer->transferBufferPool.availableBufferCapacity = 4;
|
||||
renderer->transferBufferPool.availableBufferCount = 0;
|
||||
renderer->transferBufferPool.availableBuffers = SDL_malloc(renderer->transferBufferPool.availableBufferCapacity * sizeof(VulkanTransferBuffer*));
|
||||
|
||||
renderer->transferBufferPool.submittedBufferCapacity = 4;
|
||||
renderer->transferBufferPool.submittedBufferCount = 0;
|
||||
renderer->transferBufferPool.submittedBuffers = SDL_malloc(renderer->transferBufferPool.submittedBufferCapacity * sizeof(VulkanTransferBuffer*));
|
||||
|
||||
/* Deferred destroy storage */
|
||||
|
||||
|
|
Loading…
Reference in New Issue