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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests for the QueryTracker.
#include "gpu/command_buffer/client/query_tracker.h"
#include <GLES2/gl2ext.h>
#include "base/memory/scoped_ptr.h"
#include "gpu/command_buffer/client/client_test_helper.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/mapped_memory.h"
#include "gpu/command_buffer/common/command_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace gpu {
namespace gles2 {
namespace {
void EmptyPoll() {
}
}
class QuerySyncManagerTest : public testing::Test {
protected:
static const int32 kNumCommandEntries = 400;
static const int32 kCommandBufferSizeBytes =
kNumCommandEntries * sizeof(CommandBufferEntry);
void SetUp() override {
command_buffer_.reset(new MockClientCommandBuffer());
helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
helper_->Initialize(kCommandBufferSizeBytes);
mapped_memory_.reset(new MappedMemoryManager(
helper_.get(), base::Bind(&EmptyPoll), MappedMemoryManager::kNoLimit));
sync_manager_.reset(new QuerySyncManager(mapped_memory_.get()));
}
void TearDown() override {
sync_manager_.reset();
mapped_memory_.reset();
helper_.reset();
command_buffer_.reset();
}
scoped_ptr<CommandBuffer> command_buffer_;
scoped_ptr<GLES2CmdHelper> helper_;
scoped_ptr<MappedMemoryManager> mapped_memory_;
scoped_ptr<QuerySyncManager> sync_manager_;
};
TEST_F(QuerySyncManagerTest, Basic) {
QuerySyncManager::QueryInfo infos[4];
memset(&infos, 0xBD, sizeof(infos));
for (size_t ii = 0; ii < arraysize(infos); ++ii) {
EXPECT_TRUE(sync_manager_->Alloc(&infos[ii]));
EXPECT_NE(0, infos[ii].shm_id);
ASSERT_TRUE(infos[ii].sync != NULL);
EXPECT_EQ(0, infos[ii].sync->process_count);
EXPECT_EQ(0u, infos[ii].sync->result);
}
for (size_t ii = 0; ii < arraysize(infos); ++ii) {
sync_manager_->Free(infos[ii]);
}
}
TEST_F(QuerySyncManagerTest, DontFree) {
QuerySyncManager::QueryInfo infos[4];
memset(&infos, 0xBD, sizeof(infos));
for (size_t ii = 0; ii < arraysize(infos); ++ii) {
EXPECT_TRUE(sync_manager_->Alloc(&infos[ii]));
}
}
class QueryTrackerTest : public testing::Test {
protected:
static const int32 kNumCommandEntries = 400;
static const int32 kCommandBufferSizeBytes =
kNumCommandEntries * sizeof(CommandBufferEntry);
void SetUp() override {
command_buffer_.reset(new MockClientCommandBuffer());
helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
helper_->Initialize(kCommandBufferSizeBytes);
mapped_memory_.reset(new MappedMemoryManager(
helper_.get(), base::Bind(&EmptyPoll), MappedMemoryManager::kNoLimit));
query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
}
void TearDown() override {
query_tracker_.reset();
mapped_memory_.reset();
helper_.reset();
command_buffer_.reset();
}
QuerySync* GetSync(QueryTracker::Query* query) {
return query->info_.sync;
}
QuerySyncManager::Bucket* GetBucket(QueryTracker::Query* query) {
return query->info_.bucket;
}
uint32 GetFlushGeneration() { return helper_->flush_generation(); }
scoped_ptr<CommandBuffer> command_buffer_;
scoped_ptr<GLES2CmdHelper> helper_;
scoped_ptr<MappedMemoryManager> mapped_memory_;
scoped_ptr<QueryTracker> query_tracker_;
};
TEST_F(QueryTrackerTest, Basic) {
const GLuint kId1 = 123;
const GLuint kId2 = 124;
// Check we can create a Query.
QueryTracker::Query* query = query_tracker_->CreateQuery(
kId1, GL_ANY_SAMPLES_PASSED_EXT);
ASSERT_TRUE(query != NULL);
// Check we can get the same Query.
EXPECT_EQ(query, query_tracker_->GetQuery(kId1));
// Check we get nothing for a non-existent query.
EXPECT_TRUE(query_tracker_->GetQuery(kId2) == NULL);
// Check we can delete the query.
query_tracker_->RemoveQuery(kId1);
// Check we get nothing for a non-existent query.
EXPECT_TRUE(query_tracker_->GetQuery(kId1) == NULL);
}
TEST_F(QueryTrackerTest, Query) {
const GLuint kId1 = 123;
const int32 kToken = 46;
const uint32 kResult = 456;
// Create a Query.
QueryTracker::Query* query = query_tracker_->CreateQuery(
kId1, GL_ANY_SAMPLES_PASSED_EXT);
ASSERT_TRUE(query != NULL);
EXPECT_TRUE(query->NeverUsed());
EXPECT_FALSE(query->Pending());
EXPECT_EQ(0, query->token());
EXPECT_EQ(0, query->submit_count());
// Check MarkAsActive.
query->MarkAsActive();
EXPECT_FALSE(query->NeverUsed());
EXPECT_FALSE(query->Pending());
EXPECT_EQ(0, query->token());
EXPECT_EQ(1, query->submit_count());
// Check MarkAsPending.
query->MarkAsPending(kToken);
EXPECT_FALSE(query->NeverUsed());
EXPECT_TRUE(query->Pending());
EXPECT_EQ(kToken, query->token());
EXPECT_EQ(1, query->submit_count());
// Check CheckResultsAvailable.
EXPECT_FALSE(query->CheckResultsAvailable(helper_.get()));
EXPECT_FALSE(query->NeverUsed());
EXPECT_TRUE(query->Pending());
// Flush only once if no more flushes happened between a call to
// EndQuery command and CheckResultsAvailable
// Advance put_ so flush calls in CheckResultsAvailable go through
// and updates flush_generation count
helper_->Noop(1);
// Set Query in pending state_ to simulate EndQuery command is called
query->MarkAsPending(kToken);
EXPECT_TRUE(query->Pending());
// Store FlushGeneration count after EndQuery is called
uint32 gen1 = GetFlushGeneration();
EXPECT_FALSE(query->CheckResultsAvailable(helper_.get()));
uint32 gen2 = GetFlushGeneration();
EXPECT_NE(gen1, gen2);
// Repeated calls to CheckResultsAvailable should not flush unnecessarily
EXPECT_FALSE(query->CheckResultsAvailable(helper_.get()));
gen1 = GetFlushGeneration();
EXPECT_EQ(gen1, gen2);
EXPECT_FALSE(query->CheckResultsAvailable(helper_.get()));
gen1 = GetFlushGeneration();
EXPECT_EQ(gen1, gen2);
// Simulate GPU process marking it as available.
QuerySync* sync = GetSync(query);
sync->process_count = query->submit_count();
sync->result = kResult;
// Check CheckResultsAvailable.
EXPECT_TRUE(query->CheckResultsAvailable(helper_.get()));
EXPECT_EQ(kResult, query->GetResult());
EXPECT_FALSE(query->NeverUsed());
EXPECT_FALSE(query->Pending());
}
TEST_F(QueryTrackerTest, Remove) {
const GLuint kId1 = 123;
const int32 kToken = 46;
const uint32 kResult = 456;
// Create a Query.
QueryTracker::Query* query = query_tracker_->CreateQuery(
kId1, GL_ANY_SAMPLES_PASSED_EXT);
ASSERT_TRUE(query != NULL);
QuerySyncManager::Bucket* bucket = GetBucket(query);
EXPECT_EQ(1u, bucket->used_query_count);
query->MarkAsActive();
query->MarkAsPending(kToken);
query_tracker_->RemoveQuery(kId1);
// Check we get nothing for a non-existent query.
EXPECT_TRUE(query_tracker_->GetQuery(kId1) == NULL);
// Check that memory was not freed.
EXPECT_EQ(1u, bucket->used_query_count);
// Simulate GPU process marking it as available.
QuerySync* sync = GetSync(query);
sync->process_count = query->submit_count();
sync->result = kResult;
// Check FreeCompletedQueries.
query_tracker_->FreeCompletedQueries();
EXPECT_EQ(0u, bucket->used_query_count);
}
} // namespace gles2
} // namespace gpu
|