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

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

Issue 2837213003: Restore samplers' state across virtualized GL contexts. (Closed)
Patch Set: Addressed review feedback from jbauman. Created 3 years, 7 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
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc ('k') | ui/gl/gl_state_restorer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 129 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
130 AddExpectationsForBindTexture(GL_TEXTURE_2D, 130 AddExpectationsForBindTexture(GL_TEXTURE_2D,
131 TestHelper::kServiceDefaultTexture2dId); 131 TestHelper::kServiceDefaultTexture2dId);
132 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 132 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
133 TestHelper::kServiceDefaultTextureCubemapId); 133 TestHelper::kServiceDefaultTextureCubemapId);
134 } 134 }
135 135
136 // Expect to restore the active texture unit to GL_TEXTURE0. 136 // Expect to restore the active texture unit to GL_TEXTURE0.
137 AddExpectationsForActiveTexture(GL_TEXTURE0); 137 AddExpectationsForActiveTexture(GL_TEXTURE0);
138 138
139 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 139 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(NULL);
140 } 140 }
141 141
142 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) { 142 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) {
jbauman 2017/04/26 01:22:45 Could you modify these these tests to init the dec
Ken Russell (switch to Gerrit) 2017/04/26 21:36:35 Thanks for the suggestion. Rather than do this, I'
143 InitState init; 143 InitState init;
144 InitDecoder(init); 144 InitDecoder(init);
145 SetupTexture(); 145 SetupTexture();
146 146
147 InSequence sequence; 147 InSequence sequence;
148 // Expect to restore texture bindings for unit GL_TEXTURE0. 148 // Expect to restore texture bindings for unit GL_TEXTURE0.
149 AddExpectationsForActiveTexture(GL_TEXTURE0); 149 AddExpectationsForActiveTexture(GL_TEXTURE0);
150 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 150 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
151 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 151 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
152 152
153 // Expect to restore texture bindings for remaining units. 153 // Expect to restore texture bindings for remaining units.
154 for (uint32_t i = 1; i < group().max_texture_units(); ++i) { 154 for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
155 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 155 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
156 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 156 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
157 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 157 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
158 } 158 }
159 159
160 // Expect to restore the active texture unit to GL_TEXTURE0. 160 // Expect to restore the active texture unit to GL_TEXTURE0.
161 AddExpectationsForActiveTexture(GL_TEXTURE0); 161 AddExpectationsForActiveTexture(GL_TEXTURE0);
162 162
163 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 163 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(NULL);
164 } 164 }
165 165
166 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) { 166 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
167 InitState init; 167 InitState init;
168 init.bind_generates_resource = true; 168 init.bind_generates_resource = true;
169 InitDecoder(init); 169 InitDecoder(init);
170 SetupTexture(); 170 SetupTexture();
171 171
172 // Construct a previous ContextState with all texture bindings 172 // Construct a previous ContextState with all texture bindings
173 // set to default textures. 173 // set to default textures.
174 ContextState prev_state(NULL, NULL, NULL); 174 ContextState prev_state(NULL, NULL, NULL);
175 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 175 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
176 176
177 InSequence sequence; 177 InSequence sequence;
178 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 178 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
179 // since the rest of the bindings haven't changed between the current 179 // since the rest of the bindings haven't changed between the current
180 // state and the |prev_state|. 180 // state and the |prev_state|.
181 AddExpectationsForActiveTexture(GL_TEXTURE0); 181 AddExpectationsForActiveTexture(GL_TEXTURE0);
182 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 182 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
183 183
184 // Expect to restore active texture unit to GL_TEXTURE0. 184 // Expect to restore active texture unit to GL_TEXTURE0.
185 AddExpectationsForActiveTexture(GL_TEXTURE0); 185 AddExpectationsForActiveTexture(GL_TEXTURE0);
186 186
187 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 187 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
188 } 188 }
189 189
190 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) { 190 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) {
191 InitState init; 191 InitState init;
192 InitDecoder(init); 192 InitDecoder(init);
193 SetupTexture(); 193 SetupTexture();
194 194
195 // Construct a previous ContextState with all texture bindings 195 // Construct a previous ContextState with all texture bindings
196 // set to default textures. 196 // set to default textures.
197 ContextState prev_state(NULL, NULL, NULL); 197 ContextState prev_state(NULL, NULL, NULL);
198 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 198 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
199 199
200 InSequence sequence; 200 InSequence sequence;
201 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 201 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
202 // since the rest of the bindings haven't changed between the current 202 // since the rest of the bindings haven't changed between the current
203 // state and the |prev_state|. 203 // state and the |prev_state|.
204 AddExpectationsForActiveTexture(GL_TEXTURE0); 204 AddExpectationsForActiveTexture(GL_TEXTURE0);
205 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 205 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
206 206
207 // Expect to restore active texture unit to GL_TEXTURE0. 207 // Expect to restore active texture unit to GL_TEXTURE0.
208 AddExpectationsForActiveTexture(GL_TEXTURE0); 208 AddExpectationsForActiveTexture(GL_TEXTURE0);
209 209
210 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 210 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
211 } 211 }
212 212
213 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) { 213 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) {
214 InitState init; 214 InitState init;
215 InitDecoder(init); 215 InitDecoder(init);
216 216
217 // Bind a non-default texture to GL_TEXTURE1 unit. 217 // Bind a non-default texture to GL_TEXTURE1 unit.
218 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 218 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
219 ActiveTexture cmd; 219 ActiveTexture cmd;
220 cmd.Init(GL_TEXTURE1); 220 cmd.Init(GL_TEXTURE1);
221 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 221 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
222 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 222 EXPECT_EQ(GL_NO_ERROR, GetGLError());
223 SetupTexture(); 223 SetupTexture();
224 224
225 // Construct a previous ContextState with all texture bindings 225 // Construct a previous ContextState with all texture bindings
226 // set to default textures. 226 // set to default textures.
227 ContextState prev_state(NULL, NULL, NULL); 227 ContextState prev_state(NULL, NULL, NULL);
228 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 228 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
229 229
230 InSequence sequence; 230 InSequence sequence;
231 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit, 231 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
232 // since the rest of the bindings haven't changed between the current 232 // since the rest of the bindings haven't changed between the current
233 // state and the |prev_state|. 233 // state and the |prev_state|.
234 AddExpectationsForActiveTexture(GL_TEXTURE1); 234 AddExpectationsForActiveTexture(GL_TEXTURE1);
235 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 235 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
236 236
237 // Expect to restore active texture unit to GL_TEXTURE1. 237 // Expect to restore active texture unit to GL_TEXTURE1.
238 AddExpectationsForActiveTexture(GL_TEXTURE1); 238 AddExpectationsForActiveTexture(GL_TEXTURE1);
239 239
240 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 240 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
241 } 241 }
242 242
243 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) { 243 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
244 InitState init; 244 InitState init;
245 init.bind_generates_resource = true; 245 init.bind_generates_resource = true;
246 InitDecoder(init); 246 InitDecoder(init);
247 247
248 // Bind a non-default texture to GL_TEXTURE1 unit. 248 // Bind a non-default texture to GL_TEXTURE1 unit.
249 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 249 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
250 SpecializedSetup<ActiveTexture, 0>(true); 250 SpecializedSetup<ActiveTexture, 0>(true);
(...skipping 17 matching lines...) Expand all
268 TestHelper::kServiceDefaultTexture2dId); 268 TestHelper::kServiceDefaultTexture2dId);
269 269
270 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to 270 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
271 // non-default. 271 // non-default.
272 AddExpectationsForActiveTexture(GL_TEXTURE1); 272 AddExpectationsForActiveTexture(GL_TEXTURE1);
273 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 273 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
274 274
275 // Expect to restore active texture unit to GL_TEXTURE1. 275 // Expect to restore active texture unit to GL_TEXTURE1.
276 AddExpectationsForActiveTexture(GL_TEXTURE1); 276 AddExpectationsForActiveTexture(GL_TEXTURE1);
277 277
278 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 278 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
279 } 279 }
280 280
281 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) { 281 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
282 InitState init; 282 InitState init;
283 init.bind_generates_resource = true; 283 init.bind_generates_resource = true;
284 InitDecoder(init); 284 InitDecoder(init);
285 285
286 // Bind a non-default texture to GL_TEXTURE0 unit. 286 // Bind a non-default texture to GL_TEXTURE0 unit.
287 SetupTexture(); 287 SetupTexture();
288 288
(...skipping 11 matching lines...) Expand all
300 300
301 // Expect to restore GL_TEXTURE_2D binding to the default texture 301 // Expect to restore GL_TEXTURE_2D binding to the default texture
302 // for GL_TEXTURE1 unit. 302 // for GL_TEXTURE1 unit.
303 AddExpectationsForActiveTexture(GL_TEXTURE1); 303 AddExpectationsForActiveTexture(GL_TEXTURE1);
304 AddExpectationsForBindTexture(GL_TEXTURE_2D, 304 AddExpectationsForBindTexture(GL_TEXTURE_2D,
305 TestHelper::kServiceDefaultTexture2dId); 305 TestHelper::kServiceDefaultTexture2dId);
306 306
307 // Expect to restore active texture unit to GL_TEXTURE0. 307 // Expect to restore active texture unit to GL_TEXTURE0.
308 AddExpectationsForActiveTexture(GL_TEXTURE0); 308 AddExpectationsForActiveTexture(GL_TEXTURE0);
309 309
310 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 310 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
311 } 311 }
312 312
313 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) { 313 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) {
314 InitState init; 314 InitState init;
315 InitDecoder(init); 315 InitDecoder(init);
316 316
317 // Bind a non-default texture to GL_TEXTURE1 unit. 317 // Bind a non-default texture to GL_TEXTURE1 unit.
318 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 318 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
319 SpecializedSetup<ActiveTexture, 0>(true); 319 SpecializedSetup<ActiveTexture, 0>(true);
320 ActiveTexture cmd; 320 ActiveTexture cmd;
(...skipping 15 matching lines...) Expand all
336 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 336 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
337 337
338 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to 338 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
339 // non-default. 339 // non-default.
340 AddExpectationsForActiveTexture(GL_TEXTURE1); 340 AddExpectationsForActiveTexture(GL_TEXTURE1);
341 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 341 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
342 342
343 // Expect to restore active texture unit to GL_TEXTURE1. 343 // Expect to restore active texture unit to GL_TEXTURE1.
344 AddExpectationsForActiveTexture(GL_TEXTURE1); 344 AddExpectationsForActiveTexture(GL_TEXTURE1);
345 345
346 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 346 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
347 } 347 }
348 348
349 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) { 349 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) {
350 InitState init; 350 InitState init;
351 InitDecoder(init); 351 InitDecoder(init);
352 352
353 // Bind a non-default texture to GL_TEXTURE0 unit. 353 // Bind a non-default texture to GL_TEXTURE0 unit.
354 SetupTexture(); 354 SetupTexture();
355 355
356 // Construct a previous ContextState with GL_TEXTURE_2D target in 356 // Construct a previous ContextState with GL_TEXTURE_2D target in
357 // GL_TEXTURE1 unit bound to a non-default texture and the rest 357 // GL_TEXTURE1 unit bound to a non-default texture and the rest
358 // set to default textures. 358 // set to default textures.
359 ContextState prev_state(NULL, NULL, NULL); 359 ContextState prev_state(NULL, NULL, NULL);
360 InitializeContextState(&prev_state, 1, kServiceTextureId); 360 InitializeContextState(&prev_state, 1, kServiceTextureId);
361 361
362 InSequence sequence; 362 InSequence sequence;
363 // Expect to restore GL_TEXTURE_2D binding to the non-default texture 363 // Expect to restore GL_TEXTURE_2D binding to the non-default texture
364 // for GL_TEXTURE0 unit. 364 // for GL_TEXTURE0 unit.
365 AddExpectationsForActiveTexture(GL_TEXTURE0); 365 AddExpectationsForActiveTexture(GL_TEXTURE0);
366 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 366 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
367 367
368 // Expect to restore GL_TEXTURE_2D binding to the 0 texture 368 // Expect to restore GL_TEXTURE_2D binding to the 0 texture
369 // for GL_TEXTURE1 unit. 369 // for GL_TEXTURE1 unit.
370 AddExpectationsForActiveTexture(GL_TEXTURE1); 370 AddExpectationsForActiveTexture(GL_TEXTURE1);
371 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 371 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
372 372
373 // Expect to restore active texture unit to GL_TEXTURE0. 373 // Expect to restore active texture unit to GL_TEXTURE0.
374 AddExpectationsForActiveTexture(GL_TEXTURE0); 374 AddExpectationsForActiveTexture(GL_TEXTURE0);
375 375
376 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 376 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
377 } 377 }
378 378
379 TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) { 379 TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) {
380 struct TestInfo { 380 struct TestInfo {
381 GLenum gl_enum; 381 GLenum gl_enum;
382 bool default_state; 382 bool default_state;
383 bool expect_set; 383 bool expect_set;
384 }; 384 };
385 385
386 // TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py. 386 // TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 490 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
491 491
492 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings(). 492 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
493 493
494 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 494 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
495 495
496 // TODO(vmiura): Tests for ContextState::RestoreGlobalState(). 496 // TODO(vmiura): Tests for ContextState::RestoreGlobalState().
497 497
498 } // namespace gles2 498 } // namespace gles2
499 } // namespace gpu 499 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_passthrough.cc ('k') | ui/gl/gl_state_restorer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698