OSDN Git Service

Fill buffer fix
authorAlexis Hetu <sugoi@google.com>
Mon, 25 Mar 2019 14:24:23 +0000 (10:24 -0400)
committerAlexis Hétu <sugoi@google.com>
Tue, 26 Mar 2019 11:34:56 +0000 (11:34 +0000)
memset was erroneously being used to copy 4 bytes at a time,
but the integer input value in memset is used as an 8 bit value,
so the fill was failing if the 4 bytes were not identical.

Tests: dEQP-VK.api.fill_and_update_buffer.*
Tests: dEQP-VK.memory.pipeline_barrier.host_read_transfer_dst.*

Bug b/118383648

Change-Id: I29cb5915ebd3773b4afbd89850c47a042fff6952
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27872
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>

src/Vulkan/VkBuffer.cpp

index 7f21ce4..7679553 100644 (file)
@@ -93,9 +93,18 @@ void Buffer::copyTo(Buffer* dstBuffer, const VkBufferCopy& pRegion) const
 
 void Buffer::fill(VkDeviceSize dstOffset, VkDeviceSize fillSize, uint32_t data)
 {
-       ASSERT((fillSize + dstOffset) <= size);
+       size_t bytes = (fillSize == VK_WHOLE_SIZE) ? (size - dstOffset) : fillSize;
 
-       memset(getOffsetPointer(dstOffset), data, fillSize);
+       ASSERT((bytes + dstOffset) <= size);
+
+       uint32_t* memToWrite = static_cast<uint32_t*>(getOffsetPointer(dstOffset));
+
+       // Vulkan 1.1 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."
+       for(; bytes >= 4; bytes -= 4, memToWrite++)
+       {
+               *memToWrite = data;
+       }
 }
 
 void Buffer::update(VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData)