Skip to content

Commit

Permalink
Revert using vkCmdCopyImage
Browse files Browse the repository at this point in the history
See if it fixes Android
  • Loading branch information
MarkY-LunarG committed Aug 11, 2023
1 parent 406d74f commit 414f9d4
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions framework/decode/vulkan_virtual_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,58 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(PFN_vkQueuePresentKHR
wait_stages.push_back(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
}

#if 1 // Brainpain
VkImageMemoryBarrier initial_barrier_virtual_image;
VkImageMemoryBarrier initial_barrier_swapchain_image;
VkImageMemoryBarrier final_barrier_virtual_image;
VkImageMemoryBarrier final_barrier_swapchain_image;

initial_barrier_virtual_image = {
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
nullptr,
VK_ACCESS_NONE,
VK_ACCESS_TRANSFER_READ_BIT,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
VK_NULL_HANDLE,
VkImageSubresourceRange{
VK_IMAGE_ASPECT_COLOR_BIT,
0,
1,
0,
0,
},
};

final_barrier_virtual_image = initial_barrier_virtual_image;
final_barrier_virtual_image.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
final_barrier_virtual_image.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
final_barrier_virtual_image.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
final_barrier_virtual_image.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;

initial_barrier_swapchain_image = initial_barrier_virtual_image;
initial_barrier_swapchain_image.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
initial_barrier_swapchain_image.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;

final_barrier_swapchain_image = final_barrier_virtual_image;
final_barrier_swapchain_image.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;

VkOffset3D offsets[2] = {
{
0,
0,
0,
},
{
0,
0,
1,
},
};
#endif

for (uint32_t i = 0; i < swapchainCount; ++i)
{
const auto* swapchain_info = swapchain_infos[i];
Expand Down Expand Up @@ -620,6 +672,83 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(PFN_vkQueuePresentKHR
return result;
}

#if 1 // Brainpain

initial_barrier_virtual_image.image = virtual_image.image;
initial_barrier_virtual_image.subresourceRange.layerCount = swapchain_info->image_array_layers;
initial_barrier_swapchain_image.image = replay_image;
initial_barrier_swapchain_image.subresourceRange.layerCount = swapchain_info->image_array_layers;

device_table_->CmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0,
nullptr,
0,
nullptr,
1,
&initial_barrier_virtual_image);

device_table_->CmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0,
nullptr,
0,
nullptr,
1,
&initial_barrier_swapchain_image);

subresource.layerCount = swapchain_info->image_array_layers;

offsets[1].x = static_cast<int32_t>(swapchain_info->width);
offsets[1].y = static_cast<int32_t>(swapchain_info->height);
VkImageBlit blit = {
subresource,
{ offsets[0], offsets[1] },
subresource,
{ offsets[0], offsets[1] },
};

device_table_->CmdBlitImage(command_buffer,
virtual_image.image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
replay_image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1,
&blit,
VK_FILTER_NEAREST);

final_barrier_virtual_image.image = virtual_image.image;
final_barrier_virtual_image.subresourceRange.layerCount = swapchain_info->image_array_layers;
final_barrier_swapchain_image.image = replay_image;
final_barrier_swapchain_image.subresourceRange.layerCount = swapchain_info->image_array_layers;

device_table_->CmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
0,
0,
nullptr,
0,
nullptr,
1,
&final_barrier_virtual_image);

device_table_->CmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT,
0,
0,
nullptr,
0,
nullptr,
1,
&final_barrier_swapchain_image);

#else
// NOTE: vkCmdCopyImage works on Queues of types including Graphics, Compute
// and Transfer. So should work on any queues we get a vkQueuePresentKHR from.
device_table_->CmdCopyImage(command_buffer,
Expand All @@ -629,6 +758,7 @@ VkResult VulkanVirtualSwapchain::QueuePresentKHR(PFN_vkQueuePresentKHR
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
1,
&image_copy);
#endif
result = device_table_->EndCommandBuffer(command_buffer);
if (result != VK_SUCCESS)
{
Expand Down

0 comments on commit 414f9d4

Please sign in to comment.