Fix unmap warning on swap buffers resize

This commit is contained in:
Denis Pauk 2020-10-31 23:49:45 +02:00 committed by Yamagi
parent fd327dcdae
commit 16ae9af406
3 changed files with 11 additions and 8 deletions

View file

@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
typedef struct BufferResource_s {
VkBuffer buffer;
// shared memory used for image
// shared memory used for buffer
VkDeviceMemory memory;
// image size
VkDeviceSize size;

View file

@ -2148,8 +2148,9 @@ uint8_t *QVk_GetVertexBuffer(VkDeviceSize size, VkBuffer *dstBuffer, VkDeviceSiz
for (int i = 0; i < NUM_DYNBUFFERS; ++i)
{
vk_swapBuffers[vk_activeSwapBufferIdx][swapBufferOffset + i] = vk_dynVertexBuffers[i];
// need unmap before copy to swapBuffers
buffer_unmap(&vk_dynVertexBuffers[i].resource);
vk_swapBuffers[vk_activeSwapBufferIdx][swapBufferOffset + i] = vk_dynVertexBuffers[i];
QVk_CreateVertexBuffer(NULL, vk_config.vertex_buffer_size,
&vk_dynVertexBuffers[i], VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
@ -2193,8 +2194,9 @@ static uint8_t *QVk_GetIndexBuffer(VkDeviceSize size, VkDeviceSize *dstOffset)
for (int i = 0; i < NUM_DYNBUFFERS; ++i)
{
vk_swapBuffers[vk_activeSwapBufferIdx][swapBufferOffset + i] = vk_dynIndexBuffers[i];
// need unmap before copy to swapBuffers
buffer_unmap(&vk_dynIndexBuffers[i].resource);
vk_swapBuffers[vk_activeSwapBufferIdx][swapBufferOffset + i] = vk_dynIndexBuffers[i];
QVk_CreateIndexBuffer(NULL, vk_config.index_buffer_size,
&vk_dynIndexBuffers[i], VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
@ -2244,9 +2246,10 @@ uint8_t *QVk_GetUniformBuffer(VkDeviceSize size, uint32_t *dstOffset, VkDescript
for (int i = 0; i < NUM_DYNBUFFERS; ++i)
{
// need unmap before copy to swapBuffers
buffer_unmap(&vk_dynUniformBuffers[i].resource);
vk_swapBuffers[vk_activeSwapBufferIdx][swapBufferOffset + i] = vk_dynUniformBuffers[i];
vk_swapDescriptorSets[vk_activeSwapBufferIdx][swapDescSetsOffset + i] = vk_uboDescriptorSets[i];
buffer_unmap(&vk_dynUniformBuffers[i].resource);
VK_VERIFY(QVk_CreateUniformBuffer(vk_config.uniform_buffer_size,
&vk_dynUniformBuffers[i], VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT));

View file

@ -501,8 +501,7 @@ buffer_destroy(BufferResource_t *buf)
buf->memory = VK_NULL_HANDLE;
}
buf->size = 0;
buf->offset = 0;
memset(buf, 0, sizeof(BufferResource_t));
return VK_SUCCESS;
}
@ -524,8 +523,7 @@ image_destroy(ImageResource_t *img)
img->memory = VK_NULL_HANDLE;
}
img->size = 0;
img->offset = 0;
memset(img, 0, sizeof(ImageResource_t));
return VK_SUCCESS;
}
@ -564,6 +562,7 @@ buffer_invalidate(BufferResource_t *buf)
void *
buffer_map(BufferResource_t *buf)
{
assert(buf->memory);
assert(!buf->is_mapped);
buf->is_mapped = VK_TRUE;
void *ret = NULL;
@ -577,6 +576,7 @@ buffer_map(BufferResource_t *buf)
void
buffer_unmap(BufferResource_t *buf)
{
assert(buf->memory);
assert(buf->is_mapped);
buf->is_mapped = VK_FALSE;
vkUnmapMemory(vk_device.logical, buf->memory);