Flutter Engine
The Flutter Engine
gpu_tracer_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 <memory>
6#include "flutter/testing/testing.h" // IWYU pragma: keep
8#include "gtest/gtest.h"
13
14namespace impeller {
15namespace testing {
16
17#ifdef IMPELLER_DEBUG
18TEST(GPUTracerVK, CanBeDisabled) {
19 auto const context =
20 MockVulkanContextBuilder()
21 .SetSettingsCallback([](ContextVK::Settings& settings) {
22 settings.enable_gpu_tracing = false;
23 })
24 .Build();
25 auto tracer = context->GetGPUTracer();
26
27 ASSERT_FALSE(tracer->IsEnabled());
28}
29
30TEST(GPUTracerVK, DisabledFrameCycle) {
31 auto const context =
32 MockVulkanContextBuilder()
33 .SetSettingsCallback([](ContextVK::Settings& settings) {
34 settings.enable_gpu_tracing = false;
35 })
36 .Build();
37 auto tracer = context->GetGPUTracer();
38
39 // Check that a repeated frame start/end cycle does not fail any assertions.
40 for (int i = 0; i < 2; i++) {
41 tracer->MarkFrameStart();
42 tracer->MarkFrameEnd();
43 }
44}
45
46TEST(GPUTracerVK, CanTraceCmdBuffer) {
47 auto const context =
48 MockVulkanContextBuilder()
49 .SetSettingsCallback([](ContextVK::Settings& settings) {
50 settings.enable_gpu_tracing = true;
51 })
52 .Build();
53 auto tracer = context->GetGPUTracer();
54
55 ASSERT_TRUE(tracer->IsEnabled());
56 tracer->MarkFrameStart();
57
58 auto cmd_buffer = context->CreateCommandBuffer();
59 auto blit_pass = cmd_buffer->CreateBlitPass();
60 blit_pass->EncodeCommands(context->GetResourceAllocator());
61
62 auto latch = std::make_shared<fml::CountDownLatch>(1u);
63
64 if (!context->GetCommandQueue()
65 ->Submit(
66 {cmd_buffer},
67 [latch](CommandBuffer::Status status) { latch->CountDown(); })
68 .ok()) {
69 GTEST_FAIL() << "Failed to submit cmd buffer";
70 }
71
72 tracer->MarkFrameEnd();
73 latch->Wait();
74
75 auto called = GetMockVulkanFunctions(context->GetDevice());
76 ASSERT_NE(called, nullptr);
77 ASSERT_TRUE(std::find(called->begin(), called->end(), "vkCreateQueryPool") !=
78 called->end());
79 ASSERT_TRUE(std::find(called->begin(), called->end(),
80 "vkGetQueryPoolResults") != called->end());
81}
82
83TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) {
84 auto const context =
85 MockVulkanContextBuilder()
86 .SetSettingsCallback([](ContextVK::Settings& settings) {
87 settings.enable_gpu_tracing = true;
88 })
89 .Build();
90 auto tracer = context->GetGPUTracer();
91
92 ASSERT_TRUE(tracer->IsEnabled());
93
94 auto cmd_buffer = context->CreateCommandBuffer();
95 auto blit_pass = cmd_buffer->CreateBlitPass();
96 blit_pass->EncodeCommands(context->GetResourceAllocator());
97
98 auto latch = std::make_shared<fml::CountDownLatch>(1u);
99 if (!context->GetCommandQueue()
100 ->Submit(
101 {cmd_buffer},
102 [latch](CommandBuffer::Status status) { latch->CountDown(); })
103 .ok()) {
104 GTEST_FAIL() << "Failed to submit cmd buffer";
105 }
106
107 latch->Wait();
108
109 auto called = GetMockVulkanFunctions(context->GetDevice());
110
111 ASSERT_NE(called, nullptr);
112 ASSERT_TRUE(std::find(called->begin(), called->end(),
113 "vkGetQueryPoolResults") == called->end());
114}
115
116// This cmd buffer starts when there is a frame but finishes when there is none.
117// This should result in the same recorded work.
118TEST(GPUTracerVK, TracesWithPartialFrameOverlap) {
119 auto const context =
120 MockVulkanContextBuilder()
121 .SetSettingsCallback([](ContextVK::Settings& settings) {
122 settings.enable_gpu_tracing = true;
123 })
124 .Build();
125 auto tracer = context->GetGPUTracer();
126
127 ASSERT_TRUE(tracer->IsEnabled());
128 tracer->MarkFrameStart();
129
130 auto cmd_buffer = context->CreateCommandBuffer();
131 auto blit_pass = cmd_buffer->CreateBlitPass();
132 blit_pass->EncodeCommands(context->GetResourceAllocator());
133
134 auto latch = std::make_shared<fml::CountDownLatch>(1u);
135 if (!context->GetCommandQueue()
136 ->Submit(
137 {cmd_buffer},
138 [latch](CommandBuffer::Status status) { latch->CountDown(); })
139 .ok()) {
140 GTEST_FAIL() << "Failed to submit cmd buffer";
141 }
142 tracer->MarkFrameEnd();
143
144 latch->Wait();
145
146 auto called = GetMockVulkanFunctions(context->GetDevice());
147 ASSERT_NE(called, nullptr);
148 ASSERT_TRUE(std::find(called->begin(), called->end(), "vkCreateQueryPool") !=
149 called->end());
150 ASSERT_TRUE(std::find(called->begin(), called->end(),
151 "vkGetQueryPoolResults") != called->end());
152}
153
154#endif // IMPELLER_DEBUG
155
156} // namespace testing
157} // namespace impeller
int find(T *array, int N, T item)
def Build(configs, env, options)
Definition: build.py:232
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)
Definition: mock_vulkan.cc:926
TEST(AiksCanvasTest, EmptyCullRect)