问题
Say I have a render pass with a single color attachment corresponding to the images of a swap chain. Usually, I would set the initialLayout
and finalLayout
fields of the VkAttachmentDescription
to VK_IMAGE_LAYOUT_UNDEFINED
and VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
, respectively.
Now I would like to set the initialLayout
to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
instead and perform the transition of a swap chain image to this state manually before the render pass begins.
I want to do this using memory barriers. So, given a generic function
void transition_image_layout(VkCommandBuffer command_buffer,
VkImage image, VkImageLayout old_layout, VkImageLayout new_layout)
{
VkAccessFlags src_access_mask,
dst_access_mask;
VkPipelineStageFlags src_stage_mask,
dst_stage_mask;
// set src_access_mask/dst_access_mask and
// src_stage_mask/dst_stage_mask properly
// according to old_layout/new_layout
VkImageMemoryBarrier image_memory_barrier{};
image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_memory_barrier.srcAccessMask;
image_memory_barrier.dstAccessMask;
image_memory_barrier.oldLayout = old_layout;
image_memory_barrier.newLayout = new_layout;
image_memory_barrier.srcQueueFamilyIndex = src_queue_family_index;
image_memory_barrier.dstQueueFamilyIndex = dst_queue_family_index;
image_memory_barrier.image = image;
image_memory_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
image_memory_barrier.subresourceRange.levelCount = 1;
image_memory_barrier.subresourceRange.layerCount = 1;
vkCmdPipelineBarrier(command_buffer, src_stage_mask, dst_stage_mask, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
}
at which point before, between and after vkCmdBeginRenderPass
and vkCmdEndRenderPass
would I need to perform the transition and which are the appropriate values for src_access_mask/dst_access_mask
and src_stage_mask/dst_stage_mask
?
来源:https://stackoverflow.com/questions/65266956/manually-transition-swap-chain-image-layouts