Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: gpu/vulkan/tests/vulkan_test.cc

Issue 1829163003: Added initial implementation of the Vulkan Context Provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@vk_surface_patch
Patch Set: Block off vulkan_cc with enable_vulkan (not relevant in future patch) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/vulkan/BUILD.gn ('k') | gpu/vulkan/vulkan_command_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/vulkan/tests/native_window.h" 5 #include "gpu/vulkan/tests/native_window.h"
6 #include "gpu/vulkan/vulkan_command_buffer.h" 6 #include "gpu/vulkan/vulkan_command_buffer.h"
7 #include "gpu/vulkan/vulkan_device_queue.h"
7 #include "gpu/vulkan/vulkan_render_pass.h" 8 #include "gpu/vulkan/vulkan_render_pass.h"
8 #include "gpu/vulkan/vulkan_surface.h" 9 #include "gpu/vulkan/vulkan_surface.h"
9 #include "gpu/vulkan/vulkan_swap_chain.h" 10 #include "gpu/vulkan/vulkan_swap_chain.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
12 13
13 // This file tests basic vulkan initialization steps. 14 // This file tests basic vulkan initialization steps.
14 15
15 namespace gpu { 16 namespace gpu {
16 17
17 class BasicVulkanTest : public testing::Test { 18 class BasicVulkanTest : public testing::Test {
18 public: 19 public:
19 void SetUp() override { 20 void SetUp() override {
20 const gfx::Rect kDefaultBounds(10, 10, 100, 100); 21 const gfx::Rect kDefaultBounds(10, 10, 100, 100);
21 window_ = CreateNativeWindow(kDefaultBounds); 22 window_ = CreateNativeWindow(kDefaultBounds);
23 device_queue_.Initialize(
24 VulkanDeviceQueue::GRAPHICS_QUEUE_FLAG |
25 VulkanDeviceQueue::PRESENTATION_SUPPORT_QUEUE_FLAG);
22 } 26 }
23 27
24 void TearDown() override { 28 void TearDown() override {
25 DestroyNativeWindow(window_); 29 DestroyNativeWindow(window_);
26 window_ = gfx::kNullAcceleratedWidget; 30 window_ = gfx::kNullAcceleratedWidget;
31 device_queue_.Destroy();
27 } 32 }
28 33
29 gfx::AcceleratedWidget window() const { return window_; } 34 gfx::AcceleratedWidget window() const { return window_; }
35 VulkanDeviceQueue* GetDeviceQueue() { return &device_queue_; }
30 36
31 private: 37 private:
38 VulkanDeviceQueue device_queue_;
32 gfx::AcceleratedWidget window_ = gfx::kNullAcceleratedWidget; 39 gfx::AcceleratedWidget window_ = gfx::kNullAcceleratedWidget;
33 }; 40 };
34 41
35 TEST_F(BasicVulkanTest, BasicVulkanSurface) { 42 TEST_F(BasicVulkanTest, BasicVulkanSurface) {
36 scoped_ptr<VulkanSurface> surface = 43 scoped_ptr<VulkanSurface> surface =
37 VulkanSurface::CreateViewSurface(window()); 44 VulkanSurface::CreateViewSurface(window());
38 EXPECT_TRUE(surface); 45 EXPECT_TRUE(surface);
39 EXPECT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); 46 EXPECT_TRUE(surface->Initialize(GetDeviceQueue(),
47 VulkanSurface::DEFAULT_SURFACE_FORMAT));
40 surface->Destroy(); 48 surface->Destroy();
41 } 49 }
42 50
43 TEST_F(BasicVulkanTest, EmptyVulkanSwaps) { 51 TEST_F(BasicVulkanTest, EmptyVulkanSwaps) {
44 scoped_ptr<VulkanSurface> surface = 52 scoped_ptr<VulkanSurface> surface =
45 VulkanSurface::CreateViewSurface(window()); 53 VulkanSurface::CreateViewSurface(window());
46 ASSERT_TRUE(surface); 54 ASSERT_TRUE(surface);
47 ASSERT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); 55 ASSERT_TRUE(surface->Initialize(GetDeviceQueue(),
56 VulkanSurface::DEFAULT_SURFACE_FORMAT));
48 57
49 // First swap is a special case, call it first to get better errors. 58 // First swap is a special case, call it first to get better errors.
50 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); 59 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
51 60
52 // Also make sure we can swap multiple times. 61 // Also make sure we can swap multiple times.
53 for (int i = 0; i < 10; ++i) { 62 for (int i = 0; i < 10; ++i) {
54 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); 63 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
55 } 64 }
56 surface->Finish(); 65 surface->Finish();
57 surface->Destroy(); 66 surface->Destroy();
58 } 67 }
59 68
60 TEST_F(BasicVulkanTest, BasicRenderPass) { 69 TEST_F(BasicVulkanTest, BasicRenderPass) {
61 scoped_ptr<VulkanSurface> surface = 70 scoped_ptr<VulkanSurface> surface =
62 VulkanSurface::CreateViewSurface(window()); 71 VulkanSurface::CreateViewSurface(window());
63 ASSERT_TRUE(surface); 72 ASSERT_TRUE(surface);
64 ASSERT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); 73 ASSERT_TRUE(surface->Initialize(GetDeviceQueue(),
74 VulkanSurface::DEFAULT_SURFACE_FORMAT));
65 VulkanSwapChain* swap_chain = surface->GetSwapChain(); 75 VulkanSwapChain* swap_chain = surface->GetSwapChain();
66 76
67 VulkanRenderPass::RenderPassData render_pass_data; 77 VulkanRenderPass::RenderPassData render_pass_data;
68 78
69 // There is a single attachment which transitions present -> color -> present. 79 // There is a single attachment which transitions present -> color -> present.
70 render_pass_data.attachments.resize(1); 80 render_pass_data.attachments.resize(1);
71 VulkanRenderPass::AttachmentData* attachment = 81 VulkanRenderPass::AttachmentData* attachment =
72 &render_pass_data.attachments[0]; 82 &render_pass_data.attachments[0];
73 attachment->attachment_type = 83 attachment->attachment_type =
74 VulkanRenderPass::AttachmentType::ATTACHMENT_TYPE_SWAP_IMAGE; 84 VulkanRenderPass::AttachmentType::ATTACHMENT_TYPE_SWAP_IMAGE;
(...skipping 15 matching lines...) Expand all
90 // Our subpass will handle the transition to Color. 100 // Our subpass will handle the transition to Color.
91 subpass_data->subpass_attachments.resize(1); 101 subpass_data->subpass_attachments.resize(1);
92 VulkanRenderPass::SubpassAttachment* subpass_attachment = 102 VulkanRenderPass::SubpassAttachment* subpass_attachment =
93 &subpass_data->subpass_attachments[0]; 103 &subpass_data->subpass_attachments[0];
94 subpass_attachment->attachment_index = 0; 104 subpass_attachment->attachment_index = 0;
95 subpass_attachment->subpass_layout = 105 subpass_attachment->subpass_layout =
96 VulkanRenderPass::ImageLayoutType::IMAGE_LAYOUT_TYPE_IMAGE_VIEW; 106 VulkanRenderPass::ImageLayoutType::IMAGE_LAYOUT_TYPE_IMAGE_VIEW;
97 107
98 ASSERT_TRUE(render_pass_data.ValidateData(swap_chain)); 108 ASSERT_TRUE(render_pass_data.ValidateData(swap_chain));
99 109
100 VulkanRenderPass render_pass; 110 VulkanRenderPass render_pass(GetDeviceQueue());
101 EXPECT_TRUE(render_pass.Initialize(swap_chain, render_pass_data)); 111 EXPECT_TRUE(render_pass.Initialize(swap_chain, render_pass_data));
102 112
103 for (int i = 0; i < 10; ++i) { 113 for (int i = 0; i < 10; ++i) {
104 VulkanCommandBuffer* command_buffer = swap_chain->GetCurrentCommandBuffer(); 114 VulkanCommandBuffer* command_buffer = swap_chain->GetCurrentCommandBuffer();
105 { 115 {
106 ScopedSingleUseCommandBufferRecorder recorder(*command_buffer); 116 ScopedSingleUseCommandBufferRecorder recorder(*command_buffer);
107 117
108 render_pass.BeginRenderPass(recorder, true); 118 render_pass.BeginRenderPass(recorder, true);
109 render_pass.EndRenderPass(recorder); 119 render_pass.EndRenderPass(recorder);
110 } 120 }
111 121
112 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); 122 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers());
113 } 123 }
114 124
115 surface->Finish(); 125 surface->Finish();
116 render_pass.Destroy(); 126 render_pass.Destroy();
117 surface->Destroy(); 127 surface->Destroy();
118 } 128 }
119 129
120 } // namespace gpu 130 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/vulkan/BUILD.gn ('k') | gpu/vulkan/vulkan_command_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698