Skip to content

Commit 2fdbc64

Browse files
committed
Add changes requested in code review
1 parent 1c0c221 commit 2fdbc64

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

src/Tests.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6161,7 +6161,7 @@ static void TestDataUploadingWithStagingBuffer()
61616161
const VkDeviceSize bufferSize = 65536;
61626162
std::vector<std::uint8_t> bufferData(bufferSize);
61636163
for (auto& bufferByte : bufferData) {
6164-
bufferByte = static_cast<std::uint8_t>(rand() % 256);
6164+
bufferByte = static_cast<std::uint8_t>(rand());
61656165
}
61666166

61676167
VkBufferCreateInfo uniformBufferCI = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
@@ -6170,20 +6170,14 @@ static void TestDataUploadingWithStagingBuffer()
61706170

61716171
VmaAllocationCreateInfo uniformBufferAllocCI = {};
61726172
uniformBufferAllocCI.usage = VMA_MEMORY_USAGE_AUTO;
6173-
uniformBufferAllocCI.flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
61746173

61756174
VkBuffer uniformBuffer = VK_NULL_HANDLE;
6176-
VmaAllocation uniformBufferAlloc = {};
6175+
VmaAllocation uniformBufferAlloc = VK_NULL_HANDLE;
61776176
VmaAllocationInfo uniformBufferAllocInfo = {};
61786177

61796178
VkResult result = vmaCreateBuffer(g_hAllocator, &uniformBufferCI, &uniformBufferAllocCI, &uniformBuffer, &uniformBufferAlloc, &uniformBufferAllocInfo);
61806179
TEST(result == VK_SUCCESS);
61816180

