From 414f9d4a2e05229bd4fb484bc88bf0b1094d1a9a Mon Sep 17 00:00:00 2001 From: Mark Young Date: Fri, 11 Aug 2023 11:37:31 -0600 Subject: [PATCH] Revert using vkCmdCopyImage See if it fixes Android --- framework/decode/vulkan_virtual_swapchain.cpp | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/framework/decode/vulkan_virtual_swapchain.cpp b/framework/decode/vulkan_virtual_swapchain.cpp index f817691ffb..6ed4c14af8 100644 --- a/framework/decode/vulkan_virtual_swapchain.cpp +++ b/framework/decode/vulkan_virtual_swapchain.cpp @@ -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]; @@ -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(swapchain_info->width); + offsets[1].y = static_cast(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, @@ -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) {