Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 66faf62

Browse files
[Impeller] Call vkQueuePresentKHR through the ContextVK's synchronized graphics queue wrapper (#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.
1 parent 6a3b021 commit 66faf62

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

impeller/renderer/backend/vulkan/queue_vk.cc

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ vk::Result QueueVK::Submit(const vk::SubmitInfo& submit_info,
2323
return queue_.submit(submit_info, fence);
2424
}
2525

26+
vk::Result QueueVK::Present(const vk::PresentInfoKHR& present_info) {
27+
Lock lock(queue_mutex_);
28+
return queue_.presentKHR(present_info);
29+
}
30+
2631
void QueueVK::InsertDebugMarker(std::string_view label) const {
2732
if (!HasValidationLayers()) {
2833
return;

impeller/renderer/backend/vulkan/queue_vk.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class QueueVK {
3939
vk::Result Submit(const vk::SubmitInfo& submit_info,
4040
const vk::Fence& fence) const;
4141

42+
vk::Result Present(const vk::PresentInfoKHR& present_info);
43+
4244
void InsertDebugMarker(std::string_view label) const;
4345

4446
private:

impeller/renderer/backend/vulkan/swapchain_impl_vk.cc

+1-27
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,6 @@ static std::optional<vk::CompositeAlphaFlagBitsKHR> ChooseAlphaCompositionMode(
115115
return std::nullopt;
116116
}
117117

118-
static std::optional<vk::Queue> ChoosePresentQueue(
119-
const vk::PhysicalDevice& physical_device,
120-
const vk::Device& device,
121-
const vk::SurfaceKHR& surface) {
122-
const auto families = physical_device.getQueueFamilyProperties();
123-
for (size_t family_index = 0u; family_index < families.size();
124-
family_index++) {
125-
auto [result, supported] =
126-
physical_device.getSurfaceSupportKHR(family_index, surface);
127-
if (result == vk::Result::eSuccess && supported) {
128-
return device.getQueue(family_index, 0u);
129-
}
130-
}
131-
return std::nullopt;
132-
}
133-
134118
std::shared_ptr<SwapchainImplVK> SwapchainImplVK::Create(
135119
const std::shared_ptr<Context>& context,
136120
vk::UniqueSurfaceKHR surface,
@@ -184,15 +168,6 @@ SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
184168
return;
185169
}
186170

187-
auto present_queue = ChoosePresentQueue(vk_context.GetPhysicalDevice(), //
188-
vk_context.GetDevice(), //
189-
*surface //
190-
);
191-
if (!present_queue.has_value()) {
192-
VALIDATION_LOG << "Could not pick present queue.";
193-
return;
194-
}
195-
196171
vk::SwapchainCreateInfoKHR swapchain_info;
197172
swapchain_info.surface = *surface;
198173
swapchain_info.imageFormat = format.value().format;
@@ -288,7 +263,6 @@ SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
288263

289264
context_ = context;
290265
surface_ = std::move(surface);
291-
present_queue_ = present_queue.value();
292266
surface_format_ = swapchain_info.imageFormat;
293267
swapchain_ = std::move(swapchain);
294268
images_ = std::move(swapchain_images);
@@ -476,7 +450,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
476450
present_info.setImageIndices(indices);
477451
present_info.setWaitSemaphores(*sync->present_ready);
478452

479-
auto result = present_queue_.presentKHR(present_info);
453+
auto result = context.GetGraphicsQueue()->Present(present_info);
480454

481455
switch (result) {
482456
case vk::Result::eErrorOutOfDateKHR:

impeller/renderer/backend/vulkan/swapchain_impl_vk.h

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class SwapchainImplVK final
6666
private:
6767
std::weak_ptr<Context> context_;
6868
vk::UniqueSurfaceKHR surface_;
69-
vk::Queue present_queue_ = {};
7069
vk::Format surface_format_ = vk::Format::eUndefined;
7170
vk::UniqueSwapchainKHR swapchain_;
7271
std::vector<std::shared_ptr<SwapchainImageVK>> images_;

0 commit comments

Comments
 (0)