6182-
// We need to check if the uniform buffer really ended NOT up in mappable memory.
6183-
VkMemoryPropertyFlags memPropFlags;
6184-
vmaGetAllocationMemoryProperties(g_hAllocator, uniformBufferAlloc, &memPropFlags);
6185-
TEST(!(memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
6186-
61876181
VkBufferCreateInfo stagingBufferCI = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
61886182
stagingBufferCI.size = bufferSize;
61896183
stagingBufferCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
@@ -6200,10 +6194,7 @@ static void TestDataUploadingWithStagingBuffer()
62006194
TEST(result == VK_SUCCESS);
62016195

62026196
TEST(stagingBufferAllocInfo.pMappedData != nullptr);
6203-
std::memcpy(stagingBufferAllocInfo.pMappedData, bufferData.data(), bufferData.size());
6204-
6205-
result = vmaFlushAllocation(g_hAllocator, uniformBufferAlloc, 0, VK_WHOLE_SIZE);
6206-
TEST(result == VK_SUCCESS);
6197+
vmaCopyMemoryToAllocation(g_hAllocator, bufferData.data(), stagingBufferAlloc, 0, bufferData.size());
62076198

62086199
BeginSingleTimeCommands();
62096200

@@ -6243,7 +6234,7 @@ static void TestDataUploadingWithStagingBuffer()
62436234
}
62446235

62456236
static void TestDataUploadingWithMappedMemory() {
6246-
wprintf(L"Testing data uploading with mapped memory and memcpy...\n");
6237+
wprintf(L"Testing data uploading with mapped memory...\n");
62476238

62486239
// Generate some random data to fill the uniform buffer with.
62496240
const VkDeviceSize bufferSize = 65536;
@@ -6258,10 +6249,10 @@ static void TestDataUploadingWithMappedMemory() {
62586249

62596250
VmaAllocationCreateInfo uniformBufferAllocCI = {};
62606251
uniformBufferAllocCI.usage = VMA_MEMORY_USAGE_AUTO;
6261-
uniformBufferAllocCI.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT; // We want memory to be mapped so we can use memcpy to update it
6252+
uniformBufferAllocCI.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT; // We want memory to be mapped.
62626253

62636254
VkBuffer uniformBuffer = VK_NULL_HANDLE;
6264-
VmaAllocation uniformBufferAlloc = {};
6255+
VmaAllocation uniformBufferAlloc = VK_NULL_HANDLE;
62656256
VmaAllocationInfo uniformBufferAllocInfo = {};
62666257

62676258
VkResult result = vmaCreateBuffer(g_hAllocator, &uniformBufferCI, &uniformBufferAllocCI, &uniformBuffer, &uniformBufferAlloc, &uniformBufferAllocInfo);
@@ -6273,11 +6264,7 @@ static void TestDataUploadingWithMappedMemory() {
62736264
TEST(memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
62746265

62756266
TEST(uniformBufferAllocInfo.pMappedData != nullptr);
6276-
std::memcpy(uniformBufferAllocInfo.pMappedData, bufferData.data(), bufferData.size());
6277-
6278-
// We don't need to check for VK_MEMORY_PROPERTY_HOST_COHERENT_BIT because both vmaFlushAllocation and vmaInvalidateAllocation check for this internally.
6279-
result = vmaFlushAllocation(g_hAllocator, uniformBufferAlloc, 0, VK_WHOLE_SIZE);
6280-
TEST(result == VK_SUCCESS);
6267+
vmaCopyMemoryToAllocation(g_hAllocator, bufferData.data(), uniformBufferAlloc, 0, bufferData.size());
62816268

62826269
BeginSingleTimeCommands();
62836270

@@ -6313,7 +6300,8 @@ static void TestAdvancedDataUploading() {
63136300

63146301
VmaAllocationCreateInfo uniformBufferAllocCI = {};
63156302
uniformBufferAllocCI.usage = VMA_MEMORY_USAGE_AUTO;
6316-
uniformBufferAllocCI.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
6303+
uniformBufferAllocCI.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT
6304+
| VMA_ALLOCATION_CREATE_MAPPED_BIT;
63176305

63186306
VkBuffer uniformBuffer = VK_NULL_HANDLE;
63196307
VmaAllocation uniformBufferAlloc = {};
@@ -6326,13 +6314,9 @@ static void TestAdvancedDataUploading() {
63266314
vmaGetAllocationMemoryProperties(g_hAllocator, uniformBufferAlloc, &memPropFlags);
63276315

63286316
if (memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
6329-
// The allocation ended up as mapped memory, meaning we can update it simply by using std::memcpy.
6317+
// The allocation ended up as mapped memory.
63306318
TEST(uniformBufferAllocInfo.pMappedData != nullptr);
6331-
std::memcpy(uniformBufferAllocInfo.pMappedData, bufferData.data(), bufferData.size());
6332-
6333-
// We don't need to check for VK_MEMORY_PROPERTY_HOST_COHERENT_BIT because both vmaFlushAllocation and vmaInvalidateAllocation check for this internally.
6334-
result = vmaFlushAllocation(g_hAllocator, uniformBufferAlloc, 0, VK_WHOLE_SIZE);
6335-
TEST(result == VK_SUCCESS);
6319+
vmaCopyMemoryToAllocation(g_hAllocator, bufferData.data(), uniformBufferAlloc, 0, bufferData.size());
63366320

63376321
BeginSingleTimeCommands();
63386322

@@ -6367,7 +6351,7 @@ static void TestAdvancedDataUploading() {
63676351
TEST(result == VK_SUCCESS);
63686352

63696353
TEST(stagingBufferAllocInfo.pMappedData != nullptr);
6370-
std::memcpy(stagingBufferAllocInfo.pMappedData, bufferData.data(), bufferData.size());
6354+
vmaCopyMemoryToAllocation(g_hAllocator, bufferData.data(), stagingBufferAlloc, 0, bufferData.size());
63716355

63726356
result = vmaFlushAllocation(g_hAllocator, uniformBufferAlloc, 0, VK_WHOLE_SIZE);
63736357
TEST(result == VK_SUCCESS);

0 commit comments

Comments
 (0)