Skip to content

Commit

Permalink
Adding MemoryRegion::size to avoid confusion with alignedSize
Browse files Browse the repository at this point in the history
Reviewed By: corporateshark

Differential Revision: D50226987

fbshipit-source-id: 05ae0f52a5695fe6c386b408c27c46c5c0af9f40
  • Loading branch information
mmaurer authored and facebook-github-bot committed Oct 16, 2023
1 parent 56673c4 commit 4a254b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/igl/vulkan/VulkanStagingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ VulkanStagingDevice::MemoryRegion VulkanStagingDevice::nextFreeBlock(VkDeviceSiz
regions_.erase(it);
if (unusedSize > 0) {
regions_.push_front(
{unusedOffset, unusedSize, VulkanImmediateCommands::SubmitHandle()});
{unusedOffset, unusedSize, unusedSize, VulkanImmediateCommands::SubmitHandle()});
}
};

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Found block with %u bytes at offset %u\n", it->size, it->offset);
#endif

return {it->offset, requestedAlignedSize, VulkanImmediateCommands::SubmitHandle()};
return {it->offset, size, requestedAlignedSize, VulkanImmediateCommands::SubmitHandle()};
}

// Cache the largest available region that isn't as big as the one we're looking for
Expand All @@ -142,12 +142,16 @@ VulkanStagingDevice::MemoryRegion VulkanStagingDevice::nextFreeBlock(VkDeviceSiz
};

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Found block smaller than size needed with %u bytes at offset %u\n",
IGL_LOG_INFO("Found block smaller than size needed with %u bytes (%u aligned) at offset %u\n",
bestNextIt->size,
bestNextIt->alignedSize,
bestNextIt->offset);
#endif

return {bestNextIt->offset, bestNextIt->size, VulkanImmediateCommands::SubmitHandle()};
return {bestNextIt->offset,
bestNextIt->size,
bestNextIt->alignedSize,
VulkanImmediateCommands::SubmitHandle()};
}

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
Expand All @@ -167,11 +171,12 @@ VulkanStagingDevice::MemoryRegion VulkanStagingDevice::nextFreeBlock(VkDeviceSiz
const uint32_t unusedSize = stagingBufferSize_ - requestedAlignedSize;
if (unusedSize > 0) {
const uint32_t unusedOffset = requestedAlignedSize;
regions_.push_front({unusedOffset, unusedSize, VulkanImmediateCommands::SubmitHandle()});
regions_.push_front(
{unusedOffset, unusedSize, unusedSize, VulkanImmediateCommands::SubmitHandle()});
}

//... and then return the smallest free region that can hold the requested size
return {0, requestedAlignedSize, VulkanImmediateCommands::SubmitHandle()};
return {0, size, requestedAlignedSize, VulkanImmediateCommands::SubmitHandle()};
}

void VulkanStagingDevice::getBufferSubData(VulkanBuffer& buffer,
Expand Down Expand Up @@ -208,7 +213,7 @@ void VulkanStagingDevice::getBufferSubData(VulkanBuffer& buffer,

// Copy data into data
const uint8_t* src = stagingBuffer_->getMappedPtr() + memoryChunk.offset;
checked_memcpy(dstData, size - chunkSrcOffset, src, memoryChunk.size);
checked_memcpy(dstData, size - chunkSrcOffset, src, memoryChunk.alignedSize);

size -= copySize;
dstData = (uint8_t*)dstData + copySize;
Expand Down Expand Up @@ -506,7 +511,8 @@ void VulkanStagingDevice::waitAndReset() {

regions_.clear();

regions_.push_front({0, stagingBufferSize_, VulkanImmediateCommands::SubmitHandle()});
regions_.push_front(
{0, stagingBufferSize_, stagingBufferSize_, VulkanImmediateCommands::SubmitHandle()});
}

bool VulkanStagingDevice::shouldGrowStagingBuffer(VkDeviceSize sizeNeeded) const {
Expand Down Expand Up @@ -555,7 +561,8 @@ void VulkanStagingDevice::growStagingBuffer(VkDeviceSize minimumSize) {

// Clear out the old regions and add one that represents the entire buffer
regions_.clear();
regions_.push_front({0, stagingBufferSize_, VulkanImmediateCommands::SubmitHandle()});
regions_.push_front(
{0, stagingBufferSize_, stagingBufferSize_, VulkanImmediateCommands::SubmitHandle()});
}

} // namespace vulkan
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/VulkanStagingDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class VulkanStagingDevice final {
struct MemoryRegion {
VkDeviceSize offset = 0u;
VkDeviceSize size = 0u;
VkDeviceSize alignedSize = 0u;
VulkanImmediateCommands::SubmitHandle handle;
};

Expand Down

0 comments on commit 4a254b8

Please sign in to comment.