From 57945038766ea3651f480debcbd2f66e196c429c Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Sat, 26 Sep 2020 00:08:58 -0500 Subject: [PATCH] MVKCmdFillBuffer: Round size down, not up. According to the Vulkan spec: > If `VK_WHOLE_SIZE` is used and the remaining size of the buffer is not > a multiple of 4, then the nearest **smaller** multiple is used. > [emphasis added] Therefore, we should round down when calculating the number of words to write. --- MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm index 60c62d0d..c325f2d0 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm @@ -1446,9 +1446,9 @@ VkResult MVKCmdFillBuffer::setContent(MVKCommandBuffer* cmdBuff, _dstOffset = dstOffset; _dataValue = data; - // Round up in case of VK_WHOLE_SIZE on a buffer size which is not aligned to 4 bytes. + // Round down in case of VK_WHOLE_SIZE on a buffer size which is not aligned to 4 bytes. VkDeviceSize byteCnt = (size == VK_WHOLE_SIZE) ? (_dstBuffer->getByteCount() - _dstOffset) : size; - VkDeviceSize wdCnt = (byteCnt + 3) >> 2; + VkDeviceSize wdCnt = byteCnt >> 2; if (mvkFits(wdCnt)) { _wordCount = (uint32_t)wdCnt; } else {