File: vulkan_test.cc

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 3,949 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include <optional>

#include "gpu/vulkan/tests/basic_vulkan_test.h"
#include "gpu/vulkan/vulkan_command_buffer.h"
#include "gpu/vulkan/vulkan_command_pool.h"
#include "gpu/vulkan/vulkan_function_pointers.h"
#include "gpu/vulkan/vulkan_surface.h"
#include "gpu/vulkan/vulkan_swap_chain.h"
#include "gpu/vulkan/vulkan_util.h"

// This file tests basic vulkan initialization steps.

namespace gpu {

TEST_F(BasicVulkanTest, BasicVulkanSurface) {
  if (!supports_swapchain())
    return;
  std::unique_ptr<VulkanSurface> surface = CreateViewSurface(window());
  EXPECT_TRUE(surface);
  EXPECT_TRUE(surface->Initialize(GetDeviceQueue(),
                                  VulkanSurface::DEFAULT_SURFACE_FORMAT));
  EXPECT_TRUE(
      surface->Reshape(gfx::Size(100, 100), gfx::OVERLAY_TRANSFORM_NONE));
  surface->Destroy();
}

TEST_F(BasicVulkanTest, EmptyVulkanSwaps) {
  if (!supports_swapchain())
    return;

  auto command_pool = std::make_unique<VulkanCommandPool>(GetDeviceQueue());
  EXPECT_TRUE(command_pool->Initialize());

  std::unique_ptr<VulkanSurface> surface = CreateViewSurface(window());
  ASSERT_TRUE(surface);
  ASSERT_TRUE(surface->Initialize(GetDeviceQueue(),
                                  VulkanSurface::DEFAULT_SURFACE_FORMAT));
  ASSERT_TRUE(
      surface->Reshape(gfx::Size(100, 100), gfx::OVERLAY_TRANSFORM_NONE));

  constexpr VkSemaphore kNullSemaphore = VK_NULL_HANDLE;

  std::optional<VulkanSwapChain::ScopedWrite> scoped_write;
  scoped_write.emplace(surface->swap_chain());
  EXPECT_TRUE(scoped_write->success());

  VkSemaphore begin_semaphore = scoped_write->begin_semaphore();
  EXPECT_NE(begin_semaphore, kNullSemaphore);

  VkSemaphore end_semaphore = scoped_write->end_semaphore();
  EXPECT_NE(end_semaphore, kNullSemaphore);

  auto command_buffer = command_pool->CreatePrimaryCommandBuffer();

  {
    ScopedSingleUseCommandBufferRecorder recorder(*command_buffer);
    command_buffer->TransitionImageLayout(scoped_write->image(),
                                          scoped_write->image_layout(),
                                          VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
  }
  EXPECT_TRUE(command_buffer->Submit(1, &begin_semaphore, 1, &end_semaphore));
  scoped_write.reset();

  // First swap is a special case, call it first to get better errors.
  EXPECT_EQ(gfx::SwapResult::SWAP_ACK,
            surface->SwapBuffers(
                base::DoNothingAs<void(const gfx::PresentationFeedback&)>()));

  vkQueueWaitIdle(GetDeviceQueue()->GetVulkanQueue());
  command_buffer->Destroy();
  command_buffer.reset();

  // Also make sure we can swap multiple times.
  for (int i = 0; i < 10; ++i) {
    scoped_write.emplace(surface->swap_chain());
    EXPECT_TRUE(scoped_write->success());

    begin_semaphore = scoped_write->begin_semaphore();
    EXPECT_NE(begin_semaphore, kNullSemaphore);

    end_semaphore = scoped_write->end_semaphore();
    EXPECT_NE(end_semaphore, kNullSemaphore);

    command_buffer = command_pool->CreatePrimaryCommandBuffer();
    {
      ScopedSingleUseCommandBufferRecorder recorder(*command_buffer);

      command_buffer->TransitionImageLayout(scoped_write->image(),
                                            scoped_write->image_layout(),
                                            VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
    }
    EXPECT_TRUE(command_buffer->Submit(1, &begin_semaphore, 1, &end_semaphore));
    scoped_write.reset();

    EXPECT_EQ(gfx::SwapResult::SWAP_ACK,
              surface->SwapBuffers(
                  base::DoNothingAs<void(const gfx::PresentationFeedback&)>()));
    vkQueueWaitIdle(GetDeviceQueue()->GetVulkanQueue());
    command_buffer->Destroy();
    command_buffer.reset();
  }
  surface->Finish();
  surface->Destroy();

  command_pool->Destroy();
}

}  // namespace gpu