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

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

Issue 2221173002: Implementing FlushMappedBufferRange in GPU command buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: attempt to fix win build Created 4 years, 2 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_handlers_autogen.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 7 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
8 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" 8 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
9 9
10 using ::gl::MockGLInterface; 10 using ::gl::MockGLInterface;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } else { 211 } else {
212 EXPECT_EQ(kValue0, gpu_data[ii]); 212 EXPECT_EQ(kValue0, gpu_data[ii]);
213 EXPECT_EQ(kValue0, shadow_data[ii]); 213 EXPECT_EQ(kValue0, shadow_data[ii]);
214 } 214 }
215 } 215 }
216 } 216 }
217 217
218 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 218 EXPECT_EQ(GL_NO_ERROR, GetGLError());
219 } 219 }
220 220
221
222 TEST_P(GLES3DecoderTest, FlushMappedBufferRangeSucceeds) {
223 const GLenum kTarget = GL_ELEMENT_ARRAY_BUFFER;
224 const GLintptr kMappedOffset = 10;
225 const GLsizeiptr kMappedSize = 64;
226 const GLintptr kFlushRangeOffset = 5;
227 const GLsizeiptr kFlushRangeSize = 32;
228 const GLsizeiptr kTotalSize = kMappedOffset + kMappedSize;
229 const GLbitfield kAccess = GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
230 const GLbitfield kMappedAccess = kAccess | GL_MAP_READ_BIT;
231
232 uint32_t result_shm_id = kSharedMemoryId;
233 uint32_t result_shm_offset = kSharedMemoryOffset;
234 uint32_t data_shm_id = kSharedMemoryId;
235 // uint32_t is Result for both MapBufferRange and UnmapBuffer commands.
236 uint32_t data_shm_offset = kSharedMemoryOffset + sizeof(uint32_t);
237
238 typedef MapBufferRange::Result Result;
239 Result* result = GetSharedMemoryAs<Result*>();
240 int8_t* client_data = GetSharedMemoryAs<int8_t*>() + sizeof(uint32_t);
241
242 DoBindBuffer(kTarget, client_buffer_id_, kServiceBufferId);
243 Buffer* buffer = GetBuffer(client_buffer_id_);
244 EXPECT_TRUE(buffer != nullptr);
245 DoBufferData(kTarget, kTotalSize);
246 std::vector<int8_t> gpu_data(kTotalSize);
247 for (GLsizeiptr ii = 0; ii < kTotalSize; ++ii) {
248 gpu_data[ii] = static_cast<int8_t>(ii % 128);
249 }
250 DoBufferSubData(kTarget, 0, kTotalSize, &gpu_data[0]);
251
252 EXPECT_EQ(GL_NO_ERROR, GetGLError());
253 EXPECT_TRUE(buffer->shadowed());
254 const int8_t* shadow_data = reinterpret_cast<const int8_t*>(
255 buffer->GetRange(0, kTotalSize));
256 EXPECT_TRUE(shadow_data);
257 // Verify the shadow data is initialized.
258 for (GLsizeiptr ii = 0; ii < kTotalSize; ++ii) {
259 EXPECT_EQ(static_cast<int8_t>(ii % 128), shadow_data[ii]);
260 }
261
262 { // MapBufferRange succeeds
263 EXPECT_CALL(*gl_, MapBufferRange(kTarget, kMappedOffset, kMappedSize,
264 kMappedAccess))
265 .WillOnce(Return(&gpu_data[kMappedOffset]))
266 .RetiresOnSaturation();
267
268 MapBufferRange cmd;
269 cmd.Init(kTarget, kMappedOffset, kMappedSize, kAccess,
270 data_shm_id, data_shm_offset,
271 result_shm_id, result_shm_offset);
272 *result = 0;
273 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
274 EXPECT_EQ(1u, *result);
275 // Verify the buffer range from GPU is copied to client mem.
276 EXPECT_EQ(0, memcmp(&gpu_data[kMappedOffset], client_data, kMappedSize));
277 }
278
279 // Update the client mem, including data within and outside the flush range.
280 const int8_t kValue0 = 21;
281 memset(client_data, kValue0, kTotalSize);
282
283 { // FlushMappedBufferRange succeeds
284 EXPECT_CALL(*gl_, FlushMappedBufferRange(kTarget, kFlushRangeOffset,
285 kFlushRangeSize))
286 .Times(1)
287 .RetiresOnSaturation();
288
289 FlushMappedBufferRange cmd;
290 cmd.Init(kTarget, kFlushRangeOffset, kFlushRangeSize);
291 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
292
293 // Verify the GPU mem and shadow data are both updated, but only within
294 // the flushed range.
295 for (GLsizeiptr ii = 0; ii < kTotalSize; ++ii) {
296 if (ii >= kMappedOffset + kFlushRangeOffset &&
297 ii < kMappedOffset + kFlushRangeOffset + kFlushRangeSize) {
298 EXPECT_EQ(kValue0, gpu_data[ii]);
299 EXPECT_EQ(kValue0, shadow_data[ii]);
300 } else {
301 EXPECT_EQ(static_cast<int8_t>(ii % 128), gpu_data[ii]);
302 EXPECT_EQ(static_cast<int8_t>(ii % 128), shadow_data[ii]);
303 }
304 }
305 }
306
307 { // UnmapBuffer succeeds
308 EXPECT_CALL(*gl_, UnmapBuffer(kTarget))
309 .WillOnce(Return(GL_TRUE))
310 .RetiresOnSaturation();
311
312 UnmapBuffer cmd;
313 cmd.Init(kTarget);
314 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
315
316 // Verify no further update to the GPU mem and shadow data.
317 for (GLsizeiptr ii = 0; ii < kTotalSize; ++ii) {
318 if (ii >= kMappedOffset + kFlushRangeOffset &&
319 ii < kMappedOffset + kFlushRangeOffset + kFlushRangeSize) {
320 EXPECT_EQ(kValue0, gpu_data[ii]);
321 EXPECT_EQ(kValue0, shadow_data[ii]);
322 } else {
323 EXPECT_EQ(static_cast<int8_t>(ii % 128), gpu_data[ii]);
324 EXPECT_EQ(static_cast<int8_t>(ii % 128), shadow_data[ii]);
325 }
326 }
327 }
328
329 EXPECT_EQ(GL_NO_ERROR, GetGLError());
330 }
331
221 TEST_P(GLES2DecoderTest, MapBufferRangeNotInitFails) { 332 TEST_P(GLES2DecoderTest, MapBufferRangeNotInitFails) {
222 const GLenum kTarget = GL_ARRAY_BUFFER; 333 const GLenum kTarget = GL_ARRAY_BUFFER;
223 const GLintptr kOffset = 10; 334 const GLintptr kOffset = 10;
224 const GLsizeiptr kSize = 64; 335 const GLsizeiptr kSize = 64;
225 const GLbitfield kAccess = GL_MAP_READ_BIT; 336 const GLbitfield kAccess = GL_MAP_READ_BIT;
226 std::vector<int8_t> data(kSize); 337 std::vector<int8_t> data(kSize);
227 338
228 typedef MapBufferRange::Result Result; 339 typedef MapBufferRange::Result Result;
229 Result* result = GetSharedMemoryAs<Result*>(); 340 Result* result = GetSharedMemoryAs<Result*>();
230 *result = 1; // Any value other than 0. 341 *result = 1; // Any value other than 0.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 TEST_P(GLES2DecoderTest, MapBufferRangeBadSharedMemoryFails) { 503 TEST_P(GLES2DecoderTest, MapBufferRangeBadSharedMemoryFails) {
393 const GLenum kTarget = GL_ARRAY_BUFFER; 504 const GLenum kTarget = GL_ARRAY_BUFFER;
394 const GLintptr kOffset = 10; 505 const GLintptr kOffset = 10;
395 const GLsizeiptr kSize = 64; 506 const GLsizeiptr kSize = 64;
396 const GLbitfield kAccess = GL_MAP_READ_BIT; 507 const GLbitfield kAccess = GL_MAP_READ_BIT;
397 std::vector<int8_t> data(kSize); 508 std::vector<int8_t> data(kSize);
398 for (GLsizeiptr ii = 0; ii < kSize; ++ii) { 509 for (GLsizeiptr ii = 0; ii < kSize; ++ii) {
399 data[ii] = static_cast<int8_t>(ii % 255); 510 data[ii] = static_cast<int8_t>(ii % 255);
400 } 511 }
401 512
513 DoBindBuffer(kTarget, client_buffer_id_, kServiceBufferId);
514 DoBufferData(kTarget, kOffset + kSize);
515
402 typedef MapBufferRange::Result Result; 516 typedef MapBufferRange::Result Result;
403 Result* result = GetSharedMemoryAs<Result*>(); 517 Result* result = GetSharedMemoryAs<Result*>();
404 *result = 0; 518 *result = 0;
405 uint32_t result_shm_id = kSharedMemoryId; 519 uint32_t result_shm_id = kSharedMemoryId;
406 uint32_t result_shm_offset = kSharedMemoryOffset; 520 uint32_t result_shm_offset = kSharedMemoryOffset;
407 uint32_t data_shm_id = kSharedMemoryId; 521 uint32_t data_shm_id = kSharedMemoryId;
408 uint32_t data_shm_offset = kSharedMemoryOffset + sizeof(*result); 522 uint32_t data_shm_offset = kSharedMemoryOffset + sizeof(*result);
409 523
410 decoder_->set_unsafe_es3_apis_enabled(true); 524 decoder_->set_unsafe_es3_apis_enabled(true);
411 MapBufferRange cmd; 525 MapBufferRange cmd;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 if (ii >= kWriteOffset && ii < kWriteOffset + kCopySize) { 744 if (ii >= kWriteOffset && ii < kWriteOffset + kCopySize) {
631 EXPECT_EQ(kValue0, shadow_data[ii]); 745 EXPECT_EQ(kValue0, shadow_data[ii]);
632 } else { 746 } else {
633 EXPECT_EQ(kValue1, shadow_data[ii]); 747 EXPECT_EQ(kValue1, shadow_data[ii]);
634 } 748 }
635 } 749 }
636 } 750 }
637 751
638 } // namespace gles2 752 } // namespace gles2
639 } // namespace gpu 753 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_passthrough_handlers_autogen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698