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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_context_lost.cc

Issue 1095893002: gpu: Fix some context lost marking glitches+leaks and add UMA stats (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix GLManager and fix another resource leak (comment #15) Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 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/command_buffer/service/gles2_cmd_decoder.h"
6
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
12 #include "gpu/command_buffer/service/context_group.h"
13 #include "gpu/command_buffer/service/gl_surface_mock.h"
14 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
15 #include "gpu/command_buffer/service/gpu_switches.h"
16 #include "gpu/command_buffer/service/mocks.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gl/gl_mock.h"
19
20 using ::gfx::MockGLInterface;
21 using ::testing::_;
22 using ::testing::DoAll;
23 using ::testing::InSequence;
24 using ::testing::Invoke;
25 using ::testing::MatcherCast;
26 using ::testing::Mock;
27 using ::testing::Pointee;
28 using ::testing::Return;
29 using ::testing::SaveArg;
30 using ::testing::SetArrayArgument;
31 using ::testing::SetArgumentPointee;
32 using ::testing::SetArgPointee;
33 using ::testing::StrEq;
34 using ::testing::StrictMock;
35
36 namespace gpu {
37 namespace gles2 {
38
39 using namespace cmds;
40
41 class GLES2DecoderDrawOOMTest : public GLES2DecoderManualInitTest {
42 protected:
43 void Init(bool has_robustness) {
44 InitState init;
45 init.lose_context_when_out_of_memory = true;
46 if (has_robustness)
47 init.extensions = "GL_ARB_robustness";
48 InitDecoder(init);
49 SetupDefaultProgram();
50 }
51
52 void Draw(GLenum reset_status,
53 error::ContextLostReason expected_other_reason) {
54 const GLsizei kFakeLargeCount = 0x1234;
55 SetupTexture();
56 if (context_->WasAllocatedUsingRobustnessExtension()) {
57 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
58 .WillOnce(Return(reset_status));
59 }
60 AddExpectationsForSimulatedAttrib0WithError(kFakeLargeCount, 0,
61 GL_OUT_OF_MEMORY);
62 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation();
63 // Other contexts in the group should be lost also.
64 EXPECT_CALL(*mock_decoder_, MarkContextLost(expected_other_reason))
65 .Times(1)
66 .RetiresOnSaturation();
67 DrawArrays cmd;
68 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
69 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd));
70 }
71 };
72
73 // Test that we lose context.
74 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonOOM) {
75 Init(false); // without robustness
76 const error::ContextLostReason expected_reason_for_other_contexts =
77 error::kOutOfMemory;
78 Draw(GL_NO_ERROR, expected_reason_for_other_contexts);
79 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
80 EXPECT_TRUE(decoder_->WasContextLost());
81 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason());
82 }
83
84 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsNoError) {
85 Init(true); // with robustness
86 // If the reset status is NO_ERROR, we should be signaling kOutOfMemory.
87 const error::ContextLostReason expected_reason_for_other_contexts =
88 error::kOutOfMemory;
89 Draw(GL_NO_ERROR, expected_reason_for_other_contexts);
90 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
91 EXPECT_TRUE(decoder_->WasContextLost());
92 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason());
93 }
94
95 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsGuilty) {
96 Init(true);
97 // If there was a reset, it should override kOutOfMemory.
98 const error::ContextLostReason expected_reason_for_other_contexts =
99 error::kUnknown;
100 Draw(GL_GUILTY_CONTEXT_RESET_ARB, expected_reason_for_other_contexts);
101 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
102 EXPECT_TRUE(decoder_->WasContextLost());
103 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason());
104 }
105
106 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsUnknown) {
107 Init(true);
108 // If there was a reset, it should override kOutOfMemory.
109 const error::ContextLostReason expected_reason_for_other_contexts =
110 error::kUnknown;
111 Draw(GL_UNKNOWN_CONTEXT_RESET_ARB, expected_reason_for_other_contexts);
112 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
113 EXPECT_TRUE(decoder_->WasContextLost());
114 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason());
115 }
116
117 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderDrawOOMTest, ::testing::Bool());
118
119 class GLES2DecoderLostContextTest : public GLES2DecoderManualInitTest {
120 protected:
121 void Init(bool has_robustness) {
122 InitState init;
123 init.gl_version = "opengl es 2.0";
124 if (has_robustness)
125 init.extensions = "GL_KHR_robustness";
126 InitDecoder(init);
127 }
128
129 void InitWithVirtualContextsAndRobustness() {
130 base::CommandLine command_line(0, NULL);
131 command_line.AppendSwitchASCII(
132 switches::kGpuDriverBugWorkarounds,
133 base::IntToString(USE_VIRTUALIZED_GL_CONTEXTS));
134 InitState init;
135 init.gl_version = "opengl es 2.0";
136 init.extensions = "GL_KHR_robustness";
137 InitDecoderWithCommandLine(init, &command_line);
138 }
139
140 void DoGetErrorWithContextLost(GLenum reset_status) {
141 DCHECK(context_->HasExtension("GL_KHR_robustness"));
142 EXPECT_CALL(*gl_, GetError())
143 .WillOnce(Return(GL_CONTEXT_LOST_KHR))
144 .RetiresOnSaturation();
145 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
146 .WillOnce(Return(reset_status));
147 cmds::GetError cmd;
148 cmd.Init(shared_memory_id_, shared_memory_offset_);
149 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd));
150 EXPECT_EQ(static_cast<GLuint>(GL_NO_ERROR), *GetSharedMemoryAs<GLenum*>());
151 }
152
153 void ClearCurrentDecoderError() {
154 DCHECK(decoder_->WasContextLost());
155 EXPECT_CALL(*gl_, GetError())
156 .WillOnce(Return(GL_CONTEXT_LOST_KHR))
157 .RetiresOnSaturation();
158 cmds::GetError cmd;
159 cmd.Init(shared_memory_id_, shared_memory_offset_);
160 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd));
161 }
162 };
163
164 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrent) {
165 Init(false); // without robustness
166 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false));
167 decoder_->MakeCurrent();
168 EXPECT_TRUE(decoder_->WasContextLost());
169 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason());
170
171 // We didn't process commands, so we need to clear the decoder error,
172 // so that we can shut down cleanly.
173 ClearCurrentDecoderError();
Ken Russell (switch to Gerrit) 2015/04/27 22:35:33 Will this happen in the normal operation of the co
no sievers 2015/04/27 23:24:41 FWIU there are multiple ways we detect a decoder e
174 }
175
176 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrentWithRobustness) {
177 Init(true); // with robustness
178 // If we can't make the context current, we cannot query the robustness
179 // extension.
180 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0);
181 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false));
182 decoder_->MakeCurrent();
183 EXPECT_TRUE(decoder_->WasContextLost());
184 EXPECT_FALSE(decoder_->WasContextLostByRobustnessExtension());
185 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason());
186
187 // We didn't process commands, so we need to clear the decoder error,
188 // so that we can shut down cleanly.
189 ClearCurrentDecoderError();
190 }
191
192 TEST_P(GLES2DecoderLostContextTest, LostFromResetAfterMakeCurrent) {
193 Init(true); // with robustness
194 InSequence seq;
195 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true));
196 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB())
197 .WillOnce(Return(GL_GUILTY_CONTEXT_RESET_KHR));
198 decoder_->MakeCurrent();
199 EXPECT_TRUE(decoder_->WasContextLost());
200 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension());
201 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason());
202
203 // We didn't process commands, so we need to clear the decoder error,
204 // so that we can shut down cleanly.
205 ClearCurrentDecoderError();
206 }
207
208 TEST_P(GLES2DecoderLostContextTest, LoseGuiltyFromGLError) {
209 Init(true);
210 // Always expect other contexts to be signaled as 'kUnknown' since we can't
211 // query their status without making them current.
212 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown))
213 .Times(1);
214 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_KHR);
215 EXPECT_TRUE(decoder_->WasContextLost());
216 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension());
217 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason());
218 }
219
220 TEST_P(GLES2DecoderLostContextTest, LoseInnocentFromGLError) {
221 Init(true);
222 // Always expect other contexts to be signaled as 'kUnknown' since we can't
223 // query their status without making them current.
224 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown))
225 .Times(1);
226 DoGetErrorWithContextLost(GL_INNOCENT_CONTEXT_RESET_KHR);
227 EXPECT_TRUE(decoder_->WasContextLost());
228 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension());
229 EXPECT_EQ(error::kInnocent, decoder_->GetContextLostReason());
230 }
231
232 TEST_P(GLES2DecoderLostContextTest, LoseVirtualContextWithRobustness) {
233 InitWithVirtualContextsAndRobustness();
234 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown))
235 .Times(1);
236 // Signal guilty....
237 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_KHR);
238 EXPECT_TRUE(decoder_->WasContextLost());
239 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension());
240 // ...but make sure we don't pretend, since for virtual contexts we don't
241 // know if this was really the guilty client.
242 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason());
243 }
244
245 TEST_P(GLES2DecoderLostContextTest, LoseGroupFromRobustness) {
246 // If one context in a group is lost through robustness,
247 // the other ones should also get lost and query the reset status.
248 Init(true);
249 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown))
250 .Times(1);
251 // There should be no GL calls, since we might not have a current context.
252 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0);
253 LoseContexts(error::kUnknown);
254 EXPECT_TRUE(decoder_->WasContextLost());
255 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason());
256
257 // We didn't process commands, so we need to clear the decoder error,
258 // so that we can shut down cleanly.
259 ClearCurrentDecoderError();
260 }
261
262 INSTANTIATE_TEST_CASE_P(Service,
263 GLES2DecoderLostContextTest,
264 ::testing::Bool());
265
266 } // namespace gles2
267 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698