Skip to content

Commit 68d1c97

Browse files
authored
Small improvement of 'advanced data uploading' exampe in docs (#494)
1 parent 06a453e commit 68d1c97

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/vk_mem_alloc.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18865,11 +18865,9 @@ vmaGetAllocationMemoryProperties(allocator, alloc, &memPropFlags);
1886518865

1886618866
if(memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
1886718867
{
18868-
// Allocation ended up in a mappable memory and is already mapped - write to it directly.
18869-
18870-
// [Executed in runtime]:
18871-
memcpy(allocInfo.pMappedData, myData, myDataSize);
18872-
result = vmaFlushAllocation(allocator, alloc, 0, VK_WHOLE_SIZE);
18868+
// The Allocation ended up in a mappable memory.
18869+
// Calling vmaCopyMemoryToAllocation() does vmaMapMemory(), memcpy(), vmaUnmapMemory(), and vmaFlushAllocation().
18870+
result = vmaCopyMemoryToAllocation(allocator, myData, alloc, 0, myDataSize);
1887318871
// Check result...
1887418872

1887518873
VkBufferMemoryBarrier bufMemBarrier = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER };
@@ -18881,6 +18879,7 @@ if(memPropFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
1888118879
bufMemBarrier.offset = 0;
1888218880
bufMemBarrier.size = VK_WHOLE_SIZE;
1888318881

18882+
// It's important to insert a buffer memory barrier here to ensure writing to the buffer has finished.
1888418883
vkCmdPipelineBarrier(cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
1888518884
0, 0, nullptr, 1, &bufMemBarrier, 0, nullptr);
1888618885
}
@@ -18903,9 +18902,8 @@ else
1890318902
&stagingBuf, &stagingAlloc, &stagingAllocInfo);
1890418903
// Check result...
1890518904

18906-
// [Executed in runtime]:
18907-
memcpy(stagingAllocInfo.pMappedData, myData, myDataSize);
18908-
result = vmaFlushAllocation(allocator, stagingAlloc, 0, VK_WHOLE_SIZE);
18905+
// Calling vmaCopyMemoryToAllocation() does vmaMapMemory(), memcpy(), vmaUnmapMemory(), and vmaFlushAllocation().
18906+
result = vmaCopyMemoryToAllocation(allocator, myData, stagingAlloc, 0, myDataSize);
1890918907
// Check result...
1891018908

1891118909
VkBufferMemoryBarrier bufMemBarrier = { VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER };
@@ -18917,6 +18915,7 @@ else
1891718915
bufMemBarrier.offset = 0;
1891818916
bufMemBarrier.size = VK_WHOLE_SIZE;
1891918917

18918+
// Insert a buffer memory barrier to make sure writing to the staging buffer has finished.
1892018919
vkCmdPipelineBarrier(cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
1892118920
0, 0, nullptr, 1, &bufMemBarrier, 0, nullptr);
1892218921

@@ -18937,6 +18936,7 @@ else
1893718936
bufMemBarrier2.offset = 0;
1893818937
bufMemBarrier2.size = VK_WHOLE_SIZE;
1893918938

18939+
// Make sure copying from staging buffer to the actual buffer has finished by inserting a buffer memory barrier.
1894018940
vkCmdPipelineBarrier(cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
1894118941
0, 0, nullptr, 1, &bufMemBarrier2, 0, nullptr);
1894218942
}

0 commit comments

Comments
 (0)