mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 09:51:41 +00:00
[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.
This commit is contained in:
parent
f96d7109af
commit
7e7b82086c
2 changed files with 6 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue