mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[vulkan] Free the staging buffer's command buffers
Since the staging buffer allocates the command buffers it uses, it needs to free them when it is freed. I think I was confused by the validation layers not complaining about unfreed buffers when shutting down, but that's because destroying the pool (during program shutdown, when the validation layers would complain) frees all the buffers. Thus, due to staging buffers being created and destroyed during the level load process, (rather large) command buffers were piling up like imps in a Doom level. In the process, it was necessary to rearrange some of the shutdown code because vulkan_vid_render_shutdown destroys the shared command pool, but the pool is required for freeing the command buffers, but there was a minor mess of long-lived staging buffers being freed afterwards. That didn't end particularly well.
This commit is contained in:
parent
0dca1e1124
commit
ceaac00453
4 changed files with 12 additions and 3 deletions
|
@ -13,6 +13,7 @@ typedef struct qfv_packet_s {
|
|||
|
||||
typedef struct qfv_stagebuf_s {
|
||||
struct qfv_device_s *device;
|
||||
VkCommandPool cmdPool;
|
||||
VkBuffer buffer;
|
||||
VkDeviceMemory memory;
|
||||
RING_BUFFER(qfv_packet_t, 4) packets; ///< packets for controlling access
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "QF/Vulkan/image.h"
|
||||
#include "QF/Vulkan/instance.h"
|
||||
#include "QF/Vulkan/projection.h"
|
||||
#include "QF/Vulkan/staging.h"
|
||||
#include "QF/Vulkan/renderpass.h"
|
||||
#include "QF/Vulkan/swapchain.h"
|
||||
#include "QF/ui/view.h"
|
||||
|
@ -693,8 +694,6 @@ vulkan_vid_render_shutdown (void)
|
|||
qfv_devfuncs_t *df = device->funcs;
|
||||
VkDevice dev = device->dev;
|
||||
QFV_DeviceWaitIdle (device);
|
||||
df->vkDestroyFence (dev, vulkan_ctx->fence, 0);
|
||||
df->vkDestroyCommandPool (dev, vulkan_ctx->cmdpool, 0);
|
||||
|
||||
Mod_ClearAll ();
|
||||
|
||||
|
@ -710,6 +709,11 @@ vulkan_vid_render_shutdown (void)
|
|||
|
||||
Vulkan_Texture_Shutdown (vulkan_ctx);
|
||||
Vulkan_DestroyRenderPasses (vulkan_ctx);
|
||||
|
||||
QFV_DestroyStagingBuffer (vulkan_ctx->staging);
|
||||
df->vkDestroyFence (dev, vulkan_ctx->fence, 0);
|
||||
df->vkDestroyCommandPool (dev, vulkan_ctx->cmdpool, 0);
|
||||
|
||||
Vulkan_Shutdown_Common (vulkan_ctx);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ QFV_CreateStagingBuffer (qfv_device_t *device, const char *name, size_t size,
|
|||
stage->atom_mask = atom - 1;
|
||||
size = (size + stage->atom_mask) & ~stage->atom_mask;
|
||||
stage->device = device;
|
||||
stage->cmdPool = cmdPool;
|
||||
stage->buffer = QFV_CreateBuffer (device, size,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_BUFFER, stage->buffer,
|
||||
|
@ -96,14 +97,18 @@ QFV_DestroyStagingBuffer (qfv_stagebuf_t *stage)
|
|||
|
||||
int count = RB_buffer_size (&stage->packets);
|
||||
__auto_type fences = QFV_AllocFenceSet (count, alloca);
|
||||
__auto_type cmdBuf = QFV_AllocCommandBufferSet (count, alloca);
|
||||
for (int i = 0; i < count; i++) {
|
||||
fences->a[i] = stage->packets.buffer[i].fence;
|
||||
cmdBuf->a[i] = stage->packets.buffer[i].cmd;
|
||||
}
|
||||
dfunc->vkWaitForFences (device->dev, fences->size, fences->a, VK_TRUE,
|
||||
5000000000ull);
|
||||
for (int i = 0; i < count; i++) {
|
||||
dfunc->vkDestroyFence (device->dev, fences->a[i], 0);
|
||||
}
|
||||
dfunc->vkFreeCommandBuffers (device->dev, stage->cmdPool,
|
||||
cmdBuf->size, cmdBuf->a);
|
||||
|
||||
dfunc->vkUnmapMemory (device->dev, stage->memory);
|
||||
dfunc->vkFreeMemory (device->dev, stage->memory, 0);
|
||||
|
|
|
@ -235,7 +235,6 @@ Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
|
|||
if (ctx->swapchain) {
|
||||
QFV_DestroySwapchain (ctx->swapchain);
|
||||
}
|
||||
QFV_DestroyStagingBuffer (ctx->staging);
|
||||
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
|
||||
ctx->surface, 0);
|
||||
clear_table (&ctx->pipelineLayouts);
|
||||
|
|
Loading…
Reference in a new issue