OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gpu/vulkan/tests/native_window.h" | |
6 #include "gpu/vulkan/vulkan_command_buffer.h" | |
7 #include "gpu/vulkan/vulkan_render_pass.h" | |
8 #include "gpu/vulkan/vulkan_surface.h" | |
9 #include "gpu/vulkan/vulkan_swap_chain.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "ui/gfx/geometry/rect.h" | |
12 | |
13 // This file tests basic vulkan initialization steps. | |
14 | |
15 namespace gpu { | |
16 | |
17 class BasicVulkanTest : public testing::Test { | |
18 public: | |
19 void SetUp() override { | |
20 const gfx::Rect kDefaultBounds(10, 10, 100, 100); | |
21 window_ = CreateNativeWindow(kDefaultBounds); | |
22 } | |
23 | |
24 void TearDown() override { | |
25 DestroyNativeWindow(window_); | |
26 window_ = gfx::kNullAcceleratedWidget; | |
27 } | |
28 | |
29 gfx::AcceleratedWidget window() const { return window_; } | |
30 | |
31 private: | |
32 gfx::AcceleratedWidget window_ = gfx::kNullAcceleratedWidget; | |
33 }; | |
34 | |
35 TEST_F(BasicVulkanTest, BasicVulkanSurface) { | |
36 scoped_ptr<VulkanSurface> surface = | |
37 VulkanSurface::CreateViewSurface(window()); | |
38 EXPECT_TRUE(surface); | |
39 EXPECT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); | |
40 surface->Destroy(); | |
41 } | |
42 | |
43 TEST_F(BasicVulkanTest, EmptyVulkanSwaps) { | |
44 scoped_ptr<VulkanSurface> surface = | |
45 VulkanSurface::CreateViewSurface(window()); | |
46 ASSERT_TRUE(surface); | |
47 ASSERT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); | |
48 | |
49 // First swap is a special case, call it first to get better errors. | |
50 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
51 | |
52 // Also make sure we can swap multiple times. | |
53 for (int i = 0; i < 10; ++i) { | |
54 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
55 } | |
56 | |
57 surface->Destroy(); | |
58 } | |
59 | |
60 TEST_F(BasicVulkanTest, BasicRenderPass) { | |
61 scoped_ptr<VulkanSurface> surface = | |
62 VulkanSurface::CreateViewSurface(window()); | |
63 ASSERT_TRUE(surface); | |
64 ASSERT_TRUE(surface->Initialize(VulkanSurface::DEFAULT_SURFACE_FORMAT)); | |
65 VulkanSwapChain* swap_chain = surface->GetSwapChain(); | |
66 | |
67 VulkanRenderPass::RenderPassData render_pass_data; | |
68 | |
69 // There is a single attachment which transitions present -> color -> present. | |
70 render_pass_data.attachments.resize(1); | |
71 VulkanRenderPass::AttachmentData* attachment = | |
72 &render_pass_data.attachments[0]; | |
73 attachment->attachment_type = | |
74 VulkanRenderPass::AttachmentType::ATTACHMENT_TYPE_SWAP_IMAGE; | |
75 attachment->sample_count = VK_SAMPLE_COUNT_1_BIT; | |
76 attachment->load_op = VK_ATTACHMENT_LOAD_OP_LOAD; | |
77 attachment->store_op = VK_ATTACHMENT_STORE_OP_STORE; | |
78 attachment->stencil_load_op = VK_ATTACHMENT_LOAD_OP_DONT_CARE; | |
79 attachment->stencil_store_op = VK_ATTACHMENT_STORE_OP_DONT_CARE; | |
80 attachment->start_layout = | |
81 VulkanRenderPass::ImageLayoutType::IMAGE_LAYOUT_TYPE_PRESENT; | |
82 attachment->end_layout = | |
83 VulkanRenderPass::ImageLayoutType::IMAGE_LAYOUT_TYPE_PRESENT; | |
84 | |
85 // Single subpass. | |
86 render_pass_data.subpass_datas.resize(1); | |
87 VulkanRenderPass::SubpassData* subpass_data = | |
88 &render_pass_data.subpass_datas[0]; | |
89 | |
90 // Our subpass will handle the transition to Color. | |
91 subpass_data->subpass_attachments.resize(1); | |
92 VulkanRenderPass::SubpassAttachment* subpass_attachment = | |
93 &subpass_data->subpass_attachments[0]; | |
94 subpass_attachment->attachment_index = 0; | |
95 subpass_attachment->subpass_layout = | |
96 VulkanRenderPass::ImageLayoutType::IMAGE_LAYOUT_TYPE_IMAGE_VIEW; | |
97 | |
98 ASSERT_TRUE(render_pass_data.ValidateData(swap_chain)); | |
99 | |
100 VulkanRenderPass render_pass; | |
101 EXPECT_TRUE(render_pass.Initialize(swap_chain, render_pass_data)); | |
102 | |
103 for (int i = 0; i < 10; ++i) { | |
104 VulkanCommandBuffer* command_buffer = swap_chain->GetCurrentCommandBuffer(); | |
105 { | |
106 ScopedSingleUseCommandBufferRecorder recorder(*command_buffer); | |
107 | |
108 render_pass.BeginRenderPass(recorder, true); | |
109 render_pass.EndRenderPass(recorder); | |
110 } | |
111 | |
112 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface->SwapBuffers()); | |
113 } | |
114 | |
115 render_pass.Destroy(); | |
piman
2016/03/25 02:01:26
You need to wait for the RenderPass to not be in u
David Yen
2016/03/25 17:36:13
Done. I added a Finish() call to VulkanSurface whi
| |
116 surface->Destroy(); | |
117 } | |
118 | |
119 } // namespace gpu | |
OLD | NEW |