Commit 1b869179 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Fix vulkan_tests

Bug: 1065499
Change-Id: Ib0dde0f46f73d73dbb580a6cc03288b6c0337c1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124687Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754148}
parent 09bfac8f
...@@ -147,6 +147,8 @@ if (enable_vulkan) { ...@@ -147,6 +147,8 @@ if (enable_vulkan) {
"//gpu/vulkan/init", "//gpu/vulkan/init",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//ui/events/platform",
"//ui/events/platform/x11",
"//ui/gfx", "//ui/gfx",
"//ui/gfx:native_widget_types", "//ui/gfx:native_widget_types",
"//ui/gfx/geometry", "//ui/gfx/geometry",
......
include_rules = [
"+ui/events/platform",
]
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "gpu/vulkan/init/vulkan_factory.h" #include "gpu/vulkan/init/vulkan_factory.h"
#include "gpu/vulkan/tests/native_window.h" #include "gpu/vulkan/tests/native_window.h"
#include "gpu/vulkan/vulkan_surface.h" #include "gpu/vulkan/vulkan_surface.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace gpu { namespace gpu {
...@@ -16,6 +17,7 @@ BasicVulkanTest::BasicVulkanTest() {} ...@@ -16,6 +17,7 @@ BasicVulkanTest::BasicVulkanTest() {}
BasicVulkanTest::~BasicVulkanTest() {} BasicVulkanTest::~BasicVulkanTest() {}
void BasicVulkanTest::SetUp() { void BasicVulkanTest::SetUp() {
platform_event_source_ = ui::PlatformEventSource::CreateDefault();
const gfx::Rect kDefaultBounds(10, 10, 100, 100); const gfx::Rect kDefaultBounds(10, 10, 100, 100);
window_ = CreateNativeWindow(kDefaultBounds); window_ = CreateNativeWindow(kDefaultBounds);
vulkan_implementation_ = CreateVulkanImplementation(); vulkan_implementation_ = CreateVulkanImplementation();
...@@ -33,6 +35,7 @@ void BasicVulkanTest::TearDown() { ...@@ -33,6 +35,7 @@ void BasicVulkanTest::TearDown() {
window_ = gfx::kNullAcceleratedWidget; window_ = gfx::kNullAcceleratedWidget;
device_queue_->Destroy(); device_queue_->Destroy();
vulkan_implementation_.reset(); vulkan_implementation_.reset();
platform_event_source_.reset();
} }
std::unique_ptr<VulkanSurface> BasicVulkanTest::CreateViewSurface( std::unique_ptr<VulkanSurface> BasicVulkanTest::CreateViewSurface(
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace ui {
class PlatformEventSource;
}
namespace gpu { namespace gpu {
class BasicVulkanTest : public testing::Test { class BasicVulkanTest : public testing::Test {
...@@ -25,10 +29,13 @@ class BasicVulkanTest : public testing::Test { ...@@ -25,10 +29,13 @@ class BasicVulkanTest : public testing::Test {
return vulkan_implementation_.get(); return vulkan_implementation_.get();
} }
VulkanDeviceQueue* GetDeviceQueue() { return device_queue_.get(); } VulkanDeviceQueue* GetDeviceQueue() { return device_queue_.get(); }
VkDevice device() { return device_queue_->GetVulkanDevice(); }
VkQueue queue() { return device_queue_->GetVulkanQueue(); }
std::unique_ptr<VulkanSurface> CreateViewSurface( std::unique_ptr<VulkanSurface> CreateViewSurface(
gfx::AcceleratedWidget window); gfx::AcceleratedWidget window);
private: private:
std::unique_ptr<ui::PlatformEventSource> platform_event_source_;
std::unique_ptr<VulkanImplementation> vulkan_implementation_; std::unique_ptr<VulkanImplementation> vulkan_implementation_;
std::unique_ptr<VulkanDeviceQueue> device_queue_; std::unique_ptr<VulkanDeviceQueue> device_queue_;
......
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
#include <memory> #include <memory>
#include "base/optional.h"
#include "gpu/vulkan/tests/basic_vulkan_test.h" #include "gpu/vulkan/tests/basic_vulkan_test.h"
#include "gpu/vulkan/vulkan_command_buffer.h" #include "gpu/vulkan/vulkan_command_buffer.h"
#include "gpu/vulkan/vulkan_fence_helper.h"
#include "gpu/vulkan/vulkan_surface.h" #include "gpu/vulkan/vulkan_surface.h"
#include "gpu/vulkan/vulkan_swap_chain.h" #include "gpu/vulkan/vulkan_swap_chain.h"
#include "gpu/vulkan/vulkan_util.h"
// This file tests basic vulkan initialization steps. // This file tests basic vulkan initialization steps.
...@@ -31,11 +34,42 @@ TEST_F(BasicVulkanTest, EmptyVulkanSwaps) { ...@@ -31,11 +34,42 @@ TEST_F(BasicVulkanTest, EmptyVulkanSwaps) {
ASSERT_TRUE( ASSERT_TRUE(
surface->Reshape(gfx::Size(100, 100), gfx::OVERLAY_TRANSFORM_NONE)); surface->Reshape(gfx::Size(100, 100), gfx::OVERLAY_TRANSFORM_NONE));
constexpr VkSemaphore kNullSemaphore = VK_NULL_HANDLE;
auto* fence_helper = GetDeviceQueue()->GetFenceHelper();
base::Optional<VulkanSwapChain::ScopedWrite> scoped_write;
scoped_write.emplace(surface->swap_chain());
EXPECT_TRUE(scoped_write->success());
VkSemaphore begin_semaphore = scoped_write->TakeBeginSemaphore();
EXPECT_NE(begin_semaphore, kNullSemaphore);
EXPECT_TRUE(SubmitWaitVkSemaphore(queue(), begin_semaphore));
fence_helper->EnqueueSemaphoreCleanupForSubmittedWork(begin_semaphore);
VkSemaphore end_semaphore = scoped_write->GetEndSemaphore();
EXPECT_NE(end_semaphore, kNullSemaphore);
EXPECT_TRUE(SubmitSignalVkSemaphore(queue(), end_semaphore));
scoped_write.reset();
// First swap is a special case, call it first to get better errors. // First swap is a special case, call it first to get better errors.
EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
// Also make sure we can swap multiple times. // Also make sure we can swap multiple times.
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
base::Optional<VulkanSwapChain::ScopedWrite> scoped_write;
scoped_write.emplace(surface->swap_chain());
EXPECT_TRUE(scoped_write->success());
VkSemaphore begin_semaphore = scoped_write->TakeBeginSemaphore();
EXPECT_NE(begin_semaphore, kNullSemaphore);
EXPECT_TRUE(SubmitWaitVkSemaphore(queue(), begin_semaphore));
VkSemaphore end_semaphore = scoped_write->GetEndSemaphore();
EXPECT_NE(end_semaphore, kNullSemaphore);
EXPECT_TRUE(SubmitSignalVkSemaphore(queue(), end_semaphore));
scoped_write.reset();
EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
} }
surface->Finish(); surface->Finish();
......
...@@ -168,6 +168,9 @@ TEST_F(VulkanFenceHelperTest, SkiaCallbackAfterFences) { ...@@ -168,6 +168,9 @@ TEST_F(VulkanFenceHelperTest, SkiaCallbackAfterFences) {
fence_helper->GenerateCleanupFence(); fence_helper->GenerateCleanupFence();
EXPECT_TRUE(fence_handle.is_valid()); EXPECT_TRUE(fence_handle.is_valid());
// Call vkQueueWaitIdle() to make sure the |fence_handle| is passed.
vkQueueWaitIdle(queue());
// Enqueue 5 more callbacks. // Enqueue 5 more callbacks.
for (int i = 5; i < 10; i++) { for (int i = 5; i < 10; i++) {
fence_helper->EnqueueCleanupTaskForSubmittedWork( fence_helper->EnqueueCleanupTaskForSubmittedWork(
......
...@@ -31,10 +31,14 @@ bool SubmitWaitVkSemaphores(VkQueue vk_queue, ...@@ -31,10 +31,14 @@ bool SubmitWaitVkSemaphores(VkQueue vk_queue,
const base::span<VkSemaphore>& vk_semaphores, const base::span<VkSemaphore>& vk_semaphores,
VkFence vk_fence) { VkFence vk_fence) {
DCHECK(!vk_semaphores.empty()); DCHECK(!vk_semaphores.empty());
std::vector<VkPipelineStageFlags> semaphore_stages(vk_semaphores.size());
std::fill(semaphore_stages.begin(), semaphore_stages.end(),
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
// Structure specifying a queue submit operation. // Structure specifying a queue submit operation.
VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO};
submit_info.waitSemaphoreCount = vk_semaphores.size(); submit_info.waitSemaphoreCount = vk_semaphores.size();
submit_info.pWaitSemaphores = vk_semaphores.data(); submit_info.pWaitSemaphores = vk_semaphores.data();
submit_info.pWaitDstStageMask = semaphore_stages.data();
const unsigned int submit_count = 1; const unsigned int submit_count = 1;
return vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) == return vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) ==
VK_SUCCESS; VK_SUCCESS;
......
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