fix sequence of destroing buffers

This commit is contained in:
Denis Pauk 2020-03-15 11:28:36 +02:00 committed by Yamagi
parent ca29093f64
commit 9e71e69d1c
5 changed files with 41 additions and 20 deletions

View file

@ -106,7 +106,6 @@ void
QVk_FreeBuffer(qvkbuffer_t *buffer)
{
buffer_destroy(&buffer->resource);
buffer->resource.buffer = VK_NULL_HANDLE;
buffer->currentOffset = 0;
}
@ -114,7 +113,6 @@ void
QVk_FreeStagingBuffer(qvkstagingbuffer_t *buffer)
{
buffer_destroy(&buffer->resource);
buffer->resource.buffer = VK_NULL_HANDLE;
buffer->currentOffset = 0;
}

View file

@ -750,12 +750,15 @@ static void CreateDrawBuffers()
// internal helper
static void DestroyDrawBuffer(qvktexture_t *drawBuffer)
{
if (drawBuffer->imageView != VK_NULL_HANDLE)
{
vkDestroyImageView(vk_device.logical, drawBuffer->imageView, NULL);
drawBuffer->imageView = VK_NULL_HANDLE;
}
if (drawBuffer->resource.image != VK_NULL_HANDLE)
{
image_destroy(&drawBuffer->resource);
vkDestroyImageView(vk_device.logical, drawBuffer->imageView, NULL);
drawBuffer->resource.image = VK_NULL_HANDLE;
drawBuffer->imageView = VK_NULL_HANDLE;
}
}

View file

@ -431,15 +431,18 @@ static void QVk_ReleaseTexture(qvktexture_t *texture)
vkDeviceWaitIdle(vk_device.logical);
}
if (texture->imageView != VK_NULL_HANDLE)
{
vkDestroyImageView(vk_device.logical, texture->imageView, NULL);
texture->imageView = VK_NULL_HANDLE;
}
if (texture->resource.image != VK_NULL_HANDLE)
image_destroy(&texture->resource);
if (texture->imageView != VK_NULL_HANDLE)
vkDestroyImageView(vk_device.logical, texture->imageView, NULL);
if (texture->descriptorSet != VK_NULL_HANDLE)
vkFreeDescriptorSets(vk_device.logical, vk_descriptorPool, 1, &texture->descriptorSet);
texture->resource.image = VK_NULL_HANDLE;
texture->imageView = VK_NULL_HANDLE;
texture->descriptorSet = VK_NULL_HANDLE;
}

View file

@ -179,12 +179,21 @@ VkResult
buffer_destroy(BufferResource_t *buf)
{
assert(!buf->is_mapped);
if(buf->memory != VK_NULL_HANDLE)
vkFreeMemory(vk_device.logical, buf->memory, NULL);
// buffer should be destroed before bound memory
if(buf->buffer != VK_NULL_HANDLE)
vkDestroyBuffer(vk_device.logical, buf->buffer, NULL);
buf->buffer = VK_NULL_HANDLE;
buf->memory = VK_NULL_HANDLE;
{
vkDestroyBuffer(vk_device.logical, buf->buffer, NULL);
buf->buffer = VK_NULL_HANDLE;
}
// buffer desroed, we can free up memory
if(buf->memory != VK_NULL_HANDLE)
{
vkFreeMemory(vk_device.logical, buf->memory, NULL);
buf->memory = VK_NULL_HANDLE;
}
buf->size = 0;
return VK_SUCCESS;
@ -193,12 +202,20 @@ buffer_destroy(BufferResource_t *buf)
VkResult
image_destroy(ImageResource_t *img)
{
if(img->memory != VK_NULL_HANDLE)
vkFreeMemory(vk_device.logical, img->memory, NULL);
// image should be destroed before bound memory
if(img->image != VK_NULL_HANDLE)
vkDestroyImage(vk_device.logical, img->image, NULL);
img->image = VK_NULL_HANDLE;
img->memory = VK_NULL_HANDLE;
{
vkDestroyImage(vk_device.logical, img->image, NULL);
img->image = VK_NULL_HANDLE;
}
// image destroed, we can free up memory
if(img->memory != VK_NULL_HANDLE)
{
vkFreeMemory(vk_device.logical, img->memory, NULL);
img->memory = VK_NULL_HANDLE;
}
img->size = 0;
return VK_SUCCESS;

View file

@ -77,7 +77,7 @@ void QVk_CreateValidationLayers()
.pUserData = NULL
};
if( vk_validation->value > 1 )
if(vk_validation->value)
{
callbackInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;