Skip to content

Commit

Permalink
Add assertions and debug statements to the staging device
Browse files Browse the repository at this point in the history
Summary: Add assertions and debug statements in preparation for adding the ability to grow the staging buffer dynamically.

Reviewed By: corporateshark

Differential Revision: D49329410

fbshipit-source-id: bc23447801e1b6612d1069ad1ea94554afbc91dc
  • Loading branch information
mmaurer authored and facebook-github-bot committed Sep 19, 2023
1 parent 12aa69e commit cffacf8
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/igl/vulkan/VulkanStagingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ void VulkanStagingDevice::bufferSubData(VulkanBuffer& buffer,
uint32_t chunkDstOffset = dstOffset;
void* copyData = const_cast<void*>(data);

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Upload requested for data with %u bytes\n", size);
#endif

while (size) {
// finds a free memory block to store the data in the staging buffer
MemoryRegion memoryChunk = nextFreeBlock(size);
const auto copySize = std::min(static_cast<uint32_t>(size), memoryChunk.size);
const uint32_t copySize = std::min(static_cast<uint32_t>(size), memoryChunk.size);

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("\tUploading %u bytes\n", copySize);
#endif

// copy data into the staging buffer
stagingBuffer_->bufferSubData(memoryChunk.offset, copySize, copyData);
Expand All @@ -92,11 +100,10 @@ VulkanStagingDevice::MemoryRegion VulkanStagingDevice::nextFreeBlock(uint32_t si

IGL_ASSERT(!regions_.empty());

const auto requestedAlignedSize = getAlignedSize(size);
const uint32_t requestedAlignedSize = getAlignedSize(size);

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO(
"Requesting new memory region with %u bytes, aligned %u bytes\n", size, requestedAlignedSize);
IGL_LOG_INFO("nextFreeBlock() with %u bytes, aligned %u bytes\n", size, requestedAlignedSize);
#endif

// If we can't find an empty free region that is as big as the requestedAlignedSize, return
Expand Down Expand Up @@ -152,7 +159,8 @@ VulkanStagingDevice::MemoryRegion VulkanStagingDevice::nextFreeBlock(uint32_t si

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO(
"Didn't find available block. Waiting for staging device to become fully available\n");
"Could not find an available block. Waiting for the staging device to become fully "
"available\n");
#endif

// Nothing was available. Let's wait for the entire staging buffer to become free
Expand Down Expand Up @@ -183,6 +191,10 @@ void VulkanStagingDevice::getBufferSubData(VulkanBuffer& buffer,
return;
}

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Download requested for data with %u bytes\n", size);
#endif

size_t chunkSrcOffset = srcOffset;
auto* dstData = static_cast<uint8_t*>(data);

Expand Down Expand Up @@ -223,6 +235,15 @@ void VulkanStagingDevice::imageData(VulkanImage& image,
const uint32_t storageSize =
static_cast<uint32_t>(properties.getBytesPerRange(range, bytesPerRow));

// We don't support uploading image data in small chunks. If the total upload size exceeds the
// the maximum allowed staging buffer size, we can't upload it
IGL_ASSERT_MSG(storageSize <= maxBufferCapacity_,
"Image size exceeds maximum size of staging buffer");

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Image upload requested for data with %u bytes\n", storageSize);
#endif

IGL_ASSERT(storageSize <= stagingBufferSize_);

// get next staging buffer free offset
Expand Down Expand Up @@ -383,6 +404,17 @@ void VulkanStagingDevice::getImageData2D(VkImage srcImage,
properties.getBytesPerRange(range.atMipLevel(0), mustRepack ? 0 : bytesPerRow));
IGL_ASSERT(storageSize <= stagingBufferSize_);

// We don't support uploading image data in small chunks. If the total upload size exceeds the
// the maximum allowed staging buffer size, we can't upload it
IGL_ASSERT_MSG(storageSize <= maxBufferCapacity_,
"Image size exceeds maximum size of staging buffer");

#if IGL_VULKAN_DEBUG_STAGING_DEVICE
IGL_LOG_INFO("Image download requested for data with %u bytes\n", storageSize);
#endif

IGL_ASSERT(storageSize <= stagingBufferSize_);

// get next staging buffer free offset
MemoryRegion memoryChunk = nextFreeBlock(storageSize);

Expand Down

0 comments on commit cffacf8

Please sign in to comment.