forked from MoonsideGames/Refresh
more disposal
parent
e3f07a9f5a
commit
6bfc44ca98
|
@ -108,13 +108,13 @@ static uint32_t deviceExtensionCount = SDL_arraysize(deviceExtensionNames);
|
||||||
); \
|
); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPAND_ARRAY_IF_NEEDED(arr, type, newCount, capacity, newCapacity) \
|
#define EXPAND_ARRAY_IF_NEEDED(arr, elementType, newCount, capacity, newCapacity) \
|
||||||
if (newCount >= capacity) \
|
if (newCount >= capacity) \
|
||||||
{ \
|
{ \
|
||||||
capacity = newCapacity; \
|
capacity = newCapacity; \
|
||||||
arr = (type*) SDL_realloc( \
|
arr = (elementType*) SDL_realloc( \
|
||||||
arr, \
|
arr, \
|
||||||
sizeof(type) * capacity \
|
sizeof(elementType) * capacity \
|
||||||
); \
|
); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,6 +1094,14 @@ typedef struct VulkanRenderer
|
||||||
uint32_t submittedGraphicsPipelinesToDestroyCount;
|
uint32_t submittedGraphicsPipelinesToDestroyCount;
|
||||||
uint32_t submittedGraphicsPipelinesToDestroyCapacity;
|
uint32_t submittedGraphicsPipelinesToDestroyCapacity;
|
||||||
|
|
||||||
|
VkShaderModule *shaderModulesToDestroy;
|
||||||
|
uint32_t shaderModulesToDestroyCount;
|
||||||
|
uint32_t shaderModulesToDestroyCapacity;
|
||||||
|
|
||||||
|
VkShaderModule *submittedShaderModulesToDestroy;
|
||||||
|
uint32_t submittedShaderModulesToDestroyCount;
|
||||||
|
uint32_t submittedShaderModulesToDestroyCapacity;
|
||||||
|
|
||||||
#define VULKAN_INSTANCE_FUNCTION(ext, ret, func, params) \
|
#define VULKAN_INSTANCE_FUNCTION(ext, ret, func, params) \
|
||||||
vkfntype_##func func;
|
vkfntype_##func func;
|
||||||
#define VULKAN_DEVICE_FUNCTION(ext, ret, func, params) \
|
#define VULKAN_DEVICE_FUNCTION(ext, ret, func, params) \
|
||||||
|
@ -1817,16 +1825,13 @@ static void VULKAN_INTERNAL_RemoveBuffer(
|
||||||
|
|
||||||
SDL_LockMutex(renderer->disposeLock);
|
SDL_LockMutex(renderer->disposeLock);
|
||||||
|
|
||||||
/* Queue buffer for destruction */
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
if (renderer->buffersToDestroyCount + 1 >= renderer->buffersToDestroyCapacity)
|
|
||||||
{
|
|
||||||
renderer->buffersToDestroyCapacity *= 2;
|
|
||||||
|
|
||||||
renderer->buffersToDestroy = SDL_realloc(
|
|
||||||
renderer->buffersToDestroy,
|
renderer->buffersToDestroy,
|
||||||
sizeof(VulkanBuffer*) * renderer->buffersToDestroyCapacity
|
VulkanBuffer*,
|
||||||
);
|
renderer->buffersToDestroyCount + 1,
|
||||||
}
|
renderer->buffersToDestroyCapacity,
|
||||||
|
renderer->buffersToDestroyCapacity * 2
|
||||||
|
)
|
||||||
|
|
||||||
renderer->buffersToDestroy[
|
renderer->buffersToDestroy[
|
||||||
renderer->buffersToDestroyCount
|
renderer->buffersToDestroyCount
|
||||||
|
@ -1981,6 +1986,17 @@ static void VULKAN_INTERNAL_DestroyGraphicsPipeline(
|
||||||
SDL_free(graphicsPipeline);
|
SDL_free(graphicsPipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void VULKAN_INTERNAL_DestroyShaderModule(
|
||||||
|
VulkanRenderer *renderer,
|
||||||
|
VkShaderModule shaderModule
|
||||||
|
) {
|
||||||
|
renderer->vkDestroyShaderModule(
|
||||||
|
renderer->logicalDevice,
|
||||||
|
shaderModule,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_DestroySwapchain(VulkanRenderer* renderer)
|
static void VULKAN_INTERNAL_DestroySwapchain(VulkanRenderer* renderer)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -2093,6 +2109,15 @@ static void VULKAN_INTERNAL_PostSubmitCleanup(VulkanRenderer* renderer)
|
||||||
}
|
}
|
||||||
renderer->submittedGraphicsPipelinesToDestroyCount = 0;
|
renderer->submittedGraphicsPipelinesToDestroyCount = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < renderer->submittedShaderModulesToDestroyCount; i += 1)
|
||||||
|
{
|
||||||
|
VULKAN_INTERNAL_DestroyShaderModule(
|
||||||
|
renderer,
|
||||||
|
renderer->submittedShaderModulesToDestroy[i]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
renderer->submittedShaderModulesToDestroyCount = 0;
|
||||||
|
|
||||||
/* Re-size submitted destroy lists */
|
/* Re-size submitted destroy lists */
|
||||||
|
|
||||||
EXPAND_ARRAY_IF_NEEDED(
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
|
@ -2127,6 +2152,14 @@ static void VULKAN_INTERNAL_PostSubmitCleanup(VulkanRenderer* renderer)
|
||||||
renderer->graphicsPipelinesToDestroyCount
|
renderer->graphicsPipelinesToDestroyCount
|
||||||
)
|
)
|
||||||
|
|
||||||
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
|
renderer->submittedShaderModulesToDestroy,
|
||||||
|
VkShaderModule,
|
||||||
|
renderer->shaderModulesToDestroyCount,
|
||||||
|
renderer->submittedShaderModulesToDestroyCapacity,
|
||||||
|
renderer->shaderModulesToDestroyCount
|
||||||
|
)
|
||||||
|
|
||||||
/* Rotate destroy lists */
|
/* Rotate destroy lists */
|
||||||
|
|
||||||
for (i = 0; i < renderer->colorTargetsToDestroyCount; i += 1)
|
for (i = 0; i < renderer->colorTargetsToDestroyCount; i += 1)
|
||||||
|
@ -2157,6 +2190,13 @@ static void VULKAN_INTERNAL_PostSubmitCleanup(VulkanRenderer* renderer)
|
||||||
renderer->submittedGraphicsPipelinesToDestroyCount = renderer->graphicsPipelinesToDestroyCount;
|
renderer->submittedGraphicsPipelinesToDestroyCount = renderer->graphicsPipelinesToDestroyCount;
|
||||||
renderer->graphicsPipelinesToDestroyCount = 0;
|
renderer->graphicsPipelinesToDestroyCount = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < renderer->shaderModulesToDestroyCount; i += 1)
|
||||||
|
{
|
||||||
|
renderer->submittedShaderModulesToDestroy[i] = renderer->shaderModulesToDestroy[i];
|
||||||
|
}
|
||||||
|
renderer->submittedShaderModulesToDestroyCount = renderer->shaderModulesToDestroyCount;
|
||||||
|
renderer->shaderModulesToDestroyCount = 0;
|
||||||
|
|
||||||
SDL_UnlockMutex(renderer->disposeLock);
|
SDL_UnlockMutex(renderer->disposeLock);
|
||||||
|
|
||||||
/* Increment the frame index */
|
/* Increment the frame index */
|
||||||
|
@ -5848,7 +5888,7 @@ static void VULKAN_AddDisposeTexture(
|
||||||
EXPAND_ARRAY_IF_NEEDED(
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
renderer->texturesToDestroy,
|
renderer->texturesToDestroy,
|
||||||
VulkanTexture*,
|
VulkanTexture*,
|
||||||
renderer->texturesToDestroyCount,
|
renderer->texturesToDestroyCount + 1,
|
||||||
renderer->texturesToDestroyCapacity,
|
renderer->texturesToDestroyCapacity,
|
||||||
renderer->texturesToDestroyCapacity * 2
|
renderer->texturesToDestroyCapacity * 2
|
||||||
)
|
)
|
||||||
|
@ -5892,7 +5932,7 @@ static void VULKAN_AddDisposeColorTarget(
|
||||||
EXPAND_ARRAY_IF_NEEDED(
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
renderer->colorTargetsToDestroy,
|
renderer->colorTargetsToDestroy,
|
||||||
VulkanColorTarget*,
|
VulkanColorTarget*,
|
||||||
renderer->colorTargetsToDestroyCount,
|
renderer->colorTargetsToDestroyCount + 1,
|
||||||
renderer->colorTargetsToDestroyCapacity,
|
renderer->colorTargetsToDestroyCapacity,
|
||||||
renderer->colorTargetsToDestroyCapacity * 2
|
renderer->colorTargetsToDestroyCapacity * 2
|
||||||
)
|
)
|
||||||
|
@ -5901,7 +5941,6 @@ static void VULKAN_AddDisposeColorTarget(
|
||||||
renderer->colorTargetsToDestroyCount += 1;
|
renderer->colorTargetsToDestroyCount += 1;
|
||||||
|
|
||||||
SDL_UnlockMutex(renderer->disposeLock);
|
SDL_UnlockMutex(renderer->disposeLock);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_AddDisposeDepthStencilTarget(
|
static void VULKAN_AddDisposeDepthStencilTarget(
|
||||||
|
@ -5922,7 +5961,23 @@ static void VULKAN_AddDisposeShaderModule(
|
||||||
REFRESH_Renderer *driverData,
|
REFRESH_Renderer *driverData,
|
||||||
REFRESH_ShaderModule *shaderModule
|
REFRESH_ShaderModule *shaderModule
|
||||||
) {
|
) {
|
||||||
SDL_assert(0);
|
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||||
|
VkShaderModule vulkanShaderModule = (VkShaderModule) shaderModule;
|
||||||
|
|
||||||
|
SDL_LockMutex(renderer->disposeLock);
|
||||||
|
|
||||||
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
|
renderer->shaderModulesToDestroy,
|
||||||
|
VkShaderModule,
|
||||||
|
renderer->shaderModulesToDestroyCount + 1,
|
||||||
|
renderer->shaderModulesToDestroyCapacity,
|
||||||
|
renderer->shaderModulesToDestroyCapacity * 2
|
||||||
|
)
|
||||||
|
|
||||||
|
renderer->shaderModulesToDestroy[renderer->shaderModulesToDestroyCount] = vulkanShaderModule;
|
||||||
|
renderer->shaderModulesToDestroyCount += 1;
|
||||||
|
|
||||||
|
SDL_UnlockMutex(renderer->disposeLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_AddDisposeRenderPass(
|
static void VULKAN_AddDisposeRenderPass(
|
||||||
|
@ -5944,7 +5999,7 @@ static void VULKAN_AddDisposeGraphicsPipeline(
|
||||||
EXPAND_ARRAY_IF_NEEDED(
|
EXPAND_ARRAY_IF_NEEDED(
|
||||||
renderer->graphicsPipelinesToDestroy,
|
renderer->graphicsPipelinesToDestroy,
|
||||||
VulkanGraphicsPipeline*,
|
VulkanGraphicsPipeline*,
|
||||||
renderer->graphicsPipelinesToDestroyCount,
|
renderer->graphicsPipelinesToDestroyCount + 1,
|
||||||
renderer->graphicsPipelinesToDestroyCapacity,
|
renderer->graphicsPipelinesToDestroyCapacity,
|
||||||
renderer->graphicsPipelinesToDestroyCapacity * 2
|
renderer->graphicsPipelinesToDestroyCapacity * 2
|
||||||
)
|
)
|
||||||
|
@ -7800,6 +7855,22 @@ static REFRESH_Device* VULKAN_CreateDevice(
|
||||||
renderer->submittedGraphicsPipelinesToDestroyCapacity
|
renderer->submittedGraphicsPipelinesToDestroyCapacity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
renderer->shaderModulesToDestroyCapacity = 16;
|
||||||
|
renderer->shaderModulesToDestroyCount = 0;
|
||||||
|
|
||||||
|
renderer->shaderModulesToDestroy = (VkShaderModule*) SDL_malloc(
|
||||||
|
sizeof(VkShaderModule) *
|
||||||
|
renderer->shaderModulesToDestroyCapacity
|
||||||
|
);
|
||||||
|
|
||||||
|
renderer->submittedShaderModulesToDestroyCapacity = 16;
|
||||||
|
renderer->submittedShaderModulesToDestroyCount = 0;
|
||||||
|
|
||||||
|
renderer->submittedShaderModulesToDestroy = (VkShaderModule*) SDL_malloc(
|
||||||
|
sizeof(VkShaderModule) *
|
||||||
|
renderer->submittedShaderModulesToDestroyCapacity
|
||||||
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyPipelineLayout, (VkDevice device,
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyRenderPass, (VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator))
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyRenderPass, (VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator))
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySampler, (VkDevice device, VkSampler sampler, const VkAllocationCallbacks *pAllocator))
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySampler, (VkDevice device, VkSampler sampler, const VkAllocationCallbacks *pAllocator))
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySemaphore, (VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator))
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySemaphore, (VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator))
|
||||||
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyShaderModule, (VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator))
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySwapchainKHR, (VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator))
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroySwapchainKHR, (VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator))
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyQueryPool, (VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks *pAllocator))
|
VULKAN_DEVICE_FUNCTION(BaseVK, void, vkDestroyQueryPool, (VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks *pAllocator))
|
||||||
VULKAN_DEVICE_FUNCTION(BaseVK, VkResult, vkDeviceWaitIdle, (VkDevice device))
|
VULKAN_DEVICE_FUNCTION(BaseVK, VkResult, vkDeviceWaitIdle, (VkDevice device))
|
||||||
|
|
Loading…
Reference in New Issue