Commit 4d4a9bc6 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Don't reuse Vulkan semaphores in VulkanSwapChain

VulkanSwapChain reuses semaphores used in Swapchain. That logic depends
on fences support in Swapchain, but Fuchsia's swapchain implementation
doesn't support fences. This CL disables semaphores re-use on Fuchsia.

Bug: 1117070
Change-Id: I8d57a527b572f7da1fd27821b36fae332307b725
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365357Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799998}
parent 765e7a63
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/threading/scoped_blocking_call.h" #include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "gpu/vulkan/vulkan_device_queue.h" #include "gpu/vulkan/vulkan_device_queue.h"
#include "gpu/vulkan/vulkan_fence_helper.h" #include "gpu/vulkan/vulkan_fence_helper.h"
#include "gpu/vulkan/vulkan_function_pointers.h" #include "gpu/vulkan/vulkan_function_pointers.h"
...@@ -86,6 +87,7 @@ void VulkanSwapChain::Destroy() { ...@@ -86,6 +87,7 @@ void VulkanSwapChain::Destroy() {
WaitUntilPostSubBufferAsyncFinished(); WaitUntilPostSubBufferAsyncFinished();
#if !defined(OS_FUCHSIA)
if (UNLIKELY(!fence_and_semaphores_queue_.empty())) { if (UNLIKELY(!fence_and_semaphores_queue_.empty())) {
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
{ {
...@@ -106,6 +108,7 @@ void VulkanSwapChain::Destroy() { ...@@ -106,6 +108,7 @@ void VulkanSwapChain::Destroy() {
} }
fence_and_semaphores_queue_.clear(); fence_and_semaphores_queue_.clear();
} }
#endif // !defined(OS_FUCHSIA)
DCHECK(!is_writing_); DCHECK(!is_writing_);
DestroySwapImages(); DestroySwapImages();
...@@ -199,9 +202,11 @@ bool VulkanSwapChain::InitializeSwapChain( ...@@ -199,9 +202,11 @@ bool VulkanSwapChain::InitializeSwapChain(
// Reuse |post_sub_buffer_task_runner_| and |fence_and_semaphores_queue_| // Reuse |post_sub_buffer_task_runner_| and |fence_and_semaphores_queue_|
// from the |old_swap_chain|. // from the |old_swap_chain|.
post_sub_buffer_task_runner_ = old_swap_chain->post_sub_buffer_task_runner_; post_sub_buffer_task_runner_ = old_swap_chain->post_sub_buffer_task_runner_;
#if !defined(OS_FUCHSIA)
fence_and_semaphores_queue_ = fence_and_semaphores_queue_ =
std::move(old_swap_chain->fence_and_semaphores_queue_); std::move(old_swap_chain->fence_and_semaphores_queue_);
old_swap_chain->fence_and_semaphores_queue_.clear(); old_swap_chain->fence_and_semaphores_queue_.clear();
#endif // !defined(OS_FUCHSIA)
} }
VkSwapchainKHR new_swap_chain = VK_NULL_HANDLE; VkSwapchainKHR new_swap_chain = VK_NULL_HANDLE;
...@@ -418,8 +423,10 @@ bool VulkanSwapChain::AcquireNextImage() { ...@@ -418,8 +423,10 @@ bool VulkanSwapChain::AcquireNextImage() {
// TODO(penghuang): make VulkanDeviceQueue threadsafe. // TODO(penghuang): make VulkanDeviceQueue threadsafe.
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
auto fence_and_semaphores = GetOrCreateFenceAndSemaphores(); auto fence_and_semaphores = GetOrCreateFenceAndSemaphores();
if (UNLIKELY(fence_and_semaphores.fence == VK_NULL_HANDLE)) { if (UNLIKELY(fence_and_semaphores.semaphores[0] == VK_NULL_HANDLE)) {
DCHECK(fence_and_semaphores.semaphores[0] == VK_NULL_HANDLE); #if !defined(OS_FUCHSIA)
DCHECK(fence_and_semaphores.fence == VK_NULL_HANDLE);
#endif // !defined(OS_FUCHSIA)
DCHECK(fence_and_semaphores.semaphores[1] == VK_NULL_HANDLE); DCHECK(fence_and_semaphores.semaphores[1] == VK_NULL_HANDLE);
return false; return false;
} }
...@@ -490,6 +497,7 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() { ...@@ -490,6 +497,7 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() {
VkDevice device = device_queue_->GetVulkanDevice(); VkDevice device = device_queue_->GetVulkanDevice();
FenceAndSemaphores fence_and_semaphores; FenceAndSemaphores fence_and_semaphores;
do { do {
#if !defined(OS_FUCHSIA)
if (LIKELY(!fence_and_semaphores_queue_.empty())) { if (LIKELY(!fence_and_semaphores_queue_.empty())) {
fence_and_semaphores = fence_and_semaphores_queue_.front(); fence_and_semaphores = fence_and_semaphores_queue_.front();
auto result = vkGetFenceStatus(device, fence_and_semaphores.fence); auto result = vkGetFenceStatus(device, fence_and_semaphores.fence);
...@@ -518,6 +526,7 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() { ...@@ -518,6 +526,7 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() {
break; break;
} }
} }
#endif // !defined(OS_FUCHSIA)
if (UNLIKELY(fence_and_semaphores.semaphores[0] == VK_NULL_HANDLE)) if (UNLIKELY(fence_and_semaphores.semaphores[0] == VK_NULL_HANDLE))
fence_and_semaphores.semaphores[0] = CreateSemaphore(device); fence_and_semaphores.semaphores[0] = CreateSemaphore(device);
...@@ -543,8 +552,17 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() { ...@@ -543,8 +552,17 @@ VulkanSwapChain::GetOrCreateFenceAndSemaphores() {
void VulkanSwapChain::ReturnFenceAndSemaphores( void VulkanSwapChain::ReturnFenceAndSemaphores(
const FenceAndSemaphores& fence_and_semaphores) { const FenceAndSemaphores& fence_and_semaphores) {
#if defined(OS_FUCHSIA)
VkDevice device = device_queue_->GetVulkanDevice();
DCHECK(fence_and_semaphores.fence == VK_NULL_HANDLE);
vkDestroySemaphore(device, fence_and_semaphores.semaphores[0],
nullptr /* pAllocator */);
vkDestroySemaphore(device, fence_and_semaphores.semaphores[1],
nullptr /* pAllocator */);
#else
DCHECK(fence_and_semaphores.fence != VK_NULL_HANDLE); DCHECK(fence_and_semaphores.fence != VK_NULL_HANDLE);
fence_and_semaphores_queue_.push_back(fence_and_semaphores); fence_and_semaphores_queue_.push_back(fence_and_semaphores);
#endif
} }
VulkanSwapChain::ScopedWrite::ScopedWrite(VulkanSwapChain* swap_chain) VulkanSwapChain::ScopedWrite::ScopedWrite(VulkanSwapChain* swap_chain)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/synchronization/condition_variable.h" #include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
...@@ -188,9 +189,13 @@ class COMPONENT_EXPORT(VULKAN) VulkanSwapChain { ...@@ -188,9 +189,13 @@ class COMPONENT_EXPORT(VULKAN) VulkanSwapChain {
// For executing PosSubBufferAsync tasks off the GPU main thread. // For executing PosSubBufferAsync tasks off the GPU main thread.
scoped_refptr<base::SequencedTaskRunner> post_sub_buffer_task_runner_; scoped_refptr<base::SequencedTaskRunner> post_sub_buffer_task_runner_;
#if !defined(OS_FUCHSIA)
// Available fence and semaphores can be reused when fence is passed. // Available fence and semaphores can be reused when fence is passed.
// Not used on Fuchsia because Fuchsia's swapchain implementation doesn't
// support fences.
base::circular_deque<FenceAndSemaphores> fence_and_semaphores_queue_ base::circular_deque<FenceAndSemaphores> fence_and_semaphores_queue_
GUARDED_BY(lock_); GUARDED_BY(lock_);
#endif
THREAD_CHECKER(thread_checker_); THREAD_CHECKER(thread_checker_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment