plugging more leaks
continuous-integration/drone/push Build is passing Details

pull/13/head
cosmonaut 2022-02-22 16:20:43 -08:00
parent 98b6518f2b
commit 059c28d5c0
1 changed files with 147 additions and 115 deletions

View File

@ -3895,18 +3895,17 @@ static void VULKAN_INTERNAL_RecreateSwapchain(
) { ) {
CreateSwapchainResult createSwapchainResult; CreateSwapchainResult createSwapchainResult;
renderer->vkDeviceWaitIdle(renderer->logicalDevice); VULKAN_Wait((Refresh_Renderer*)renderer);
VULKAN_INTERNAL_DestroySwapchain(renderer, windowHandle); VULKAN_INTERNAL_DestroySwapchain(renderer, windowHandle);
createSwapchainResult = VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle); createSwapchainResult = VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle);
if (createSwapchainResult == CREATE_SWAPCHAIN_FAIL) if (createSwapchainResult == CREATE_SWAPCHAIN_FAIL)
{ {
Refresh_LogError("Failed to recreate swapchain!");
return; return;
} }
renderer->vkDeviceWaitIdle(renderer->logicalDevice); VULKAN_Wait((Refresh_Renderer*)renderer);
} }
/* Command Buffers */ /* Command Buffers */
@ -3980,10 +3979,25 @@ static void VULKAN_DestroyDevice(
VULKAN_Wait(device->driverData); VULKAN_Wait(device->driverData);
SDL_free(renderer->submittedCommandBuffers);
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyVertexUniformBuffer->vulkanBuffer); VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyVertexUniformBuffer->vulkanBuffer);
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyFragmentUniformBuffer->vulkanBuffer); VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyFragmentUniformBuffer->vulkanBuffer);
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyComputeUniformBuffer->vulkanBuffer); VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->dummyComputeUniformBuffer->vulkanBuffer);
SDL_free(renderer->dummyVertexUniformBuffer);
SDL_free(renderer->dummyFragmentUniformBuffer);
SDL_free(renderer->dummyComputeUniformBuffer);
for (i = 0; i < renderer->transferBufferPool.availableBufferCount; i += 1)
{
VULKAN_INTERNAL_DestroyBuffer(renderer, renderer->transferBufferPool.availableBuffers[i]->buffer);
SDL_free(renderer->transferBufferPool.availableBuffers[i]);
}
SDL_free(renderer->transferBufferPool.availableBuffers);
SDL_DestroyMutex(renderer->transferBufferPool.lock);
for (i = 0; i < renderer->availableFenceCount; i += 1) for (i = 0; i < renderer->availableFenceCount; i += 1)
{ {
renderer->vkDestroyFence( renderer->vkDestroyFence(
@ -3993,6 +4007,8 @@ static void VULKAN_DestroyDevice(
); );
} }
SDL_free(renderer->availableFences);
for (i = 0; i < NUM_COMMAND_POOL_BUCKETS; i += 1) for (i = 0; i < NUM_COMMAND_POOL_BUCKETS; i += 1)
{ {
commandPoolHashArray = renderer->commandPoolHashTable.buckets[i]; commandPoolHashArray = renderer->commandPoolHashTable.buckets[i];
@ -4015,11 +4031,23 @@ static void VULKAN_DestroyDevice(
graphicsPipelineLayoutHashArray = renderer->graphicsPipelineLayoutHashTable.buckets[i]; graphicsPipelineLayoutHashArray = renderer->graphicsPipelineLayoutHashTable.buckets[i];
for (j = 0; j < graphicsPipelineLayoutHashArray.count; j += 1) for (j = 0; j < graphicsPipelineLayoutHashArray.count; j += 1)
{ {
VULKAN_INTERNAL_DestroyDescriptorSetCache(
renderer,
graphicsPipelineLayoutHashArray.elements[j].value->vertexSamplerDescriptorSetCache
);
VULKAN_INTERNAL_DestroyDescriptorSetCache(
renderer,
graphicsPipelineLayoutHashArray.elements[j].value->fragmentSamplerDescriptorSetCache
);
renderer->vkDestroyPipelineLayout( renderer->vkDestroyPipelineLayout(
renderer->logicalDevice, renderer->logicalDevice,
graphicsPipelineLayoutHashArray.elements[j].value->pipelineLayout, graphicsPipelineLayoutHashArray.elements[j].value->pipelineLayout,
NULL NULL
); );
SDL_free(graphicsPipelineLayoutHashArray.elements[j].value);
} }
if (graphicsPipelineLayoutHashArray.elements != NULL) if (graphicsPipelineLayoutHashArray.elements != NULL)
@ -4045,6 +4073,8 @@ static void VULKAN_DestroyDevice(
computePipelineLayoutHashArray.elements[j].value->pipelineLayout, computePipelineLayoutHashArray.elements[j].value->pipelineLayout,
NULL NULL
); );
SDL_free(computePipelineLayoutHashArray.elements[j].value);
} }
if (computePipelineLayoutHashArray.elements != NULL) if (computePipelineLayoutHashArray.elements != NULL)
@ -5695,7 +5725,7 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
Refresh_BufferUsageFlags usageFlags, Refresh_BufferUsageFlags usageFlags,
uint32_t sizeInBytes uint32_t sizeInBytes
) { ) {
VulkanBuffer* buffer = SDL_malloc(sizeof(VulkanBuffer)); VulkanBuffer* buffer;
VkBufferUsageFlags vulkanUsageFlags = VkBufferUsageFlags vulkanUsageFlags =
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
@ -7459,7 +7489,7 @@ static void VULKAN_INTERNAL_AllocateCommandBuffers(
VkResult vulkanResult; VkResult vulkanResult;
uint32_t i; uint32_t i;
VkCommandBuffer *commandBuffers = SDL_stack_alloc(VkCommandBuffer, allocateCount); VkCommandBuffer *commandBuffers = SDL_stack_alloc(VkCommandBuffer, allocateCount);
VulkanCommandBuffer *currentVulkanCommandBuffer; VulkanCommandBuffer *commandBuffer;
vulkanCommandPool->inactiveCommandBufferCapacity += allocateCount; vulkanCommandPool->inactiveCommandBufferCapacity += allocateCount;
@ -7490,23 +7520,117 @@ static void VULKAN_INTERNAL_AllocateCommandBuffers(
for (i = 0; i < allocateCount; i += 1) for (i = 0; i < allocateCount; i += 1)
{ {
currentVulkanCommandBuffer = SDL_malloc(sizeof(VulkanCommandBuffer)); commandBuffer = SDL_malloc(sizeof(VulkanCommandBuffer));
currentVulkanCommandBuffer->commandPool = vulkanCommandPool; commandBuffer->commandPool = vulkanCommandPool;
currentVulkanCommandBuffer->commandBuffer = commandBuffers[i]; commandBuffer->commandBuffer = commandBuffers[i];
currentVulkanCommandBuffer->boundComputeBufferCount = 0; commandBuffer->boundComputeBufferCount = 0;
currentVulkanCommandBuffer->transferBufferCapacity = 4;
currentVulkanCommandBuffer->transferBufferCount = 0; commandBuffer->present = 0;
currentVulkanCommandBuffer->transferBuffers = SDL_malloc( commandBuffer->presentWindowHandle = NULL;
currentVulkanCommandBuffer->transferBufferCapacity * sizeof(VulkanTransferBuffer*) commandBuffer->presentSwapchainImageIndex = 0;
commandBuffer->needNewSwapchain = 0;
/* Transfer buffer tracking */
commandBuffer->transferBufferCapacity = 4;
commandBuffer->transferBufferCount = 0;
commandBuffer->transferBuffers = SDL_malloc(
commandBuffer->transferBufferCapacity * sizeof(VulkanTransferBuffer*)
);
/* Bound buffer tracking */
commandBuffer->boundUniformBufferCapacity = 16;
commandBuffer->boundUniformBufferCount = 0;
commandBuffer->boundUniformBuffers = SDL_malloc(
commandBuffer->boundUniformBufferCapacity * sizeof(VulkanUniformBuffer*)
);
/* Descriptor set tracking */
commandBuffer->boundDescriptorSetDataCapacity = 16;
commandBuffer->boundDescriptorSetDataCount = 0;
commandBuffer->boundDescriptorSetDatas = SDL_malloc(
commandBuffer->boundDescriptorSetDataCapacity * sizeof(DescriptorSetData)
);
/* Deferred destroy storage */
commandBuffer->renderTargetsToDestroyCapacity = 16;
commandBuffer->renderTargetsToDestroyCount = 0;
commandBuffer->renderTargetsToDestroy = (VulkanRenderTarget**) SDL_malloc(
sizeof(VulkanRenderTarget*) *
commandBuffer->renderTargetsToDestroyCapacity
);
commandBuffer->texturesToDestroyCapacity = 16;
commandBuffer->texturesToDestroyCount = 0;
commandBuffer->texturesToDestroy = (VulkanTexture**)SDL_malloc(
sizeof(VulkanTexture*) *
commandBuffer->texturesToDestroyCapacity
);
commandBuffer->buffersToDestroyCapacity = 16;
commandBuffer->buffersToDestroyCount = 0;
commandBuffer->buffersToDestroy = (VulkanBuffer**) SDL_malloc(
sizeof(VulkanBuffer*) *
commandBuffer->buffersToDestroyCapacity
);
commandBuffer->graphicsPipelinesToDestroyCapacity = 16;
commandBuffer->graphicsPipelinesToDestroyCount = 0;
commandBuffer->graphicsPipelinesToDestroy = (VulkanGraphicsPipeline**) SDL_malloc(
sizeof(VulkanGraphicsPipeline*) *
commandBuffer->graphicsPipelinesToDestroyCapacity
);
commandBuffer->computePipelinesToDestroyCapacity = 16;
commandBuffer->computePipelinesToDestroyCount = 0;
commandBuffer->computePipelinesToDestroy = (VulkanComputePipeline**) SDL_malloc(
sizeof(VulkanComputePipeline*) *
commandBuffer->computePipelinesToDestroyCapacity
);
commandBuffer->shaderModulesToDestroyCapacity = 16;
commandBuffer->shaderModulesToDestroyCount = 0;
commandBuffer->shaderModulesToDestroy = (VkShaderModule*) SDL_malloc(
sizeof(VkShaderModule) *
commandBuffer->shaderModulesToDestroyCapacity
);
commandBuffer->samplersToDestroyCapacity = 16;
commandBuffer->samplersToDestroyCount = 0;
commandBuffer->samplersToDestroy = (VkSampler*) SDL_malloc(
sizeof(VkSampler) *
commandBuffer->samplersToDestroyCapacity
);
commandBuffer->framebuffersToDestroyCapacity = 16;
commandBuffer->framebuffersToDestroyCount = 0;
commandBuffer->framebuffersToDestroy = (VulkanFramebuffer**) SDL_malloc(
sizeof(VulkanFramebuffer*) *
commandBuffer->framebuffersToDestroyCapacity
);
commandBuffer->renderPassesToDestroyCapacity = 16;
commandBuffer->renderPassesToDestroyCount = 0;
commandBuffer->renderPassesToDestroy = (VkRenderPass*) SDL_malloc(
sizeof(VkRenderPass) *
commandBuffer->renderPassesToDestroyCapacity
); );
currentVulkanCommandBuffer->present = 0;
currentVulkanCommandBuffer->presentWindowHandle = NULL;
currentVulkanCommandBuffer->presentSwapchainImageIndex = 0;
currentVulkanCommandBuffer->needNewSwapchain = 0;
vulkanCommandPool->inactiveCommandBuffers[ vulkanCommandPool->inactiveCommandBuffers[
vulkanCommandPool->inactiveCommandBufferCount vulkanCommandPool->inactiveCommandBufferCount
] = currentVulkanCommandBuffer; ] = commandBuffer;
vulkanCommandPool->inactiveCommandBufferCount += 1; vulkanCommandPool->inactiveCommandBufferCount += 1;
} }
@ -7615,7 +7739,7 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
SDL_UnlockMutex(renderer->acquireCommandBufferLock); SDL_UnlockMutex(renderer->acquireCommandBufferLock);
/* State tracking */ /* Reset state */
commandBuffer->currentComputePipeline = NULL; commandBuffer->currentComputePipeline = NULL;
commandBuffer->currentGraphicsPipeline = NULL; commandBuffer->currentGraphicsPipeline = NULL;
@ -7624,97 +7748,10 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
commandBuffer->fragmentUniformBuffer = NULL; commandBuffer->fragmentUniformBuffer = NULL;
commandBuffer->computeUniformBuffer = NULL; commandBuffer->computeUniformBuffer = NULL;
/* Bound buffer tracking */ commandBuffer->fixed = fixed;
commandBuffer->submitted = 0;
commandBuffer->boundUniformBufferCapacity = 16; commandBuffer->present = 0;
commandBuffer->boundUniformBufferCount = 0; commandBuffer->renderPassInProgress = 0;
commandBuffer->boundUniformBuffers = SDL_malloc(
commandBuffer->boundUniformBufferCapacity * sizeof(VulkanUniformBuffer*)
);
/* Descriptor set tracking */
commandBuffer->boundDescriptorSetDataCapacity = 16;
commandBuffer->boundDescriptorSetDataCount = 0;
commandBuffer->boundDescriptorSetDatas = SDL_malloc(
commandBuffer->boundDescriptorSetDataCapacity * sizeof(DescriptorSetData)
);
/* Deferred destroy storage */
commandBuffer->renderTargetsToDestroyCapacity = 16;
commandBuffer->renderTargetsToDestroyCount = 0;
commandBuffer->renderTargetsToDestroy = (VulkanRenderTarget**) SDL_malloc(
sizeof(VulkanRenderTarget*) *
commandBuffer->renderTargetsToDestroyCapacity
);
commandBuffer->texturesToDestroyCapacity = 16;
commandBuffer->texturesToDestroyCount = 0;
commandBuffer->texturesToDestroy = (VulkanTexture**)SDL_malloc(
sizeof(VulkanTexture*) *
commandBuffer->texturesToDestroyCapacity
);
commandBuffer->buffersToDestroyCapacity = 16;
commandBuffer->buffersToDestroyCount = 0;
commandBuffer->buffersToDestroy = (VulkanBuffer**) SDL_malloc(
sizeof(VulkanBuffer*) *
commandBuffer->buffersToDestroyCapacity
);
commandBuffer->graphicsPipelinesToDestroyCapacity = 16;
commandBuffer->graphicsPipelinesToDestroyCount = 0;
commandBuffer->graphicsPipelinesToDestroy = (VulkanGraphicsPipeline**) SDL_malloc(
sizeof(VulkanGraphicsPipeline*) *
commandBuffer->graphicsPipelinesToDestroyCapacity
);
commandBuffer->computePipelinesToDestroyCapacity = 16;
commandBuffer->computePipelinesToDestroyCount = 0;
commandBuffer->computePipelinesToDestroy = (VulkanComputePipeline**) SDL_malloc(
sizeof(VulkanComputePipeline*) *
commandBuffer->computePipelinesToDestroyCapacity
);
commandBuffer->shaderModulesToDestroyCapacity = 16;
commandBuffer->shaderModulesToDestroyCount = 0;
commandBuffer->shaderModulesToDestroy = (VkShaderModule*) SDL_malloc(
sizeof(VkShaderModule) *
commandBuffer->shaderModulesToDestroyCapacity
);
commandBuffer->samplersToDestroyCapacity = 16;
commandBuffer->samplersToDestroyCount = 0;
commandBuffer->samplersToDestroy = (VkSampler*) SDL_malloc(
sizeof(VkSampler) *
commandBuffer->samplersToDestroyCapacity
);
commandBuffer->framebuffersToDestroyCapacity = 16;
commandBuffer->framebuffersToDestroyCount = 0;
commandBuffer->framebuffersToDestroy = (VulkanFramebuffer**) SDL_malloc(
sizeof(VulkanFramebuffer*) *
commandBuffer->framebuffersToDestroyCapacity
);
commandBuffer->renderPassesToDestroyCapacity = 16;
commandBuffer->renderPassesToDestroyCount = 0;
commandBuffer->renderPassesToDestroy = (VkRenderPass*) SDL_malloc(
sizeof(VkRenderPass) *
commandBuffer->renderPassesToDestroyCapacity
);
/* init bound compute buffer array */
for (i = 0; i < MAX_BUFFER_BINDINGS; i += 1) for (i = 0; i < MAX_BUFFER_BINDINGS; i += 1)
{ {
@ -7722,11 +7759,6 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
} }
commandBuffer->boundComputeBufferCount = 0; commandBuffer->boundComputeBufferCount = 0;
commandBuffer->fixed = fixed;
commandBuffer->submitted = 0;
commandBuffer->present = 0;
commandBuffer->renderPassInProgress = 0;
VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer); VULKAN_INTERNAL_BeginCommandBuffer(renderer, commandBuffer);
return (Refresh_CommandBuffer*) commandBuffer; return (Refresh_CommandBuffer*) commandBuffer;