From 7e7b82086cf6384bebec038f9a8d7cacdd688b6c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 22 Jan 2021 02:18:39 +0900 Subject: [PATCH] [vulkan] Round up the staging buffer size Vulkan validation (quite rightly) doesn't like it when the flush range goes past the end of the buffer, but also doesn't like it when the flush range isn't cache-line aligned, so align the size of the buffer, too. --- include/QF/Vulkan/staging.h | 1 + libs/video/renderer/vulkan/staging.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/QF/Vulkan/staging.h b/include/QF/Vulkan/staging.h index aaac5d749..e8cf18ae7 100644 --- a/include/QF/Vulkan/staging.h +++ b/include/QF/Vulkan/staging.h @@ -17,6 +17,7 @@ typedef struct qfv_stagebuf_s { size_t num_packets;///< number of packets in array size_t next_packet;///< index of the next packet to be used size_t size; ///< actual size of the buffer + size_t atom_mask; ///< for flush size rounding size_t end; ///< effective end of the buffer due to early wrap size_t head; size_t tail; diff --git a/libs/video/renderer/vulkan/staging.c b/libs/video/renderer/vulkan/staging.c index 68bf6a9aa..613422b2b 100644 --- a/libs/video/renderer/vulkan/staging.c +++ b/libs/video/renderer/vulkan/staging.c @@ -58,10 +58,13 @@ qfv_stagebuf_t * QFV_CreateStagingBuffer (qfv_device_t *device, size_t size, int num_packets, VkCommandPool cmdPool) { + size_t atom = device->physDev->properties.limits.nonCoherentAtomSize; qfv_devfuncs_t *dfunc = device->funcs; qfv_stagebuf_t *stage = malloc (sizeof (qfv_stagebuf_t) + num_packets * sizeof (qfv_packet_t)); + stage->atom_mask = atom - 1; + size = (size + stage->atom_mask) & ~stage->atom_mask; stage->device = device; stage->buffer = QFV_CreateBuffer (device, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); @@ -119,9 +122,8 @@ QFV_FlushStagingBuffer (qfv_stagebuf_t *stage, size_t offset, size_t size) qfv_device_t *device = stage->device; qfv_devfuncs_t *dfunc = device->funcs; - size_t atom = device->physDev->properties.limits.nonCoherentAtomSize; - offset &= ~(atom - 1); - size = (size + atom - 1) & ~ (atom - 1); + offset &= ~stage->atom_mask; + size = (size + stage->atom_mask) & ~stage->atom_mask; VkMappedMemoryRange range = { VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0, stage->memory, offset, size