[Impeller] Call vkQueuePresentKHR through the ContextVK's synchronized graphics queue wrapper (flutter/engine#50509)
SwapchainImplVK had been querying the physical device for a queue that supports presentation on the specified surface. However, the selected queue is typically the same VkQueue instance as the graphics queue provided by ContextVK. This could cause a thread policy violation where the raster thread is calling vkQueuePresentKHR while the IO thread is calling vkQueueSubmit on the same queue during image decoding. This PR moves the vkQueuePresentKHR call to the ContextVK's graphics queue wrapper, which serializes access to the VkQueue.
This commit is contained in:
@@ -23,6 +23,11 @@ vk::Result QueueVK::Submit(const vk::SubmitInfo& submit_info,
|
||||
return queue_.submit(submit_info, fence);
|
||||
}
|
||||
|
||||
vk::Result QueueVK::Present(const vk::PresentInfoKHR& present_info) {
|
||||
Lock lock(queue_mutex_);
|
||||
return queue_.presentKHR(present_info);
|
||||
}
|
||||
|
||||
void QueueVK::InsertDebugMarker(std::string_view label) const {
|
||||
if (!HasValidationLayers()) {
|
||||
return;
|
||||
|
||||
@@ -39,6 +39,8 @@ class QueueVK {
|
||||
vk::Result Submit(const vk::SubmitInfo& submit_info,
|
||||
const vk::Fence& fence) const;
|
||||
|
||||
vk::Result Present(const vk::PresentInfoKHR& present_info);
|
||||
|
||||
void InsertDebugMarker(std::string_view label) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -115,22 +115,6 @@ static std::optional<vk::CompositeAlphaFlagBitsKHR> ChooseAlphaCompositionMode(
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static std::optional<vk::Queue> ChoosePresentQueue(
|
||||
const vk::PhysicalDevice& physical_device,
|
||||
const vk::Device& device,
|
||||
const vk::SurfaceKHR& surface) {
|
||||
const auto families = physical_device.getQueueFamilyProperties();
|
||||
for (size_t family_index = 0u; family_index < families.size();
|
||||
family_index++) {
|
||||
auto [result, supported] =
|
||||
physical_device.getSurfaceSupportKHR(family_index, surface);
|
||||
if (result == vk::Result::eSuccess && supported) {
|
||||
return device.getQueue(family_index, 0u);
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::shared_ptr<SwapchainImplVK> SwapchainImplVK::Create(
|
||||
const std::shared_ptr<Context>& context,
|
||||
vk::UniqueSurfaceKHR surface,
|
||||
@@ -184,15 +168,6 @@ SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
|
||||
return;
|
||||
}
|
||||
|
||||
auto present_queue = ChoosePresentQueue(vk_context.GetPhysicalDevice(), //
|
||||
vk_context.GetDevice(), //
|
||||
*surface //
|
||||
);
|
||||
if (!present_queue.has_value()) {
|
||||
VALIDATION_LOG << "Could not pick present queue.";
|
||||
return;
|
||||
}
|
||||
|
||||
vk::SwapchainCreateInfoKHR swapchain_info;
|
||||
swapchain_info.surface = *surface;
|
||||
swapchain_info.imageFormat = format.value().format;
|
||||
@@ -288,7 +263,6 @@ SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
|
||||
|
||||
context_ = context;
|
||||
surface_ = std::move(surface);
|
||||
present_queue_ = present_queue.value();
|
||||
surface_format_ = swapchain_info.imageFormat;
|
||||
swapchain_ = std::move(swapchain);
|
||||
images_ = std::move(swapchain_images);
|
||||
@@ -476,7 +450,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
|
||||
present_info.setImageIndices(indices);
|
||||
present_info.setWaitSemaphores(*sync->present_ready);
|
||||
|
||||
auto result = present_queue_.presentKHR(present_info);
|
||||
auto result = context.GetGraphicsQueue()->Present(present_info);
|
||||
|
||||
switch (result) {
|
||||
case vk::Result::eErrorOutOfDateKHR:
|
||||
|
||||
@@ -66,7 +66,6 @@ class SwapchainImplVK final
|
||||
private:
|
||||
std::weak_ptr<Context> context_;
|
||||
vk::UniqueSurfaceKHR surface_;
|
||||
vk::Queue present_queue_ = {};
|
||||
vk::Format surface_format_ = vk::Format::eUndefined;
|
||||
vk::UniqueSwapchainKHR swapchain_;
|
||||
std::vector<std::shared_ptr<SwapchainImageVK>> images_;
|
||||
|
||||
Reference in New Issue
Block a user