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