About subresourceRange and bufferCopyRegion

Hello

If a ktx image has k mipLevels,

why do we have only one imageMemoryBarrier variable having k mipLevels inside
and why do we have separate k bufferCopyRegions, each of which has one mipLevel inside ?

Could you please explain to me
why do we do just like this ?

below is a source example

VkImageMemoryBarrier imageMemoryBarrier = vks::initializers::imageMemoryBarrier();
....
imageMemoryBarrier.subresourceRange.baseMipLevel = 0;
imageMemoryBarrier.subresourceRange.levelCount = mipLevels;
....


vkCmdPipelineBarrier(
	cmdbuffer,
	srcStageMask,
	dstStageMask,
	0,
	0, nullptr,
	0, nullptr,
	1, &imageMemoryBarrier); <=== only one imageMemoryBarrier


std::vector<VkBufferImageCopy> bufferCopyRegions; <=== separate bufferCopyRegions
for (uint32_t i = 0; i < mipLevels; i++)
{
	VkBufferImageCopy bufferCopyRegion = {};
	bufferCopyRegion.imageSubresource.mipLevel = i;

........

	bufferCopyRegions.push_back(bufferCopyRegion);
}


vkCmdCopyBufferToImage(copyCmd, stagingBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast<uint32_t>(bufferCopyRegions.size()), bufferCopyRegions.data()); <=== separate bufferCopyRegions

and

another vkCmdPipelineBarrier

The barrier always acts on whole mip-levels, while the copy can operate on a sub-region (specified by imageOffset, imageExtent) of a mip-level.

1 Like

Hello, Carsten

That is so deep
Now I understand
Thank you and see you again, Carsten